Changeset 2ed94a9 for src/Parser


Ignore:
Timestamp:
Feb 8, 2023, 2:27:55 PM (18 months ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, master
Children:
b110bcc
Parents:
997185e (diff), ccb29b4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/Parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.ll

    r997185e r2ed94a9  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Thu Oct 13 20:46:04 2022
    13  * Update Count     : 764
     12 * Last Modified On : Mon Jan 30 19:03:34 2023
     13 * Update Count     : 767
    1414 */
    1515
     
    340340vtable                  { KEYWORD_RETURN(VTABLE); }                             // CFA
    341341waitfor                 { KEYWORD_RETURN(WAITFOR); }                    // CFA
     342waituntil               { KEYWORD_RETURN(WAITUNTIL); }                  // CFA
    342343when                    { KEYWORD_RETURN(WHEN); }                               // CFA
    343344while                   { KEYWORD_RETURN(WHILE); }
     
    502503        SemanticErrorThrow = true;
    503504        cerr << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1
    504                  << ": " << ErrorHelpers::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl;
     505                 << ": " << ErrorHelpers::error_str() << errmsg << " before token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl;
    505506}
    506507
  • src/Parser/parser.yy

    r997185e r2ed94a9  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Nov 21 22:34:30 2022
    13 // Update Count     : 5848
     12// Last Modified On : Thu Feb  2 21:36:16 2023
     13// Update Count     : 5865
    1414//
    1515
     
    331331%token ATTRIBUTE EXTENSION                                                              // GCC
    332332%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
    333 %token CHOOSE FALLTHRU FALLTHROUGH WITH WHEN WAITFOR    // CFA
     333%token CHOOSE FALLTHRU FALLTHROUGH WITH WHEN WAITFOR WAITUNTIL // CFA
    334334%token DISABLE ENABLE TRY THROW THROWRESUME AT                  // CFA
    335335%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
     
    16451645exception_statement:
    16461646        TRY compound_statement handler_clause                                   %prec THEN
    1647                 { $$ = new StatementNode( build_try( $2, $3, 0 ) ); }
     1647                { $$ = new StatementNode( build_try( $2, $3, nullptr ) ); }
    16481648        | TRY compound_statement finally_clause
    1649                 { $$ = new StatementNode( build_try( $2, 0, $3 ) ); }
     1649                { $$ = new StatementNode( build_try( $2, nullptr, $3 ) ); }
    16501650        | TRY compound_statement handler_clause finally_clause
    16511651                { $$ = new StatementNode( build_try( $2, $3, $4 ) ); }
     
    16991699asm_statement:
    17001700        ASM asm_volatile_opt '(' string_literal ')' ';'
    1701                 { $$ = new StatementNode( build_asm( $2, $4, 0 ) ); }
     1701                { $$ = new StatementNode( build_asm( $2, $4, nullptr ) ); }
    17021702        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC
    17031703                { $$ = new StatementNode( build_asm( $2, $4, $6 ) ); }
     
    17071707                { $$ = new StatementNode( build_asm( $2, $4, $6, $8, $10 ) ); }
    17081708        | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
    1709                 { $$ = new StatementNode( build_asm( $2, $5, 0, $8, $10, $12 ) ); }
     1709                { $$ = new StatementNode( build_asm( $2, $5, nullptr, $8, $10, $12 ) ); }
    17101710        ;
    17111711
     
    18801880//      '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict
    18811881//              {
    1882 //                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
     1882//                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, nullptr, true );
    18831883//              }
    18841884//      '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')'
    18851885//              {
    18861886//                      typedefTable.setNextIdentifier( *$5 );
    1887 //                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
     1887//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, nullptr, true );
    18881888//              }
    18891889//      | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')'
    18901890//              {
    18911891//                      typedefTable.setNextIdentifier( *$5 );
    1892 //                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
     1892//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, nullptr, true );
    18931893//              }
    18941894//      | '[' ']' typegen_name
     
    19021902        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
    19031903                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    1904                 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); }
     1904                { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); }
    19051905        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
    1906                 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); }
     1906                { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); }
    19071907        ;
    19081908
     
    19391939        TYPEDEF type_specifier declarator
    19401940                {
     1941                        // if type_specifier is an anon aggregate => name
    19411942                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" );
    19421943                        $$ = $3->addType( $2 )->addTypedef();
     
    19951996declaration_specifier:                                                                  // type specifier + storage class
    19961997        basic_declaration_specifier
     1998        | type_declaration_specifier
    19971999        | sue_declaration_specifier
    1998         | type_declaration_specifier
     2000        | sue_declaration_specifier invalid_types
     2001                {
     2002                        SemanticError( yylloc,
     2003                                                  ::toString( "Missing ';' after end of ",
     2004                                                                          $1->type->enumeration.name ? "enum" : AggregateDecl::aggrString( $1->type->aggregate.kind ),
     2005                                                                          " declaration" ) );
     2006                        $$ = nullptr;
     2007                }
     2008        ;
     2009
     2010invalid_types:
     2011        aggregate_key
     2012        | basic_type_name
     2013        | indirect_type
    19992014        ;
    20002015
     
    20652080                { $$ = DeclarationNode::newTypeQualifier( Type::Atomic ); }
    20662081        | forall
     2082                { $$ = DeclarationNode::newForall( $1 ); }
    20672083        ;
    20682084
    20692085forall:
    20702086        FORALL '(' type_parameter_list ')'                                      // CFA
    2071                 { $$ = DeclarationNode::newForall( $3 ); }
     2087                { $$ = $3; }
    20722088        ;
    20732089
     
    24732489        | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
    24742490                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
     2491        | STATIC type_specifier field_declaring_list_opt ';' // CFA
     2492                { SemanticError( yylloc, "STATIC aggregate field qualifier currently unimplemented." ); $$ = nullptr; }
    24752493        | INLINE type_specifier field_abstract_list_opt ';'     // CFA
    24762494                {
     
    25952613enum_type_nobody:                                                                               // enum - {...}
    25962614        ENUM attribute_list_opt identifier
    2597                 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false, false )->addQualifiers( $2 ); }
     2615                { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, nullptr, false, false )->addQualifiers( $2 ); }
    25982616        | ENUM attribute_list_opt type_name
    2599                 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false, false )->addQualifiers( $2 ); }
     2617                { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, nullptr, false, false )->addQualifiers( $2 ); }
    26002618        ;
    26012619
     
    29382956                {
    29392957                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" );
    2940                         $$ = DeclarationNode::newTypeDecl( $1, 0 );
     2958                        $$ = DeclarationNode::newTypeDecl( $1, nullptr );
    29412959                }
    29422960        | identifier_or_type_name '(' type_parameter_list ')'
     
    29492967trait_specifier:                                                                                // CFA
    29502968        TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' '}'
    2951                 { $$ = DeclarationNode::newTrait( $2, $4, 0 ); }
     2969                {
     2970                        SemanticWarning( yylloc, Warning::DeprecTraitSyntax, "" );
     2971                        $$ = DeclarationNode::newTrait( $2, $4, nullptr );
     2972                }
     2973        | forall TRAIT identifier_or_type_name '{' '}'          // alternate
     2974                { $$ = DeclarationNode::newTrait( $3, $1, nullptr ); }
    29522975        | TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
    2953                 { $$ = DeclarationNode::newTrait( $2, $4, $8 ); }
     2976                {
     2977                        SemanticWarning( yylloc, Warning::DeprecTraitSyntax, "" );
     2978                        $$ = DeclarationNode::newTrait( $2, $4, $8 );
     2979                }
     2980        | forall TRAIT identifier_or_type_name '{' push trait_declaration_list pop '}' // alternate
     2981                { $$ = DeclarationNode::newTrait( $3, $1, $6 ); }
    29542982        ;
    29552983
     
    30313059                }
    30323060        | ASM '(' string_literal ')' ';'                                        // GCC, global assembler statement
    3033                 { $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, 0 ) ) ); }
     3061                { $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, nullptr ) ) ); }
    30343062        | EXTERN STRINGliteral
    30353063                {
     
    32753303variable_ptr:
    32763304        ptrref_operator variable_declarator
    3277                 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3305                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    32783306        | ptrref_operator type_qualifier_list variable_declarator
    32793307                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
     
    33393367function_ptr:
    33403368        ptrref_operator function_declarator
    3341                 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3369                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    33423370        | ptrref_operator type_qualifier_list function_declarator
    33433371                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
     
    33913419KR_function_ptr:
    33923420        ptrref_operator KR_function_declarator
    3393                 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3421                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    33943422        | ptrref_operator type_qualifier_list KR_function_declarator
    33953423                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
     
    34473475type_ptr:
    34483476        ptrref_operator variable_type_redeclarator
    3449                 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3477                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    34503478        | ptrref_operator type_qualifier_list variable_type_redeclarator
    34513479                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
     
    35053533identifier_parameter_ptr:
    35063534        ptrref_operator identifier_parameter_declarator
    3507                 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3535                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    35083536        | ptrref_operator type_qualifier_list identifier_parameter_declarator
    35093537                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
     
    35623590type_parameter_ptr:
    35633591        ptrref_operator type_parameter_redeclarator
    3564                 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3592                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    35653593        | ptrref_operator type_qualifier_list type_parameter_redeclarator
    35663594                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
     
    36053633abstract_ptr:
    36063634        ptrref_operator
    3607                 { $$ = DeclarationNode::newPointer( 0, $1 ); }
     3635                { $$ = DeclarationNode::newPointer( nullptr, $1 ); }
    36083636        | ptrref_operator type_qualifier_list
    36093637                { $$ = DeclarationNode::newPointer( $2, $1 ); }
    36103638        | ptrref_operator abstract_declarator
    3611                 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3639                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    36123640        | ptrref_operator type_qualifier_list abstract_declarator
    36133641                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
     
    36383666                // Only the first dimension can be empty.
    36393667        '[' ']'
    3640                 { $$ = DeclarationNode::newArray( 0, 0, false ); }
     3668                { $$ = DeclarationNode::newArray( nullptr, nullptr, false ); }
    36413669        | '[' ']' multi_array_dimension
    3642                 { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); }
     3670                { $$ = DeclarationNode::newArray( nullptr, nullptr, false )->addArray( $3 ); }
    36433671                // Cannot use constant_expression because of tuples => semantic check
    36443672        | '[' push assignment_expression pop ',' comma_expression ']' // CFA
    3645                 { $$ = DeclarationNode::newArray( $3, 0, false )->addArray( DeclarationNode::newArray( $6, 0, false ) ); }
     3673                { $$ = DeclarationNode::newArray( $3, nullptr, false )->addArray( DeclarationNode::newArray( $6, nullptr, false ) ); }
    36463674                // { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; }
    36473675        | '[' push array_type_list pop ']'                                      // CFA
     
    36723700multi_array_dimension:
    36733701        '[' push assignment_expression pop ']'
    3674                 { $$ = DeclarationNode::newArray( $3, 0, false ); }
     3702                { $$ = DeclarationNode::newArray( $3, nullptr, false ); }
    36753703        | '[' push '*' pop ']'                                                          // C99
    36763704                { $$ = DeclarationNode::newVarArray( 0 ); }
    36773705        | multi_array_dimension '[' push assignment_expression pop ']'
    3678                 { $$ = $1->addArray( DeclarationNode::newArray( $4, 0, false ) ); }
     3706                { $$ = $1->addArray( DeclarationNode::newArray( $4, nullptr, false ) ); }
    36793707        | multi_array_dimension '[' push '*' pop ']'            // C99
    36803708                { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); }
     
    37733801array_parameter_1st_dimension:
    37743802        '[' ']'
    3775                 { $$ = DeclarationNode::newArray( 0, 0, false ); }
     3803                { $$ = DeclarationNode::newArray( nullptr, nullptr, false ); }
    37763804                // multi_array_dimension handles the '[' '*' ']' case
    37773805        | '[' push type_qualifier_list '*' pop ']'                      // remaining C99
    37783806                { $$ = DeclarationNode::newVarArray( $3 ); }
    37793807        | '[' push type_qualifier_list pop ']'
    3780                 { $$ = DeclarationNode::newArray( 0, $3, false ); }
     3808                { $$ = DeclarationNode::newArray( nullptr, $3, false ); }
    37813809                // multi_array_dimension handles the '[' assignment_expression ']' case
    37823810        | '[' push type_qualifier_list assignment_expression pop ']'
     
    38073835variable_abstract_ptr:
    38083836        ptrref_operator
    3809                 { $$ = DeclarationNode::newPointer( 0, $1 ); }
     3837                { $$ = DeclarationNode::newPointer( nullptr, $1 ); }
    38103838        | ptrref_operator type_qualifier_list
    38113839                { $$ = DeclarationNode::newPointer( $2, $1 ); }
    38123840        | ptrref_operator variable_abstract_declarator
    3813                 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3841                { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    38143842        | ptrref_operator type_qualifier_list variable_abstract_declarator
    38153843                { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
     
    38533881                // No SUE declaration in parameter list.
    38543882        ptrref_operator type_specifier_nobody
    3855                 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3883                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    38563884        | type_qualifier_list ptrref_operator type_specifier_nobody
    38573885                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
    38583886        | ptrref_operator cfa_abstract_function
    3859                 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3887                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    38603888        | type_qualifier_list ptrref_operator cfa_abstract_function
    38613889                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
    38623890        | ptrref_operator cfa_identifier_parameter_declarator_tuple
    3863                 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3891                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    38643892        | type_qualifier_list ptrref_operator cfa_identifier_parameter_declarator_tuple
    38653893                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
     
    38703898                // shift/reduce conflict with new-style empty (void) function return type.
    38713899        '[' ']' type_specifier_nobody
    3872                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     3900                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    38733901        | cfa_array_parameter_1st_dimension type_specifier_nobody
    38743902                { $$ = $2->addNewArray( $1 ); }
    38753903        | '[' ']' multi_array_dimension type_specifier_nobody
    3876                 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     3904                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    38773905        | cfa_array_parameter_1st_dimension multi_array_dimension type_specifier_nobody
    38783906                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
     
    38813909
    38823910        | '[' ']' cfa_identifier_parameter_ptr
    3883                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     3911                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    38843912        | cfa_array_parameter_1st_dimension cfa_identifier_parameter_ptr
    38853913                { $$ = $2->addNewArray( $1 ); }
    38863914        | '[' ']' multi_array_dimension cfa_identifier_parameter_ptr
    3887                 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     3915                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    38883916        | cfa_array_parameter_1st_dimension multi_array_dimension cfa_identifier_parameter_ptr
    38893917                { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
     
    39413969cfa_abstract_ptr:                                                                               // CFA
    39423970        ptrref_operator type_specifier
    3943                 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3971                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    39443972        | type_qualifier_list ptrref_operator type_specifier
    39453973                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
    39463974        | ptrref_operator cfa_abstract_function
    3947                 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3975                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    39483976        | type_qualifier_list ptrref_operator cfa_abstract_function
    39493977                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
    39503978        | ptrref_operator cfa_abstract_declarator_tuple
    3951                 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
     3979                { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
    39523980        | type_qualifier_list ptrref_operator cfa_abstract_declarator_tuple
    39533981                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
Note: See TracChangeset for help on using the changeset viewer.