Ignore:
Timestamp:
Mar 4, 2021, 7:40:25 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
77d601f
Parents:
342af53 (diff), a5040fe (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r342af53 r8e4aa05  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 11 21:32:10 2021
    13 // Update Count     : 4633
     12// Last Modified On : Wed Feb 17 09:03:07 2021
     13// Update Count     : 4722
    1414//
    1515
     
    4141
    4242%{
    43 #define YYDEBUG_LEXER_TEXT (yylval)                                             // lexer loads this up each time
     43#define YYDEBUG_LEXER_TEXT( yylval )                                    // lexer loads this up each time
    4444#define YYDEBUG 1                                                                               // get the pretty debugging code to compile
    4545#define YYERROR_VERBOSE                                                                 // more information in syntax errors
     
    6363extern TypedefTable typedefTable;
    6464
    65 stack< LinkageSpec::Spec > linkageStack;
     65stack<LinkageSpec::Spec> linkageStack;
    6666
    6767bool appendStr( string & to, string & from ) {
     
    187187        ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get());
    188188        if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) {
    189         type = new ExpressionNode( new CastExpr( maybeMoveBuild< Expression >(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
     189                type = new ExpressionNode( new CastExpr( maybeMoveBuild<Expression>(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
    190190        } // if
    191191        return new ForCtrl(
     
    282282%token ATTRIBUTE EXTENSION                                                              // GCC
    283283%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
    284 %token CHOOSE DISABLE ENABLE FALLTHRU FALLTHROUGH TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH WHEN WAITFOR // CFA
     284%token CHOOSE DISABLE ENABLE FALLTHRU FALLTHROUGH TRY THROW THROWRESUME AT WITH WHEN WAITFOR // CFA
    285285%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    286286%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
    287287
    288288// names and constants: lexer differentiates between identifier and typedef names
    289 %token<tok> IDENTIFIER                  QUOTED_IDENTIFIER               TYPEDEFname                             TYPEGENname
    290 %token<tok> TIMEOUT                             WOR
    291 %token<tok> INTEGERconstant             CHARACTERconstant               STRINGliteral
     289%token<tok> IDENTIFIER          QUOTED_IDENTIFIER       TYPEDEFname             TYPEGENname
     290%token<tok> TIMEOUT                     WOR                                     CATCH                   RECOVER                 CATCHRESUME             FIXUP           FINALLY         // CFA
     291%token<tok> INTEGERconstant     CHARACTERconstant       STRINGliteral
    292292%token<tok> DIRECTIVE
    293293// Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and
     
    440440
    441441%type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list
    442 %type<decl> type_specifier type_specifier_nobody
     442%type<decl> type_specifier type_specifier_nobody enum_specifier_nobody
    443443
    444444%type<decl> variable_declarator variable_ptr variable_array variable_function
    445445%type<decl> variable_abstract_declarator variable_abstract_ptr variable_abstract_array variable_abstract_function
    446446
    447 %type<decl> attribute_list_opt attribute_list attribute_name_list attribute attribute_name
     447%type<decl> attribute_list_opt attribute_list attribute_opt attribute attribute_name_list attribute_name
    448448
    449449// initializers
     
    462462// Order of these lines matters (low-to-high precedence). THEN is left associative over WOR/TIMEOUT/ELSE, WOR is left
    463463// associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE.
    464 %precedence THEN        // rule precedence for IF/WAITFOR statement
    465 %precedence WOR         // token precedence for start of WOR in WAITFOR statement
    466 %precedence TIMEOUT     // token precedence for start of TIMEOUT in WAITFOR statement
    467 %precedence ELSE        // token precedence for start of else clause in IF/WAITFOR statement
     464%precedence THEN                // rule precedence for IF/WAITFOR statement
     465%precedence WOR                 // token precedence for start of WOR in WAITFOR statement
     466%precedence TIMEOUT             // token precedence for start of TIMEOUT in WAITFOR statement
     467%precedence CATCH               // token precedence for start of TIMEOUT in WAITFOR statement
     468%precedence RECOVER             // token precedence for start of TIMEOUT in WAITFOR statement
     469%precedence CATCHRESUME // token precedence for start of TIMEOUT in WAITFOR statement
     470%precedence FIXUP               // token precedence for start of TIMEOUT in WAITFOR statement
     471%precedence FINALLY             // token precedence for start of TIMEOUT in WAITFOR statement
     472%precedence ELSE                // token precedence for start of else clause in IF/WAITFOR statement
     473
    468474
    469475// Handle shift/reduce conflict for generic type by shifting the '(' token. For example, this string is ambiguous:
     
    544550        TIMEOUT
    545551        | WOR
     552        | CATCH
     553        | RECOVER
     554        | CATCHRESUME
     555        | FIXUP
     556        | FINALLY
    546557        ;
    547558
     
    578589                { $$ = $2; }
    579590        | '(' compound_statement ')'                                            // GCC, lambda expression
    580                 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); }
     591                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); }
    581592        | type_name '.' identifier                                                      // CFA, nested type
    582593                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     
    610621                {
    611622                        // create a GenericExpr wrapper with one association pair
    612                         $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>($3) } } );
     623                        $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>( $3 ) } } );
    613624                }
    614625        | DEFAULT ':' assignment_expression
    615                 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); }
     626                { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>( $3 ) } } ); }
    616627        ;
    617628
    618629postfix_expression:
    619630        primary_expression
     631        | postfix_expression '[' assignment_expression ',' comma_expression ']'
     632                // { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_binary_val( OperKinds::Index, $3, $5 ) ) ) ); }
     633                { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; }
    620634        | postfix_expression '[' assignment_expression ']'
    621635                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
     
    743757                        switch ( $1 ) {
    744758                          case OperKinds::AddressOf:
    745                                 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild< Expression >( $2 ) ) );
     759                                $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) );
    746760                                break;
    747761                          case OperKinds::PointTo:
     
    749763                                break;
    750764                          case OperKinds::And:
    751                                 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild< Expression >( $2 ) ) ) );
     765                                $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) ) );
    752766                                break;
    753767                          default:
     
    762776                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); }
    763777        | SIZEOF unary_expression
    764                 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild< Expression >( $2 ) ) ); }
     778                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }
    765779        | SIZEOF '(' type_no_function ')'
    766780                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuildType( $3 ) ) ); }
    767781        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    768                 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild< Expression >( $2 ) ) ); }
     782                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }
    769783        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    770784                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); }
     
    794808                { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }
    795809        | '(' VIRTUAL ')' cast_expression                                       // CFA
    796                 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); }
     810                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); }
    797811        | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
    798                 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); }
     812                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); }
    799813        | '(' RETURN type_no_function ')' cast_expression       // CFA
    800814                { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; }
     
    977991        assignment_expression
    978992        | comma_expression ',' assignment_expression
    979                 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
     993                { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
    980994        ;
    981995
     
    11021116        constant_expression                                                     { $$ = $1; }
    11031117        | constant_expression ELLIPSIS constant_expression      // GCC, subrange
    1104                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
     1118                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
    11051119        | subrange                                                                                      // CFA, subrange
    11061120        ;
     
    12471261                { $$ = new StatementNode( build_computedgoto( $3 ) ); }
    12481262                // A semantic check is required to ensure fallthru appears only in the body of a choose statement.
    1249     | fall_through_name ';'                                                             // CFA
     1263        | fall_through_name ';'                                                         // CFA
    12501264                { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); }
    1251     | fall_through_name identifier_or_type_name ';'             // CFA
     1265        | fall_through_name identifier_or_type_name ';'         // CFA
    12521266                { $$ = new StatementNode( build_branch( $2, BranchStmt::FallThrough ) ); }
    12531267        | fall_through_name DEFAULT ';'                                         // CFA
     
    13631377
    13641378exception_statement:
    1365         TRY compound_statement handler_clause
     1379        TRY compound_statement handler_clause                                   %prec THEN
    13661380                { $$ = new StatementNode( build_try( $2, $3, 0 ) ); }
    13671381        | TRY compound_statement finally_clause
     
    13861400handler_key:
    13871401        CATCH                                                                           { $$ = CatchStmt::Terminate; }
     1402        | RECOVER                                                                       { $$ = CatchStmt::Terminate; }
    13881403        | CATCHRESUME                                                           { $$ = CatchStmt::Resume; }
     1404        | FIXUP                                                                         { $$ = CatchStmt::Resume; }
    13891405        ;
    13901406
     
    14481464asm_operand:                                                                                    // GCC
    14491465        string_literal '(' constant_expression ')'
    1450                 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild< Expression >( $3 ) ) ); }
     1466                { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    14511467        | '[' IDENTIFIER ']' string_literal '(' constant_expression ')'
    1452                 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild< Expression >( $6 ) ) ); }
     1468                { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild<Expression>( $6 ) ) ); }
    14531469        ;
    14541470
     
    17361752        | sue_type_specifier_nobody
    17371753        | type_type_specifier
     1754        ;
     1755
     1756enum_specifier_nobody:                                                                  // type specifier - {...}
     1757                // Preclude SUE declarations in restricted scopes (see type_specifier_nobody)
     1758        basic_type_specifier
     1759        | sue_type_specifier_nobody
    17381760        ;
    17391761
     
    20042026        ;
    20052027
    2006 fred:
    2007         // empty
    2008                 { yyy = false; }
    2009         ;
    2010 
    20112028aggregate_type:                                                                                 // struct, union
    20122029        aggregate_key attribute_list_opt
     
    20142031          '{' field_declaration_list_opt '}' type_parameters_opt
    20152032                { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 ); }
    2016         | aggregate_key attribute_list_opt identifier fred
     2033        | aggregate_key attribute_list_opt identifier
    20172034                {
    20182035                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef
     
    20202037                }
    20212038          '{' field_declaration_list_opt '}' type_parameters_opt
    2022                 { $$ = DeclarationNode::newAggregate( $1, $3, $9, $7, true )->addQualifiers( $2 ); }
    2023         | aggregate_key attribute_list_opt type_name fred
     2039                { $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); }
     2040        | aggregate_key attribute_list_opt type_name
    20242041                {
    20252042                        // for type_name can be a qualified type name S.T, in which case only the last name in the chain needs a typedef (other names in the chain should already have one)
     
    20282045                }
    20292046          '{' field_declaration_list_opt '}' type_parameters_opt
    2030                 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $9, $7, true )->addQualifiers( $2 ); }
     2047                { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $8, $6, true )->addQualifiers( $2 ); }
    20312048        | aggregate_type_nobody
    20322049        ;
     
    20402057
    20412058aggregate_type_nobody:                                                                  // struct, union - {...}
    2042         aggregate_key attribute_list_opt identifier fred
     2059        aggregate_key attribute_list_opt identifier
    20432060                {
    20442061                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname );
     
    20462063                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    20472064                }
    2048         | aggregate_key attribute_list_opt type_name fred
     2065        | aggregate_key attribute_list_opt type_name
    20492066                {
    20502067                        forall = false;                                                         // reset
     
    21842201        ;
    21852202
     2203// Cannot use attribute_list_opt because of ambiguity with enum_specifier_nobody, which already parses attribute.
     2204// Hence, only a single attribute is allowed after the "ENUM".
    21862205enum_type:                                                                                              // enum
    2187         ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
     2206        ENUM attribute_opt '{' enumerator_list comma_opt '}'
    21882207                { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
    2189         | ENUM attribute_list_opt identifier
     2208        | ENUM attribute_opt identifier
    21902209                { typedefTable.makeTypedef( *$3 ); }
    21912210          '{' enumerator_list comma_opt '}'
    21922211                { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
    2193         | ENUM attribute_list_opt type_name
     2212        | ENUM attribute_opt typedef                                            // enum cannot be generic
    21942213          '{' enumerator_list comma_opt '}'
    2195                 { $$ = DeclarationNode::newEnum( $3->type->symbolic.name, $5, true )->addQualifiers( $2 ); }
     2214                { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }
     2215        | ENUM enum_specifier_nobody '{' enumerator_list comma_opt '}'
     2216                // { $$ = DeclarationNode::newEnum( nullptr, $4, true ); }
     2217                { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; }
     2218        | ENUM enum_specifier_nobody declarator '{' enumerator_list comma_opt '}'
     2219                // {
     2220                //      typedefTable.makeTypedef( *$3->name );
     2221                //      $$ = DeclarationNode::newEnum( nullptr, $5, true );
     2222                // }
     2223                { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; }
    21962224        | enum_type_nobody
    21972225        ;
    21982226
    21992227enum_type_nobody:                                                                               // enum - {...}
    2200         ENUM attribute_list_opt identifier
     2228        ENUM attribute_opt identifier
    22012229                {
    22022230                        typedefTable.makeTypedef( *$3 );
    22032231                        $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 );
    22042232                }
    2205         | ENUM attribute_list_opt type_name
     2233        | ENUM attribute_opt type_name                                          // enum cannot be generic
    22062234                {
    22072235                        typedefTable.makeTypedef( *$3->type->symbolic.name );
     
    22202248        // empty
    22212249                { $$ = nullptr; }
    2222         | '=' constant_expression
    2223                 { $$ = $2; }
     2250        // | '=' constant_expression
     2251        //      { $$ = $2; }
     2252        | '=' initializer
     2253                { $$ = $2->get_expression(); }                                  // FIX ME: enum only deals with constant_expression
    22242254        ;
    22252255
     
    24032433                { $$ = $3; }
    24042434        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    2405                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
     2435                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $3 ), maybeMoveBuild<Expression>( $5 ) ) ); }
    24062436        | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
    24072437                { $$ = $4; }
     
    24412471type_parameter:                                                                                 // CFA
    24422472        type_class identifier_or_type_name
    2443                 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
     2473                {
     2474                        typedefTable.addToScope( *$2, TYPEDEFname, "9" );
     2475                        if ( $1 == TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated, use T " ); }
     2476                        if ( $1 == TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated, use T &" ); }
     2477                        if ( $1 == TypeDecl::Ttype ) { SemanticError( yylloc, "ttype keyword is deprecated, use T ..." ); }
     2478                }
    24442479          type_initializer_opt assertion_list_opt
    24452480                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     
    27342769subrange:
    27352770        constant_expression '~' constant_expression                     // CFA, integer subrange
    2736                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
     2771                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
    27372772        ;
    27382773
     
    27582793        | attribute_list attribute
    27592794                { $$ = $2->addQualifiers( $1 ); }
     2795        ;
     2796
     2797attribute_opt:
     2798        // empty
     2799                { $$ = nullptr; }
     2800        | attribute
    27602801        ;
    27612802
     
    31623203        | '[' ']' multi_array_dimension
    31633204                { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); }
     3205        | '[' push assignment_expression pop ',' comma_expression ']'
     3206                { $$ = DeclarationNode::newArray( $3, 0, false )->addArray( DeclarationNode::newArray( $6, 0, false ) ); }
     3207                // { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; }
    31643208        | multi_array_dimension
    31653209        ;
Note: See TracChangeset for help on using the changeset viewer.