From 0d9e6d4166aaee92db6403b1e84967bd13fcfd79 Mon Sep 17 00:00:00 2001 From: payetvin <113102157+payetvin@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:01:41 +0100 Subject: [PATCH] Modeler 4.4: expression parsing [ANT-2313] (#2471) This pull request includes several updates and improvements to the ANTLR grammar and related files for the `Expr` language. The changes involve modifications to the grammar rules, updates to the CMake configuration, and synchronization with a newer version of ANTLR. ### Grammar and Parsing Improvements: * Refactored `Expr.g4` grammar to introduce new rules and improve parsing capabilities, including the addition of `atom`, `shift_expr`, and `right_expr` rules. [[1]](diffhunk://#diff-9904320a1807a7a3514cd161403920248cbde82e6c2dbc9cf855c5c134dd62dcL20-R68) [[2]](diffhunk://#diff-9904320a1807a7a3514cd161403920248cbde82e6c2dbc9cf855c5c134dd62dcL45-L48) * Updated `Expr.tokens` to reflect new token definitions and changes in the grammar. * Removed redundant rules and tokens from `Expr.g4` and `Expr.tokens`. [[1]](diffhunk://#diff-9904320a1807a7a3514cd161403920248cbde82e6c2dbc9cf855c5c134dd62dcL45-L48) [[2]](diffhunk://#diff-cb10c1b9428e9e48c48e524757dfc48dcc6ae8dd2ad921eff65851cbc3c2e5c1L10-R30) ### Build Configuration Updates: * Updated `sonar-project.properties` to exclude `src/libs/antares/antlr-interface` from Sonar analysis. antlr-interface contains generated code that trigger defect in analysis * Modified `CMakeLists.txt` to always include the `antlr-interface` directory and removed conditional logic for building with ANTLR4. [[1]](diffhunk://#diff-148715d6ea0c0ea0a346af3f6bd610d010d490eca35ac6a9b408748f7ca9e3f4L186-L188) [[2]](diffhunk://#diff-148715d6ea0c0ea0a346af3f6bd610d010d490eca35ac6a9b408748f7ca9e3f4R194-R195) [[3]](diffhunk://#diff-9e299f60c14464c86511d6c9a4e7c081765abb4840b57ea4dc25238311006ce9L31-L33) ### Synchronization with ANTLR 4.13.2: * Updated generated files to be compatible with ANTLR 4.13.2, including `ExprBaseVisitor.cpp`, `ExprBaseVisitor.h`, and `ExprLexer.cpp`. [[1]](diffhunk://#diff-bda2e00a884ff4b113d535c8239b493bfc88c5c4f1d38c4687c2f28e44cdfde8L2-R2) [[2]](diffhunk://#diff-abcc97c1794721be0f33a540339645ac1d5d9d3dd6cbe941235200bad3dcacb9L2-R2) [[3]](diffhunk://#diff-6adabe5fce15f2c6367db67aa33a2e02bb220796c9ff4e143160752a637ca3c0L2-R2) * Adjusted `ExprLexer.cpp` to use `std::unique_ptr` for static data initialization. [[1]](diffhunk://#diff-6adabe5fce15f2c6367db67aa33a2e02bb220796c9ff4e143160752a637ca3c0L48-R48) [[2]](diffhunk://#diff-6adabe5fce15f2c6367db67aa33a2e02bb220796c9ff4e143160752a637ca3c0L61-R62) ### Visitor Pattern Enhancements: * Updated `ExprBaseVisitor` to include new visit methods for the added grammar rules. [[1]](diffhunk://#diff-abcc97c1794721be0f33a540339645ac1d5d9d3dd6cbe941235200bad3dcacb9L22-R57) [[2]](diffhunk://#diff-abcc97c1794721be0f33a540339645ac1d5d9d3dd6cbe941235200bad3dcacb9L58-R106) These changes collectively enhance the flexibility and maintainability of the grammar and build configuration, while ensuring compatibility with the latest ANTLR version. --------- Co-authored-by: Abdoulbari Zaher <32519851+a-zakir@users.noreply.github.com> Co-authored-by: Florian OMNES <26088210+flomnes@users.noreply.github.com> Co-authored-by: Florian OMNES --- sonar-project.properties | 16 +- src/CMakeLists.txt | 5 +- src/libs/antares/CMakeLists.txt | 4 +- .../antares/antlr-interface/CMakeLists.txt | 1 - src/libs/antares/antlr-interface/Expr.g4 | 66 +- src/libs/antares/antlr-interface/Expr.interp | 31 +- src/libs/antares/antlr-interface/Expr.tokens | 38 +- .../antlr-interface/ExprBaseVisitor.cpp | 2 +- .../antares/antlr-interface/ExprBaseVisitor.h | 50 +- .../antares/antlr-interface/ExprLexer.cpp | 85 +- src/libs/antares/antlr-interface/ExprLexer.h | 6 +- .../antares/antlr-interface/ExprLexer.interp | 33 +- .../antares/antlr-interface/ExprLexer.tokens | 38 +- .../antares/antlr-interface/ExprParser.cpp | 1163 +++++++++++------ src/libs/antares/antlr-interface/ExprParser.h | 236 +++- .../antares/antlr-interface/ExprVisitor.cpp | 2 +- .../antares/antlr-interface/ExprVisitor.h | 34 +- src/solver/expressions/CMakeLists.txt | 5 +- src/solver/expressions/NodeRegistry.cpp | 14 + .../antares/solver/expressions/NodeRegistry.h | 22 + .../antares/solver/expressions/Registry.hxx | 7 +- .../expressions/visitors/AstDOTStyleVisitor.h | 3 +- .../solver/expressions/visitors/NodeVisitor.h | 23 +- .../visitors/AstDOTStyleVisitor.cpp | 2 +- .../expressions/visitors/EvalVisitor.cpp | 1 + .../expressions/visitors/NodeVisitor.cpp | 46 + src/solver/modelConverter/CMakeLists.txt | 6 +- .../modelConverter/convertorVisitor.cpp | 297 +++++ .../solver/modelConverter/convertorVisitor.h | 32 + .../solver/modelConverter/modelConverter.h | 16 +- src/solver/modelConverter/modelConverter.cpp | 88 +- src/study/system-model/CMakeLists.txt | 1 + .../antares/study/system-model/constraint.h | 2 +- .../antares/study/system-model/expression.h | 13 +- .../antares/study/system-model/library.h | 7 +- .../antares/study/system-model/model.h | 12 +- .../antares/study/system-model/parameter.h | 8 - .../antares/study/system-model/variable.h | 8 +- src/study/system-model/library.cpp | 4 +- src/study/system-model/model.cpp | 6 +- src/tests/src/libs/antares/CMakeLists.txt | 5 +- .../src/solver/modelParser/CMakeLists.txt | 5 +- .../modelParser/testConvertorVisitor.cpp | 228 ++++ .../modelParser/testModelTranslator.cpp | 75 +- .../src/solver/modelParser/test_full.cpp | 144 +- src/vcpkg.json | 3 + 46 files changed, 2068 insertions(+), 825 deletions(-) create mode 100644 src/solver/expressions/NodeRegistry.cpp create mode 100644 src/solver/expressions/include/antares/solver/expressions/NodeRegistry.h create mode 100644 src/solver/expressions/visitors/NodeVisitor.cpp create mode 100644 src/solver/modelConverter/convertorVisitor.cpp create mode 100644 src/solver/modelConverter/include/antares/solver/modelConverter/convertorVisitor.h create mode 100644 src/tests/src/solver/modelParser/testConvertorVisitor.cpp diff --git a/sonar-project.properties b/sonar-project.properties index 7a7aaca2e6..0c74bd252a 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -9,7 +9,19 @@ sonar.projectVersion=9.2.0 sonar.sources=src sonar.tests=src/tests sonar.sourceEncoding=UTF-8 -sonar.exclusions=src/ext/**,src/tests/**,src/ui/** -sonar.coverage.exclusions=src/ext/**,src/tests/**,src/analyzer/**,src/distrib/**,src/tools/**,src/ui/** + +sonar.exclusions=src/ext/**,\ + src/tests/**,\ + src/ui/**,\ + src/libs/antares/antlr-interface/** + +sonar.coverage.exclusions=src/ext/**,\ + src/tests/**,\ + src/analyzer/**,\ + src/distrib/**,\ + src/tools/**,\ + src/ui/**,\ + src/libs/antares/antlr-interface/** + sonar.coverageReportPaths=coverage.xml sonar.cfamily.threads=4 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56533d676a..e1fca9a3d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -183,9 +183,6 @@ message(STATUS "Build antares tools: ${BUILD_TOOLS}") option(BUILD_ORTOOLS "Build OR-Tools" OFF) message(STATUS "Build OR-Tools: ${BUILD_ORTOOLS}") -option(WITH_ANTLR4 "With antlr4" OFF) -message(STATUS "With antlr4: ${WITH_ANTLR4}") - option(BUILD_MERSENNE_TWISTER_PYBIND11 "Build pybind11 bindings for Mersenne-Twister" OFF) if (${BUILD_MERSENNE_TWISTER_PYBIND11}) find_package(pybind11 REQUIRED) @@ -194,6 +191,8 @@ endif() #Boost header libraries find_package(Boost REQUIRED) +find_package(antlr4-runtime REQUIRED) + #Sirius solver if(POLICY CMP0074) cmake_policy(SET CMP0074 NEW) diff --git a/src/libs/antares/CMakeLists.txt b/src/libs/antares/CMakeLists.txt index 5b4f253052..c06632cd29 100644 --- a/src/libs/antares/CMakeLists.txt +++ b/src/libs/antares/CMakeLists.txt @@ -28,9 +28,7 @@ add_subdirectory(study-loader) add_subdirectory(sys) add_subdirectory(utils) add_subdirectory(writer) -if(WITH_ANTLR4) - add_subdirectory(antlr-interface) -endif() +add_subdirectory(antlr-interface) add_subdirectory(optimization-options) diff --git a/src/libs/antares/antlr-interface/CMakeLists.txt b/src/libs/antares/antlr-interface/CMakeLists.txt index 4cd06fef3b..727ec96d0e 100644 --- a/src/libs/antares/antlr-interface/CMakeLists.txt +++ b/src/libs/antares/antlr-interface/CMakeLists.txt @@ -13,7 +13,6 @@ ExprLexer.cpp ExprParser.cpp ExprVisitor.cpp ) -find_package(antlr4-runtime CONFIG REQUIRED) add_library(${PROJ} ${SRCS}) add_library(Antares::${PROJ} ALIAS ${PROJ}) diff --git a/src/libs/antares/antlr-interface/Expr.g4 b/src/libs/antares/antlr-interface/Expr.g4 index d0d1642497..9b21de7bbd 100644 --- a/src/libs/antares/antlr-interface/Expr.g4 +++ b/src/libs/antares/antlr-interface/Expr.g4 @@ -17,23 +17,55 @@ grammar Expr; /* To match the whole input */ fullexpr: expr EOF; -shift: TIME (op=('+' | '-') expr)?; - -expr: '-' expr # negation - | expr op=('/' | '*') expr # muldiv - | expr op=('+' | '-') expr # addsub - | expr COMPARISON expr # comparison - | IDENTIFIER # identifier - | IDENTIFIER '.' IDENTIFIER # portField - | NUMBER # number - | '(' expr ')' # expression - | IDENTIFIER '(' expr ')' # function - | IDENTIFIER '[' shift (',' shift)* ']' # timeShift - | IDENTIFIER '[' expr (',' expr )* ']' # timeIndex - | IDENTIFIER '[' shift1=shift '..' shift2=shift ']' # timeShiftRange - | IDENTIFIER '[' expr '..' expr ']' # timeRange +expr + : atom # unsignedAtom + | IDENTIFIER '.' IDENTIFIER # portField + | '-' expr # negation + | '(' expr ')' # expression + | expr op=('/' | '*') expr # muldiv + | expr op=('+' | '-') expr # addsub + | expr COMPARISON expr # comparison + | 'sum' '(' expr ')' # allTimeSum + | 'sum' '(' from=shift '..' to=shift ',' expr ')' # timeSum + | IDENTIFIER '(' expr ')' # function + | IDENTIFIER '[' shift ']' # timeShift + | IDENTIFIER '[' expr ']' # timeIndex ; +atom + : NUMBER # number + | IDENTIFIER # identifier + ; + +// a shift is required to be either "t" or "t + ..." or "t - ..." +// Note: simply defining it as "shift: TIME ('+' | '-') expr" won't work +// because the minus sign will not have the expected precedence: +// "t - d + 1" would be equivalent to "t - (d + 1)" +shift: TIME shift_expr?; + +// Because the shift MUST start with + or -, we need +// to differentiate it from generic "expr". +// A shift expression can only be extended to the right by a +// "right_expr" which cannot start with a + or -, +// unlike shift_expr itself. +// TODO: the grammar is still a little weird, because we +// allow more things in the "expr" parts of those +// shift expressions than on their left-most part +// (port fields, nested time shifts and so on). +shift_expr + : shift_expr op=('*' | '/') right_expr # shiftMuldiv + | shift_expr op=('+' | '-') right_expr # shiftAddsub + | op=('+' | '-') atom # signedAtom + | op=('+' | '-') '(' expr ')' # signedExpression + ; + +right_expr + : right_expr op=('/' | '*') right_expr # rightMuldiv + | '(' expr ')' # rightExpression + | atom # rightAtom + ; + + fragment DIGIT : [0-9] ; fragment CHAR : [a-zA-Z_]; fragment CHAR_OR_DIGIT : (CHAR | DIGIT); @@ -42,9 +74,5 @@ NUMBER : DIGIT+ ('.' DIGIT+)?; TIME : 't'; IDENTIFIER : CHAR CHAR_OR_DIGIT*; COMPARISON : ( '=' | '>=' | '<=' ); -ADDSUB : ( '+' | '-' ); -MULDIV : ( '*' | '/' ); -LBRACKET: '['; -RBRACKET: ']'; WS: (' ' | '\t' | '\r'| '\n') -> skip; diff --git a/src/libs/antares/antlr-interface/Expr.interp b/src/libs/antares/antlr-interface/Expr.interp index bed351938d..d4189d97c1 100644 --- a/src/libs/antares/antlr-interface/Expr.interp +++ b/src/libs/antares/antlr-interface/Expr.interp @@ -1,23 +1,22 @@ token literal names: null -'+' -'-' -'/' -'*' '.' +'-' '(' ')' -',' +'/' +'*' +'+' +'sum' '..' +',' +'[' +']' null 't' null null null -null -'[' -']' -null token symbolic names: null @@ -30,21 +29,23 @@ null null null null +null +null +null NUMBER TIME IDENTIFIER COMPARISON -ADDSUB -MULDIV -LBRACKET -RBRACKET WS rule names: fullexpr -shift expr +atom +shift +shift_expr +right_expr atn: -[4, 1, 18, 86, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 3, 1, 13, 8, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 37, 8, 2, 10, 2, 12, 2, 40, 9, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 49, 8, 2, 10, 2, 12, 2, 52, 9, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 70, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 81, 8, 2, 10, 2, 12, 2, 84, 9, 2, 1, 2, 0, 1, 4, 3, 0, 2, 4, 0, 2, 1, 0, 1, 2, 1, 0, 3, 4, 97, 0, 6, 1, 0, 0, 0, 2, 9, 1, 0, 0, 0, 4, 69, 1, 0, 0, 0, 6, 7, 3, 4, 2, 0, 7, 8, 5, 0, 0, 1, 8, 1, 1, 0, 0, 0, 9, 12, 5, 11, 0, 0, 10, 11, 7, 0, 0, 0, 11, 13, 3, 4, 2, 0, 12, 10, 1, 0, 0, 0, 12, 13, 1, 0, 0, 0, 13, 3, 1, 0, 0, 0, 14, 15, 6, 2, -1, 0, 15, 16, 5, 2, 0, 0, 16, 70, 3, 4, 2, 13, 17, 70, 5, 12, 0, 0, 18, 19, 5, 12, 0, 0, 19, 20, 5, 5, 0, 0, 20, 70, 5, 12, 0, 0, 21, 70, 5, 10, 0, 0, 22, 23, 5, 6, 0, 0, 23, 24, 3, 4, 2, 0, 24, 25, 5, 7, 0, 0, 25, 70, 1, 0, 0, 0, 26, 27, 5, 12, 0, 0, 27, 28, 5, 6, 0, 0, 28, 29, 3, 4, 2, 0, 29, 30, 5, 7, 0, 0, 30, 70, 1, 0, 0, 0, 31, 32, 5, 12, 0, 0, 32, 33, 5, 16, 0, 0, 33, 38, 3, 2, 1, 0, 34, 35, 5, 8, 0, 0, 35, 37, 3, 2, 1, 0, 36, 34, 1, 0, 0, 0, 37, 40, 1, 0, 0, 0, 38, 36, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 41, 1, 0, 0, 0, 40, 38, 1, 0, 0, 0, 41, 42, 5, 17, 0, 0, 42, 70, 1, 0, 0, 0, 43, 44, 5, 12, 0, 0, 44, 45, 5, 16, 0, 0, 45, 50, 3, 4, 2, 0, 46, 47, 5, 8, 0, 0, 47, 49, 3, 4, 2, 0, 48, 46, 1, 0, 0, 0, 49, 52, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51, 1, 0, 0, 0, 51, 53, 1, 0, 0, 0, 52, 50, 1, 0, 0, 0, 53, 54, 5, 17, 0, 0, 54, 70, 1, 0, 0, 0, 55, 56, 5, 12, 0, 0, 56, 57, 5, 16, 0, 0, 57, 58, 3, 2, 1, 0, 58, 59, 5, 9, 0, 0, 59, 60, 3, 2, 1, 0, 60, 61, 5, 17, 0, 0, 61, 70, 1, 0, 0, 0, 62, 63, 5, 12, 0, 0, 63, 64, 5, 16, 0, 0, 64, 65, 3, 4, 2, 0, 65, 66, 5, 9, 0, 0, 66, 67, 3, 4, 2, 0, 67, 68, 5, 17, 0, 0, 68, 70, 1, 0, 0, 0, 69, 14, 1, 0, 0, 0, 69, 17, 1, 0, 0, 0, 69, 18, 1, 0, 0, 0, 69, 21, 1, 0, 0, 0, 69, 22, 1, 0, 0, 0, 69, 26, 1, 0, 0, 0, 69, 31, 1, 0, 0, 0, 69, 43, 1, 0, 0, 0, 69, 55, 1, 0, 0, 0, 69, 62, 1, 0, 0, 0, 70, 82, 1, 0, 0, 0, 71, 72, 10, 12, 0, 0, 72, 73, 7, 1, 0, 0, 73, 81, 3, 4, 2, 13, 74, 75, 10, 11, 0, 0, 75, 76, 7, 0, 0, 0, 76, 81, 3, 4, 2, 12, 77, 78, 10, 10, 0, 0, 78, 79, 5, 13, 0, 0, 79, 81, 3, 4, 2, 11, 80, 71, 1, 0, 0, 0, 80, 74, 1, 0, 0, 0, 80, 77, 1, 0, 0, 0, 81, 84, 1, 0, 0, 0, 82, 80, 1, 0, 0, 0, 82, 83, 1, 0, 0, 0, 83, 5, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 6, 12, 38, 50, 69, 80, 82] \ No newline at end of file +[4, 1, 17, 117, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 56, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 67, 8, 1, 10, 1, 12, 1, 70, 9, 1, 1, 2, 1, 2, 3, 2, 74, 8, 2, 1, 3, 1, 3, 3, 3, 78, 8, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 88, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 5, 4, 96, 8, 4, 10, 4, 12, 4, 99, 9, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 107, 8, 5, 1, 5, 1, 5, 1, 5, 5, 5, 112, 8, 5, 10, 5, 12, 5, 115, 9, 5, 1, 5, 0, 3, 2, 8, 10, 6, 0, 2, 4, 6, 8, 10, 0, 2, 1, 0, 5, 6, 2, 0, 2, 2, 7, 7, 128, 0, 12, 1, 0, 0, 0, 2, 55, 1, 0, 0, 0, 4, 73, 1, 0, 0, 0, 6, 75, 1, 0, 0, 0, 8, 87, 1, 0, 0, 0, 10, 106, 1, 0, 0, 0, 12, 13, 3, 2, 1, 0, 13, 14, 5, 0, 0, 1, 14, 1, 1, 0, 0, 0, 15, 16, 6, 1, -1, 0, 16, 56, 3, 4, 2, 0, 17, 18, 5, 15, 0, 0, 18, 19, 5, 1, 0, 0, 19, 56, 5, 15, 0, 0, 20, 21, 5, 2, 0, 0, 21, 56, 3, 2, 1, 10, 22, 23, 5, 3, 0, 0, 23, 24, 3, 2, 1, 0, 24, 25, 5, 4, 0, 0, 25, 56, 1, 0, 0, 0, 26, 27, 5, 8, 0, 0, 27, 28, 5, 3, 0, 0, 28, 29, 3, 2, 1, 0, 29, 30, 5, 4, 0, 0, 30, 56, 1, 0, 0, 0, 31, 32, 5, 8, 0, 0, 32, 33, 5, 3, 0, 0, 33, 34, 3, 6, 3, 0, 34, 35, 5, 9, 0, 0, 35, 36, 3, 6, 3, 0, 36, 37, 5, 10, 0, 0, 37, 38, 3, 2, 1, 0, 38, 39, 5, 4, 0, 0, 39, 56, 1, 0, 0, 0, 40, 41, 5, 15, 0, 0, 41, 42, 5, 3, 0, 0, 42, 43, 3, 2, 1, 0, 43, 44, 5, 4, 0, 0, 44, 56, 1, 0, 0, 0, 45, 46, 5, 15, 0, 0, 46, 47, 5, 11, 0, 0, 47, 48, 3, 6, 3, 0, 48, 49, 5, 12, 0, 0, 49, 56, 1, 0, 0, 0, 50, 51, 5, 15, 0, 0, 51, 52, 5, 11, 0, 0, 52, 53, 3, 2, 1, 0, 53, 54, 5, 12, 0, 0, 54, 56, 1, 0, 0, 0, 55, 15, 1, 0, 0, 0, 55, 17, 1, 0, 0, 0, 55, 20, 1, 0, 0, 0, 55, 22, 1, 0, 0, 0, 55, 26, 1, 0, 0, 0, 55, 31, 1, 0, 0, 0, 55, 40, 1, 0, 0, 0, 55, 45, 1, 0, 0, 0, 55, 50, 1, 0, 0, 0, 56, 68, 1, 0, 0, 0, 57, 58, 10, 8, 0, 0, 58, 59, 7, 0, 0, 0, 59, 67, 3, 2, 1, 9, 60, 61, 10, 7, 0, 0, 61, 62, 7, 1, 0, 0, 62, 67, 3, 2, 1, 8, 63, 64, 10, 6, 0, 0, 64, 65, 5, 16, 0, 0, 65, 67, 3, 2, 1, 7, 66, 57, 1, 0, 0, 0, 66, 60, 1, 0, 0, 0, 66, 63, 1, 0, 0, 0, 67, 70, 1, 0, 0, 0, 68, 66, 1, 0, 0, 0, 68, 69, 1, 0, 0, 0, 69, 3, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 71, 74, 5, 13, 0, 0, 72, 74, 5, 15, 0, 0, 73, 71, 1, 0, 0, 0, 73, 72, 1, 0, 0, 0, 74, 5, 1, 0, 0, 0, 75, 77, 5, 14, 0, 0, 76, 78, 3, 8, 4, 0, 77, 76, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 7, 1, 0, 0, 0, 79, 80, 6, 4, -1, 0, 80, 81, 7, 1, 0, 0, 81, 88, 3, 4, 2, 0, 82, 83, 7, 1, 0, 0, 83, 84, 5, 3, 0, 0, 84, 85, 3, 2, 1, 0, 85, 86, 5, 4, 0, 0, 86, 88, 1, 0, 0, 0, 87, 79, 1, 0, 0, 0, 87, 82, 1, 0, 0, 0, 88, 97, 1, 0, 0, 0, 89, 90, 10, 4, 0, 0, 90, 91, 7, 0, 0, 0, 91, 96, 3, 10, 5, 0, 92, 93, 10, 3, 0, 0, 93, 94, 7, 1, 0, 0, 94, 96, 3, 10, 5, 0, 95, 89, 1, 0, 0, 0, 95, 92, 1, 0, 0, 0, 96, 99, 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 97, 98, 1, 0, 0, 0, 98, 9, 1, 0, 0, 0, 99, 97, 1, 0, 0, 0, 100, 101, 6, 5, -1, 0, 101, 102, 5, 3, 0, 0, 102, 103, 3, 2, 1, 0, 103, 104, 5, 4, 0, 0, 104, 107, 1, 0, 0, 0, 105, 107, 3, 4, 2, 0, 106, 100, 1, 0, 0, 0, 106, 105, 1, 0, 0, 0, 107, 113, 1, 0, 0, 0, 108, 109, 10, 3, 0, 0, 109, 110, 7, 0, 0, 0, 110, 112, 3, 10, 5, 4, 111, 108, 1, 0, 0, 0, 112, 115, 1, 0, 0, 0, 113, 111, 1, 0, 0, 0, 113, 114, 1, 0, 0, 0, 114, 11, 1, 0, 0, 0, 115, 113, 1, 0, 0, 0, 10, 55, 66, 68, 73, 77, 87, 95, 97, 106, 113] \ No newline at end of file diff --git a/src/libs/antares/antlr-interface/Expr.tokens b/src/libs/antares/antlr-interface/Expr.tokens index 29d96df5f3..868577445e 100644 --- a/src/libs/antares/antlr-interface/Expr.tokens +++ b/src/libs/antares/antlr-interface/Expr.tokens @@ -7,24 +7,24 @@ T__5=6 T__6=7 T__7=8 T__8=9 -NUMBER=10 -TIME=11 -IDENTIFIER=12 -COMPARISON=13 -ADDSUB=14 -MULDIV=15 -LBRACKET=16 -RBRACKET=17 -WS=18 -'+'=1 +T__9=10 +T__10=11 +T__11=12 +NUMBER=13 +TIME=14 +IDENTIFIER=15 +COMPARISON=16 +WS=17 +'.'=1 '-'=2 -'/'=3 -'*'=4 -'.'=5 -'('=6 -')'=7 -','=8 +'('=3 +')'=4 +'/'=5 +'*'=6 +'+'=7 +'sum'=8 '..'=9 -'t'=11 -'['=16 -']'=17 +','=10 +'['=11 +']'=12 +'t'=14 diff --git a/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp b/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp index 42d6fef5d3..864d91febf 100644 --- a/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp +++ b/src/libs/antares/antlr-interface/ExprBaseVisitor.cpp @@ -1,5 +1,5 @@ -// Generated from Expr.g4 by ANTLR 4.13.1 +// Generated from Expr.g4 by ANTLR 4.13.2 #include "ExprBaseVisitor.h" diff --git a/src/libs/antares/antlr-interface/ExprBaseVisitor.h b/src/libs/antares/antlr-interface/ExprBaseVisitor.h index a8af3c573f..5df811ca64 100644 --- a/src/libs/antares/antlr-interface/ExprBaseVisitor.h +++ b/src/libs/antares/antlr-interface/ExprBaseVisitor.h @@ -1,5 +1,5 @@ -// Generated from Expr.g4 by ANTLR 4.13.1 +// Generated from Expr.g4 by ANTLR 4.13.2 #pragma once @@ -19,15 +19,15 @@ class ExprBaseVisitor : public ExprVisitor { return visitChildren(ctx); } - virtual std::any visitShift(ExprParser::ShiftContext *ctx) override { + virtual std::any visitTimeSum(ExprParser::TimeSumContext *ctx) override { return visitChildren(ctx); } - virtual std::any visitIdentifier(ExprParser::IdentifierContext *ctx) override { + virtual std::any visitNegation(ExprParser::NegationContext *ctx) override { return visitChildren(ctx); } - virtual std::any visitNegation(ExprParser::NegationContext *ctx) override { + virtual std::any visitUnsignedAtom(ExprParser::UnsignedAtomContext *ctx) override { return visitChildren(ctx); } @@ -35,10 +35,26 @@ class ExprBaseVisitor : public ExprVisitor { return visitChildren(ctx); } + virtual std::any visitTimeIndex(ExprParser::TimeIndexContext *ctx) override { + return visitChildren(ctx); + } + virtual std::any visitComparison(ExprParser::ComparisonContext *ctx) override { return visitChildren(ctx); } + virtual std::any visitAllTimeSum(ExprParser::AllTimeSumContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitTimeShift(ExprParser::TimeShiftContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitFunction(ExprParser::FunctionContext *ctx) override { + return visitChildren(ctx); + } + virtual std::any visitAddsub(ExprParser::AddsubContext *ctx) override { return visitChildren(ctx); } @@ -55,23 +71,39 @@ class ExprBaseVisitor : public ExprVisitor { return visitChildren(ctx); } - virtual std::any visitTimeIndex(ExprParser::TimeIndexContext *ctx) override { + virtual std::any visitIdentifier(ExprParser::IdentifierContext *ctx) override { return visitChildren(ctx); } - virtual std::any visitTimeShift(ExprParser::TimeShiftContext *ctx) override { + virtual std::any visitShift(ExprParser::ShiftContext *ctx) override { return visitChildren(ctx); } - virtual std::any visitFunction(ExprParser::FunctionContext *ctx) override { + virtual std::any visitSignedAtom(ExprParser::SignedAtomContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitSignedExpression(ExprParser::SignedExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitShiftMuldiv(ExprParser::ShiftMuldivContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitShiftAddsub(ExprParser::ShiftAddsubContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitRightExpression(ExprParser::RightExpressionContext *ctx) override { return visitChildren(ctx); } - virtual std::any visitTimeShiftRange(ExprParser::TimeShiftRangeContext *ctx) override { + virtual std::any visitRightMuldiv(ExprParser::RightMuldivContext *ctx) override { return visitChildren(ctx); } - virtual std::any visitTimeRange(ExprParser::TimeRangeContext *ctx) override { + virtual std::any visitRightAtom(ExprParser::RightAtomContext *ctx) override { return visitChildren(ctx); } diff --git a/src/libs/antares/antlr-interface/ExprLexer.cpp b/src/libs/antares/antlr-interface/ExprLexer.cpp index a645fcddd0..6cb4377101 100644 --- a/src/libs/antares/antlr-interface/ExprLexer.cpp +++ b/src/libs/antares/antlr-interface/ExprLexer.cpp @@ -1,5 +1,5 @@ -// Generated from Expr.g4 by ANTLR 4.13.1 +// Generated from Expr.g4 by ANTLR 4.13.2 #include "ExprLexer.h" @@ -45,7 +45,7 @@ ::antlr4::internal::OnceFlag exprlexerLexerOnceFlag; #if ANTLR4_USE_THREAD_LOCAL_CACHE static thread_local #endif -ExprLexerStaticData *exprlexerLexerStaticData = nullptr; +std::unique_ptr exprlexerLexerStaticData = nullptr; void exprlexerLexerInitialize() { #if ANTLR4_USE_THREAD_LOCAL_CACHE @@ -58,8 +58,8 @@ void exprlexerLexerInitialize() { auto staticData = std::make_unique( std::vector{ "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", - "DIGIT", "CHAR", "CHAR_OR_DIGIT", "NUMBER", "TIME", "IDENTIFIER", - "COMPARISON", "ADDSUB", "MULDIV", "LBRACKET", "RBRACKET", "WS" + "T__9", "T__10", "T__11", "DIGIT", "CHAR", "CHAR_OR_DIGIT", "NUMBER", + "TIME", "IDENTIFIER", "COMPARISON", "WS" }, std::vector{ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" @@ -68,50 +68,49 @@ void exprlexerLexerInitialize() { "DEFAULT_MODE" }, std::vector{ - "", "'+'", "'-'", "'/'", "'*'", "'.'", "'('", "')'", "','", "'..'", - "", "'t'", "", "", "", "", "'['", "']'" + "", "'.'", "'-'", "'('", "')'", "'/'", "'*'", "'+'", "'sum'", "'..'", + "','", "'['", "']'", "", "'t'" }, std::vector{ - "", "", "", "", "", "", "", "", "", "", "NUMBER", "TIME", "IDENTIFIER", - "COMPARISON", "ADDSUB", "MULDIV", "LBRACKET", "RBRACKET", "WS" + "", "", "", "", "", "", "", "", "", "", "", "", "", "NUMBER", "TIME", + "IDENTIFIER", "COMPARISON", "WS" } ); static const int32_t serializedATNSegment[] = { - 4,0,18,111,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 4,0,17,109,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, - 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,1,0, - 1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,7,1,7,1,8,1,8,1, - 8,1,9,1,9,1,10,1,10,1,11,1,11,3,11,69,8,11,1,12,4,12,72,8,12,11,12,12, - 12,73,1,12,1,12,4,12,78,8,12,11,12,12,12,79,3,12,82,8,12,1,13,1,13,1, - 14,1,14,5,14,88,8,14,10,14,12,14,91,9,14,1,15,1,15,1,15,1,15,1,15,3,15, - 98,8,15,1,16,1,16,1,17,1,17,1,18,1,18,1,19,1,19,1,20,1,20,1,20,1,20,0, - 0,21,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,0,21,0,23,0,25,10,27, - 11,29,12,31,13,33,14,35,15,37,16,39,17,41,18,1,0,5,1,0,48,57,3,0,65,90, - 95,95,97,122,2,0,43,43,45,45,2,0,42,42,47,47,3,0,9,10,13,13,32,32,114, - 0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0, - 0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0, - 0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39, - 1,0,0,0,0,41,1,0,0,0,1,43,1,0,0,0,3,45,1,0,0,0,5,47,1,0,0,0,7,49,1,0, - 0,0,9,51,1,0,0,0,11,53,1,0,0,0,13,55,1,0,0,0,15,57,1,0,0,0,17,59,1,0, - 0,0,19,62,1,0,0,0,21,64,1,0,0,0,23,68,1,0,0,0,25,71,1,0,0,0,27,83,1,0, - 0,0,29,85,1,0,0,0,31,97,1,0,0,0,33,99,1,0,0,0,35,101,1,0,0,0,37,103,1, - 0,0,0,39,105,1,0,0,0,41,107,1,0,0,0,43,44,5,43,0,0,44,2,1,0,0,0,45,46, - 5,45,0,0,46,4,1,0,0,0,47,48,5,47,0,0,48,6,1,0,0,0,49,50,5,42,0,0,50,8, - 1,0,0,0,51,52,5,46,0,0,52,10,1,0,0,0,53,54,5,40,0,0,54,12,1,0,0,0,55, - 56,5,41,0,0,56,14,1,0,0,0,57,58,5,44,0,0,58,16,1,0,0,0,59,60,5,46,0,0, - 60,61,5,46,0,0,61,18,1,0,0,0,62,63,7,0,0,0,63,20,1,0,0,0,64,65,7,1,0, - 0,65,22,1,0,0,0,66,69,3,21,10,0,67,69,3,19,9,0,68,66,1,0,0,0,68,67,1, - 0,0,0,69,24,1,0,0,0,70,72,3,19,9,0,71,70,1,0,0,0,72,73,1,0,0,0,73,71, - 1,0,0,0,73,74,1,0,0,0,74,81,1,0,0,0,75,77,5,46,0,0,76,78,3,19,9,0,77, - 76,1,0,0,0,78,79,1,0,0,0,79,77,1,0,0,0,79,80,1,0,0,0,80,82,1,0,0,0,81, - 75,1,0,0,0,81,82,1,0,0,0,82,26,1,0,0,0,83,84,5,116,0,0,84,28,1,0,0,0, - 85,89,3,21,10,0,86,88,3,23,11,0,87,86,1,0,0,0,88,91,1,0,0,0,89,87,1,0, - 0,0,89,90,1,0,0,0,90,30,1,0,0,0,91,89,1,0,0,0,92,98,5,61,0,0,93,94,5, - 62,0,0,94,98,5,61,0,0,95,96,5,60,0,0,96,98,5,61,0,0,97,92,1,0,0,0,97, - 93,1,0,0,0,97,95,1,0,0,0,98,32,1,0,0,0,99,100,7,2,0,0,100,34,1,0,0,0, - 101,102,7,3,0,0,102,36,1,0,0,0,103,104,5,91,0,0,104,38,1,0,0,0,105,106, - 5,93,0,0,106,40,1,0,0,0,107,108,7,4,0,0,108,109,1,0,0,0,109,110,6,20, - 0,0,110,42,1,0,0,0,7,0,68,73,79,81,89,97,1,6,0,0 + 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,1,0,1,0,1,1,1, + 1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,7,1,7,1,7,1,7,1,8,1,8,1,8, + 1,9,1,9,1,10,1,10,1,11,1,11,1,12,1,12,1,13,1,13,1,14,1,14,3,14,75,8,14, + 1,15,4,15,78,8,15,11,15,12,15,79,1,15,1,15,4,15,84,8,15,11,15,12,15,85, + 3,15,88,8,15,1,16,1,16,1,17,1,17,5,17,94,8,17,10,17,12,17,97,9,17,1,18, + 1,18,1,18,1,18,1,18,3,18,104,8,18,1,19,1,19,1,19,1,19,0,0,20,1,1,3,2, + 5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,0,27,0,29,0,31,13, + 33,14,35,15,37,16,39,17,1,0,3,1,0,48,57,3,0,65,90,95,95,97,122,3,0,9, + 10,13,13,32,32,112,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0, + 9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1, + 0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0, + 0,0,37,1,0,0,0,0,39,1,0,0,0,1,41,1,0,0,0,3,43,1,0,0,0,5,45,1,0,0,0,7, + 47,1,0,0,0,9,49,1,0,0,0,11,51,1,0,0,0,13,53,1,0,0,0,15,55,1,0,0,0,17, + 59,1,0,0,0,19,62,1,0,0,0,21,64,1,0,0,0,23,66,1,0,0,0,25,68,1,0,0,0,27, + 70,1,0,0,0,29,74,1,0,0,0,31,77,1,0,0,0,33,89,1,0,0,0,35,91,1,0,0,0,37, + 103,1,0,0,0,39,105,1,0,0,0,41,42,5,46,0,0,42,2,1,0,0,0,43,44,5,45,0,0, + 44,4,1,0,0,0,45,46,5,40,0,0,46,6,1,0,0,0,47,48,5,41,0,0,48,8,1,0,0,0, + 49,50,5,47,0,0,50,10,1,0,0,0,51,52,5,42,0,0,52,12,1,0,0,0,53,54,5,43, + 0,0,54,14,1,0,0,0,55,56,5,115,0,0,56,57,5,117,0,0,57,58,5,109,0,0,58, + 16,1,0,0,0,59,60,5,46,0,0,60,61,5,46,0,0,61,18,1,0,0,0,62,63,5,44,0,0, + 63,20,1,0,0,0,64,65,5,91,0,0,65,22,1,0,0,0,66,67,5,93,0,0,67,24,1,0,0, + 0,68,69,7,0,0,0,69,26,1,0,0,0,70,71,7,1,0,0,71,28,1,0,0,0,72,75,3,27, + 13,0,73,75,3,25,12,0,74,72,1,0,0,0,74,73,1,0,0,0,75,30,1,0,0,0,76,78, + 3,25,12,0,77,76,1,0,0,0,78,79,1,0,0,0,79,77,1,0,0,0,79,80,1,0,0,0,80, + 87,1,0,0,0,81,83,5,46,0,0,82,84,3,25,12,0,83,82,1,0,0,0,84,85,1,0,0,0, + 85,83,1,0,0,0,85,86,1,0,0,0,86,88,1,0,0,0,87,81,1,0,0,0,87,88,1,0,0,0, + 88,32,1,0,0,0,89,90,5,116,0,0,90,34,1,0,0,0,91,95,3,27,13,0,92,94,3,29, + 14,0,93,92,1,0,0,0,94,97,1,0,0,0,95,93,1,0,0,0,95,96,1,0,0,0,96,36,1, + 0,0,0,97,95,1,0,0,0,98,104,5,61,0,0,99,100,5,62,0,0,100,104,5,61,0,0, + 101,102,5,60,0,0,102,104,5,61,0,0,103,98,1,0,0,0,103,99,1,0,0,0,103,101, + 1,0,0,0,104,38,1,0,0,0,105,106,7,2,0,0,106,107,1,0,0,0,107,108,6,19,0, + 0,108,40,1,0,0,0,7,0,74,79,85,87,95,103,1,6,0,0 }; staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); @@ -123,7 +122,7 @@ void exprlexerLexerInitialize() { for (size_t i = 0; i < count; i++) { staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); } - exprlexerLexerStaticData = staticData.release(); + exprlexerLexerStaticData = std::move(staticData); } } diff --git a/src/libs/antares/antlr-interface/ExprLexer.h b/src/libs/antares/antlr-interface/ExprLexer.h index c7db2c5f77..3d6d36bd29 100644 --- a/src/libs/antares/antlr-interface/ExprLexer.h +++ b/src/libs/antares/antlr-interface/ExprLexer.h @@ -1,5 +1,5 @@ -// Generated from Expr.g4 by ANTLR 4.13.1 +// Generated from Expr.g4 by ANTLR 4.13.2 #pragma once @@ -13,8 +13,8 @@ class ExprLexer : public antlr4::Lexer { public: enum { T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7, - T__7 = 8, T__8 = 9, NUMBER = 10, TIME = 11, IDENTIFIER = 12, COMPARISON = 13, - ADDSUB = 14, MULDIV = 15, LBRACKET = 16, RBRACKET = 17, WS = 18 + T__7 = 8, T__8 = 9, T__9 = 10, T__10 = 11, T__11 = 12, NUMBER = 13, + TIME = 14, IDENTIFIER = 15, COMPARISON = 16, WS = 17 }; explicit ExprLexer(antlr4::CharStream *input); diff --git a/src/libs/antares/antlr-interface/ExprLexer.interp b/src/libs/antares/antlr-interface/ExprLexer.interp index e98cab1e7c..43521ebb69 100644 --- a/src/libs/antares/antlr-interface/ExprLexer.interp +++ b/src/libs/antares/antlr-interface/ExprLexer.interp @@ -1,23 +1,22 @@ token literal names: null -'+' -'-' -'/' -'*' '.' +'-' '(' ')' -',' +'/' +'*' +'+' +'sum' '..' +',' +'[' +']' null 't' null null null -null -'[' -']' -null token symbolic names: null @@ -30,14 +29,13 @@ null null null null +null +null +null NUMBER TIME IDENTIFIER COMPARISON -ADDSUB -MULDIV -LBRACKET -RBRACKET WS rule names: @@ -50,6 +48,9 @@ T__5 T__6 T__7 T__8 +T__9 +T__10 +T__11 DIGIT CHAR CHAR_OR_DIGIT @@ -57,10 +58,6 @@ NUMBER TIME IDENTIFIER COMPARISON -ADDSUB -MULDIV -LBRACKET -RBRACKET WS channel names: @@ -71,4 +68,4 @@ mode names: DEFAULT_MODE atn: -[4, 0, 18, 111, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 3, 11, 69, 8, 11, 1, 12, 4, 12, 72, 8, 12, 11, 12, 12, 12, 73, 1, 12, 1, 12, 4, 12, 78, 8, 12, 11, 12, 12, 12, 79, 3, 12, 82, 8, 12, 1, 13, 1, 13, 1, 14, 1, 14, 5, 14, 88, 8, 14, 10, 14, 12, 14, 91, 9, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 3, 15, 98, 8, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 0, 0, 21, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 0, 21, 0, 23, 0, 25, 10, 27, 11, 29, 12, 31, 13, 33, 14, 35, 15, 37, 16, 39, 17, 41, 18, 1, 0, 5, 1, 0, 48, 57, 3, 0, 65, 90, 95, 95, 97, 122, 2, 0, 43, 43, 45, 45, 2, 0, 42, 42, 47, 47, 3, 0, 9, 10, 13, 13, 32, 32, 114, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 1, 43, 1, 0, 0, 0, 3, 45, 1, 0, 0, 0, 5, 47, 1, 0, 0, 0, 7, 49, 1, 0, 0, 0, 9, 51, 1, 0, 0, 0, 11, 53, 1, 0, 0, 0, 13, 55, 1, 0, 0, 0, 15, 57, 1, 0, 0, 0, 17, 59, 1, 0, 0, 0, 19, 62, 1, 0, 0, 0, 21, 64, 1, 0, 0, 0, 23, 68, 1, 0, 0, 0, 25, 71, 1, 0, 0, 0, 27, 83, 1, 0, 0, 0, 29, 85, 1, 0, 0, 0, 31, 97, 1, 0, 0, 0, 33, 99, 1, 0, 0, 0, 35, 101, 1, 0, 0, 0, 37, 103, 1, 0, 0, 0, 39, 105, 1, 0, 0, 0, 41, 107, 1, 0, 0, 0, 43, 44, 5, 43, 0, 0, 44, 2, 1, 0, 0, 0, 45, 46, 5, 45, 0, 0, 46, 4, 1, 0, 0, 0, 47, 48, 5, 47, 0, 0, 48, 6, 1, 0, 0, 0, 49, 50, 5, 42, 0, 0, 50, 8, 1, 0, 0, 0, 51, 52, 5, 46, 0, 0, 52, 10, 1, 0, 0, 0, 53, 54, 5, 40, 0, 0, 54, 12, 1, 0, 0, 0, 55, 56, 5, 41, 0, 0, 56, 14, 1, 0, 0, 0, 57, 58, 5, 44, 0, 0, 58, 16, 1, 0, 0, 0, 59, 60, 5, 46, 0, 0, 60, 61, 5, 46, 0, 0, 61, 18, 1, 0, 0, 0, 62, 63, 7, 0, 0, 0, 63, 20, 1, 0, 0, 0, 64, 65, 7, 1, 0, 0, 65, 22, 1, 0, 0, 0, 66, 69, 3, 21, 10, 0, 67, 69, 3, 19, 9, 0, 68, 66, 1, 0, 0, 0, 68, 67, 1, 0, 0, 0, 69, 24, 1, 0, 0, 0, 70, 72, 3, 19, 9, 0, 71, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 71, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 81, 1, 0, 0, 0, 75, 77, 5, 46, 0, 0, 76, 78, 3, 19, 9, 0, 77, 76, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 77, 1, 0, 0, 0, 79, 80, 1, 0, 0, 0, 80, 82, 1, 0, 0, 0, 81, 75, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 26, 1, 0, 0, 0, 83, 84, 5, 116, 0, 0, 84, 28, 1, 0, 0, 0, 85, 89, 3, 21, 10, 0, 86, 88, 3, 23, 11, 0, 87, 86, 1, 0, 0, 0, 88, 91, 1, 0, 0, 0, 89, 87, 1, 0, 0, 0, 89, 90, 1, 0, 0, 0, 90, 30, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, 92, 98, 5, 61, 0, 0, 93, 94, 5, 62, 0, 0, 94, 98, 5, 61, 0, 0, 95, 96, 5, 60, 0, 0, 96, 98, 5, 61, 0, 0, 97, 92, 1, 0, 0, 0, 97, 93, 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 98, 32, 1, 0, 0, 0, 99, 100, 7, 2, 0, 0, 100, 34, 1, 0, 0, 0, 101, 102, 7, 3, 0, 0, 102, 36, 1, 0, 0, 0, 103, 104, 5, 91, 0, 0, 104, 38, 1, 0, 0, 0, 105, 106, 5, 93, 0, 0, 106, 40, 1, 0, 0, 0, 107, 108, 7, 4, 0, 0, 108, 109, 1, 0, 0, 0, 109, 110, 6, 20, 0, 0, 110, 42, 1, 0, 0, 0, 7, 0, 68, 73, 79, 81, 89, 97, 1, 6, 0, 0] \ No newline at end of file +[4, 0, 17, 109, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 3, 14, 75, 8, 14, 1, 15, 4, 15, 78, 8, 15, 11, 15, 12, 15, 79, 1, 15, 1, 15, 4, 15, 84, 8, 15, 11, 15, 12, 15, 85, 3, 15, 88, 8, 15, 1, 16, 1, 16, 1, 17, 1, 17, 5, 17, 94, 8, 17, 10, 17, 12, 17, 97, 9, 17, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 3, 18, 104, 8, 18, 1, 19, 1, 19, 1, 19, 1, 19, 0, 0, 20, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 0, 27, 0, 29, 0, 31, 13, 33, 14, 35, 15, 37, 16, 39, 17, 1, 0, 3, 1, 0, 48, 57, 3, 0, 65, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 112, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 1, 41, 1, 0, 0, 0, 3, 43, 1, 0, 0, 0, 5, 45, 1, 0, 0, 0, 7, 47, 1, 0, 0, 0, 9, 49, 1, 0, 0, 0, 11, 51, 1, 0, 0, 0, 13, 53, 1, 0, 0, 0, 15, 55, 1, 0, 0, 0, 17, 59, 1, 0, 0, 0, 19, 62, 1, 0, 0, 0, 21, 64, 1, 0, 0, 0, 23, 66, 1, 0, 0, 0, 25, 68, 1, 0, 0, 0, 27, 70, 1, 0, 0, 0, 29, 74, 1, 0, 0, 0, 31, 77, 1, 0, 0, 0, 33, 89, 1, 0, 0, 0, 35, 91, 1, 0, 0, 0, 37, 103, 1, 0, 0, 0, 39, 105, 1, 0, 0, 0, 41, 42, 5, 46, 0, 0, 42, 2, 1, 0, 0, 0, 43, 44, 5, 45, 0, 0, 44, 4, 1, 0, 0, 0, 45, 46, 5, 40, 0, 0, 46, 6, 1, 0, 0, 0, 47, 48, 5, 41, 0, 0, 48, 8, 1, 0, 0, 0, 49, 50, 5, 47, 0, 0, 50, 10, 1, 0, 0, 0, 51, 52, 5, 42, 0, 0, 52, 12, 1, 0, 0, 0, 53, 54, 5, 43, 0, 0, 54, 14, 1, 0, 0, 0, 55, 56, 5, 115, 0, 0, 56, 57, 5, 117, 0, 0, 57, 58, 5, 109, 0, 0, 58, 16, 1, 0, 0, 0, 59, 60, 5, 46, 0, 0, 60, 61, 5, 46, 0, 0, 61, 18, 1, 0, 0, 0, 62, 63, 5, 44, 0, 0, 63, 20, 1, 0, 0, 0, 64, 65, 5, 91, 0, 0, 65, 22, 1, 0, 0, 0, 66, 67, 5, 93, 0, 0, 67, 24, 1, 0, 0, 0, 68, 69, 7, 0, 0, 0, 69, 26, 1, 0, 0, 0, 70, 71, 7, 1, 0, 0, 71, 28, 1, 0, 0, 0, 72, 75, 3, 27, 13, 0, 73, 75, 3, 25, 12, 0, 74, 72, 1, 0, 0, 0, 74, 73, 1, 0, 0, 0, 75, 30, 1, 0, 0, 0, 76, 78, 3, 25, 12, 0, 77, 76, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 77, 1, 0, 0, 0, 79, 80, 1, 0, 0, 0, 80, 87, 1, 0, 0, 0, 81, 83, 5, 46, 0, 0, 82, 84, 3, 25, 12, 0, 83, 82, 1, 0, 0, 0, 84, 85, 1, 0, 0, 0, 85, 83, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, 88, 1, 0, 0, 0, 87, 81, 1, 0, 0, 0, 87, 88, 1, 0, 0, 0, 88, 32, 1, 0, 0, 0, 89, 90, 5, 116, 0, 0, 90, 34, 1, 0, 0, 0, 91, 95, 3, 27, 13, 0, 92, 94, 3, 29, 14, 0, 93, 92, 1, 0, 0, 0, 94, 97, 1, 0, 0, 0, 95, 93, 1, 0, 0, 0, 95, 96, 1, 0, 0, 0, 96, 36, 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 98, 104, 5, 61, 0, 0, 99, 100, 5, 62, 0, 0, 100, 104, 5, 61, 0, 0, 101, 102, 5, 60, 0, 0, 102, 104, 5, 61, 0, 0, 103, 98, 1, 0, 0, 0, 103, 99, 1, 0, 0, 0, 103, 101, 1, 0, 0, 0, 104, 38, 1, 0, 0, 0, 105, 106, 7, 2, 0, 0, 106, 107, 1, 0, 0, 0, 107, 108, 6, 19, 0, 0, 108, 40, 1, 0, 0, 0, 7, 0, 74, 79, 85, 87, 95, 103, 1, 6, 0, 0] \ No newline at end of file diff --git a/src/libs/antares/antlr-interface/ExprLexer.tokens b/src/libs/antares/antlr-interface/ExprLexer.tokens index 29d96df5f3..868577445e 100644 --- a/src/libs/antares/antlr-interface/ExprLexer.tokens +++ b/src/libs/antares/antlr-interface/ExprLexer.tokens @@ -7,24 +7,24 @@ T__5=6 T__6=7 T__7=8 T__8=9 -NUMBER=10 -TIME=11 -IDENTIFIER=12 -COMPARISON=13 -ADDSUB=14 -MULDIV=15 -LBRACKET=16 -RBRACKET=17 -WS=18 -'+'=1 +T__9=10 +T__10=11 +T__11=12 +NUMBER=13 +TIME=14 +IDENTIFIER=15 +COMPARISON=16 +WS=17 +'.'=1 '-'=2 -'/'=3 -'*'=4 -'.'=5 -'('=6 -')'=7 -','=8 +'('=3 +')'=4 +'/'=5 +'*'=6 +'+'=7 +'sum'=8 '..'=9 -'t'=11 -'['=16 -']'=17 +','=10 +'['=11 +']'=12 +'t'=14 diff --git a/src/libs/antares/antlr-interface/ExprParser.cpp b/src/libs/antares/antlr-interface/ExprParser.cpp index 3c688d96d3..3572cd6863 100644 --- a/src/libs/antares/antlr-interface/ExprParser.cpp +++ b/src/libs/antares/antlr-interface/ExprParser.cpp @@ -1,5 +1,5 @@ -// Generated from Expr.g4 by ANTLR 4.13.1 +// Generated from Expr.g4 by ANTLR 4.13.2 #include "ExprVisitor.h" @@ -40,7 +40,7 @@ ::antlr4::internal::OnceFlag exprParserOnceFlag; #if ANTLR4_USE_THREAD_LOCAL_CACHE static thread_local #endif -ExprParserStaticData *exprParserStaticData = nullptr; +std::unique_ptr exprParserStaticData = nullptr; void exprParserInitialize() { #if ANTLR4_USE_THREAD_LOCAL_CACHE @@ -52,44 +52,54 @@ void exprParserInitialize() { #endif auto staticData = std::make_unique( std::vector{ - "fullexpr", "shift", "expr" + "fullexpr", "expr", "atom", "shift", "shift_expr", "right_expr" }, std::vector{ - "", "'+'", "'-'", "'/'", "'*'", "'.'", "'('", "')'", "','", "'..'", - "", "'t'", "", "", "", "", "'['", "']'" + "", "'.'", "'-'", "'('", "')'", "'/'", "'*'", "'+'", "'sum'", "'..'", + "','", "'['", "']'", "", "'t'" }, std::vector{ - "", "", "", "", "", "", "", "", "", "", "NUMBER", "TIME", "IDENTIFIER", - "COMPARISON", "ADDSUB", "MULDIV", "LBRACKET", "RBRACKET", "WS" + "", "", "", "", "", "", "", "", "", "", "", "", "", "NUMBER", "TIME", + "IDENTIFIER", "COMPARISON", "WS" } ); static const int32_t serializedATNSegment[] = { - 4,1,18,86,2,0,7,0,2,1,7,1,2,2,7,2,1,0,1,0,1,0,1,1,1,1,1,1,3,1,13,8,1, - 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,5,2,37,8,2,10,2,12,2,40,9,2,1,2,1,2,1,2,1,2,1,2,1,2, - 1,2,5,2,49,8,2,10,2,12,2,52,9,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1, - 2,1,2,1,2,1,2,1,2,1,2,1,2,3,2,70,8,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2, - 1,2,5,2,81,8,2,10,2,12,2,84,9,2,1,2,0,1,4,3,0,2,4,0,2,1,0,1,2,1,0,3,4, - 97,0,6,1,0,0,0,2,9,1,0,0,0,4,69,1,0,0,0,6,7,3,4,2,0,7,8,5,0,0,1,8,1,1, - 0,0,0,9,12,5,11,0,0,10,11,7,0,0,0,11,13,3,4,2,0,12,10,1,0,0,0,12,13,1, - 0,0,0,13,3,1,0,0,0,14,15,6,2,-1,0,15,16,5,2,0,0,16,70,3,4,2,13,17,70, - 5,12,0,0,18,19,5,12,0,0,19,20,5,5,0,0,20,70,5,12,0,0,21,70,5,10,0,0,22, - 23,5,6,0,0,23,24,3,4,2,0,24,25,5,7,0,0,25,70,1,0,0,0,26,27,5,12,0,0,27, - 28,5,6,0,0,28,29,3,4,2,0,29,30,5,7,0,0,30,70,1,0,0,0,31,32,5,12,0,0,32, - 33,5,16,0,0,33,38,3,2,1,0,34,35,5,8,0,0,35,37,3,2,1,0,36,34,1,0,0,0,37, - 40,1,0,0,0,38,36,1,0,0,0,38,39,1,0,0,0,39,41,1,0,0,0,40,38,1,0,0,0,41, - 42,5,17,0,0,42,70,1,0,0,0,43,44,5,12,0,0,44,45,5,16,0,0,45,50,3,4,2,0, - 46,47,5,8,0,0,47,49,3,4,2,0,48,46,1,0,0,0,49,52,1,0,0,0,50,48,1,0,0,0, - 50,51,1,0,0,0,51,53,1,0,0,0,52,50,1,0,0,0,53,54,5,17,0,0,54,70,1,0,0, - 0,55,56,5,12,0,0,56,57,5,16,0,0,57,58,3,2,1,0,58,59,5,9,0,0,59,60,3,2, - 1,0,60,61,5,17,0,0,61,70,1,0,0,0,62,63,5,12,0,0,63,64,5,16,0,0,64,65, - 3,4,2,0,65,66,5,9,0,0,66,67,3,4,2,0,67,68,5,17,0,0,68,70,1,0,0,0,69,14, - 1,0,0,0,69,17,1,0,0,0,69,18,1,0,0,0,69,21,1,0,0,0,69,22,1,0,0,0,69,26, - 1,0,0,0,69,31,1,0,0,0,69,43,1,0,0,0,69,55,1,0,0,0,69,62,1,0,0,0,70,82, - 1,0,0,0,71,72,10,12,0,0,72,73,7,1,0,0,73,81,3,4,2,13,74,75,10,11,0,0, - 75,76,7,0,0,0,76,81,3,4,2,12,77,78,10,10,0,0,78,79,5,13,0,0,79,81,3,4, - 2,11,80,71,1,0,0,0,80,74,1,0,0,0,80,77,1,0,0,0,81,84,1,0,0,0,82,80,1, - 0,0,0,82,83,1,0,0,0,83,5,1,0,0,0,84,82,1,0,0,0,6,12,38,50,69,80,82 + 4,1,17,117,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,1,0,1,0,1, + 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,3,1,56,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 5,1,67,8,1,10,1,12,1,70,9,1,1,2,1,2,3,2,74,8,2,1,3,1,3,3,3,78,8,3,1,4, + 1,4,1,4,1,4,1,4,1,4,1,4,1,4,3,4,88,8,4,1,4,1,4,1,4,1,4,1,4,1,4,5,4,96, + 8,4,10,4,12,4,99,9,4,1,5,1,5,1,5,1,5,1,5,1,5,3,5,107,8,5,1,5,1,5,1,5, + 5,5,112,8,5,10,5,12,5,115,9,5,1,5,0,3,2,8,10,6,0,2,4,6,8,10,0,2,1,0,5, + 6,2,0,2,2,7,7,128,0,12,1,0,0,0,2,55,1,0,0,0,4,73,1,0,0,0,6,75,1,0,0,0, + 8,87,1,0,0,0,10,106,1,0,0,0,12,13,3,2,1,0,13,14,5,0,0,1,14,1,1,0,0,0, + 15,16,6,1,-1,0,16,56,3,4,2,0,17,18,5,15,0,0,18,19,5,1,0,0,19,56,5,15, + 0,0,20,21,5,2,0,0,21,56,3,2,1,10,22,23,5,3,0,0,23,24,3,2,1,0,24,25,5, + 4,0,0,25,56,1,0,0,0,26,27,5,8,0,0,27,28,5,3,0,0,28,29,3,2,1,0,29,30,5, + 4,0,0,30,56,1,0,0,0,31,32,5,8,0,0,32,33,5,3,0,0,33,34,3,6,3,0,34,35,5, + 9,0,0,35,36,3,6,3,0,36,37,5,10,0,0,37,38,3,2,1,0,38,39,5,4,0,0,39,56, + 1,0,0,0,40,41,5,15,0,0,41,42,5,3,0,0,42,43,3,2,1,0,43,44,5,4,0,0,44,56, + 1,0,0,0,45,46,5,15,0,0,46,47,5,11,0,0,47,48,3,6,3,0,48,49,5,12,0,0,49, + 56,1,0,0,0,50,51,5,15,0,0,51,52,5,11,0,0,52,53,3,2,1,0,53,54,5,12,0,0, + 54,56,1,0,0,0,55,15,1,0,0,0,55,17,1,0,0,0,55,20,1,0,0,0,55,22,1,0,0,0, + 55,26,1,0,0,0,55,31,1,0,0,0,55,40,1,0,0,0,55,45,1,0,0,0,55,50,1,0,0,0, + 56,68,1,0,0,0,57,58,10,8,0,0,58,59,7,0,0,0,59,67,3,2,1,9,60,61,10,7,0, + 0,61,62,7,1,0,0,62,67,3,2,1,8,63,64,10,6,0,0,64,65,5,16,0,0,65,67,3,2, + 1,7,66,57,1,0,0,0,66,60,1,0,0,0,66,63,1,0,0,0,67,70,1,0,0,0,68,66,1,0, + 0,0,68,69,1,0,0,0,69,3,1,0,0,0,70,68,1,0,0,0,71,74,5,13,0,0,72,74,5,15, + 0,0,73,71,1,0,0,0,73,72,1,0,0,0,74,5,1,0,0,0,75,77,5,14,0,0,76,78,3,8, + 4,0,77,76,1,0,0,0,77,78,1,0,0,0,78,7,1,0,0,0,79,80,6,4,-1,0,80,81,7,1, + 0,0,81,88,3,4,2,0,82,83,7,1,0,0,83,84,5,3,0,0,84,85,3,2,1,0,85,86,5,4, + 0,0,86,88,1,0,0,0,87,79,1,0,0,0,87,82,1,0,0,0,88,97,1,0,0,0,89,90,10, + 4,0,0,90,91,7,0,0,0,91,96,3,10,5,0,92,93,10,3,0,0,93,94,7,1,0,0,94,96, + 3,10,5,0,95,89,1,0,0,0,95,92,1,0,0,0,96,99,1,0,0,0,97,95,1,0,0,0,97,98, + 1,0,0,0,98,9,1,0,0,0,99,97,1,0,0,0,100,101,6,5,-1,0,101,102,5,3,0,0,102, + 103,3,2,1,0,103,104,5,4,0,0,104,107,1,0,0,0,105,107,3,4,2,0,106,100,1, + 0,0,0,106,105,1,0,0,0,107,113,1,0,0,0,108,109,10,3,0,0,109,110,7,0,0, + 0,110,112,3,10,5,4,111,108,1,0,0,0,112,115,1,0,0,0,113,111,1,0,0,0,113, + 114,1,0,0,0,114,11,1,0,0,0,115,113,1,0,0,0,10,55,66,68,73,77,87,95,97, + 106,113 }; staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); @@ -101,7 +111,7 @@ void exprParserInitialize() { for (size_t i = 0; i < count; i++) { staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); } - exprParserStaticData = staticData.release(); + exprParserStaticData = std::move(staticData); } } @@ -178,9 +188,9 @@ ExprParser::FullexprContext* ExprParser::fullexpr() { }); try { enterOuterAlt(_localctx, 1); - setState(6); + setState(12); expr(0); - setState(7); + setState(13); match(ExprParser::EOF); } @@ -193,82 +203,6 @@ ExprParser::FullexprContext* ExprParser::fullexpr() { return _localctx; } -//----------------- ShiftContext ------------------------------------------------------------------ - -ExprParser::ShiftContext::ShiftContext(ParserRuleContext *parent, size_t invokingState) - : ParserRuleContext(parent, invokingState) { -} - -tree::TerminalNode* ExprParser::ShiftContext::TIME() { - return getToken(ExprParser::TIME, 0); -} - -ExprParser::ExprContext* ExprParser::ShiftContext::expr() { - return getRuleContext(0); -} - - -size_t ExprParser::ShiftContext::getRuleIndex() const { - return ExprParser::RuleShift; -} - - -std::any ExprParser::ShiftContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitShift(this); - else - return visitor->visitChildren(this); -} - -ExprParser::ShiftContext* ExprParser::shift() { - ShiftContext *_localctx = _tracker.createInstance(_ctx, getState()); - enterRule(_localctx, 2, ExprParser::RuleShift); - size_t _la = 0; - -#if __cplusplus > 201703L - auto onExit = finally([=, this] { -#else - auto onExit = finally([=] { -#endif - exitRule(); - }); - try { - enterOuterAlt(_localctx, 1); - setState(9); - match(ExprParser::TIME); - setState(12); - _errHandler->sync(this); - - _la = _input->LA(1); - if (_la == ExprParser::T__0 - - || _la == ExprParser::T__1) { - setState(10); - antlrcpp::downCast(_localctx)->op = _input->LT(1); - _la = _input->LA(1); - if (!(_la == ExprParser::T__0 - - || _la == ExprParser::T__1)) { - antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); - } - else { - _errHandler->reportMatch(this); - consume(); - } - setState(11); - expr(0); - } - - } - catch (RecognitionException &e) { - _errHandler->reportError(this, e); - _localctx->exception = std::current_exception(); - _errHandler->recover(this, _localctx->exception); - } - - return _localctx; -} - //----------------- ExprContext ------------------------------------------------------------------ ExprParser::ExprContext::ExprContext(ParserRuleContext *parent, size_t invokingState) @@ -284,18 +218,26 @@ void ExprParser::ExprContext::copyFrom(ExprContext *ctx) { ParserRuleContext::copyFrom(ctx); } -//----------------- IdentifierContext ------------------------------------------------------------------ +//----------------- TimeSumContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::IdentifierContext::IDENTIFIER() { - return getToken(ExprParser::IDENTIFIER, 0); +ExprParser::ExprContext* ExprParser::TimeSumContext::expr() { + return getRuleContext(0); +} + +std::vector ExprParser::TimeSumContext::shift() { + return getRuleContexts(); } -ExprParser::IdentifierContext::IdentifierContext(ExprContext *ctx) { copyFrom(ctx); } +ExprParser::ShiftContext* ExprParser::TimeSumContext::shift(size_t i) { + return getRuleContext(i); +} +ExprParser::TimeSumContext::TimeSumContext(ExprContext *ctx) { copyFrom(ctx); } -std::any ExprParser::IdentifierContext::accept(tree::ParseTreeVisitor *visitor) { + +std::any ExprParser::TimeSumContext::accept(tree::ParseTreeVisitor *visitor) { if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitIdentifier(this); + return parserVisitor->visitTimeSum(this); else return visitor->visitChildren(this); } @@ -314,144 +256,90 @@ std::any ExprParser::NegationContext::accept(tree::ParseTreeVisitor *visitor) { else return visitor->visitChildren(this); } -//----------------- ExpressionContext ------------------------------------------------------------------ - -ExprParser::ExprContext* ExprParser::ExpressionContext::expr() { - return getRuleContext(0); -} - -ExprParser::ExpressionContext::ExpressionContext(ExprContext *ctx) { copyFrom(ctx); } - - -std::any ExprParser::ExpressionContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitExpression(this); - else - return visitor->visitChildren(this); -} -//----------------- ComparisonContext ------------------------------------------------------------------ - -std::vector ExprParser::ComparisonContext::expr() { - return getRuleContexts(); -} - -ExprParser::ExprContext* ExprParser::ComparisonContext::expr(size_t i) { - return getRuleContext(i); -} +//----------------- UnsignedAtomContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::ComparisonContext::COMPARISON() { - return getToken(ExprParser::COMPARISON, 0); +ExprParser::AtomContext* ExprParser::UnsignedAtomContext::atom() { + return getRuleContext(0); } -ExprParser::ComparisonContext::ComparisonContext(ExprContext *ctx) { copyFrom(ctx); } +ExprParser::UnsignedAtomContext::UnsignedAtomContext(ExprContext *ctx) { copyFrom(ctx); } -std::any ExprParser::ComparisonContext::accept(tree::ParseTreeVisitor *visitor) { +std::any ExprParser::UnsignedAtomContext::accept(tree::ParseTreeVisitor *visitor) { if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitComparison(this); + return parserVisitor->visitUnsignedAtom(this); else return visitor->visitChildren(this); } -//----------------- AddsubContext ------------------------------------------------------------------ - -std::vector ExprParser::AddsubContext::expr() { - return getRuleContexts(); -} +//----------------- ExpressionContext ------------------------------------------------------------------ -ExprParser::ExprContext* ExprParser::AddsubContext::expr(size_t i) { - return getRuleContext(i); +ExprParser::ExprContext* ExprParser::ExpressionContext::expr() { + return getRuleContext(0); } -ExprParser::AddsubContext::AddsubContext(ExprContext *ctx) { copyFrom(ctx); } +ExprParser::ExpressionContext::ExpressionContext(ExprContext *ctx) { copyFrom(ctx); } -std::any ExprParser::AddsubContext::accept(tree::ParseTreeVisitor *visitor) { +std::any ExprParser::ExpressionContext::accept(tree::ParseTreeVisitor *visitor) { if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitAddsub(this); + return parserVisitor->visitExpression(this); else return visitor->visitChildren(this); } -//----------------- PortFieldContext ------------------------------------------------------------------ +//----------------- TimeIndexContext ------------------------------------------------------------------ -std::vector ExprParser::PortFieldContext::IDENTIFIER() { - return getTokens(ExprParser::IDENTIFIER); +tree::TerminalNode* ExprParser::TimeIndexContext::IDENTIFIER() { + return getToken(ExprParser::IDENTIFIER, 0); } -tree::TerminalNode* ExprParser::PortFieldContext::IDENTIFIER(size_t i) { - return getToken(ExprParser::IDENTIFIER, i); +ExprParser::ExprContext* ExprParser::TimeIndexContext::expr() { + return getRuleContext(0); } -ExprParser::PortFieldContext::PortFieldContext(ExprContext *ctx) { copyFrom(ctx); } +ExprParser::TimeIndexContext::TimeIndexContext(ExprContext *ctx) { copyFrom(ctx); } -std::any ExprParser::PortFieldContext::accept(tree::ParseTreeVisitor *visitor) { +std::any ExprParser::TimeIndexContext::accept(tree::ParseTreeVisitor *visitor) { if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitPortField(this); + return parserVisitor->visitTimeIndex(this); else return visitor->visitChildren(this); } -//----------------- MuldivContext ------------------------------------------------------------------ +//----------------- ComparisonContext ------------------------------------------------------------------ -std::vector ExprParser::MuldivContext::expr() { +std::vector ExprParser::ComparisonContext::expr() { return getRuleContexts(); } -ExprParser::ExprContext* ExprParser::MuldivContext::expr(size_t i) { +ExprParser::ExprContext* ExprParser::ComparisonContext::expr(size_t i) { return getRuleContext(i); } -ExprParser::MuldivContext::MuldivContext(ExprContext *ctx) { copyFrom(ctx); } - - -std::any ExprParser::MuldivContext::accept(tree::ParseTreeVisitor *visitor) { - if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitMuldiv(this); - else - return visitor->visitChildren(this); -} -//----------------- NumberContext ------------------------------------------------------------------ - -tree::TerminalNode* ExprParser::NumberContext::NUMBER() { - return getToken(ExprParser::NUMBER, 0); +tree::TerminalNode* ExprParser::ComparisonContext::COMPARISON() { + return getToken(ExprParser::COMPARISON, 0); } -ExprParser::NumberContext::NumberContext(ExprContext *ctx) { copyFrom(ctx); } +ExprParser::ComparisonContext::ComparisonContext(ExprContext *ctx) { copyFrom(ctx); } -std::any ExprParser::NumberContext::accept(tree::ParseTreeVisitor *visitor) { +std::any ExprParser::ComparisonContext::accept(tree::ParseTreeVisitor *visitor) { if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitNumber(this); + return parserVisitor->visitComparison(this); else return visitor->visitChildren(this); } -//----------------- TimeIndexContext ------------------------------------------------------------------ - -tree::TerminalNode* ExprParser::TimeIndexContext::IDENTIFIER() { - return getToken(ExprParser::IDENTIFIER, 0); -} - -tree::TerminalNode* ExprParser::TimeIndexContext::LBRACKET() { - return getToken(ExprParser::LBRACKET, 0); -} - -std::vector ExprParser::TimeIndexContext::expr() { - return getRuleContexts(); -} - -ExprParser::ExprContext* ExprParser::TimeIndexContext::expr(size_t i) { - return getRuleContext(i); -} +//----------------- AllTimeSumContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::TimeIndexContext::RBRACKET() { - return getToken(ExprParser::RBRACKET, 0); +ExprParser::ExprContext* ExprParser::AllTimeSumContext::expr() { + return getRuleContext(0); } -ExprParser::TimeIndexContext::TimeIndexContext(ExprContext *ctx) { copyFrom(ctx); } +ExprParser::AllTimeSumContext::AllTimeSumContext(ExprContext *ctx) { copyFrom(ctx); } -std::any ExprParser::TimeIndexContext::accept(tree::ParseTreeVisitor *visitor) { +std::any ExprParser::AllTimeSumContext::accept(tree::ParseTreeVisitor *visitor) { if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitTimeIndex(this); + return parserVisitor->visitAllTimeSum(this); else return visitor->visitChildren(this); } @@ -461,20 +349,8 @@ tree::TerminalNode* ExprParser::TimeShiftContext::IDENTIFIER() { return getToken(ExprParser::IDENTIFIER, 0); } -tree::TerminalNode* ExprParser::TimeShiftContext::LBRACKET() { - return getToken(ExprParser::LBRACKET, 0); -} - -std::vector ExprParser::TimeShiftContext::shift() { - return getRuleContexts(); -} - -ExprParser::ShiftContext* ExprParser::TimeShiftContext::shift(size_t i) { - return getRuleContext(i); -} - -tree::TerminalNode* ExprParser::TimeShiftContext::RBRACKET() { - return getToken(ExprParser::RBRACKET, 0); +ExprParser::ShiftContext* ExprParser::TimeShiftContext::shift() { + return getRuleContext(0); } ExprParser::TimeShiftContext::TimeShiftContext(ExprContext *ctx) { copyFrom(ctx); } @@ -505,65 +381,60 @@ std::any ExprParser::FunctionContext::accept(tree::ParseTreeVisitor *visitor) { else return visitor->visitChildren(this); } -//----------------- TimeShiftRangeContext ------------------------------------------------------------------ +//----------------- AddsubContext ------------------------------------------------------------------ -tree::TerminalNode* ExprParser::TimeShiftRangeContext::IDENTIFIER() { - return getToken(ExprParser::IDENTIFIER, 0); +std::vector ExprParser::AddsubContext::expr() { + return getRuleContexts(); } -tree::TerminalNode* ExprParser::TimeShiftRangeContext::LBRACKET() { - return getToken(ExprParser::LBRACKET, 0); +ExprParser::ExprContext* ExprParser::AddsubContext::expr(size_t i) { + return getRuleContext(i); } -tree::TerminalNode* ExprParser::TimeShiftRangeContext::RBRACKET() { - return getToken(ExprParser::RBRACKET, 0); +ExprParser::AddsubContext::AddsubContext(ExprContext *ctx) { copyFrom(ctx); } + + +std::any ExprParser::AddsubContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitAddsub(this); + else + return visitor->visitChildren(this); } +//----------------- PortFieldContext ------------------------------------------------------------------ -std::vector ExprParser::TimeShiftRangeContext::shift() { - return getRuleContexts(); +std::vector ExprParser::PortFieldContext::IDENTIFIER() { + return getTokens(ExprParser::IDENTIFIER); } -ExprParser::ShiftContext* ExprParser::TimeShiftRangeContext::shift(size_t i) { - return getRuleContext(i); +tree::TerminalNode* ExprParser::PortFieldContext::IDENTIFIER(size_t i) { + return getToken(ExprParser::IDENTIFIER, i); } -ExprParser::TimeShiftRangeContext::TimeShiftRangeContext(ExprContext *ctx) { copyFrom(ctx); } +ExprParser::PortFieldContext::PortFieldContext(ExprContext *ctx) { copyFrom(ctx); } -std::any ExprParser::TimeShiftRangeContext::accept(tree::ParseTreeVisitor *visitor) { +std::any ExprParser::PortFieldContext::accept(tree::ParseTreeVisitor *visitor) { if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitTimeShiftRange(this); + return parserVisitor->visitPortField(this); else return visitor->visitChildren(this); } -//----------------- TimeRangeContext ------------------------------------------------------------------ - -tree::TerminalNode* ExprParser::TimeRangeContext::IDENTIFIER() { - return getToken(ExprParser::IDENTIFIER, 0); -} - -tree::TerminalNode* ExprParser::TimeRangeContext::LBRACKET() { - return getToken(ExprParser::LBRACKET, 0); -} +//----------------- MuldivContext ------------------------------------------------------------------ -std::vector ExprParser::TimeRangeContext::expr() { +std::vector ExprParser::MuldivContext::expr() { return getRuleContexts(); } -ExprParser::ExprContext* ExprParser::TimeRangeContext::expr(size_t i) { +ExprParser::ExprContext* ExprParser::MuldivContext::expr(size_t i) { return getRuleContext(i); } -tree::TerminalNode* ExprParser::TimeRangeContext::RBRACKET() { - return getToken(ExprParser::RBRACKET, 0); -} - -ExprParser::TimeRangeContext::TimeRangeContext(ExprContext *ctx) { copyFrom(ctx); } +ExprParser::MuldivContext::MuldivContext(ExprContext *ctx) { copyFrom(ctx); } -std::any ExprParser::TimeRangeContext::accept(tree::ParseTreeVisitor *visitor) { +std::any ExprParser::MuldivContext::accept(tree::ParseTreeVisitor *visitor) { if (auto parserVisitor = dynamic_cast(visitor)) - return parserVisitor->visitTimeRange(this); + return parserVisitor->visitMuldiv(this); else return visitor->visitChildren(this); } @@ -578,8 +449,8 @@ ExprParser::ExprContext* ExprParser::expr(int precedence) { ExprParser::ExprContext *_localctx = _tracker.createInstance(_ctx, parentState); ExprParser::ExprContext *previousContext = _localctx; (void)previousContext; // Silence compiler, in case the context is not used by generated code. - size_t startState = 4; - enterRecursionRule(_localctx, 4, ExprParser::RuleExpr, precedence); + size_t startState = 2; + enterRecursionRule(_localctx, 2, ExprParser::RuleExpr, precedence); size_t _la = 0; @@ -593,169 +464,136 @@ ExprParser::ExprContext* ExprParser::expr(int precedence) { try { size_t alt; enterOuterAlt(_localctx, 1); - setState(69); + setState(55); _errHandler->sync(this); - switch (getInterpreter()->adaptivePredict(_input, 3, _ctx)) { + switch (getInterpreter()->adaptivePredict(_input, 0, _ctx)) { case 1: { - _localctx = _tracker.createInstance(_localctx); + _localctx = _tracker.createInstance(_localctx); _ctx = _localctx; previousContext = _localctx; - setState(15); - match(ExprParser::T__1); setState(16); - expr(13); + atom(); break; } case 2: { - _localctx = _tracker.createInstance(_localctx); + _localctx = _tracker.createInstance(_localctx); _ctx = _localctx; previousContext = _localctx; setState(17); match(ExprParser::IDENTIFIER); - break; - } - - case 3: { - _localctx = _tracker.createInstance(_localctx); - _ctx = _localctx; - previousContext = _localctx; setState(18); - match(ExprParser::IDENTIFIER); + match(ExprParser::T__0); setState(19); - match(ExprParser::T__4); - setState(20); match(ExprParser::IDENTIFIER); break; } - case 4: { - _localctx = _tracker.createInstance(_localctx); + case 3: { + _localctx = _tracker.createInstance(_localctx); _ctx = _localctx; previousContext = _localctx; + setState(20); + match(ExprParser::T__1); setState(21); - match(ExprParser::NUMBER); + expr(10); break; } - case 5: { + case 4: { _localctx = _tracker.createInstance(_localctx); _ctx = _localctx; previousContext = _localctx; setState(22); - match(ExprParser::T__5); + match(ExprParser::T__2); setState(23); expr(0); setState(24); - match(ExprParser::T__6); + match(ExprParser::T__3); break; } - case 6: { - _localctx = _tracker.createInstance(_localctx); + case 5: { + _localctx = _tracker.createInstance(_localctx); _ctx = _localctx; previousContext = _localctx; setState(26); - match(ExprParser::IDENTIFIER); + match(ExprParser::T__7); setState(27); - match(ExprParser::T__5); + match(ExprParser::T__2); setState(28); expr(0); setState(29); - match(ExprParser::T__6); + match(ExprParser::T__3); break; } - case 7: { - _localctx = _tracker.createInstance(_localctx); + case 6: { + _localctx = _tracker.createInstance(_localctx); _ctx = _localctx; previousContext = _localctx; setState(31); - match(ExprParser::IDENTIFIER); + match(ExprParser::T__7); setState(32); - match(ExprParser::LBRACKET); + match(ExprParser::T__2); setState(33); - shift(); + antlrcpp::downCast(_localctx)->from = shift(); + setState(34); + match(ExprParser::T__8); + setState(35); + antlrcpp::downCast(_localctx)->to = shift(); + setState(36); + match(ExprParser::T__9); + setState(37); + expr(0); setState(38); - _errHandler->sync(this); - _la = _input->LA(1); - while (_la == ExprParser::T__7) { - setState(34); - match(ExprParser::T__7); - setState(35); - shift(); - setState(40); - _errHandler->sync(this); - _la = _input->LA(1); - } - setState(41); - match(ExprParser::RBRACKET); + match(ExprParser::T__3); break; } - case 8: { - _localctx = _tracker.createInstance(_localctx); + case 7: { + _localctx = _tracker.createInstance(_localctx); _ctx = _localctx; previousContext = _localctx; - setState(43); + setState(40); match(ExprParser::IDENTIFIER); - setState(44); - match(ExprParser::LBRACKET); - setState(45); + setState(41); + match(ExprParser::T__2); + setState(42); expr(0); - setState(50); - _errHandler->sync(this); - _la = _input->LA(1); - while (_la == ExprParser::T__7) { - setState(46); - match(ExprParser::T__7); - setState(47); - expr(0); - setState(52); - _errHandler->sync(this); - _la = _input->LA(1); - } - setState(53); - match(ExprParser::RBRACKET); + setState(43); + match(ExprParser::T__3); break; } - case 9: { - _localctx = _tracker.createInstance(_localctx); + case 8: { + _localctx = _tracker.createInstance(_localctx); _ctx = _localctx; previousContext = _localctx; - setState(55); + setState(45); match(ExprParser::IDENTIFIER); - setState(56); - match(ExprParser::LBRACKET); - setState(57); - antlrcpp::downCast(_localctx)->shift1 = shift(); - setState(58); - match(ExprParser::T__8); - setState(59); - antlrcpp::downCast(_localctx)->shift2 = shift(); - setState(60); - match(ExprParser::RBRACKET); + setState(46); + match(ExprParser::T__10); + setState(47); + shift(); + setState(48); + match(ExprParser::T__11); break; } - case 10: { - _localctx = _tracker.createInstance(_localctx); + case 9: { + _localctx = _tracker.createInstance(_localctx); _ctx = _localctx; previousContext = _localctx; - setState(62); + setState(50); match(ExprParser::IDENTIFIER); - setState(63); - match(ExprParser::LBRACKET); - setState(64); - expr(0); - setState(65); - match(ExprParser::T__8); - setState(66); + setState(51); + match(ExprParser::T__10); + setState(52); expr(0); - setState(67); - match(ExprParser::RBRACKET); + setState(53); + match(ExprParser::T__11); break; } @@ -763,38 +601,38 @@ ExprParser::ExprContext* ExprParser::expr(int precedence) { break; } _ctx->stop = _input->LT(-1); - setState(82); + setState(68); _errHandler->sync(this); - alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); + alt = getInterpreter()->adaptivePredict(_input, 2, _ctx); while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) { if (alt == 1) { if (!_parseListeners.empty()) triggerExitRuleEvent(); previousContext = _localctx; - setState(80); + setState(66); _errHandler->sync(this); - switch (getInterpreter()->adaptivePredict(_input, 4, _ctx)) { + switch (getInterpreter()->adaptivePredict(_input, 1, _ctx)) { case 1: { auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); _localctx = newContext; pushNewRecursionContext(newContext, startState, RuleExpr); - setState(71); + setState(57); - if (!(precpred(_ctx, 12))) throw FailedPredicateException(this, "precpred(_ctx, 12)"); - setState(72); + if (!(precpred(_ctx, 8))) throw FailedPredicateException(this, "precpred(_ctx, 8)"); + setState(58); antlrcpp::downCast(_localctx)->op = _input->LT(1); _la = _input->LA(1); - if (!(_la == ExprParser::T__2 + if (!(_la == ExprParser::T__4 - || _la == ExprParser::T__3)) { + || _la == ExprParser::T__5)) { antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); } else { _errHandler->reportMatch(this); consume(); } - setState(73); - expr(13); + setState(59); + expr(9); break; } @@ -802,23 +640,23 @@ ExprParser::ExprContext* ExprParser::expr(int precedence) { auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); _localctx = newContext; pushNewRecursionContext(newContext, startState, RuleExpr); - setState(74); + setState(60); - if (!(precpred(_ctx, 11))) throw FailedPredicateException(this, "precpred(_ctx, 11)"); - setState(75); + if (!(precpred(_ctx, 7))) throw FailedPredicateException(this, "precpred(_ctx, 7)"); + setState(61); antlrcpp::downCast(_localctx)->op = _input->LT(1); _la = _input->LA(1); - if (!(_la == ExprParser::T__0 + if (!(_la == ExprParser::T__1 - || _la == ExprParser::T__1)) { + || _la == ExprParser::T__6)) { antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); } else { _errHandler->reportMatch(this); consume(); } - setState(76); - expr(12); + setState(62); + expr(8); break; } @@ -826,13 +664,13 @@ ExprParser::ExprContext* ExprParser::expr(int precedence) { auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); _localctx = newContext; pushNewRecursionContext(newContext, startState, RuleExpr); - setState(77); + setState(63); - if (!(precpred(_ctx, 10))) throw FailedPredicateException(this, "precpred(_ctx, 10)"); - setState(78); + if (!(precpred(_ctx, 6))) throw FailedPredicateException(this, "precpred(_ctx, 6)"); + setState(64); match(ExprParser::COMPARISON); - setState(79); - expr(11); + setState(65); + expr(7); break; } @@ -840,9 +678,565 @@ ExprParser::ExprContext* ExprParser::expr(int precedence) { break; } } + setState(70); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 2, _ctx); + } + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + return _localctx; +} + +//----------------- AtomContext ------------------------------------------------------------------ + +ExprParser::AtomContext::AtomContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + + +size_t ExprParser::AtomContext::getRuleIndex() const { + return ExprParser::RuleAtom; +} + +void ExprParser::AtomContext::copyFrom(AtomContext *ctx) { + ParserRuleContext::copyFrom(ctx); +} + +//----------------- NumberContext ------------------------------------------------------------------ + +tree::TerminalNode* ExprParser::NumberContext::NUMBER() { + return getToken(ExprParser::NUMBER, 0); +} + +ExprParser::NumberContext::NumberContext(AtomContext *ctx) { copyFrom(ctx); } + + +std::any ExprParser::NumberContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitNumber(this); + else + return visitor->visitChildren(this); +} +//----------------- IdentifierContext ------------------------------------------------------------------ + +tree::TerminalNode* ExprParser::IdentifierContext::IDENTIFIER() { + return getToken(ExprParser::IDENTIFIER, 0); +} + +ExprParser::IdentifierContext::IdentifierContext(AtomContext *ctx) { copyFrom(ctx); } + + +std::any ExprParser::IdentifierContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitIdentifier(this); + else + return visitor->visitChildren(this); +} +ExprParser::AtomContext* ExprParser::atom() { + AtomContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 4, ExprParser::RuleAtom); + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + setState(73); + _errHandler->sync(this); + switch (_input->LA(1)) { + case ExprParser::NUMBER: { + _localctx = _tracker.createInstance(_localctx); + enterOuterAlt(_localctx, 1); + setState(71); + match(ExprParser::NUMBER); + break; + } + + case ExprParser::IDENTIFIER: { + _localctx = _tracker.createInstance(_localctx); + enterOuterAlt(_localctx, 2); + setState(72); + match(ExprParser::IDENTIFIER); + break; + } + + default: + throw NoViableAltException(this); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- ShiftContext ------------------------------------------------------------------ + +ExprParser::ShiftContext::ShiftContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +tree::TerminalNode* ExprParser::ShiftContext::TIME() { + return getToken(ExprParser::TIME, 0); +} + +ExprParser::Shift_exprContext* ExprParser::ShiftContext::shift_expr() { + return getRuleContext(0); +} + + +size_t ExprParser::ShiftContext::getRuleIndex() const { + return ExprParser::RuleShift; +} + + +std::any ExprParser::ShiftContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitShift(this); + else + return visitor->visitChildren(this); +} + +ExprParser::ShiftContext* ExprParser::shift() { + ShiftContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 6, ExprParser::RuleShift); + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(75); + match(ExprParser::TIME); + setState(77); + _errHandler->sync(this); + + _la = _input->LA(1); + if (_la == ExprParser::T__1 + + || _la == ExprParser::T__6) { + setState(76); + shift_expr(0); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- Shift_exprContext ------------------------------------------------------------------ + +ExprParser::Shift_exprContext::Shift_exprContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + + +size_t ExprParser::Shift_exprContext::getRuleIndex() const { + return ExprParser::RuleShift_expr; +} + +void ExprParser::Shift_exprContext::copyFrom(Shift_exprContext *ctx) { + ParserRuleContext::copyFrom(ctx); +} + +//----------------- SignedAtomContext ------------------------------------------------------------------ + +ExprParser::AtomContext* ExprParser::SignedAtomContext::atom() { + return getRuleContext(0); +} + +ExprParser::SignedAtomContext::SignedAtomContext(Shift_exprContext *ctx) { copyFrom(ctx); } + + +std::any ExprParser::SignedAtomContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitSignedAtom(this); + else + return visitor->visitChildren(this); +} +//----------------- SignedExpressionContext ------------------------------------------------------------------ + +ExprParser::ExprContext* ExprParser::SignedExpressionContext::expr() { + return getRuleContext(0); +} + +ExprParser::SignedExpressionContext::SignedExpressionContext(Shift_exprContext *ctx) { copyFrom(ctx); } + + +std::any ExprParser::SignedExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitSignedExpression(this); + else + return visitor->visitChildren(this); +} +//----------------- ShiftMuldivContext ------------------------------------------------------------------ + +ExprParser::Shift_exprContext* ExprParser::ShiftMuldivContext::shift_expr() { + return getRuleContext(0); +} + +ExprParser::Right_exprContext* ExprParser::ShiftMuldivContext::right_expr() { + return getRuleContext(0); +} + +ExprParser::ShiftMuldivContext::ShiftMuldivContext(Shift_exprContext *ctx) { copyFrom(ctx); } + + +std::any ExprParser::ShiftMuldivContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitShiftMuldiv(this); + else + return visitor->visitChildren(this); +} +//----------------- ShiftAddsubContext ------------------------------------------------------------------ + +ExprParser::Shift_exprContext* ExprParser::ShiftAddsubContext::shift_expr() { + return getRuleContext(0); +} + +ExprParser::Right_exprContext* ExprParser::ShiftAddsubContext::right_expr() { + return getRuleContext(0); +} + +ExprParser::ShiftAddsubContext::ShiftAddsubContext(Shift_exprContext *ctx) { copyFrom(ctx); } + + +std::any ExprParser::ShiftAddsubContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitShiftAddsub(this); + else + return visitor->visitChildren(this); +} + +ExprParser::Shift_exprContext* ExprParser::shift_expr() { + return shift_expr(0); +} + +ExprParser::Shift_exprContext* ExprParser::shift_expr(int precedence) { + ParserRuleContext *parentContext = _ctx; + size_t parentState = getState(); + ExprParser::Shift_exprContext *_localctx = _tracker.createInstance(_ctx, parentState); + ExprParser::Shift_exprContext *previousContext = _localctx; + (void)previousContext; // Silence compiler, in case the context is not used by generated code. + size_t startState = 8; + enterRecursionRule(_localctx, 8, ExprParser::RuleShift_expr, precedence); + + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + unrollRecursionContexts(parentContext); + }); + try { + size_t alt; + enterOuterAlt(_localctx, 1); + setState(87); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 5, _ctx)) { + case 1: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + + setState(80); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExprParser::T__1 + + || _la == ExprParser::T__6)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(81); + atom(); + break; + } + + case 2: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(82); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExprParser::T__1 + + || _la == ExprParser::T__6)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(83); + match(ExprParser::T__2); setState(84); + expr(0); + setState(85); + match(ExprParser::T__3); + break; + } + + default: + break; + } + _ctx->stop = _input->LT(-1); + setState(97); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 7, _ctx); + while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) { + if (alt == 1) { + if (!_parseListeners.empty()) + triggerExitRuleEvent(); + previousContext = _localctx; + setState(95); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 6, _ctx)) { + case 1: { + auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); + _localctx = newContext; + pushNewRecursionContext(newContext, startState, RuleShift_expr); + setState(89); + + if (!(precpred(_ctx, 4))) throw FailedPredicateException(this, "precpred(_ctx, 4)"); + setState(90); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExprParser::T__4 + + || _la == ExprParser::T__5)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(91); + right_expr(0); + break; + } + + case 2: { + auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); + _localctx = newContext; + pushNewRecursionContext(newContext, startState, RuleShift_expr); + setState(92); + + if (!(precpred(_ctx, 3))) throw FailedPredicateException(this, "precpred(_ctx, 3)"); + setState(93); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExprParser::T__1 + + || _la == ExprParser::T__6)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(94); + right_expr(0); + break; + } + + default: + break; + } + } + setState(99); _errHandler->sync(this); - alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); + alt = getInterpreter()->adaptivePredict(_input, 7, _ctx); + } + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + return _localctx; +} + +//----------------- Right_exprContext ------------------------------------------------------------------ + +ExprParser::Right_exprContext::Right_exprContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + + +size_t ExprParser::Right_exprContext::getRuleIndex() const { + return ExprParser::RuleRight_expr; +} + +void ExprParser::Right_exprContext::copyFrom(Right_exprContext *ctx) { + ParserRuleContext::copyFrom(ctx); +} + +//----------------- RightExpressionContext ------------------------------------------------------------------ + +ExprParser::ExprContext* ExprParser::RightExpressionContext::expr() { + return getRuleContext(0); +} + +ExprParser::RightExpressionContext::RightExpressionContext(Right_exprContext *ctx) { copyFrom(ctx); } + + +std::any ExprParser::RightExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitRightExpression(this); + else + return visitor->visitChildren(this); +} +//----------------- RightMuldivContext ------------------------------------------------------------------ + +std::vector ExprParser::RightMuldivContext::right_expr() { + return getRuleContexts(); +} + +ExprParser::Right_exprContext* ExprParser::RightMuldivContext::right_expr(size_t i) { + return getRuleContext(i); +} + +ExprParser::RightMuldivContext::RightMuldivContext(Right_exprContext *ctx) { copyFrom(ctx); } + + +std::any ExprParser::RightMuldivContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitRightMuldiv(this); + else + return visitor->visitChildren(this); +} +//----------------- RightAtomContext ------------------------------------------------------------------ + +ExprParser::AtomContext* ExprParser::RightAtomContext::atom() { + return getRuleContext(0); +} + +ExprParser::RightAtomContext::RightAtomContext(Right_exprContext *ctx) { copyFrom(ctx); } + + +std::any ExprParser::RightAtomContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitRightAtom(this); + else + return visitor->visitChildren(this); +} + +ExprParser::Right_exprContext* ExprParser::right_expr() { + return right_expr(0); +} + +ExprParser::Right_exprContext* ExprParser::right_expr(int precedence) { + ParserRuleContext *parentContext = _ctx; + size_t parentState = getState(); + ExprParser::Right_exprContext *_localctx = _tracker.createInstance(_ctx, parentState); + ExprParser::Right_exprContext *previousContext = _localctx; + (void)previousContext; // Silence compiler, in case the context is not used by generated code. + size_t startState = 10; + enterRecursionRule(_localctx, 10, ExprParser::RuleRight_expr, precedence); + + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + unrollRecursionContexts(parentContext); + }); + try { + size_t alt; + enterOuterAlt(_localctx, 1); + setState(106); + _errHandler->sync(this); + switch (_input->LA(1)) { + case ExprParser::T__2: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + + setState(101); + match(ExprParser::T__2); + setState(102); + expr(0); + setState(103); + match(ExprParser::T__3); + break; + } + + case ExprParser::NUMBER: + case ExprParser::IDENTIFIER: { + _localctx = _tracker.createInstance(_localctx); + _ctx = _localctx; + previousContext = _localctx; + setState(105); + atom(); + break; + } + + default: + throw NoViableAltException(this); + } + _ctx->stop = _input->LT(-1); + setState(113); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 9, _ctx); + while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) { + if (alt == 1) { + if (!_parseListeners.empty()) + triggerExitRuleEvent(); + previousContext = _localctx; + auto newContext = _tracker.createInstance(_tracker.createInstance(parentContext, parentState)); + _localctx = newContext; + pushNewRecursionContext(newContext, startState, RuleRight_expr); + setState(108); + + if (!(precpred(_ctx, 3))) throw FailedPredicateException(this, "precpred(_ctx, 3)"); + setState(109); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExprParser::T__4 + + || _la == ExprParser::T__5)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(110); + right_expr(4); + } + setState(115); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 9, _ctx); } } catch (RecognitionException &e) { @@ -855,7 +1249,9 @@ ExprParser::ExprContext* ExprParser::expr(int precedence) { bool ExprParser::sempred(RuleContext *context, size_t ruleIndex, size_t predicateIndex) { switch (ruleIndex) { - case 2: return exprSempred(antlrcpp::downCast(context), predicateIndex); + case 1: return exprSempred(antlrcpp::downCast(context), predicateIndex); + case 4: return shift_exprSempred(antlrcpp::downCast(context), predicateIndex); + case 5: return right_exprSempred(antlrcpp::downCast(context), predicateIndex); default: break; @@ -865,9 +1261,30 @@ bool ExprParser::sempred(RuleContext *context, size_t ruleIndex, size_t predicat bool ExprParser::exprSempred(ExprContext *_localctx, size_t predicateIndex) { switch (predicateIndex) { - case 0: return precpred(_ctx, 12); - case 1: return precpred(_ctx, 11); - case 2: return precpred(_ctx, 10); + case 0: return precpred(_ctx, 8); + case 1: return precpred(_ctx, 7); + case 2: return precpred(_ctx, 6); + + default: + break; + } + return true; +} + +bool ExprParser::shift_exprSempred(Shift_exprContext *_localctx, size_t predicateIndex) { + switch (predicateIndex) { + case 3: return precpred(_ctx, 4); + case 4: return precpred(_ctx, 3); + + default: + break; + } + return true; +} + +bool ExprParser::right_exprSempred(Right_exprContext *_localctx, size_t predicateIndex) { + switch (predicateIndex) { + case 5: return precpred(_ctx, 3); default: break; diff --git a/src/libs/antares/antlr-interface/ExprParser.h b/src/libs/antares/antlr-interface/ExprParser.h index aa1c8b6f09..4d7f02fd16 100644 --- a/src/libs/antares/antlr-interface/ExprParser.h +++ b/src/libs/antares/antlr-interface/ExprParser.h @@ -1,5 +1,5 @@ -// Generated from Expr.g4 by ANTLR 4.13.1 +// Generated from Expr.g4 by ANTLR 4.13.2 #pragma once @@ -13,12 +13,13 @@ class ExprParser : public antlr4::Parser { public: enum { T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7, - T__7 = 8, T__8 = 9, NUMBER = 10, TIME = 11, IDENTIFIER = 12, COMPARISON = 13, - ADDSUB = 14, MULDIV = 15, LBRACKET = 16, RBRACKET = 17, WS = 18 + T__7 = 8, T__8 = 9, T__9 = 10, T__10 = 11, T__11 = 12, NUMBER = 13, + TIME = 14, IDENTIFIER = 15, COMPARISON = 16, WS = 17 }; enum { - RuleFullexpr = 0, RuleShift = 1, RuleExpr = 2 + RuleFullexpr = 0, RuleExpr = 1, RuleAtom = 2, RuleShift = 3, RuleShift_expr = 4, + RuleRight_expr = 5 }; explicit ExprParser(antlr4::TokenStream *input); @@ -39,8 +40,11 @@ class ExprParser : public antlr4::Parser { class FullexprContext; + class ExprContext; + class AtomContext; class ShiftContext; - class ExprContext; + class Shift_exprContext; + class Right_exprContext; class FullexprContext : public antlr4::ParserRuleContext { public: @@ -56,21 +60,6 @@ class ExprParser : public antlr4::Parser { FullexprContext* fullexpr(); - class ShiftContext : public antlr4::ParserRuleContext { - public: - antlr4::Token *op = nullptr; - ShiftContext(antlr4::ParserRuleContext *parent, size_t invokingState); - virtual size_t getRuleIndex() const override; - antlr4::tree::TerminalNode *TIME(); - ExprContext *expr(); - - - virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; - - }; - - ShiftContext* shift(); - class ExprContext : public antlr4::ParserRuleContext { public: ExprContext(antlr4::ParserRuleContext *parent, size_t invokingState); @@ -84,11 +73,15 @@ class ExprParser : public antlr4::Parser { }; - class IdentifierContext : public ExprContext { + class TimeSumContext : public ExprContext { public: - IdentifierContext(ExprContext *ctx); + TimeSumContext(ExprContext *ctx); - antlr4::tree::TerminalNode *IDENTIFIER(); + ExprParser::ShiftContext *from = nullptr; + ExprParser::ShiftContext *to = nullptr; + ExprContext *expr(); + std::vector shift(); + ShiftContext* shift(size_t i); virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; }; @@ -102,6 +95,15 @@ class ExprParser : public antlr4::Parser { virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; }; + class UnsignedAtomContext : public ExprContext { + public: + UnsignedAtomContext(ExprContext *ctx); + + AtomContext *atom(); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; + class ExpressionContext : public ExprContext { public: ExpressionContext(ExprContext *ctx); @@ -111,6 +113,16 @@ class ExprParser : public antlr4::Parser { virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; }; + class TimeIndexContext : public ExprContext { + public: + TimeIndexContext(ExprContext *ctx); + + antlr4::tree::TerminalNode *IDENTIFIER(); + ExprContext *expr(); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; + class ComparisonContext : public ExprContext { public: ComparisonContext(ExprContext *ctx); @@ -122,6 +134,35 @@ class ExprParser : public antlr4::Parser { virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; }; + class AllTimeSumContext : public ExprContext { + public: + AllTimeSumContext(ExprContext *ctx); + + ExprContext *expr(); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; + + class TimeShiftContext : public ExprContext { + public: + TimeShiftContext(ExprContext *ctx); + + antlr4::tree::TerminalNode *IDENTIFIER(); + ShiftContext *shift(); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; + + class FunctionContext : public ExprContext { + public: + FunctionContext(ExprContext *ctx); + + antlr4::tree::TerminalNode *IDENTIFIER(); + ExprContext *expr(); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; + class AddsubContext : public ExprContext { public: AddsubContext(ExprContext *ctx); @@ -154,85 +195,162 @@ class ExprParser : public antlr4::Parser { virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; }; - class NumberContext : public ExprContext { + ExprContext* expr(); + ExprContext* expr(int precedence); + class AtomContext : public antlr4::ParserRuleContext { + public: + AtomContext(antlr4::ParserRuleContext *parent, size_t invokingState); + + AtomContext() = default; + void copyFrom(AtomContext *context); + using antlr4::ParserRuleContext::copyFrom; + + virtual size_t getRuleIndex() const override; + + + }; + + class NumberContext : public AtomContext { public: - NumberContext(ExprContext *ctx); + NumberContext(AtomContext *ctx); antlr4::tree::TerminalNode *NUMBER(); virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; }; - class TimeIndexContext : public ExprContext { + class IdentifierContext : public AtomContext { public: - TimeIndexContext(ExprContext *ctx); + IdentifierContext(AtomContext *ctx); antlr4::tree::TerminalNode *IDENTIFIER(); - antlr4::tree::TerminalNode *LBRACKET(); - std::vector expr(); - ExprContext* expr(size_t i); - antlr4::tree::TerminalNode *RBRACKET(); virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; }; - class TimeShiftContext : public ExprContext { + AtomContext* atom(); + + class ShiftContext : public antlr4::ParserRuleContext { public: - TimeShiftContext(ExprContext *ctx); + ShiftContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + antlr4::tree::TerminalNode *TIME(); + Shift_exprContext *shift_expr(); - antlr4::tree::TerminalNode *IDENTIFIER(); - antlr4::tree::TerminalNode *LBRACKET(); - std::vector shift(); - ShiftContext* shift(size_t i); - antlr4::tree::TerminalNode *RBRACKET(); virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; - class FunctionContext : public ExprContext { + ShiftContext* shift(); + + class Shift_exprContext : public antlr4::ParserRuleContext { public: - FunctionContext(ExprContext *ctx); + Shift_exprContext(antlr4::ParserRuleContext *parent, size_t invokingState); + + Shift_exprContext() = default; + void copyFrom(Shift_exprContext *context); + using antlr4::ParserRuleContext::copyFrom; - antlr4::tree::TerminalNode *IDENTIFIER(); + virtual size_t getRuleIndex() const override; + + + }; + + class SignedAtomContext : public Shift_exprContext { + public: + SignedAtomContext(Shift_exprContext *ctx); + + antlr4::Token *op = nullptr; + AtomContext *atom(); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; + + class SignedExpressionContext : public Shift_exprContext { + public: + SignedExpressionContext(Shift_exprContext *ctx); + + antlr4::Token *op = nullptr; ExprContext *expr(); virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; }; - class TimeShiftRangeContext : public ExprContext { + class ShiftMuldivContext : public Shift_exprContext { public: - TimeShiftRangeContext(ExprContext *ctx); + ShiftMuldivContext(Shift_exprContext *ctx); - ExprParser::ShiftContext *shift1 = nullptr; - ExprParser::ShiftContext *shift2 = nullptr; - antlr4::tree::TerminalNode *IDENTIFIER(); - antlr4::tree::TerminalNode *LBRACKET(); - antlr4::tree::TerminalNode *RBRACKET(); - std::vector shift(); - ShiftContext* shift(size_t i); + antlr4::Token *op = nullptr; + Shift_exprContext *shift_expr(); + Right_exprContext *right_expr(); virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; }; - class TimeRangeContext : public ExprContext { + class ShiftAddsubContext : public Shift_exprContext { public: - TimeRangeContext(ExprContext *ctx); + ShiftAddsubContext(Shift_exprContext *ctx); - antlr4::tree::TerminalNode *IDENTIFIER(); - antlr4::tree::TerminalNode *LBRACKET(); - std::vector expr(); - ExprContext* expr(size_t i); - antlr4::tree::TerminalNode *RBRACKET(); + antlr4::Token *op = nullptr; + Shift_exprContext *shift_expr(); + Right_exprContext *right_expr(); virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; }; - ExprContext* expr(); - ExprContext* expr(int precedence); + Shift_exprContext* shift_expr(); + Shift_exprContext* shift_expr(int precedence); + class Right_exprContext : public antlr4::ParserRuleContext { + public: + Right_exprContext(antlr4::ParserRuleContext *parent, size_t invokingState); + + Right_exprContext() = default; + void copyFrom(Right_exprContext *context); + using antlr4::ParserRuleContext::copyFrom; + + virtual size_t getRuleIndex() const override; + + + }; + + class RightExpressionContext : public Right_exprContext { + public: + RightExpressionContext(Right_exprContext *ctx); + + ExprContext *expr(); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; + + class RightMuldivContext : public Right_exprContext { + public: + RightMuldivContext(Right_exprContext *ctx); + + antlr4::Token *op = nullptr; + std::vector right_expr(); + Right_exprContext* right_expr(size_t i); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; + + class RightAtomContext : public Right_exprContext { + public: + RightAtomContext(Right_exprContext *ctx); + + AtomContext *atom(); + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + }; + + Right_exprContext* right_expr(); + Right_exprContext* right_expr(int precedence); bool sempred(antlr4::RuleContext *_localctx, size_t ruleIndex, size_t predicateIndex) override; bool exprSempred(ExprContext *_localctx, size_t predicateIndex); + bool shift_exprSempred(Shift_exprContext *_localctx, size_t predicateIndex); + bool right_exprSempred(Right_exprContext *_localctx, size_t predicateIndex); // By default the static state used to implement the parser is lazily initialized during the first // call to the constructor. You can call this function if you wish to initialize the static state diff --git a/src/libs/antares/antlr-interface/ExprVisitor.cpp b/src/libs/antares/antlr-interface/ExprVisitor.cpp index c214f0f76f..0cdeed41d9 100644 --- a/src/libs/antares/antlr-interface/ExprVisitor.cpp +++ b/src/libs/antares/antlr-interface/ExprVisitor.cpp @@ -1,5 +1,5 @@ -// Generated from Expr.g4 by ANTLR 4.13.1 +// Generated from Expr.g4 by ANTLR 4.13.2 #include "ExprVisitor.h" diff --git a/src/libs/antares/antlr-interface/ExprVisitor.h b/src/libs/antares/antlr-interface/ExprVisitor.h index c064d6d54a..e92c3e3402 100644 --- a/src/libs/antares/antlr-interface/ExprVisitor.h +++ b/src/libs/antares/antlr-interface/ExprVisitor.h @@ -1,5 +1,5 @@ -// Generated from Expr.g4 by ANTLR 4.13.1 +// Generated from Expr.g4 by ANTLR 4.13.2 #pragma once @@ -21,16 +21,24 @@ class ExprVisitor : public antlr4::tree::AbstractParseTreeVisitor { */ virtual std::any visitFullexpr(ExprParser::FullexprContext *context) = 0; - virtual std::any visitShift(ExprParser::ShiftContext *context) = 0; - - virtual std::any visitIdentifier(ExprParser::IdentifierContext *context) = 0; + virtual std::any visitTimeSum(ExprParser::TimeSumContext *context) = 0; virtual std::any visitNegation(ExprParser::NegationContext *context) = 0; + virtual std::any visitUnsignedAtom(ExprParser::UnsignedAtomContext *context) = 0; + virtual std::any visitExpression(ExprParser::ExpressionContext *context) = 0; + virtual std::any visitTimeIndex(ExprParser::TimeIndexContext *context) = 0; + virtual std::any visitComparison(ExprParser::ComparisonContext *context) = 0; + virtual std::any visitAllTimeSum(ExprParser::AllTimeSumContext *context) = 0; + + virtual std::any visitTimeShift(ExprParser::TimeShiftContext *context) = 0; + + virtual std::any visitFunction(ExprParser::FunctionContext *context) = 0; + virtual std::any visitAddsub(ExprParser::AddsubContext *context) = 0; virtual std::any visitPortField(ExprParser::PortFieldContext *context) = 0; @@ -39,15 +47,23 @@ class ExprVisitor : public antlr4::tree::AbstractParseTreeVisitor { virtual std::any visitNumber(ExprParser::NumberContext *context) = 0; - virtual std::any visitTimeIndex(ExprParser::TimeIndexContext *context) = 0; + virtual std::any visitIdentifier(ExprParser::IdentifierContext *context) = 0; - virtual std::any visitTimeShift(ExprParser::TimeShiftContext *context) = 0; + virtual std::any visitShift(ExprParser::ShiftContext *context) = 0; - virtual std::any visitFunction(ExprParser::FunctionContext *context) = 0; + virtual std::any visitSignedAtom(ExprParser::SignedAtomContext *context) = 0; + + virtual std::any visitSignedExpression(ExprParser::SignedExpressionContext *context) = 0; + + virtual std::any visitShiftMuldiv(ExprParser::ShiftMuldivContext *context) = 0; + + virtual std::any visitShiftAddsub(ExprParser::ShiftAddsubContext *context) = 0; + + virtual std::any visitRightExpression(ExprParser::RightExpressionContext *context) = 0; - virtual std::any visitTimeShiftRange(ExprParser::TimeShiftRangeContext *context) = 0; + virtual std::any visitRightMuldiv(ExprParser::RightMuldivContext *context) = 0; - virtual std::any visitTimeRange(ExprParser::TimeRangeContext *context) = 0; + virtual std::any visitRightAtom(ExprParser::RightAtomContext *context) = 0; }; diff --git a/src/solver/expressions/CMakeLists.txt b/src/solver/expressions/CMakeLists.txt index 5f30a6779d..58643f6529 100644 --- a/src/solver/expressions/CMakeLists.txt +++ b/src/solver/expressions/CMakeLists.txt @@ -21,9 +21,12 @@ set(SRC_Expressions visitors/PortFieldSumSubstitutionVisitor.cpp visitors/AstDOTStyleVisitor.cpp visitors/InvalidNode.cpp + visitors/NodeVisitor.cpp hashable.cpp + NodeRegistry.cpp + include/antares/solver/expressions/NodeRegistry.h include/antares/solver/expressions/nodes/SumNode.h include/antares/solver/expressions/nodes/BinaryNode.h include/antares/solver/expressions/nodes/ComparisonNode.h @@ -78,8 +81,8 @@ target_include_directories(solver-expressions ) target_link_libraries(solver-expressions PUBLIC - Antares::logs Boost::headers + Antares::logs ) diff --git a/src/solver/expressions/NodeRegistry.cpp b/src/solver/expressions/NodeRegistry.cpp new file mode 100644 index 0000000000..0fdbdea819 --- /dev/null +++ b/src/solver/expressions/NodeRegistry.cpp @@ -0,0 +1,14 @@ +#include +#include +#include + +namespace Antares::Solver +{ +NodeRegistry::NodeRegistry(Antares::Solver::Nodes::Node* node, + Antares::Solver::Registry registry): + node(node), + registry(std::move(registry)) +{ +} + +} // namespace Antares::Solver diff --git a/src/solver/expressions/include/antares/solver/expressions/NodeRegistry.h b/src/solver/expressions/include/antares/solver/expressions/NodeRegistry.h new file mode 100644 index 0000000000..994b8f6886 --- /dev/null +++ b/src/solver/expressions/include/antares/solver/expressions/NodeRegistry.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +namespace Antares::Solver +{ +class NodeRegistry +{ +public: + NodeRegistry() = default; + NodeRegistry(Antares::Solver::Nodes::Node* node, + Antares::Solver::Registry registry); + + // Shallow copy + NodeRegistry(NodeRegistry&&) = default; + NodeRegistry& operator=(NodeRegistry&&) = default; + + Antares::Solver::Nodes::Node* node; + Antares::Solver::Registry registry; +}; +} // namespace Antares::Solver diff --git a/src/solver/expressions/include/antares/solver/expressions/Registry.hxx b/src/solver/expressions/include/antares/solver/expressions/Registry.hxx index 2ccc9ff8fd..ba74974cb0 100644 --- a/src/solver/expressions/include/antares/solver/expressions/Registry.hxx +++ b/src/solver/expressions/include/antares/solver/expressions/Registry.hxx @@ -32,14 +32,16 @@ template class Registry { public: + Registry() = default; + Registry(Registry&&) = default; + Registry& operator=(Registry&&) = default; + // Method to create a new derived class object and add it to the registry template requires std::derived_from Derived* create(Args&&... args) { auto created = std::make_unique(std::forward(args)...); - - std::lock_guard lock(mutex_); registry_.push_back(std::move(created)); return dynamic_cast( registry_.back().get()); // Return the pointer to the newly created object @@ -48,6 +50,5 @@ public: private: std::vector> registry_; // Registry to manage dynamically allocated objects - std::mutex mutex_; }; } // namespace Antares::Solver diff --git a/src/solver/expressions/include/antares/solver/expressions/visitors/AstDOTStyleVisitor.h b/src/solver/expressions/include/antares/solver/expressions/visitors/AstDOTStyleVisitor.h index a8e4e1ff43..f2a0240e69 100644 --- a/src/solver/expressions/include/antares/solver/expressions/visitors/AstDOTStyleVisitor.h +++ b/src/solver/expressions/include/antares/solver/expressions/visitors/AstDOTStyleVisitor.h @@ -20,6 +20,7 @@ */ #pragma once +#include #include #include @@ -116,7 +117,7 @@ class AstDOTStyleVisitor: public NodeVisitor * @param os The output stream to which the DOT representation is written. * @param root The root of the expression to be output. */ - void operator()(std::ostream& os, Nodes::Node* root); + void operator()(std::ostream& os, const Nodes::Node* root); private: void visit(const Nodes::SumNode* node, std::ostream& os) override; diff --git a/src/solver/expressions/include/antares/solver/expressions/visitors/NodeVisitor.h b/src/solver/expressions/include/antares/solver/expressions/visitors/NodeVisitor.h index 9b88019376..3681224ee6 100644 --- a/src/solver/expressions/include/antares/solver/expressions/visitors/NodeVisitor.h +++ b/src/solver/expressions/include/antares/solver/expressions/visitors/NodeVisitor.h @@ -19,11 +19,11 @@ ** along with Antares_Simulator. If not, see . */ #pragma once +#include #include #include #include -#include #include #include #include @@ -31,6 +31,19 @@ namespace Antares::Solver::Visitors { +// we use LogSink because the inclusion of somehow results in the +// inclusion of (very bad idea in a header!) which conflict with antlr4 headers (defines +// in the former become enums in the latter etc...) +struct LogSink +{ + using LogFunction = std::function; + + LogFunction info; + LogFunction warning; + LogFunction error; +}; + +LogSink RedirectToAntaresLogs(); template RetT tryVisit(const Nodes::Node* node, VisitorT& visitor, Args... args) @@ -119,7 +132,7 @@ class NodeVisitor: public IName } catch (std::exception&) { - logs.error() << "Antares::Solver::Visitor: could not visit the node!"; + log_.error("Antares::Solver::Visitor: could not visit the node!"); throw; } } @@ -269,5 +282,11 @@ class NodeVisitor: public IName * @return The result of processing the ComponentParameterNode. */ virtual R visit(const Nodes::ComponentParameterNode*, Args... args) = 0; + +private: + // we use LogSink because the inclusion of somehow results in the + // inclusion of (very bad idea in a header!) which conflict with antlr4 headers + // (defines in the former become enums in the latter etc...) + LogSink log_ = RedirectToAntaresLogs(); }; } // namespace Antares::Solver::Visitors diff --git a/src/solver/expressions/visitors/AstDOTStyleVisitor.cpp b/src/solver/expressions/visitors/AstDOTStyleVisitor.cpp index fb74a129df..2538ec1360 100644 --- a/src/solver/expressions/visitors/AstDOTStyleVisitor.cpp +++ b/src/solver/expressions/visitors/AstDOTStyleVisitor.cpp @@ -258,7 +258,7 @@ void AstDOTStyleVisitor::EndTreeGraph(std::ostream& os) nbNodesPerType_.clear(); } -void AstDOTStyleVisitor::operator()(std::ostream& os, Nodes::Node* root) +void AstDOTStyleVisitor::operator()(std::ostream& os, const Nodes::Node* root) { NewTreeGraph(os); dispatch(root, os); diff --git a/src/solver/expressions/visitors/EvalVisitor.cpp b/src/solver/expressions/visitors/EvalVisitor.cpp index 4d0b45e119..aa89bd5cc9 100644 --- a/src/solver/expressions/visitors/EvalVisitor.cpp +++ b/src/solver/expressions/visitors/EvalVisitor.cpp @@ -21,6 +21,7 @@ #include "antares/solver/expressions/visitors/EvalVisitor.h" +#include #include #include diff --git a/src/solver/expressions/visitors/NodeVisitor.cpp b/src/solver/expressions/visitors/NodeVisitor.cpp new file mode 100644 index 0000000000..6499f72328 --- /dev/null +++ b/src/solver/expressions/visitors/NodeVisitor.cpp @@ -0,0 +1,46 @@ +/* +** Copyright 2007-2024, RTE (https://www.rte-france.com) +** See AUTHORS.txt +** SPDX-License-Identifier: MPL-2.0 +** This file is part of Antares-Simulator, +** Adequacy and Performance assessment for interconnected energy networks. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the Mozilla Public Licence 2.0 as published by +** the Mozilla Foundation, either version 2 of the License, or +** (at your option) any later version. +** +** Antares_Simulator is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** Mozilla Public Licence 2.0 for more details. +** +** You should have received a copy of the Mozilla Public Licence 2.0 +** along with Antares_Simulator. If not, see . +*/ + +#include +#include + +namespace Antares::Solver::Visitors +{ +static void ToYuniInfo(const std::string& msg) +{ + logs.info() << msg; +} + +static void ToYuniWarning(const std::string& msg) +{ + logs.warning() << msg; +} + +static void ToYuniError(const std::string& msg) +{ + logs.error() << msg; +} + +LogSink RedirectToAntaresLogs() +{ + return {.info = ToYuniInfo, .warning = ToYuniWarning, .error = ToYuniError}; +} +} // namespace Antares::Solver::Visitors diff --git a/src/solver/modelConverter/CMakeLists.txt b/src/solver/modelConverter/CMakeLists.txt index 86c97eb569..005a47e55d 100644 --- a/src/solver/modelConverter/CMakeLists.txt +++ b/src/solver/modelConverter/CMakeLists.txt @@ -1,6 +1,8 @@ set(SOURCES modelConverter.cpp + convertorVisitor.cpp include/antares/solver/modelConverter/modelConverter.h + include/antares/solver/modelConverter/convertorVisitor.h ) # Create the library @@ -18,8 +20,10 @@ target_link_libraries(modelConverter PRIVATE Antares::antares-study-system-model Antares::modelParser + Antares::antlr-interface + Antares::solver-expressions ) install(DIRECTORY include/antares DESTINATION "include" -) \ No newline at end of file +) diff --git a/src/solver/modelConverter/convertorVisitor.cpp b/src/solver/modelConverter/convertorVisitor.cpp new file mode 100644 index 0000000000..6a9267f142 --- /dev/null +++ b/src/solver/modelConverter/convertorVisitor.cpp @@ -0,0 +1,297 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ + +#include +#include + +#include "ExprLexer.h" +#include "ExprParser.h" +#include "antlr4-runtime.h" + +namespace Antares::Solver::ModelConverter +{ + +using namespace Antares::Solver::Nodes; + +/// Visitor to convert ANTLR expressions to Antares::Solver::Nodes +class ConvertorVisitor: public ExprVisitor +{ +public: + ConvertorVisitor(Registry& registry, const ModelParser::Model& model); + + std::any visit(antlr4::tree::ParseTree* tree) override; + + std::any visitIdentifier(ExprParser::IdentifierContext* context) override; + std::any visitMuldiv(ExprParser::MuldivContext* context) override; + std::any visitFullexpr(ExprParser::FullexprContext* context) override; + std::any visitShift(ExprParser::ShiftContext* context) override; + std::any visitNegation(ExprParser::NegationContext* context) override; + std::any visitExpression(ExprParser::ExpressionContext* context) override; + std::any visitComparison(ExprParser::ComparisonContext* context) override; + std::any visitAddsub(ExprParser::AddsubContext* context) override; + std::any visitPortField(ExprParser::PortFieldContext* context) override; + std::any visitNumber(ExprParser::NumberContext* context) override; + std::any visitTimeIndex(ExprParser::TimeIndexContext* context) override; + std::any visitTimeShift(ExprParser::TimeShiftContext* context) override; + std::any visitFunction(ExprParser::FunctionContext* context) override; + + std::any visitTimeSum(ExprParser::TimeSumContext* context) override; + std::any visitAllTimeSum(ExprParser::AllTimeSumContext* context) override; + std::any visitSignedAtom(ExprParser::SignedAtomContext* context) override; + std::any visitUnsignedAtom(ExprParser::UnsignedAtomContext* context) override; + std::any visitRightAtom(ExprParser::RightAtomContext* context) override; + std::any visitSignedExpression(ExprParser::SignedExpressionContext* context) override; + std::any visitShiftAddsub(ExprParser::ShiftAddsubContext* context) override; + std::any visitShiftMuldiv(ExprParser::ShiftMuldivContext* context) override; + std::any visitRightMuldiv(ExprParser::RightMuldivContext* context) override; + std::any visitRightExpression(ExprParser::RightExpressionContext* context) override; + +private: + Registry& registry_; + const ModelParser::Model& model_; +}; + +NodeRegistry convertExpressionToNode(const std::string& exprStr, const ModelParser::Model& model) +{ + if (exprStr.empty()) + { + return {}; + } + antlr4::ANTLRInputStream input(exprStr); + ExprLexer lexer(&input); + antlr4::CommonTokenStream tokens(&lexer); + ExprParser parser(&tokens); + + ExprParser::ExprContext* tree = parser.expr(); + Antares::Solver::Registry registry; + ConvertorVisitor visitor(registry, model); + Node* root = std::any_cast(visitor.visit(tree)); + return NodeRegistry(root, std::move(registry)); +} + +ConvertorVisitor::ConvertorVisitor(Antares::Solver::Registry& registry, + const ModelParser::Model& model): + registry_(registry), + model_(model) +{ +} + +std::any ConvertorVisitor::visit(antlr4::tree::ParseTree* tree) +{ + return tree->accept(this); +} + +class NoParameterOrVariableWithThisName: public std::runtime_error +{ +public: + explicit NoParameterOrVariableWithThisName(const std::string& name): + runtime_error("No parameter or variable found for this identifier: " + name) + { + } +}; + +std::any ConvertorVisitor::visitIdentifier(ExprParser::IdentifierContext* context) +{ + for (const auto& param: model_.parameters) + { + if (param.id == context->IDENTIFIER()->getText()) + { + return static_cast(registry_.create(param.id)); + } + } + + for (const auto& var: model_.variables) + { + if (var.id == context->getText()) + { + return static_cast(registry_.create(var.id)); + } + } + + throw NoParameterOrVariableWithThisName(context->getText()); +} + +std::any ConvertorVisitor::visitMuldiv(ExprParser::MuldivContext* context) +{ + auto* left = std::any_cast(visit(context->expr(0))); + auto* right = std::any_cast(visit(context->expr(1))); + + std::string op = context->op->getText(); + return (op == "*") ? static_cast(registry_.create(left, right)) + : static_cast(registry_.create(left, right)); +} + +std::any ConvertorVisitor::visitFullexpr(ExprParser::FullexprContext* context) +{ + return context->expr()->accept(this); +} + +std::any ConvertorVisitor::visitNegation(ExprParser::NegationContext* context) +{ + Node* n = std::any_cast(context->expr()->accept(this)); + return static_cast(registry_.create(n)); +} + +std::any ConvertorVisitor::visitExpression(ExprParser::ExpressionContext* context) +{ + return context->expr()->accept(this); +} + +std::any ConvertorVisitor::visitComparison(ExprParser::ComparisonContext* context) +{ + Node* left = std::any_cast(visit(context->expr(0))); + Node* right = std::any_cast(visit(context->expr(1))); + + std::string op = context->COMPARISON()->getText(); + if (op == "=") + { + return static_cast(registry_.create(left, right)); + } + else if (op == "<=") + { + return static_cast(registry_.create(left, right)); + } + else + { + return static_cast(registry_.create(left, right)); + } +} + +std::any ConvertorVisitor::visitAddsub(ExprParser::AddsubContext* context) +{ + Node* left = std::any_cast(visit(context->expr(0))); + Node* right = std::any_cast(visit(context->expr(1))); + + std::string op = context->op->getText(); + return (op == "+") ? static_cast(registry_.create(left, right)) + : static_cast(registry_.create(left, right)); +} + +class NotImplemented: public std::runtime_error +{ +public: + using std::runtime_error::runtime_error; +}; + +// TODO implement this +std::any ConvertorVisitor::visitPortField([[maybe_unused]] ExprParser::PortFieldContext* context) +{ + throw NotImplemented("Node portfield not implemented yet"); +} + +std::any ConvertorVisitor::visitNumber(ExprParser::NumberContext* context) +{ + double d = stod(context->getText()); + return static_cast(registry_.create(d)); +} + +// TODO implement this +std::any ConvertorVisitor::visitTimeIndex([[maybe_unused]] ExprParser::TimeIndexContext* context) +{ + throw NotImplemented("Node time index not implemented yet"); +} + +// TODO implement this +std::any ConvertorVisitor::visitTimeShift([[maybe_unused]] ExprParser::TimeShiftContext* context) +{ + throw NotImplemented("Node time shift not implemented yet"); +} + +// TODO implement this +std::any ConvertorVisitor::visitFunction([[maybe_unused]] ExprParser::FunctionContext* context) +{ + throw NotImplemented("Node function not implemented yet"); +} + +// TODO implement this +std::any ConvertorVisitor::visitTimeSum([[maybe_unused]] ExprParser::TimeSumContext* context) +{ + throw NotImplemented("Node time sum not implemented yet"); +} + +// TODO implement this +std::any ConvertorVisitor::visitAllTimeSum([[maybe_unused]] ExprParser::AllTimeSumContext* context) +{ + throw NotImplemented("Node all time sum not implemented yet"); +} + +// shift related, not tested +std::any ConvertorVisitor::visitSignedAtom(ExprParser::SignedAtomContext* context) +{ + auto a = context->atom()->accept(this); + if (context->op->getText() == "-") + { + return static_cast(registry_.create(std::any_cast(a))); + } + return a; +} + +std::any ConvertorVisitor::visitUnsignedAtom(ExprParser::UnsignedAtomContext* context) +{ + return context->atom()->accept(this); +} + +// TODO implement this +std::any ConvertorVisitor::visitRightAtom([[maybe_unused]] ExprParser::RightAtomContext* context) +{ + throw NotImplemented("Node right atom not implemented yet"); +} + +// TODO implement this +std::any ConvertorVisitor::visitShift([[maybe_unused]] ExprParser::ShiftContext* context) +{ + throw NotImplemented("Node shift not implemented yet"); +} + +// TODO implement this +std::any ConvertorVisitor::visitShiftAddsub( + [[maybe_unused]] ExprParser::ShiftAddsubContext* context) +{ + throw NotImplemented("Node shift add sub not implemented yet"); +} + +// TODO implement this +std::any ConvertorVisitor::visitShiftMuldiv( + [[maybe_unused]] ExprParser::ShiftMuldivContext* context) +{ + throw NotImplemented("Node shift mul div not implemented yet"); +} + +// TODO implement this +std::any ConvertorVisitor::visitRightMuldiv( + [[maybe_unused]] ExprParser::RightMuldivContext* context) +{ + throw NotImplemented("Node right mul div not implemented yet"); +} + +// TODO implement this +std::any ConvertorVisitor::visitSignedExpression( + [[maybe_unused]] ExprParser::SignedExpressionContext* context) +{ + throw NotImplemented("Node signed expression not implemented yet"); +} + +std::any ConvertorVisitor::visitRightExpression(ExprParser::RightExpressionContext* context) +{ + return context->expr()->accept(this); +} + +} // namespace Antares::Solver::ModelConverter diff --git a/src/solver/modelConverter/include/antares/solver/modelConverter/convertorVisitor.h b/src/solver/modelConverter/include/antares/solver/modelConverter/convertorVisitor.h new file mode 100644 index 0000000000..1b8dd34643 --- /dev/null +++ b/src/solver/modelConverter/include/antares/solver/modelConverter/convertorVisitor.h @@ -0,0 +1,32 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ + +#pragma once + +#include + +#include +#include "antares/solver/modelParser/Library.h" + +namespace Antares::Solver::ModelConverter +{ +NodeRegistry convertExpressionToNode(const std::string& exprStr, const ModelParser::Model& model); +} // namespace Antares::Solver::ModelConverter diff --git a/src/solver/modelConverter/include/antares/solver/modelConverter/modelConverter.h b/src/solver/modelConverter/include/antares/solver/modelConverter/modelConverter.h index 7ca778e10d..ffa0b66a71 100644 --- a/src/solver/modelConverter/include/antares/solver/modelConverter/modelConverter.h +++ b/src/solver/modelConverter/include/antares/solver/modelConverter/modelConverter.h @@ -20,6 +20,9 @@ */ #pragma once +#include + +#include "antares/solver/modelParser/Library.h" namespace Antares { @@ -34,7 +37,18 @@ class Library; } } // namespace Antares +namespace Antares::Solver::Nodes +{ +class Node; +} + namespace Antares::Solver::ModelConverter { +class UnknownTypeException: public std::runtime_error +{ +public: + explicit UnknownTypeException(ModelParser::ValueType type); +}; + Antares::Study::SystemModel::Library convert(const Antares::Solver::ModelParser::Library& library); -} +} // namespace Antares::Solver::ModelConverter diff --git a/src/solver/modelConverter/modelConverter.cpp b/src/solver/modelConverter/modelConverter.cpp index b585215195..c8b3d856c9 100644 --- a/src/solver/modelConverter/modelConverter.cpp +++ b/src/solver/modelConverter/modelConverter.cpp @@ -21,10 +21,9 @@ #include "antares/solver/modelConverter/modelConverter.h" -#include - -#include "antares/solver/modelParser/Library.h" +#include "antares/solver/modelConverter/convertorVisitor.h" #include "antares/study/system-model/constraint.h" +#include "antares/study/system-model/expression.h" #include "antares/study/system-model/library.h" #include "antares/study/system-model/model.h" #include "antares/study/system-model/parameter.h" @@ -34,11 +33,16 @@ namespace Antares::Solver::ModelConverter { +UnknownTypeException::UnknownTypeException(ModelParser::ValueType type): + std::runtime_error("Unknown type: " + ModelParser::toString(type)) +{ +} + /** - * \brief Converts parameters from ModelParser::Model to ObjectModel::Parameter. + * \brief Converts parameters from ModelParser::Model to SystemModel::Parameter. * * \param model The ModelParser::Model object containing parameters. - * \return A vector of ObjectModel::Parameter objects. + * \return A vector of SystemModel::Parameter objects. */ std::vector convertTypes( const Antares::Solver::ModelParser::Library& library) @@ -61,11 +65,11 @@ std::vector convertTypes( } /** - * \brief Converts a ModelParser::ValueType to an ObjectModel::ValueType. + * \brief Converts a ModelParser::ValueType to an SystemModel::ValueType. * * \param type The ModelParser::ValueType to convert. - * \return The corresponding ObjectModel::ValueType. - * \throws std::runtime_error if the type is unknown. + * \return The corresponding SystemModel::ValueType. + * \throws UnknownType if the type is unknown. */ std::vector convertParameters( const Antares::Solver::ModelParser::Model& model) @@ -73,22 +77,21 @@ std::vector convertParameters( std::vector parameters; for (const auto& parameter: model.parameters) { - parameters.emplace_back(Antares::Study::SystemModel::Parameter{ + parameters.emplace_back( parameter.id, - Antares::Study::SystemModel::ValueType::FLOAT, // TODO: change to correct type static_cast( parameter.time_dependent), static_cast( - parameter.scenario_dependent)}); + parameter.scenario_dependent)); } return parameters; } /** - * \brief Converts variables from ModelParser::Model to ObjectModel::Variable. + * \brief Converts variables from ModelParser::Model to SystemModel::Variable. * * \param model The ModelParser::Model object containing variables. - * \return A vector of ObjectModel::Variable objects. + * \return A vector of SystemModel::Variable objects. */ Antares::Study::SystemModel::ValueType convertType(Antares::Solver::ModelParser::ValueType type) { @@ -102,46 +105,46 @@ Antares::Study::SystemModel::ValueType convertType(Antares::Solver::ModelParser: case Antares::Solver::ModelParser::ValueType::BOOL: return Antares::Study::SystemModel::ValueType::BOOL; default: - throw std::runtime_error("Unknown type: " + Antares::Solver::ModelParser::toString(type)); + throw UnknownTypeException(type); } } /** - * \brief Converts ports from ModelParser::Model to ObjectModel::Port. + * \brief Converts ports from ModelParser::Model to SystemModel::Port. * * \param model The ModelParser::Model object containing ports. - * \return A vector of ObjectModel::Port objects. + * \return A vector of SystemModel::Port objects. */ -std::vector convertVariables( - const Antares::Solver::ModelParser::Model& model) +std::vector convertVariables(const ModelParser::Model& model) { std::vector variables; for (const auto& variable: model.variables) { - variables.emplace_back(Antares::Study::SystemModel::Variable{ - variable.id, - Antares::Study::SystemModel::Expression{variable.lower_bound}, - Antares::Study::SystemModel::Expression{variable.upper_bound}, - convertType(variable.variable_type)}); + Antares::Study::SystemModel::Expression lb(variable.lower_bound, + convertExpressionToNode(variable.lower_bound, + model)); + Antares::Study::SystemModel::Expression ub(variable.upper_bound, + convertExpressionToNode(variable.upper_bound, + model)); + variables.emplace_back(variable.id, + std::move(lb), + std::move(ub), + convertType(variable.variable_type)); } + return variables; } /** - * \brief Converts constraints from ModelParser::Model to ObjectModel::Constraint. + * \brief Converts constraints from ModelParser::Model to SystemModel::Constraint. * * \param model The ModelParser::Model object containing constraints. - * \return A vector of ObjectModel::Constraint objects. + * \return A vector of SystemModel::Constraint objects. */ std::vector convertPorts( - const Antares::Solver::ModelParser::Model& model) + [[maybe_unused]] const Antares::Solver::ModelParser::Model& model) { - std::vector ports; - for (const auto& port: model.ports) - { - // ports.emplace_back(Antares::Study::SystemModel::Port{port.name, port.type}); - } - return ports; + return {}; } std::vector convertConstraints( @@ -150,18 +153,19 @@ std::vector convertConstraints( std::vector constraints; for (const auto& constraint: model.constraints) { - constraints.emplace_back(Antares::Study::SystemModel::Constraint{ - constraint.id, - Antares::Study::SystemModel::Expression{constraint.expression}}); + auto expr = convertExpressionToNode(constraint.expression, model); + constraints.emplace_back(constraint.id, + Antares::Study::SystemModel::Expression{constraint.expression, + std::move(expr)}); } return constraints; } /** - * \brief Converts models from ModelParser::Library to ObjectModel::Model. + * \brief Converts models from ModelParser::Library to SystemModel::Model. * * \param library The ModelParser::Library object containing models. - * \return A vector of ObjectModel::Model objects. + * \return A vector of SystemModel::Model objects. */ std::vector convertModels( const Antares::Solver::ModelParser::Library& library) @@ -176,8 +180,12 @@ std::vector convertModels( std::vector constraints = convertConstraints( model); + auto nodeObjective = convertExpressionToNode(model.objective, model); + auto modelObj = modelBuilder.withId(model.id) - .withObjective(Antares::Study::SystemModel::Expression{model.objective}) + .withObjective( + Antares::Study::SystemModel::Expression{model.objective, + std::move(nodeObjective)}) .withParameters(std::move(parameters)) .withVariables(std::move(variables)) .withPorts(std::move(ports)) @@ -189,10 +197,10 @@ std::vector convertModels( } /** - * \brief Converts a ModelParser::Library object to an ObjectModel::Library object. + * \brief Converts a ModelParser::Library object to an SystemModel::Library object. * * \param library The ModelParser::Library object to convert. - * \return The corresponding ObjectModel::Library object. + * \return The corresponding SystemModel::Library object. */ Antares::Study::SystemModel::Library convert(const Antares::Solver::ModelParser::Library& library) { diff --git a/src/study/system-model/CMakeLists.txt b/src/study/system-model/CMakeLists.txt index b497026127..e9a7348534 100644 --- a/src/study/system-model/CMakeLists.txt +++ b/src/study/system-model/CMakeLists.txt @@ -27,6 +27,7 @@ target_include_directories(antares-study-system-model ) target_link_libraries(antares-study-system-model PUBLIC + Antares::solver-expressions ) install(DIRECTORY include/antares DESTINATION "include" diff --git a/src/study/system-model/include/antares/study/system-model/constraint.h b/src/study/system-model/include/antares/study/system-model/constraint.h index eb7777f484..b4afe5c0ef 100644 --- a/src/study/system-model/include/antares/study/system-model/constraint.h +++ b/src/study/system-model/include/antares/study/system-model/constraint.h @@ -43,7 +43,7 @@ class Constraint return id_; } - Expression expression() const + const Expression& expression() const { return expression_; } diff --git a/src/study/system-model/include/antares/study/system-model/expression.h b/src/study/system-model/include/antares/study/system-model/expression.h index 6924401e68..0b52d82f91 100644 --- a/src/study/system-model/include/antares/study/system-model/expression.h +++ b/src/study/system-model/include/antares/study/system-model/expression.h @@ -22,6 +22,13 @@ #include +#include + +namespace Antares::Solver::Nodes +{ +class Node; +} + namespace Antares::Study::SystemModel { @@ -30,8 +37,9 @@ class Expression public: Expression() = default; - explicit Expression(std::string value): - value_(std::move(value)) + explicit Expression(const std::string& value, Antares::Solver::NodeRegistry root): + value_(value), + root_(std::move(root)) { } @@ -42,6 +50,7 @@ class Expression private: std::string value_; + Antares::Solver::NodeRegistry root_; }; } // namespace Antares::Study::SystemModel diff --git a/src/study/system-model/include/antares/study/system-model/library.h b/src/study/system-model/include/antares/study/system-model/library.h index a056731156..8f5e3599f8 100644 --- a/src/study/system-model/include/antares/study/system-model/library.h +++ b/src/study/system-model/include/antares/study/system-model/library.h @@ -53,7 +53,7 @@ class Library const std::unordered_map& Models() const { - return models_; + return *models_; } private: @@ -63,7 +63,8 @@ class Library std::string description_; std::unordered_map portTypes_; - std::unordered_map models_; + std::shared_ptr> + models_ = std::make_shared>(); }; /** @@ -79,7 +80,7 @@ class LibraryBuilder LibraryBuilder& withPortTypes(std::vector&& portTypes); LibraryBuilder& withModels(std::vector&& models); - Library build(); + const Library& build() const; private: Library library_; diff --git a/src/study/system-model/include/antares/study/system-model/model.h b/src/study/system-model/include/antares/study/system-model/model.h index 8f19d424c1..a050424131 100644 --- a/src/study/system-model/include/antares/study/system-model/model.h +++ b/src/study/system-model/include/antares/study/system-model/model.h @@ -39,12 +39,20 @@ namespace Antares::Study::SystemModel class Model { public: + Model() = default; + Model(Model&&) = default; + Model(const Model&) = delete; + ~Model() = default; + + Model& operator=(Model&&) = default; + Model& operator=(const Model&) = delete; + const std::string& Id() const { return id_; } - Expression Objective() const + const Expression& Objective() const { return objective_; } @@ -84,7 +92,7 @@ class ModelBuilder { public: ModelBuilder& withId(std::string_view id); - ModelBuilder& withObjective(Expression objective); + ModelBuilder& withObjective(Expression&& objective); ModelBuilder& withParameters(std::vector&& parameters); ModelBuilder& withVariables(std::vector&& variables); ModelBuilder& withPorts(std::vector&& ports); diff --git a/src/study/system-model/include/antares/study/system-model/parameter.h b/src/study/system-model/include/antares/study/system-model/parameter.h index 4daa3d2b94..b2dad9b7d1 100644 --- a/src/study/system-model/include/antares/study/system-model/parameter.h +++ b/src/study/system-model/include/antares/study/system-model/parameter.h @@ -53,11 +53,9 @@ class Parameter }; explicit Parameter(std::string id, - ValueType type, TimeDependent timeDependent, ScenarioDependent scenarioDependent): id_(std::move(id)), - type_(type), timeDependent_(timeDependent), scenarioDependent_(scenarioDependent) { @@ -68,11 +66,6 @@ class Parameter return id_; } - ValueType Type() const - { - return type_; - } - bool isTimeDependent() const { return timeDependent_ == TimeDependent::YES; @@ -85,7 +78,6 @@ class Parameter private: std::string id_; - ValueType type_; TimeDependent timeDependent_ = TimeDependent::YES; // optional at construction ScenarioDependent scenarioDependent_ = ScenarioDependent::YES; // optional at construction }; diff --git a/src/study/system-model/include/antares/study/system-model/variable.h b/src/study/system-model/include/antares/study/system-model/variable.h index ad9011df79..451fbd2b90 100644 --- a/src/study/system-model/include/antares/study/system-model/variable.h +++ b/src/study/system-model/include/antares/study/system-model/variable.h @@ -35,8 +35,8 @@ class Variable Variable(std::string id, Expression lower_bound, Expression upper_bound, ValueType type): id_(std::move(id)), type_(type), - lowerBound_(lower_bound), - upperBound_(upper_bound) + lowerBound_(std::move(lower_bound)), + upperBound_(std::move(upper_bound)) { } @@ -50,12 +50,12 @@ class Variable return type_; } - Expression LowerBound() const + const Expression& LowerBound() const { return lowerBound_; } - Expression UpperBound() const + const Expression& UpperBound() const { return upperBound_; } diff --git a/src/study/system-model/library.cpp b/src/study/system-model/library.cpp index e7026afd86..ace09d45ae 100644 --- a/src/study/system-model/library.cpp +++ b/src/study/system-model/library.cpp @@ -83,7 +83,7 @@ LibraryBuilder& LibraryBuilder::withModels(std::vector&& models) { std::transform(models.begin(), models.end(), - std::inserter(library_.models_, library_.models_.end()), + std::inserter(*library_.models_, library_.models_->end()), [](/*Non const to prevent copy*/ Model& model) { return std::make_pair(model.Id(), std::move(model)); }); return *this; @@ -94,7 +94,7 @@ LibraryBuilder& LibraryBuilder::withModels(std::vector&& models) * * \return The constructed Library object. */ -Library LibraryBuilder::build() +const Library& LibraryBuilder::build() const { return library_; } diff --git a/src/study/system-model/model.cpp b/src/study/system-model/model.cpp index 5870840d73..fd77cb3cf2 100644 --- a/src/study/system-model/model.cpp +++ b/src/study/system-model/model.cpp @@ -36,7 +36,7 @@ namespace Antares::Study::SystemModel */ Model ModelBuilder::build() { - return model_; + return std::move(model_); } /** @@ -57,9 +57,9 @@ ModelBuilder& ModelBuilder::withId(std::string_view id) * \param objective The Expression object representing the objective. * \return Reference to the ModelBuilder object. */ -ModelBuilder& ModelBuilder::withObjective(Expression objective) +ModelBuilder& ModelBuilder::withObjective(Expression&& objective) { - model_.objective_ = objective; + model_.objective_ = std::move(objective); return *this; } diff --git a/src/tests/src/libs/antares/CMakeLists.txt b/src/tests/src/libs/antares/CMakeLists.txt index 654f897b0a..97ef92fd0e 100644 --- a/src/tests/src/libs/antares/CMakeLists.txt +++ b/src/tests/src/libs/antares/CMakeLists.txt @@ -5,10 +5,7 @@ add_subdirectory(benchmarking) add_subdirectory(inifile) add_subdirectory(yaml-parser) - -if(WITH_ANTLR4) - add_subdirectory(antlr4-interface) -endif() +add_subdirectory(antlr4-interface) set(src_libs_antares "${CMAKE_SOURCE_DIR}/libs/antares") diff --git a/src/tests/src/solver/modelParser/CMakeLists.txt b/src/tests/src/solver/modelParser/CMakeLists.txt index 57f733030c..9f884255d8 100644 --- a/src/tests/src/solver/modelParser/CMakeLists.txt +++ b/src/tests/src/solver/modelParser/CMakeLists.txt @@ -2,6 +2,7 @@ set(SOURCE_FILES testModelParser.cpp testModelTranslator.cpp + testConvertorVisitor.cpp test_full.cpp enum_operators.h ) @@ -13,9 +14,11 @@ add_executable(TestModelParser ${SOURCE_FILES}) target_link_libraries(TestModelParser PRIVATE Boost::unit_test_framework + Antares::solver-expressions Antares::modelConverter Antares::modelParser Antares::antares-study-system-model + Antares::antlr-interface ) # Storing test-toybox under the folder Unit-tests in the IDE @@ -25,4 +28,4 @@ set_target_properties(${EXECUTABLE_NAME} PROPERTIES FOLDER Unit-tests) add_test(NAME TestModelParser COMMAND TestModelParser) # Set test properties -set_property(TEST TestModelParser PROPERTY LABELS unit) \ No newline at end of file +set_property(TEST TestModelParser PROPERTY LABELS unit) diff --git a/src/tests/src/solver/modelParser/testConvertorVisitor.cpp b/src/tests/src/solver/modelParser/testConvertorVisitor.cpp new file mode 100644 index 0000000000..8eddcda921 --- /dev/null +++ b/src/tests/src/solver/modelParser/testConvertorVisitor.cpp @@ -0,0 +1,228 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ +#define WIN32_LEAN_AND_MEAN + +#include + +#include +#include "antares/solver/expressions/Registry.hxx" +#include "antares/solver/expressions/visitors/CompareVisitor.h" +#include "antares/solver/modelConverter/convertorVisitor.h" +#include "antares/solver/modelParser/Library.h" + +using namespace Antares::Solver; + +class ExpressionToNodeConvertorEmptyModel +{ +public: + ExpressionToNodeConvertorEmptyModel(ModelParser::Model&& model): + model_(std::move(model)) + { + } + + // Empty model + ExpressionToNodeConvertorEmptyModel() = default; + + NodeRegistry run(const std::string& input) + { + return ModelConverter::convertExpressionToNode(input, model_); + } + +private: + const ModelParser::Model model_; +}; + +static Nodes::LiteralNode* toLiteral(Nodes::Node* n) +{ + return dynamic_cast(n); +} + +BOOST_FIXTURE_TEST_CASE(empty_expression, ExpressionToNodeConvertorEmptyModel) +{ + BOOST_CHECK_EQUAL(run("").node, nullptr); +} + +BOOST_FIXTURE_TEST_CASE(negation, ExpressionToNodeConvertorEmptyModel) +{ + std::string expression = "-7"; + auto expr = run(expression); + BOOST_CHECK_EQUAL(expr.node->name(), "NegationNode"); + auto* nodeNeg = dynamic_cast(expr.node); + BOOST_REQUIRE(nodeNeg); + BOOST_CHECK_EQUAL(toLiteral(nodeNeg->child())->value(), 7); +} + +BOOST_AUTO_TEST_CASE(identifier) +{ + ModelParser::Model model{ + .id = "model0", + .description = "description", + .parameters = {{"param1", true, false}, {"param2", false, false}}, + .variables = {{"varP", "7", "pmin", ModelParser::ValueType::CONTINUOUS}}, + .ports = {}, + .port_field_definitions = {}, + .constraints = {}, + .objective = "objectives"}; + ExpressionToNodeConvertorEmptyModel converter(std::move(model)); + + { + std::string expression = "param1"; + auto expr = converter.run(expression); + BOOST_CHECK_EQUAL(expr.node->name(), "ParameterNode"); + } + + { + std::string expression = "varP"; + auto expr = converter.run(expression); + BOOST_CHECK_EQUAL(expr.node->name(), "VariableNode"); + } +} + +bool expectedMessage(const std::runtime_error& ex) +{ + BOOST_CHECK_EQUAL(ex.what(), + std::string("No parameter or variable found for this identifier: abc")); + return true; +} + +BOOST_AUTO_TEST_CASE(identifierNotFound) +{ + ModelParser::Model model{ + .id = "model0", + .description = "description", + .parameters = {{"param1", true, false}}, + .variables = {{"varP", "7", "pmin", ModelParser::ValueType::CONTINUOUS}}, + .ports = {}, + .port_field_definitions = {}, + .constraints = {}, + .objective = "objectives"}; + + std::string expression = "abc"; // not a param or var + BOOST_CHECK_EXCEPTION(ModelConverter::convertExpressionToNode(expression, model), + std::runtime_error, + expectedMessage); +} + +BOOST_FIXTURE_TEST_CASE(addTwoLiterals, ExpressionToNodeConvertorEmptyModel) +{ + const std::string expression = "1 + 2"; + auto expr = run(expression); + BOOST_CHECK_EQUAL(expr.node->name(), "SumNode"); + + auto* nodeSum = dynamic_cast(expr.node); + BOOST_REQUIRE(nodeSum); + auto operands = nodeSum->getOperands(); + BOOST_CHECK_EQUAL(toLiteral(operands[0])->value(), 1); + BOOST_CHECK_EQUAL(toLiteral(operands[1])->value(), 2); +} + +BOOST_FIXTURE_TEST_CASE(subtractTwoLiterals, ExpressionToNodeConvertorEmptyModel) +{ + const std::string expression = "6 - 3"; + auto expr = run(expression); + BOOST_CHECK_EQUAL(expr.node->name(), "SubtractionNode"); + + auto* nodeSub = dynamic_cast(expr.node); + BOOST_REQUIRE(nodeSub); + BOOST_CHECK_EQUAL(toLiteral(nodeSub->left())->value(), 6); + BOOST_CHECK_EQUAL(toLiteral(nodeSub->right())->value(), 3); +} + +BOOST_FIXTURE_TEST_CASE(multiplyTwoLiterals, ExpressionToNodeConvertorEmptyModel) +{ + std::string expression = "1 * 2"; + auto expr = run(expression); + BOOST_CHECK_EQUAL(expr.node->name(), "MultiplicationNode"); + + auto* nodeMult = dynamic_cast(expr.node); + BOOST_REQUIRE(nodeMult); + BOOST_CHECK_EQUAL(toLiteral(nodeMult->left())->value(), 1); + BOOST_CHECK_EQUAL(toLiteral(nodeMult->right())->value(), 2); +} + +BOOST_FIXTURE_TEST_CASE(divideTwoLiterals, ExpressionToNodeConvertorEmptyModel) +{ + const std::string expression = "6 / 3"; + auto expr = run(expression); + BOOST_CHECK_EQUAL(expr.node->name(), "DivisionNode"); + + auto* nodeDiv = dynamic_cast(expr.node); + BOOST_REQUIRE(nodeDiv); + BOOST_CHECK_EQUAL(toLiteral(nodeDiv->left())->value(), 6); + BOOST_CHECK_EQUAL(toLiteral(nodeDiv->right())->value(), 3); +} + +BOOST_FIXTURE_TEST_CASE(comparison, ExpressionToNodeConvertorEmptyModel) +{ + std::string expression = "1 = 2"; + auto expr = run(expression); + BOOST_CHECK_EQUAL(expr.node->name(), "EqualNode"); + + expression = "1 <= 5"; + expr = run(expression); + BOOST_CHECK_EQUAL(expr.node->name(), "LessThanOrEqualNode"); + + expression = "8364 >= 27"; + expr = run(expression); + BOOST_CHECK_EQUAL(expr.node->name(), "GreaterThanOrEqualNode"); + + auto* nodeGreater = dynamic_cast(expr.node); + BOOST_REQUIRE(nodeGreater); + BOOST_CHECK_EQUAL(toLiteral(nodeGreater->left())->value(), 8364); + BOOST_CHECK_EQUAL(toLiteral(nodeGreater->right())->value(), 27); +} + +BOOST_AUTO_TEST_CASE(medium_expression) +{ + ModelParser::Model model{ + .id = "model0", + .description = "description", + .parameters = {{"param1", true, false}, {"param2", false, false}}, + .variables = {{"varP", "7", "param1", ModelParser::ValueType::CONTINUOUS}}, + .ports = {}, + .port_field_definitions = {}, + .constraints = {}, + .objective = "objectives"}; + + ExpressionToNodeConvertorEmptyModel converter(std::move(model)); + std::string expression = "(12 * (4 - 1) + param1) / -(42 + 3 + varP)"; + auto expr = converter.run(expression); + + Registry registry; + + auto* param = registry.create("param1"); + auto* var = registry.create("varP"); + auto* l3 = registry.create(3); + auto* l42 = registry.create(42); + auto* l1 = registry.create(1); + auto* l4 = registry.create(4); + auto* l12 = registry.create(12); + auto* sub = registry.create(l4, l1); + auto* mult = registry.create(l12, sub); + auto* sum1 = registry.create(mult, param); + auto* sum2 = registry.create(l42, l3); + auto* sum3 = registry.create(sum2, var); + auto* neg = registry.create(sum3); + auto* div = registry.create(sum1, neg); + + Visitors::CompareVisitor cmp; + BOOST_CHECK(cmp.dispatch(expr.node, div)); +} diff --git a/src/tests/src/solver/modelParser/testModelTranslator.cpp b/src/tests/src/solver/modelParser/testModelTranslator.cpp index a22955b5db..9233b90767 100644 --- a/src/tests/src/solver/modelParser/testModelTranslator.cpp +++ b/src/tests/src/solver/modelParser/testModelTranslator.cpp @@ -1,5 +1,4 @@ -/* - * Copyright 2007-2024, RTE (https://www.rte-france.com) +/* * Copyright 2007-2024, RTE (https://www.rte-france.com) * See AUTHORS.txt * SPDX-License-Identifier: MPL-2.0 * This file is part of Antares-Simulator, @@ -25,6 +24,7 @@ #include +#include "antares/solver/expressions/nodes/Node.h" #include "antares/solver/modelConverter/modelConverter.h" #include "antares/solver/modelParser/Library.h" #include "antares/study/system-model/library.h" @@ -34,10 +34,14 @@ using namespace Antares::Solver; using namespace Antares::Study; -// Test empty library -BOOST_AUTO_TEST_CASE(Empty_library_is_valid) +struct Fixture { ModelParser::Library library; +}; + +// Test empty library +BOOST_FIXTURE_TEST_CASE(Empty_library_is_valid, Fixture) +{ SystemModel::Library lib = ModelConverter::convert(library); BOOST_CHECK(lib.Id().empty()); BOOST_CHECK(lib.Description().empty()); @@ -46,9 +50,9 @@ BOOST_AUTO_TEST_CASE(Empty_library_is_valid) } // Test library with id and description -BOOST_AUTO_TEST_CASE(library_id_description_properly_translated) +BOOST_FIXTURE_TEST_CASE(library_id_description_properly_translated, Fixture) + { - ModelParser::Library library; library.id = "test_id"; library.description = "test_description"; SystemModel::Library lib = ModelConverter::convert(library); @@ -57,9 +61,8 @@ BOOST_AUTO_TEST_CASE(library_id_description_properly_translated) } // Test library with port types -BOOST_AUTO_TEST_CASE(port_type_with_empty_fileds_properly_translated) +BOOST_FIXTURE_TEST_CASE(port_type_with_empty_fileds_properly_translated, Fixture) { - ModelParser::Library library; ModelParser::PortType portType1{"port1", "flow port", {}}; ModelParser::PortType portType2{"port2", "impedance port", {}}; library.port_types = {portType1, portType2}; @@ -81,9 +84,8 @@ BOOST_AUTO_TEST_CASE(port_type_with_empty_fileds_properly_translated) } // Test library with port types and fields -BOOST_AUTO_TEST_CASE(portType_with_fields_properly_translated) +BOOST_FIXTURE_TEST_CASE(portType_with_fields_properly_translated, Fixture) { - ModelParser::Library library; ModelParser::PortType portType1{"port1", "flow port", {"field1", "field2"}}; ModelParser::PortType portType2{"port2", "impedance port", {"field3", "field4"}}; library.port_types = {portType1, portType2}; @@ -97,28 +99,26 @@ BOOST_AUTO_TEST_CASE(portType_with_fields_properly_translated) } // Test library with models -BOOST_AUTO_TEST_CASE(empty_model_properly_translated) +BOOST_FIXTURE_TEST_CASE(empty_model_properly_translated, Fixture) { - ModelParser::Library library; ModelParser::Model model1{.id = "model1", .description = "description", - .parameters = {}, + .parameters = {{"param1", true, false}}, .variables = {}, .ports = {}, .port_field_definitions = {}, .constraints = {}, - .objective = "objectives"}; + .objective = "param1"}; library.models = {model1}; SystemModel::Library lib = ModelConverter::convert(library); BOOST_REQUIRE_EQUAL(lib.Models().size(), 1); BOOST_CHECK_EQUAL(lib.Models().at("model1").Id(), "model1"); - BOOST_CHECK_EQUAL(lib.Models().at("model1").Objective().Value(), "objectives"); + BOOST_CHECK_EQUAL(lib.Models().at("model1").Objective().Value(), "param1"); } // Test library with models and parameters -BOOST_AUTO_TEST_CASE(model_parameters_properly_translated) +BOOST_FIXTURE_TEST_CASE(model_parameters_properly_translated, Fixture) { - ModelParser::Library library; ModelParser::Model model1{.id = "model1", .description = "description", .parameters = {{"param1", true, false}, {"param2", false, false}}, @@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(model_parameters_properly_translated) .ports = {}, .port_field_definitions{}, .constraints{}, - .objective = "objectives"}; + .objective = ""}; library.models = {model1}; SystemModel::Library lib = ModelConverter::convert(library); auto& model = lib.Models().at("model1"); @@ -136,27 +136,24 @@ BOOST_AUTO_TEST_CASE(model_parameters_properly_translated) BOOST_CHECK_EQUAL(parameter1.Id(), "param1"); BOOST_CHECK(parameter1.isTimeDependent()); BOOST_CHECK(!parameter1.isScenarioDependent()); - BOOST_CHECK_EQUAL(parameter1.Type(), SystemModel::ValueType::FLOAT); BOOST_CHECK_EQUAL(parameter2.Id(), "param2"); BOOST_CHECK(!parameter2.isTimeDependent()); BOOST_CHECK(!parameter2.isScenarioDependent()); - BOOST_CHECK_EQUAL(parameter2.Type(), SystemModel::ValueType::FLOAT); } // Test library with models and variables -BOOST_AUTO_TEST_CASE(model_variables_properly_translated) +BOOST_FIXTURE_TEST_CASE(model_variables_properly_translated, Fixture) { - ModelParser::Library library; ModelParser::Model model1{ .id = "model1", .description = "description", - .parameters = {}, + .parameters = {{"pmax", true, false}}, .variables = {{"var1", "7", "pmax", ModelParser::ValueType::BOOL}, - {"var2", "99999999.9999999", "vcost", ModelParser::ValueType::INTEGER}}, + {"var2", "99999999.9999999", "var1", ModelParser::ValueType::INTEGER}}, .ports = {}, .port_field_definitions = {}, .constraints = {}, - .objective = "objectives"}; + .objective = "var1"}; library.models = {model1}; SystemModel::Library lib = ModelConverter::convert(library); auto& model = lib.Models().at("model1"); @@ -169,7 +166,7 @@ BOOST_AUTO_TEST_CASE(model_variables_properly_translated) BOOST_CHECK_EQUAL(variable1.Type(), SystemModel::ValueType::BOOL); BOOST_CHECK_EQUAL(variable2.Id(), "var2"); BOOST_CHECK_EQUAL(variable2.LowerBound().Value(), "99999999.9999999"); - BOOST_CHECK_EQUAL(variable2.UpperBound().Value(), "vcost"); + BOOST_CHECK_EQUAL(variable2.UpperBound().Value(), "var1"); BOOST_CHECK_EQUAL(variable2.Type(), SystemModel::ValueType::INTEGER); } @@ -177,6 +174,7 @@ BOOST_AUTO_TEST_CASE(model_variables_properly_translated) BOOST_AUTO_TEST_CASE(model_ports_properly_translated, *boost::unit_test::disabled()) { ModelParser::Library library; + Registry registry; ModelParser::Model model1{.id = "model1", .description = "description", .parameters = {}, @@ -184,10 +182,10 @@ BOOST_AUTO_TEST_CASE(model_ports_properly_translated, *boost::unit_test::disable .ports = {{"port1", "flow"}, {"port2", "impedance"}}, .port_field_definitions = {}, .constraints = {}, - .objective = "objectives"}; + .objective = ""}; library.models = {model1}; SystemModel::Library lib = ModelConverter::convert(library); - auto& model = lib.Models().at("model1"); + [[maybe_unused]] auto& model = lib.Models().at("model1"); // BOOST_REQUIRE_EQUAL(model.Ports().size(), 2); // auto& port1 = model.Ports().at("port1"); // auto& port2 = model.Ports().at("port2"); @@ -198,18 +196,18 @@ BOOST_AUTO_TEST_CASE(model_ports_properly_translated, *boost::unit_test::disable } // Test library with models and constraints -BOOST_AUTO_TEST_CASE(model_constraints_properly_translated) +BOOST_FIXTURE_TEST_CASE(model_constraints_properly_translated, Fixture) { - ModelParser::Library library; ModelParser::Model model1{.id = "model1", .description = "description", - .parameters = {}, + .parameters = {{"expression1", true, false}, + {"expression2", true, false}}, .variables = {}, .ports = {}, .port_field_definitions = {}, .constraints = {{"constraint1", "expression1"}, {"constraint2", "expression2"}}, - .objective = "objectives"}; + .objective = ""}; library.models = {model1}; SystemModel::Library lib = ModelConverter::convert(library); auto& model = lib.Models().at("model1"); @@ -223,28 +221,27 @@ BOOST_AUTO_TEST_CASE(model_constraints_properly_translated) } // Test with 2 models -BOOST_AUTO_TEST_CASE(multiple_models_properly_translated) +BOOST_FIXTURE_TEST_CASE(multiple_models_properly_translated, Fixture) { - ModelParser::Library library; ModelParser::Model model1{ .id = "model1", .description = "description", .parameters = {{"param1", true, false}, {"param2", false, false}}, - .variables = {{"varP", "7", "pmin", ModelParser::ValueType::CONTINUOUS}}, + .variables = {{"varP", "7", "param2", ModelParser::ValueType::CONTINUOUS}}, .ports = {}, .port_field_definitions = {}, .constraints = {}, - .objective = "objectives"}; + .objective = ""}; ModelParser::Model model2{ .id = "model2", .description = "description", .parameters = {}, - .variables = {{"var1", "7", "pmax", ModelParser::ValueType::BOOL}, - {"var2", "99999999.9999999", "vcost", ModelParser::ValueType::INTEGER}}, + .variables = {{"var1", "7", "8", ModelParser::ValueType::BOOL}, + {"var2", "99999999.9999999", "var1", ModelParser::ValueType::INTEGER}}, .ports = {}, .port_field_definitions = {}, .constraints = {}, - .objective = "objectives"}; + .objective = ""}; library.models = {model1, model2}; SystemModel::Library lib = ModelConverter::convert(library); BOOST_REQUIRE_EQUAL(lib.Models().size(), 2); diff --git a/src/tests/src/solver/modelParser/test_full.cpp b/src/tests/src/solver/modelParser/test_full.cpp index 71824c692d..4901fa610b 100644 --- a/src/tests/src/solver/modelParser/test_full.cpp +++ b/src/tests/src/solver/modelParser/test_full.cpp @@ -25,6 +25,7 @@ #include +#include "antares/solver/expressions/nodes/Node.h" #include "antares/solver/modelConverter/modelConverter.h" #include "antares/solver/modelParser/Library.h" #include "antares/solver/modelParser/parser.h" @@ -39,14 +40,12 @@ using namespace Antares::Study; void checkParameter(const SystemModel::Parameter& parameter, const std::string& name, bool timeDependent, - bool scenarioDependent, - SystemModel::ValueType type) + bool scenarioDependent) { std::cout << "Parameter: " << parameter.Id() << std::endl; BOOST_CHECK_EQUAL(parameter.Id(), name); BOOST_CHECK_EQUAL(parameter.isTimeDependent(), timeDependent); BOOST_CHECK_EQUAL(parameter.isScenarioDependent(), scenarioDependent); - BOOST_CHECK_EQUAL(parameter.Type(), type); } void checkVariable(const SystemModel::Variable& variable, @@ -116,7 +115,7 @@ BOOST_AUTO_TEST_CASE(test_full) - port: injection_port field: flow definition: generation - objective: expec(sum(cost * generation)) + objective: cost * generation - id: node description: A basic balancing node model @@ -125,7 +124,7 @@ BOOST_AUTO_TEST_CASE(test_full) type: flow binding-constraints: - id: balance - expression: sum_connections(injection_port.flow) = 0 + expression: injection_port = 0 - id: spillage description: A basic spillage model @@ -203,7 +202,7 @@ BOOST_AUTO_TEST_CASE(test_full) definition: injection - withdrawal constraints: - id: Level equation - expression: level[t] - level[t-1] - efficiency * injection + withdrawal = inflows + expression: level - level - efficiency * injection + withdrawal = inflows - id: thermal-cluster-dhd description: DHD model for thermal cluster @@ -251,12 +250,12 @@ BOOST_AUTO_TEST_CASE(test_full) - id: Min generation expression: generation >= nb_on * p_min - id: Number of units variation - expression: nb_on = nb_on[t-1] + nb_start - nb_stop + expression: nb_on = nb_on + nb_start - nb_stop - id: Min up time - expression: sum(t-d_min_up + 1 .. t, nb_start) <= nb_on + expression: t-d_min_up + 1 <= nb_on - id: Min down time - expression: sum(t-d_min_down + 1 .. t, nb_stop) <= nb_units_max[t-d_min_down] - nb_on - objective: expec(sum(cost * generation)) + expression: t-d_min_down + 1 <= nb_units_max - nb_on + objective: cost * generation )"s; try @@ -279,7 +278,7 @@ BOOST_AUTO_TEST_CASE(test_full) BOOST_REQUIRE_EQUAL(lib.Models().size(), 7); auto& model0 = lib.Models().at("generator"); BOOST_CHECK_EQUAL(model0.Id(), "generator"); - BOOST_CHECK_EQUAL(model0.Objective().Value(), "expec(sum(cost * generation))"); + BOOST_CHECK_EQUAL(model0.Objective().Value(), "cost * generation"); BOOST_REQUIRE_EQUAL(model0.getConstraints().size(), 0); BOOST_REQUIRE_EQUAL(model0.Parameters().size(), 2); @@ -287,16 +286,8 @@ BOOST_AUTO_TEST_CASE(test_full) // BOOST_REQUIRE_EQUAL(model0.Ports().size(), 1); Unsuported // BOOST_REQUIRE_EQUAL(model0.PortFieldDefinitions().size(), 1); Unsuported - checkParameter(model0.Parameters().at("cost"), - "cost", - false, - false, - SystemModel::ValueType::FLOAT); - checkParameter(model0.Parameters().at("p_max"), - "p_max", - false, - false, - SystemModel::ValueType::FLOAT); + checkParameter(model0.Parameters().at("cost"), "cost", false, false); + checkParameter(model0.Parameters().at("p_max"), "p_max", false, false); checkVariable(model0.Variables().at("generation"), "generation", @@ -324,11 +315,7 @@ BOOST_AUTO_TEST_CASE(test_full) // BOOST_REQUIRE_EQUAL(model2.Ports().size(), 1); Unsuported // BOOST_REQUIRE_EQUAL(model2.PortFieldDefinitions().size(), 1); Unsuported - checkParameter(model2.Parameters().at("cost"), - "cost", - false, - false, - SystemModel::ValueType::FLOAT); + checkParameter(model2.Parameters().at("cost"), "cost", false, false); checkVariable(model2.Variables().at("spillage"), "spillage", "0", @@ -342,11 +329,7 @@ BOOST_AUTO_TEST_CASE(test_full) BOOST_REQUIRE_EQUAL(model3.Variables().size(), 1); // BOOST_REQUIRE_EQUAL(model3.Ports().size(), 1); Unsuported // BOOST_REQUIRE_EQUAL(model3.PortFieldDefinitions().size(), 1); Unsuported - checkParameter(model3.Parameters().at("cost"), - "cost", - false, - false, - SystemModel::ValueType::FLOAT); + checkParameter(model3.Parameters().at("cost"), "cost", false, false); checkVariable(model3.Variables().at("unsupplied_energy"), "unsupplied_energy", "0", @@ -360,11 +343,7 @@ BOOST_AUTO_TEST_CASE(test_full) BOOST_REQUIRE_EQUAL(model4.Variables().size(), 0); // BOOST_REQUIRE_EQUAL(model4.Ports().size(), 1); Unsuported // BOOST_REQUIRE_EQUAL(model4.PortFieldDefinitions().size(), 1); Unsuported - checkParameter(model4.Parameters().at("demand"), - "demand", - true, - true, - SystemModel::ValueType::FLOAT); + checkParameter(model4.Parameters().at("demand"), "demand", true, true); auto& model5 = lib.Models().at("short-term-storage"); BOOST_CHECK_EQUAL(model5.Id(), "short-term-storage"); @@ -373,36 +352,12 @@ BOOST_AUTO_TEST_CASE(test_full) BOOST_REQUIRE_EQUAL(model5.Variables().size(), 3); // BOOST_REQUIRE_EQUAL(model5.Ports().size(), 1); Unsuported // BOOST_REQUIRE_EQUAL(model5.PortFieldDefinitions().size(), 1); Unsuported - checkParameter(model5.Parameters().at("efficiency"), - "efficiency", - true, - true, - SystemModel::ValueType::FLOAT); - checkParameter(model5.Parameters().at("level_min"), - "level_min", - true, - true, - SystemModel::ValueType::FLOAT); - checkParameter(model5.Parameters().at("level_max"), - "level_max", - true, - true, - SystemModel::ValueType::FLOAT); - checkParameter(model5.Parameters().at("p_max_withdrawal"), - "p_max_withdrawal", - true, - true, - SystemModel::ValueType::FLOAT); - checkParameter(model5.Parameters().at("p_max_injection"), - "p_max_injection", - true, - true, - SystemModel::ValueType::FLOAT); - checkParameter(model5.Parameters().at("inflows"), - "inflows", - true, - true, - SystemModel::ValueType::FLOAT); + checkParameter(model5.Parameters().at("efficiency"), "efficiency", true, true); + checkParameter(model5.Parameters().at("level_min"), "level_min", true, true); + checkParameter(model5.Parameters().at("level_max"), "level_max", true, true); + checkParameter(model5.Parameters().at("p_max_withdrawal"), "p_max_withdrawal", true, true); + checkParameter(model5.Parameters().at("p_max_injection"), "p_max_injection", true, true); + checkParameter(model5.Parameters().at("inflows"), "inflows", true, true); checkVariable(model5.Variables().at("injection"), "injection", "0", @@ -420,7 +375,7 @@ BOOST_AUTO_TEST_CASE(test_full) SystemModel::ValueType::FLOAT); checkConstraint(model5.getConstraints().at("Level equation"), "Level equation", - "level[t] - level[t-1] - efficiency * injection + withdrawal = inflows"); + "level - level - efficiency * injection + withdrawal = inflows"); auto& model6 = lib.Models().at("thermal-cluster-dhd"); BOOST_CHECK_EQUAL(model6.Id(), "thermal-cluster-dhd"); @@ -429,41 +384,13 @@ BOOST_AUTO_TEST_CASE(test_full) BOOST_REQUIRE_EQUAL(model6.Variables().size(), 4); // BOOST_REQUIRE_EQUAL(model6.Ports().size(), 1); Unsuported // BOOST_REQUIRE_EQUAL(model6.PortFieldDefinitions().size(), 1); Unsuported - checkParameter(model6.Parameters().at("cost"), - "cost", - true, - true, - SystemModel::ValueType::FLOAT); - checkParameter(model6.Parameters().at("p_min"), - "p_min", - true, - true, - SystemModel::ValueType::FLOAT); - checkParameter(model6.Parameters().at("p_max"), - "p_max", - true, - true, - SystemModel::ValueType::FLOAT); - checkParameter(model6.Parameters().at("d_min_up"), - "d_min_up", - true, - true, - SystemModel::ValueType::FLOAT); - checkParameter(model6.Parameters().at("d_min_down"), - "d_min_down", - true, - true, - SystemModel::ValueType::FLOAT); - checkParameter(model6.Parameters().at("nb_units_max"), - "nb_units_max", - true, - true, - SystemModel::ValueType::FLOAT); - checkParameter(model6.Parameters().at("nb_failures"), - "nb_failures", - true, - true, - SystemModel::ValueType::FLOAT); + checkParameter(model6.Parameters().at("cost"), "cost", true, true); + checkParameter(model6.Parameters().at("p_min"), "p_min", true, true); + checkParameter(model6.Parameters().at("p_max"), "p_max", true, true); + checkParameter(model6.Parameters().at("d_min_up"), "d_min_up", true, true); + checkParameter(model6.Parameters().at("d_min_down"), "d_min_down", true, true); + checkParameter(model6.Parameters().at("nb_units_max"), "nb_units_max", true, true); + checkParameter(model6.Parameters().at("nb_failures"), "nb_failures", true, true); checkVariable(model6.Variables().at("generation"), "generation", "0", @@ -492,15 +419,14 @@ BOOST_AUTO_TEST_CASE(test_full) "generation >= nb_on * p_min"); checkConstraint(model6.getConstraints().at("Number of units variation"), "Number of units variation", - "nb_on = nb_on[t-1] + nb_start - nb_stop"); + "nb_on = nb_on + nb_start - nb_stop"); checkConstraint(model6.getConstraints().at("Min up time"), "Min up time", - "sum(t-d_min_up + 1 .. t, nb_start) <= nb_on"); - checkConstraint( - model6.getConstraints().at("Min down time"), - "Min down time", - "sum(t-d_min_down + 1 .. t, nb_stop) <= nb_units_max[t-d_min_down] - nb_on"); - BOOST_CHECK_EQUAL(model6.Objective().Value(), "expec(sum(cost * generation))"); + "t-d_min_up + 1 <= nb_on"); + checkConstraint(model6.getConstraints().at("Min down time"), + "Min down time", + "t-d_min_down + 1 <= nb_units_max - nb_on"); + BOOST_CHECK_EQUAL(model6.Objective().Value(), "cost * generation"); } catch (const YAML::Exception& e) { diff --git a/src/vcpkg.json b/src/vcpkg.json index a4a3e12fcf..68a34fa53c 100644 --- a/src/vcpkg.json +++ b/src/vcpkg.json @@ -37,6 +37,9 @@ }, { "name": "yaml-cpp" + }, + { + "name": "antlr4" } ] }