Changeset f9c3100
- Timestamp:
- Mar 23, 2021, 9:18:44 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 1f55a75
- Parents:
- a46b69c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
ra46b69c rf9c3100 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Mar 15 13:34:17202113 // Update Count : 4 74012 // Last Modified On : Tue Mar 23 20:56:24 2021 13 // Update Count : 4929 14 14 // 15 15 … … 32 32 // 33 33 // 1. designation with and without '=' (use ':' instead) 34 // 2. attributes not allowed in parenthesis of declarator 34 35 35 // 36 36 // All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall … … 321 321 %type<en> constant 322 322 %type<en> tuple tuple_expression_list 323 %type<op> ptrref_operator unary_operator assignment_operator 323 %type<op> ptrref_operator unary_operator assignment_operator simple_assignment_operator compound_assignment_operator 324 324 %type<en> primary_expression postfix_expression unary_expression 325 325 %type<en> cast_expression_list cast_expression exponential_expression multiplicative_expression additive_expression … … 428 428 429 429 %type<decl> type_declaration_specifier type_type_specifier type_name typegen_name 430 %type<decl> typedef typedef_declaration typedef_expression430 %type<decl> typedef_name typedef_declaration typedef_expression 431 431 432 432 %type<decl> variable_type_redeclarator type_ptr type_array type_function … … 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 attributeattribute_name_list attribute_name447 %type<decl> attribute_list_opt attribute_list attribute attribute_name_list attribute_name 448 448 449 449 // initializers … … 950 950 951 951 assignment_operator: 952 simple_assignment_operator 953 | compound_assignment_operator 954 ; 955 956 simple_assignment_operator: 952 957 '=' { $$ = OperKinds::Assign; } 953 | ATassign { $$ = OperKinds::AtAssn; } 954 | EXPassign { $$ = OperKinds::ExpAssn; } 958 | ATassign { $$ = OperKinds::AtAssn; } // CFA 959 ; 960 961 compound_assignment_operator: 962 EXPassign { $$ = OperKinds::ExpAssn; } 955 963 | MULTassign { $$ = OperKinds::MulAssn; } 956 964 | DIVassign { $$ = OperKinds::DivAssn; } … … 1754 1762 ; 1755 1763 1756 enum_specifier_nobody: // type specifier - {...}1757 // Preclude SUE declarations in restricted scopes (see type_specifier_nobody)1758 basic_type_specifier1759 | sue_type_specifier_nobody1760 ;1761 1762 1764 type_qualifier_list_opt: // GCC, used in asm_statement 1763 1765 // empty … … 2038 2040 '{' field_declaration_list_opt '}' type_parameters_opt 2039 2041 { $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); } 2040 | aggregate_key attribute_list_opt type_name 2041 { 2042 // 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) 2043 typedefTable.makeTypedef( *$3->type->leafName(), forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef 2042 | aggregate_key attribute_list_opt TYPEDEFname // unqualified type name 2043 { 2044 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef 2044 2045 forall = false; // reset 2045 2046 } 2046 2047 '{' field_declaration_list_opt '}' type_parameters_opt 2047 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $8, $6, true )->addQualifiers( $2 ); } 2048 { 2049 DeclarationNode::newFromTypedef( $3 ); 2050 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); 2051 } 2052 | aggregate_key attribute_list_opt TYPEGENname // unqualified type name 2053 { 2054 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef 2055 forall = false; // reset 2056 } 2057 '{' field_declaration_list_opt '}' type_parameters_opt 2058 { 2059 DeclarationNode::newFromTypeGen( $3, nullptr ); 2060 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); 2061 } 2048 2062 | aggregate_type_nobody 2049 2063 ; … … 2201 2215 ; 2202 2216 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".2205 2217 enum_type: // enum 2206 ENUM attribute_ opt '{' enumerator_list comma_opt '}'2218 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2207 2219 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); } 2208 | ENUM attribute_ opt identifier2220 | ENUM attribute_list_opt identifier 2209 2221 { typedefTable.makeTypedef( *$3 ); } 2210 2222 '{' enumerator_list comma_opt '}' 2211 2223 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); } 2212 | ENUM attribute_ opt typedef // enum cannot be generic2224 | ENUM attribute_list_opt typedef_name // unqualified type name 2213 2225 '{' enumerator_list comma_opt '}' 2214 2226 { $$ = 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; }2227 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2228 // { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; } 2229 { $$ = nullptr; } 2230 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt '{' enumerator_list comma_opt '}' 2231 // { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; } 2232 { typedefTable.makeTypedef( *$6 ); } 2233 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' 2234 // { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; } 2235 { typedefTable.makeTypedef( *$6->name ); } 2224 2236 | enum_type_nobody 2225 2237 ; 2226 2238 2227 2239 enum_type_nobody: // enum - {...} 2228 ENUM attribute_opt identifier 2229 { 2230 typedefTable.makeTypedef( *$3 ); 2231 $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); 2232 } 2233 | ENUM attribute_opt type_name // enum cannot be generic 2234 { 2235 typedefTable.makeTypedef( *$3->type->symbolic.name ); 2236 $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); 2237 } 2240 ENUM attribute_list_opt identifier 2241 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); } 2242 | ENUM attribute_list_opt type_name // qualified type name 2243 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); } 2238 2244 ; 2239 2245 … … 2241 2247 identifier_or_type_name enumerator_value_opt 2242 2248 { $$ = DeclarationNode::newEnumConstant( $1, $2 ); } 2249 | INLINE type_name 2250 { $$ = DeclarationNode::newEnumConstant( new string("inline"), nullptr ); } 2243 2251 | enumerator_list ',' identifier_or_type_name enumerator_value_opt 2244 2252 { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); } 2253 | enumerator_list ',' INLINE type_name enumerator_value_opt 2254 { $$ = $1->appendList( DeclarationNode::newEnumConstant( new string("inline"), nullptr ) ); } 2245 2255 ; 2246 2256 … … 2250 2260 // | '=' constant_expression 2251 2261 // { $$ = $2; } 2252 | '='initializer2262 | simple_assignment_operator initializer 2253 2263 { $$ = $2->get_expression(); } // FIX ME: enum only deals with constant_expression 2254 2264 ; … … 2378 2388 // empty 2379 2389 { $$ = nullptr; } 2380 | '=' initializer 2381 { $$ = $2; } 2382 | '=' VOID 2383 { $$ = new InitializerNode( true ); } 2384 | ATassign initializer 2385 { $$ = $2->set_maybeConstructed( false ); } 2390 | simple_assignment_operator initializer { $$ = $1 == OperKinds::Assign ? $2 : $2->set_maybeConstructed( false ); } 2391 | '=' VOID { $$ = new InitializerNode( true ); } 2386 2392 ; 2387 2393 … … 2793 2799 | attribute_list attribute 2794 2800 { $$ = $2->addQualifiers( $1 ); } 2795 ;2796 2797 attribute_opt:2798 // empty2799 { $$ = nullptr; }2800 | attribute2801 2801 ; 2802 2802 … … 3032 3032 3033 3033 paren_type: 3034 typedef 3035 // hide type name in enclosing scope by variable name 3036 { 3037 // if ( ! typedefTable.existsCurr( *$1->name ) ) { 3038 typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" ); 3039 // } else { 3040 // SemanticError( yylloc, string("'") + *$1->name + "' redeclared as different kind of symbol." ); $$ = nullptr; 3041 // } // if 3034 typedef_name 3035 { 3036 // hide type name in enclosing scope by variable name 3037 typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" ); 3042 3038 } 3043 3039 | '(' paren_type ')' … … 3152 3148 3153 3149 type_parameter_redeclarator: 3154 typedef attribute_list_opt3150 typedef_name attribute_list_opt 3155 3151 { $$ = $1->addQualifiers( $2 ); } 3156 | '&' MUTEX typedef attribute_list_opt3152 | '&' MUTEX typedef_name attribute_list_opt 3157 3153 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( Type::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); } 3158 3154 | type_parameter_ptr … … 3163 3159 ; 3164 3160 3165 typedef :3161 typedef_name: 3166 3162 TYPEDEFname 3167 3163 { $$ = DeclarationNode::newName( $1 ); } … … 3180 3176 3181 3177 type_parameter_array: 3182 typedef array_parameter_dimension3178 typedef_name array_parameter_dimension 3183 3179 { $$ = $1->addArray( $2 ); } 3184 3180 | '(' type_parameter_ptr ')' array_parameter_dimension … … 3187 3183 3188 3184 type_parameter_function: 3189 typedef '(' push parameter_type_list_opt pop ')'// empty parameter list OBSOLESCENT (see 3)3185 typedef_name '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 3190 3186 { $$ = $1->addParamList( $4 ); } 3191 3187 | '(' type_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
Note: See TracChangeset
for help on using the changeset viewer.