Changeset b0d9ff7 for src/Parser
- Timestamp:
- Sep 1, 2022, 1:27:52 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 12df6fe
- Parents:
- def751f
- Location:
- src/Parser
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Parser/DeclarationNode.cc ¶
rdef751f rb0d9ff7 253 253 } // DeclarationNode::newAggregate 254 254 255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, DeclarationNode * base) {255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base) { 256 256 DeclarationNode * newnode = new DeclarationNode; 257 257 newnode->type = new TypeData( TypeData::Enum ); … … 260 260 newnode->type->enumeration.body = body; 261 261 newnode->type->enumeration.anon = name == nullptr; 262 newnode->type->enumeration.typed = typed; 262 263 if ( base && base->type) { 263 264 newnode->type->base = base->type; 264 265 } // if 265 266 266 // Check: if base has TypeData267 267 return newnode; 268 268 } // DeclarationNode::newEnum … … 284 284 285 285 DeclarationNode * DeclarationNode::newEnumValueGeneric( const string * name, InitializerNode * init ) { 286 if ( init ) { // list init {} or a singleInit287 if ( init->get_expression() ) { // singleInit286 if ( init ) { 287 if ( init->get_expression() ) { 288 288 return newEnumConstant( name, init->get_expression() ); 289 } else { // TODO: listInit289 } else { 290 290 DeclarationNode * newnode = newName( name ); 291 291 newnode->initializer = init; … … 293 293 } // if 294 294 } else { 295 return newName( name ); // Not explicitly inited enum value;295 return newName( name ); 296 296 } // if 297 297 } // DeclarationNode::newEnumValueGeneric -
TabularUnified src/Parser/ExpressionNode.cc ¶
rdef751f rb0d9ff7 510 510 511 511 QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name ) { 512 Type * targetType = maybeMoveBuildType( decl_node ); 513 return new QualifiedNameExpr( targetType, name->name ); 514 return nullptr; 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 ); 515 533 } 516 534 -
TabularUnified src/Parser/ParseNode.h ¶
rdef751f rb0d9ff7 184 184 NameExpr * build_varref( const std::string * name ); 185 185 QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name ); 186 QualifiedNameExpr * build_qualified_expr( const EnumDecl * decl, const NameExpr * name ); 186 187 DimensionExpr * build_dimensionref( const std::string * name ); 187 188 … … 236 237 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ); 237 238 static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 238 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 ); 239 240 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 240 241 static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init ); -
TabularUnified src/Parser/TypeData.cc ¶
rdef751f rb0d9ff7 548 548 return buildAggInst( td ); 549 549 case TypeData::EnumConstant: 550 // the name gets filled in later -- by SymTab::Validate551 550 return new EnumInstType( buildQualifiers( td ), "" ); 552 551 case TypeData::SymbolicInst: … … 923 922 assert( td->kind == TypeData::Enum ); 924 923 Type * baseType = td->base ? typebuild(td->base) : nullptr; 925 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage, baseType );924 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, td->enumeration.typed, linkage, baseType ); 926 925 buildList( td->enumeration.constants, ret->get_members() ); 927 926 list< Declaration * >::iterator members = ret->get_members().begin(); 928 927 for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 929 if ( cur->has_enumeratorValue() ) { 928 if ( ret->isTyped && cur->has_enumeratorValue() ) { 929 SemanticError( td->location, "Enumerator of enum(void) cannot have an explicit initializer value." ); 930 } else if ( cur->has_enumeratorValue() ) { 930 931 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 931 932 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) ); 932 933 } else if ( !cur->initializer ) { 933 934 if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) { 934 SemanticError( td->location, " A non whole number enum value declmust be explicitly initialized." );935 SemanticError( td->location, "Enumerators of an non-integer typed enum must be explicitly initialized." ); 935 936 } 936 937 } -
TabularUnified src/Parser/TypeData.h ¶
rdef751f rb0d9ff7 59 59 bool body; 60 60 bool anon; 61 bool typed; 61 62 }; 62 63 -
TabularUnified src/Parser/parser.yy ¶
rdef751f rb0d9ff7 614 614 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); } 615 615 | type_name '.' identifier // CFA, nested type 616 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }616 { $$ = new ExpressionNode( build_qualified_expr( $1, build_varref( $3 ) ) ); } 617 617 | type_name '.' '[' field_name_list ']' // CFA, nested type / tuple field selector 618 618 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 2387 2387 enum_type: 2388 2388 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2389 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }2389 { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); } 2390 2390 | ENUM attribute_list_opt identifier 2391 2391 { typedefTable.makeTypedef( *$3 ); } 2392 2392 '{' enumerator_list comma_opt '}' 2393 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }2393 { $$ = DeclarationNode::newEnum( $3, $6, true, false )->addQualifiers( $2 ); } 2394 2394 | ENUM attribute_list_opt typedef_name // unqualified type name 2395 2395 '{' enumerator_list comma_opt '}' 2396 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }2396 { $$ = DeclarationNode::newEnum( $3->name, $5, true, false )->addQualifiers( $2 ); } 2397 2397 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2398 2398 { … … 2400 2400 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2401 2401 2402 $$ = DeclarationNode::newEnum( nullptr, $7, true, $3 )->addQualifiers( $5 ); 2402 $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 ); 2403 } 2404 | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2405 { 2406 $$ = DeclarationNode::newEnum( nullptr, $6, true, true )->addQualifiers( $4 ); 2403 2407 } 2404 2408 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt … … 2409 2413 '{' enumerator_list comma_opt '}' 2410 2414 { 2411 $$ = DeclarationNode::newEnum( $6, $10, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 ); 2412 } 2415 $$ = DeclarationNode::newEnum( $6, $10, true, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 ); 2416 } 2417 | ENUM '(' ')' attribute_list_opt identifier attribute_list_opt 2418 '{' enumerator_list comma_opt '}' 2419 { 2420 $$ = DeclarationNode::newEnum( $5, $8, true, true, nullptr )->addQualifiers( $4 )->addQualifiers( $6 ); 2421 } 2413 2422 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' 2414 2423 { 2415 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." ); } 2416 typedefTable.makeTypedef( *$6->name ); 2417 $$ = DeclarationNode::newEnum( $6->name, $9, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 ); 2424 $$ = DeclarationNode::newEnum( $6->name, $9, true, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 ); 2425 } 2426 | ENUM '(' ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' 2427 { 2428 $$ = DeclarationNode::newEnum( $5->name, $8, true, true, nullptr )->addQualifiers( $4 )->addQualifiers( $6 ); 2418 2429 } 2419 2430 | enum_type_nobody … … 2422 2433 enum_type_nobody: // enum - {...} 2423 2434 ENUM attribute_list_opt identifier 2424 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); }2425 | ENUM attribute_list_opt type_name // qualified type name2426 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); }2435 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false, false )->addQualifiers( $2 ); } 2436 | ENUM attribute_list_opt type_name 2437 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false, false )->addQualifiers( $2 ); } 2427 2438 ; 2428 2439
Note: See TracChangeset
for help on using the changeset viewer.