- Timestamp:
- Feb 4, 2021, 10:03:29 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 5ce9bea
- Parents:
- c292244 (diff), 9af0fe2d (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. - File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rc292244 ref0b456 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 11 21:32:10202113 // Update Count : 4 63312 // Last Modified On : Wed Feb 3 18:30:12 2021 13 // Update Count : 4700 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 442 %type<decl> type_specifier type_specifier_nobody enum_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_ name_list attributeattribute_name447 %type<decl> attribute_list_opt attribute_list attribute_opt attribute attribute_name_list 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 618 618 postfix_expression: 619 619 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; } 620 623 | postfix_expression '[' assignment_expression ']' 621 624 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a … … 743 746 switch ( $1 ) { 744 747 case OperKinds::AddressOf: 745 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild< Expression>( $2 ) ) );748 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) ); 746 749 break; 747 750 case OperKinds::PointTo: … … 749 752 break; 750 753 case OperKinds::And: 751 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild< Expression>( $2 ) ) ) );754 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) ) ); 752 755 break; 753 756 default: … … 762 765 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); } 763 766 | SIZEOF unary_expression 764 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild< Expression>( $2 ) ) ); }767 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild<Expression>( $2 ) ) ); } 765 768 | SIZEOF '(' type_no_function ')' 766 769 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuildType( $3 ) ) ); } 767 770 | ALIGNOF unary_expression // GCC, variable alignment 768 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild< Expression>( $2 ) ) ); }771 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild<Expression>( $2 ) ) ); } 769 772 | ALIGNOF '(' type_no_function ')' // GCC, type alignment 770 773 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); } … … 794 797 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 795 798 | '(' VIRTUAL ')' cast_expression // CFA 796 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); }799 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); } 797 800 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 798 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); }801 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); } 799 802 | '(' RETURN type_no_function ')' cast_expression // CFA 800 803 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; } … … 977 980 assignment_expression 978 981 | comma_expression ',' assignment_expression 979 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression>( $3 ) ) ); }982 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); } 980 983 ; 981 984 … … 1102 1105 constant_expression { $$ = $1; } 1103 1106 | constant_expression ELLIPSIS constant_expression // GCC, subrange 1104 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression>( $3 ) ) ); }1107 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); } 1105 1108 | subrange // CFA, subrange 1106 1109 ; … … 1247 1250 { $$ = new StatementNode( build_computedgoto( $3 ) ); } 1248 1251 // A semantic check is required to ensure fallthru appears only in the body of a choose statement. 1249 | fall_through_name ';' // CFA1252 | fall_through_name ';' // CFA 1250 1253 { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); } 1251 | fall_through_name identifier_or_type_name ';' // CFA1254 | fall_through_name identifier_or_type_name ';' // CFA 1252 1255 { $$ = new StatementNode( build_branch( $2, BranchStmt::FallThrough ) ); } 1253 1256 | fall_through_name DEFAULT ';' // CFA … … 1448 1451 asm_operand: // GCC 1449 1452 string_literal '(' constant_expression ')' 1450 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild< Expression>( $3 ) ) ); }1453 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild<Expression>( $3 ) ) ); } 1451 1454 | '[' IDENTIFIER ']' string_literal '(' constant_expression ')' 1452 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild< Expression>( $6 ) ) ); }1455 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild<Expression>( $6 ) ) ); } 1453 1456 ; 1454 1457 … … 1736 1739 | sue_type_specifier_nobody 1737 1740 | 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 1738 1747 ; 1739 1748 … … 2004 2013 ; 2005 2014 2006 fred:2007 // empty2008 { yyy = false; }2009 ;2010 2011 2015 aggregate_type: // struct, union 2012 2016 aggregate_key attribute_list_opt … … 2014 2018 '{' field_declaration_list_opt '}' type_parameters_opt 2015 2019 { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 ); } 2016 | aggregate_key attribute_list_opt identifier fred2020 | aggregate_key attribute_list_opt identifier 2017 2021 { 2018 2022 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef … … 2020 2024 } 2021 2025 '{' 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 fred2026 { $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); } 2027 | aggregate_key attribute_list_opt type_name 2024 2028 { 2025 2029 // 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) … … 2028 2032 } 2029 2033 '{' field_declaration_list_opt '}' type_parameters_opt 2030 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $ 9, $7, true )->addQualifiers( $2 ); }2034 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $8, $6, true )->addQualifiers( $2 ); } 2031 2035 | aggregate_type_nobody 2032 2036 ; … … 2040 2044 2041 2045 aggregate_type_nobody: // struct, union - {...} 2042 aggregate_key attribute_list_opt identifier fred2046 aggregate_key attribute_list_opt identifier 2043 2047 { 2044 2048 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); … … 2046 2050 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 2047 2051 } 2048 | aggregate_key attribute_list_opt type_name fred2052 | aggregate_key attribute_list_opt type_name 2049 2053 { 2050 2054 forall = false; // reset … … 2184 2188 ; 2185 2189 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". 2186 2192 enum_type: // enum 2187 ENUM attribute_ list_opt '{' enumerator_list comma_opt '}'2193 ENUM attribute_opt '{' enumerator_list comma_opt '}' 2188 2194 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); } 2189 | ENUM attribute_ list_opt identifier2195 | ENUM attribute_opt identifier 2190 2196 { typedefTable.makeTypedef( *$3 ); } 2191 2197 '{' enumerator_list comma_opt '}' 2192 2198 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); } 2193 | ENUM attribute_ list_opt type_name2199 | ENUM attribute_opt typedef // enum cannot be generic 2194 2200 '{' enumerator_list comma_opt '}' 2195 { $$ = DeclarationNode::newEnum( $3->type->symbolic.name, $5, true )->addQualifiers( $2 ); } 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; } 2196 2211 | enum_type_nobody 2197 2212 ; 2198 2213 2199 2214 enum_type_nobody: // enum - {...} 2200 ENUM attribute_ list_opt identifier2215 ENUM attribute_opt identifier 2201 2216 { 2202 2217 typedefTable.makeTypedef( *$3 ); 2203 2218 $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); 2204 2219 } 2205 | ENUM attribute_ list_opt type_name2220 | ENUM attribute_opt type_name // enum cannot be generic 2206 2221 { 2207 2222 typedefTable.makeTypedef( *$3->type->symbolic.name ); … … 2220 2235 // empty 2221 2236 { $$ = nullptr; } 2222 | '=' constant_expression 2223 { $$ = $2; } 2237 // | '=' constant_expression 2238 // { $$ = $2; } 2239 | '=' initializer 2240 { $$ = $2->get_expression(); } // FIX ME: enum only deals with constant_expression 2224 2241 ; 2225 2242 … … 2403 2420 { $$ = $3; } 2404 2421 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2405 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression>( $5 ) ) ); }2422 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $3 ), maybeMoveBuild<Expression>( $5 ) ) ); } 2406 2423 | '.' '[' push field_name_list pop ']' // CFA, tuple field selector 2407 2424 { $$ = $4; } … … 2441 2458 type_parameter: // CFA 2442 2459 type_class identifier_or_type_name 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" ); } 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 ..." ); } 2447 2465 } 2448 2466 type_initializer_opt assertion_list_opt … … 2738 2756 subrange: 2739 2757 constant_expression '~' constant_expression // CFA, integer subrange 2740 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression>( $3 ) ) ); }2758 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); } 2741 2759 ; 2742 2760 … … 2762 2780 | attribute_list attribute 2763 2781 { $$ = $2->addQualifiers( $1 ); } 2782 ; 2783 2784 attribute_opt: 2785 // empty 2786 { $$ = nullptr; } 2787 | attribute 2764 2788 ; 2765 2789 … … 3166 3190 | '[' ']' multi_array_dimension 3167 3191 { $$ = 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; } 3168 3195 | multi_array_dimension 3169 3196 ;
Note:
See TracChangeset
for help on using the changeset viewer.