Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r6a99803 rfd54fef  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  3 18:30:12 2021
    13 // Update Count     : 4700
     12// Last Modified On : Mon Jan 11 21:32:10 2021
     13// Update Count     : 4633
    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(
     
    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 enum_specifier_nobody
     442%type<decl> type_specifier type_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_opt attribute attribute_name_list attribute_name
     447%type<decl> attribute_list_opt attribute_list attribute_name_list attribute attribute_name
    448448
    449449// initializers
     
    578578                { $$ = $2; }
    579579        | '(' compound_statement ')'                                            // GCC, lambda expression
    580                 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); }
     580                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); }
    581581        | type_name '.' identifier                                                      // CFA, nested type
    582582                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     
    610610                {
    611611                        // create a GenericExpr wrapper with one association pair
    612                         $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>( $3 ) } } );
     612                        $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>($3) } } );
    613613                }
    614614        | DEFAULT ':' assignment_expression
    615                 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>( $3 ) } } ); }
     615                { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); }
    616616        ;
    617617
    618618postfix_expression:
    619619        primary_expression
    620         | postfix_expression '[' assignment_expression ',' comma_expression ']'
    621                 // { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_binary_val( OperKinds::Index, $3, $5 ) ) ) ); }
    622                 { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; }
    623620        | postfix_expression '[' assignment_expression ']'
    624621                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
     
    746743                        switch ( $1 ) {
    747744                          case OperKinds::AddressOf:
    748                                 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) );
     745                                $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild< Expression >( $2 ) ) );
    749746                                break;
    750747                          case OperKinds::PointTo:
     
    752749                                break;
    753750                          case OperKinds::And:
    754                                 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) ) );
     751                                $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild< Expression >( $2 ) ) ) );
    755752                                break;
    756753                          default:
     
    765762                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); }
    766763        | SIZEOF unary_expression
    767                 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }
     764                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild< Expression >( $2 ) ) ); }
    768765        | SIZEOF '(' type_no_function ')'
    769766                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuildType( $3 ) ) ); }
    770767        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    771                 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }
     768                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild< Expression >( $2 ) ) ); }
    772769        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    773770                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); }
     
    797794                { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }
    798795        | '(' VIRTUAL ')' cast_expression                                       // CFA
    799                 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); }
     796                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); }
    800797        | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
    801                 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); }
     798                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); }
    802799        | '(' RETURN type_no_function ')' cast_expression       // CFA
    803800                { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; }
     
    980977        assignment_expression
    981978        | comma_expression ',' assignment_expression
    982                 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
     979                { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
    983980        ;
    984981
     
    11051102        constant_expression                                                     { $$ = $1; }
    11061103        | constant_expression ELLIPSIS constant_expression      // GCC, subrange
    1107                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
     1104                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
    11081105        | subrange                                                                                      // CFA, subrange
    11091106        ;
     
    12501247                { $$ = new StatementNode( build_computedgoto( $3 ) ); }
    12511248                // A semantic check is required to ensure fallthru appears only in the body of a choose statement.
    1252         | fall_through_name ';'                                                         // CFA
     1249    | fall_through_name ';'                                                             // CFA
    12531250                { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); }
    1254         | fall_through_name identifier_or_type_name ';'         // CFA
     1251    | fall_through_name identifier_or_type_name ';'             // CFA
    12551252                { $$ = new StatementNode( build_branch( $2, BranchStmt::FallThrough ) ); }
    12561253        | fall_through_name DEFAULT ';'                                         // CFA
     
    14511448asm_operand:                                                                                    // GCC
    14521449        string_literal '(' constant_expression ')'
    1453                 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild<Expression>( $3 ) ) ); }
     1450                { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild< Expression >( $3 ) ) ); }
    14541451        | '[' IDENTIFIER ']' string_literal '(' constant_expression ')'
    1455                 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild<Expression>( $6 ) ) ); }
     1452                { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild< Expression >( $6 ) ) ); }
    14561453        ;
    14571454
     
    17391736        | sue_type_specifier_nobody
    17401737        | type_type_specifier
    1741         ;
    1742 
    1743 enum_specifier_nobody:                                                                  // type specifier - {...}
    1744                 // Preclude SUE declarations in restricted scopes (see type_specifier_nobody)
    1745         basic_type_specifier
    1746         | sue_type_specifier_nobody
    17471738        ;
    17481739
     
    20132004        ;
    20142005
     2006fred:
     2007        // empty
     2008                { yyy = false; }
     2009        ;
     2010
    20152011aggregate_type:                                                                                 // struct, union
    20162012        aggregate_key attribute_list_opt
     
    20182014          '{' field_declaration_list_opt '}' type_parameters_opt
    20192015                { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 ); }
    2020         | aggregate_key attribute_list_opt identifier
     2016        | aggregate_key attribute_list_opt identifier fred
    20212017                {
    20222018                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef
     
    20242020                }
    20252021          '{' field_declaration_list_opt '}' type_parameters_opt
    2026                 { $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); }
    2027         | aggregate_key attribute_list_opt type_name
     2022                { $$ = DeclarationNode::newAggregate( $1, $3, $9, $7, true )->addQualifiers( $2 ); }
     2023        | aggregate_key attribute_list_opt type_name fred
    20282024                {
    20292025                        // 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)
     
    20322028                }
    20332029          '{' field_declaration_list_opt '}' type_parameters_opt
    2034                 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $8, $6, true )->addQualifiers( $2 ); }
     2030                { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $9, $7, true )->addQualifiers( $2 ); }
    20352031        | aggregate_type_nobody
    20362032        ;
     
    20442040
    20452041aggregate_type_nobody:                                                                  // struct, union - {...}
    2046         aggregate_key attribute_list_opt identifier
     2042        aggregate_key attribute_list_opt identifier fred
    20472043                {
    20482044                        typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname );
     
    20502046                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    20512047                }
    2052         | aggregate_key attribute_list_opt type_name
     2048        | aggregate_key attribute_list_opt type_name fred
    20532049                {
    20542050                        forall = false;                                                         // reset
     
    21882184        ;
    21892185
    2190 // Cannot use attribute_list_opt because of ambiguity with enum_specifier_nobody, which already parses attribute.
    2191 // Hence, only a single attribute is allowed after the "ENUM".
    21922186enum_type:                                                                                              // enum
    2193         ENUM attribute_opt '{' enumerator_list comma_opt '}'
     2187        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    21942188                { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
    2195         | ENUM attribute_opt identifier
     2189        | ENUM attribute_list_opt identifier
    21962190                { typedefTable.makeTypedef( *$3 ); }
    21972191          '{' enumerator_list comma_opt '}'
    21982192                { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
    2199         | ENUM attribute_opt typedef                                            // enum cannot be generic
     2193        | ENUM attribute_list_opt type_name
    22002194          '{' enumerator_list comma_opt '}'
    2201                 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }
    2202         | ENUM enum_specifier_nobody '{' enumerator_list comma_opt '}'
    2203                 // { $$ = DeclarationNode::newEnum( nullptr, $4, true ); }
    2204                 { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; }
    2205         | ENUM enum_specifier_nobody declarator '{' enumerator_list comma_opt '}'
    2206                 // {
    2207                 //      typedefTable.makeTypedef( *$3->name );
    2208                 //      $$ = DeclarationNode::newEnum( nullptr, $5, true );
    2209                 // }
    2210                 { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; }
     2195                { $$ = DeclarationNode::newEnum( $3->type->symbolic.name, $5, true )->addQualifiers( $2 ); }
    22112196        | enum_type_nobody
    22122197        ;
    22132198
    22142199enum_type_nobody:                                                                               // enum - {...}
    2215         ENUM attribute_opt identifier
     2200        ENUM attribute_list_opt identifier
    22162201                {
    22172202                        typedefTable.makeTypedef( *$3 );
    22182203                        $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 );
    22192204                }
    2220         | ENUM attribute_opt type_name                                          // enum cannot be generic
     2205        | ENUM attribute_list_opt type_name
    22212206                {
    22222207                        typedefTable.makeTypedef( *$3->type->symbolic.name );
     
    22352220        // empty
    22362221                { $$ = nullptr; }
    2237         // | '=' constant_expression
    2238         //      { $$ = $2; }
    2239         | '=' initializer
    2240                 { $$ = $2->get_expression(); }                                  // FIX ME: enum only deals with constant_expression
     2222        | '=' constant_expression
     2223                { $$ = $2; }
    22412224        ;
    22422225
     
    24202403                { $$ = $3; }
    24212404        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    2422                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $3 ), maybeMoveBuild<Expression>( $5 ) ) ); }
     2405                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
    24232406        | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
    24242407                { $$ = $4; }
     
    24582441type_parameter:                                                                                 // CFA
    24592442        type_class identifier_or_type_name
    2460                 {
    2461                         typedefTable.addToScope( *$2, TYPEDEFname, "9" );
    2462                         if ( $1 == TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated, use T " ); }
    2463                         if ( $1 == TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated, use T &" ); }
    2464                         if ( $1 == TypeDecl::Ttype ) { SemanticError( yylloc, "ttype keyword is deprecated, use T ..." ); }
     2443                {   typedefTable.addToScope( *$2, TYPEDEFname, "9" );
     2444                        if ( $1 == TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated" ); }
     2445                        if ( $1 == TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated" ); }
     2446                        if ( $1 == TypeDecl::Ttype ) { SemanticError( yylloc, "ttype keyword is deprecated" ); }
    24652447                }
    24662448          type_initializer_opt assertion_list_opt
     
    27562738subrange:
    27572739        constant_expression '~' constant_expression                     // CFA, integer subrange
    2758                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
     2740                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); }
    27592741        ;
    27602742
     
    27802762        | attribute_list attribute
    27812763                { $$ = $2->addQualifiers( $1 ); }
    2782         ;
    2783 
    2784 attribute_opt:
    2785         // empty
    2786                 { $$ = nullptr; }
    2787         | attribute
    27882764        ;
    27892765
     
    31903166        | '[' ']' multi_array_dimension
    31913167                { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); }
    3192         | '[' push assignment_expression pop ',' comma_expression ']'
    3193                 { $$ = DeclarationNode::newArray( $3, 0, false )->addArray( DeclarationNode::newArray( $6, 0, false ) ); }
    3194                 // { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; }
    31953168        | multi_array_dimension
    31963169        ;
Note: See TracChangeset for help on using the changeset viewer.