From 6632e8341d0cc2b32afaf3f81625d696647c2b05 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sat, 6 Jan 2024 17:33:06 +0800 Subject: [PATCH] feat: update cpp to 14 for better render #24 --- chapi-ast-cpp/src/main/antlr/CPP.g4 | 1940 ----------------- chapi-ast-cpp/src/main/antlr/CPP14Lexer.g4 | 398 ++++ chapi-ast-cpp/src/main/antlr/CPP14Parser.g4 | 1080 +++++++++ .../java/chapi/ast/antlr/CPP14ParserBase.java | 24 + .../kotlin/chapi/ast/cppast/CPPAnalyser.kt | 17 +- .../chapi/ast/cppast/CPPFullIdentListener.kt | 73 +- 6 files changed, 1547 insertions(+), 1985 deletions(-) delete mode 100644 chapi-ast-cpp/src/main/antlr/CPP.g4 create mode 100644 chapi-ast-cpp/src/main/antlr/CPP14Lexer.g4 create mode 100644 chapi-ast-cpp/src/main/antlr/CPP14Parser.g4 create mode 100644 chapi-ast-cpp/src/main/java/chapi/ast/antlr/CPP14ParserBase.java diff --git a/chapi-ast-cpp/src/main/antlr/CPP.g4 b/chapi-ast-cpp/src/main/antlr/CPP.g4 deleted file mode 100644 index 2b16f31e..00000000 --- a/chapi-ast-cpp/src/main/antlr/CPP.g4 +++ /dev/null @@ -1,1940 +0,0 @@ -/******************************************************************************* - * The MIT License (MIT) - * - * Copyright (c) 2015 Camilo Sanchez (Camiloasc1) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - ******************************************************************************/ -grammar CPP; -/*Basic concepts*/ - - -translationunit - : declarationseq? EOF - ; -/*Expressions*/ - - -primaryexpression - : literal - | This - | '(' expression ')' - | idexpression - | lambdaexpression - ; - -idexpression - : unqualifiedid - | qualifiedid - ; - -unqualifiedid - : Identifier - | operatorfunctionid - | conversionfunctionid - | literaloperatorid - | '~' classname - | '~' decltypespecifier - | templateid - ; - -qualifiedid - : nestednamespecifier Template? unqualifiedid - ; - -nestednamespecifier - : '::' - | thetypename '::' - | namespacename '::' - | decltypespecifier '::' - | nestednamespecifier Identifier '::' - | nestednamespecifier Template? simpletemplateid '::' - ; - -lambdaexpression - : lambdaintroducer lambdadeclarator? compoundstatement - ; - -lambdaintroducer - : '[' lambdacapture? ']' - ; - -lambdacapture - : capturedefault - | capturelist - | capturedefault ',' capturelist - ; - -capturedefault - : '&' - | '=' - ; - -capturelist - : capture '...'? - | capturelist ',' capture '...'? - ; - -capture - : simplecapture - | initcapture - ; - -simplecapture - : Identifier - | '&' Identifier - | This - ; - -initcapture - : Identifier initializer - | '&' Identifier initializer - ; - -lambdadeclarator - : '(' parameterdeclarationclause ')' Mutable? exceptionspecification? attributespecifierseq? trailingreturntype? - ; - -postfixexpression - : primaryexpression - | postfixexpression '[' expression ']' - | postfixexpression '[' bracedinitlist ']' - | postfixexpression '(' expressionlist? ')' - | simpletypespecifier '(' expressionlist? ')' - | typenamespecifier '(' expressionlist? ')' - | simpletypespecifier bracedinitlist - | typenamespecifier bracedinitlist - | postfixexpression '.' Template? idexpression - | postfixexpression '->' Template? idexpression - | postfixexpression '.' pseudodestructorname - | postfixexpression '->' pseudodestructorname - | postfixexpression '++' - | postfixexpression '--' - | Dynamic_cast '<' thetypeid '>' '(' expression ')' - | Static_cast '<' thetypeid '>' '(' expression ')' - | Reinterpret_cast '<' thetypeid '>' '(' expression ')' - | Const_cast '<' thetypeid '>' '(' expression ')' - | typeidofthetypeid '(' expression ')' - | typeidofthetypeid '(' thetypeid ')' - ; -/* -add a middle layer to eliminate duplicated function declarations -*/ - - -typeidofexpr - : Typeid_ - ; - -typeidofthetypeid - : Typeid_ - ; - -expressionlist - : initializerlist - ; - -pseudodestructorname - : nestednamespecifier? thetypename '::' '~' thetypename - | nestednamespecifier Template simpletemplateid '::' '~' thetypename - | nestednamespecifier? '~' thetypename - | '~' decltypespecifier - ; - -unaryexpression - : postfixexpression - | '++' castexpression - | '--' castexpression - | unaryoperator castexpression - | Sizeof unaryexpression - | Sizeof '(' thetypeid ')' - | Sizeof '...' '(' Identifier ')' - | Alignof '(' thetypeid ')' - | noexceptexpression - | newexpression - | deleteexpression - ; - -unaryoperator - : '|' - | '*' - | '&' - | '+' - | '!' - | '~' - | '-' - | 'not' - ; - -newexpression - : '::'? New newplacement? newtypeid newinitializer? - | '::'? New newplacement? '(' thetypeid ')' newinitializer? - ; - -newplacement - : '(' expressionlist ')' - ; - -newtypeid - : typespecifierseq newdeclarator? - ; - -newdeclarator - : ptroperator newdeclarator? - | noptrnewdeclarator - ; - -noptrnewdeclarator - : '[' expression ']' attributespecifierseq? - | noptrnewdeclarator '[' constantexpression ']' attributespecifierseq? - ; - -newinitializer - : '(' expressionlist? ')' - | bracedinitlist - ; - -deleteexpression - : '::'? Delete castexpression - | '::'? Delete '[' ']' castexpression - ; - -noexceptexpression - : Noexcept '(' expression ')' - ; - -castexpression - : unaryexpression - | '(' thetypeid ')' castexpression - ; - -pmexpression - : castexpression - | pmexpression '.*' castexpression - | pmexpression '->*' castexpression - ; - -multiplicativeexpression - : pmexpression - | multiplicativeexpression '*' pmexpression - | multiplicativeexpression '/' pmexpression - | multiplicativeexpression '%' pmexpression - ; - -additiveexpression - : multiplicativeexpression - | additiveexpression '+' multiplicativeexpression - | additiveexpression '-' multiplicativeexpression - ; - -shiftexpression - : additiveexpression - | shiftexpression shiftoperator additiveexpression - ; - -shiftoperator - : RightShift - | LeftShift - ; - -relationalexpression - : shiftexpression - | relationalexpression '<' shiftexpression - | relationalexpression '>' shiftexpression - | relationalexpression '<=' shiftexpression - | relationalexpression '>=' shiftexpression - ; - -equalityexpression - : relationalexpression - | equalityexpression '==' relationalexpression - | equalityexpression '!=' relationalexpression - ; - -andexpression - : equalityexpression - | andexpression '&' equalityexpression - ; - -exclusiveorexpression - : andexpression - | exclusiveorexpression '^' andexpression - ; - -inclusiveorexpression - : exclusiveorexpression - | inclusiveorexpression '|' exclusiveorexpression - ; - -logicalandexpression - : inclusiveorexpression - | logicalandexpression '&&' inclusiveorexpression - | logicalandexpression 'and' inclusiveorexpression - ; - -logicalorexpression - : logicalandexpression - | logicalorexpression '||' logicalandexpression - | logicalorexpression 'or' logicalandexpression - ; - -conditionalexpression - : logicalorexpression - | logicalorexpression '?' expression ':' assignmentexpression - ; - -assignmentexpression - : conditionalexpression - | logicalorexpression assignmentoperator initializerclause - | throwexpression - ; - -assignmentoperator - : '=' - | '*=' - | '/=' - | '%=' - | '+=' - | '-=' - | RightShiftAssign - | LeftShiftAssign - | '&=' - | '^=' - | '|=' - ; - -expression - : assignmentexpression - | expression ',' assignmentexpression - ; - -constantexpression - : conditionalexpression - ; -/*Statements*/ - - -statement - : labeledstatement - | attributespecifierseq? expressionstatement - | attributespecifierseq? compoundstatement - | attributespecifierseq? selectionstatement - | attributespecifierseq? iterationstatement - | attributespecifierseq? jumpstatement - | declarationstatement - | attributespecifierseq? tryblock - ; - -labeledstatement - : attributespecifierseq? Identifier ':' statement - | attributespecifierseq? Case constantexpression ':' statement - | attributespecifierseq? Default ':' statement - ; - -expressionstatement - : expression? ';' - ; - -compoundstatement - : '{' statementseq? '}' - ; - -statementseq - : statement - | statementseq statement - ; - -selectionstatement - : If '(' condition ')' statement - | If '(' condition ')' statement Else statement - | Switch '(' condition ')' statement - ; - -condition - : expression - | attributespecifierseq? declspecifierseq declarator '=' initializerclause - | attributespecifierseq? declspecifierseq declarator bracedinitlist - ; - -iterationstatement - : While '(' condition ')' statement - | Do statement While '(' expression ')' ';' - | For '(' forinitstatement condition? ';' expression? ')' statement - | For '(' forrangedeclaration ':' forrangeinitializer ')' statement - ; - -forinitstatement - : expressionstatement - | simpledeclaration - ; - -forrangedeclaration - : attributespecifierseq? declspecifierseq declarator - ; - -forrangeinitializer - : expression - | bracedinitlist - ; - -jumpstatement - : Break ';' - | Continue ';' - | Return expression? ';' - | Return bracedinitlist ';' - | Goto Identifier ';' - ; - -declarationstatement - : blockdeclaration - ; -/*Declarations*/ - - -declarationseq - : declaration - | declarationseq declaration - ; - -declaration - : blockdeclaration - | functiondefinition - | templatedeclaration - | explicitinstantiation - | explicitspecialization - | linkagespecification - | namespacedefinition - | emptydeclaration - | attributedeclaration - ; - -blockdeclaration - : simpledeclaration - | asmdefinition - | namespacealiasdefinition - | usingdeclaration - | usingdirective - | static_assertdeclaration - | aliasdeclaration - | opaqueenumdeclaration - ; - -aliasdeclaration - : Using Identifier attributespecifierseq? '=' thetypeid ';' - ; - -simpledeclaration - : declspecifierseq? initdeclaratorlist? ';' - | attributespecifierseq declspecifierseq? initdeclaratorlist ';' - ; - -static_assertdeclaration - : Static_assert '(' constantexpression ',' Stringliteral ')' ';' - ; - -emptydeclaration - : ';' - ; - -attributedeclaration - : attributespecifierseq ';' - ; - -declspecifier - : storageclassspecifier - | typespecifier - | functionspecifier - | Friend - | Typedef - | Constexpr - ; - -declspecifierseq - : declspecifier attributespecifierseq? - | declspecifier declspecifierseq - ; - -storageclassspecifier - : Register - | Static - | Thread_local - | Extern - | Mutable - ; - -functionspecifier - : Inline - | Virtual - | Explicit - ; - -typedefname - : Identifier - ; - -typespecifier - : trailingtypespecifier - | classspecifier - | enumspecifier - ; - -trailingtypespecifier - : simpletypespecifier - | elaboratedtypespecifier - | typenamespecifier - | cvqualifier - ; - -typespecifierseq - : typespecifier attributespecifierseq? - | typespecifier typespecifierseq - ; - -trailingtypespecifierseq - : trailingtypespecifier attributespecifierseq? - | trailingtypespecifier trailingtypespecifierseq - ; - -simpletypespecifier - : nestednamespecifier? thetypename - | nestednamespecifier Template simpletemplateid - | Char - | Char16 - | Char32 - | Wchar - | Bool - | Short - | Int - | Long - | Signed - | Unsigned - | Float - | Double - | Void - | Auto - | decltypespecifier - ; - -thetypename - : classname - | enumname - | typedefname - | simpletemplateid - ; - -decltypespecifier - : Decltype '(' expression ')' - | Decltype '(' Auto ')' - ; - -elaboratedtypespecifier - : classkey attributespecifierseq? nestednamespecifier? Identifier - | classkey simpletemplateid - | classkey nestednamespecifier Template? simpletemplateid - | Enum nestednamespecifier? Identifier - ; - -enumname - : Identifier - ; - -enumspecifier - : enumhead '{' enumeratorlist? '}' - | enumhead '{' enumeratorlist ',' '}' - ; - -enumhead - : enumkey attributespecifierseq? Identifier? enumbase? - | enumkey attributespecifierseq? nestednamespecifier Identifier enumbase? - ; - -opaqueenumdeclaration - : enumkey attributespecifierseq? Identifier enumbase? ';' - ; - -enumkey - : Enum - | Enum Class - | Enum Struct - ; - -enumbase - : ':' typespecifierseq - ; - -enumeratorlist - : enumeratordefinition - | enumeratorlist ',' enumeratordefinition - ; - -enumeratordefinition - : enumerator - | enumerator '=' constantexpression - ; - -enumerator - : Identifier - ; - -namespacename - : originalnamespacename - | namespacealias - ; - -originalnamespacename - : Identifier - ; - -namespacedefinition - : namednamespacedefinition - | unnamednamespacedefinition - ; - -namednamespacedefinition - : originalnamespacedefinition - | extensionnamespacedefinition - ; - -originalnamespacedefinition - : Inline? Namespace Identifier '{' namespacebody '}' - ; - -extensionnamespacedefinition - : Inline? Namespace originalnamespacename '{' namespacebody '}' - ; - -unnamednamespacedefinition - : Inline? Namespace '{' namespacebody '}' - ; - -namespacebody - : declarationseq? - ; - -namespacealias - : Identifier - ; - -namespacealiasdefinition - : Namespace Identifier '=' qualifiednamespacespecifier ';' - ; - -qualifiednamespacespecifier - : nestednamespecifier? namespacename - ; - -usingdeclaration - : Using Typename_? nestednamespecifier unqualifiedid ';' - | Using '::' unqualifiedid ';' - ; - -usingdirective - : attributespecifierseq? Using Namespace nestednamespecifier? namespacename ';' - ; - -asmdefinition - : Asm '(' Stringliteral ')' ';' - ; - -linkagespecification - : Extern Stringliteral '{' declarationseq? '}' - | Extern Stringliteral declaration - ; - -attributespecifierseq - : attributespecifier - | attributespecifierseq attributespecifier - ; - -attributespecifier - : '[' '[' attributelist ']' ']' - | alignmentspecifier - ; - -alignmentspecifier - : Alignas '(' thetypeid '...'? ')' - | Alignas '(' constantexpression '...'? ')' - ; - -attributelist - : attribute? - | attributelist ',' attribute? - | attribute '...' - | attributelist ',' attribute '...' - ; - -attribute - : attributetoken attributeargumentclause? - ; - -attributetoken - : Identifier - | attributescopedtoken - ; - -attributescopedtoken - : attributenamespace '::' Identifier - ; - -attributenamespace - : Identifier - ; - -attributeargumentclause - : '(' balancedtokenseq ')' - ; - -balancedtokenseq - : balancedtoken? - | balancedtokenseq balancedtoken - ; - -balancedtoken - : '(' balancedtokenseq ')' - | '[' balancedtokenseq ']' - | '{' balancedtokenseq '}' - | ~('('|')'|'{'|'}'|'['|']')+ - ; -/*Declarators*/ - - -initdeclaratorlist - : initdeclarator - | initdeclaratorlist ',' initdeclarator - ; - -initdeclarator - : declarator initializer? - ; - -declarator - : ptrdeclarator - | noptrdeclarator parametersandqualifiers trailingreturntype - ; - -ptrdeclarator - : noptrdeclarator - | ptroperator ptrdeclarator - ; - -noptrdeclarator - : declaratorid attributespecifierseq? - | noptrdeclarator parametersandqualifiers - | noptrdeclarator '[' constantexpression? ']' attributespecifierseq? - | '(' ptrdeclarator ')' - ; - -parametersandqualifiers - : '(' parameterdeclarationclause ')' cvqualifierseq? refqualifier? exceptionspecification? attributespecifierseq? - ; - -trailingreturntype - : '->' trailingtypespecifierseq abstractdeclarator? - ; - -ptroperator - : '*' attributespecifierseq? cvqualifierseq? - | '&' attributespecifierseq? - | '&&' attributespecifierseq? - | nestednamespecifier '*' attributespecifierseq? cvqualifierseq? - ; - -cvqualifierseq - : cvqualifier cvqualifierseq? - ; - -cvqualifier - : Const - | Volatile - ; - -refqualifier - : '&' - | '&&' - ; - -declaratorid - : '...'? idexpression - ; - -thetypeid - : typespecifierseq abstractdeclarator? - ; - -abstractdeclarator - : ptrabstractdeclarator - | noptrabstractdeclarator? parametersandqualifiers trailingreturntype - | abstractpackdeclarator - ; - -ptrabstractdeclarator - : noptrabstractdeclarator - | ptroperator ptrabstractdeclarator? - ; - -noptrabstractdeclarator - : noptrabstractdeclarator parametersandqualifiers - | parametersandqualifiers - | noptrabstractdeclarator '[' constantexpression? ']' attributespecifierseq? - | '[' constantexpression? ']' attributespecifierseq? - | '(' ptrabstractdeclarator ')' - ; - -abstractpackdeclarator - : noptrabstractpackdeclarator - | ptroperator abstractpackdeclarator - ; - -noptrabstractpackdeclarator - : noptrabstractpackdeclarator parametersandqualifiers - | noptrabstractpackdeclarator '[' constantexpression? ']' attributespecifierseq? - | '...' - ; - -parameterdeclarationclause - : parameterdeclarationlist? '...'? - | parameterdeclarationlist ',' '...' - ; - -parameterdeclarationlist - : parameterdeclaration - | parameterdeclarationlist ',' parameterdeclaration - ; - -parameterdeclaration - : attributespecifierseq? declspecifierseq declarator - | attributespecifierseq? declspecifierseq declarator '=' initializerclause - | attributespecifierseq? declspecifierseq abstractdeclarator? - | attributespecifierseq? declspecifierseq abstractdeclarator? '=' initializerclause - ; - -functiondefinition - : attributespecifierseq? declspecifierseq? declarator virtspecifierseq? functionbody - ; - -functionbody - : ctorinitializer? compoundstatement - | functiontryblock - | '=' Default ';' - | '=' Delete ';' - ; - -initializer - : braceorequalinitializer - | '(' expressionlist ')' - ; - -braceorequalinitializer - : '=' initializerclause - | bracedinitlist - ; - -initializerclause - : assignmentexpression - | bracedinitlist - ; - -initializerlist - : initializerclause '...'? - | initializerlist ',' initializerclause '...'? - ; - -bracedinitlist - : '{' initializerlist ','? '}' - | '{' '}' - ; -/*Classes*/ - - -classname - : Identifier - | simpletemplateid - ; - -classspecifier - : classhead '{' memberspecification? '}' - ; - -classhead - : classkey attributespecifierseq? classheadname classvirtspecifier? baseclause? - | classkey attributespecifierseq? baseclause? - ; - -classheadname - : nestednamespecifier? classname - ; - -classvirtspecifier - : Final - ; - -classkey - : Class - | Struct - | Union - ; - -memberspecification - : memberdeclaration memberspecification? - | accessspecifier ':' memberspecification? - ; - -memberdeclaration - : attributespecifierseq? declspecifierseq? memberdeclaratorlist? ';' - | functiondefinition - | usingdeclaration - | static_assertdeclaration - | templatedeclaration - | aliasdeclaration - | emptydeclaration - ; - -memberdeclaratorlist - : memberdeclarator - | memberdeclaratorlist ',' memberdeclarator - ; - -memberdeclarator - : declarator virtspecifierseq? purespecifier? - | declarator braceorequalinitializer? - | Identifier? attributespecifierseq? ':' constantexpression - ; - -virtspecifierseq - : virtspecifier - | virtspecifierseq virtspecifier - ; - -virtspecifier - : Override - | Final - ; -/* -purespecifier: - '=' '0'//Conflicts with the lexer - ; - */ - - -purespecifier - : Assign val = Octalliteral - {if($val.text.compareTo("0")!=0) throw new InputMismatchException(this);} - ; -/*Derived classes*/ - - -baseclause - : ':' basespecifierlist - ; - -basespecifierlist - : basespecifier '...'? - | basespecifierlist ',' basespecifier '...'? - ; - -basespecifier - : attributespecifierseq? basetypespecifier - | attributespecifierseq? Virtual accessspecifier? basetypespecifier - | attributespecifierseq? accessspecifier Virtual? basetypespecifier - ; - -classordecltype - : nestednamespecifier? classname - | decltypespecifier - ; - -basetypespecifier - : classordecltype - ; - -accessspecifier - : Private - | Protected - | Public - ; -/*Special member functions*/ - - -conversionfunctionid - : Operator conversiontypeid - ; - -conversiontypeid - : typespecifierseq conversiondeclarator? - ; - -conversiondeclarator - : ptroperator conversiondeclarator? - ; - -ctorinitializer - : ':' meminitializerlist - ; - -meminitializerlist - : meminitializer '...'? - | meminitializer '...'? ',' meminitializerlist - ; - -meminitializer - : meminitializerid '(' expressionlist? ')' - | meminitializerid bracedinitlist - ; - -meminitializerid - : classordecltype - | Identifier - ; -/*Overloading*/ - - -operatorfunctionid - : Operator theoperator - ; - -literaloperatorid - : Operator Stringliteral Identifier - | Operator Userdefinedstringliteral - ; -/*Templates*/ - - -templatedeclaration - : Template '<' templateparameterlist '>' declaration - ; - -templateparameterlist - : templateparameter - | templateparameterlist ',' templateparameter - ; - -templateparameter - : typeparameter - | parameterdeclaration - ; - -typeparameter - : Class '...'? Identifier? - | Class Identifier? '=' thetypeid - | Typename_ '...'? Identifier? - | Typename_ Identifier? '=' thetypeid - | Template '<' templateparameterlist '>' Class '...'? Identifier? - | Template '<' templateparameterlist '>' Class Identifier? '=' idexpression - ; - -simpletemplateid - : templatename '<' templateargumentlist? '>' - ; - -templateid - : simpletemplateid - | operatorfunctionid '<' templateargumentlist? '>' - | literaloperatorid '<' templateargumentlist? '>' - ; - -templatename - : Identifier - ; - -templateargumentlist - : templateargument '...'? - | templateargumentlist ',' templateargument '...'? - ; - -templateargument - : thetypeid - | constantexpression - | idexpression - ; - -typenamespecifier - : Typename_ nestednamespecifier Identifier - | Typename_ nestednamespecifier Template? simpletemplateid - ; - -explicitinstantiation - : Extern? Template declaration - ; - -explicitspecialization - : Template '<' '>' declaration - ; -/*Exception handling*/ - - -tryblock - : Try compoundstatement handlerseq - ; - -functiontryblock - : Try ctorinitializer? compoundstatement handlerseq - ; - -handlerseq - : handler handlerseq? - ; - -handler - : Catch '(' exceptiondeclaration ')' compoundstatement - ; - -exceptiondeclaration - : attributespecifierseq? typespecifierseq declarator - | attributespecifierseq? typespecifierseq abstractdeclarator? - | '...' - ; - -throwexpression - : Throw assignmentexpression? - ; - -exceptionspecification - : dynamicexceptionspecification - | noexceptspecification - ; - -dynamicexceptionspecification - : Throw '(' typeidlist? ')' - ; - -typeidlist - : thetypeid '...'? - | typeidlist ',' thetypeid '...'? - ; - -noexceptspecification - : Noexcept '(' constantexpression ')' - | Noexcept - ; -/*Preprocessing directives*/ - - -MultiLineMacro - : '#' (~ [\n]*? '\\' '\r'? '\n')+ ~ [\n]+ -> channel (HIDDEN) - ; - -Directive - : '#' ~ [\n]* -> channel (HIDDEN) - ; -/*Lexer*/ - -/*Keywords*/ - - -Alignas - : 'alignas' - ; - -Alignof - : 'alignof' - ; - -Asm - : 'asm' - ; - -Auto - : 'auto' - ; - -Bool - : 'bool' - ; - -Break - : 'break' - ; - -Case - : 'case' - ; - -Catch - : 'catch' - ; - -Char - : 'char' - ; - -Char16 - : 'char16_t' - ; - -Char32 - : 'char32_t' - ; - -Class - : 'class' - ; - -Const - : 'const' - ; - -Constexpr - : 'constexpr' - ; - -Const_cast - : 'const_cast' - ; - -Continue - : 'continue' - ; - -Decltype - : 'decltype' - ; - -Default - : 'default' - ; - -Delete - : 'delete' - ; - -Do - : 'do' - ; - -Double - : 'double' - ; - -Dynamic_cast - : 'dynamic_cast' - ; - -Else - : 'else' - ; - -Enum - : 'enum' - ; - -Explicit - : 'explicit' - ; - -Export - : 'export' - ; - -Extern - : 'extern' - ; - -False - : 'false' - ; - -Final - : 'final' - ; - -Float - : 'float' - ; - -For - : 'for' - ; - -Friend - : 'friend' - ; - -Goto - : 'goto' - ; - -If - : 'if' - ; - -Inline - : 'inline' - ; - -Int - : 'int' - ; - -Long - : 'long' - ; - -Mutable - : 'mutable' - ; - -Namespace - : 'namespace' - ; - -New - : 'new' - ; - -Noexcept - : 'noexcept' - ; - -Nullptr - : 'nullptr' - ; - -Operator - : 'operator' - ; - -Override - : 'override' - ; - -Private - : 'private' - ; - -Protected - : 'protected' - ; - -Public - : 'public' - ; - -Register - : 'register' - ; - -Reinterpret_cast - : 'reinterpret_cast' - ; - -Return - : 'return' - ; - -Short - : 'short' - ; - -Signed - : 'signed' - ; - -Sizeof - : 'sizeof' - ; - -Static - : 'static' - ; - -Static_assert - : 'static_assert' - ; - -Static_cast - : 'static_cast' - ; - -Struct - : 'struct' - ; - -Switch - : 'switch' - ; - -Template - : 'template' - ; - -This - : 'this' - ; - -Thread_local - : 'thread_local' - ; - -Throw - : 'throw' - ; - -True - : 'true' - ; - -Try - : 'try' - ; - -Typedef - : 'typedef' - ; - -Typeid_ - : 'typeid' - ; - -Typename_ - : 'typename' - ; - -Union - : 'union' - ; - -Unsigned - : 'unsigned' - ; - -Using - : 'using' - ; - -Virtual - : 'virtual' - ; - -Void - : 'void' - ; - -Volatile - : 'volatile' - ; - -Wchar - : 'wchar_t' - ; - -While - : 'while' - ; -/*Operators*/ - - -LeftParen - : '(' - ; - -RightParen - : ')' - ; - -LeftBracket - : '[' - ; - -RightBracket - : ']' - ; - -LeftBrace - : '{' - ; - -RightBrace - : '}' - ; - -Plus - : '+' - ; - -Minus - : '-' - ; - -Star - : '*' - ; - -Div - : '/' - ; - -Mod - : '%' - ; - -Caret - : '^' - ; - -And - : '&' - ; - -Or - : '|' - ; - -Tilde - : '~' - ; - -Not - : '!' - | 'not' - ; - -Assign - : '=' - ; - -Less - : '<' - ; - -Greater - : '>' - ; - -PlusAssign - : '+=' - ; - -MinusAssign - : '-=' - ; - -StarAssign - : '*=' - ; - -DivAssign - : '/=' - ; - -ModAssign - : '%=' - ; - -XorAssign - : '^=' - ; - -AndAssign - : '&=' - ; - -OrAssign - : '|=' - ; - -LeftShift - : '<<' - ; - -RightShift - : - '>>' - ; - -LeftShiftAssign - : '<<=' - ; - -RightShiftAssign - : - '>>=' - ; - -Equal - : '==' - ; - -NotEqual - : '!=' - ; - -LessEqual - : '<=' - ; - -GreaterEqual - : '>=' - ; - -AndAnd - : '&&' - | 'and' - ; - -OrOr - : '||' - | 'or' - ; - -PlusPlus - : '++' - ; - -MinusMinus - : '--' - ; - -Comma - : ',' - ; - -ArrowStar - : '->*' - ; - -Arrow - : '->' - ; - -Question - : '?' - ; - -Colon - : ':' - ; - -Doublecolon - : '::' - ; - -Semi - : ';' - ; - -Dot - : '.' - ; - -DotStar - : '.*' - ; - -Ellipsis - : '...' - ; - -theoperator - : New - | Delete - | New '[' ']' - | Delete '[' ']' - | '+' - | '-' - | '*' - | '/' - | '%' - | '^' - | '&' - | '|' - | '~' - | '!' - | 'not' - | '=' - | '<' - | '>' - | '+=' - | '-=' - | '*=' - | '/=' - | '%=' - | '^=' - | '&=' - | '|=' - | LeftShift - | RightShift - | RightShiftAssign - | LeftShiftAssign - | '==' - | '!=' - | '<=' - | '>=' - | '&&' - | 'and' - | '||' - | 'or' - | '++' - | '--' - | ',' - | '->*' - | '->' - | '(' ')' - | '[' ']' - ; -/*Lexer*/ - - -fragment Hexquad - : HEXADECIMALDIGIT HEXADECIMALDIGIT HEXADECIMALDIGIT HEXADECIMALDIGIT - ; - -fragment Universalcharactername - : '\\u' Hexquad - | '\\U' Hexquad Hexquad - ; - -Identifier - : -/* - Identifiernondigit - | Identifier Identifiernondigit - | Identifier DIGIT - */ - Identifiernondigit (Identifiernondigit | DIGIT)* - ; - -fragment Identifiernondigit - : NONDIGIT - | Universalcharactername - ; - -fragment NONDIGIT - : [a-zA-Z_] - ; - -fragment DIGIT - : [0-9] - ; - -literal - : Integerliteral - | Characterliteral - | Floatingliteral - | Stringliteral - | booleanliteral - | pointerliteral - | userdefinedliteral - ; - -Integerliteral - : Decimalliteral Integersuffix? - | Octalliteral Integersuffix? - | Hexadecimalliteral Integersuffix? - | Binaryliteral Integersuffix? - ; - -Decimalliteral - : NONZERODIGIT ('\''? DIGIT)* - ; - -Octalliteral - : '0' ('\''? OCTALDIGIT)* - ; - -Hexadecimalliteral - : ('0x' | '0X') HEXADECIMALDIGIT ('\''? HEXADECIMALDIGIT)* - ; - -Binaryliteral - : ('0b' | '0B') BINARYDIGIT ('\''? BINARYDIGIT)* - ; - -fragment NONZERODIGIT - : [1-9] - ; - -fragment OCTALDIGIT - : [0-7] - ; - -fragment HEXADECIMALDIGIT - : [0-9a-fA-F] - ; - -fragment BINARYDIGIT - : [01] - ; - -Integersuffix - : Unsignedsuffix Longsuffix? - | Unsignedsuffix Longlongsuffix? - | Longsuffix Unsignedsuffix? - | Longlongsuffix Unsignedsuffix? - ; - -fragment Unsignedsuffix - : [uU] - ; - -fragment Longsuffix - : [lL] - ; - -fragment Longlongsuffix - : 'll' - | 'LL' - ; - -Characterliteral - : '\'' Cchar+ '\'' - | 'u' '\'' Cchar+ '\'' - | 'U' '\'' Cchar+ '\'' - | 'L' '\'' Cchar+ '\'' - ; - -fragment Cchar - : ~ ['\\\r\n] - | Escapesequence - | Universalcharactername - ; - -fragment Escapesequence - : Simpleescapesequence - | Octalescapesequence - | Hexadecimalescapesequence - ; - -fragment Simpleescapesequence - : '\\\'' - | '\\"' - | '\\?' - | '\\\\' - | '\\a' - | '\\b' - | '\\f' - | '\\n' - | '\\r' - | '\\t' - | '\\v' - ; - -fragment Octalescapesequence - : '\\' OCTALDIGIT - | '\\' OCTALDIGIT OCTALDIGIT - | '\\' OCTALDIGIT OCTALDIGIT OCTALDIGIT - ; - -fragment Hexadecimalescapesequence - : '\\x' HEXADECIMALDIGIT+ - ; - -Floatingliteral - : Fractionalconstant Exponentpart? Floatingsuffix? - | Digitsequence Exponentpart Floatingsuffix? - ; - -fragment Fractionalconstant - : Digitsequence? '.' Digitsequence - | Digitsequence '.' - ; - -fragment Exponentpart - : 'e' SIGN? Digitsequence - | 'E' SIGN? Digitsequence - ; - -fragment SIGN - : [+-] - ; - -fragment Digitsequence - : DIGIT ('\''? DIGIT)* - ; - -fragment Floatingsuffix - : [flFL] - ; - -Stringliteral - : Encodingprefix? '"' Schar* '"' - | Encodingprefix? 'R' Rawstring - ; - -fragment Encodingprefix - : 'u8' - | 'u' - | 'U' - | 'L' - ; - -fragment Schar - : ~ ["\\\r\n] - | Escapesequence - | Universalcharactername - ; - -fragment Rawstring - : '"' .*? '(' .*? ')' .*? '"' - ; - -booleanliteral - : False - | True - ; - -pointerliteral - : Nullptr - ; - -userdefinedliteral - : Userdefinedintegerliteral - | Userdefinedfloatingliteral - | Userdefinedstringliteral - | Userdefinedcharacterliteral - ; - -Userdefinedintegerliteral - : Decimalliteral Udsuffix - | Octalliteral Udsuffix - | Hexadecimalliteral Udsuffix - | Binaryliteral Udsuffix - ; - -Userdefinedfloatingliteral - : Fractionalconstant Exponentpart? Udsuffix - | Digitsequence Exponentpart Udsuffix - ; - -Userdefinedstringliteral - : Stringliteral Udsuffix - ; - -Userdefinedcharacterliteral - : Characterliteral Udsuffix - ; - -fragment Udsuffix - : Identifier - ; - -Whitespace - : [ \t]+ -> skip - ; - -Newline - : ('\r' '\n'? | '\n') -> skip - ; - -BlockComment - : '/*' .*? '*/' -> skip - ; - -LineComment - : '//' ~ [\r\n]* -> skip - ; diff --git a/chapi-ast-cpp/src/main/antlr/CPP14Lexer.g4 b/chapi-ast-cpp/src/main/antlr/CPP14Lexer.g4 new file mode 100644 index 00000000..897f6aec --- /dev/null +++ b/chapi-ast-cpp/src/main/antlr/CPP14Lexer.g4 @@ -0,0 +1,398 @@ +// $antlr-format alignTrailingComments true, columnLimit 150, maxEmptyLinesToKeep 1, reflowComments false, useTab false +// $antlr-format allowShortRulesOnASingleLine true, allowShortBlocksOnASingleLine true, minEmptyLines 0, alignSemicolons ownLine +// $antlr-format alignColons trailing, singleLineOverrulesHangingColon true, alignLexerCommands true, alignLabels true, alignTrailers true + +lexer grammar CPP14Lexer; + +IntegerLiteral: + DecimalLiteral Integersuffix? + | OctalLiteral Integersuffix? + | HexadecimalLiteral Integersuffix? + | BinaryLiteral Integersuffix? +; + +CharacterLiteral: ('u' | 'U' | 'L')? '\'' Cchar+ '\''; + +FloatingLiteral: + Fractionalconstant Exponentpart? Floatingsuffix? + | Digitsequence Exponentpart Floatingsuffix? +; + +StringLiteral: Encodingprefix? (Rawstring | '"' Schar* '"'); + +BooleanLiteral: False_ | True_; + +PointerLiteral: Nullptr; + +UserDefinedLiteral: + UserDefinedIntegerLiteral + | UserDefinedFloatingLiteral + | UserDefinedStringLiteral + | UserDefinedCharacterLiteral +; + +MultiLineMacro: '#' (~[\n]*? '\\' '\r'? '\n')+ ~ [\n]+ -> channel (HIDDEN); + +Directive: '#' ~ [\n]* -> channel (HIDDEN); +/*Keywords*/ + +Alignas: 'alignas'; + +Alignof: 'alignof'; + +Asm: 'asm'; + +Auto: 'auto'; + +Bool: 'bool'; + +Break: 'break'; + +Case: 'case'; + +Catch: 'catch'; + +Char: 'char'; + +Char16: 'char16_t'; + +Char32: 'char32_t'; + +Class: 'class'; + +Const: 'const'; + +Constexpr: 'constexpr'; + +Const_cast: 'const_cast'; + +Continue: 'continue'; + +Decltype: 'decltype'; + +Default: 'default'; + +Delete: 'delete'; + +Do: 'do'; + +Double: 'double'; + +Dynamic_cast: 'dynamic_cast'; + +Else: 'else'; + +Enum: 'enum'; + +Explicit: 'explicit'; + +Export: 'export'; + +Extern: 'extern'; + +//DO NOT RENAME - PYTHON NEEDS True and False +False_: 'false'; + +Final: 'final'; + +Float: 'float'; + +For: 'for'; + +Friend: 'friend'; + +Goto: 'goto'; + +If: 'if'; + +Inline: 'inline'; + +Int: 'int'; + +Long: 'long'; + +Mutable: 'mutable'; + +Namespace: 'namespace'; + +New: 'new'; + +Noexcept: 'noexcept'; + +Nullptr: 'nullptr'; + +Operator: 'operator'; + +Override: 'override'; + +Private: 'private'; + +Protected: 'protected'; + +Public: 'public'; + +Register: 'register'; + +Reinterpret_cast: 'reinterpret_cast'; + +Return: 'return'; + +Short: 'short'; + +Signed: 'signed'; + +Sizeof: 'sizeof'; + +Static: 'static'; + +Static_assert: 'static_assert'; + +Static_cast: 'static_cast'; + +Struct: 'struct'; + +Switch: 'switch'; + +Template: 'template'; + +This: 'this'; + +Thread_local: 'thread_local'; + +Throw: 'throw'; + +//DO NOT RENAME - PYTHON NEEDS True and False +True_: 'true'; + +Try: 'try'; + +Typedef: 'typedef'; + +Typeid_: 'typeid'; + +Typename_: 'typename'; + +Union: 'union'; + +Unsigned: 'unsigned'; + +Using: 'using'; + +Virtual: 'virtual'; + +Void: 'void'; + +Volatile: 'volatile'; + +Wchar: 'wchar_t'; + +While: 'while'; +/*Operators*/ + +LeftParen: '('; + +RightParen: ')'; + +LeftBracket: '['; + +RightBracket: ']'; + +LeftBrace: '{'; + +RightBrace: '}'; + +Plus: '+'; + +Minus: '-'; + +Star: '*'; + +Div: '/'; + +Mod: '%'; + +Caret: '^'; + +And: '&'; + +Or: '|'; + +Tilde: '~'; + +Not: '!' | 'not'; + +Assign: '='; + +Less: '<'; + +Greater: '>'; + +PlusAssign: '+='; + +MinusAssign: '-='; + +StarAssign: '*='; + +DivAssign: '/='; + +ModAssign: '%='; + +XorAssign: '^='; + +AndAssign: '&='; + +OrAssign: '|='; + +LeftShiftAssign: '<<='; + +RightShiftAssign: '>>='; + +Equal: '=='; + +NotEqual: '!='; + +LessEqual: '<='; + +GreaterEqual: '>='; + +AndAnd: '&&' | 'and'; + +OrOr: '||' | 'or'; + +PlusPlus: '++'; + +MinusMinus: '--'; + +Comma: ','; + +ArrowStar: '->*'; + +Arrow: '->'; + +Question: '?'; + +Colon: ':'; + +Doublecolon: '::'; + +Semi: ';'; + +Dot: '.'; + +DotStar: '.*'; + +Ellipsis: '...'; + +fragment Hexquad: HEXADECIMALDIGIT HEXADECIMALDIGIT HEXADECIMALDIGIT HEXADECIMALDIGIT; + +fragment Universalcharactername: '\\u' Hexquad | '\\U' Hexquad Hexquad; + +Identifier: + /* + Identifiernondigit | Identifier Identifiernondigit | Identifier DIGIT + */ Identifiernondigit (Identifiernondigit | DIGIT)* +; + +fragment Identifiernondigit: NONDIGIT | Universalcharactername; + +fragment NONDIGIT: [a-zA-Z_]; + +fragment DIGIT: [0-9]; + +DecimalLiteral: NONZERODIGIT ('\''? DIGIT)*; + +OctalLiteral: '0' ('\''? OCTALDIGIT)*; + +HexadecimalLiteral: ('0x' | '0X') HEXADECIMALDIGIT ( '\''? HEXADECIMALDIGIT)*; + +BinaryLiteral: ('0b' | '0B') BINARYDIGIT ('\''? BINARYDIGIT)*; + +fragment NONZERODIGIT: [1-9]; + +fragment OCTALDIGIT: [0-7]; + +fragment HEXADECIMALDIGIT: [0-9a-fA-F]; + +fragment BINARYDIGIT: [01]; + +Integersuffix: + Unsignedsuffix Longsuffix? + | Unsignedsuffix Longlongsuffix? + | Longsuffix Unsignedsuffix? + | Longlongsuffix Unsignedsuffix? +; + +fragment Unsignedsuffix: [uU]; + +fragment Longsuffix: [lL]; + +fragment Longlongsuffix: 'll' | 'LL'; + +fragment Cchar: ~ ['\\\r\n] | Escapesequence | Universalcharactername; + +fragment Escapesequence: Simpleescapesequence | Octalescapesequence | Hexadecimalescapesequence; + +fragment Simpleescapesequence: + '\\\'' + | '\\"' + | '\\?' + | '\\\\' + | '\\a' + | '\\b' + | '\\f' + | '\\n' + | '\\r' + | '\\' ('\r' '\n'? | '\n') + | '\\t' + | '\\v' +; + +fragment Octalescapesequence: + '\\' OCTALDIGIT + | '\\' OCTALDIGIT OCTALDIGIT + | '\\' OCTALDIGIT OCTALDIGIT OCTALDIGIT +; + +fragment Hexadecimalescapesequence: '\\x' HEXADECIMALDIGIT+; + +fragment Fractionalconstant: Digitsequence? '.' Digitsequence | Digitsequence '.'; + +fragment Exponentpart: 'e' SIGN? Digitsequence | 'E' SIGN? Digitsequence; + +fragment SIGN: [+-]; + +fragment Digitsequence: DIGIT ('\''? DIGIT)*; + +fragment Floatingsuffix: [flFL]; + +fragment Encodingprefix: 'u8' | 'u' | 'U' | 'L'; + +fragment Schar: ~ ["\\\r\n] | Escapesequence | Universalcharactername; + +fragment Rawstring: 'R"' ( '\\' ["()] | ~[\r\n (])*? '(' ~[)]*? ')' ( '\\' ["()] | ~[\r\n "])*? '"'; + +UserDefinedIntegerLiteral: + DecimalLiteral Udsuffix + | OctalLiteral Udsuffix + | HexadecimalLiteral Udsuffix + | BinaryLiteral Udsuffix +; + +UserDefinedFloatingLiteral: + Fractionalconstant Exponentpart? Udsuffix + | Digitsequence Exponentpart Udsuffix +; + +UserDefinedStringLiteral: StringLiteral Udsuffix; + +UserDefinedCharacterLiteral: CharacterLiteral Udsuffix; + +fragment Udsuffix: Identifier; + +Whitespace: [ \t]+ -> skip; + +Newline: ('\r' '\n'? | '\n') -> skip; + +BlockComment: '/*' .*? '*/' -> skip; + +LineComment: '//' ~ [\r\n]* -> skip; \ No newline at end of file diff --git a/chapi-ast-cpp/src/main/antlr/CPP14Parser.g4 b/chapi-ast-cpp/src/main/antlr/CPP14Parser.g4 new file mode 100644 index 00000000..b8ec3120 --- /dev/null +++ b/chapi-ast-cpp/src/main/antlr/CPP14Parser.g4 @@ -0,0 +1,1080 @@ +/******************************************************************************* + * The MIT License (MIT) + * + * Copyright (c) 2015 Camilo Sanchez (Camiloasc1) 2020 Martin Mirchev (Marti2203) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and + * associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT + * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * **************************************************************************** + */ + +// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false +// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging + +parser grammar CPP14Parser; + +options { + superClass = CPP14ParserBase; + tokenVocab = CPP14Lexer; +} + +// Insert here @header for C++ parser. + +/*Basic concepts*/ + +translationUnit + : declarationseq? EOF + ; + +/*Expressions*/ + +primaryExpression + : literal+ + | This + | LeftParen expression RightParen + | idExpression + | lambdaExpression + ; + +idExpression + : unqualifiedId + | qualifiedId + ; + +unqualifiedId + : Identifier + | operatorFunctionId + | conversionFunctionId + | literalOperatorId + | Tilde (className | decltypeSpecifier) + | templateId + ; + +qualifiedId + : nestedNameSpecifier Template? unqualifiedId + ; + +nestedNameSpecifier + : (theTypeName | namespaceName | decltypeSpecifier)? Doublecolon + | nestedNameSpecifier ( Identifier | Template? simpleTemplateId) Doublecolon + ; + +lambdaExpression + : lambdaIntroducer lambdaDeclarator? compoundStatement + ; + +lambdaIntroducer + : LeftBracket lambdaCapture? RightBracket + ; + +lambdaCapture + : captureList + | captureDefault (Comma captureList)? + ; + +captureDefault + : And + | Assign + ; + +captureList + : capture (Comma capture)* Ellipsis? + ; + +capture + : simpleCapture + | initcapture + ; + +simpleCapture + : And? Identifier + | This + ; + +initcapture + : And? Identifier initializer + ; + +lambdaDeclarator + : LeftParen parameterDeclarationClause? RightParen Mutable? exceptionSpecification? attributeSpecifierSeq? trailingReturnType? + ; + +postfixExpression + : primaryExpression + | postfixExpression LeftBracket (expression | bracedInitList) RightBracket + | postfixExpression LeftParen expressionList? RightParen + | (simpleTypeSpecifier | typeNameSpecifier) ( + LeftParen expressionList? RightParen + | bracedInitList + ) + | postfixExpression (Dot | Arrow) (Template? idExpression | pseudoDestructorName) + | postfixExpression (PlusPlus | MinusMinus) + | (Dynamic_cast | Static_cast | Reinterpret_cast | Const_cast) Less theTypeId Greater LeftParen expression RightParen + | typeIdOfTheTypeId LeftParen (expression | theTypeId) RightParen + ; + +/* + add a middle layer to eliminate duplicated function declarations + */ + +typeIdOfTheTypeId + : Typeid_ + ; + +expressionList + : initializerList + ; + +pseudoDestructorName + : nestedNameSpecifier? (theTypeName Doublecolon)? Tilde theTypeName + | nestedNameSpecifier Template simpleTemplateId Doublecolon Tilde theTypeName + | Tilde decltypeSpecifier + ; + +unaryExpression + : postfixExpression + | (PlusPlus | MinusMinus | unaryOperator | Sizeof) unaryExpression + | Sizeof (LeftParen theTypeId RightParen | Ellipsis LeftParen Identifier RightParen) + | Alignof LeftParen theTypeId RightParen + | noExceptExpression + | newExpression_ + | deleteExpression + ; + +unaryOperator + : Or + | Star + | And + | Plus + | Tilde + | Minus + | Not + ; + +newExpression_ + : Doublecolon? New newPlacement? (newTypeId | LeftParen theTypeId RightParen) newInitializer_? + ; + +newPlacement + : LeftParen expressionList RightParen + ; + +newTypeId + : typeSpecifierSeq newDeclarator_? + ; + +newDeclarator_ + : pointerOperator newDeclarator_? + | noPointerNewDeclarator + ; + +noPointerNewDeclarator + : LeftBracket expression RightBracket attributeSpecifierSeq? + | noPointerNewDeclarator LeftBracket constantExpression RightBracket attributeSpecifierSeq? + ; + +newInitializer_ + : LeftParen expressionList? RightParen + | bracedInitList + ; + +deleteExpression + : Doublecolon? Delete (LeftBracket RightBracket)? castExpression + ; + +noExceptExpression + : Noexcept LeftParen expression RightParen + ; + +castExpression + : unaryExpression + | LeftParen theTypeId RightParen castExpression + ; + +pointerMemberExpression + : castExpression ((DotStar | ArrowStar) castExpression)* + ; + +multiplicativeExpression + : pointerMemberExpression ((Star | Div | Mod) pointerMemberExpression)* + ; + +additiveExpression + : multiplicativeExpression ((Plus | Minus) multiplicativeExpression)* + ; + +shiftExpression + : additiveExpression (shiftOperator additiveExpression)* + ; + +shiftOperator + : Greater Greater + | Less Less + ; + +relationalExpression + : shiftExpression ((Less | Greater | LessEqual | GreaterEqual) shiftExpression)* + ; + +equalityExpression + : relationalExpression ((Equal | NotEqual) relationalExpression)* + ; + +andExpression + : equalityExpression (And equalityExpression)* + ; + +exclusiveOrExpression + : andExpression (Caret andExpression)* + ; + +inclusiveOrExpression + : exclusiveOrExpression (Or exclusiveOrExpression)* + ; + +logicalAndExpression + : inclusiveOrExpression (AndAnd inclusiveOrExpression)* + ; + +logicalOrExpression + : logicalAndExpression (OrOr logicalAndExpression)* + ; + +conditionalExpression + : logicalOrExpression (Question expression Colon assignmentExpression)? + ; + +assignmentExpression + : conditionalExpression + | logicalOrExpression assignmentOperator initializerClause + | throwExpression + ; + +assignmentOperator + : Assign + | StarAssign + | DivAssign + | ModAssign + | PlusAssign + | MinusAssign + | RightShiftAssign + | LeftShiftAssign + | AndAssign + | XorAssign + | OrAssign + ; + +expression + : assignmentExpression (Comma assignmentExpression)* + ; + +constantExpression + : conditionalExpression + ; + +/*Statements*/ + +statement + : labeledStatement + | declarationStatement + | attributeSpecifierSeq? ( + expressionStatement + | compoundStatement + | selectionStatement + | iterationStatement + | jumpStatement + | tryBlock + ) + ; + +labeledStatement + : attributeSpecifierSeq? (Identifier | Case constantExpression | Default) Colon statement + ; + +expressionStatement + : expression? Semi + ; + +compoundStatement + : LeftBrace statementSeq? RightBrace + ; + +statementSeq + : statement+ + ; + +selectionStatement + : If LeftParen condition RightParen statement (Else statement)? + | Switch LeftParen condition RightParen statement + ; + +condition + : expression + | attributeSpecifierSeq? declSpecifierSeq declarator ( + Assign initializerClause + | bracedInitList + ) + ; + +iterationStatement + : While LeftParen condition RightParen statement + | Do statement While LeftParen expression RightParen Semi + | For LeftParen ( + forInitStatement condition? Semi expression? + | forRangeDeclaration Colon forRangeInitializer + ) RightParen statement + ; + +forInitStatement + : expressionStatement + | simpleDeclaration + ; + +forRangeDeclaration + : attributeSpecifierSeq? declSpecifierSeq declarator + ; + +forRangeInitializer + : expression + | bracedInitList + ; + +jumpStatement + : (Break | Continue | Return (expression | bracedInitList)? | Goto Identifier) Semi + ; + +declarationStatement + : blockDeclaration + ; + +/*Declarations*/ + +declarationseq + : declaration+ + ; + +declaration + : blockDeclaration + | functionDefinition + | templateDeclaration + | explicitInstantiation + | explicitSpecialization + | linkageSpecification + | namespaceDefinition + | emptyDeclaration_ + | attributeDeclaration + ; + +blockDeclaration + : simpleDeclaration + | asmDefinition + | namespaceAliasDefinition + | usingDeclaration + | usingDirective + | staticAssertDeclaration + | aliasDeclaration + | opaqueEnumDeclaration + ; + +aliasDeclaration + : Using Identifier attributeSpecifierSeq? Assign theTypeId Semi + ; + +simpleDeclaration + : declSpecifierSeq? initDeclaratorList? Semi + | attributeSpecifierSeq declSpecifierSeq? initDeclaratorList Semi + ; + +staticAssertDeclaration + : Static_assert LeftParen constantExpression Comma StringLiteral RightParen Semi + ; + +emptyDeclaration_ + : Semi + ; + +attributeDeclaration + : attributeSpecifierSeq Semi + ; + +declSpecifier + : storageClassSpecifier + | typeSpecifier + | functionSpecifier + | Friend + | Typedef + | Constexpr + ; + +declSpecifierSeq + : declSpecifier+? attributeSpecifierSeq? + ; + +storageClassSpecifier + : Register + | Static + | Thread_local + | Extern + | Mutable + ; + +functionSpecifier + : Inline + | Virtual + | Explicit + ; + +typedefName + : Identifier + ; + +typeSpecifier + : trailingTypeSpecifier + | classSpecifier + | enumSpecifier + ; + +trailingTypeSpecifier + : simpleTypeSpecifier + | elaboratedTypeSpecifier + | typeNameSpecifier + | cvQualifier + ; + +typeSpecifierSeq + : typeSpecifier+ attributeSpecifierSeq? + ; + +trailingTypeSpecifierSeq + : trailingTypeSpecifier+ attributeSpecifierSeq? + ; + +simpleTypeLengthModifier + : Short + | Long + ; + +simpleTypeSignednessModifier + : Unsigned + | Signed + ; + +simpleTypeSpecifier + : nestedNameSpecifier? theTypeName + | nestedNameSpecifier Template simpleTemplateId + | Char + | Char16 + | Char32 + | Wchar + | Bool + | Short + | Int + | Long + | Float + | Signed + | Unsigned + | Float + | Double + | Void + | Auto + | decltypeSpecifier + ; + +theTypeName + : className + | enumName + | typedefName + | simpleTemplateId + ; + +decltypeSpecifier + : Decltype LeftParen (expression | Auto) RightParen + ; + +elaboratedTypeSpecifier + : classKey ( + attributeSpecifierSeq? nestedNameSpecifier? Identifier + | simpleTemplateId + | nestedNameSpecifier Template? simpleTemplateId + ) + | Enum nestedNameSpecifier? Identifier + ; + +enumName + : Identifier + ; + +enumSpecifier + : enumHead LeftBrace (enumeratorList Comma?)? RightBrace + ; + +enumHead + : enumkey attributeSpecifierSeq? (nestedNameSpecifier? Identifier)? enumbase? + ; + +opaqueEnumDeclaration + : enumkey attributeSpecifierSeq? Identifier enumbase? Semi + ; + +enumkey + : Enum (Class | Struct)? + ; + +enumbase + : Colon typeSpecifierSeq + ; + +enumeratorList + : enumeratorDefinition (Comma enumeratorDefinition)* + ; + +enumeratorDefinition + : enumerator (Assign constantExpression)? + ; + +enumerator + : Identifier + ; + +namespaceName + : originalNamespaceName + | namespaceAlias + ; + +originalNamespaceName + : Identifier + ; + +namespaceDefinition + : Inline? Namespace (Identifier | originalNamespaceName)? LeftBrace namespaceBody = declarationseq? RightBrace + ; + +namespaceAlias + : Identifier + ; + +namespaceAliasDefinition + : Namespace Identifier Assign qualifiednamespacespecifier Semi + ; + +qualifiednamespacespecifier + : nestedNameSpecifier? namespaceName + ; + +usingDeclaration + : Using (Typename_? nestedNameSpecifier | Doublecolon) unqualifiedId Semi + ; + +usingDirective + : attributeSpecifierSeq? Using Namespace nestedNameSpecifier? namespaceName Semi + ; + +asmDefinition + : Asm LeftParen StringLiteral RightParen Semi + ; + +linkageSpecification + : Extern StringLiteral (LeftBrace declarationseq? RightBrace | declaration) + ; + +attributeSpecifierSeq + : attributeSpecifier+ + ; + +attributeSpecifier + : LeftBracket LeftBracket attributeList? RightBracket RightBracket + | alignmentspecifier + ; + +alignmentspecifier + : Alignas LeftParen (theTypeId | constantExpression) Ellipsis? RightParen + ; + +attributeList + : attribute (Comma attribute)* Ellipsis? + ; + +attribute + : (attributeNamespace Doublecolon)? Identifier attributeArgumentClause? + ; + +attributeNamespace + : Identifier + ; + +attributeArgumentClause + : LeftParen balancedTokenSeq? RightParen + ; + +balancedTokenSeq + : balancedtoken+ + ; + +balancedtoken + : LeftParen balancedTokenSeq RightParen + | LeftBracket balancedTokenSeq RightBracket + | LeftBrace balancedTokenSeq RightBrace + | ~(LeftParen | RightParen | LeftBrace | RightBrace | LeftBracket | RightBracket)+ + ; + +/*Declarators*/ + +initDeclaratorList + : initDeclarator (Comma initDeclarator)* + ; + +initDeclarator + : declarator initializer? + ; + +declarator + : pointerDeclarator + | noPointerDeclarator parametersAndQualifiers trailingReturnType + ; + +pointerDeclarator + : (pointerOperator Const?)* noPointerDeclarator + ; + +noPointerDeclarator + : declaratorid attributeSpecifierSeq? + | noPointerDeclarator ( + parametersAndQualifiers + | LeftBracket constantExpression? RightBracket attributeSpecifierSeq? + ) + | LeftParen pointerDeclarator RightParen + ; + +parametersAndQualifiers + : LeftParen parameterDeclarationClause? RightParen cvqualifierseq? refqualifier? exceptionSpecification? attributeSpecifierSeq? + ; + +trailingReturnType + : Arrow trailingTypeSpecifierSeq abstractDeclarator? + ; + +pointerOperator + : (And | AndAnd) attributeSpecifierSeq? + | nestedNameSpecifier? Star attributeSpecifierSeq? cvqualifierseq? + ; + +cvqualifierseq + : cvQualifier+ + ; + +cvQualifier + : Const + | Volatile + ; + +refqualifier + : And + | AndAnd + ; + +declaratorid + : Ellipsis? idExpression + ; + +theTypeId + : typeSpecifierSeq abstractDeclarator? + ; + +abstractDeclarator + : pointerAbstractDeclarator + | noPointerAbstractDeclarator? parametersAndQualifiers trailingReturnType + | abstractPackDeclarator + ; + +pointerAbstractDeclarator + : noPointerAbstractDeclarator + | pointerOperator+ noPointerAbstractDeclarator? + ; + +noPointerAbstractDeclarator + : noPointerAbstractDeclarator ( + parametersAndQualifiers + | noPointerAbstractDeclarator LeftBracket constantExpression? RightBracket attributeSpecifierSeq? + ) + | parametersAndQualifiers + | LeftBracket constantExpression? RightBracket attributeSpecifierSeq? + | LeftParen pointerAbstractDeclarator RightParen + ; + +abstractPackDeclarator + : pointerOperator* noPointerAbstractPackDeclarator + ; + +noPointerAbstractPackDeclarator + : noPointerAbstractPackDeclarator ( + parametersAndQualifiers + | LeftBracket constantExpression? RightBracket attributeSpecifierSeq? + ) + | Ellipsis + ; + +parameterDeclarationClause + : parameterDeclarationList (Comma? Ellipsis)? + ; + +parameterDeclarationList + : parameterDeclaration (Comma parameterDeclaration)* + ; + +parameterDeclaration + : attributeSpecifierSeq? declSpecifierSeq (declarator | abstractDeclarator?) ( + Assign initializerClause + )? + ; + +functionDefinition + : attributeSpecifierSeq? declSpecifierSeq? declarator virtualSpecifierSeq? functionBody + ; + +functionBody + : constructorInitializer? compoundStatement + | functionTryBlock + | Assign (Default | Delete) Semi + ; + +initializer + : braceOrEqualInitializer + | LeftParen expressionList RightParen + ; + +braceOrEqualInitializer + : Assign initializerClause + | bracedInitList + ; + +initializerClause + : assignmentExpression + | bracedInitList + ; + +initializerList + : initializerClause Ellipsis? (Comma initializerClause Ellipsis?)* + ; + +bracedInitList + : LeftBrace (initializerList Comma?)? RightBrace + ; + +/*Classes*/ + +className + : Identifier + | simpleTemplateId + ; + +classSpecifier + : classHead LeftBrace memberSpecification? RightBrace + ; + +classHead + : classKey attributeSpecifierSeq? (classHeadName classVirtSpecifier?)? baseClause? + | Union attributeSpecifierSeq? ( classHeadName classVirtSpecifier?)? + ; + +classHeadName + : nestedNameSpecifier? className + ; + +classVirtSpecifier + : Final + ; + +classKey + : Class + | Struct + ; + +memberSpecification + : (memberdeclaration | accessSpecifier Colon)+ + ; + +memberdeclaration + : attributeSpecifierSeq? declSpecifierSeq? memberDeclaratorList? Semi + | functionDefinition + | usingDeclaration + | staticAssertDeclaration + | templateDeclaration + | aliasDeclaration + | emptyDeclaration_ + ; + +memberDeclaratorList + : memberDeclarator (Comma memberDeclarator)* + ; + +memberDeclarator + : declarator ( + virtualSpecifierSeq + | { this.IsPureSpecifierAllowed() }? pureSpecifier + | { this.IsPureSpecifierAllowed() }? virtualSpecifierSeq pureSpecifier + | braceOrEqualInitializer + ) + | declarator + | Identifier? attributeSpecifierSeq? Colon constantExpression + ; + +virtualSpecifierSeq + : virtualSpecifier+ + ; + +virtualSpecifier + : Override + | Final + ; + +/* + purespecifier: Assign '0'//Conflicts with the lexer ; + */ + +pureSpecifier + : Assign IntegerLiteral + ; + +/*Derived classes*/ + +baseClause + : Colon baseSpecifierList + ; + +baseSpecifierList + : baseSpecifier Ellipsis? (Comma baseSpecifier Ellipsis?)* + ; + +baseSpecifier + : attributeSpecifierSeq? ( + baseTypeSpecifier + | Virtual accessSpecifier? baseTypeSpecifier + | accessSpecifier Virtual? baseTypeSpecifier + ) + ; + +classOrDeclType + : nestedNameSpecifier? className + | decltypeSpecifier + ; + +baseTypeSpecifier + : classOrDeclType + ; + +accessSpecifier + : Private + | Protected + | Public + ; + +/*Special member functions*/ + +conversionFunctionId + : Operator conversionTypeId + ; + +conversionTypeId + : typeSpecifierSeq conversionDeclarator? + ; + +conversionDeclarator + : pointerOperator conversionDeclarator? + ; + +constructorInitializer + : Colon memInitializerList + ; + +memInitializerList + : memInitializer Ellipsis? (Comma memInitializer Ellipsis?)* + ; + +memInitializer + : meminitializerid (LeftParen expressionList? RightParen | bracedInitList) + ; + +meminitializerid + : classOrDeclType + | Identifier + ; + +/*Overloading*/ + +operatorFunctionId + : Operator theOperator + ; + +literalOperatorId + : Operator (StringLiteral Identifier | UserDefinedStringLiteral) + ; + +/*Templates*/ + +templateDeclaration + : Template Less templateparameterList Greater declaration + ; + +templateparameterList + : templateParameter (Comma templateParameter)* + ; + +templateParameter + : typeParameter + | parameterDeclaration + ; + +typeParameter + : ((Template Less templateparameterList Greater)? Class | Typename_) ( + Ellipsis? Identifier? + | Identifier? Assign theTypeId + ) + ; + +simpleTemplateId + : templateName Less templateArgumentList? Greater + ; + +templateId + : simpleTemplateId + | (operatorFunctionId | literalOperatorId) Less templateArgumentList? Greater + ; + +templateName + : Identifier + ; + +templateArgumentList + : templateArgument Ellipsis? (Comma templateArgument Ellipsis?)* + ; + +templateArgument + : theTypeId + | constantExpression + | idExpression + ; + +typeNameSpecifier + : Typename_ nestedNameSpecifier (Identifier | Template? simpleTemplateId) + ; + +explicitInstantiation + : Extern? Template declaration + ; + +explicitSpecialization + : Template Less Greater declaration + ; + +/*Exception handling*/ + +tryBlock + : Try compoundStatement handlerSeq + ; + +functionTryBlock + : Try constructorInitializer? compoundStatement handlerSeq + ; + +handlerSeq + : handler+ + ; + +handler + : Catch LeftParen exceptionDeclaration RightParen compoundStatement + ; + +exceptionDeclaration + : attributeSpecifierSeq? typeSpecifierSeq (declarator | abstractDeclarator)? + | Ellipsis + ; + +throwExpression + : Throw assignmentExpression? + ; + +exceptionSpecification + : dynamicExceptionSpecification + | noeExceptSpecification + ; + +dynamicExceptionSpecification + : Throw LeftParen typeIdList? RightParen + ; + +typeIdList + : theTypeId Ellipsis? (Comma theTypeId Ellipsis?)* + ; + +noeExceptSpecification + : Noexcept LeftParen constantExpression RightParen + | Noexcept + ; + +/*Preprocessing directives*/ + +/*Lexer*/ + +theOperator + : New (LeftBracket RightBracket)? + | Delete (LeftBracket RightBracket)? + | Plus + | Minus + | Star + | Div + | Mod + | Caret + | And + | Or + | Tilde + | Not + | Assign + | Greater + | Less + | GreaterEqual + | PlusAssign + | MinusAssign + | StarAssign + | ModAssign + | XorAssign + | AndAssign + | OrAssign + | Less Less + | Greater Greater + | RightShiftAssign + | LeftShiftAssign + | Equal + | NotEqual + | LessEqual + | AndAnd + | OrOr + | PlusPlus + | MinusMinus + | Comma + | ArrowStar + | Arrow + | LeftParen RightParen + | LeftBracket RightBracket + ; + +literal + : IntegerLiteral + | CharacterLiteral + | FloatingLiteral + | StringLiteral + | BooleanLiteral + | PointerLiteral + | UserDefinedLiteral + ; \ No newline at end of file diff --git a/chapi-ast-cpp/src/main/java/chapi/ast/antlr/CPP14ParserBase.java b/chapi-ast-cpp/src/main/java/chapi/ast/antlr/CPP14ParserBase.java new file mode 100644 index 00000000..5f5a3d5c --- /dev/null +++ b/chapi-ast-cpp/src/main/java/chapi/ast/antlr/CPP14ParserBase.java @@ -0,0 +1,24 @@ +package chapi.ast.antlr; + +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.tree.ParseTree; + +public abstract class CPP14ParserBase extends Parser { + protected CPP14ParserBase(TokenStream input) { + super(input); + } + + protected boolean IsPureSpecifierAllowed() { + try { + ParserRuleContext x = this._ctx;// memberDeclarator + ParseTree c = x.getChild(0).getChild(0); + ParseTree c2 = c.getChild(0); + ParseTree p = c2.getChild(1); + if (p == null) return false; + return (p instanceof CPP14Parser.ParametersAndQualifiersContext); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } +} diff --git a/chapi-ast-cpp/src/main/kotlin/chapi/ast/cppast/CPPAnalyser.kt b/chapi-ast-cpp/src/main/kotlin/chapi/ast/cppast/CPPAnalyser.kt index aa36b531..cc52becb 100644 --- a/chapi-ast-cpp/src/main/kotlin/chapi/ast/cppast/CPPAnalyser.kt +++ b/chapi-ast-cpp/src/main/kotlin/chapi/ast/cppast/CPPAnalyser.kt @@ -1,7 +1,7 @@ package chapi.ast.cppast -import chapi.ast.antlr.CPPLexer -import chapi.ast.antlr.CPPParser +import chapi.ast.antlr.CPP14Lexer +import chapi.ast.antlr.CPP14Parser import chapi.domain.core.CodeContainer import chapi.parser.Analyser import org.antlr.v4.runtime.CharStreams @@ -10,7 +10,7 @@ import org.antlr.v4.runtime.tree.ParseTreeWalker open class CPPAnalyser: Analyser { override fun analysis(code: String, filePath: String): CodeContainer { - val context = this.parse(code).translationunit() + val context = this.parse(code).translationUnit() val listener = CPPFullIdentListener(fileName = filePath) ParseTreeWalker().walk(listener, context) @@ -19,10 +19,9 @@ open class CPPAnalyser: Analyser { return nodeInfo } - open fun parse(str: String): CPPParser { - val fromString = CharStreams.fromString(str) - val lexer = CPPLexer (fromString) - val tokenStream = CommonTokenStream(lexer) - return CPPParser(tokenStream) - } + open fun parse(str: String): CPP14Parser = + CharStreams.fromString(str) + .let(::CPP14Lexer) + .let(::CommonTokenStream) + .let(::CPP14Parser) } diff --git a/chapi-ast-cpp/src/main/kotlin/chapi/ast/cppast/CPPFullIdentListener.kt b/chapi-ast-cpp/src/main/kotlin/chapi/ast/cppast/CPPFullIdentListener.kt index 34bbec3a..00c8a60a 100644 --- a/chapi-ast-cpp/src/main/kotlin/chapi/ast/cppast/CPPFullIdentListener.kt +++ b/chapi-ast-cpp/src/main/kotlin/chapi/ast/cppast/CPPFullIdentListener.kt @@ -1,73 +1,74 @@ package chapi.ast.cppast -import chapi.ast.antlr.CPPBaseListener -import chapi.ast.antlr.CPPParser +import chapi.ast.antlr.CPP14Parser +import chapi.ast.antlr.CPP14ParserBaseListener import chapi.domain.core.CodeContainer import chapi.domain.core.CodeDataStruct import chapi.domain.core.CodeFunction -import chapi.domain.core.CodeProperty -class CPPFullIdentListener(fileName: String) : CPPBaseListener() { +class CPPFullIdentListener(fileName: String) : CPP14ParserBaseListener() { private var codeContainer: CodeContainer = CodeContainer(FullName = fileName) private var defaultNode = CodeDataStruct() - override fun enterFunctiondefinition(ctx: CPPParser.FunctiondefinitionContext?) { + override fun enterFunctionDefinition(ctx: CPP14Parser.FunctionDefinitionContext?) { val method = CodeFunction() val context = ctx!! - if (context.declspecifierseq() != null) { - method.ReturnType = context.declspecifierseq().text + if (context.declSpecifierSeq() != null) { + method.ReturnType = context.declSpecifierSeq().text } - val firstPtrDecl = context.declarator().ptrdeclarator() + val firstPtrDecl = context.declarator().pointerDeclarator() if (firstPtrDecl != null) { - if (firstPtrDecl.noptrdeclarator() != null) { + if (firstPtrDecl.noPointerDeclarator() != null) { tryFunctionBuild(firstPtrDecl, method) } } } - private fun tryFunctionBuild(firstPtrDecl: CPPParser.PtrdeclaratorContext, method: CodeFunction) { - val parametersandqualifiers = firstPtrDecl.noptrdeclarator().parametersandqualifiers() - if (parametersandqualifiers != null) { - val functionName = firstPtrDecl.noptrdeclarator().noptrdeclarator().text + private fun tryFunctionBuild(firstPtrDecl: CPP14Parser.PointerDeclaratorContext, method: CodeFunction) { + val parametersAndQualifiersContext = firstPtrDecl.noPointerDeclarator().parametersAndQualifiers() + if (parametersAndQualifiersContext != null) { + val functionName = firstPtrDecl.noPointerDeclarator().noPointerDeclarator().text method.Name = functionName - if (parametersandqualifiers.parameterdeclarationclause() != null) { - buildParameters(parametersandqualifiers.parameterdeclarationclause(), method) + if (parametersAndQualifiersContext.parameterDeclarationClause() != null) { + buildParameters(parametersAndQualifiersContext.parameterDeclarationClause(), method) } defaultNode.Functions += method } - } - private fun buildParameters(paramDecl: CPPParser.ParameterdeclarationclauseContext, method: CodeFunction) { - if (paramDecl.parameterdeclarationlist() != null) { - buildParameter(paramDecl.parameterdeclarationlist()!!, method) - } } - private fun buildParameter( - paramDeclCtx: CPPParser.ParameterdeclarationlistContext, - method: CodeFunction - ) { - if (paramDeclCtx.parameterdeclarationlist() != null) { - buildParameter(paramDeclCtx.parameterdeclarationlist(), method) + private fun buildParameters(parameterDeclarationClause: CPP14Parser.ParameterDeclarationClauseContext, method: CodeFunction) { + if (parameterDeclarationClause.parameterDeclarationList() != null) { + buildParameter(parameterDeclarationClause.parameterDeclarationList()!!, method) } - val paramDecl = paramDeclCtx.parameterdeclaration() - if (paramDecl != null) { - val declspecifierseq = paramDecl.declspecifierseq() - val type = declspecifierseq.declspecifier().typespecifier().text - val param = CodeProperty(TypeType = type, TypeValue = "") - - if (paramDecl.declarator() != null) { - param.TypeValue = paramDecl.declarator().text - } + } - method.Parameters += param + private fun buildParameter(parameterDeclarationList: CPP14Parser.ParameterDeclarationListContext, method: CodeFunction) { +// if (parameterDeclarationList.parameterDeclaration() != null) { +// buildParameter(parameterDeclarationList.parameterDeclarationList(), method) +// parameterDeclarationList.parameterDeclaration().forEach { +// buildParameter(it, method) +// } +// } + val parameterDeclaration = parameterDeclarationList.parameterDeclaration() + if (parameterDeclaration != null) { +// val declSpecifierSeq = parameterDeclaration.declSpecifierSeq() +// val declSpecifierSeq = parameterDeclaration +// val type = declSpecifierSeq.declSpecifier().typeSpecifier().text +// val param = CodeProperty(TypeType = type, TypeValue = "") +// +// if (parameterDeclaration.declarator() != null) { +// param.TypeValue = parameterDeclaration.declarator().text +// } +// method.Parameters += param } } + fun getNodeInfo(): CodeContainer { if (defaultNode.Functions.isNotEmpty()) { codeContainer.DataStructures += defaultNode