10# if !defined (HPP_ALIB_EXPRESSIONS_DETAIL_AST)
14# if !defined (HPP_ALIB_EXPRESSIONS_COMPILERPLUGIN)
18# if !defined (HPP_ALIB_EXPRESSIONS_DETAIL_PROGRAM)
22# if !defined (HPP_ALIB_STRINGS_FORMAT)
29namespace alib {
namespace expressions {
namespace detail {
45#define SPACE(flag) ( HasBits(format, Normalization::flag ) ? normSpace : EmptyString() )
46#define COND_SPACE(flag, force) if( HasBits(format, Normalization::flag ) || force ) normalized << ' '
50 for(
auto& it : compiler.CfgNormalizationDisallowed )
51 if( it.Length() > spaceInsertionPos && normalized.ContainsAt( it, positionToCheck ) )
53 normalized.InsertAt(
A_CHAR(
" "), positionToCheck + spaceInsertionPos );
67 for(
auto& arg : Arguments )
146 auto oldFlags= nf->
Flags;
149 nf->
Flags+= NumberFormatFlags::ForceScientific;
199 functionName <<
Name;
202 normalized << functionName;
209 bool replacedNestedExpressionIdentifierByLiteral=
false;
210 bool thirdArgumentIsThrowIdentifier=
false;
213 if( qtyArgs < 1 || qtyArgs > 3 )
222 && (*
Arguments.begin())->NodeType == Types::Identifier )
227 replacedNestedExpressionIdentifierByLiteral=
true;
236 if( (*argIt)->NodeType != Types::Identifier
243 thirdArgumentIsThrowIdentifier=
true;
258 if( replacedNestedExpressionIdentifierByLiteral
263 argAst->Assemble( program, allocator, normalized );
265 normalized << dynamic_cast<ASTLiteral*>(argAst)->Value.Unbox<
String>();
272 if( no != 2 || !thirdArgumentIsThrowIdentifier )
273 argAst->Assemble( program, allocator, normalized );
285 if( completeIdentifierNames )
301 bool replacedNestedExpressionIdentifierByLiteral=
false;
311 nonVerbalOp= it.Mapped();
322 replacedNestedExpressionIdentifierByLiteral=
true;
329 auto opIdx= normalized.
Length();
331 auto opLen= normalized.
Length() - opIdx;
340 bool opSpaceIfNotVerbal= !brackets
343 normalized << ( brackets
354 if( replacedNestedExpressionIdentifierByLiteral
357 normalized.
ShortenTo( lenBeforeArgument );
358 normalized << dynamic_cast<ASTLiteral*>(
Argument )->Value.Unbox<
String>();
383 for(
integer i= opIdx ; i < opIdx + opLen ; ++i )
389 if( !opSpaceIfNotVerbal && !isalpha(op.
CharAtStart() ) )
390 normalized.
Delete( opIdx + opLen, 1 );
404 checkForbiddenStrings( program.
compiler, normalized, opIdx, opLen );
425 auto opIdx= normalized.
Length();
442 int lhsBinaryPrecedence=
Lhs->
NodeType == Types::BinaryOp
445 int rhsBinaryPrecedence=
Rhs->
NodeType == Types::BinaryOp
450 bool lhsBrackets=
Lhs->
NodeType == Types::TernaryOp
451 || ( lhsBinaryPrecedence
453 || precedence > lhsBinaryPrecedence
455 && rhsBinaryPrecedence )
463 if( lhsBrackets ) normalized << normBracketOpen[bracketStringIdx];
465 if( lhsBrackets ) normalized << normBracketClose[bracketStringIdx];
470 auto opIdx= normalized.
Length();
472 auto opLen= normalized.
Length() - opIdx;
486 bool rhsBrackets=
Rhs->
NodeType == Types::TernaryOp
487 || ( rhsBinaryPrecedence
489 || ( precedence >= rhsBinaryPrecedence )
491 && precedence < rhsBinaryPrecedence )
493 && lhsBinaryPrecedence )
499 if( rhsBrackets ) normalized << normBracketOpen[bracketStringIdx];
501 if( rhsBrackets ) normalized << normBracketClose[bracketStringIdx];
520 for(
integer i= opIdx ; i < opIdx + opLen ; ++i )
528 normalized.
Delete( opIdx + opLen, 1 );
529 normalized.
Delete( opIdx - 1 , 1 );
543 checkForbiddenStrings( program.
compiler, normalized, opIdx, opLen );
556 Q->
Assemble( program, allocator, normalized );
564 bool brackets=
T->
NodeType == Types::TernaryOp
567 if( brackets ) normalized << normBracketOpen[bracketStringIdx];
568 T->
Assemble( program, allocator, normalized );
569 if( brackets ) normalized << normBracketClose[bracketStringIdx];
580 brackets=
F->
NodeType == Types::TernaryOp
583 if( brackets ) normalized << normBracketOpen[bracketStringIdx];
584 F->
Assemble( program, allocator, normalized );
585 if( brackets ) normalized << normBracketClose[bracketStringIdx];
decltype(std::declval< typename TFDecl::Signature >()(std::declval< Box & >(), std::declval< TArgs >()...)) CallDirect(typename TFDecl::Signature function, TArgs &&... args) const
TFDecl::Signature GetFunction(Reach searchScope, bool isInvocation=false) const
const TUnboxable Unbox() const
HashMap< String, String, alib::hash_string_ignore_case< character >, alib::equal_to_string_ignore_case< character > > AlphabeticUnaryOperatorAliases
String CfgNestedExpressionOperator
int GetBinaryOperatorPrecedence(const String &symbol)
Compilation CfgCompilation
strings::util::Token CfgNestedExpressionFunction
Normalization CfgNormalization
String CfgNestedExpressionThrowIdentifier
ALIB_API void AssembleCondFinalize_T(integer idxInOriginal, integer idxInNormalized)
ALIB_API void AssembleCondFinalize_F(integer idxInOriginal, integer idxInNormalized)
ALIB_API void AssembleUnaryOp(String &op, integer idxInOriginal, integer idxInNormalized)
ALIB_API void AssembleFunction(AString &functionName, integer qtyArgsOrNoParentheses, integer idxInOriginal, integer idxInNormalized)
ALIB_API void AssembleConstant(Box &value, integer idxInOriginal, integer idxInNormalized)
ALIB_API void AssembleCondFinalize_Q(integer idxInOriginal, integer idxInNormalized)
ALIB_API void AssembleBinaryOp(String &op, integer idxInOriginal, integer idxInNormalized)
ALIB_FORCE_INLINE T * Emplace(TArgs &&... args)
TAString & ShortenTo(integer newLength)
TAString & Delete(integer regionStart, integer regionLength=MAX_LEN)
TAString & ReplaceSubstring(const TString< TChar > &src, integer regionStart, integer regionLength)
void DbgDisableBufferReplacementWarning()
constexpr integer Length() const
TChar CharAtStart() const
bool Equals(const TString< TChar > &rhs) const
ALIB_API bool Match(const String &needle)
#define ALIB_CALLER_NULLED
#define ALIB_STRING_RESETTER(astring)
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
@ AllowIdentifiersForNestedExpressions
@ FunctionInnerBracketSpace
@ ConditionalOpSpaceBeforeQM
@ RedundantUnaryOpBrackets
@ QuoteUnaryNestedExpressionOperatorArgument
@ ReplaceVerbalOperatorsToLowerCase
@ FunctionSpaceBeforeOpeningBracket
@ FunctionSpaceBeforeComma
@ UnaryOpSpaceIfUnaryFollows
@ RedundantRhsBracketsIfRhsIsStrongerBinaryOp
@ ConditionalOpSpaceAfterQM
@ UnaryOpSpaceIfBracketFollows
@ FunctionSpaceAfterComma
@ UnaryOpInnerBracketSpace
@ ConditionalOpSpaceBeforeColon
@ SubscriptSpaceBeforeBrackets
@ RedundantBracketsBetweenTwoUnaryOps
@ RedundantBracketsIfLhsAndRhsAreBinaryOps
@ SubscriptInnerBracketSpace
@ FunctionInnerBracketSpaceIfNoArguments
@ RedundantConditionalOpBrackets
@ RedundantBinaryOpBrackets
@ RemoveRedundantUnaryOpsOnNumberLiterals
@ ReplaceVerbalOperatorsToUpperCase
@ ConditionalOpSpaceAfterColon
@ NestedExpressionCallArgumentMismatch
@ On
Switch it on, switched on, etc.
@ Local
Denotes local reach.
lang::Exception Exception
Type alias in namespace alib.
constexpr CString EmptyString()
strings::TFormat< character > Format
Type alias in namespace alib.
strings::TAString< character > AString
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
expressions::Compiler Compiler
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
static TChar ToLower(TChar c)
static TChar ToUpper(TChar c)
String Operator
The operator symbol.
virtual AST * Optimize(Normalization normalization) override
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
AST * Rhs
The right-hand-side expression node.
AST * Lhs
The left-hand-side expression node.
integer ColonPosition
The index of the colon in the expression string.
virtual AST * Optimize(Normalization normalization) override
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
String Name
The function name as parsed.
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
List< AST * > Arguments
The argument nodes.
String Name
The name of the identifier as parsed from the expression string.
virtual AST * Optimize(Normalization normalization) override
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
Box Value
The value of the literal.
@ Scientific
Float was given in scientific format.
@ Hexadecimal
Integral value was given in hexadecimal format.
@ Binary
Integral value was given in binary format.
@ Octal
Integral value was given in octal format.
NFHint Format
The value of the literal.
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
String Operator
The operator symbol.
AST * Argument
The argument node.
virtual AST * Optimize(Normalization normalization) override
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
virtual AST * Optimize(Normalization normalization)=0
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized)=0