8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
41#define SPACE(flag) ( HasBits(format, Normalization::flag ) ? normSpace : EMPTY_STRING )
42#define COND_SPACE(flag, force) if( HasBits(format, Normalization::flag ) || force ) normalized << ' '
46 for(
auto& it : compiler.CfgNormalizationDisallowed )
47 if( it.Length() > spaceInsertionPos
48 && normalized.ContainsAt( it, positionToCheck ) )
50 normalized.InsertAt(
A_CHAR(
" "), positionToCheck + spaceInsertionPos );
65 arg= arg->Optimize( normalization );
71 Lhs=
Lhs->Optimize( normalization );
72 Rhs=
Rhs->Optimize( normalization );
78 Q=
Q->Optimize( normalization );
79 T=
T->Optimize( normalization );
80 F=
F->Optimize( normalization );
140 else if(
Value.IsType<
double>() )
143 auto oldFlags= nf->
Flags;
146 nf->
Flags+= NumberFormatFlags::ForceScientific;
166 else normalized <<
Dec(value, 0, nf);
195 functionName <<
Name;
198 normalized << functionName;
205 bool replacedNestedExpressionIdentifierByLiteral=
false;
206 bool thirdArgumentIsThrowIdentifier=
false;
209 if( qtyArgs < 1 || qtyArgs > 3 )
223 replacedNestedExpressionIdentifierByLiteral=
true;
239 thirdArgumentIsThrowIdentifier=
true;
254 if( replacedNestedExpressionIdentifierByLiteral
259 argAst->Assemble( program, allocator, normalized );
261 normalized << dynamic_cast<ASTLiteral*>(argAst)->Value.Unbox<
String>();
268 if( no != 2 || !thirdArgumentIsThrowIdentifier )
269 argAst->Assemble( program, allocator, normalized );
281 if( completeIdentifierNames )
297 bool replacedNestedExpressionIdentifierByLiteral=
false;
307 nonVerbalOp= it.Mapped();
318 replacedNestedExpressionIdentifierByLiteral=
true;
323 auto opIdx= normalized.
Length();
325 auto opLen= normalized.
Length() - opIdx;
334 bool opSpaceIfNotVerbal= !brackets
337 normalized << ( brackets
345 Argument->Assemble( program, allocator, normalized );
348 if( replacedNestedExpressionIdentifierByLiteral
351 normalized.
ShortenTo( lenBeforeArgument );
352 normalized << dynamic_cast<ASTLiteral*>(
Argument )->Value.Unbox<
String>();
375 for(
integer i= opIdx ; i < opIdx + opLen ; ++i )
381 if( !opSpaceIfNotVerbal && !isalpha(op.CharAtStart() ) )
382 normalized.
Delete( opIdx + opLen, 1 );
396 checkForbiddenStrings( program.
compiler, normalized, opIdx, opLen );
409 Lhs->Assemble( program, allocator, normalized );
417 auto opIdx= normalized.
Length();
418 Rhs->Assemble( program, allocator, normalized );
443 || ( lhsBinaryPrecedence
445 || precedence > lhsBinaryPrecedence
447 && rhsBinaryPrecedence )
455 if( lhsBrackets ) normalized << normBracketOpen[bracketStringIdx];
456 Lhs->Assemble( program, allocator, normalized );
457 if( lhsBrackets ) normalized << normBracketClose[bracketStringIdx];
462 auto opIdx= normalized.
Length();
464 auto opLen= normalized.
Length() - opIdx;
479 || ( rhsBinaryPrecedence
481 || ( precedence >= rhsBinaryPrecedence )
483 && precedence < rhsBinaryPrecedence )
485 && lhsBinaryPrecedence )
491 if( rhsBrackets ) normalized << normBracketOpen[bracketStringIdx];
492 Rhs->Assemble( program, allocator, normalized );
493 if( rhsBrackets ) normalized << normBracketClose[bracketStringIdx];
512 for(
integer i= opIdx ; i < opIdx + opLen ; ++i )
520 normalized.
Delete( opIdx + opLen, 1 );
521 normalized.
Delete( opIdx - 1 , 1 );
535 checkForbiddenStrings( program.
compiler, normalized, opIdx, opLen );
548 Q->Assemble( program, allocator, normalized );
559 if( brackets ) normalized << normBracketOpen[bracketStringIdx];
560 T->Assemble( program, allocator, normalized );
561 if( brackets ) normalized << normBracketClose[bracketStringIdx];
575 if( brackets ) normalized << normBracketOpen[bracketStringIdx];
576 F->Assemble( program, allocator, normalized );
577 if( brackets ) normalized << normBracketClose[bracketStringIdx];
Normalization CfgNormalization
Compilation CfgCompilation
Compilation flags.
strings::util::Token CfgNestedExpressionFunction
String CfgNestedExpressionThrowIdentifier
HashMap< MonoAllocator, String, String, alib::hash_string_ignore_case< character >, alib::equal_to_string_ignore_case< character > > AlphabeticUnaryOperatorAliases
int GetBinaryOperatorPrecedence(const String &symbol)
String CfgNestedExpressionOperator
ALIB_DLL void AssembleUnaryOp(String &op, integer idxInOriginal, integer idxInNormalized)
ALIB_DLL void AssembleFunction(AString &functionName, bool isIdentifier, int qtyArgs, integer idxInOriginal, integer idxInNormalized)
ALIB_DLL void AssembleBinaryOp(String &op, integer idxInOriginal, integer idxInNormalized)
ALIB_DLL void AssembleCondFinalize_Q(integer idxInOriginal, integer idxInNormalized)
ALIB_DLL void AssembleConstant(Box &value, integer idxInOriginal, integer idxInNormalized)
Compiler & compiler
The compiler that created this object.
ALIB_DLL void AssembleCondFinalize_F(integer idxInOriginal, integer idxInNormalized)
ALIB_DLL void AssembleCondFinalize_T(integer idxInOriginal, integer idxInNormalized)
TAString & Delete(integer regionStart, integer regionLength=MAX_LEN)
TAString & ReplaceSubstring(const TString< TChar > &src, integer regionStart, integer regionLength)
TAString & ShortenTo(integer newLength)
void DbgDisableBufferReplacementWarning()
constexpr integer Length() const
TChar CharAtStart() const
bool Equals(const TString< TChar > &rhs) const
ALIB_DLL bool Match(const String &needle)
#define ALIB_CALLER_NULLED
#define ALIB_STRING_RESETTER(astring)
@ FunctionInnerBracketSpace
@ ConditionalOpSpaceBeforeQM
@ RedundantUnaryOpBrackets
@ QuoteUnaryNestedExpressionOperatorArgument
@ ReplaceVerbalOperatorsToLowerCase
See sibling flag ReplaceVerbalOperatorsToSymbolic.
@ FunctionSpaceBeforeOpeningBracket
@ FunctionSpaceBeforeComma
@ UnaryOpSpaceIfUnaryFollows
@ RedundantRhsBracketsIfRhsIsStrongerBinaryOp
@ ConditionalOpSpaceAfterQM
@ UnaryOpSpaceIfBracketFollows
@ FunctionSpaceAfterComma
@ UnaryOpInnerBracketSpace
@ ConditionalOpSpaceBeforeColon
@ SubscriptSpaceBeforeBrackets
@ RedundantBracketsBetweenTwoUnaryOps
@ RedundantBracketsIfLhsAndRhsAreBinaryOps
@ SubscriptInnerBracketSpace
@ FunctionInnerBracketSpaceIfNoArguments
@ RedundantConditionalOpBrackets
@ NONE
All flags are cleared, may be used for testing bits.
@ RedundantBinaryOpBrackets
@ RemoveRedundantUnaryOpsOnNumberLiterals
@ ReplaceVerbalOperatorsToUpperCase
See sibling flag ReplaceVerbalOperatorsToSymbolic.
@ ConditionalOpSpaceAfterColon
@ AllowIdentifiersForNestedExpressions
@ NestedExpressionCallArgumentMismatch
@ Local
Denotes local reach.
@ On
Switch it on, switched on, etc.
strings::TEscape< character > Escape
Type alias in namespace alib.
strings::TDec< character > Dec
Type alias in namespace alib.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
LocalString< 64 > String64
Type alias name for TLocalString<character,64>.
constexpr const String EMPTY_STRING
An empty string of the default character type.
lang::integer integer
Type alias in namespace alib.
strings::TNumberFormat< character > NumberFormat
Type alias in namespace alib.
strings::TOct< character > Oct
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
strings::THex< character > Hex
Type alias in namespace alib.
exceptions::Exception Exception
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
expressions::Compiler Compiler
Type alias in namespace alib.
strings::TBin< character > Bin
Type alias in namespace alib.
@ Identifier
An identifier.
@ UnaryOp
A unary operator.
@ BinaryOp
A binary operator.
@ TernaryOp
A ternary operator.
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
virtual AST * Optimize(Normalization normalization) override
ASTBinaryOp(const String &op, AST *lhs, AST *rhs, integer position)
AST * Lhs
The left-hand-side expression node.
String Operator
The operator symbol.
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
integer ColonPosition
The index of the colon in the expression string.
virtual AST * Optimize(Normalization normalization) override
List< MonoAllocator, AST * > Arguments
The argument nodes.
String Name
The function name as parsed.
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
Abstract syntax tree node representing identifiers.
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
Abstract syntax tree node representing identifiers.
@ 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.
Box Value
The value of the literal.
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
NFHint Format
Format hints.
virtual AST * Optimize(Normalization normalization) override
AST * Argument
The argument node.
String Operator
The operator symbol.
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
integer Position
Position in the original expression string.
AST()=delete
Deleted default constructor.