Changes in src/Parser/parser.yy [ec3f9c8:fd54fef]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rec3f9c8 rfd54fef 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 27 08:58:56202113 // Update Count : 46 8012 // Last Modified On : Mon Jan 11 21:32:10 2021 13 // Update Count : 4633 14 14 // 15 15 … … 41 41 42 42 %{ 43 #define YYDEBUG_LEXER_TEXT ( yylval )// lexer loads this up each time43 #define YYDEBUG_LEXER_TEXT (yylval) // lexer loads this up each time 44 44 #define YYDEBUG 1 // get the pretty debugging code to compile 45 45 #define YYERROR_VERBOSE // more information in syntax errors … … 63 63 extern TypedefTable typedefTable; 64 64 65 stack< LinkageSpec::Spec> linkageStack;65 stack< LinkageSpec::Spec > linkageStack; 66 66 67 67 bool appendStr( string & to, string & from ) { … … 187 187 ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get()); 188 188 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 ) ) ); 190 190 } // if 191 191 return new ForCtrl( … … 440 440 441 441 %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_nobody442 %type<decl> type_specifier type_specifier_nobody 443 443 444 444 %type<decl> variable_declarator variable_ptr variable_array variable_function 445 445 %type<decl> variable_abstract_declarator variable_abstract_ptr variable_abstract_array variable_abstract_function 446 446 447 %type<decl> attribute_list_opt attribute_list attribute_ opt attribute attribute_name_listattribute_name447 %type<decl> attribute_list_opt attribute_list attribute_name_list attribute attribute_name 448 448 449 449 // initializers … … 578 578 { $$ = $2; } 579 579 | '(' 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) ) ) ); } 581 581 | type_name '.' identifier // CFA, nested type 582 582 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 610 610 { 611 611 // 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) } } ); 613 613 } 614 614 | DEFAULT ':' assignment_expression 615 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>( $3) } } ); }615 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); } 616 616 ; 617 617 … … 743 743 switch ( $1 ) { 744 744 case OperKinds::AddressOf: 745 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild< Expression>( $2 ) ) );745 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild< Expression >( $2 ) ) ); 746 746 break; 747 747 case OperKinds::PointTo: … … 749 749 break; 750 750 case OperKinds::And: 751 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild< Expression>( $2 ) ) ) );751 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild< Expression >( $2 ) ) ) ); 752 752 break; 753 753 default: … … 762 762 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); } 763 763 | SIZEOF unary_expression 764 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild< Expression>( $2 ) ) ); }764 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild< Expression >( $2 ) ) ); } 765 765 | SIZEOF '(' type_no_function ')' 766 766 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuildType( $3 ) ) ); } 767 767 | ALIGNOF unary_expression // GCC, variable alignment 768 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild< Expression>( $2 ) ) ); }768 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild< Expression >( $2 ) ) ); } 769 769 | ALIGNOF '(' type_no_function ')' // GCC, type alignment 770 770 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); } … … 794 794 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 795 795 | '(' VIRTUAL ')' cast_expression // CFA 796 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); }796 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); } 797 797 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 798 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); }798 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); } 799 799 | '(' RETURN type_no_function ')' cast_expression // CFA 800 800 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; } … … 977 977 assignment_expression 978 978 | comma_expression ',' assignment_expression 979 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild< Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }979 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); } 980 980 ; 981 981 … … 1102 1102 constant_expression { $$ = $1; } 1103 1103 | constant_expression ELLIPSIS constant_expression // GCC, subrange 1104 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }1104 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); } 1105 1105 | subrange // CFA, subrange 1106 1106 ; … … 1247 1247 { $$ = new StatementNode( build_computedgoto( $3 ) ); } 1248 1248 // A semantic check is required to ensure fallthru appears only in the body of a choose statement. 1249 | fall_through_name ';' // CFA1249 | fall_through_name ';' // CFA 1250 1250 { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); } 1251 | fall_through_name identifier_or_type_name ';' // CFA1251 | fall_through_name identifier_or_type_name ';' // CFA 1252 1252 { $$ = new StatementNode( build_branch( $2, BranchStmt::FallThrough ) ); } 1253 1253 | fall_through_name DEFAULT ';' // CFA … … 1448 1448 asm_operand: // GCC 1449 1449 string_literal '(' constant_expression ')' 1450 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild< Expression>( $3 ) ) ); }1450 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild< Expression >( $3 ) ) ); } 1451 1451 | '[' IDENTIFIER ']' string_literal '(' constant_expression ')' 1452 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild< Expression>( $6 ) ) ); }1452 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild< Expression >( $6 ) ) ); } 1453 1453 ; 1454 1454 … … 1736 1736 | sue_type_specifier_nobody 1737 1737 | type_type_specifier 1738 ;1739 1740 enum_specifier_nobody: // type specifier - {...}1741 // Preclude SUE declarations in restricted scopes (see type_specifier_nobody)1742 basic_type_specifier1743 | sue_type_specifier_nobody1744 1738 ; 1745 1739 … … 2010 2004 ; 2011 2005 2006 fred: 2007 // empty 2008 { yyy = false; } 2009 ; 2010 2012 2011 aggregate_type: // struct, union 2013 2012 aggregate_key attribute_list_opt … … 2015 2014 '{' field_declaration_list_opt '}' type_parameters_opt 2016 2015 { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 ); } 2017 | aggregate_key attribute_list_opt identifier 2016 | aggregate_key attribute_list_opt identifier fred 2018 2017 { 2019 2018 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef … … 2021 2020 } 2022 2021 '{' field_declaration_list_opt '}' type_parameters_opt 2023 { $$ = DeclarationNode::newAggregate( $1, $3, $ 8, $6, true )->addQualifiers( $2 ); }2024 | 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 2025 2024 { 2026 2025 // 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) … … 2029 2028 } 2030 2029 '{' field_declaration_list_opt '}' type_parameters_opt 2031 { $$ = 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 ); } 2032 2031 | aggregate_type_nobody 2033 2032 ; … … 2041 2040 2042 2041 aggregate_type_nobody: // struct, union - {...} 2043 aggregate_key attribute_list_opt identifier 2042 aggregate_key attribute_list_opt identifier fred 2044 2043 { 2045 2044 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); … … 2047 2046 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 2048 2047 } 2049 | aggregate_key attribute_list_opt type_name 2048 | aggregate_key attribute_list_opt type_name fred 2050 2049 { 2051 2050 forall = false; // reset … … 2185 2184 ; 2186 2185 2187 // Cannot use attribute_list_opt because of ambiguity with enum_specifier_nobody, which already parses attribute.2188 // Hence, only a single attribute is allowed after the "ENUM".2189 2186 enum_type: // enum 2190 ENUM attribute_ opt '{' enumerator_list comma_opt '}'2187 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2191 2188 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); } 2192 | ENUM attribute_ opt identifier2189 | ENUM attribute_list_opt identifier 2193 2190 { typedefTable.makeTypedef( *$3 ); } 2194 2191 '{' enumerator_list comma_opt '}' 2195 2192 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); } 2196 | ENUM attribute_ opt typedef // enum cannot be generic2193 | ENUM attribute_list_opt type_name 2197 2194 '{' enumerator_list comma_opt '}' 2198 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); } 2199 | ENUM enum_specifier_nobody '{' enumerator_list comma_opt '}' 2200 // { $$ = DeclarationNode::newEnum( nullptr, $4, true ); } 2201 { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; } 2202 | ENUM enum_specifier_nobody declarator '{' enumerator_list comma_opt '}' 2203 // { 2204 // typedefTable.makeTypedef( *$3->name ); 2205 // $$ = DeclarationNode::newEnum( nullptr, $5, true ); 2206 // } 2207 { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; } 2195 { $$ = DeclarationNode::newEnum( $3->type->symbolic.name, $5, true )->addQualifiers( $2 ); } 2208 2196 | enum_type_nobody 2209 2197 ; 2210 2198 2211 2199 enum_type_nobody: // enum - {...} 2212 ENUM attribute_ opt identifier2200 ENUM attribute_list_opt identifier 2213 2201 { 2214 2202 typedefTable.makeTypedef( *$3 ); 2215 2203 $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); 2216 2204 } 2217 | ENUM attribute_ opt type_name // enum cannot be generic2205 | ENUM attribute_list_opt type_name 2218 2206 { 2219 2207 typedefTable.makeTypedef( *$3->type->symbolic.name ); … … 2232 2220 // empty 2233 2221 { $$ = nullptr; } 2234 // | '=' constant_expression 2235 // { $$ = $2; } 2236 | '=' initializer 2237 { $$ = $2->get_expression(); } // FIX ME: enum only deals with constant_expression 2222 | '=' constant_expression 2223 { $$ = $2; } 2238 2224 ; 2239 2225 … … 2417 2403 { $$ = $3; } 2418 2404 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2419 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression>( $3 ), maybeMoveBuild<Expression>( $5 ) ) ); }2405 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); } 2420 2406 | '.' '[' push field_name_list pop ']' // CFA, tuple field selector 2421 2407 { $$ = $4; } … … 2455 2441 type_parameter: // CFA 2456 2442 type_class identifier_or_type_name 2457 { 2458 typedefTable.addToScope( *$2, TYPEDEFname, "9" ); 2459 if ( $1 == TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated, use T " ); } 2460 if ( $1 == TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated, use T &" ); } 2461 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" ); } 2462 2447 } 2463 2448 type_initializer_opt assertion_list_opt … … 2753 2738 subrange: 2754 2739 constant_expression '~' constant_expression // CFA, integer subrange 2755 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }2740 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); } 2756 2741 ; 2757 2742 … … 2777 2762 | attribute_list attribute 2778 2763 { $$ = $2->addQualifiers( $1 ); } 2779 ;2780 2781 attribute_opt:2782 // empty2783 { $$ = nullptr; }2784 | attribute2785 2764 ; 2786 2765
Note:
See TracChangeset
for help on using the changeset viewer.