Changeset dc56b9d for src/Parser
- Timestamp:
- Sep 20, 2022, 9:24:55 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- b6c3688
- Parents:
- 1c893ae (diff), 53a768d (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
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Parser/DeclarationNode.cc ¶
r1c893ae rdc56b9d 254 254 } // DeclarationNode::newAggregate 255 255 256 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, DeclarationNode * base) {256 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base) { 257 257 DeclarationNode * newnode = new DeclarationNode; 258 258 newnode->type = new TypeData( TypeData::Enum ); … … 261 261 newnode->type->enumeration.body = body; 262 262 newnode->type->enumeration.anon = name == nullptr; 263 newnode->type->enumeration.typed = typed; 263 264 if ( base && base->type) { 264 265 newnode->type->base = base->type; 265 266 } // if 266 267 267 // Check: if base has TypeData268 268 return newnode; 269 269 } // DeclarationNode::newEnum … … 285 285 286 286 DeclarationNode * DeclarationNode::newEnumValueGeneric( const string * name, InitializerNode * init ) { 287 if ( init ) { // list init {} or a singleInit288 if ( init->get_expression() ) { // singleInit287 if ( init ) { 288 if ( init->get_expression() ) { 289 289 return newEnumConstant( name, init->get_expression() ); 290 } else { // TODO: listInit290 } else { 291 291 DeclarationNode * newnode = newName( name ); 292 292 newnode->initializer = init; … … 294 294 } // if 295 295 } else { 296 return newName( name ); // Not explicitly inited enum value;296 return newName( name ); 297 297 } // if 298 298 } // DeclarationNode::newEnumValueGeneric -
TabularUnified src/Parser/ExpressionNode.cc ¶
r1c893ae rdc56b9d 509 509 } // build_varref 510 510 511 QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name ) { 512 Declaration * newDecl = maybeBuild< Declaration >(decl_node); 513 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { 514 const Type * t = newDeclWithType->get_type(); 515 if ( t ) { 516 if ( const TypeInstType * typeInst = dynamic_cast<const TypeInstType *>( t ) ) { 517 newDecl= new EnumDecl( typeInst->name ); 518 } 519 } 520 } 521 auto ret = new QualifiedNameExpr( newDecl, name->name ); 522 if ( auto e = dynamic_cast<EnumDecl*>(newDecl) ) { 523 auto enumInst = new EnumInstType( Type::Qualifiers(), e ); 524 auto obj = new ObjectDecl( name->name, Type::StorageClasses(), LinkageSpec::Cforall, nullptr, enumInst, nullptr ); 525 ret->set_var( obj ); 526 } 527 return ret; 528 } 529 530 QualifiedNameExpr * build_qualified_expr( const EnumDecl * decl_node, const NameExpr * name ) { 531 EnumDecl * newDecl = const_cast< EnumDecl * >( decl_node ); 532 return new QualifiedNameExpr( newDecl, name->name ); 533 } 534 511 535 DimensionExpr * build_dimensionref( const string * name ) { 512 536 DimensionExpr * expr = new DimensionExpr( *name ); -
TabularUnified src/Parser/ParseNode.h ¶
r1c893ae rdc56b9d 183 183 184 184 NameExpr * build_varref( const std::string * name ); 185 QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name ); 186 QualifiedNameExpr * build_qualified_expr( const EnumDecl * decl, const NameExpr * name ); 185 187 DimensionExpr * build_dimensionref( const std::string * name ); 186 188 … … 235 237 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ); 236 238 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, DeclarationNode * base = nullptr );239 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base = nullptr ); 238 240 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 239 241 static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init ); -
TabularUnified src/Parser/TypeData.cc ¶
r1c893ae rdc56b9d 546 546 return buildAggInst( td ); 547 547 case TypeData::EnumConstant: 548 // the name gets filled in later -- by SymTab::Validate549 548 return new EnumInstType( buildQualifiers( td ), "" ); 550 549 case TypeData::SymbolicInst: … … 921 920 assert( td->kind == TypeData::Enum ); 922 921 Type * baseType = td->base ? typebuild(td->base) : nullptr; 923 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage, baseType );922 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, td->enumeration.typed, linkage, baseType ); 924 923 buildList( td->enumeration.constants, ret->get_members() ); 925 924 list< Declaration * >::iterator members = ret->get_members().begin(); 926 925 for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 927 if ( cur->has_enumeratorValue() ) { 926 if ( ret->isTyped && !ret->base && cur->has_enumeratorValue() ) { 927 SemanticError( td->location, "Enumerator of enum(void) cannot have an explicit initializer value." ); 928 } else if ( cur->has_enumeratorValue() ) { 928 929 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 929 930 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) ); 930 931 } else if ( !cur->initializer ) { 931 932 if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) { 932 SemanticError( td->location, " A non whole number enum value declmust be explicitly initialized." );933 SemanticError( td->location, "Enumerators of an non-integer typed enum must be explicitly initialized." ); 933 934 } 934 935 } -
TabularUnified src/Parser/TypeData.h ¶
r1c893ae rdc56b9d 59 59 bool body; 60 60 bool anon; 61 bool typed; 61 62 }; 62 63 -
TabularUnified src/Parser/parser.yy ¶
r1c893ae rdc56b9d 637 637 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); } 638 638 | type_name '.' identifier // CFA, nested type 639 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }639 { $$ = new ExpressionNode( build_qualified_expr( $1, build_varref( $3 ) ) ); } 640 640 | type_name '.' '[' field_name_list ']' // CFA, nested type / tuple field selector 641 641 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 2538 2538 enum_type: 2539 2539 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2540 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }2540 { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); } 2541 2541 | ENUM attribute_list_opt identifier 2542 2542 { typedefTable.makeTypedef( *$3 ); } 2543 2543 '{' enumerator_list comma_opt '}' 2544 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }2544 { $$ = DeclarationNode::newEnum( $3, $6, true, false )->addQualifiers( $2 ); } 2545 2545 | ENUM attribute_list_opt typedef_name // unqualified type name 2546 2546 '{' enumerator_list comma_opt '}' 2547 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); } 2548 | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2549 { SemanticError( yylloc, "Unvalued enumerated type is currently unimplemented." ); $$ = nullptr; } 2547 { $$ = DeclarationNode::newEnum( $3->name, $5, true, false )->addQualifiers( $2 ); } 2550 2548 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2551 2549 { … … 2553 2551 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2554 2552 2555 $$ = DeclarationNode::newEnum( nullptr, $7, true, $3 )->addQualifiers( $5 ); 2553 $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 ); 2554 } 2555 | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2556 { 2557 $$ = DeclarationNode::newEnum( nullptr, $6, true, true )->addQualifiers( $4 ); 2556 2558 } 2557 2559 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt … … 2562 2564 '{' enumerator_list comma_opt '}' 2563 2565 { 2564 $$ = DeclarationNode::newEnum( $6, $10, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 ); 2565 } 2566 $$ = DeclarationNode::newEnum( $6, $10, true, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 ); 2567 } 2568 | ENUM '(' ')' attribute_list_opt identifier attribute_list_opt 2569 '{' enumerator_list comma_opt '}' 2570 { 2571 $$ = DeclarationNode::newEnum( $5, $8, true, true, nullptr )->addQualifiers( $4 )->addQualifiers( $6 ); 2572 } 2566 2573 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' 2567 2574 { 2568 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." ); } 2569 typedefTable.makeTypedef( *$6->name ); 2570 $$ = DeclarationNode::newEnum( $6->name, $9, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 ); 2575 $$ = DeclarationNode::newEnum( $6->name, $9, true, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 ); 2576 } 2577 | ENUM '(' ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' 2578 { 2579 $$ = DeclarationNode::newEnum( $5->name, $8, true, true, nullptr )->addQualifiers( $4 )->addQualifiers( $6 ); 2571 2580 } 2572 2581 | enum_type_nobody … … 2575 2584 enum_type_nobody: // enum - {...} 2576 2585 ENUM attribute_list_opt identifier 2577 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); }2578 | ENUM attribute_list_opt type_name // qualified type name2579 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); }2586 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false, false )->addQualifiers( $2 ); } 2587 | ENUM attribute_list_opt type_name 2588 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false, false )->addQualifiers( $2 ); } 2580 2589 ; 2581 2590
Note: See TracChangeset
for help on using the changeset viewer.