Changeset 6cef439 for src/Parser/parser.yy
- Timestamp:
- Mar 6, 2024, 12:34:15 PM (4 months ago)
- Branches:
- master
- Children:
- b93c544, e72fc60
- Parents:
- 1df26c3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r1df26c3 r6cef439 317 317 318 318 %union { 319 // A raw token can be used. 319 320 Token tok; 321 322 // The general node types hold some generic node or list of nodes. 323 DeclarationNode * decl; 324 InitializerNode * init; 320 325 ExpressionNode * expr; 321 DeclarationNode * decl;322 ast::AggregateDecl::Aggregate aggKey;323 ast::TypeDecl::Kind tclass;324 326 StatementNode * stmt; 325 327 ClauseNode * clause; 326 ast::WaitForStmt * wfs; 327 ast::WaitUntilStmt::ClauseNode * wucn; 328 TypeData * type; 329 330 // Special "nodes" containing compound information. 328 331 CondCtl * ifctl; 329 332 ForCtrl * forctl; 330 333 LabelNode * labels; 331 InitializerNode * init; 334 335 // Various flags and single values that become fields later. 336 ast::AggregateDecl::Aggregate aggKey; 337 ast::TypeDecl::Kind tclass; 332 338 OperKinds oper; 333 std::string * str;334 339 bool is_volatile; 335 340 EnumHiding enum_hiding; 336 341 ast::ExceptionKind except_kind; 342 // String passes ownership with it. 343 std::string * str; 344 345 // Narrower node types are used to avoid constant unwrapping. 346 ast::WaitForStmt * wfs; 347 ast::WaitUntilStmt::ClauseNode * wucn; 337 348 ast::GenericExpr * genexpr; 338 349 } … … 464 475 465 476 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type 466 %type<decl> vtable vtable_opt default_opt 477 %type<type> basic_type_name_type 478 %type<type> vtable vtable_opt default_opt 467 479 468 480 %type<decl> trait_declaration trait_declaration_list trait_declaring_list trait_specifier … … 519 531 %type<decl> type_declarator type_declarator_name type_declaring_list 520 532 521 %type<decl> type_declaration_specifier type_type_specifier type_name typegen_name 533 %type<decl> type_declaration_specifier type_type_specifier 534 %type<type> type_name typegen_name 522 535 %type<decl> typedef_name typedef_declaration typedef_expression 523 536 … … 532 545 %type<expr> type_parameters_opt type_list array_type_list // array_dimension_list 533 546 534 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list 547 %type<decl> type_qualifier forall type_qualifier_list_opt type_qualifier_list 548 %type<type> type_qualifier_name 535 549 %type<decl> type_specifier type_specifier_nobody 536 550 … … 687 701 { $$ = new ExpressionNode( build_varref( yylloc, $1 ) ); } 688 702 | TYPEDIMname // CFA, generic length argument 689 // { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( DeclarationNode::newFromTypedef( $1 ) ) ) ); }690 // { $$ = new ExpressionNode( build_varref( $1 ) ); }691 703 { $$ = new ExpressionNode( build_dimensionref( yylloc, $1 ) ); } 692 704 | tuple … … 696 708 { $$ = new ExpressionNode( new ast::StmtExpr( yylloc, dynamic_cast<ast::CompoundStmt *>( maybeMoveBuild( $2 ) ) ) ); } 697 709 | type_name '.' identifier // CFA, nested type 698 { $$ = new ExpressionNode( build_qualified_expr( yylloc, $1, build_varref( yylloc, $3 ) ) ); }710 { $$ = new ExpressionNode( build_qualified_expr( yylloc, DeclarationNode::newFromTypeData( $1 ), build_varref( yylloc, $3 ) ) ); } 699 711 | type_name '.' '[' field_name_list ']' // CFA, nested type / tuple field selector 700 712 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 978 990 { $$ = new ExpressionNode( build_keyword_cast( yylloc, $2, $5 ) ); } 979 991 | '(' VIRTUAL ')' cast_expression // CFA 980 { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $4 ), maybeMoveBuildType( nullptr )) ); }992 { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $4 ), nullptr ) ); } 981 993 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 982 994 { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); } … … 2215 2227 type_qualifier: 2216 2228 type_qualifier_name 2229 { $$ = DeclarationNode::newFromTypeData( $1 ); } 2217 2230 | attribute // trick handles most attribute locations 2218 2231 ; … … 2220 2233 type_qualifier_name: 2221 2234 CONST 2222 { $$ = DeclarationNode::newTypeQualifier( ast::CV::Const ); }2235 { $$ = build_type_qualifier( ast::CV::Const ); } 2223 2236 | RESTRICT 2224 { $$ = DeclarationNode::newTypeQualifier( ast::CV::Restrict ); }2237 { $$ = build_type_qualifier( ast::CV::Restrict ); } 2225 2238 | VOLATILE 2226 { $$ = DeclarationNode::newTypeQualifier( ast::CV::Volatile ); }2239 { $$ = build_type_qualifier( ast::CV::Volatile ); } 2227 2240 | ATOMIC 2228 { $$ = DeclarationNode::newTypeQualifier( ast::CV::Atomic ); }2241 { $$ = build_type_qualifier( ast::CV::Atomic ); } 2229 2242 2230 2243 // forall must be a CV qualifier because it can appear in places where SC qualifiers are disallowed. … … 2233 2246 // void bar( static int ); // static disallowed (gcc/CFA) 2234 2247 | forall 2235 { $$ = DeclarationNode::newForall( $1 ); }2248 { $$ = build_forall( $1 ); } 2236 2249 ; 2237 2250 … … 2283 2296 2284 2297 basic_type_name: 2298 basic_type_name_type 2299 { $$ = DeclarationNode::newFromTypeData( $1 ); } 2300 ; 2301 2302 // Just an intermediate value for conversion. 2303 basic_type_name_type: 2285 2304 VOID 2286 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }2305 { $$ = build_basic_type( DeclarationNode::Void ); } 2287 2306 | BOOL // C99 2288 { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }2307 { $$ = build_basic_type( DeclarationNode::Bool ); } 2289 2308 | CHAR 2290 { $$ = DeclarationNode::newBasicType( DeclarationNode::Char ); }2309 { $$ = build_basic_type( DeclarationNode::Char ); } 2291 2310 | INT 2292 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }2311 { $$ = build_basic_type( DeclarationNode::Int ); } 2293 2312 | INT128 2294 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 ); }2313 { $$ = build_basic_type( DeclarationNode::Int128 ); } 2295 2314 | UINT128 2296 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int128 )->addType( DeclarationNode::newSignedNess( DeclarationNode::Unsigned ) ); }2315 { $$ = addType( build_basic_type( DeclarationNode::Int128 ), build_signedness( DeclarationNode::Unsigned ) ); } 2297 2316 | FLOAT 2298 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }2317 { $$ = build_basic_type( DeclarationNode::Float ); } 2299 2318 | DOUBLE 2300 { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); }2319 { $$ = build_basic_type( DeclarationNode::Double ); } 2301 2320 | uuFLOAT80 2302 { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat80 ); }2321 { $$ = build_basic_type( DeclarationNode::uuFloat80 ); } 2303 2322 | uuFLOAT128 2304 { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat128 ); }2323 { $$ = build_basic_type( DeclarationNode::uuFloat128 ); } 2305 2324 | uFLOAT16 2306 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat16 ); }2325 { $$ = build_basic_type( DeclarationNode::uFloat16 ); } 2307 2326 | uFLOAT32 2308 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32 ); }2327 { $$ = build_basic_type( DeclarationNode::uFloat32 ); } 2309 2328 | uFLOAT32X 2310 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32x ); }2329 { $$ = build_basic_type( DeclarationNode::uFloat32x ); } 2311 2330 | uFLOAT64 2312 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64 ); }2331 { $$ = build_basic_type( DeclarationNode::uFloat64 ); } 2313 2332 | uFLOAT64X 2314 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64x ); }2333 { $$ = build_basic_type( DeclarationNode::uFloat64x ); } 2315 2334 | uFLOAT128 2316 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat128 ); }2335 { $$ = build_basic_type( DeclarationNode::uFloat128 ); } 2317 2336 | DECIMAL32 2318 2337 { SemanticError( yylloc, "_Decimal32 is currently unimplemented." ); $$ = nullptr; } … … 2322 2341 { SemanticError( yylloc, "_Decimal128 is currently unimplemented." ); $$ = nullptr; } 2323 2342 | COMPLEX // C99 2324 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }2343 { $$ = build_complex_type( DeclarationNode::Complex ); } 2325 2344 | IMAGINARY // C99 2326 { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }2345 { $$ = build_complex_type( DeclarationNode::Imaginary ); } 2327 2346 | SIGNED 2328 { $$ = DeclarationNode::newSignedNess( DeclarationNode::Signed ); }2347 { $$ = build_signedness( DeclarationNode::Signed ); } 2329 2348 | UNSIGNED 2330 { $$ = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); }2349 { $$ = build_signedness( DeclarationNode::Unsigned ); } 2331 2350 | SHORT 2332 { $$ = DeclarationNode::newLength( DeclarationNode::Short ); }2351 { $$ = build_length( DeclarationNode::Short ); } 2333 2352 | LONG 2334 { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }2353 { $$ = build_length( DeclarationNode::Long ); } 2335 2354 | VA_LIST // GCC, __builtin_va_list 2336 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }2355 { $$ = build_builtin_type( DeclarationNode::Valist ); } 2337 2356 | AUTO_TYPE 2338 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::AutoType ); }2357 { $$ = build_builtin_type( DeclarationNode::AutoType ); } 2339 2358 | vtable 2340 2359 ; … … 2348 2367 vtable: 2349 2368 VTABLE '(' type_name ')' default_opt 2350 { $$ = DeclarationNode::newVtableType( $3 ); } 2351 // { SemanticError( yylloc, "vtable is currently unimplemented." ); $$ = nullptr; } 2369 { $$ = build_vtable_type( $3 ); } 2352 2370 ; 2353 2371 … … 2399 2417 { $$ = DeclarationNode::newTypeof( $3, true ); } 2400 2418 | ZERO_T // CFA 2401 { $$ = DeclarationNode::new BuiltinType( DeclarationNode::Zero); }2419 { $$ = DeclarationNode::newFromTypeData( build_builtin_type( DeclarationNode::Zero ) ); } 2402 2420 | ONE_T // CFA 2403 { $$ = DeclarationNode::new BuiltinType( DeclarationNode::One); }2421 { $$ = DeclarationNode::newFromTypeData( build_builtin_type( DeclarationNode::One ) ); } 2404 2422 ; 2405 2423 … … 2457 2475 type_type_specifier: // typedef types 2458 2476 type_name 2477 { $$ = DeclarationNode::newFromTypeData( $1 ); } 2459 2478 | type_qualifier_list type_name 2460 { $$ = $2->addQualifiers( $1 ); }2479 { $$ = DeclarationNode::newFromTypeData( $2 )->addQualifiers( $1 ); } 2461 2480 | type_type_specifier type_qualifier 2462 2481 { $$ = $1->addQualifiers( $2 ); } … … 2465 2484 type_name: 2466 2485 TYPEDEFname 2467 { $$ = DeclarationNode::newFromTypedef( $1 ); }2486 { $$ = build_typedef( $1 ); } 2468 2487 | '.' TYPEDEFname 2469 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }2488 { $$ = build_qualified_type( build_global_scope(), build_typedef( $2 ) ); } 2470 2489 | type_name '.' TYPEDEFname 2471 { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }2490 { $$ = build_qualified_type( $1, build_typedef( $3 ) ); } 2472 2491 | typegen_name 2473 2492 | '.' typegen_name 2474 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }2493 { $$ = build_qualified_type( build_global_scope(), $2 ); } 2475 2494 | type_name '.' typegen_name 2476 { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }2495 { $$ = build_qualified_type( $1, $3 ); } 2477 2496 ; 2478 2497 2479 2498 typegen_name: // CFA 2480 2499 TYPEGENname 2481 { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }2500 { $$ = build_type_gen( $1, nullptr ); } 2482 2501 | TYPEGENname '(' ')' 2483 { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }2502 { $$ = build_type_gen( $1, nullptr ); } 2484 2503 | TYPEGENname '(' type_list ')' 2485 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }2504 { $$ = build_type_gen( $1, $3 ); } 2486 2505 ; 2487 2506 … … 2519 2538 '{' field_declaration_list_opt '}' type_parameters_opt 2520 2539 { 2521 DeclarationNode::newFromType def( $3);2540 DeclarationNode::newFromTypeData( build_typedef( $3 ) ); 2522 2541 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); 2523 2542 } … … 2529 2548 '{' field_declaration_list_opt '}' type_parameters_opt 2530 2549 { 2531 DeclarationNode::newFromType Gen( $3, nullptr);2550 DeclarationNode::newFromTypeData( build_type_gen( $3, nullptr ) ); 2532 2551 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); 2533 2552 } … … 2554 2573 // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is 2555 2574 // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and 2556 // delete newFromTypeGen. 2557 if ( $3->type->kind == TypeData::SymbolicInst && ! $3->type->symbolic.isTypedef ) { 2558 $$ = $3->addQualifiers( $2 ); 2575 if ( $3->kind == TypeData::SymbolicInst && ! $3->symbolic.isTypedef ) { 2576 $$ = DeclarationNode::newFromTypeData( $3 )->addQualifiers( $2 ); 2559 2577 } else { 2560 $$ = DeclarationNode::newAggregate( $1, $3-> type->symbolic.name, $3->type->symbolic.actuals, nullptr, false )->addQualifiers( $2 );2561 $3-> type->symbolic.name = nullptr; // copied to $$2562 $3-> type->symbolic.actuals = nullptr;2578 $$ = DeclarationNode::newAggregate( $1, $3->symbolic.name, $3->symbolic.actuals, nullptr, false )->addQualifiers( $2 ); 2579 $3->symbolic.name = nullptr; // copied to $$ 2580 $3->symbolic.actuals = nullptr; 2563 2581 delete $3; 2564 2582 } … … 2785 2803 | ENUM attribute_list_opt type_name 2786 2804 { 2787 typedefTable.makeTypedef( *$3-> type->symbolic.name, "enum_type_nobody 2" );2788 $$ = DeclarationNode::newEnum( $3-> type->symbolic.name, nullptr, false, false )->addQualifiers( $2 );2805 typedefTable.makeTypedef( *$3->symbolic.name, "enum_type_nobody 2" ); 2806 $$ = DeclarationNode::newEnum( $3->symbolic.name, nullptr, false, false )->addQualifiers( $2 ); 2789 2807 } 2790 2808 ; … … 2794 2812 { $$ = DeclarationNode::newEnumValueGeneric( $2, $3 ); } 2795 2813 | INLINE type_name 2796 { $$ = DeclarationNode::newEnumInLine( *$2-> type->symbolic.name ); }2814 { $$ = DeclarationNode::newEnumInLine( *$2->symbolic.name ); } 2797 2815 | enumerator_list ',' visible_hide_opt identifier_or_type_name enumerator_value_opt 2798 2816 { $$ = $1->set_last( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); } … … 2839 2857 cfa_parameter_list_ellipsis_opt: // CFA, abstract + real 2840 2858 // empty 2841 { $$ = DeclarationNode::new BasicType( DeclarationNode::Void); }2859 { $$ = DeclarationNode::newFromTypeData( build_basic_type( DeclarationNode::Void ) ); } 2842 2860 | ELLIPSIS 2843 2861 { $$ = nullptr; } … … 3775 3793 { $$ = $1->addQualifiers( $2 ); } 3776 3794 | '&' MUTEX paren_identifier attribute_list_opt 3777 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::new TypeQualifier( ast::CV::Mutex),3795 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newFromTypeData( build_type_qualifier( ast::CV::Mutex ) ), 3778 3796 OperKinds::AddressOf ) )->addQualifiers( $4 ); } 3779 3797 | identifier_parameter_ptr … … 3826 3844 { $$ = $1->addQualifiers( $2 ); } 3827 3845 | '&' MUTEX typedef_name attribute_list_opt 3828 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::new TypeQualifier( ast::CV::Mutex),3846 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newFromTypeData( build_type_qualifier( ast::CV::Mutex ) ), 3829 3847 OperKinds::AddressOf ) )->addQualifiers( $4 ); } 3830 3848 | type_parameter_ptr … … 4010 4028 abstract_parameter_ptr 4011 4029 | '&' MUTEX attribute_list_opt 4012 { $$ = DeclarationNode::newPointer( DeclarationNode::new TypeQualifier( ast::CV::Mutex), OperKinds::AddressOf )->addQualifiers( $3 ); }4030 { $$ = DeclarationNode::newPointer( DeclarationNode::newFromTypeData( build_type_qualifier( ast::CV::Mutex ) ), OperKinds::AddressOf )->addQualifiers( $3 ); } 4013 4031 | abstract_parameter_array attribute_list_opt 4014 4032 { $$ = $1->addQualifiers( $2 ); }
Note: See TracChangeset
for help on using the changeset viewer.