Changeset 2e9b59b for src/Parser
- Timestamp:
- Apr 19, 2022, 3:00:04 PM (4 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 5b84a321
- Parents:
- ba897d21 (diff), bb7c77d (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. - Location:
- src/Parser
- Files:
-
- 6 edited
-
DeclarationNode.cc (modified) (5 diffs)
-
ParseNode.h (modified) (2 diffs)
-
StatementNode.cc (modified) (1 diff)
-
TypeData.cc (modified) (1 diff)
-
TypeData.h (modified) (1 diff)
-
parser.yy (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rba897d21 r2e9b59b 78 78 delete variable.initializer; 79 79 80 delete type;80 // delete type; 81 81 delete bitfieldWidth; 82 82 … … 253 253 } // DeclarationNode::newAggregate 254 254 255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body ) {255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed) { 256 256 DeclarationNode * newnode = new DeclarationNode; 257 257 newnode->type = new TypeData( TypeData::Enum ); … … 263 263 } // DeclarationNode::newEnum 264 264 265 266 265 267 DeclarationNode * DeclarationNode::newName( const string * name ) { 266 268 DeclarationNode * newnode = new DeclarationNode; … … 270 272 } // DeclarationNode::newName 271 273 272 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) { 274 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) { // Marker 273 275 DeclarationNode * newnode = newName( name ); 274 276 newnode->enumeratorValue.reset( constant ); … … 665 667 } 666 668 669 DeclarationNode * DeclarationNode::addEnumBase( DeclarationNode * o ) { 670 if ( o && o -> type) { 671 type->base= o->type; 672 } 673 delete o; 674 return this; 675 } 676 667 677 DeclarationNode * DeclarationNode::addTypedef() { 668 678 TypeData * newtype = new TypeData( TypeData::Symbolic ); -
src/Parser/ParseNode.h
rba897d21 r2e9b59b 235 235 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ); 236 236 static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 237 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body );237 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed ); 238 238 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 239 239 static DeclarationNode * newName( const std::string * ); … … 265 265 DeclarationNode * addType( DeclarationNode * ); 266 266 DeclarationNode * addTypedef(); 267 DeclarationNode * addEnumBase( DeclarationNode * ); 267 268 DeclarationNode * addAssertions( DeclarationNode * ); 268 269 DeclarationNode * addName( std::string * ); -
src/Parser/StatementNode.cc
rba897d21 r2e9b59b 366 366 } // maybe_build_compound 367 367 368 // Question 368 369 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) { 369 370 list< Expression * > out, in; -
src/Parser/TypeData.cc
rba897d21 r2e9b59b 918 918 EnumDecl * buildEnum( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) { 919 919 assert( td->kind == TypeData::Enum ); 920 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage ); 920 Type * baseType = td->base ? typebuild(td->base) : nullptr; 921 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage, baseType ); 921 922 buildList( td->enumeration.constants, ret->get_members() ); 922 923 list< Declaration * >::iterator members = ret->get_members().begin(); 923 for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {924 for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 924 925 if ( cur->has_enumeratorValue() ) { 925 926 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 926 927 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) ); 928 } else { 929 if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) { 930 SemanticError( td->location, "A non whole number enum value decl must be explicitly initialized." ); 931 } 927 932 } // if 928 933 } // for 929 ret->set_body( td->enumeration.body ); 934 ret->set_body( td->enumeration.body ); // Boolean; if it has body 930 935 return ret; 931 936 } // buildEnum -
src/Parser/TypeData.h
rba897d21 r2e9b59b 132 132 Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() ); 133 133 FunctionType * buildFunction( const TypeData * ); 134 Declaration * addEnumBase( Declaration *, const TypeData * ); 134 135 void buildKRFunction( const TypeData::Function_t & function ); 135 136 -
src/Parser/parser.yy
rba897d21 r2e9b59b 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Feb 25 17:54:56202213 // Update Count : 52 6212 // Last Modified On : Mon Mar 14 16:35:29 2022 13 // Update Count : 5276 14 14 // 15 15 … … 652 652 // Historic, transitional: Disallow commas in subscripts. 653 653 // Switching to this behaviour may help check if a C compatibilty case uses comma-exprs in subscripts. 654 // { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; }655 654 // Current: Commas in subscripts make tuples. 656 655 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $5 ) ) )) ) ); } … … 661 660 // equivalent to the old x[i,j]. 662 661 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); } 662 | constant '[' assignment_expression ']' // 3[a], 'a'[a], 3.5[a] 663 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); } 664 | string_literal '[' assignment_expression ']' // "abc"[3], 3["abc"] 665 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, new ExpressionNode( $1 ), $3 ) ); } 663 666 | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call 664 667 { … … 2300 2303 ; 2301 2304 2302 enum_type: // enum2305 enum_type: // static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed ); // enum 2303 2306 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2304 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }2307 { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); } 2305 2308 | ENUM attribute_list_opt identifier 2306 2309 { typedefTable.makeTypedef( *$3 ); } 2307 2310 '{' enumerator_list comma_opt '}' 2308 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }2311 { $$ = DeclarationNode::newEnum( $3, $6, true, false )->addQualifiers( $2 ); } 2309 2312 | ENUM attribute_list_opt typedef_name // unqualified type name 2310 2313 '{' enumerator_list comma_opt '}' 2311 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }2314 { $$ = DeclarationNode::newEnum( $3->name, $5, true, false )->addQualifiers( $2 ); } 2312 2315 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2313 2316 { 2314 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2315 SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; 2316 } 2317 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2317 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) 2318 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2319 // SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; 2320 2321 $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 ) -> addEnumBase( $3 ); 2322 // $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 ); 2323 } 2324 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier 2318 2325 { 2319 2326 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } … … 2322 2329 '{' enumerator_list comma_opt '}' 2323 2330 { 2324 SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; 2331 $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 ); 2332 // $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2325 2333 } 2326 2334 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' … … 2328 2336 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2329 2337 typedefTable.makeTypedef( *$6->name ); 2330 SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; 2338 $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 ); 2339 // $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2331 2340 } 2332 2341 | enum_type_nobody … … 2335 2344 enum_type_nobody: // enum - {...} 2336 2345 ENUM attribute_list_opt identifier 2337 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); }2346 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false, false )->addQualifiers( $2 ); } 2338 2347 | ENUM attribute_list_opt type_name // qualified type name 2339 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); }2348 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false, false )->addQualifiers( $2 ); } 2340 2349 ; 2341 2350
Note:
See TracChangeset
for help on using the changeset viewer.