15#define SPACE(flag) ( HasBits(format, Normalization::flag ) ? normSpace : EMPTY_STRING )
16#define COND_SPACE(flag, force) if( HasBits(format, Normalization::flag ) || force ) normalized << ' '
20 for(
auto& it : compiler.CfgNormalizationDisallowed )
21 if( it.Length() > spaceInsertionPos
22 && normalized.ContainsAt( it, positionToCheck ) )
24 normalized.InsertAt(
A_CHAR(
" "), positionToCheck + spaceInsertionPos );
37 arg= arg->Optimize( normalization );
42 Lhs=
Lhs->Optimize( normalization );
43 Rhs=
Rhs->Optimize( normalization );
48 Q=
Q->Optimize( normalization );
49 T=
T->Optimize( normalization );
50 F=
F->Optimize( normalization );
100 else if(
Value.IsType<
double>() ) {
102 auto oldFlags= nf->
Flags;
105 nf->
Flags+= NumberFormatFlags::ForceScientific;
124 else normalized <<
Dec(value, 0, nf);
151 functionName <<
Name;
154 normalized << functionName;
161 bool replacedNestedExpressionIdentifierByLiteral=
false;
162 bool thirdArgumentIsThrowIdentifier=
false;
164 if( qtyArgs < 1 || qtyArgs > 3 ) {
177 replacedNestedExpressionIdentifierByLiteral=
true;
192 thirdArgumentIsThrowIdentifier=
true;
203 if( replacedNestedExpressionIdentifierByLiteral
208 argAst->Assemble( program, allocator, normalized );
210 normalized << dynamic_cast<ASTLiteral*>(argAst)->Value.Unbox<
String>();
216 if( no != 2 || !thirdArgumentIsThrowIdentifier )
217 argAst->Assemble( program, allocator, normalized );
229 if( completeIdentifierNames )
244 bool replacedNestedExpressionIdentifierByLiteral=
false;
252 nonVerbalOp= it.Mapped();
263 replacedNestedExpressionIdentifierByLiteral=
true;
267 auto opIdx= normalized.
Length();
269 auto opLen= normalized.
Length() - opIdx;
278 bool opSpaceIfNotVerbal= !brackets
281 normalized << ( brackets
289 Argument->Assemble( program, allocator, normalized );
292 if( replacedNestedExpressionIdentifierByLiteral
295 normalized.
ShortenTo( lenBeforeArgument );
296 normalized << dynamic_cast<ASTLiteral*>(
Argument )->Value.Unbox<
String>();
306 if( op !=
Operator || isVerbalOp ) {
317 for(
integer i= opIdx ; i < opIdx + opLen ; ++i )
323 if( !opSpaceIfNotVerbal && !isalpha(op.CharAtStart() ) )
324 normalized.
Delete( opIdx + opLen, 1 );
336 checkForbiddenStrings( program.
compiler, normalized, opIdx, opLen );
345 if( op ==
A_CHAR(
"[]") ) {
347 Lhs->Assemble( program, allocator, normalized );
355 auto opIdx= normalized.
Length();
356 Rhs->Assemble( program, allocator, normalized );
381 || ( lhsBinaryPrecedence
383 || precedence > lhsBinaryPrecedence
385 && rhsBinaryPrecedence )
393 if( lhsBrackets ) normalized << normBracketOpen[bracketStringIdx];
394 Lhs->Assemble( program, allocator, normalized );
395 if( lhsBrackets ) normalized << normBracketClose[bracketStringIdx];
400 auto opIdx= normalized.
Length();
402 auto opLen= normalized.
Length() - opIdx;
417 || ( rhsBinaryPrecedence
419 || ( precedence >= rhsBinaryPrecedence )
421 && precedence < rhsBinaryPrecedence )
423 && lhsBinaryPrecedence )
429 if( rhsBrackets ) normalized << normBracketOpen[bracketStringIdx];
430 Rhs->Assemble( program, allocator, normalized );
431 if( rhsBrackets ) normalized << normBracketClose[bracketStringIdx];
437 if( op !=
Operator || isVerbalOp ) {
448 for(
integer i= opIdx ; i < opIdx + opLen ; ++i )
455 normalized.
Delete( opIdx + opLen, 1 );
456 normalized.
Delete( opIdx - 1 , 1 );
468 checkForbiddenStrings( program.
compiler, normalized, opIdx, opLen );
480 Q->Assemble( program, allocator, normalized );
491 if( brackets ) normalized << normBracketOpen[bracketStringIdx];
492 T->Assemble( program, allocator, normalized );
493 if( brackets ) normalized << normBracketClose[bracketStringIdx];
507 if( brackets ) normalized << normBracketOpen[bracketStringIdx];
508 F->Assemble( program, allocator, normalized );
509 if( brackets ) normalized << normBracketClose[bracketStringIdx];
#define ALIB_CALLER_NULLED
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
void AssembleUnaryOp(String &op, integer idxInOriginal, integer idxInNormalized)
void AssembleFunction(AString &functionName, bool isIdentifier, int qtyArgs, integer idxInOriginal, integer idxInNormalized)
void AssembleBinaryOp(String &op, integer idxInOriginal, integer idxInNormalized)
void AssembleCondFinalize_Q(integer idxInOriginal, integer idxInNormalized)
void AssembleConstant(Box &value, integer idxInOriginal, integer idxInNormalized)
Compiler & compiler
The compiler that created this object.
void AssembleCondFinalize_F(integer idxInOriginal, integer idxInNormalized)
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
bool Match(const String &needle)
@ FunctionInnerBracketSpace
@ ConditionalOpSpaceBeforeQM
@ RedundantUnaryOpBrackets
@ QuoteUnaryNestedExpressionOperatorArgument
@ ReplaceVerbalOperatorsToLowerCase
See sibling flag #"Normalization::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 #"Normalization::ReplaceVerbalOperatorsToSymbolic".
@ ConditionalOpSpaceAfterColon
@ AllowIdentifiersForNestedExpressions
@ NestedExpressionCallArgumentMismatch
@ Local
Denotes local reach.
@ On
Switch it on, switched on, etc.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
strings::TNumberFormat< character > NumberFormat
Type alias in namespace #"%alib".
strings::TEscape< character > Escape
Type alias in namespace #"%alib".
LocalString< 64 > String64
Type alias name for #"TLocalString;TLocalString<character,64>".
constexpr const String EMPTY_STRING
An empty string of the default character type.
lang::integer integer
Type alias in namespace #"%alib".
expressions::Compiler Compiler
Type alias in namespace #"%alib".
strings::TString< character > String
Type alias in namespace #"%alib".
strings::TDec< character > Dec
Type alias in namespace #"%alib".
exceptions::Exception Exception
Type alias in namespace #"%alib".
strings::TBin< character > Bin
Type alias in namespace #"%alib".
strings::TOct< character > Oct
Type alias in namespace #"%alib".
strings::THex< character > Hex
Type alias in namespace #"%alib".
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace #"%alib".
#define ALIB_STRING_RESETTER(astring)
@ 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
String Name
The function name as parsed.
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
ListMA< AST * > Arguments
The argument nodes.
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.