Changes in / [e825c9d:1f55a75]
- Location:
- src/Parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
re825c9d r1f55a75 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:35:37202113 // Update Count : 114 112 // Last Modified On : Tue Mar 23 08:44:08 2021 13 // Update Count : 1149 14 14 // 15 15 … … 167 167 } 168 168 169 DeclarationNode * DeclarationNode::newFunction( const string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ) {170 DeclarationNode * newnode = new DeclarationNode;171 newnode->name = name;172 newnode->type = new TypeData( TypeData::Function );173 newnode->type->function.params = param;174 newnode->type->function.body = body;175 176 if ( ret ) {177 newnode->type->base = ret->type;178 ret->type = nullptr;179 delete ret;180 } // if181 182 return newnode;183 } // DeclarationNode::newFunction184 185 186 169 DeclarationNode * DeclarationNode::newStorageClass( Type::StorageClasses sc ) { 187 170 DeclarationNode * newnode = new DeclarationNode; … … 237 220 return newnode; 238 221 } // DeclarationNode::newForall 239 240 DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) {241 DeclarationNode * newnode = new DeclarationNode;242 newnode->type = new TypeData( TypeData::SymbolicInst );243 newnode->type->symbolic.name = name;244 newnode->type->symbolic.isTypedef = true;245 newnode->type->symbolic.params = nullptr;246 return newnode;247 } // DeclarationNode::newFromTypedef248 222 249 223 DeclarationNode * DeclarationNode::newFromGlobalScope() { … … 289 263 } // DeclarationNode::newEnum 290 264 265 DeclarationNode * DeclarationNode::newName( const string * name ) { 266 DeclarationNode * newnode = new DeclarationNode; 267 assert( ! newnode->name ); 268 newnode->name = name; 269 return newnode; 270 } // DeclarationNode::newName 271 291 272 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) { 292 DeclarationNode * newnode = new DeclarationNode; 293 newnode->name = name; 273 DeclarationNode * newnode = newName( name ); 294 274 newnode->enumeratorValue.reset( constant ); 295 275 return newnode; 296 276 } // DeclarationNode::newEnumConstant 297 277 298 DeclarationNode * DeclarationNode::newName( const string * name ) { 299 DeclarationNode * newnode = new DeclarationNode; 300 newnode->name = name; 301 return newnode; 302 } // DeclarationNode::newName 278 DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) { 279 DeclarationNode * newnode = new DeclarationNode; 280 newnode->type = new TypeData( TypeData::SymbolicInst ); 281 newnode->type->symbolic.name = name; 282 newnode->type->symbolic.isTypedef = true; 283 newnode->type->symbolic.params = nullptr; 284 return newnode; 285 } // DeclarationNode::newFromTypedef 303 286 304 287 DeclarationNode * DeclarationNode::newFromTypeGen( const string * name, ExpressionNode * params ) { … … 312 295 313 296 DeclarationNode * DeclarationNode::newTypeParam( TypeDecl::Kind tc, const string * name ) { 314 DeclarationNode * newnode = new DeclarationNode;297 DeclarationNode * newnode = newName( name ); 315 298 newnode->type = nullptr; 316 assert( ! newnode->name );317 // newnode->variable.name = name;318 newnode->name = name;319 299 newnode->variable.tyClass = tc; 320 300 newnode->variable.assertions = nullptr; … … 343 323 344 324 DeclarationNode * DeclarationNode::newTypeDecl( const string * name, DeclarationNode * typeParams ) { 345 DeclarationNode * newnode = new DeclarationNode; 346 newnode->name = name; 325 DeclarationNode * newnode = newName( name ); 347 326 newnode->type = new TypeData( TypeData::Symbolic ); 348 327 newnode->type->symbolic.isTypedef = false; … … 416 395 return newnode; 417 396 } // DeclarationNode::newBuiltinType 397 398 DeclarationNode * DeclarationNode::newFunction( const string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ) { 399 DeclarationNode * newnode = newName( name ); 400 newnode->type = new TypeData( TypeData::Function ); 401 newnode->type->function.params = param; 402 newnode->type->function.body = body; 403 404 if ( ret ) { 405 newnode->type->base = ret->type; 406 ret->type = nullptr; 407 delete ret; 408 } // if 409 410 return newnode; 411 } // DeclarationNode::newFunction 418 412 419 413 DeclarationNode * DeclarationNode::newAttribute( const string * name, ExpressionNode * expr ) { … … 885 879 } 886 880 887 DeclarationNode * DeclarationNode::cloneType( string * n ewName ) {888 DeclarationNode * newnode = new DeclarationNode;881 DeclarationNode * DeclarationNode::cloneType( string * name ) { 882 DeclarationNode * newnode = newName( name ); 889 883 newnode->type = maybeClone( type ); 890 884 newnode->copySpecifiers( this ); 891 assert( newName );892 newnode->name = newName;893 885 return newnode; 894 886 } -
src/Parser/TypedefTable.cc
re825c9d r1f55a75 10 10 // Created On : Sat May 16 15:20:13 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Feb 15 08:06:36 202013 // Update Count : 2 5912 // Last Modified On : Mon Mar 15 20:56:47 2021 13 // Update Count : 260 14 14 // 15 15 … … 89 89 debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << " level " << level << " note " << kindTable.getNote( kindTable.currentScope() - 1 ).level << endl ); 90 90 auto ret = kindTable.insertAt( scope, identifier, kind ); 91 if ( ! ret.second ) ret.first->second = kind; // exists => update91 if ( ! ret.second ) ret.first->second = kind; // exists => update 92 92 } // TypedefTable::addToEnclosingScope 93 93 -
src/Parser/parser.yy
re825c9d r1f55a75 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.