16namespace alib {
namespace expressions {
namespace detail {
32#define SPACE(flag) ( HasBits(format, Normalization::flag ) ? normSpace : EMPTY_STRING )
33#define COND_SPACE(flag, force) if( HasBits(format, Normalization::flag ) || force ) normalized << ' '
37 for(
auto& it : compiler.CfgNormalizationDisallowed )
38 if( it.Length() > spaceInsertionPos
39 && normalized.ContainsAt( it, positionToCheck ) )
41 normalized.InsertAt(
A_CHAR(
" "), positionToCheck + spaceInsertionPos );
55 for(
auto& arg : Arguments )
134 auto oldFlags= nf->
Flags;
137 nf->
Flags+= NumberFormatFlags::ForceScientific;
186 functionName <<
Name;
189 normalized << functionName;
196 bool replacedNestedExpressionIdentifierByLiteral=
false;
197 bool thirdArgumentIsThrowIdentifier=
false;
200 if( qtyArgs < 1 || qtyArgs > 3 )
209 && (*
Arguments.begin())->NodeType == Types::Identifier )
214 replacedNestedExpressionIdentifierByLiteral=
true;
223 if( (*argIt)->NodeType != Types::Identifier
230 thirdArgumentIsThrowIdentifier=
true;
245 if( replacedNestedExpressionIdentifierByLiteral
250 argAst->Assemble( program, allocator, normalized );
252 normalized << dynamic_cast<ASTLiteral*>(argAst)->Value.Unbox<
String>();
259 if( no != 2 || !thirdArgumentIsThrowIdentifier )
260 argAst->Assemble( program, allocator, normalized );
272 if( completeIdentifierNames )
288 bool replacedNestedExpressionIdentifierByLiteral=
false;
298 nonVerbalOp= it.Mapped();
309 replacedNestedExpressionIdentifierByLiteral=
true;
316 auto opIdx= normalized.
Length();
318 auto opLen= normalized.
Length() - opIdx;
327 bool opSpaceIfNotVerbal= !brackets
330 normalized << ( brackets
341 if( replacedNestedExpressionIdentifierByLiteral
344 normalized.
ShortenTo( lenBeforeArgument );
345 normalized << dynamic_cast<ASTLiteral*>(
Argument )->Value.Unbox<
String>();
370 for(
integer i= opIdx ; i < opIdx + opLen ; ++i )
376 if( !opSpaceIfNotVerbal && !isalpha(op.CharAtStart() ) )
377 normalized.
Delete( opIdx + opLen, 1 );
391 checkForbiddenStrings( program.
compiler, normalized, opIdx, opLen );
412 auto opIdx= normalized.
Length();
429 int lhsBinaryPrecedence=
Lhs->
NodeType == Types::BinaryOp
432 int rhsBinaryPrecedence=
Rhs->
NodeType == Types::BinaryOp
437 bool lhsBrackets=
Lhs->
NodeType == Types::TernaryOp
438 || ( lhsBinaryPrecedence
440 || precedence > lhsBinaryPrecedence
442 && rhsBinaryPrecedence )
450 if( lhsBrackets ) normalized << normBracketOpen[bracketStringIdx];
452 if( lhsBrackets ) normalized << normBracketClose[bracketStringIdx];
457 auto opIdx= normalized.
Length();
459 auto opLen= normalized.
Length() - opIdx;
473 bool rhsBrackets=
Rhs->
NodeType == Types::TernaryOp
474 || ( rhsBinaryPrecedence
476 || ( precedence >= rhsBinaryPrecedence )
478 && precedence < rhsBinaryPrecedence )
480 && lhsBinaryPrecedence )
486 if( rhsBrackets ) normalized << normBracketOpen[bracketStringIdx];
488 if( rhsBrackets ) normalized << normBracketClose[bracketStringIdx];
507 for(
integer i= opIdx ; i < opIdx + opLen ; ++i )
515 normalized.
Delete( opIdx + opLen, 1 );
516 normalized.
Delete( opIdx - 1 , 1 );
530 checkForbiddenStrings( program.
compiler, normalized, opIdx, opLen );
543 Q->
Assemble( program, allocator, normalized );
551 bool brackets=
T->
NodeType == Types::TernaryOp
554 if( brackets ) normalized << normBracketOpen[bracketStringIdx];
555 T->
Assemble( program, allocator, normalized );
556 if( brackets ) normalized << normBracketClose[bracketStringIdx];
567 brackets=
F->
NodeType == Types::TernaryOp
570 if( brackets ) normalized << normBracketOpen[bracketStringIdx];
571 F->
Assemble( program, allocator, normalized );
572 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< MonoAllocator, 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
Compilation flags.
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)
Compiler & compiler
The compiler that created this object.
ALIB_API void AssembleConstant(Box &value, integer idxInOriginal, integer idxInNormalized)
ALIB_API void AssembleCondFinalize_Q(integer idxInOriginal, integer idxInNormalized)
ALIB_API void AssembleFunction(AString &functionName, bool isIdentifier, int qtyArgs, integer idxInOriginal, integer idxInNormalized)
ALIB_API void AssembleBinaryOp(String &op, integer idxInOriginal, integer idxInNormalized)
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
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
@ NestedExpressionCallArgumentMismatch
@ On
Switch it on, switched on, etc.
@ Local
Denotes local reach.
lang::Exception Exception
Type alias in namespace alib.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
constexpr const String EMPTY_STRING
An empty string of the default character type.
strings::TFormat< character > Format
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.
Abstract syntax tree node representing binary operators.
String Operator
The operator symbol.
virtual AST * Optimize(Normalization normalization) override
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized) override
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< MonoAllocator, 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.
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
Format hints.
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
Types NodeType
Type of derived this AST node.
integer Position
Position in original expression string.