2021-01-13 17:28:27 +01:00
# include <hex/lang/evaluator.hpp>
2020-11-19 11:36:52 +01:00
2021-01-13 17:28:27 +01:00
# include <hex/lang/token.hpp>
# include <hex/helpers/utils.hpp>
# include <hex/api/content_registry.hpp>
2020-12-27 15:54:12 +01:00
2020-11-20 20:26:19 +01:00
# include <bit>
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
# include <algorithm>
2020-11-19 11:36:52 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
# include <unistd.h>
2020-11-19 11:36:52 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
namespace hex : : lang {
2020-12-06 21:40:57 +01:00
2021-01-06 16:28:41 +01:00
ASTNodeIntegerLiteral * Evaluator : : evaluateScopeResolution ( ASTNodeScopeResolution * node ) {
ASTNode * currScope = nullptr ;
for ( const auto & identifier : node - > getPath ( ) ) {
if ( currScope = = nullptr ) {
if ( ! this - > m_types . contains ( identifier ) )
break ;
currScope = this - > m_types [ identifier . data ( ) ] ;
} else if ( auto enumNode = dynamic_cast < ASTNodeEnum * > ( currScope ) ; enumNode ! = nullptr ) {
if ( ! enumNode - > getEntries ( ) . contains ( identifier ) )
break ;
else
return evaluateMathematicalExpression ( static_cast < ASTNodeNumericExpression * > ( enumNode - > getEntries ( ) . at ( identifier ) ) ) ;
}
}
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " failed to find identifier " ) ;
2021-01-06 16:28:41 +01:00
}
2021-04-21 10:17:42 +02:00
PatternData * Evaluator : : findPattern ( std : : vector < PatternData * > currMembers , const ASTNodeRValue : : Path & path ) {
2021-04-12 20:49:37 +02:00
PatternData * currPattern = nullptr ;
2021-04-21 10:17:42 +02:00
for ( const auto & part : path ) {
if ( auto stringPart = std : : get_if < std : : string > ( & part ) ; stringPart ! = nullptr ) {
if ( * stringPart = = " parent " ) {
if ( currPattern = = nullptr ) {
if ( ! currMembers . empty ( ) )
currPattern = this - > m_currMemberScope . back ( ) ;
if ( currPattern = = nullptr )
this - > getConsole ( ) . abortEvaluation ( " attempted to get parent of global namespace " ) ;
}
auto parent = currPattern - > getParent ( ) ;
if ( parent = = nullptr ) {
2021-06-16 21:13:54 +02:00
this - > getConsole ( ) . abortEvaluation ( " no parent available for identifier " ) ;
2021-04-21 10:17:42 +02:00
} else {
currPattern = parent ;
}
2021-04-12 20:49:37 +02:00
} else {
2021-04-21 10:17:42 +02:00
if ( currPattern ! = nullptr ) {
if ( auto structPattern = dynamic_cast < PatternDataStruct * > ( currPattern ) ; structPattern ! = nullptr )
currMembers = structPattern - > getMembers ( ) ;
else if ( auto unionPattern = dynamic_cast < PatternDataUnion * > ( currPattern ) ; unionPattern ! = nullptr )
currMembers = unionPattern - > getMembers ( ) ;
else if ( auto arrayPattern = dynamic_cast < PatternDataArray * > ( currPattern ) ; arrayPattern ! = nullptr ) {
currMembers = arrayPattern - > getEntries ( ) ;
continue ;
}
else
this - > getConsole ( ) . abortEvaluation ( " tried to access member of a non-struct/union type " ) ;
}
auto candidate = std : : find_if ( currMembers . begin ( ) , currMembers . end ( ) , [ & ] ( auto member ) {
return member - > getVariableName ( ) = = * stringPart ;
} ) ;
if ( candidate ! = currMembers . end ( ) )
currPattern = * candidate ;
2021-04-12 20:49:37 +02:00
else
2021-04-21 10:17:42 +02:00
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " no member found with identifier '{0}' " , * stringPart ) ) ;
}
} else if ( auto nodePart = std : : get_if < ASTNode * > ( & part ) ; nodePart ! = nullptr ) {
if ( auto numericalExpressionNode = dynamic_cast < ASTNodeNumericExpression * > ( * nodePart ) ) {
auto arrayIndexNode = evaluateMathematicalExpression ( numericalExpressionNode ) ;
ON_SCOPE_EXIT { delete arrayIndexNode ; } ;
if ( currPattern ! = nullptr ) {
if ( auto arrayPattern = dynamic_cast < PatternDataArray * > ( currPattern ) ; arrayPattern ! = nullptr ) {
2021-06-20 21:22:31 +02:00
std : : visit ( [ this ] ( auto & & arrayIndex ) {
if ( std : : is_floating_point_v < decltype ( arrayIndex ) > )
this - > getConsole ( ) . abortEvaluation ( " cannot use float to index into array " ) ;
} , arrayIndexNode - > getValue ( ) ) ;
2021-04-21 10:17:42 +02:00
std : : visit ( [ & ] ( auto & & arrayIndex ) {
if ( arrayIndex > = 0 & & arrayIndex < arrayPattern - > getEntries ( ) . size ( ) )
currPattern = arrayPattern - > getEntries ( ) [ arrayIndex ] ;
else
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " tried to access out of bounds index {} of '{}' " , arrayIndex , currPattern - > getVariableName ( ) ) ) ;
} , arrayIndexNode - > getValue ( ) ) ;
}
else
this - > getConsole ( ) . abortEvaluation ( " tried to index into non-array type " ) ;
}
} else {
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " invalid node in rvalue path. This is a bug!' " ) ) ;
2021-04-12 20:49:37 +02:00
}
}
if ( auto pointerPattern = dynamic_cast < PatternDataPointer * > ( currPattern ) ; pointerPattern ! = nullptr )
currPattern = pointerPattern - > getPointedAtPattern ( ) ;
}
return currPattern ;
}
2021-04-21 10:17:42 +02:00
PatternData * Evaluator : : patternFromName ( const ASTNodeRValue : : Path & path ) {
2021-04-12 20:49:37 +02:00
PatternData * currPattern = nullptr ;
2021-06-20 21:22:31 +02:00
// Local variable access
currPattern = this - > findPattern ( * this - > m_localVariables . back ( ) , path ) ;
// If no local variable was found try local structure members
if ( this - > m_currMembers . size ( ) > 1 ) {
2021-06-16 21:13:54 +02:00
currPattern = this - > findPattern ( * this - > m_currMembers [ this - > m_currMembers . size ( ) - 2 ] , path ) ;
2021-06-20 21:22:31 +02:00
}
2021-04-12 20:49:37 +02:00
// If no local member was found, try globally
if ( currPattern = = nullptr ) {
currPattern = this - > findPattern ( this - > m_globalMembers , path ) ;
}
// If still no pattern was found, the path is invalid
2021-04-21 10:17:42 +02:00
if ( currPattern = = nullptr ) {
std : : string identifier ;
for ( const auto & part : path ) {
if ( part . index ( ) = = 0 ) {
// Path part is a identifier
identifier + = std : : get < std : : string > ( part ) ;
} else if ( part . index ( ) = = 1 ) {
// Path part is a array index
identifier + = " [..] " ;
}
2020-11-19 11:36:52 +01:00
2021-04-21 10:17:42 +02:00
identifier + = " . " ;
2021-01-08 20:12:16 +01:00
}
2021-04-21 10:17:42 +02:00
identifier . pop_back ( ) ;
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " no identifier with name '{}' was found " , identifier ) ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-11-19 11:36:52 +01:00
2021-04-21 10:17:42 +02:00
return currPattern ;
2021-01-20 22:54:46 +01:00
}
ASTNodeIntegerLiteral * Evaluator : : evaluateRValue ( ASTNodeRValue * node ) {
2021-04-21 10:17:42 +02:00
if ( node - > getPath ( ) . size ( ) = = 1 ) {
if ( auto part = std : : get_if < std : : string > ( & node - > getPath ( ) [ 0 ] ) ; part ! = nullptr & & * part = = " $ " )
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( this - > m_currOffset ) ;
2021-04-21 10:17:42 +02:00
}
2021-01-20 22:54:46 +01:00
auto currPattern = this - > patternFromName ( node - > getPath ( ) ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
if ( auto unsignedPattern = dynamic_cast < PatternDataUnsigned * > ( currPattern ) ; unsignedPattern ! = nullptr ) {
2021-06-20 21:22:31 +02:00
2021-01-05 14:42:08 +01:00
u8 value [ unsignedPattern - > getSize ( ) ] ;
2021-06-20 21:22:31 +02:00
if ( currPattern - > isLocal ( ) )
std : : memcpy ( value , this - > m_localStack . data ( ) + unsignedPattern - > getOffset ( ) , unsignedPattern - > getSize ( ) ) ;
else
this - > m_provider - > read ( unsignedPattern - > getOffset ( ) , value , unsignedPattern - > getSize ( ) ) ;
2021-01-05 14:42:08 +01:00
switch ( unsignedPattern - > getSize ( ) ) {
2021-06-20 21:22:31 +02:00
case 1 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < u8 * > ( value ) , 1 , unsignedPattern - > getEndian ( ) ) ) ;
case 2 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < u16 * > ( value ) , 2 , unsignedPattern - > getEndian ( ) ) ) ;
case 4 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < u32 * > ( value ) , 4 , unsignedPattern - > getEndian ( ) ) ) ;
case 8 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < u64 * > ( value ) , 8 , unsignedPattern - > getEndian ( ) ) ) ;
case 16 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < u128 * > ( value ) , 16 , unsignedPattern - > getEndian ( ) ) ) ;
2021-01-21 11:36:58 +01:00
default : this - > getConsole ( ) . abortEvaluation ( " invalid rvalue size " ) ;
2021-01-05 14:42:08 +01:00
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
} else if ( auto signedPattern = dynamic_cast < PatternDataSigned * > ( currPattern ) ; signedPattern ! = nullptr ) {
2021-02-17 21:04:59 +01:00
u8 value [ signedPattern - > getSize ( ) ] ;
2021-06-20 21:22:31 +02:00
if ( currPattern - > isLocal ( ) )
std : : memcpy ( value , this - > m_localStack . data ( ) + signedPattern - > getOffset ( ) , signedPattern - > getSize ( ) ) ;
else
this - > m_provider - > read ( signedPattern - > getOffset ( ) , value , signedPattern - > getSize ( ) ) ;
2021-01-05 14:42:08 +01:00
2021-02-17 21:04:59 +01:00
switch ( signedPattern - > getSize ( ) ) {
2021-06-20 21:22:31 +02:00
case 1 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < s8 * > ( value ) , 1 , signedPattern - > getEndian ( ) ) ) ;
case 2 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < s16 * > ( value ) , 2 , signedPattern - > getEndian ( ) ) ) ;
case 4 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < s32 * > ( value ) , 4 , signedPattern - > getEndian ( ) ) ) ;
case 8 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < s64 * > ( value ) , 8 , signedPattern - > getEndian ( ) ) ) ;
case 16 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < s128 * > ( value ) , 16 , signedPattern - > getEndian ( ) ) ) ;
2021-01-21 11:36:58 +01:00
default : this - > getConsole ( ) . abortEvaluation ( " invalid rvalue size " ) ;
2021-01-05 14:42:08 +01:00
}
2021-01-07 00:02:51 +01:00
} else if ( auto enumPattern = dynamic_cast < PatternDataEnum * > ( currPattern ) ; enumPattern ! = nullptr ) {
u8 value [ enumPattern - > getSize ( ) ] ;
2021-06-20 21:22:31 +02:00
if ( currPattern - > isLocal ( ) )
std : : memcpy ( value , this - > m_localStack . data ( ) + enumPattern - > getOffset ( ) , enumPattern - > getSize ( ) ) ;
else
this - > m_provider - > read ( enumPattern - > getOffset ( ) , value , enumPattern - > getSize ( ) ) ;
2021-01-07 00:02:51 +01:00
switch ( enumPattern - > getSize ( ) ) {
2021-06-20 21:22:31 +02:00
case 1 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < u8 * > ( value ) , 1 , enumPattern - > getEndian ( ) ) ) ;
case 2 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < u16 * > ( value ) , 2 , enumPattern - > getEndian ( ) ) ) ;
case 4 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < u32 * > ( value ) , 4 , enumPattern - > getEndian ( ) ) ) ;
case 8 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < u64 * > ( value ) , 8 , enumPattern - > getEndian ( ) ) ) ;
case 16 : return new ASTNodeIntegerLiteral ( hex : : changeEndianess ( * reinterpret_cast < u128 * > ( value ) , 16 , enumPattern - > getEndian ( ) ) ) ;
2021-01-21 11:36:58 +01:00
default : this - > getConsole ( ) . abortEvaluation ( " invalid rvalue size " ) ;
2021-01-07 00:02:51 +01:00
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
} else
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " tried to use non-integer value in numeric expression " ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-11-21 23:00:09 +01:00
2021-01-11 23:54:12 +01:00
ASTNode * Evaluator : : evaluateFunctionCall ( ASTNodeFunctionCall * node ) {
2021-01-09 21:47:11 +01:00
std : : vector < ASTNode * > evaluatedParams ;
2021-03-31 22:54:43 +02:00
ON_SCOPE_EXIT {
2021-01-07 15:37:37 +01:00
for ( auto & param : evaluatedParams )
delete param ;
2021-03-31 22:54:43 +02:00
} ;
2021-01-07 15:37:37 +01:00
2021-01-09 21:47:11 +01:00
for ( auto & param : node - > getParams ( ) ) {
if ( auto numericExpression = dynamic_cast < ASTNodeNumericExpression * > ( param ) ; numericExpression ! = nullptr )
evaluatedParams . push_back ( this - > evaluateMathematicalExpression ( numericExpression ) ) ;
2021-06-17 23:13:58 +02:00
else if ( auto typeOperatorExpression = dynamic_cast < ASTNodeTypeOperator * > ( param ) ; typeOperatorExpression ! = nullptr )
2021-04-21 10:17:42 +02:00
evaluatedParams . push_back ( this - > evaluateTypeOperator ( typeOperatorExpression ) ) ;
2021-01-09 21:47:11 +01:00
else if ( auto stringLiteral = dynamic_cast < ASTNodeStringLiteral * > ( param ) ; stringLiteral ! = nullptr )
evaluatedParams . push_back ( stringLiteral - > clone ( ) ) ;
}
2021-01-07 15:37:37 +01:00
2021-06-20 21:22:31 +02:00
ContentRegistry : : PatternLanguageFunctions : : Function * function ;
if ( this - > m_definedFunctions . contains ( node - > getFunctionName ( ) . data ( ) ) )
function = & this - > m_definedFunctions [ node - > getFunctionName ( ) . data ( ) ] ;
else if ( ContentRegistry : : PatternLanguageFunctions : : getEntries ( ) . contains ( node - > getFunctionName ( ) . data ( ) ) )
function = & ContentRegistry : : PatternLanguageFunctions : : getEntries ( ) [ node - > getFunctionName ( ) . data ( ) ] ;
else
2021-03-03 19:58:22 +01:00
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " no function named '{0}' found " , node - > getFunctionName ( ) . data ( ) ) ) ;
2021-01-07 15:37:37 +01:00
2021-06-20 21:22:31 +02:00
if ( function - > parameterCount = = ContentRegistry : : PatternLanguageFunctions : : UnlimitedParameters ) {
2021-01-07 15:37:37 +01:00
; // Don't check parameter count
}
2021-06-20 21:22:31 +02:00
else if ( function - > parameterCount & ContentRegistry : : PatternLanguageFunctions : : LessParametersThan ) {
if ( evaluatedParams . size ( ) > = ( function - > parameterCount & ~ ContentRegistry : : PatternLanguageFunctions : : LessParametersThan ) )
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " too many parameters for function '{0}'. Expected {1} " , node - > getFunctionName ( ) . data ( ) , function - > parameterCount & ~ ContentRegistry : : PatternLanguageFunctions : : LessParametersThan ) ) ;
} else if ( function - > parameterCount & ContentRegistry : : PatternLanguageFunctions : : MoreParametersThan ) {
if ( evaluatedParams . size ( ) < = ( function - > parameterCount & ~ ContentRegistry : : PatternLanguageFunctions : : MoreParametersThan ) )
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " too few parameters for function '{0}'. Expected {1} " , node - > getFunctionName ( ) . data ( ) , function - > parameterCount & ~ ContentRegistry : : PatternLanguageFunctions : : MoreParametersThan ) ) ;
} else if ( function - > parameterCount ! = evaluatedParams . size ( ) ) {
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " invalid number of parameters for function '{0}'. Expected {1} " , node - > getFunctionName ( ) . data ( ) , function - > parameterCount ) ) ;
2021-01-07 15:37:37 +01:00
}
2021-06-20 21:22:31 +02:00
return function - > func ( * this , evaluatedParams ) ;
2021-01-07 15:37:37 +01:00
}
2021-04-21 10:17:42 +02:00
ASTNodeIntegerLiteral * Evaluator : : evaluateTypeOperator ( ASTNodeTypeOperator * typeOperatorNode ) {
if ( auto rvalue = dynamic_cast < ASTNodeRValue * > ( typeOperatorNode - > getExpression ( ) ) ; rvalue ! = nullptr ) {
auto pattern = this - > patternFromName ( rvalue - > getPath ( ) ) ;
switch ( typeOperatorNode - > getOperator ( ) ) {
case Token : : Operator : : AddressOf :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( static_cast < u64 > ( pattern - > getOffset ( ) ) ) ;
2021-04-21 10:17:42 +02:00
case Token : : Operator : : SizeOf :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( static_cast < u64 > ( pattern - > getSize ( ) ) ) ;
2021-04-21 10:17:42 +02:00
default :
this - > getConsole ( ) . abortEvaluation ( " invalid type operator used. This is a bug! " ) ;
}
} else {
this - > getConsole ( ) . abortEvaluation ( " non-rvalue used in type operator " ) ;
}
}
2021-01-05 14:42:08 +01:00
# define FLOAT_BIT_OPERATION(name) \
2021-01-07 20:06:28 +01:00
auto name ( hex : : floating_point auto left , auto right ) { throw std : : runtime_error ( " " ) ; return 0 ; } \
auto name ( auto left , hex : : floating_point auto right ) { throw std : : runtime_error ( " " ) ; return 0 ; } \
auto name ( hex : : floating_point auto left , hex : : floating_point auto right ) { throw std : : runtime_error ( " " ) ; return 0 ; } \
auto name ( hex : : integral auto left , hex : : integral auto right )
2020-11-19 11:36:52 +01:00
2021-01-05 14:42:08 +01:00
namespace {
FLOAT_BIT_OPERATION ( shiftLeft ) {
return left < < right ;
}
2020-11-21 20:19:33 +01:00
2021-01-05 14:42:08 +01:00
FLOAT_BIT_OPERATION ( shiftRight ) {
return left > > right ;
}
FLOAT_BIT_OPERATION ( bitAnd ) {
return left & right ;
}
FLOAT_BIT_OPERATION ( bitOr ) {
return left | right ;
}
FLOAT_BIT_OPERATION ( bitXor ) {
return left ^ right ;
}
2021-01-07 00:41:06 +01:00
FLOAT_BIT_OPERATION ( bitNot ) {
return ~ right ;
}
2021-01-20 22:55:57 +01:00
FLOAT_BIT_OPERATION ( modulus ) {
return left % right ;
}
2021-01-05 14:42:08 +01:00
}
ASTNodeIntegerLiteral * Evaluator : : evaluateOperator ( ASTNodeIntegerLiteral * left , ASTNodeIntegerLiteral * right , Token : : Operator op ) {
try {
return std : : visit ( [ & ] ( auto & & leftValue , auto & & rightValue ) - > ASTNodeIntegerLiteral * {
switch ( op ) {
case Token : : Operator : : Plus :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue + rightValue ) ;
2021-01-05 14:42:08 +01:00
case Token : : Operator : : Minus :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue - rightValue ) ;
2021-01-05 14:42:08 +01:00
case Token : : Operator : : Star :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue * rightValue ) ;
2021-01-05 14:42:08 +01:00
case Token : : Operator : : Slash :
2021-03-02 22:55:23 +01:00
if ( rightValue = = 0 )
this - > getConsole ( ) . abortEvaluation ( " Division by zero " ) ;
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue / rightValue ) ;
2021-01-20 22:55:57 +01:00
case Token : : Operator : : Percent :
2021-03-02 22:55:23 +01:00
if ( rightValue = = 0 )
this - > getConsole ( ) . abortEvaluation ( " Division by zero " ) ;
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( modulus ( leftValue , rightValue ) ) ;
2021-01-05 14:42:08 +01:00
case Token : : Operator : : ShiftLeft :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( shiftLeft ( leftValue , rightValue ) ) ;
2021-01-05 14:42:08 +01:00
case Token : : Operator : : ShiftRight :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( shiftRight ( leftValue , rightValue ) ) ;
2021-01-05 14:42:08 +01:00
case Token : : Operator : : BitAnd :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( bitAnd ( leftValue , rightValue ) ) ;
2021-01-05 14:42:08 +01:00
case Token : : Operator : : BitXor :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( bitXor ( leftValue , rightValue ) ) ;
2021-01-05 14:42:08 +01:00
case Token : : Operator : : BitOr :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( bitOr ( leftValue , rightValue ) ) ;
2021-01-07 00:41:06 +01:00
case Token : : Operator : : BitNot :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( bitNot ( leftValue , rightValue ) ) ;
2021-01-07 00:02:51 +01:00
case Token : : Operator : : BoolEquals :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue = = rightValue ) ;
2021-01-07 00:02:51 +01:00
case Token : : Operator : : BoolNotEquals :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue ! = rightValue ) ;
2021-01-07 00:02:51 +01:00
case Token : : Operator : : BoolGreaterThan :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue > rightValue ) ;
2021-01-07 00:02:51 +01:00
case Token : : Operator : : BoolLessThan :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue < rightValue ) ;
2021-01-07 00:02:51 +01:00
case Token : : Operator : : BoolGreaterThanOrEquals :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue > = rightValue ) ;
2021-01-07 00:02:51 +01:00
case Token : : Operator : : BoolLessThanOrEquals :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue < = rightValue ) ;
2021-01-07 00:02:51 +01:00
case Token : : Operator : : BoolAnd :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue & & rightValue ) ;
2021-01-07 00:02:51 +01:00
case Token : : Operator : : BoolXor :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue & & ! rightValue | | ! leftValue & & rightValue ) ;
2021-01-07 00:02:51 +01:00
case Token : : Operator : : BoolOr :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( leftValue | | rightValue ) ;
2021-01-07 00:41:06 +01:00
case Token : : Operator : : BoolNot :
2021-06-20 21:22:31 +02:00
return new ASTNodeIntegerLiteral ( ! rightValue ) ;
2021-01-05 14:42:08 +01:00
default :
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " invalid operator used in mathematical expression " ) ;
2021-01-05 14:42:08 +01:00
}
} , left - > getValue ( ) , right - > getValue ( ) ) ;
} catch ( std : : runtime_error & e ) {
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " bitwise operations on floating point numbers are forbidden " ) ;
2021-01-05 14:42:08 +01:00
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-11-21 20:19:33 +01:00
2021-01-07 01:19:54 +01:00
ASTNodeIntegerLiteral * Evaluator : : evaluateOperand ( ASTNode * node ) {
if ( auto exprLiteral = dynamic_cast < ASTNodeIntegerLiteral * > ( node ) ; exprLiteral ! = nullptr )
return exprLiteral ;
else if ( auto exprExpression = dynamic_cast < ASTNodeNumericExpression * > ( node ) ; exprExpression ! = nullptr )
return evaluateMathematicalExpression ( exprExpression ) ;
else if ( auto exprRvalue = dynamic_cast < ASTNodeRValue * > ( node ) ; exprRvalue ! = nullptr )
return evaluateRValue ( exprRvalue ) ;
else if ( auto exprScopeResolution = dynamic_cast < ASTNodeScopeResolution * > ( node ) ; exprScopeResolution ! = nullptr )
return evaluateScopeResolution ( exprScopeResolution ) ;
else if ( auto exprTernary = dynamic_cast < ASTNodeTernaryExpression * > ( node ) ; exprTernary ! = nullptr )
return evaluateTernaryExpression ( exprTernary ) ;
2021-01-09 21:47:11 +01:00
else if ( auto exprFunctionCall = dynamic_cast < ASTNodeFunctionCall * > ( node ) ; exprFunctionCall ! = nullptr ) {
auto returnValue = evaluateFunctionCall ( exprFunctionCall ) ;
if ( returnValue = = nullptr )
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " function returning void used in expression " ) ;
2021-01-11 23:54:12 +01:00
else if ( auto integerNode = dynamic_cast < ASTNodeIntegerLiteral * > ( returnValue ) ; integerNode ! = nullptr )
return integerNode ;
2021-01-09 21:47:11 +01:00
else
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " function not returning a numeric value used in expression " ) ;
2021-04-21 10:17:42 +02:00
} else if ( auto typeOperator = dynamic_cast < ASTNodeTypeOperator * > ( node ) ; typeOperator ! = nullptr )
return evaluateTypeOperator ( typeOperator ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
else
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " invalid operand " ) ;
2021-01-07 01:19:54 +01:00
}
ASTNodeIntegerLiteral * Evaluator : : evaluateTernaryExpression ( ASTNodeTernaryExpression * node ) {
switch ( node - > getOperator ( ) ) {
case Token : : Operator : : TernaryConditional : {
auto condition = this - > evaluateOperand ( node - > getFirstOperand ( ) ) ;
2021-03-31 22:54:43 +02:00
ON_SCOPE_EXIT { delete condition ; } ;
2021-01-07 01:19:54 +01:00
if ( std : : visit ( [ ] ( auto & & value ) { return value ! = 0 ; } , condition - > getValue ( ) ) )
return this - > evaluateOperand ( node - > getSecondOperand ( ) ) ;
else
return this - > evaluateOperand ( node - > getThirdOperand ( ) ) ;
}
default :
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " invalid operator used in ternary expression " ) ;
2021-01-07 01:19:54 +01:00
}
}
ASTNodeIntegerLiteral * Evaluator : : evaluateMathematicalExpression ( ASTNodeNumericExpression * node ) {
auto leftInteger = this - > evaluateOperand ( node - > getLeftOperand ( ) ) ;
auto rightInteger = this - > evaluateOperand ( node - > getRightOperand ( ) ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
return evaluateOperator ( leftInteger , rightInteger , node - > getOperator ( ) ) ;
}
2020-12-06 22:52:15 +01:00
2021-06-20 21:22:31 +02:00
void Evaluator : : createLocalVariable ( std : : string_view varName , PatternData * pattern ) {
auto startOffset = this - > m_currOffset ;
ON_SCOPE_EXIT { this - > m_currOffset = startOffset ; } ;
auto endOfStack = this - > m_localStack . size ( ) ;
for ( auto & variable : * this - > m_localVariables . back ( ) ) {
if ( variable - > getVariableName ( ) = = varName )
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " redefinition of variable {} " , varName ) ) ;
}
this - > m_localStack . resize ( endOfStack + pattern - > getSize ( ) ) ;
pattern - > setVariableName ( std : : string ( varName ) ) ;
pattern - > setOffset ( endOfStack ) ;
pattern - > setLocal ( true ) ;
this - > m_localVariables . back ( ) - > push_back ( pattern ) ;
std : : memset ( this - > m_localStack . data ( ) + pattern - > getOffset ( ) , 0x00 , pattern - > getSize ( ) ) ;
}
void Evaluator : : setLocalVariableValue ( std : : string_view varName , const void * value , size_t size ) {
PatternData * varPattern = nullptr ;
for ( auto & var : * this - > m_localVariables . back ( ) ) {
if ( var - > getVariableName ( ) = = varName )
varPattern = var ;
}
std : : memset ( this - > m_localStack . data ( ) + varPattern - > getOffset ( ) , 0x00 , varPattern - > getSize ( ) ) ;
std : : memcpy ( this - > m_localStack . data ( ) + varPattern - > getOffset ( ) , value , std : : min ( varPattern - > getSize ( ) , size ) ) ;
}
void Evaluator : : evaluateFunctionDefinition ( ASTNodeFunctionDefinition * node ) {
ContentRegistry : : PatternLanguageFunctions : : Function function = {
( u32 ) node - > getParams ( ) . size ( ) ,
[ paramNames = node - > getParams ( ) , body = node - > getBody ( ) ] ( Evaluator & evaluator , std : : vector < ASTNode * > & params ) - > ASTNode * {
// Create local variables from parameters
std : : vector < PatternData * > localVariables ;
evaluator . m_localVariables . push_back ( & localVariables ) ;
ON_SCOPE_EXIT {
u32 stackSizeToDrop = 0 ;
for ( auto & localVar : * evaluator . m_localVariables . back ( ) ) {
stackSizeToDrop + = localVar - > getSize ( ) ;
delete localVar ;
}
evaluator . m_localVariables . pop_back ( ) ;
evaluator . m_localStack . resize ( evaluator . m_localStack . size ( ) - stackSizeToDrop ) ;
} ;
auto startOffset = evaluator . m_currOffset ;
for ( u32 i = 0 ; i < params . size ( ) ; i + + ) {
if ( auto integerLiteralNode = dynamic_cast < ASTNodeIntegerLiteral * > ( params [ i ] ) ; integerLiteralNode ! = nullptr ) {
std : : visit ( [ & ] ( auto & & value ) {
using Type = std : : remove_cvref_t < decltype ( value ) > ;
PatternData * pattern ;
if constexpr ( std : : is_unsigned_v < Type > )
pattern = new PatternDataUnsigned ( 0 , sizeof ( value ) ) ;
else if constexpr ( std : : is_signed_v < Type > )
pattern = new PatternDataSigned ( 0 , sizeof ( value ) ) ;
else if constexpr ( std : : is_floating_point_v < Type > )
pattern = new PatternDataFloat ( 0 , sizeof ( value ) ) ;
else return ;
evaluator . createLocalVariable ( paramNames [ i ] , pattern ) ;
evaluator . setLocalVariableValue ( paramNames [ i ] , & value , sizeof ( value ) ) ;
} , integerLiteralNode - > getValue ( ) ) ;
}
}
evaluator . m_currOffset = startOffset ;
for ( auto & statement : body ) {
ON_SCOPE_EXIT { evaluator . m_currOffset = startOffset ; } ;
if ( auto functionCallNode = dynamic_cast < ASTNodeFunctionCall * > ( statement ) ; functionCallNode ! = nullptr ) {
auto result = evaluator . evaluateFunctionCall ( functionCallNode ) ;
delete result ;
} else if ( auto varDeclNode = dynamic_cast < ASTNodeVariableDecl * > ( statement ) ; varDeclNode ! = nullptr ) {
auto pattern = evaluator . evaluateVariable ( varDeclNode ) ;
evaluator . createLocalVariable ( varDeclNode - > getName ( ) , pattern ) ;
} else if ( auto assignmentNode = dynamic_cast < ASTNodeAssignment * > ( statement ) ; assignmentNode ! = nullptr ) {
if ( auto numericExpressionNode = dynamic_cast < ASTNodeNumericExpression * > ( assignmentNode - > getRValue ( ) ) ; numericExpressionNode ! = nullptr ) {
auto value = evaluator . evaluateMathematicalExpression ( numericExpressionNode ) ;
ON_SCOPE_EXIT { delete value ; } ;
std : : visit ( [ & ] ( auto & & value ) {
evaluator . setLocalVariableValue ( assignmentNode - > getLValueName ( ) , & value , sizeof ( value ) ) ;
} , value - > getValue ( ) ) ;
} else {
evaluator . getConsole ( ) . abortEvaluation ( " invalid rvalue used in assignment " ) ;
}
} else if ( auto assignmentNode = dynamic_cast < ASTNodeAssignment * > ( statement ) ; assignmentNode ! = nullptr ) {
if ( auto numericExpressionNode = dynamic_cast < ASTNodeNumericExpression * > ( assignmentNode - > getRValue ( ) ) ; numericExpressionNode ! = nullptr ) {
auto value = evaluator . evaluateMathematicalExpression ( numericExpressionNode ) ;
ON_SCOPE_EXIT { delete value ; } ;
std : : visit ( [ & ] ( auto & & value ) {
evaluator . setLocalVariableValue ( assignmentNode - > getLValueName ( ) , & value , sizeof ( value ) ) ;
} , value - > getValue ( ) ) ;
} else {
evaluator . getConsole ( ) . abortEvaluation ( " invalid rvalue used in assignment " ) ;
}
} else if ( auto returnNode = dynamic_cast < ASTNodeReturnStatement * > ( statement ) ; returnNode ! = nullptr ) {
if ( auto numericExpressionNode = dynamic_cast < ASTNodeNumericExpression * > ( returnNode - > getRValue ( ) ) ; numericExpressionNode ! = nullptr ) {
return evaluator . evaluateMathematicalExpression ( numericExpressionNode ) ;
} else {
evaluator . getConsole ( ) . abortEvaluation ( " invalid rvalue used in return statement " ) ;
}
}
}
return nullptr ;
}
} ;
if ( this - > m_definedFunctions . contains ( std : : string ( node - > getName ( ) ) ) )
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " redefinition of function {} " , node - > getName ( ) ) ) ;
this - > m_definedFunctions . insert ( { std : : string ( node - > getName ( ) ) , function } ) ;
}
2021-01-21 17:49:30 +01:00
PatternData * Evaluator : : evaluateAttributes ( ASTNode * currNode , PatternData * currPattern ) {
auto attributableNode = dynamic_cast < Attributable * > ( currNode ) ;
if ( attributableNode = = nullptr )
this - > getConsole ( ) . abortEvaluation ( " attributes applied to invalid expression " ) ;
auto handleVariableAttributes = [ this , & currPattern ] ( auto attribute , auto value ) {
2021-01-21 20:55:10 +01:00
if ( attribute = = " color " & & value . has_value ( ) )
2021-02-25 12:08:46 +01:00
currPattern - > setColor ( hex : : changeEndianess ( u32 ( strtoul ( value - > data ( ) , nullptr , 16 ) ) < < 8 , std : : endian : : big ) ) ;
2021-01-21 20:55:10 +01:00
else if ( attribute = = " name " & & value . has_value ( ) )
currPattern - > setVariableName ( value - > data ( ) ) ;
else if ( attribute = = " comment " & & value . has_value ( ) )
currPattern - > setComment ( value - > data ( ) ) ;
2021-06-17 23:42:43 +02:00
else if ( attribute = = " hidden " & & value . has_value ( ) )
currPattern - > setHidden ( true ) ;
2021-01-21 17:49:30 +01:00
else
this - > getConsole ( ) . abortEvaluation ( " unknown or invalid attribute " ) ;
} ;
auto & attributes = attributableNode - > getAttributes ( ) ;
2021-01-21 20:55:10 +01:00
if ( attributes . empty ( ) )
return currPattern ;
2021-01-21 17:49:30 +01:00
if ( auto variableDeclNode = dynamic_cast < ASTNodeVariableDecl * > ( currNode ) ; variableDeclNode ! = nullptr ) {
for ( auto & attribute : attributes )
handleVariableAttributes ( attribute - > getAttribute ( ) , attribute - > getValue ( ) ) ;
} else if ( auto arrayDeclNode = dynamic_cast < ASTNodeArrayVariableDecl * > ( currNode ) ; arrayDeclNode ! = nullptr ) {
for ( auto & attribute : attributes )
handleVariableAttributes ( attribute - > getAttribute ( ) , attribute - > getValue ( ) ) ;
} else if ( auto pointerDeclNode = dynamic_cast < ASTNodePointerVariableDecl * > ( currNode ) ; pointerDeclNode ! = nullptr ) {
for ( auto & attribute : attributes )
handleVariableAttributes ( attribute - > getAttribute ( ) , attribute - > getValue ( ) ) ;
} else if ( auto structNode = dynamic_cast < ASTNodeStruct * > ( currNode ) ; structNode ! = nullptr ) {
this - > getConsole ( ) . abortEvaluation ( " unknown or invalid attribute " ) ;
} else if ( auto unionNode = dynamic_cast < ASTNodeUnion * > ( currNode ) ; unionNode ! = nullptr ) {
this - > getConsole ( ) . abortEvaluation ( " unknown or invalid attribute " ) ;
} else if ( auto enumNode = dynamic_cast < ASTNodeEnum * > ( currNode ) ; enumNode ! = nullptr ) {
this - > getConsole ( ) . abortEvaluation ( " unknown or invalid attribute " ) ;
} else if ( auto bitfieldNode = dynamic_cast < ASTNodeBitfield * > ( currNode ) ; bitfieldNode ! = nullptr ) {
this - > getConsole ( ) . abortEvaluation ( " unknown or invalid attribute " ) ;
} else
this - > getConsole ( ) . abortEvaluation ( " attributes applied to invalid expression " ) ;
return currPattern ;
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * Evaluator : : evaluateBuiltinType ( ASTNodeBuiltinType * node ) {
auto & type = node - > getType ( ) ;
auto typeSize = Token : : getTypeSize ( type ) ;
2020-11-21 20:19:33 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * pattern ;
2020-11-19 11:36:52 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
if ( type = = Token : : ValueType : : Character )
pattern = new PatternDataCharacter ( this - > m_currOffset ) ;
2021-05-02 20:13:37 +02:00
else if ( type = = Token : : ValueType : : Character16 )
pattern = new PatternDataCharacter16 ( this - > m_currOffset ) ;
2021-01-07 17:34:50 +01:00
else if ( type = = Token : : ValueType : : Boolean )
pattern = new PatternDataBoolean ( this - > m_currOffset ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
else if ( Token : : isUnsigned ( type ) )
pattern = new PatternDataUnsigned ( this - > m_currOffset , typeSize ) ;
else if ( Token : : isSigned ( type ) )
pattern = new PatternDataSigned ( this - > m_currOffset , typeSize ) ;
else if ( Token : : isFloatingPoint ( type ) )
pattern = new PatternDataFloat ( this - > m_currOffset , typeSize ) ;
2021-06-17 23:13:58 +02:00
else if ( type = = Token : : ValueType : : Padding )
pattern = new PatternDataPadding ( this - > m_currOffset , 1 ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
else
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " invalid builtin type " ) ;
2020-11-19 11:36:52 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
this - > m_currOffset + = typeSize ;
2020-12-06 21:40:57 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
pattern - > setTypeName ( Token : : getTypeName ( type ) ) ;
2021-01-08 15:03:53 +01:00
pattern - > setEndian ( this - > getCurrentEndian ( ) ) ;
2020-11-19 11:36:52 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
return pattern ;
2020-11-19 11:36:52 +01:00
}
2021-01-10 19:40:44 +01:00
void Evaluator : : evaluateMember ( ASTNode * node , std : : vector < PatternData * > & currMembers , bool increaseOffset ) {
auto startOffset = this - > m_currOffset ;
2021-01-07 00:02:51 +01:00
if ( auto memberVariableNode = dynamic_cast < ASTNodeVariableDecl * > ( node ) ; memberVariableNode ! = nullptr )
2021-01-10 19:40:44 +01:00
currMembers . push_back ( this - > evaluateVariable ( memberVariableNode ) ) ;
2021-01-07 00:02:51 +01:00
else if ( auto memberArrayNode = dynamic_cast < ASTNodeArrayVariableDecl * > ( node ) ; memberArrayNode ! = nullptr )
2021-01-10 19:40:44 +01:00
currMembers . push_back ( this - > evaluateArray ( memberArrayNode ) ) ;
2021-01-07 00:02:51 +01:00
else if ( auto memberPointerNode = dynamic_cast < ASTNodePointerVariableDecl * > ( node ) ; memberPointerNode ! = nullptr )
2021-01-10 19:40:44 +01:00
currMembers . push_back ( this - > evaluatePointer ( memberPointerNode ) ) ;
2021-01-07 00:02:51 +01:00
else if ( auto conditionalNode = dynamic_cast < ASTNodeConditionalStatement * > ( node ) ; conditionalNode ! = nullptr ) {
auto condition = this - > evaluateMathematicalExpression ( static_cast < ASTNodeNumericExpression * > ( conditionalNode - > getCondition ( ) ) ) ;
if ( std : : visit ( [ ] ( auto & & value ) { return value ! = 0 ; } , condition - > getValue ( ) ) ) {
for ( auto & statement : conditionalNode - > getTrueBody ( ) ) {
2021-01-10 19:40:44 +01:00
this - > evaluateMember ( statement , currMembers , increaseOffset ) ;
2021-01-07 00:02:51 +01:00
}
} else {
for ( auto & statement : conditionalNode - > getFalseBody ( ) ) {
2021-01-10 19:40:44 +01:00
this - > evaluateMember ( statement , currMembers , increaseOffset ) ;
2021-01-07 00:02:51 +01:00
}
}
delete condition ;
}
else
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " invalid struct member " ) ;
2021-01-10 19:40:44 +01:00
if ( ! increaseOffset )
this - > m_currOffset = startOffset ;
2021-01-07 00:02:51 +01:00
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * Evaluator : : evaluateStruct ( ASTNodeStruct * node ) {
std : : vector < PatternData * > memberPatterns ;
2021-04-12 20:49:37 +02:00
auto structPattern = new PatternDataStruct ( this - > m_currOffset , 0 ) ;
structPattern - > setParent ( this - > m_currMemberScope . back ( ) ) ;
2021-01-04 16:13:03 +01:00
this - > m_currMembers . push_back ( & memberPatterns ) ;
2021-04-12 20:49:37 +02:00
this - > m_currMemberScope . push_back ( structPattern ) ;
ON_SCOPE_EXIT {
this - > m_currMembers . pop_back ( ) ;
this - > m_currMemberScope . pop_back ( ) ;
} ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
2021-03-15 08:11:19 +01:00
this - > m_currRecursionDepth + + ;
if ( this - > m_currRecursionDepth > this - > m_recursionLimit )
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " evaluation depth exceeds maximum of {0}. Use #pragma eval_depth <depth> to increase the maximum " , this - > m_recursionLimit ) ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
auto startOffset = this - > m_currOffset ;
for ( auto & member : node - > getMembers ( ) ) {
2021-01-10 19:40:44 +01:00
this - > evaluateMember ( member , memberPatterns , true ) ;
2021-04-12 20:49:37 +02:00
structPattern - > setMembers ( memberPatterns ) ;
2020-11-27 21:20:23 +01:00
}
2021-04-12 20:49:37 +02:00
structPattern - > setSize ( this - > m_currOffset - startOffset ) ;
2020-11-20 21:29:28 +01:00
2021-03-15 08:11:19 +01:00
this - > m_currRecursionDepth - - ;
2021-04-12 20:49:37 +02:00
return this - > evaluateAttributes ( node , structPattern ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-11-22 16:22:02 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * Evaluator : : evaluateUnion ( ASTNodeUnion * node ) {
std : : vector < PatternData * > memberPatterns ;
2021-04-12 20:49:37 +02:00
auto unionPattern = new PatternDataUnion ( this - > m_currOffset , 0 ) ;
unionPattern - > setParent ( this - > m_currMemberScope . back ( ) ) ;
2021-01-04 16:13:03 +01:00
this - > m_currMembers . push_back ( & memberPatterns ) ;
2021-04-12 20:49:37 +02:00
this - > m_currMemberScope . push_back ( unionPattern ) ;
ON_SCOPE_EXIT {
this - > m_currMembers . pop_back ( ) ;
this - > m_currMemberScope . pop_back ( ) ;
} ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
auto startOffset = this - > m_currOffset ;
2020-11-20 21:29:28 +01:00
2021-03-15 08:11:19 +01:00
this - > m_currRecursionDepth + + ;
if ( this - > m_currRecursionDepth > this - > m_recursionLimit )
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " evaluation depth exceeds maximum of {0}. Use #pragma eval_depth <depth> to increase the maximum " , this - > m_recursionLimit ) ) ;
2021-01-10 19:40:44 +01:00
for ( auto & member : node - > getMembers ( ) ) {
this - > evaluateMember ( member , memberPatterns , false ) ;
2021-04-12 20:49:37 +02:00
unionPattern - > setMembers ( memberPatterns ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-11-20 21:29:28 +01:00
2021-03-15 08:11:19 +01:00
this - > m_currRecursionDepth - - ;
2021-01-10 19:40:44 +01:00
size_t size = 0 ;
for ( const auto & pattern : memberPatterns )
size = std : : max ( size , pattern - > getSize ( ) ) ;
2021-04-12 20:49:37 +02:00
unionPattern - > setSize ( size ) ;
2021-01-10 19:40:44 +01:00
2021-01-10 22:57:04 +01:00
this - > m_currOffset + = size ;
2021-04-12 20:49:37 +02:00
return this - > evaluateAttributes ( node , unionPattern ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-11-20 21:29:28 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * Evaluator : : evaluateEnum ( ASTNodeEnum * node ) {
2021-01-05 14:42:08 +01:00
std : : vector < std : : pair < Token : : IntegerLiteral , std : : string > > entryPatterns ;
2020-11-20 21:29:28 +01:00
2021-03-31 22:10:06 +02:00
auto underlyingType = dynamic_cast < ASTNodeTypeDecl * > ( node - > getUnderlyingType ( ) ) ;
if ( underlyingType = = nullptr )
this - > getConsole ( ) . abortEvaluation ( " enum underlying type was not ASTNodeTypeDecl. This is a bug " ) ;
size_t size ;
auto builtinUnderlyingType = dynamic_cast < ASTNodeBuiltinType * > ( underlyingType - > getType ( ) ) ;
if ( builtinUnderlyingType ! = nullptr )
size = Token : : getTypeSize ( builtinUnderlyingType - > getType ( ) ) ;
else
this - > getConsole ( ) . abortEvaluation ( " invalid enum underlying type " ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
auto startOffset = this - > m_currOffset ;
for ( auto & [ name , value ] : node - > getEntries ( ) ) {
auto expression = dynamic_cast < ASTNodeNumericExpression * > ( value ) ;
if ( expression = = nullptr )
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " invalid expression in enum value " ) ;
2020-11-21 23:00:09 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
auto valueNode = evaluateMathematicalExpression ( expression ) ;
2021-03-31 22:54:43 +02:00
ON_SCOPE_EXIT { delete valueNode ; } ;
2020-11-21 23:00:09 +01:00
2021-06-20 21:22:31 +02:00
entryPatterns . emplace_back ( valueNode - > getValue ( ) , name ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-11-22 16:22:02 +01:00
2021-01-10 18:24:58 +01:00
this - > m_currOffset + = size ;
2021-04-12 20:49:37 +02:00
auto enumPattern = new PatternDataEnum ( startOffset , size ) ;
enumPattern - > setSize ( size ) ;
enumPattern - > setEnumValues ( entryPatterns ) ;
return this - > evaluateAttributes ( node , enumPattern ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-11-20 21:29:28 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * Evaluator : : evaluateBitfield ( ASTNodeBitfield * node ) {
std : : vector < std : : pair < std : : string , size_t > > entryPatterns ;
2020-12-05 10:36:30 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
auto startOffset = this - > m_currOffset ;
size_t bits = 0 ;
for ( auto & [ name , value ] : node - > getEntries ( ) ) {
auto expression = dynamic_cast < ASTNodeNumericExpression * > ( value ) ;
if ( expression = = nullptr )
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " invalid expression in bitfield field size " ) ;
2020-11-21 23:00:09 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
auto valueNode = evaluateMathematicalExpression ( expression ) ;
2021-03-31 22:54:43 +02:00
ON_SCOPE_EXIT { delete valueNode ; } ;
2020-11-20 21:29:28 +01:00
2021-06-20 21:22:31 +02:00
auto fieldBits = std : : visit ( [ this ] ( auto & & value ) {
using Type = std : : remove_cvref_t < decltype ( value ) > ;
if constexpr ( std : : is_floating_point_v < Type > )
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " bitfield entry size must be an integer value " ) ;
2021-01-05 14:42:08 +01:00
return static_cast < s128 > ( value ) ;
} , valueNode - > getValue ( ) ) ;
if ( fieldBits > 64 | | fieldBits < = 0 )
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " bitfield entry must occupy between 1 and 64 bits " ) ;
2020-11-20 21:29:28 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
bits + = fieldBits ;
2020-12-06 21:40:57 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
entryPatterns . emplace_back ( name , fieldBits ) ;
2020-11-20 21:29:28 +01:00
}
2021-01-10 13:40:07 +01:00
size_t size = ( bits + 7 ) / 8 ;
this - > m_currOffset + = size ;
2021-04-12 20:49:37 +02:00
auto bitfieldPattern = new PatternDataBitfield ( startOffset , size ) ;
bitfieldPattern - > setFields ( entryPatterns ) ;
return this - > evaluateAttributes ( node , bitfieldPattern ) ;
2020-11-20 21:29:28 +01:00
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * Evaluator : : evaluateType ( ASTNodeTypeDecl * node ) {
auto type = node - > getType ( ) ;
2021-04-13 20:40:21 +02:00
if ( type = = nullptr )
type = this - > m_types [ node - > getName ( ) . data ( ) ] ;
2021-01-08 15:03:53 +01:00
this - > m_endianStack . push_back ( node - > getEndian ( ) . value_or ( this - > m_defaultDataEndian ) ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * pattern ;
if ( auto builtinTypeNode = dynamic_cast < ASTNodeBuiltinType * > ( type ) ; builtinTypeNode ! = nullptr )
return this - > evaluateBuiltinType ( builtinTypeNode ) ;
else if ( auto typeDeclNode = dynamic_cast < ASTNodeTypeDecl * > ( type ) ; typeDeclNode ! = nullptr )
pattern = this - > evaluateType ( typeDeclNode ) ;
else if ( auto structNode = dynamic_cast < ASTNodeStruct * > ( type ) ; structNode ! = nullptr )
pattern = this - > evaluateStruct ( structNode ) ;
else if ( auto unionNode = dynamic_cast < ASTNodeUnion * > ( type ) ; unionNode ! = nullptr )
pattern = this - > evaluateUnion ( unionNode ) ;
else if ( auto enumNode = dynamic_cast < ASTNodeEnum * > ( type ) ; enumNode ! = nullptr )
pattern = this - > evaluateEnum ( enumNode ) ;
else if ( auto bitfieldNode = dynamic_cast < ASTNodeBitfield * > ( type ) ; bitfieldNode ! = nullptr )
pattern = this - > evaluateBitfield ( bitfieldNode ) ;
else
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " type could not be evaluated " ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
if ( ! node - > getName ( ) . empty ( ) )
pattern - > setTypeName ( node - > getName ( ) . data ( ) ) ;
2021-01-08 16:56:39 +01:00
pattern - > setEndian ( this - > getCurrentEndian ( ) ) ;
2021-01-08 15:03:53 +01:00
this - > m_endianStack . pop_back ( ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
return pattern ;
2020-11-19 11:36:52 +01:00
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * Evaluator : : evaluateVariable ( ASTNodeVariableDecl * node ) {
2020-11-20 20:26:19 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
if ( auto offset = dynamic_cast < ASTNodeNumericExpression * > ( node - > getPlacementOffset ( ) ) ; offset ! = nullptr ) {
auto valueNode = evaluateMathematicalExpression ( offset ) ;
2021-03-31 22:54:43 +02:00
ON_SCOPE_EXIT { delete valueNode ; } ;
2020-11-20 20:26:19 +01:00
2021-06-20 21:22:31 +02:00
this - > m_currOffset = std : : visit ( [ this ] ( auto & & value ) {
using Type = std : : remove_cvref_t < decltype ( value ) > ;
if constexpr ( std : : is_floating_point_v < Type > )
this - > getConsole ( ) . abortEvaluation ( " bitfield entry size must be an integer value " ) ;
2021-01-05 14:42:08 +01:00
return static_cast < u64 > ( value ) ;
} , valueNode - > getValue ( ) ) ;
2020-11-27 21:20:23 +01:00
}
2021-04-13 21:50:24 +02:00
if ( this - > m_currOffset < this - > m_provider - > getBaseAddress ( ) | | this - > m_currOffset > = this - > m_provider - > getActualSize ( ) + this - > m_provider - > getBaseAddress ( ) ) {
if ( node - > getPlacementOffset ( ) ! = nullptr )
this - > getConsole ( ) . abortEvaluation ( " variable placed out of range " ) ;
else
return nullptr ;
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * pattern ;
if ( auto typeDecl = dynamic_cast < ASTNodeTypeDecl * > ( node - > getType ( ) ) ; typeDecl ! = nullptr )
pattern = this - > evaluateType ( typeDecl ) ;
else if ( auto builtinTypeDecl = dynamic_cast < ASTNodeBuiltinType * > ( node - > getType ( ) ) ; builtinTypeDecl ! = nullptr )
pattern = this - > evaluateBuiltinType ( builtinTypeDecl ) ;
else
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " ASTNodeVariableDecl had an invalid type. This is a bug! " ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
pattern - > setVariableName ( node - > getName ( ) . data ( ) ) ;
2021-01-21 17:49:30 +01:00
return this - > evaluateAttributes ( node , pattern ) ;
2020-11-20 20:26:19 +01:00
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * Evaluator : : evaluateArray ( ASTNodeArrayVariableDecl * node ) {
2020-11-21 20:19:33 +01:00
2021-06-17 23:13:58 +02:00
// Evaluate placement of array
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
if ( auto offset = dynamic_cast < ASTNodeNumericExpression * > ( node - > getPlacementOffset ( ) ) ; offset ! = nullptr ) {
auto valueNode = evaluateMathematicalExpression ( offset ) ;
2021-03-31 22:54:43 +02:00
ON_SCOPE_EXIT { delete valueNode ; } ;
2020-11-19 11:36:52 +01:00
2021-06-20 21:22:31 +02:00
this - > m_currOffset = std : : visit ( [ this ] ( auto & & value ) {
using Type = std : : remove_cvref_t < decltype ( value ) > ;
if constexpr ( std : : is_floating_point_v < Type > )
this - > getConsole ( ) . abortEvaluation ( " bitfield entry size must be an integer value " ) ;
2021-01-05 14:42:08 +01:00
return static_cast < u64 > ( value ) ;
} , valueNode - > getValue ( ) ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-12-06 21:40:57 +01:00
2021-06-17 23:13:58 +02:00
// Check if placed in range of the data
2021-04-13 21:50:24 +02:00
if ( this - > m_currOffset < this - > m_provider - > getBaseAddress ( ) | | this - > m_currOffset > = this - > m_provider - > getActualSize ( ) + this - > m_provider - > getBaseAddress ( ) ) {
if ( node - > getPlacementOffset ( ) ! = nullptr )
this - > getConsole ( ) . abortEvaluation ( " variable placed out of range " ) ;
else
return nullptr ;
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
auto startOffset = this - > m_currOffset ;
2020-11-19 11:36:52 +01:00
2021-06-17 23:13:58 +02:00
std : : vector < PatternData * > entries ;
std : : optional < u32 > color ;
2021-01-04 14:10:59 +01:00
2021-06-17 23:13:58 +02:00
auto addEntry = [ this , node , & entries , & color ] ( u64 index ) {
PatternData * entry ;
if ( auto typeDecl = dynamic_cast < ASTNodeTypeDecl * > ( node - > getType ( ) ) ; typeDecl ! = nullptr )
entry = this - > evaluateType ( typeDecl ) ;
else if ( auto builtinTypeDecl = dynamic_cast < ASTNodeBuiltinType * > ( node - > getType ( ) ) ; builtinTypeDecl ! = nullptr )
entry = this - > evaluateBuiltinType ( builtinTypeDecl ) ;
2021-01-07 21:16:34 +01:00
else
2021-06-17 23:13:58 +02:00
this - > getConsole ( ) . abortEvaluation ( " ASTNodeVariableDecl had an invalid type. This is a bug! " ) ;
entry - > setVariableName ( hex : : format ( " [{0}] " , index ) ) ;
entry - > setEndian ( this - > getCurrentEndian ( ) ) ;
if ( ! color . has_value ( ) )
color = entry - > getColor ( ) ;
entry - > setColor ( color . value_or ( 0 ) ) ;
2020-11-21 20:19:33 +01:00
2021-06-17 23:13:58 +02:00
if ( this - > m_currOffset > this - > m_provider - > getActualSize ( ) + this - > m_provider - > getBaseAddress ( ) ) {
delete entry ;
return ;
}
entries . push_back ( entry ) ;
} ;
auto sizeNode = node - > getSize ( ) ;
if ( auto numericExpression = dynamic_cast < ASTNodeNumericExpression * > ( sizeNode ) ; numericExpression ! = nullptr ) {
// Parse explicit size of array
auto valueNode = this - > evaluateMathematicalExpression ( numericExpression ) ;
2021-03-31 22:54:43 +02:00
ON_SCOPE_EXIT { delete valueNode ; } ;
2020-11-21 20:19:33 +01:00
2021-06-20 21:22:31 +02:00
auto arraySize = std : : visit ( [ this ] ( auto & & value ) {
using Type = std : : remove_cvref_t < decltype ( value ) > ;
if constexpr ( std : : is_floating_point_v < Type > )
this - > getConsole ( ) . abortEvaluation ( " bitfield entry size must be an integer value " ) ;
2021-01-07 21:16:34 +01:00
return static_cast < u64 > ( value ) ;
} , valueNode - > getValue ( ) ) ;
2020-11-19 11:36:52 +01:00
2021-06-17 23:13:58 +02:00
for ( u64 i = 0 ; i < arraySize ; i + + ) {
addEntry ( i ) ;
}
} else if ( auto whileLoopExpression = dynamic_cast < ASTNodeWhileStatement * > ( sizeNode ) ; whileLoopExpression ! = nullptr ) {
// Parse while loop based size of array
auto conditionNode = this - > evaluateMathematicalExpression ( static_cast < ASTNodeNumericExpression * > ( whileLoopExpression - > getCondition ( ) ) ) ;
ON_SCOPE_EXIT { delete conditionNode ; } ;
u64 index = 0 ;
while ( std : : visit ( [ ] ( auto & & value ) { return value ! = 0 ; } , conditionNode - > getValue ( ) ) ) {
addEntry ( index ) ;
index + + ;
delete conditionNode ;
conditionNode = this - > evaluateMathematicalExpression ( static_cast < ASTNodeNumericExpression * > ( whileLoopExpression - > getCondition ( ) ) ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2021-01-07 21:16:34 +01:00
} else {
2021-06-17 23:13:58 +02:00
// Parse unsized array
2021-05-02 20:13:37 +02:00
if ( auto typeDecl = dynamic_cast < ASTNodeTypeDecl * > ( node - > getType ( ) ) ; typeDecl ! = nullptr ) {
if ( auto builtinType = dynamic_cast < ASTNodeBuiltinType * > ( typeDecl - > getType ( ) ) ; builtinType ! = nullptr ) {
std : : vector < u8 > bytes ( Token : : getTypeSize ( builtinType - > getType ( ) ) , 0x00 ) ;
u64 offset = startOffset ;
2021-06-17 23:13:58 +02:00
u64 index = 0 ;
2021-05-02 20:13:37 +02:00
do {
this - > m_provider - > read ( offset , bytes . data ( ) , bytes . size ( ) ) ;
offset + = bytes . size ( ) ;
2021-06-17 23:13:58 +02:00
addEntry ( index ) ;
index + + ;
2021-05-02 20:13:37 +02:00
} while ( ! std : : all_of ( bytes . begin ( ) , bytes . end ( ) , [ ] ( u8 byte ) { return byte = = 0x00 ; } ) & & offset < this - > m_provider - > getSize ( ) ) ;
}
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-12-06 21:40:57 +01:00
2021-06-17 23:13:58 +02:00
auto deleteEntries = SCOPE_GUARD {
for ( auto & entry : entries )
2021-04-13 21:50:24 +02:00
delete entry ;
2021-06-17 23:13:58 +02:00
} ;
2020-11-19 11:36:52 +01:00
2021-06-17 23:13:58 +02:00
if ( auto typeDecl = dynamic_cast < ASTNodeTypeDecl * > ( node - > getType ( ) ) ; typeDecl ! = nullptr ) {
if ( auto builtinType = dynamic_cast < ASTNodeBuiltinType * > ( typeDecl - > getType ( ) ) ; builtinType ! = nullptr ) {
if ( builtinType - > getType ( ) = = Token : : ValueType : : Padding )
return new PatternDataPadding ( startOffset , this - > m_currOffset - startOffset ) ;
}
2020-11-19 11:36:52 +01:00
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * pattern ;
2021-06-17 23:13:58 +02:00
if ( entries . empty ( ) )
2021-01-04 16:25:03 +01:00
pattern = new PatternDataPadding ( startOffset , 0 ) ;
2021-05-02 20:13:37 +02:00
else if ( dynamic_cast < PatternDataCharacter * > ( entries [ 0 ] ) ! = nullptr )
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
pattern = new PatternDataString ( startOffset , ( this - > m_currOffset - startOffset ) , color . value_or ( 0 ) ) ;
2021-05-02 20:13:37 +02:00
else if ( dynamic_cast < PatternDataCharacter16 * > ( entries [ 0 ] ) ! = nullptr )
pattern = new PatternDataString16 ( startOffset , ( this - > m_currOffset - startOffset ) , color . value_or ( 0 ) ) ;
2021-01-07 21:16:34 +01:00
else {
if ( node - > getSize ( ) = = nullptr )
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " no bounds provided for array " ) ;
2021-04-12 20:49:37 +02:00
auto arrayPattern = new PatternDataArray ( startOffset , ( this - > m_currOffset - startOffset ) , color . value_or ( 0 ) ) ;
arrayPattern - > setEntries ( entries ) ;
2021-06-17 23:13:58 +02:00
deleteEntries . release ( ) ;
2021-04-12 20:49:37 +02:00
pattern = arrayPattern ;
2021-01-07 21:16:34 +01:00
}
2020-11-19 11:36:52 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
pattern - > setVariableName ( node - > getName ( ) . data ( ) ) ;
2020-11-19 11:36:52 +01:00
2021-01-21 17:49:30 +01:00
return this - > evaluateAttributes ( node , pattern ) ;
2020-11-19 11:36:52 +01:00
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * Evaluator : : evaluatePointer ( ASTNodePointerVariableDecl * node ) {
s128 pointerOffset ;
if ( auto offset = dynamic_cast < ASTNodeNumericExpression * > ( node - > getPlacementOffset ( ) ) ; offset ! = nullptr ) {
auto valueNode = evaluateMathematicalExpression ( offset ) ;
2021-03-31 22:54:43 +02:00
ON_SCOPE_EXIT { delete valueNode ; } ;
2020-11-19 11:36:52 +01:00
2021-06-20 21:22:31 +02:00
pointerOffset = std : : visit ( [ this ] ( auto & & value ) {
using Type = std : : remove_cvref_t < decltype ( value ) > ;
if constexpr ( std : : is_floating_point_v < Type > )
this - > getConsole ( ) . abortEvaluation ( " bitfield entry size must be an integer value " ) ;
2021-01-05 14:42:08 +01:00
return static_cast < s128 > ( value ) ;
} , valueNode - > getValue ( ) ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
this - > m_currOffset = pointerOffset ;
} else {
pointerOffset = this - > m_currOffset ;
2020-11-19 11:36:52 +01:00
}
2021-04-13 21:50:24 +02:00
if ( this - > m_currOffset < this - > m_provider - > getBaseAddress ( ) | | this - > m_currOffset > = this - > m_provider - > getActualSize ( ) + this - > m_provider - > getBaseAddress ( ) ) {
if ( node - > getPlacementOffset ( ) ! = nullptr )
this - > getConsole ( ) . abortEvaluation ( " variable placed out of range " ) ;
else
return nullptr ;
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
PatternData * sizeType ;
2021-01-08 16:56:39 +01:00
auto underlyingType = dynamic_cast < ASTNodeTypeDecl * > ( node - > getSizeType ( ) ) ;
if ( underlyingType = = nullptr )
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " underlying type is not ASTNodeTypeDecl. This is a bug " ) ;
2021-01-08 16:56:39 +01:00
if ( auto builtinTypeNode = dynamic_cast < ASTNodeBuiltinType * > ( underlyingType - > getType ( ) ) ; builtinTypeNode ! = nullptr ) {
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
sizeType = evaluateBuiltinType ( builtinTypeNode ) ;
} else
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " pointer size is not a builtin type " ) ;
2020-11-19 11:36:52 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
size_t pointerSize = sizeType - > getSize ( ) ;
2020-11-19 11:36:52 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
u128 pointedAtOffset = 0 ;
2021-04-16 21:50:15 +02:00
this - > m_provider - > read ( pointerOffset , & pointedAtOffset , pointerSize ) ;
2021-01-08 16:56:39 +01:00
this - > m_currOffset = hex : : changeEndianess ( pointedAtOffset , pointerSize , underlyingType - > getEndian ( ) . value_or ( this - > m_defaultDataEndian ) ) ;
delete sizeType ;
2020-11-19 11:36:52 +01:00
2021-01-08 15:03:53 +01:00
2021-04-13 21:50:24 +02:00
if ( this - > m_currOffset > this - > m_provider - > getActualSize ( ) + this - > m_provider - > getBaseAddress ( ) )
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " pointer points past the end of the data " ) ;
2021-01-08 15:03:53 +01:00
PatternData * pointedAt ;
if ( auto typeDecl = dynamic_cast < ASTNodeTypeDecl * > ( node - > getType ( ) ) ; typeDecl ! = nullptr )
pointedAt = this - > evaluateType ( typeDecl ) ;
else if ( auto builtinTypeDecl = dynamic_cast < ASTNodeBuiltinType * > ( node - > getType ( ) ) ; builtinTypeDecl ! = nullptr )
pointedAt = this - > evaluateBuiltinType ( builtinTypeDecl ) ;
else
2021-01-21 11:36:58 +01:00
this - > getConsole ( ) . abortEvaluation ( " ASTNodeVariableDecl had an invalid type. This is a bug! " ) ;
2021-01-08 15:03:53 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
this - > m_currOffset = pointerOffset + pointerSize ;
2020-11-19 11:36:52 +01:00
2021-04-12 20:49:37 +02:00
auto pattern = new PatternDataPointer ( pointerOffset , pointerSize ) ;
2021-01-08 15:03:53 +01:00
pattern - > setVariableName ( node - > getName ( ) . data ( ) ) ;
pattern - > setEndian ( this - > getCurrentEndian ( ) ) ;
2021-04-12 20:49:37 +02:00
pattern - > setPointedAtPattern ( pointedAt ) ;
2021-01-08 15:03:53 +01:00
2021-01-21 17:49:30 +01:00
return this - > evaluateAttributes ( node , pattern ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-11-19 11:36:52 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
std : : optional < std : : vector < PatternData * > > Evaluator : : evaluate ( const std : : vector < ASTNode * > & ast ) {
2020-11-19 11:36:52 +01:00
2021-01-23 14:00:09 +01:00
this - > m_globalMembers . clear ( ) ;
this - > m_types . clear ( ) ;
this - > m_endianStack . clear ( ) ;
2021-06-20 21:22:31 +02:00
this - > m_definedFunctions . clear ( ) ;
2021-01-23 14:00:09 +01:00
this - > m_currOffset = 0 ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
try {
2021-04-13 20:40:21 +02:00
for ( const auto & node : ast ) {
if ( auto typeDeclNode = dynamic_cast < ASTNodeTypeDecl * > ( node ) ; typeDeclNode ! = nullptr ) {
if ( this - > m_types [ typeDeclNode - > getName ( ) . data ( ) ] = = nullptr )
this - > m_types [ typeDeclNode - > getName ( ) . data ( ) ] = typeDeclNode - > getType ( ) ;
}
}
for ( const auto & [ name , node ] : this - > m_types ) {
if ( auto typeDeclNode = static_cast < ASTNodeTypeDecl * > ( node ) ; typeDeclNode - > getType ( ) = = nullptr )
this - > getConsole ( ) . abortEvaluation ( hex : : format ( " unresolved type '{}' " , name ) ) ;
}
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
for ( const auto & node : ast ) {
2021-04-12 20:49:37 +02:00
this - > m_currMembers . clear ( ) ;
this - > m_currMemberScope . clear ( ) ;
this - > m_currMemberScope . push_back ( nullptr ) ;
2021-01-08 15:03:53 +01:00
this - > m_endianStack . push_back ( this - > m_defaultDataEndian ) ;
2021-03-07 13:20:33 +01:00
this - > m_currRecursionDepth = 0 ;
2020-11-19 11:36:52 +01:00
2021-04-13 21:50:24 +02:00
PatternData * pattern = nullptr ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
if ( auto variableDeclNode = dynamic_cast < ASTNodeVariableDecl * > ( node ) ; variableDeclNode ! = nullptr ) {
2021-04-13 21:50:24 +02:00
pattern = this - > evaluateVariable ( variableDeclNode ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
} else if ( auto arrayDeclNode = dynamic_cast < ASTNodeArrayVariableDecl * > ( node ) ; arrayDeclNode ! = nullptr ) {
2021-04-13 21:50:24 +02:00
pattern = this - > evaluateArray ( arrayDeclNode ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
} else if ( auto pointerDeclNode = dynamic_cast < ASTNodePointerVariableDecl * > ( node ) ; pointerDeclNode ! = nullptr ) {
2021-04-13 21:50:24 +02:00
pattern = this - > evaluatePointer ( pointerDeclNode ) ;
2021-01-06 16:28:41 +01:00
} else if ( auto typeDeclNode = dynamic_cast < ASTNodeTypeDecl * > ( node ) ; typeDeclNode ! = nullptr ) {
2021-04-13 20:40:21 +02:00
// Handled above
2021-01-09 21:47:11 +01:00
} else if ( auto functionCallNode = dynamic_cast < ASTNodeFunctionCall * > ( node ) ; functionCallNode ! = nullptr ) {
auto result = this - > evaluateFunctionCall ( functionCallNode ) ;
delete result ;
2021-06-20 21:22:31 +02:00
} else if ( auto functionDefNode = dynamic_cast < ASTNodeFunctionDefinition * > ( node ) ; functionDefNode ! = nullptr ) {
this - > evaluateFunctionDefinition ( functionDefNode ) ;
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
}
2020-11-19 11:36:52 +01:00
2021-04-13 21:50:24 +02:00
if ( pattern ! = nullptr )
this - > m_globalMembers . push_back ( pattern ) ;
2021-01-10 17:14:38 +01:00
this - > m_endianStack . clear ( ) ;
2020-11-19 11:36:52 +01:00
}
2021-01-21 11:36:58 +01:00
} catch ( LogConsole : : EvaluateError & e ) {
this - > getConsole ( ) . log ( LogConsole : : Level : : Error , e ) ;
2021-01-08 15:03:53 +01:00
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 20:27:11 +01:00
return { } ;
2020-11-19 11:36:52 +01:00
}
2021-01-08 17:37:05 +01:00
return this - > m_globalMembers ;
2020-11-19 11:36:52 +01:00
}
}