diff --git a/sonar-project.properties b/sonar-project.properties index 2a76f458da..4e499b93f4 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -12,8 +12,8 @@ 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 e93c5fcd58..6d57164639 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/include/antares/solver/expressions/visitors/AstDOTStyleVisitor.h b/src/solver/expressions/include/antares/solver/expressions/visitors/AstDOTStyleVisitor.h index a8e4e1ff43..d1e1fcd581 100644 --- a/src/solver/expressions/include/antares/solver/expressions/visitors/AstDOTStyleVisitor.h +++ b/src/solver/expressions/include/antares/solver/expressions/visitors/AstDOTStyleVisitor.h @@ -116,7 +116,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/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/libModelObject/CMakeLists.txt b/src/solver/libModelObject/CMakeLists.txt index bb489afd7e..d1272d6b5a 100644 --- a/src/solver/libModelObject/CMakeLists.txt +++ b/src/solver/libModelObject/CMakeLists.txt @@ -28,6 +28,7 @@ target_include_directories(antares-solver-libObjectModel ) target_link_libraries(antares-solver-libObjectModel PUBLIC + Antares::solver-expressions ) install(DIRECTORY include/antares DESTINATION "include" diff --git a/src/solver/libModelObject/include/antares/solver/libObjectModel/expression.h b/src/solver/libModelObject/include/antares/solver/libObjectModel/expression.h index 87fefbc8c5..083f7e2415 100644 --- a/src/solver/libModelObject/include/antares/solver/libObjectModel/expression.h +++ b/src/solver/libModelObject/include/antares/solver/libObjectModel/expression.h @@ -22,6 +22,8 @@ #include +#include + namespace Antares::Solver::ObjectModel { @@ -30,8 +32,9 @@ class Expression public: Expression() = default; - explicit Expression(std::string value): - value_(std::move(value)) + explicit Expression(std::string value, Nodes::Node* node): + value_(std::move(value)), + node_(node) { } @@ -40,8 +43,15 @@ class Expression return value_; } + const Nodes::Node* Node() const + { + return node_; + } + private: std::string value_; + + Nodes::Node* node_; }; } // namespace Antares::Solver::ObjectModel diff --git a/src/solver/modelConverter/CMakeLists.txt b/src/solver/modelConverter/CMakeLists.txt index d679c3f7ff..4bbc23cc4b 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,11 @@ target_link_libraries(modelConverter PRIVATE Antares::antares-solver-libObjectModel Antares::modelParser + Antares::antlr-interface + Antares::solver-expressions + Antares::logs ) 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..690ba75852 --- /dev/null +++ b/src/solver/modelConverter/convertorVisitor.cpp @@ -0,0 +1,283 @@ +/* + * 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 + +#include "ExprLexer.h" +#include "ExprParser.h" +#include "antlr4-runtime.h" + +namespace Antares::Solver::ModelConverter +{ + +using namespace Antares::Solver::Nodes; + +static Node* toNodePtr(const std::any& a) +{ + return std::any_cast(a); +} + +Node* convertExpressionToNode(const std::string& exprStr, + Antares::Solver::Registry& registry, + const ModelParser::Model& model) +{ + if (exprStr.empty()) + { + return nullptr; + } + + antlr4::ANTLRInputStream input(exprStr); + ExprLexer lexer(&input); + antlr4::CommonTokenStream tokens(&lexer); + ExprParser parser(&tokens); + + ExprParser::ExprContext* tree = parser.expr(); + + ConvertorVisitor visitor(registry, model); + return toNodePtr(visitor.visit(tree)); +} + +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::exception +{ +public: + NoParameterOrVariableWithThisName(const std::string& id) + { + msg_ = "No parameter or variable found for this identifier: " + id; + } + + const char* what() const noexcept override + { + return msg_.c_str(); + } + +private: + std::string msg_; +}; + +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)); + } + } + + logs.error() << "No parameter or variable found with this name: " << context->getText(); + throw NoParameterOrVariableWithThisName(context->getText()); +} + +std::any ConvertorVisitor::visitMuldiv(ExprParser::MuldivContext* context) +{ + auto* left = toNodePtr(visit(context->expr(0))); + auto* right = toNodePtr(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) +{ + auto n = toNodePtr(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) +{ + auto* left = toNodePtr(visit(context->expr(0))); + auto* right = toNodePtr(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) +{ + auto* left = toNodePtr(visit(context->expr(0))); + auto* right = toNodePtr(visit(context->expr(1))); + + std::string op = context->op->getText(); + return (op == "+") ? static_cast(registry_.create(left, right)) + : static_cast(registry_.create(left, right)); +} + +// TODO implement this +std::any ConvertorVisitor::visitPortField([[maybe_unused]] ExprParser::PortFieldContext* context) +{ + throw std::runtime_error(std::string("Node portfield not implemented yet")); + return std::any(); +} + +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 std::runtime_error(std::string("Node time index not implemented yet")); + return std::any(); +} + +// TODO implement this +std::any ConvertorVisitor::visitTimeShift([[maybe_unused]] ExprParser::TimeShiftContext* context) +{ + throw std::runtime_error(std::string("Node time shift not implemented yet")); + return std::any(); +} + +// TODO implement this +std::any ConvertorVisitor::visitFunction([[maybe_unused]] ExprParser::FunctionContext* context) +{ + throw std::runtime_error(std::string("Node function not implemented yet")); + return std::any(); +} + +// TODO implement this +std::any ConvertorVisitor::visitTimeSum([[maybe_unused]] ExprParser::TimeSumContext* context) +{ + throw std::runtime_error(std::string("Node time sum not implemented yet")); + return std::any(); +} + +// TODO implement this +std::any ConvertorVisitor::visitAllTimeSum([[maybe_unused]] ExprParser::AllTimeSumContext* context) +{ + throw std::runtime_error(std::string("Node all time sum not implemented yet")); + return std::any(); +} + +// 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(toNodePtr(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 std::runtime_error(std::string("Node right atom not implemented yet")); + return std::any(); +} + +// TODO implement this +std::any ConvertorVisitor::visitShift([[maybe_unused]] ExprParser::ShiftContext* context) +{ + throw std::runtime_error(std::string("Node shift not implemented yet")); + return std::any(); +} + +// TODO implement this +std::any ConvertorVisitor::visitShiftAddsub( + [[maybe_unused]] ExprParser::ShiftAddsubContext* context) +{ + throw std::runtime_error(std::string("Node shift add sub not implemented yet")); + return std::any(); +} + +// TODO implement this +std::any ConvertorVisitor::visitShiftMuldiv( + [[maybe_unused]] ExprParser::ShiftMuldivContext* context) +{ + throw std::runtime_error(std::string("Node shift mul div not implemented yet")); + return std::any(); +} + +// TODO implement this +std::any ConvertorVisitor::visitRightMuldiv( + [[maybe_unused]] ExprParser::RightMuldivContext* context) +{ + throw std::runtime_error(std::string("Node right mul div not implemented yet")); + return std::any(); +} + +// TODO implement this +std::any ConvertorVisitor::visitSignedExpression( + [[maybe_unused]] ExprParser::SignedExpressionContext* context) +{ + throw std::runtime_error(std::string("Node signed expression not implemented yet")); + return std::any(); +} + +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..e3f5542897 --- /dev/null +++ b/src/solver/modelConverter/include/antares/solver/modelConverter/convertorVisitor.h @@ -0,0 +1,74 @@ +/* + * 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 +#include "antares/solver/modelParser/Library.h" + +namespace Antares::Solver::ModelConverter +{ + +Nodes::Node* convertExpressionToNode(const std::string& exprStr, + Registry& registry, + const ModelParser::Model& model); + +/// 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; + + Registry& registry_; + 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 4d2212b749..07026cdc11 100644 --- a/src/solver/modelConverter/include/antares/solver/modelConverter/modelConverter.h +++ b/src/solver/modelConverter/include/antares/solver/modelConverter/modelConverter.h @@ -1,4 +1,3 @@ - /* * Copyright 2007-2024, RTE (https://www.rte-france.com) * See AUTHORS.txt @@ -22,6 +21,9 @@ #pragma once +#include +#include + namespace Antares::Solver { namespace ObjectModel @@ -37,5 +39,5 @@ class Library; namespace Antares::Solver::ModelConverter { -Antares::Solver::ObjectModel::Library convert(const Antares::Solver::ModelParser::Library& library); +ObjectModel::Library convert(const ModelParser::Library& library, Registry& registry); } diff --git a/src/solver/modelConverter/modelConverter.cpp b/src/solver/modelConverter/modelConverter.cpp index a103c8fcd2..c0b66d654c 100644 --- a/src/solver/modelConverter/modelConverter.cpp +++ b/src/solver/modelConverter/modelConverter.cpp @@ -30,6 +30,7 @@ #include "antares/solver/libObjectModel/port.h" #include "antares/solver/libObjectModel/portType.h" #include "antares/solver/libObjectModel/variable.h" +#include "antares/solver/modelConverter/convertorVisitor.h" #include "antares/solver/modelParser/Library.h" namespace Antares::Solver::ModelConverter @@ -41,21 +42,18 @@ namespace Antares::Solver::ModelConverter * \param model The ModelParser::Model object containing parameters. * \return A vector of ObjectModel::Parameter objects. */ -std::vector convertTypes( - const Antares::Solver::ModelParser::Library& library) +std::vector convertTypes(const ModelParser::Library& library) { - // Convert portTypes to Antares::Solver::ObjectModel::PortType - std::vector out; + // Convert portTypes to ObjectModel::PortType + std::vector out; for (const auto& portType: library.port_types) { - std::vector fields; + std::vector fields; for (const auto& field: portType.fields) { - fields.emplace_back(Antares::Solver::ObjectModel::PortField{field}); + fields.emplace_back(ObjectModel::PortField{field}); } - Antares::Solver::ObjectModel::PortType portTypeModel(portType.id, - portType.description, - std::move(fields)); + ObjectModel::PortType portTypeModel(portType.id, portType.description, std::move(fields)); out.emplace_back(std::move(portTypeModel)); } return out; @@ -68,19 +66,16 @@ std::vector convertTypes( * \return The corresponding ObjectModel::ValueType. * \throws std::runtime_error if the type is unknown. */ -std::vector convertParameters( - const Antares::Solver::ModelParser::Model& model) +std::vector convertParameters(const ModelParser::Model& model) { - std::vector parameters; + std::vector parameters; for (const auto& parameter: model.parameters) { - parameters.emplace_back(Antares::Solver::ObjectModel::Parameter{ + parameters.emplace_back(ObjectModel::Parameter{ parameter.id, - Antares::Solver::ObjectModel::ValueType::FLOAT, // TODO: change to correct type - static_cast( - parameter.time_dependent), - static_cast( - parameter.scenario_dependent)}); + ObjectModel::ValueType::FLOAT, // TODO: change to correct type + static_cast(parameter.time_dependent), + static_cast(parameter.scenario_dependent)}); } return parameters; } @@ -91,19 +86,19 @@ std::vector convertParameters( * \param model The ModelParser::Model object containing variables. * \return A vector of ObjectModel::Variable objects. */ -Antares::Solver::ObjectModel::ValueType convertType(Antares::Solver::ModelParser::ValueType type) +ObjectModel::ValueType convertType(ModelParser::ValueType type) { using namespace std::string_literals; switch (type) { - case Antares::Solver::ModelParser::ValueType::CONTINUOUS: - return Antares::Solver::ObjectModel::ValueType::FLOAT; - case Antares::Solver::ModelParser::ValueType::INTEGER: - return Antares::Solver::ObjectModel::ValueType::INTEGER; - case Antares::Solver::ModelParser::ValueType::BOOL: - return Antares::Solver::ObjectModel::ValueType::BOOL; + case ModelParser::ValueType::CONTINUOUS: + return ObjectModel::ValueType::FLOAT; + case ModelParser::ValueType::INTEGER: + return ObjectModel::ValueType::INTEGER; + case ModelParser::ValueType::BOOL: + return ObjectModel::ValueType::BOOL; default: - throw std::runtime_error("Unknown type: " + Antares::Solver::ModelParser::toString(type)); + throw std::runtime_error("Unknown type: " + ModelParser::toString(type)); } } @@ -113,16 +108,18 @@ Antares::Solver::ObjectModel::ValueType convertType(Antares::Solver::ModelParser * \param model The ModelParser::Model object containing ports. * \return A vector of ObjectModel::Port objects. */ -std::vector convertVariables( - const Antares::Solver::ModelParser::Model& model) +std::vector convertVariables(const ModelParser::Model& model, + Registry& registry) { - std::vector variables; + std::vector variables; for (const auto& variable: model.variables) { - variables.emplace_back(Antares::Solver::ObjectModel::Variable{ + variables.emplace_back(ObjectModel::Variable{ variable.id, - Antares::Solver::ObjectModel::Expression{variable.lower_bound}, - Antares::Solver::ObjectModel::Expression{variable.upper_bound}, + ObjectModel::Expression{variable.lower_bound, + convertExpressionToNode(variable.lower_bound, registry, model)}, + ObjectModel::Expression{variable.upper_bound, + convertExpressionToNode(variable.upper_bound, registry, model)}, convertType(variable.variable_type)}); } return variables; @@ -134,26 +131,26 @@ std::vector convertVariables( * \param model The ModelParser::Model object containing constraints. * \return A vector of ObjectModel::Constraint objects. */ -std::vector convertPorts( - const Antares::Solver::ModelParser::Model& model) +std::vector convertPorts([[maybe_unused]] const ModelParser::Model& model) { - std::vector ports; - for (const auto& port: model.ports) - { - // ports.emplace_back(Antares::Solver::ObjectModel::Port{port.name, port.type}); - } + std::vector ports; + /* for (const auto& port: model.ports) */ + /* { */ + /* ports.emplace_back(ObjectModel::Port{port.name, port.type}); */ + /* } */ return ports; } -std::vector convertConstraints( - const Antares::Solver::ModelParser::Model& model) +std::vector convertConstraints(const ModelParser::Model& model, + Registry& registry) { - std::vector constraints; + std::vector constraints; for (const auto& constraint: model.constraints) { - constraints.emplace_back(Antares::Solver::ObjectModel::Constraint{ - constraint.id, - Antares::Solver::ObjectModel::Expression{constraint.expression}}); + Nodes::Node* expr = convertExpressionToNode(constraint.expression, registry, model); + constraints.emplace_back( + ObjectModel::Constraint{constraint.id, + ObjectModel::Expression{constraint.expression, expr}}); } return constraints; } @@ -164,21 +161,22 @@ std::vector convertConstraints( * \param library The ModelParser::Library object containing models. * \return A vector of ObjectModel::Model objects. */ -std::vector convertModels( - const Antares::Solver::ModelParser::Library& library) +std::vector convertModels(const ModelParser::Library& library, + Registry& registry) { - std::vector models; + std::vector models; for (const auto& model: library.models) { - Antares::Solver::ObjectModel::ModelBuilder modelBuilder; - std::vector parameters = convertParameters(model); - std::vector variables = convertVariables(model); - std::vector ports = convertPorts(model); - std::vector constraints = convertConstraints( - model); + ObjectModel::ModelBuilder modelBuilder; + std::vector parameters = convertParameters(model); + std::vector variables = convertVariables(model, registry); + std::vector ports = convertPorts(model); + std::vector constraints = convertConstraints(model, registry); + + auto nodeObjective = convertExpressionToNode(model.objective, registry, model); auto modelObj = modelBuilder.withId(model.id) - .withObjective(Antares::Solver::ObjectModel::Expression{model.objective}) + .withObjective(ObjectModel::Expression{model.objective, nodeObjective}) .withParameters(std::move(parameters)) .withVariables(std::move(variables)) .withPorts(std::move(ports)) @@ -195,16 +193,16 @@ std::vector convertModels( * \param library The ModelParser::Library object to convert. * \return The corresponding ObjectModel::Library object. */ -Antares::Solver::ObjectModel::Library convert(const Antares::Solver::ModelParser::Library& library) +ObjectModel::Library convert(const ModelParser::Library& library, Registry& registry) { - Antares::Solver::ObjectModel::LibraryBuilder builder; - std::vector portTypes = convertTypes(library); - std::vector models = convertModels(library); - Antares::Solver::ObjectModel::Library lib = builder.withId(library.id) - .withDescription(library.description) - .withPortTypes(std::move(portTypes)) - .withModels(std::move(models)) - .build(); + ObjectModel::LibraryBuilder builder; + std::vector portTypes = convertTypes(library); + std::vector models = convertModels(library, registry); + ObjectModel::Library lib = builder.withId(library.id) + .withDescription(library.description) + .withPortTypes(std::move(portTypes)) + .withModels(std::move(models)) + .build(); return lib; } 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 e694d66126..4f8bc3819d 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 ) @@ -16,6 +17,7 @@ target_link_libraries(TestModelParser Antares::modelConverter Antares::modelParser Antares::antares-solver-libObjectModel + Antares::antlr-interface ) # Storing test-toybox under the folder Unit-tests in the IDE @@ -25,4 +27,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..2d2be338bb --- /dev/null +++ b/src/tests/src/solver/modelParser/testConvertorVisitor.cpp @@ -0,0 +1,189 @@ +/* + * 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 "antares/solver/expressions/Registry.hxx" +#include "antares/solver/expressions/visitors/AstDOTStyleVisitor.h" +#include "antares/solver/libObjectModel/library.h" +#include "antares/solver/modelConverter/convertorVisitor.h" +#include "antares/solver/modelConverter/modelConverter.h" +#include "antares/solver/modelParser/Library.h" + +using namespace Antares::Solver; + +struct Fixture +{ + ModelParser::Model model; + Antares::Solver::Registry registry; +}; + +// TODO remove, used for debug +static void printTree(Nodes::Node* n) +{ + std::ofstream out("/tmp/tree.dot"); + Visitors::AstDOTStyleVisitor dot; + dot(out, n); +} + +static Nodes::LiteralNode* toLiteral(Nodes::Node* n) +{ + return dynamic_cast(n); +} + +BOOST_FIXTURE_TEST_CASE(empty_expression, Fixture) +{ + auto* node = ModelConverter::convertExpressionToNode("", registry, model); + BOOST_CHECK_EQUAL(node, nullptr); +} + +BOOST_FIXTURE_TEST_CASE(negation, Fixture) +{ + std::string expression = "-7"; + auto* n = ModelConverter::convertExpressionToNode(expression, registry, model); + BOOST_CHECK_EQUAL(n->name(), "NegationNode"); + auto* nodeNeg = dynamic_cast(n); + BOOST_CHECK_EQUAL(toLiteral(nodeNeg->child())->value(), 7); +} + +BOOST_FIXTURE_TEST_CASE(identifier, Fixture) +{ + ModelParser::Library library; + ModelParser::Model model0{ + .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"}; + + std::string expression = "param1"; + auto* n = ModelConverter::convertExpressionToNode(expression, registry, model0); + BOOST_CHECK_EQUAL(n->name(), "ParameterNode"); + + expression = "varP"; + n = ModelConverter::convertExpressionToNode(expression, registry, model0); + BOOST_CHECK_EQUAL(n->name(), "VariableNode"); +} + +bool expectedMessage(const std::exception& ex) +{ + BOOST_CHECK_EQUAL(ex.what(), + std::string("No parameter or variable found for this identifier: abc")); + return true; +} + +BOOST_FIXTURE_TEST_CASE(identifierNotFound, Fixture) +{ + ModelParser::Library library; + ModelParser::Model model0{ + .id = "model0", + .description = "description", + .parameters = {{"param1", true, false}, {"param2", false, false}}, + .variables = {{"varP", "7", "pmin", ModelParser::ValueType::CONTINUOUS}, + {"var2", "0", "param2", 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, registry, model0), + std::exception, + expectedMessage); +} + +BOOST_FIXTURE_TEST_CASE(AddSub, Fixture) +{ + std::string expression = "1 + 2"; + auto* n = ModelConverter::convertExpressionToNode(expression, registry, model); + BOOST_CHECK_EQUAL(n->name(), "SumNode"); + + auto* nodeSum = dynamic_cast(n); + auto operands = nodeSum->getOperands(); + BOOST_CHECK_EQUAL(toLiteral(operands[0])->value(), 1); + BOOST_CHECK_EQUAL(toLiteral(operands[1])->value(), 2); + + expression = "6 - 3"; + n = ModelConverter::convertExpressionToNode(expression, registry, model); + BOOST_CHECK_EQUAL(n->name(), "SubtractionNode"); + + auto* nodeSub = dynamic_cast(n); + BOOST_CHECK_EQUAL(toLiteral(nodeSub->left())->value(), 6); + BOOST_CHECK_EQUAL(toLiteral(nodeSub->right())->value(), 3); +} + +BOOST_FIXTURE_TEST_CASE(mulDiv, Fixture) +{ + std::string expression = "1 * 2"; + auto* n = ModelConverter::convertExpressionToNode(expression, registry, model); + BOOST_CHECK_EQUAL(n->name(), "MultiplicationNode"); + + auto* nodeMult = dynamic_cast(n); + BOOST_CHECK_EQUAL(toLiteral(nodeMult->left())->value(), 1); + BOOST_CHECK_EQUAL(toLiteral(nodeMult->right())->value(), 2); + + expression = "6 / 3"; + n = ModelConverter::convertExpressionToNode(expression, registry, model); + BOOST_CHECK_EQUAL(n->name(), "DivisionNode"); + + auto* nodeDiv = dynamic_cast(n); + BOOST_CHECK_EQUAL(toLiteral(nodeDiv->left())->value(), 6); + BOOST_CHECK_EQUAL(toLiteral(nodeDiv->right())->value(), 3); +} + +BOOST_FIXTURE_TEST_CASE(comparison, Fixture) +{ + std::string expression = "1 = 2"; + auto* n = ModelConverter::convertExpressionToNode(expression, registry, model); + BOOST_CHECK_EQUAL(n->name(), "EqualNode"); + + expression = "1 <= 5"; + n = ModelConverter::convertExpressionToNode(expression, registry, model); + BOOST_CHECK_EQUAL(n->name(), "LessThanOrEqualNode"); + + expression = "8364 >= 27"; + n = ModelConverter::convertExpressionToNode(expression, registry, model); + BOOST_CHECK_EQUAL(n->name(), "GreaterThanOrEqualNode"); + + auto* nodeGreater = dynamic_cast(n); + BOOST_CHECK_EQUAL(toLiteral(nodeGreater->left())->value(), 8364); + BOOST_CHECK_EQUAL(toLiteral(nodeGreater->right())->value(), 27); +} + +BOOST_FIXTURE_TEST_CASE(medium_expression, Fixture) +{ + ModelParser::Model model0{ + .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"}; + + std::string expression = "(12 * (3 - 1) + param1) / -(42 + 3 + varP)"; + ModelConverter::convertExpressionToNode(expression, registry, model0); +} diff --git a/src/tests/src/solver/modelParser/testModelTranslator.cpp b/src/tests/src/solver/modelParser/testModelTranslator.cpp index 8f0e5aff19..1d3bc00dd7 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, @@ -33,11 +32,16 @@ using namespace Antares::Solver; -// Test empty library -BOOST_AUTO_TEST_CASE(Empty_library_is_valid) +struct Fixture { ModelParser::Library library; - ObjectModel::Library lib = ModelConverter::convert(library); + Registry registry; +}; + +// Test empty library +BOOST_FIXTURE_TEST_CASE(Empty_library_is_valid, Fixture) +{ + ObjectModel::Library lib = ModelConverter::convert(library, registry); BOOST_CHECK(lib.Id().empty()); BOOST_CHECK(lib.Description().empty()); BOOST_CHECK(lib.PortTypes().empty()); @@ -45,24 +49,22 @@ 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"; - ObjectModel::Library lib = ModelConverter::convert(library); + ObjectModel::Library lib = ModelConverter::convert(library, registry); BOOST_CHECK_EQUAL(lib.Id(), "test_id"); BOOST_CHECK_EQUAL(lib.Description(), "test_description"); } // 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}; - ObjectModel::Library lib = ModelConverter::convert(library); + ObjectModel::Library lib = ModelConverter::convert(library, registry); BOOST_REQUIRE_EQUAL(lib.PortTypes().size(), 2); BOOST_CHECK_EQUAL(lib.PortTypes().at("port1").Id(), "port1"); BOOST_CHECK_EQUAL(lib.PortTypes().at("port1").Description(), "flow port"); @@ -80,13 +82,12 @@ 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}; - ObjectModel::Library lib = ModelConverter::convert(library); + ObjectModel::Library lib = ModelConverter::convert(library, registry); BOOST_REQUIRE_EQUAL(lib.PortTypes().at("port1").Fields().size(), 2); BOOST_CHECK_EQUAL(lib.PortTypes().at("port1").Fields()[0].Id(), "field1"); BOOST_CHECK_EQUAL(lib.PortTypes().at("port1").Fields()[1].Id(), "field2"); @@ -96,28 +97,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}; - ObjectModel::Library lib = ModelConverter::convert(library); + ObjectModel::Library lib = ModelConverter::convert(library, registry); 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}}, @@ -125,9 +124,9 @@ BOOST_AUTO_TEST_CASE(model_parameters_properly_translated) .ports = {}, .port_field_definitions{}, .constraints{}, - .objective = "objectives"}; + .objective = ""}; library.models = {model1}; - ObjectModel::Library lib = ModelConverter::convert(library); + ObjectModel::Library lib = ModelConverter::convert(library, registry); auto& model = lib.Models().at("model1"); BOOST_REQUIRE_EQUAL(model.Parameters().size(), 2); auto& parameter1 = model.Parameters().at("param1"); @@ -143,21 +142,20 @@ BOOST_AUTO_TEST_CASE(model_parameters_properly_translated) } // 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}; - ObjectModel::Library lib = ModelConverter::convert(library); + ObjectModel::Library lib = ModelConverter::convert(library, registry); auto& model = lib.Models().at("model1"); BOOST_REQUIRE_EQUAL(model.Variables().size(), 2); auto& variable1 = model.Variables().at("var1"); @@ -168,7 +166,7 @@ BOOST_AUTO_TEST_CASE(model_variables_properly_translated) BOOST_CHECK_EQUAL(variable1.Type(), ObjectModel::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(), ObjectModel::ValueType::INTEGER); } @@ -176,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 = {}, @@ -183,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}; - ObjectModel::Library lib = ModelConverter::convert(library); - auto& model = lib.Models().at("model1"); + ObjectModel::Library lib = ModelConverter::convert(library, registry); + [[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"); @@ -197,20 +196,20 @@ 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}; - ObjectModel::Library lib = ModelConverter::convert(library); + ObjectModel::Library lib = ModelConverter::convert(library, registry); auto& model = lib.Models().at("model1"); BOOST_REQUIRE_EQUAL(model.getConstraints().size(), 2); auto& constraint1 = model.getConstraints().at("constraint1"); @@ -222,30 +221,29 @@ 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}; - ObjectModel::Library lib = ModelConverter::convert(library); + ObjectModel::Library lib = ModelConverter::convert(library, registry); BOOST_REQUIRE_EQUAL(lib.Models().size(), 2); auto& modelo1 = lib.Models().at("model1"); BOOST_REQUIRE_EQUAL(modelo1.Parameters().size(), 2); diff --git a/src/tests/src/solver/modelParser/test_full.cpp b/src/tests/src/solver/modelParser/test_full.cpp index a2a7316192..191c7780da 100644 --- a/src/tests/src/solver/modelParser/test_full.cpp +++ b/src/tests/src/solver/modelParser/test_full.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2007-2024, RTE (https://www.rte-france.com) * See AUTHORS.txt @@ -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,19 +250,20 @@ 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 { + Registry registry; ModelParser::Parser parser; ModelParser::Library libraryObj = parser.parse(library); - ObjectModel::Library lib = ModelConverter::convert(libraryObj); + ObjectModel::Library lib = ModelConverter::convert(libraryObj, registry); BOOST_CHECK_EQUAL(lib.Id(), "basic"); BOOST_CHECK_EQUAL(lib.Description(), "Basic library"); @@ -279,7 +279,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); @@ -420,7 +420,7 @@ BOOST_AUTO_TEST_CASE(test_full) ObjectModel::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"); @@ -492,15 +492,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 b87c13d7b3..775fab0682 100644 --- a/src/vcpkg.json +++ b/src/vcpkg.json @@ -37,6 +37,9 @@ }, { "name": "yaml-cpp" + }, + { + "name": "antlr4" } ] }