2020-11-19 10:36:52 +00:00
# include "lang/evaluator.hpp"
2020-12-27 14:54:12 +00:00
# include "lang/token.hpp"
2021-01-07 00:56:15 +00:00
# include "helpers/utils.hpp"
2021-01-11 22:54:12 +00:00
# include "helpers/content_registry.hpp"
2020-12-27 14:54:12 +00:00
2020-11-20 19:26:19 +00: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 19:27:11 +00:00
# include <algorithm>
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
# include <unistd.h>
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
namespace hex : : lang {
2020-12-06 20:40:57 +00: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 19:27:11 +00:00
Evaluator : : Evaluator ( prv : : Provider * & provider , std : : endian defaultDataEndian )
: m_provider ( provider ) , m_defaultDataEndian ( defaultDataEndian ) {
2021-01-07 14:37:37 +00:00
2021-01-11 22:54:12 +00:00
this - > registerBuiltinFunctions ( ) ;
2020-11-19 10:36:52 +00:00
}
2021-01-06 15:28:41 +00: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-09 22:48:42 +00:00
throwEvaluateError ( " failed to find identifier " ) ;
2021-01-06 15:28:41 +00: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 19:27:11 +00:00
ASTNodeIntegerLiteral * Evaluator : : evaluateRValue ( ASTNodeRValue * node ) {
2021-01-08 16:37:05 +00:00
if ( this - > m_currMembers . empty ( ) & & this - > m_globalMembers . empty ( ) )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " no variables available " ) ;
2020-11-19 10:36:52 +00:00
2021-01-08 16:37:05 +00:00
std : : vector < PatternData * > currMembers ;
if ( ! this - > m_currMembers . empty ( ) )
std : : copy ( this - > m_currMembers . back ( ) - > begin ( ) , this - > m_currMembers . back ( ) - > end ( ) , std : : back_inserter ( currMembers ) ) ;
if ( ! this - > m_globalMembers . empty ( ) )
std : : copy ( this - > m_globalMembers . begin ( ) , this - > m_globalMembers . end ( ) , std : : back_inserter ( currMembers ) ) ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
PatternData * currPattern = nullptr ;
2021-01-08 19:12:16 +00:00
for ( u32 i = 0 ; i < node - > getPath ( ) . size ( ) ; i + + ) {
const auto & identifier = node - > getPath ( ) [ i ] ;
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 19:27:11 +00:00
if ( auto structPattern = dynamic_cast < PatternDataStruct * > ( currPattern ) ; structPattern ! = nullptr )
2021-01-08 16:37:05 +00:00
currMembers = structPattern - > getMembers ( ) ;
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 19:27:11 +00:00
else if ( auto unionPattern = dynamic_cast < PatternDataUnion * > ( currPattern ) ; unionPattern ! = nullptr )
2021-01-08 16:37:05 +00:00
currMembers = unionPattern - > getMembers ( ) ;
2021-01-08 19:12:16 +00:00
else if ( auto pointerPattern = dynamic_cast < PatternDataPointer * > ( currPattern ) ; pointerPattern ! = nullptr ) {
currPattern = pointerPattern - > getPointedAtPattern ( ) ;
i - - ;
continue ;
}
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 19:27:11 +00:00
else if ( currPattern ! = nullptr )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " tried to access member of a non-struct/union type " ) ;
2020-11-19 10:36:52 +00:00
2021-01-08 16:37:05 +00:00
auto candidate = std : : find_if ( currMembers . begin ( ) , currMembers . end ( ) , [ & ] ( auto member ) {
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 19:27:11 +00:00
return member - > getVariableName ( ) = = identifier ;
} ) ;
2020-11-22 15:22:02 +00:00
2021-01-08 16:37:05 +00:00
if ( candidate ! = currMembers . end ( ) )
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 19:27:11 +00:00
currPattern = * candidate ;
2020-11-21 22:00:09 +00:00
else
2021-01-09 22:48:42 +00:00
throwEvaluateError ( hex : : format ( " could not find identifier '%s' " , identifier . c_str ( ) ) ) ;
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 19:27:11 +00:00
}
2020-11-19 10:36:52 +00:00
2021-01-08 19:12:16 +00:00
if ( auto pointerPattern = dynamic_cast < PatternDataPointer * > ( currPattern ) ; pointerPattern ! = nullptr )
currPattern = pointerPattern - > getPointedAtPattern ( ) ;
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 19:27:11 +00:00
if ( auto unsignedPattern = dynamic_cast < PatternDataUnsigned * > ( currPattern ) ; unsignedPattern ! = nullptr ) {
2021-01-05 13:42:08 +00:00
u8 value [ unsignedPattern - > getSize ( ) ] ;
this - > m_provider - > read ( unsignedPattern - > getOffset ( ) , value , unsignedPattern - > getSize ( ) ) ;
switch ( unsignedPattern - > getSize ( ) ) {
2021-01-10 16:18:14 +00:00
case 1 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Unsigned8Bit , hex : : changeEndianess ( * reinterpret_cast < u8 * > ( value ) , 1 , unsignedPattern - > getEndian ( ) ) } ) ;
case 2 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Unsigned16Bit , hex : : changeEndianess ( * reinterpret_cast < u16 * > ( value ) , 2 , unsignedPattern - > getEndian ( ) ) } ) ;
case 4 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Unsigned32Bit , hex : : changeEndianess ( * reinterpret_cast < u32 * > ( value ) , 4 , unsignedPattern - > getEndian ( ) ) } ) ;
case 8 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Unsigned64Bit , hex : : changeEndianess ( * reinterpret_cast < u64 * > ( value ) , 8 , unsignedPattern - > getEndian ( ) ) } ) ;
case 16 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Unsigned128Bit , hex : : changeEndianess ( * reinterpret_cast < u128 * > ( value ) , 16 , unsignedPattern - > getEndian ( ) ) } ) ;
2021-01-09 22:48:42 +00:00
default : throwEvaluateError ( " invalid rvalue size " ) ;
2021-01-05 13:42:08 +00: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 19:27:11 +00:00
} else if ( auto signedPattern = dynamic_cast < PatternDataSigned * > ( currPattern ) ; signedPattern ! = nullptr ) {
2021-01-05 13:42:08 +00:00
u8 value [ unsignedPattern - > getSize ( ) ] ;
this - > m_provider - > read ( signedPattern - > getOffset ( ) , value , signedPattern - > getSize ( ) ) ;
switch ( unsignedPattern - > getSize ( ) ) {
2021-01-10 16:18:14 +00:00
case 1 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Signed8Bit , hex : : changeEndianess ( * reinterpret_cast < s8 * > ( value ) , 1 , signedPattern - > getEndian ( ) ) } ) ;
case 2 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Signed16Bit , hex : : changeEndianess ( * reinterpret_cast < s16 * > ( value ) , 2 , signedPattern - > getEndian ( ) ) } ) ;
case 4 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Signed32Bit , hex : : changeEndianess ( * reinterpret_cast < s32 * > ( value ) , 4 , signedPattern - > getEndian ( ) ) } ) ;
case 8 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Signed64Bit , hex : : changeEndianess ( * reinterpret_cast < s64 * > ( value ) , 8 , signedPattern - > getEndian ( ) ) } ) ;
case 16 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Signed128Bit , hex : : changeEndianess ( * reinterpret_cast < s128 * > ( value ) , 16 , signedPattern - > getEndian ( ) ) } ) ;
2021-01-09 22:48:42 +00:00
default : throwEvaluateError ( " invalid rvalue size " ) ;
2021-01-05 13:42:08 +00:00
}
2021-01-06 23:02:51 +00:00
} else if ( auto enumPattern = dynamic_cast < PatternDataEnum * > ( currPattern ) ; enumPattern ! = nullptr ) {
u8 value [ enumPattern - > getSize ( ) ] ;
this - > m_provider - > read ( enumPattern - > getOffset ( ) , value , enumPattern - > getSize ( ) ) ;
switch ( enumPattern - > getSize ( ) ) {
2021-01-10 16:18:14 +00:00
case 1 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Unsigned8Bit , hex : : changeEndianess ( * reinterpret_cast < u8 * > ( value ) , 1 , enumPattern - > getEndian ( ) ) } ) ;
case 2 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Unsigned16Bit , hex : : changeEndianess ( * reinterpret_cast < u16 * > ( value ) , 2 , enumPattern - > getEndian ( ) ) } ) ;
case 4 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Unsigned32Bit , hex : : changeEndianess ( * reinterpret_cast < u32 * > ( value ) , 4 , enumPattern - > getEndian ( ) ) } ) ;
case 8 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Unsigned64Bit , hex : : changeEndianess ( * reinterpret_cast < u64 * > ( value ) , 8 , enumPattern - > getEndian ( ) ) } ) ;
case 16 : return new ASTNodeIntegerLiteral ( { Token : : ValueType : : Unsigned128Bit , hex : : changeEndianess ( * reinterpret_cast < u128 * > ( value ) , 16 , enumPattern - > getEndian ( ) ) } ) ;
2021-01-09 22:48:42 +00:00
default : throwEvaluateError ( " invalid rvalue size " ) ;
2021-01-06 23:02:51 +00: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 19:27:11 +00:00
} else
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " 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 19:27:11 +00:00
}
2020-11-21 22:00:09 +00:00
2021-01-11 22:54:12 +00:00
ASTNode * Evaluator : : evaluateFunctionCall ( ASTNodeFunctionCall * node ) {
2021-01-09 20:47:11 +00:00
std : : vector < ASTNode * > evaluatedParams ;
2021-01-07 14:37:37 +00:00
ScopeExit paramCleanup ( [ & ] {
for ( auto & param : evaluatedParams )
delete param ;
} ) ;
2021-01-09 20:47:11 +00:00
for ( auto & param : node - > getParams ( ) ) {
if ( auto numericExpression = dynamic_cast < ASTNodeNumericExpression * > ( param ) ; numericExpression ! = nullptr )
evaluatedParams . push_back ( this - > evaluateMathematicalExpression ( numericExpression ) ) ;
else if ( auto stringLiteral = dynamic_cast < ASTNodeStringLiteral * > ( param ) ; stringLiteral ! = nullptr )
evaluatedParams . push_back ( stringLiteral - > clone ( ) ) ;
}
2021-01-07 14:37:37 +00:00
2021-01-11 22:54:12 +00:00
if ( ! ContentRegistry : : PatternLanguageFunctions : : getEntries ( ) . contains ( node - > getFunctionName ( ) . data ( ) ) )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( hex : : format ( " no function named '%s' found " , node - > getFunctionName ( ) . data ( ) ) ) ;
2021-01-07 14:37:37 +00:00
2021-01-11 22:54:12 +00:00
auto & function = ContentRegistry : : PatternLanguageFunctions : : getEntries ( ) [ node - > getFunctionName ( ) . data ( ) ] ;
2021-01-07 14:37:37 +00:00
2021-01-11 22:54:12 +00:00
if ( function . parameterCount = = ContentRegistry : : PatternLanguageFunctions : : UnlimitedParameters ) {
2021-01-07 14:37:37 +00:00
; // Don't check parameter count
}
2021-01-11 22:54:12 +00:00
else if ( function . parameterCount & ContentRegistry : : PatternLanguageFunctions : : LessParametersThan ) {
if ( evaluatedParams . size ( ) > = ( function . parameterCount & ~ ContentRegistry : : PatternLanguageFunctions : : LessParametersThan ) )
throwEvaluateError ( hex : : format ( " too many parameters for function '%s'. Expected %d " , node - > getFunctionName ( ) . data ( ) , function . parameterCount & ~ ContentRegistry : : PatternLanguageFunctions : : LessParametersThan ) ) ;
} else if ( function . parameterCount & ContentRegistry : : PatternLanguageFunctions : : MoreParametersThan ) {
if ( evaluatedParams . size ( ) < = ( function . parameterCount & ~ ContentRegistry : : PatternLanguageFunctions : : MoreParametersThan ) )
throwEvaluateError ( hex : : format ( " too few parameters for function '%s'. Expected %d " , node - > getFunctionName ( ) . data ( ) , function . parameterCount & ~ ContentRegistry : : PatternLanguageFunctions : : MoreParametersThan ) ) ;
2021-01-07 14:37:37 +00:00
} else if ( function . parameterCount ! = evaluatedParams . size ( ) ) {
2021-01-09 22:48:42 +00:00
throwEvaluateError ( hex : : format ( " invalid number of parameters for function '%s'. Expected %d " , node - > getFunctionName ( ) . data ( ) , function . parameterCount ) ) ;
2021-01-07 14:37:37 +00:00
}
return function . func ( evaluatedParams ) ;
}
2021-01-05 13:42:08 +00:00
# define FLOAT_BIT_OPERATION(name) \
2021-01-07 19:06:28 +00: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 10:36:52 +00:00
2021-01-05 13:42:08 +00:00
namespace {
FLOAT_BIT_OPERATION ( shiftLeft ) {
return left < < right ;
}
2020-11-21 19:19:33 +00:00
2021-01-05 13:42:08 +00: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-06 23:41:06 +00:00
FLOAT_BIT_OPERATION ( bitNot ) {
return ~ right ;
}
2021-01-05 13:42:08 +00:00
}
ASTNodeIntegerLiteral * Evaluator : : evaluateOperator ( ASTNodeIntegerLiteral * left , ASTNodeIntegerLiteral * right , Token : : Operator op ) {
auto newType = [ & ] {
# define CHECK_TYPE(type) if (left->getType() == (type) || right->getType() == (type)) return (type)
# define DEFAULT_TYPE(type) return (type)
2021-01-09 23:40:57 +00:00
if ( left - > getType ( ) = = Token : : ValueType : : Any & & right - > getType ( ) ! = Token : : ValueType : : Any )
return right - > getType ( ) ;
if ( left - > getType ( ) ! = Token : : ValueType : : Any & & right - > getType ( ) = = Token : : ValueType : : Any )
return left - > getType ( ) ;
2021-01-05 13:42:08 +00:00
CHECK_TYPE ( Token : : ValueType : : Double ) ;
CHECK_TYPE ( Token : : ValueType : : Float ) ;
CHECK_TYPE ( Token : : ValueType : : Unsigned128Bit ) ;
CHECK_TYPE ( Token : : ValueType : : Signed128Bit ) ;
CHECK_TYPE ( Token : : ValueType : : Unsigned64Bit ) ;
CHECK_TYPE ( Token : : ValueType : : Signed64Bit ) ;
CHECK_TYPE ( Token : : ValueType : : Unsigned32Bit ) ;
CHECK_TYPE ( Token : : ValueType : : Signed32Bit ) ;
CHECK_TYPE ( Token : : ValueType : : Unsigned16Bit ) ;
CHECK_TYPE ( Token : : ValueType : : Signed16Bit ) ;
CHECK_TYPE ( Token : : ValueType : : Unsigned8Bit ) ;
CHECK_TYPE ( Token : : ValueType : : Signed8Bit ) ;
CHECK_TYPE ( Token : : ValueType : : Character ) ;
2021-01-09 23:40:57 +00:00
CHECK_TYPE ( Token : : ValueType : : Boolean ) ;
2021-01-05 13:42:08 +00:00
DEFAULT_TYPE ( Token : : ValueType : : Signed32Bit ) ;
# undef CHECK_TYPE
# undef DEFAULT_TYPE
} ( ) ;
try {
return std : : visit ( [ & ] ( auto & & leftValue , auto & & rightValue ) - > ASTNodeIntegerLiteral * {
switch ( op ) {
case Token : : Operator : : Plus :
return new ASTNodeIntegerLiteral ( { newType , leftValue + rightValue } ) ;
case Token : : Operator : : Minus :
return new ASTNodeIntegerLiteral ( { newType , leftValue - rightValue } ) ;
case Token : : Operator : : Star :
return new ASTNodeIntegerLiteral ( { newType , leftValue * rightValue } ) ;
case Token : : Operator : : Slash :
return new ASTNodeIntegerLiteral ( { newType , leftValue / rightValue } ) ;
case Token : : Operator : : ShiftLeft :
return new ASTNodeIntegerLiteral ( { newType , shiftLeft ( leftValue , rightValue ) } ) ;
case Token : : Operator : : ShiftRight :
return new ASTNodeIntegerLiteral ( { newType , shiftRight ( leftValue , rightValue ) } ) ;
case Token : : Operator : : BitAnd :
return new ASTNodeIntegerLiteral ( { newType , bitAnd ( leftValue , rightValue ) } ) ;
case Token : : Operator : : BitXor :
return new ASTNodeIntegerLiteral ( { newType , bitXor ( leftValue , rightValue ) } ) ;
case Token : : Operator : : BitOr :
return new ASTNodeIntegerLiteral ( { newType , bitOr ( leftValue , rightValue ) } ) ;
2021-01-06 23:41:06 +00:00
case Token : : Operator : : BitNot :
return new ASTNodeIntegerLiteral ( { newType , bitNot ( leftValue , rightValue ) } ) ;
2021-01-06 23:02:51 +00:00
case Token : : Operator : : BoolEquals :
return new ASTNodeIntegerLiteral ( { newType , leftValue = = rightValue } ) ;
case Token : : Operator : : BoolNotEquals :
return new ASTNodeIntegerLiteral ( { newType , leftValue ! = rightValue } ) ;
case Token : : Operator : : BoolGreaterThan :
return new ASTNodeIntegerLiteral ( { newType , leftValue > rightValue } ) ;
case Token : : Operator : : BoolLessThan :
return new ASTNodeIntegerLiteral ( { newType , leftValue < rightValue } ) ;
case Token : : Operator : : BoolGreaterThanOrEquals :
return new ASTNodeIntegerLiteral ( { newType , leftValue > = rightValue } ) ;
case Token : : Operator : : BoolLessThanOrEquals :
return new ASTNodeIntegerLiteral ( { newType , leftValue < = rightValue } ) ;
case Token : : Operator : : BoolAnd :
return new ASTNodeIntegerLiteral ( { newType , leftValue & & rightValue } ) ;
case Token : : Operator : : BoolXor :
return new ASTNodeIntegerLiteral ( { newType , leftValue & & ! rightValue | | ! leftValue & & rightValue } ) ;
case Token : : Operator : : BoolOr :
return new ASTNodeIntegerLiteral ( { newType , leftValue | | rightValue } ) ;
2021-01-06 23:41:06 +00:00
case Token : : Operator : : BoolNot :
return new ASTNodeIntegerLiteral ( { newType , ! rightValue } ) ;
2021-01-05 13:42:08 +00:00
default :
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " invalid operator used in mathematical expression " ) ;
2021-01-05 13:42:08 +00:00
}
} , left - > getValue ( ) , right - > getValue ( ) ) ;
} catch ( std : : runtime_error & e ) {
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " bitwise operations on floating point numbers are forbidden " ) ;
2021-01-05 13:42:08 +00: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 19:27:11 +00:00
}
2020-11-21 19:19:33 +00:00
2021-01-07 00:19:54 +00: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 20:47:11 +00:00
else if ( auto exprFunctionCall = dynamic_cast < ASTNodeFunctionCall * > ( node ) ; exprFunctionCall ! = nullptr ) {
auto returnValue = evaluateFunctionCall ( exprFunctionCall ) ;
if ( returnValue = = nullptr )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " function returning void used in expression " ) ;
2021-01-11 22:54:12 +00:00
else if ( auto integerNode = dynamic_cast < ASTNodeIntegerLiteral * > ( returnValue ) ; integerNode ! = nullptr )
return integerNode ;
2021-01-09 20:47:11 +00:00
else
2021-01-11 22:54:12 +00:00
throwEvaluateError ( " function not returning a numeric value used in expression " ) ;
2021-01-09 20:47:11 +00: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 19:27:11 +00:00
else
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " invalid operand " ) ;
2021-01-07 00:19:54 +00:00
}
ASTNodeIntegerLiteral * Evaluator : : evaluateTernaryExpression ( ASTNodeTernaryExpression * node ) {
switch ( node - > getOperator ( ) ) {
case Token : : Operator : : TernaryConditional : {
auto condition = this - > evaluateOperand ( node - > getFirstOperand ( ) ) ;
SCOPE_EXIT ( delete condition ; ) ;
if ( std : : visit ( [ ] ( auto & & value ) { return value ! = 0 ; } , condition - > getValue ( ) ) )
return this - > evaluateOperand ( node - > getSecondOperand ( ) ) ;
else
return this - > evaluateOperand ( node - > getThirdOperand ( ) ) ;
}
default :
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " invalid operator used in ternary expression " ) ;
2021-01-07 00:19:54 +00: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 19:27:11 +00:00
return evaluateOperator ( leftInteger , rightInteger , node - > getOperator ( ) ) ;
}
2020-12-06 21:52:15 +00: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 19:27:11 +00:00
PatternData * Evaluator : : evaluateBuiltinType ( ASTNodeBuiltinType * node ) {
auto & type = node - > getType ( ) ;
auto typeSize = Token : : getTypeSize ( type ) ;
2020-11-21 19:19:33 +00: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 19:27:11 +00:00
PatternData * pattern ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
if ( type = = Token : : ValueType : : Character )
pattern = new PatternDataCharacter ( this - > m_currOffset ) ;
2021-01-07 16:34:50 +00: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 19:27:11 +00: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 ) ;
else
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " invalid builtin type " ) ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
this - > m_currOffset + = typeSize ;
2020-12-06 20:40:57 +00: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 19:27:11 +00:00
pattern - > setTypeName ( Token : : getTypeName ( type ) ) ;
2021-01-08 14:03:53 +00:00
pattern - > setEndian ( this - > getCurrentEndian ( ) ) ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
return pattern ;
2020-11-19 10:36:52 +00:00
}
2021-01-10 18:40:44 +00:00
void Evaluator : : evaluateMember ( ASTNode * node , std : : vector < PatternData * > & currMembers , bool increaseOffset ) {
auto startOffset = this - > m_currOffset ;
2021-01-06 23:02:51 +00:00
if ( auto memberVariableNode = dynamic_cast < ASTNodeVariableDecl * > ( node ) ; memberVariableNode ! = nullptr )
2021-01-10 18:40:44 +00:00
currMembers . push_back ( this - > evaluateVariable ( memberVariableNode ) ) ;
2021-01-06 23:02:51 +00:00
else if ( auto memberArrayNode = dynamic_cast < ASTNodeArrayVariableDecl * > ( node ) ; memberArrayNode ! = nullptr )
2021-01-10 18:40:44 +00:00
currMembers . push_back ( this - > evaluateArray ( memberArrayNode ) ) ;
2021-01-06 23:02:51 +00:00
else if ( auto memberPointerNode = dynamic_cast < ASTNodePointerVariableDecl * > ( node ) ; memberPointerNode ! = nullptr )
2021-01-10 18:40:44 +00:00
currMembers . push_back ( this - > evaluatePointer ( memberPointerNode ) ) ;
2021-01-06 23:02:51 +00: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 18:40:44 +00:00
this - > evaluateMember ( statement , currMembers , increaseOffset ) ;
2021-01-06 23:02:51 +00:00
}
} else {
for ( auto & statement : conditionalNode - > getFalseBody ( ) ) {
2021-01-10 18:40:44 +00:00
this - > evaluateMember ( statement , currMembers , increaseOffset ) ;
2021-01-06 23:02:51 +00:00
}
}
delete condition ;
}
else
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " invalid struct member " ) ;
2021-01-10 18:40:44 +00:00
if ( ! increaseOffset )
this - > m_currOffset = startOffset ;
2021-01-06 23:02:51 +00: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 19:27:11 +00:00
PatternData * Evaluator : : evaluateStruct ( ASTNodeStruct * node ) {
std : : vector < PatternData * > memberPatterns ;
2021-01-04 15:13:03 +00:00
this - > m_currMembers . push_back ( & memberPatterns ) ;
SCOPE_EXIT ( this - > m_currMembers . 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 19:27:11 +00:00
auto startOffset = this - > m_currOffset ;
for ( auto & member : node - > getMembers ( ) ) {
2021-01-10 18:40:44 +00:00
this - > evaluateMember ( member , memberPatterns , true ) ;
2020-11-27 20:20:23 +00:00
}
2020-11-20 20:29:28 +00: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 19:27:11 +00:00
return new PatternDataStruct ( startOffset , this - > m_currOffset - startOffset , memberPatterns ) ;
}
2020-11-22 15:22:02 +00: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 19:27:11 +00:00
PatternData * Evaluator : : evaluateUnion ( ASTNodeUnion * node ) {
std : : vector < PatternData * > memberPatterns ;
2021-01-04 15:13:03 +00:00
this - > m_currMembers . push_back ( & memberPatterns ) ;
SCOPE_EXIT ( this - > m_currMembers . 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 19:27:11 +00:00
auto startOffset = this - > m_currOffset ;
2020-11-20 20:29:28 +00:00
2021-01-10 18:40:44 +00:00
for ( auto & member : node - > getMembers ( ) ) {
this - > evaluateMember ( member , memberPatterns , false ) ;
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 19:27:11 +00:00
}
2020-11-20 20:29:28 +00:00
2021-01-10 18:40:44 +00:00
size_t size = 0 ;
for ( const auto & pattern : memberPatterns )
size = std : : max ( size , pattern - > getSize ( ) ) ;
2021-01-10 21:57:04 +00:00
this - > m_currOffset + = size ;
2021-01-10 18:40:44 +00:00
return new PatternDataUnion ( startOffset , size , 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 19:27:11 +00:00
}
2020-11-20 20:29:28 +00: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 19:27:11 +00:00
PatternData * Evaluator : : evaluateEnum ( ASTNodeEnum * node ) {
2021-01-05 13:42:08 +00:00
std : : vector < std : : pair < Token : : IntegerLiteral , std : : string > > entryPatterns ;
2020-11-20 20:29:28 +00: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 19:27:11 +00:00
auto startOffset = this - > m_currOffset ;
for ( auto & [ name , value ] : node - > getEntries ( ) ) {
auto expression = dynamic_cast < ASTNodeNumericExpression * > ( value ) ;
if ( expression = = nullptr )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " invalid expression in enum value " ) ;
2020-11-21 22:00:09 +00: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 19:27:11 +00:00
auto valueNode = evaluateMathematicalExpression ( expression ) ;
SCOPE_EXIT ( delete valueNode ; ) ;
2020-11-21 22:00:09 +00:00
2021-01-05 13:42:08 +00:00
entryPatterns . push_back ( { { valueNode - > getType ( ) , 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 19:27:11 +00:00
}
2020-11-22 15:22:02 +00:00
2021-01-10 16:14:38 +00:00
auto underlyingType = dynamic_cast < ASTNodeTypeDecl * > ( node - > getUnderlyingType ( ) ) ;
if ( underlyingType = = nullptr )
throwEvaluateError ( " enum underlying type was not ASTNodeTypeDecl. 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 19:27:11 +00:00
size_t size ;
2021-01-10 16:14:38 +00:00
if ( auto builtinType = dynamic_cast < ASTNodeBuiltinType * > ( underlyingType - > getType ( ) ) ; builtinType ! = nullptr )
size = Token : : getTypeSize ( builtinType - > getType ( ) ) ;
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 19:27:11 +00:00
else
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " invalid enum underlying type " ) ;
2020-11-22 15:22:02 +00:00
2021-01-10 17:24:58 +00:00
this - > m_currOffset + = size ;
2021-01-10 16:14:38 +00:00
return new PatternDataEnum ( startOffset , size , entryPatterns ) ; ;
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 19:27:11 +00:00
}
2020-11-20 20:29:28 +00: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 19:27:11 +00:00
PatternData * Evaluator : : evaluateBitfield ( ASTNodeBitfield * node ) {
std : : vector < std : : pair < std : : string , size_t > > entryPatterns ;
2020-12-05 09:36:30 +00: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 19:27:11 +00: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-09 22:48:42 +00:00
throwEvaluateError ( " invalid expression in bitfield field size " ) ;
2020-11-21 22:00:09 +00: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 19:27:11 +00:00
auto valueNode = evaluateMathematicalExpression ( expression ) ;
SCOPE_EXIT ( delete valueNode ; ) ;
2020-11-20 20:29:28 +00:00
2021-01-05 13:42:08 +00:00
auto fieldBits = std : : visit ( [ node , type = valueNode - > getType ( ) ] ( auto & & value ) {
if ( Token : : isFloatingPoint ( type ) )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " bitfield entry size must be an integer value " ) ;
2021-01-05 13:42:08 +00:00
return static_cast < s128 > ( value ) ;
} , valueNode - > getValue ( ) ) ;
if ( fieldBits > 64 | | fieldBits < = 0 )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " bitfield entry must occupy between 1 and 64 bits " ) ;
2020-11-20 20:29:28 +00: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 19:27:11 +00:00
bits + = fieldBits ;
2020-12-06 20:40:57 +00: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 19:27:11 +00:00
entryPatterns . emplace_back ( name , fieldBits ) ;
2020-11-20 20:29:28 +00:00
}
2021-01-10 12:40:07 +00:00
size_t size = ( bits + 7 ) / 8 ;
this - > m_currOffset + = size ;
return new PatternDataBitfield ( startOffset , size , entryPatterns ) ;
2020-11-20 20:29:28 +00: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 19:27:11 +00:00
PatternData * Evaluator : : evaluateType ( ASTNodeTypeDecl * node ) {
auto type = node - > getType ( ) ;
2021-01-08 14:03:53 +00: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 19:27:11 +00: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-09 22:48:42 +00:00
throwEvaluateError ( " 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 19:27:11 +00:00
if ( ! node - > getName ( ) . empty ( ) )
pattern - > setTypeName ( node - > getName ( ) . data ( ) ) ;
2021-01-08 15:56:39 +00:00
pattern - > setEndian ( this - > getCurrentEndian ( ) ) ;
2021-01-08 14:03:53 +00: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 19:27:11 +00:00
return pattern ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
PatternData * Evaluator : : evaluateVariable ( ASTNodeVariableDecl * node ) {
2020-11-20 19:26:19 +00: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 19:27:11 +00:00
if ( auto offset = dynamic_cast < ASTNodeNumericExpression * > ( node - > getPlacementOffset ( ) ) ; offset ! = nullptr ) {
auto valueNode = evaluateMathematicalExpression ( offset ) ;
SCOPE_EXIT ( delete valueNode ; ) ;
2020-11-20 19:26:19 +00:00
2021-01-05 13:42:08 +00:00
this - > m_currOffset = std : : visit ( [ node , type = valueNode - > getType ( ) ] ( auto & & value ) {
if ( Token : : isFloatingPoint ( type ) )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " placement offset must be an integer value " ) ;
2021-01-05 13:42:08 +00:00
return static_cast < u64 > ( value ) ;
} , valueNode - > getValue ( ) ) ;
2020-11-27 20:20:23 +00: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 19:27:11 +00:00
if ( this - > m_currOffset > = this - > m_provider - > getActualSize ( ) )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " variable placed out of range " ) ;
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 19:27:11 +00: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-09 22:48:42 +00:00
throwEvaluateError ( " 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 19:27:11 +00:00
pattern - > setVariableName ( node - > getName ( ) . data ( ) ) ;
return pattern ;
2020-11-20 19:26:19 +00: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 19:27:11 +00:00
PatternData * Evaluator : : evaluateArray ( ASTNodeArrayVariableDecl * node ) {
2020-11-21 19:19:33 +00: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 19:27:11 +00:00
if ( auto offset = dynamic_cast < ASTNodeNumericExpression * > ( node - > getPlacementOffset ( ) ) ; offset ! = nullptr ) {
auto valueNode = evaluateMathematicalExpression ( offset ) ;
SCOPE_EXIT ( delete valueNode ; ) ;
2020-11-19 10:36:52 +00:00
2021-01-05 13:42:08 +00:00
this - > m_currOffset = std : : visit ( [ node , type = valueNode - > getType ( ) ] ( auto & & value ) {
if ( Token : : isFloatingPoint ( type ) )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " placement offset must be an integer value " ) ;
2021-01-05 13:42:08 +00: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 19:27:11 +00:00
}
2020-12-06 20:40:57 +00: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 19:27:11 +00:00
auto startOffset = this - > m_currOffset ;
2020-11-19 10:36:52 +00:00
2021-01-04 13:10:59 +00:00
ASTNodeIntegerLiteral * valueNode ;
2021-01-07 20:16:34 +00:00
u64 arraySize = 0 ;
2021-01-04 13:10:59 +00:00
2021-01-07 20:16:34 +00:00
if ( node - > getSize ( ) ! = nullptr ) {
if ( auto sizeNumericExpression = dynamic_cast < ASTNodeNumericExpression * > ( node - > getSize ( ) ) ; sizeNumericExpression ! = nullptr )
valueNode = evaluateMathematicalExpression ( sizeNumericExpression ) ;
else
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " array size not a numeric expression " ) ;
2020-11-21 19:19:33 +00:00
2021-01-07 20:16:34 +00:00
SCOPE_EXIT ( delete valueNode ; ) ;
2020-11-21 19:19:33 +00:00
2021-01-07 20:16:34 +00:00
arraySize = std : : visit ( [ node , type = valueNode - > getType ( ) ] ( auto & & value ) {
if ( Token : : isFloatingPoint ( type ) )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " array size must be an integer value " ) ;
2021-01-07 20:16:34 +00:00
return static_cast < u64 > ( value ) ;
} , valueNode - > getValue ( ) ) ;
2020-11-19 10:36:52 +00:00
2021-01-07 20:16:34 +00: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 ) {
this - > m_currOffset + = arraySize ;
return new PatternDataPadding ( startOffset , arraySize ) ;
}
2020-12-06 20:40:57 +00: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 19:27:11 +00:00
}
2021-01-07 20:16:34 +00:00
} else {
u8 currByte = 0x00 ;
u64 offset = startOffset ;
do {
this - > m_provider - > read ( offset , & currByte , sizeof ( u8 ) ) ;
offset + = sizeof ( u8 ) ;
arraySize + = sizeof ( u8 ) ;
} while ( currByte ! = 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 19:27:11 +00:00
}
2020-12-06 20:40:57 +00: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 19:27:11 +00:00
std : : vector < PatternData * > entries ;
std : : optional < u32 > color ;
for ( s128 i = 0 ; i < arraySize ; i + + ) {
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 ) ;
}
else
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " ASTNodeVariableDecl had an invalid type. This is a bug! " ) ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
entry - > setVariableName ( hex : : format ( " [%llu] " , ( u64 ) i ) ) ;
entry - > setEndian ( this - > getCurrentEndian ( ) ) ;
2020-11-21 19:19:33 +00: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 19:27:11 +00:00
if ( ! color . has_value ( ) )
color = entry - > getColor ( ) ;
entry - > setColor ( color . value_or ( 0 ) ) ;
2020-11-21 19:19:33 +00: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 19:27:11 +00:00
entries . push_back ( entry ) ;
2020-11-19 10:36:52 +00:00
2021-01-10 21:52:12 +00:00
if ( this - > m_currOffset > this - > m_provider - > getActualSize ( ) )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " array exceeds size of file " ) ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
PatternData * pattern ;
2021-01-07 20:16:34 +00:00
if ( entries . empty ( ) ) {
2021-01-04 15:25:03 +00:00
pattern = new PatternDataPadding ( startOffset , 0 ) ;
2021-01-07 20:16:34 +00:00
}
2021-01-04 15:25:03 +00:00
else if ( dynamic_cast < PatternDataCharacter * > ( entries [ 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 19:27:11 +00:00
pattern = new PatternDataString ( startOffset , ( this - > m_currOffset - startOffset ) , color . value_or ( 0 ) ) ;
2021-01-07 20:16:34 +00:00
else {
if ( node - > getSize ( ) = = nullptr )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " no bounds provided for 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 19:27:11 +00:00
pattern = new PatternDataArray ( startOffset , ( this - > m_currOffset - startOffset ) , entries , color . value_or ( 0 ) ) ;
2021-01-07 20:16:34 +00:00
}
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
pattern - > setVariableName ( node - > getName ( ) . data ( ) ) ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
return pattern ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
PatternData * Evaluator : : evaluatePointer ( ASTNodePointerVariableDecl * node ) {
s128 pointerOffset ;
if ( auto offset = dynamic_cast < ASTNodeNumericExpression * > ( node - > getPlacementOffset ( ) ) ; offset ! = nullptr ) {
auto valueNode = evaluateMathematicalExpression ( offset ) ;
SCOPE_EXIT ( delete valueNode ; ) ;
2020-11-19 10:36:52 +00:00
2021-01-05 13:42:08 +00:00
pointerOffset = std : : visit ( [ node , type = valueNode - > getType ( ) ] ( auto & & value ) {
if ( Token : : isFloatingPoint ( type ) )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " pointer offset must be an integer value " ) ;
2021-01-05 13:42:08 +00: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 19:27:11 +00:00
this - > m_currOffset = pointerOffset ;
} else {
pointerOffset = this - > m_currOffset ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
PatternData * sizeType ;
2021-01-08 15:56:39 +00:00
auto underlyingType = dynamic_cast < ASTNodeTypeDecl * > ( node - > getSizeType ( ) ) ;
if ( underlyingType = = nullptr )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " underlying type is not ASTNodeTypeDecl. This is a bug " ) ;
2021-01-08 15:56:39 +00: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 19:27:11 +00:00
sizeType = evaluateBuiltinType ( builtinTypeNode ) ;
} else
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " pointer size is not a builtin type " ) ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
size_t pointerSize = sizeType - > getSize ( ) ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
u128 pointedAtOffset = 0 ;
this - > m_provider - > read ( pointerOffset , & pointedAtOffset , pointerSize ) ;
2021-01-08 15:56:39 +00:00
this - > m_currOffset = hex : : changeEndianess ( pointedAtOffset , pointerSize , underlyingType - > getEndian ( ) . value_or ( this - > m_defaultDataEndian ) ) ;
delete sizeType ;
2020-11-19 10:36:52 +00:00
2021-01-08 14:03:53 +00:00
if ( this - > m_currOffset > this - > m_provider - > getActualSize ( ) )
2021-01-09 22:48:42 +00:00
throwEvaluateError ( " pointer points past the end of the data " ) ;
2021-01-08 14:03:53 +00: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-09 22:48:42 +00:00
throwEvaluateError ( " ASTNodeVariableDecl had an invalid type. This is a bug! " ) ;
2021-01-08 14:03:53 +00: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 19:27:11 +00:00
this - > m_currOffset = pointerOffset + pointerSize ;
2020-11-19 10:36:52 +00:00
2021-01-08 14:03:53 +00:00
auto pattern = new PatternDataPointer ( pointerOffset , pointerSize , pointedAt ) ;
pattern - > setVariableName ( node - > getName ( ) . data ( ) ) ;
pattern - > setEndian ( this - > getCurrentEndian ( ) ) ;
return 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 19:27:11 +00:00
}
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
std : : optional < std : : vector < PatternData * > > Evaluator : : evaluate ( const std : : vector < ASTNode * > & ast ) {
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
try {
for ( const auto & node : ast ) {
2021-01-08 14:03:53 +00:00
this - > m_endianStack . push_back ( this - > m_defaultDataEndian ) ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
if ( auto variableDeclNode = dynamic_cast < ASTNodeVariableDecl * > ( node ) ; variableDeclNode ! = nullptr ) {
2021-01-08 16:37:05 +00:00
this - > m_globalMembers . push_back ( 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 19:27:11 +00:00
} else if ( auto arrayDeclNode = dynamic_cast < ASTNodeArrayVariableDecl * > ( node ) ; arrayDeclNode ! = nullptr ) {
2021-01-08 16:37:05 +00:00
this - > m_globalMembers . push_back ( 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 19:27:11 +00:00
} else if ( auto pointerDeclNode = dynamic_cast < ASTNodePointerVariableDecl * > ( node ) ; pointerDeclNode ! = nullptr ) {
2021-01-08 16:37:05 +00:00
this - > m_globalMembers . push_back ( this - > evaluatePointer ( pointerDeclNode ) ) ;
2021-01-06 15:28:41 +00:00
} else if ( auto typeDeclNode = dynamic_cast < ASTNodeTypeDecl * > ( node ) ; typeDeclNode ! = nullptr ) {
this - > m_types [ typeDeclNode - > getName ( ) . data ( ) ] = typeDeclNode - > getType ( ) ;
2021-01-09 20:47:11 +00:00
} else if ( auto functionCallNode = dynamic_cast < ASTNodeFunctionCall * > ( node ) ; functionCallNode ! = nullptr ) {
auto result = this - > evaluateFunctionCall ( functionCallNode ) ;
delete result ;
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 19:27:11 +00:00
}
2020-11-19 10:36:52 +00:00
2021-01-10 16:14:38 +00:00
this - > m_endianStack . clear ( ) ;
2020-11-19 10:36:52 +00: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 19:27:11 +00:00
} catch ( EvaluateError & e ) {
2021-01-09 22:48:42 +00:00
this - > m_consoleLog . emplace_back ( ConsoleLogLevel : : Error , e ) ;
2021-01-08 14:03:53 +00:00
this - > m_endianStack . clear ( ) ;
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 19:27:11 +00:00
return { } ;
2020-11-19 10:36:52 +00:00
}
2021-01-08 14:03:53 +00:00
this - > m_endianStack . clear ( ) ;
2020-11-19 10:36:52 +00:00
2021-01-08 16:37:05 +00:00
return this - > m_globalMembers ;
2020-11-19 10:36:52 +00:00
}
}