Changeset fa2c005
- Timestamp:
- Jun 8, 2023, 3:19:43 PM (4 months ago)
- Branches:
- ADT
- Parents:
- 044ae62
- Location:
- src
- Files:
-
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r044ae62 rfa2c005 321 321 get<Type>().accept1(node->base) 322 322 ); 323 // decl->data_constructors = get<StructDecl>().acceptL( node->data_constructors );324 // decl->data_union = get<UnionDecl>().accept1( node->data_union );325 // decl->tag = get<EnumDecl>().accept1( node->tag );326 // decl->tag_union = get<StructDecl>().accept1( node->tag_union );327 323 return aggregatePostamble( decl, node ); 328 324 } … … 334 330 get<Attribute>().acceptL( node->attributes ), 335 331 LinkageSpec::Spec( node->linkage.val ), 336 get<StructDecl>().acceptL( node->data_constructors ),337 332 get<UnionDecl>().accept1( node->data_union ), 338 333 get<EnumDecl>().accept1( node->tag ), … … 1344 1339 } 1345 1340 1341 const ast::Type * visit( [[maybe_unused]]const ast::AdtInstType * node ) override final { 1342 return nullptr; 1343 } 1344 1346 1345 const ast::Type * visit( const ast::UnionInstType * node ) override final { 1347 1346 UnionInstType * ty; … … 1824 1823 decl->uniqueId = old->uniqueId; 1825 1824 decl->storage = { old->storageClasses.val }; 1826 decl->data_constructors = GET_ACCEPT_V( data_constructors, StructDecl );1827 1825 decl->data_union = GET_ACCEPT_1( data_union, UnionDecl ); 1828 1826 decl->tag = GET_ACCEPT_1( tag, EnumDecl ); … … 2876 2874 postvisit( old, ty ); 2877 2875 } 2876 2877 virtual void visit( const AdtInstType * old ) override final { 2878 ast::AdtInstType * ty; 2879 if ( old->baseAdt ) { 2880 ty = new ast::AdtInstType{ 2881 GET_ACCEPT_1( baseAdt, AdtDecl ), 2882 cv( old ), 2883 GET_ACCEPT_V( attributes, Attribute ) 2884 }; 2885 } else { 2886 ty = new ast::AdtInstType{ 2887 old->name, 2888 cv( old ), 2889 GET_ACCEPT_V( attributes, Attribute ) 2890 }; 2891 } 2892 postvisit( old, ty ); 2893 } 2878 2894 2879 2895 virtual void visit( const UnionInstType * old ) override final { -
src/AST/Decl.hpp
r044ae62 rfa2c005 248 248 class AggregateDecl : public Decl { 249 249 public: 250 enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate, Adt };250 enum Aggregate { Undecided, Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate, Adt }; 251 251 static const char * aggrString( Aggregate aggr ); 252 252 … … 346 346 class AdtDecl final : public AggregateDecl { 347 347 public: 348 std::vector<ptr<StructDecl>> data_constructors; // Todo: members?349 348 ptr<UnionDecl> data_union; 350 349 ptr<EnumDecl> tag; -
src/AST/Fwd.hpp
r044ae62 rfa2c005 123 123 using UnionInstType = SueInstType<UnionDecl>; 124 124 using EnumInstType = SueInstType<EnumDecl>; 125 using AdtInstType = SueInstType<AdtDecl>; 125 126 class TraitInstType; 126 127 class TypeInstType; -
src/AST/Pass.hpp
r044ae62 rfa2c005 219 219 const ast::Type * visit( const ast::FunctionType * ) override final; 220 220 const ast::Type * visit( const ast::StructInstType * ) override final; 221 const ast::Type * visit( const ast::AdtInstType * ) override final; 221 222 const ast::Type * visit( const ast::UnionInstType * ) override final; 222 223 const ast::Type * visit( const ast::EnumInstType * ) override final; -
src/AST/Pass.impl.hpp
r044ae62 rfa2c005 585 585 586 586 //-------------------------------------------------------------------------- 587 // AdtDecl 588 template< typename core_t > 589 const ast::Decl * ast::Pass< core_t >::visit( const ast::AdtDecl * node ) { 590 VISIT_START( node ); 591 592 __pass::symtab::addAdtFwd( core, 0, node ); 593 594 if ( __visit_children() ) { 595 guard_symtab guard { *this }; 596 maybe_accept( node, &AdtDecl::params ); 597 maybe_accept( node, &AdtDecl::members ); 598 maybe_accept( node, &AdtDecl::attributes ); 599 600 maybe_accept( node, &AdtDecl::data_union ); 601 maybe_accept( node, &AdtDecl::tag ); 602 maybe_accept( node, &AdtDecl::tag_union ); 603 } 604 605 __pass::symtab::addAdt( core, 0, node ); 606 VISIT_END( Decl, node ); 607 } 608 609 //-------------------------------------------------------------------------- 587 610 // UnionDecl 588 611 template< typename core_t > … … 620 643 maybe_accept( node, &EnumDecl::members ); 621 644 maybe_accept( node, &EnumDecl::attributes ); 622 623 // maybe_accept( node, &EnumDecl::data_constructors );624 // maybe_accept( node, &EnumDecl::data_union );625 // maybe_accept( node, &EnumDecl::tag );626 // maybe_accept( node, &EnumDecl::tag_union );627 645 } else { 628 646 maybe_accept( node, &EnumDecl::base ); … … 630 648 maybe_accept( node, &EnumDecl::members ); 631 649 maybe_accept( node, &EnumDecl::attributes ); 632 633 // maybe_accept( node, &EnumDecl::data_constructors ); 634 // maybe_accept( node, &EnumDecl::data_union ); 635 // maybe_accept( node, &EnumDecl::tag ); 636 // maybe_accept( node, &EnumDecl::tag_union ); 637 } 638 } 639 640 VISIT_END( Decl, node ); 641 } 642 643 template< typename core_t > 644 const ast::Decl * ast::Pass< core_t >::visit( const ast::AdtDecl * node ) { 645 VISIT_START( node ); 646 647 __pass::symtab::addAdt( core, 0, node ); 648 649 if ( __visit_children() ) { 650 guard_symtab guard { *this }; 651 maybe_accept( node, &AdtDecl::params ); 652 maybe_accept( node, &AdtDecl::members ); 653 maybe_accept( node, &AdtDecl::attributes ); 654 655 maybe_accept( node, &AdtDecl::data_constructors ); 656 maybe_accept( node, &AdtDecl::data_union ); 657 maybe_accept( node, &AdtDecl::tag ); 658 maybe_accept( node, &AdtDecl::tag_union ); 650 } 659 651 } 660 652 … … 1967 1959 1968 1960 //-------------------------------------------------------------------------- 1961 // AdtInstType 1962 template< typename core_t > 1963 const ast::Type * ast::Pass< core_t >::visit( const ast::AdtInstType * node ) { 1964 VISIT_START( node ); 1965 1966 __pass::symtab::addAdt( core, 0, node->name ); 1967 1968 if ( __visit_children() ) { 1969 guard_symtab guard { *this }; 1970 maybe_accept( node, &AdtInstType::params ); 1971 } 1972 1973 VISIT_END( Type, node ); 1974 } 1975 1976 //-------------------------------------------------------------------------- 1969 1977 // UnionInstType 1970 1978 template< typename core_t > -
src/AST/Pass.proto.hpp
r044ae62 rfa2c005 477 477 478 478 template<typename core_t> 479 static inline auto addAdtFwd( core_t & core, int, const ast::AdtDecl * decl ) -> decltype( core.symtab.addAdt( decl ), void() ) { 480 ast::AdtDecl * fwd = new ast::AdtDecl( decl->location, decl->name ); 481 for ( const auto & param : decl->params ) { 482 fwd->params.push_back( deepCopy( param.get() ) ); 483 } 484 core.symtab.addAdt( fwd ); 485 } 486 487 template<typename core_t> 488 static inline auto addAdtFwd( core_t &, long, const ast::AdtDecl * ) {} 489 490 template<typename core_t> 479 491 static inline auto addUnionFwd( core_t & core, int, const ast::UnionDecl * decl ) -> decltype( core.symtab.addUnion( decl ), void() ) { 480 492 ast::UnionDecl * fwd = new ast::UnionDecl( decl->location, decl->name ); … … 489 501 490 502 template<typename core_t> 491 static inline auto addAdtFwd( core_t & core, int, const ast::AdtDecl * decl ) -> decltype( core.symtab.addAdt( decl ), void() ) {492 ast::AdtDecl * fwd = new ast::AdtDecl( decl->location, decl->name );493 for ( const auto & param : decl->params ) {494 fwd->params.push_back( deepCopy( param.get() ) );495 }496 // Experimental497 for ( const auto & ctor : decl->data_constructors ) {498 addStructFwd( core, 0, ctor );499 }500 core.symtab.addAdt( fwd );501 }502 503 template<typename core_t>504 static inline auto addAdtFwd( core_t &, long, const ast::AdtDecl) {}505 506 template<typename core_t>507 503 static inline auto addStruct( core_t & core, int, const std::string & str ) -> decltype( core.symtab.addStruct( str ), void() ) { 508 504 if ( ! core.symtab.lookupStruct( str ) ) { … … 513 509 template<typename core_t> 514 510 static inline void addStruct( core_t &, long, const std::string & ) {} 511 512 template<typename core_t> 513 static inline auto addAdt( core_t & core, int, const std::string & str ) -> decltype( core.symtab.addAdt( str ), void() ) { 514 if ( ! core.symtab.lookupAdt( str ) ) { 515 core.symtab.addAdt( str ); 516 } 517 } 518 519 template<typename core_t> 520 static inline void addAdt( core_t &, long, const std::string & ) {} 515 521 516 522 template<typename core_t> -
src/AST/Print.cpp
r044ae62 rfa2c005 1501 1501 } 1502 1502 1503 virtual const ast::Type * visit( const ast::AdtInstType * node ) override final { 1504 preprint( node ); 1505 os << "instance of Adt " << node->name; 1506 print( node->params ); 1507 return node; 1508 } 1509 1503 1510 virtual const ast::Type * visit( const ast::UnionInstType * node ) override final { 1504 1511 preprint( node ); -
src/AST/SymbolTable.cpp
r044ae62 rfa2c005 218 218 } 219 219 220 const AdtDecl * SymbolTable::lookupAdt( const std::string &id ) const { 221 ++*stats().lookup_calls; 222 if ( ! adtTable ) return nullptr; 223 auto it = adtTable->find( id ); 224 return it == adtTable->end() ? nullptr : it->second.decl; 225 } 226 220 227 const EnumDecl * SymbolTable::lookupEnum( const std::string &id ) const { 221 228 ++*stats().lookup_calls; … … 339 346 } 340 347 341 void SymbolTable::addEnum( const EnumDecl *decl ) { 342 ++*stats().add_calls; 343 const std::string &id = decl->name; 344 345 if ( ! enumTable ) { 346 enumTable = EnumTable::new_ptr(); 347 } else { 348 ++*stats().map_lookups; 349 auto existing = enumTable->find( id ); 350 if ( existing != enumTable->end() 351 && existing->second.scope == scope 352 && addedDeclConflicts( existing->second.decl, decl ) ) return; 353 } 354 355 lazyInitScope(); 356 ++*stats().map_mutations; 357 enumTable = enumTable->set( id, scoped<EnumDecl>{ decl, scope } ); 348 void SymbolTable::addAdt( const std::string &id ) { 349 addAdt( new AdtDecl( CodeLocation(), id ) ); 358 350 } 359 351 … … 377 369 adtTable = adtTable->set( id, scoped<AdtDecl>{ decl, scope }); 378 370 } 371 372 void SymbolTable::addEnum( const EnumDecl *decl ) { 373 ++*stats().add_calls; 374 const std::string &id = decl->name; 375 376 if ( ! enumTable ) { 377 enumTable = EnumTable::new_ptr(); 378 } else { 379 ++*stats().map_lookups; 380 auto existing = enumTable->find( id ); 381 if ( existing != enumTable->end() 382 && existing->second.scope == scope 383 && addedDeclConflicts( existing->second.decl, decl ) ) return; 384 } 385 386 lazyInitScope(); 387 ++*stats().map_mutations; 388 enumTable = enumTable->set( id, scoped<EnumDecl>{ decl, scope } ); 389 } 390 379 391 380 392 void SymbolTable::addUnion( const std::string &id ) { -
src/AST/SymbolTable.hpp
r044ae62 rfa2c005 111 111 /// Gets the top-most struct declaration with the given ID 112 112 const StructDecl * lookupStruct( const std::string &id ) const; 113 114 const AdtDecl * lookupAdt( const std::string &id ) const; 113 115 /// Gets the top-most enum declaration with the given ID 114 116 const EnumDecl * lookupEnum( const std::string &id ) const; … … 141 143 void addEnum( const EnumDecl * decl ); 142 144 /// Adds an adt declaration to the symbol table 145 void addAdt( const std::string & id ); 143 146 void addAdt( const AdtDecl * decl ); 144 147 /// Adds a union declaration to the symbol table by name -
src/AST/Type.cpp
r044ae62 rfa2c005 138 138 template class SueInstType<UnionDecl>; 139 139 template class SueInstType<EnumDecl>; 140 template class SueInstType<AdtDecl>; 140 141 141 142 // --- TraitInstType -
src/AST/Visitor.hpp
r044ae62 rfa2c005 111 111 virtual const ast::Type * visit( const ast::TraitInstType * ) = 0; 112 112 virtual const ast::Type * visit( const ast::TypeInstType * ) = 0; 113 virtual const ast::Type * visit( const ast::AdtInstType * ) = 0; 113 114 virtual const ast::Type * visit( const ast::TupleType * ) = 0; 114 115 virtual const ast::Type * visit( const ast::TypeofType * ) = 0; -
src/CodeGen/CodeGenerator.cc
r044ae62 rfa2c005 296 296 297 297 void CodeGenerator::handleData( EnumDecl * ) { 298 // output << " /** data type */" << endl;299 // for ( StructDecl * decl : dataDecl->data_constructors ) {300 // postvisit(decl);301 // output << ";" << endl;302 // }303 // postvisit( dataDecl->data_union );304 // output << ";" << endl;305 // postvisit( dataDecl->tag );306 // output << ";" << endl;307 // postvisit( dataDecl->tag_union );308 // output << ";" << endl;309 298 assert(false); 310 299 } 311 300 312 301 void CodeGenerator::postvisit( EnumDecl * enumDecl ) { 313 // if ( enumDecl->data_constructors.size() > 0 ) return handleData( enumDecl );314 302 extension( enumDecl ); 315 303 std::list< Declaration* > &memb = enumDecl->get_members(); … … 350 338 } 351 339 352 void CodeGenerator::postvisit( AdtDecl * ) { 353 // TODO 340 // Temporary fix, But visitor should be able to handle this 341 void CodeGenerator::postvisit( AdtDecl * adtDecl ) { 342 output << endl << "/* AdtDecl Code Section */" << endl; 343 postvisit( adtDecl->tag ); 344 output << ";" << endl; 345 postvisit( adtDecl->data_union ); 346 output << ";" << endl; 347 postvisit( adtDecl->tag_union ); 354 348 } 355 349 -
src/Common/CodeLocationTools.cpp
r044ae62 rfa2c005 185 185 macro(FunctionType, Type) \ 186 186 macro(StructInstType, Type) \ 187 macro(AdtInstType, Type) \ 187 188 macro(UnionInstType, Type) \ 188 189 macro(EnumInstType, Type) \ -
src/Common/PassVisitor.h
r044ae62 rfa2c005 226 226 virtual void visit( StructInstType * aggregateUseType ) override final; 227 227 virtual void visit( const StructInstType * aggregateUseType ) override final; 228 virtual void visit( AdtInstType * aggregateUseType ) override final; 229 virtual void visit( const AdtInstType * aggregateUseType ) override final; 228 230 virtual void visit( UnionInstType * aggregateUseType ) override final; 229 231 virtual void visit( const UnionInstType * aggregateUseType ) override final; … … 351 353 virtual Type * mutate( FunctionType * functionType ) override final; 352 354 virtual Type * mutate( StructInstType * aggregateUseType ) override final; 355 virtual Type * mutate( AdtInstType * aggregateUseType ) override final; 353 356 virtual Type * mutate( UnionInstType * aggregateUseType ) override final; 354 357 virtual Type * mutate( EnumInstType * aggregateUseType ) override final; … … 442 445 void indexerAddStructFwd( const StructDecl * node ) { indexer_impl_addStructFwd( pass, 0, node ); } 443 446 void indexerAddEnum ( const EnumDecl * node ) { indexer_impl_addEnum ( pass, 0, node ); } 447 void indexerAddAdt ( const std::string & id ) { indexer_impl_addAdt ( pass, 0, id ); } 444 448 void indexerAddAdt ( const AdtDecl * node ) { indexer_impl_addAdt ( pass, 0, node ); } 445 449 void indexerAddAdtFwd ( const AdtDecl * node ) { indexer_impl_addAdtFwd ( pass, 0, node ); } -
src/Common/PassVisitor.impl.h
r044ae62 rfa2c005 688 688 689 689 //-------------------------------------------------------------------------- 690 // AdtDecl 691 template< typename pass_type > 692 void PassVisitor< pass_type >::visit( AdtDecl * node ) { 693 VISIT_START( node ); 694 695 indexerAddAdtFwd( node ); 696 697 maybeAccept_impl( node->data_union, *this ); 698 maybeAccept_impl( node->tag, *this ); 699 700 maybeAccept_impl( node->parameters, *this ); 701 maybeAccept_impl( node->members , *this ); 702 maybeAccept_impl( node->attributes, *this ); 703 704 indexerAddAdt( node ); 705 706 VISIT_END( node ); 707 } 708 709 template< typename pass_type > 710 void PassVisitor< pass_type >::visit( const AdtDecl * node ) { 711 VISIT_START( node ); 712 713 indexerAddAdtFwd( node ); 714 715 maybeAccept_impl( node->data_union, *this ); 716 maybeAccept_impl( node->tag, *this ); 717 718 maybeAccept_impl( node->parameters, *this ); 719 maybeAccept_impl( node->members , *this ); 720 maybeAccept_impl( node->attributes, *this ); 721 722 indexerAddAdt( node ); 723 724 VISIT_END( node ); 725 } 726 727 template< typename pass_type > 728 Declaration * PassVisitor< pass_type >::mutate( AdtDecl * node ) { 729 MUTATE_START( node ); 730 731 indexerAddAdtFwd( node ); 732 733 maybeMutate_impl( node->data_union, *this ); 734 maybeMutate_impl( node->tag, *this ); 735 736 maybeMutate_impl( node->parameters, *this ); 737 maybeMutate_impl( node->members , *this ); 738 maybeMutate_impl( node->attributes, *this ); 739 740 indexerAddAdt( node ); 741 742 MUTATE_END( Declaration, node ); 743 } 744 745 746 //-------------------------------------------------------------------------- 690 747 // UnionDecl 691 748 template< typename pass_type > … … 789 846 } 790 847 791 template< typename pass_type >792 void PassVisitor< pass_type >::visit( AdtDecl * node ) {793 VISIT_START( node );794 795 indexerAddAdtFwd( node );796 797 // unlike structs, traits, and unions, enums inject their members into the global scope798 maybeAccept_impl( node->data_constructors, *this );799 maybeAccept_impl( node->data_union, *this );800 maybeAccept_impl( node->tag, *this );801 802 maybeAccept_impl( node->parameters, *this );803 maybeAccept_impl( node->members , *this );804 maybeAccept_impl( node->attributes, *this );805 806 VISIT_END( node );807 }808 809 template< typename pass_type >810 void PassVisitor< pass_type >::visit( const AdtDecl * node ) {811 VISIT_START( node );812 813 indexerAddAdtFwd( node );814 815 maybeAccept_impl( node->data_constructors, *this );816 maybeAccept_impl( node->data_union, *this );817 maybeAccept_impl( node->tag, *this );818 819 maybeAccept_impl( node->parameters, *this );820 maybeAccept_impl( node->members , *this );821 maybeAccept_impl( node->attributes, *this );822 823 824 VISIT_END( node );825 }826 827 template< typename pass_type >828 Declaration * PassVisitor< pass_type >::mutate( AdtDecl * node ) {829 MUTATE_START( node );830 831 indexerAddAdtFwd( node );832 833 maybeMutate_impl( node->data_constructors, *this );834 maybeMutate_impl( node->data_union, *this );835 maybeMutate_impl( node->tag, *this );836 837 maybeMutate_impl( node->parameters, *this );838 maybeMutate_impl( node->members , *this );839 maybeMutate_impl( node->attributes, *this );840 841 MUTATE_END( Declaration, node );842 }843 848 844 849 //-------------------------------------------------------------------------- … … 3540 3545 3541 3546 indexerAddStruct( node->name ); 3547 3548 { 3549 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 3550 maybeMutate_impl( node->forall , *this ); 3551 maybeMutate_impl( node->parameters, *this ); 3552 } 3553 3554 MUTATE_END( Type, node ); 3555 } 3556 3557 //-------------------------------------------------------------------------- 3558 // AdtInstType 3559 template< typename pass_type > 3560 void PassVisitor< pass_type >::visit( AdtInstType * node ) { 3561 VISIT_START( node ); 3562 3563 indexerAddAdt( node->name ); 3564 3565 { 3566 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 3567 maybeAccept_impl( node->forall , *this ); 3568 maybeAccept_impl( node->parameters, *this ); 3569 } 3570 3571 VISIT_END( node ); 3572 } 3573 3574 template< typename pass_type > 3575 void PassVisitor< pass_type >::visit( const AdtInstType * node ) { 3576 VISIT_START( node ); 3577 3578 indexerAddAdt( node->name ); 3579 3580 { 3581 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 3582 maybeAccept_impl( node->forall , *this ); 3583 maybeAccept_impl( node->parameters, *this ); 3584 } 3585 3586 VISIT_END( node ); 3587 } 3588 3589 template< typename pass_type > 3590 Type * PassVisitor< pass_type >::mutate( AdtInstType * node ) { 3591 MUTATE_START( node ); 3592 3593 indexerAddAdt( node->name ); 3542 3594 3543 3595 { -
src/Common/PassVisitor.proto.h
r044ae62 rfa2c005 256 256 cloneAll( decl->parameters, fwd->parameters ); 257 257 258 // Experimental259 for ( const StructDecl * ctor : fwd->data_constructors ) {260 indexer_impl_addStructFwd( pass, 0, ctor );261 }262 263 258 pass.indexer.addAdt( fwd ); 264 259 } … … 288 283 289 284 template<typename pass_type> 285 static inline auto indexer_impl_addAdt( pass_type & pass, int, const std::string & str ) -> decltype( pass.indexer.addAdt( str ), void() ) { 286 assert( false ); 287 if ( ! pass.indexer.lookupAdt( str )) { 288 pass.indexer.addAdt( str ); 289 } 290 } 291 292 template<typename pass_type> 293 static inline auto indexer_impl_addAdt( pass_type &, long, const std::string & ) { 294 assert( false ); 295 } 296 297 template<typename pass_type> 290 298 static inline auto indexer_impl_addUnion( pass_type & pass, int, const std::string & str ) -> decltype( pass.indexer.addUnion( str ), void() ) { 291 299 if ( ! pass.indexer.lookupUnion( str ) ) { -
src/GenPoly/Box.cc
r044ae62 rfa2c005 185 185 void premutate( StructDecl * ); 186 186 void premutate( UnionDecl * ); 187 void premutate( AdtDecl * ); 187 188 188 189 void beginScope(); … … 1513 1514 } 1514 1515 1516 void PolyGenericCalculator::premutate( AdtDecl * adtDecl ) { 1517 mutateMembers( adtDecl ); 1518 } 1519 1515 1520 void PolyGenericCalculator::premutate( DeclStmt *declStmt ) { 1516 1521 if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) { -
src/Parser/DeclarationNode.cc
r044ae62 rfa2c005 1104 1104 std::back_insert_iterator<std::vector<ast::ptr<ast::StructDecl>>> out( outputList ); 1105 1105 for ( const DeclarationNode * cur = firstNode; cur; cur = strict_next( cur ) ) { 1106 // td->kind == TypeData::Symbolic 1106 1107 1107 assert( cur->type->kind == TypeData::Symbolic ); 1108 1108 const std::string * name = cur->name; … … 1125 1125 member->name = "field_" + std::to_string(i); 1126 1126 } 1127 1127 1128 *out++ = ctor; 1128 1129 } … … 1130 1131 } 1131 1132 1132 ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::StructDecl>> & typeList ) { 1133 void buildDataConstructorsAsMember( DeclarationNode * firstNode, ast::AdtDecl * adtDecl ) { 1134 std::back_insert_iterator<std::vector<ast::ptr<ast::Decl>>> out( adtDecl->members ); 1135 for ( const DeclarationNode * cur = firstNode; cur; cur = strict_next( cur ) ) { 1136 1137 assert( cur->type->kind == TypeData::Symbolic ); 1138 const std::string * name = cur->name; 1139 auto ctor = new ast::StructDecl( cur->location, 1140 std::string(*name), 1141 ast::AggregateDecl::Aggregate::Struct 1142 ); 1143 ctor->set_body(true); 1144 TypeData * td = cur->type; 1145 TypeData::Symbolic_t st = td->symbolic; 1146 DeclarationNode * params = st.params; 1147 1148 if ( params ) { 1149 buildList( params, ctor->members ); 1150 } 1151 1152 for ( std::size_t i = 0; i < ctor->members.size(); ++i ) { 1153 assert(ctor->members[i]->name == ""); 1154 ast::Decl * member = ctor->members[i].get_and_mutate(); 1155 member->name = "field_" + std::to_string(i); 1156 } 1157 1158 *out++ = ctor; 1159 } 1160 } 1161 1162 ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::Decl>> & typeList ) { 1133 1163 ast::UnionDecl * out = new ast::UnionDecl( loc, "temp_data_union" ); 1134 1164 // size_t index = 0; 1135 1165 if ( typeList.size() > 0 ) out->set_body( true ); 1136 1166 size_t i = 0; 1137 for (const ast::ptr<ast:: StructDecl> structDecl : typeList ) {1138 ast::StructInstType * inst = new ast::StructInstType( structDecl);1167 for (const ast::ptr<ast::Decl> structDecl : typeList ) { 1168 ast::StructInstType * inst = new ast::StructInstType( structDecl.as< ast::StructDecl >() ); 1139 1169 ast::ObjectDecl * instObj = new ast::ObjectDecl( 1140 1170 structDecl->location, … … 1149 1179 } 1150 1180 1151 ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast:: StructDecl>> & typeList ) {1181 ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast::Decl>> & typeList ) { 1152 1182 ast::EnumDecl * out = new ast::EnumDecl( loc, "temp_data_tag" ); 1153 1183 if ( typeList.size() > 0 ) out->set_body( true ); 1154 for ( const ast::ptr<ast:: StructDecl> structDecl : typeList ) {1184 for ( const ast::ptr<ast::Decl> structDecl : typeList ) { 1155 1185 ast::EnumInstType * inst = new ast::EnumInstType( out ); 1156 1186 assert( inst->base != nullptr ); … … 1167 1197 ast::StructDecl * buildTaggedUnions( const TypeData * data, const ast::EnumDecl * tags, const ast::UnionDecl * data_union ) { 1168 1198 assert( tags->members.size() == data_union->members.size() ); 1169 ast::StructDecl * out = new ast::StructDecl( data->location, *(data->adt.name));1199 ast::StructDecl * out = new ast::StructDecl( data->location, (*(data->adt.name)) + "_tag_union" ); 1170 1200 out->kind = ast::AggregateDecl::Adt; 1171 1201 -
src/Parser/DeclarationNode.h
r044ae62 rfa2c005 218 218 219 219 std::vector<ast::ptr<ast::StructDecl>> buildDataConstructors( DeclarationNode * firstNode ); 220 ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::StructDecl>> & typeList ); 221 ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast::StructDecl>> & typeList ); 220 void buildDataConstructorsAsMember( DeclarationNode * firstNode, ast::AdtDecl * adtDecl ); 221 ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::Decl>> & typeList ); 222 ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast::Decl>> & typeList ); 222 223 ast::StructDecl * buildTaggedUnions( const TypeData * data, const ast::EnumDecl * tag, const ast::UnionDecl * data_union ); 223 224 -
src/Parser/TypeData.cc
r044ae62 rfa2c005 81 81 case Symbolic: 82 82 case SymbolicInst: 83 aggregate.kind = ast::AggregateDecl::Aggregate::Undecided; 84 83 85 symbolic.name = nullptr; 84 86 symbolic.params = nullptr; … … 225 227 newtype->enumeration.body = enumeration.body; 226 228 newtype->enumeration.anon = enumeration.anon; 227 newtype->enumeration.data_constructors = maybeClone( enumeration.data_constructors );228 229 break; 229 230 case Adt: 230 newtype->adt.data_constructors = maybeClone( enumeration.data_constructors );231 newtype->adt.data_constructors = maybeClone( adt.data_constructors ); 231 232 newtype->adt.name = new string ( *adt.name ); 232 233 break; … … 1276 1277 ); 1277 1278 buildList( td->enumeration.constants, ret->members ); 1278 if ( td->enumeration.data_constructors != nullptr ) { 1279 assert( false ); 1280 // ret->data_constructors = buildDataConstructors( td->enumeration.data_constructors ); 1281 // ret->data_union = buildDataUnion( td->location, ret->data_constructors ); 1282 // ret->tag = buildTag( td->location, ret->data_constructors ); 1283 // ret->tag_union = buildTaggedUnions( td, ret->tag.get(), ret->data_union.get() ); 1284 } 1285 1286 // if ( ret->data_constructors.size() > 0 ) ret->isData = true; 1279 1287 1280 auto members = ret->members.begin(); 1288 1281 ret->hide = td->enumeration.hiding == EnumHiding::Hide ? ast::EnumDecl::EnumHiding::Hide : ast::EnumDecl::EnumHiding::Visible; … … 1317 1310 assert( td->kind == TypeData::Adt ); 1318 1311 ast::AdtDecl * ret = new ast::AdtDecl( td->location, *(td->adt.name) ); 1319 ret->data_constructors = buildDataConstructors( td->adt.data_constructors ); 1320 ret->data_union = buildDataUnion( td->location, ret->data_constructors ); 1321 ret->tag = buildTag( td->location, ret->data_constructors ); 1312 1313 buildDataConstructorsAsMember( td->adt.data_constructors, ret ); 1314 1315 ret->data_union = buildDataUnion( td->location, ret->members ); 1316 ret->tag = buildTag( td->location, ret->members ); 1322 1317 ret->tag_union = buildTaggedUnions( td, ret->tag.get(), ret->data_union.get() ); 1323 1318 return ret; -
src/Parser/TypeData.h
r044ae62 rfa2c005 25 25 struct TypeData { 26 26 enum Kind { Basic, Pointer, Reference, Array, Function, Aggregate, AggregateInst, Enum, EnumConstant, Symbolic, 27 SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, Adt, Ctor,Unknown };27 SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, Adt, Unknown }; 28 28 29 29 struct Aggregate_t { … … 59 59 EnumHiding hiding; 60 60 bool isData = false; 61 62 DeclarationNode * data_constructors = nullptr;63 61 }; 64 62 -
src/SymTab/Validate.cc
r044ae62 rfa2c005 210 210 void previsit( StructDecl * aggregateDecl ); 211 211 void previsit( UnionDecl * aggregateDecl ); 212 void previsit( AdtDecl * AggregateDecl ); 212 213 void previsit( CompoundStmt * compoundStmt ); 213 214 }; … … 569 570 570 571 void EliminateTypedef::previsit( UnionDecl * aggregateDecl ) { 572 handleAggregate( aggregateDecl ); 573 } 574 575 void EliminateTypedef::previsit( AdtDecl * aggregateDecl ) { 571 576 handleAggregate( aggregateDecl ); 572 577 } -
src/SynTree/Declaration.h
r044ae62 rfa2c005 365 365 typedef AggregateDecl Parent; 366 366 public: 367 std::list<StructDecl*> data_constructors;368 367 UnionDecl * data_union; 369 368 EnumDecl * tag; … … 373 372 const std::list< Attribute * > & attributes = std::list< class Attribute * >(), 374 373 LinkageSpec::Spec linkage = LinkageSpec::Cforall, 375 const std::list< StructDecl* > data_constructors = std::list< StructDecl * >(),376 374 UnionDecl * data_union = nullptr, EnumDecl * tag = nullptr, StructDecl * tag_union = nullptr ) 377 : Parent( name, attributes, linkage ), data_constructors(data_constructors),375 : Parent( name, attributes, linkage ), 378 376 data_union( data_union ), tag( tag ), tag_union( tag_union ) {} 379 377 -
src/SynTree/Mutator.h
r044ae62 rfa2c005 110 110 virtual Type * mutate( FunctionType * functionType ) = 0; 111 111 virtual Type * mutate( StructInstType * aggregateUseType ) = 0; 112 virtual Type * mutate( AdtInstType * aggregateUseType ) = 0; 112 113 virtual Type * mutate( UnionInstType * aggregateUseType ) = 0; 113 114 virtual Type * mutate( EnumInstType * aggregateUseType ) = 0; -
src/SynTree/SynTree.h
r044ae62 rfa2c005 119 119 class UnionInstType; 120 120 class EnumInstType; 121 class AdtInstType; 121 122 class TraitInstType; 122 123 class TypeInstType; -
src/SynTree/Type.h
r044ae62 rfa2c005 476 476 }; 477 477 478 class AdtInstType : public ReferenceToType { 479 typedef ReferenceToType Parent; 480 public: 481 AdtDecl * baseAdt; 482 483 AdtInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseAdt( 0 ) {} 484 AdtInstType( const Type::Qualifiers & tq, AdtDecl * baseAdt, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 485 AdtInstType( const AdtInstType & other ) : Parent( other ), baseAdt( other.baseAdt ) {} 486 487 AdtDecl * get_baseAdt() const { return baseAdt; } 488 void set_baseAdt( AdtDecl * newValue ) { baseAdt = newValue; } 489 490 std::list<TypeDecl*> * get_baseParameters(); 491 const std::list<TypeDecl*> * get_baseParameters() const; 492 493 virtual bool isComplete() const override; 494 495 virtual AggregateDecl * getAggr() const override; 496 497 virtual TypeSubstitution genericSubstitution() const override; 498 499 void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const override; 500 501 virtual AdtInstType * clone() const override { return new AdtInstType( * this ); } 502 virtual void accept( Visitor & v ) override { v.visit( this ); } 503 virtual void accept( Visitor & v ) const override { v.visit( this ); } 504 virtual Type * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 505 506 virtual void print( std::ostream & os, Indenter indenter = {} ) const override; 507 private: 508 virtual std::string typeString() const override; 509 }; 510 478 511 class UnionInstType : public ReferenceToType { 479 512 typedef ReferenceToType Parent; -
src/SynTree/Visitor.h
r044ae62 rfa2c005 196 196 virtual void visit( UnionInstType * node ) { visit( const_cast<const UnionInstType *>(node) ); } 197 197 virtual void visit( const UnionInstType * aggregateUseType ) = 0; 198 virtual void visit( AdtInstType * node ) { visit( const_cast<const AdtInstType *>(node) ); } 199 virtual void visit( const AdtInstType * node ) = 0; 198 200 virtual void visit( EnumInstType * node ) { visit( const_cast<const EnumInstType *>(node) ); } 199 201 virtual void visit( const EnumInstType * aggregateUseType ) = 0; -
src/Validate/EliminateTypedef.cpp
r044ae62 rfa2c005 31 31 ast::StructDecl const * previsit( ast::StructDecl const * decl ); 32 32 ast::UnionDecl const * previsit( ast::UnionDecl const * decl ); 33 ast::AdtDecl const * previsit( ast::AdtDecl const * decl ); 33 34 // Remove typedefs from statement lists. 34 35 ast::CompoundStmt const * previsit( ast::CompoundStmt const * stmt ); … … 65 66 } 66 67 68 ast::AdtDecl const * EliminateTypedefCore::previsit( ast::AdtDecl const * decl ) { 69 return field_erase_if( decl, &ast::AdtDecl::members, isTypedef ); 70 } 71 67 72 ast::CompoundStmt const * EliminateTypedefCore::previsit( ast::CompoundStmt const * stmt ) { 68 73 return field_erase_if( stmt, &ast::CompoundStmt::kids, isTypedefStmt ); -
src/Validate/FixQualifiedTypes.cpp
r044ae62 rfa2c005 59 59 instp = inst; 60 60 } else if ( auto inst = parent.as<ast::UnionInstType>() ) { 61 aggr = inst->base; 62 instp = inst; 63 } else if ( auto inst = parent.as<ast::AdtInstType>() ) { 61 64 aggr = inst->base; 62 65 instp = inst; -
src/Validate/HoistStruct.cpp
r044ae62 rfa2c005 28 28 return dynamic_cast< ast::StructDecl const * >( decl ) 29 29 || dynamic_cast< ast::UnionDecl const * >( decl ) 30 || dynamic_cast< ast::StaticAssertDecl const * >( decl ); 30 || dynamic_cast< ast::StaticAssertDecl const * >( decl ) 31 || dynamic_cast< ast::AdtDecl const * >( decl ); 31 32 } 32 33 … … 45 46 ast::UnionInstType const * previsit( ast::UnionInstType const * type ); 46 47 ast::EnumInstType const * previsit( ast::EnumInstType const * type ); 48 ast::AdtDecl const * previsit( ast::AdtDecl const * decl ); 49 ast::AdtDecl const * postvisit( ast::AdtDecl const * decl ); 47 50 48 51 private: … … 100 103 } 101 104 105 ast::AdtDecl const * HoistStructCore::previsit( ast::AdtDecl const * decl ) { 106 return preAggregate( decl ); 107 } 108 109 ast::AdtDecl const * HoistStructCore::postvisit( ast::AdtDecl const * decl ) { 110 return postAggregate( decl ); 111 } 112 102 113 ast::StructDecl const * HoistStructCore::postvisit( ast::StructDecl const * decl ) { 103 114 return postAggregate( decl ); … … 138 149 } 139 150 140 void hoistAdt( [[maybe_unused]] ast::TranslationUnit & trnaslationUnit ) {141 142 }143 144 151 } // namespace Validate 145 152 -
src/Validate/HoistStruct.hpp
r044ae62 rfa2c005 24 24 /// Flattens nested type declarations. (Run right after Fix Qualified Types.) 25 25 void hoistStruct( ast::TranslationUnit & translationUnit ); 26 void hoistAdt( ast::TranslationUnit & trnaslationUnit );27 26 28 27 } -
src/Validate/LinkReferenceToTypes.cpp
r044ae62 rfa2c005 20 20 #include "Validate/ForallPointerDecay.hpp" 21 21 #include "Validate/NoIdSymbolTable.hpp" 22 #include <assert.h> 22 23 23 24 namespace Validate { … … 35 36 ast::UnionInstType const * postvisit( ast::UnionInstType const * type ); 36 37 ast::TraitInstType const * postvisit( ast::TraitInstType const * type ); 38 ast::AdtInstType const * postvisit( ast::AdtInstType const * type ); 37 39 void previsit( ast::QualifiedType const * type ); 38 40 void postvisit( ast::QualifiedType const * type ); … … 107 109 auto mut = ast::mutate( type ); 108 110 forwardStructs[ mut->name ].push_back( mut ); 111 type = mut; 112 } 113 return type; 114 } 115 116 ast::AdtInstType const * LinkTypesCore::postvisit( ast::AdtInstType const * type ) { 117 ast::AdtDecl const * decl = symtab.lookupAdt( type->name ); 118 assert( decl != nullptr ); 119 if ( decl ) { 120 auto mut = ast::mutate( type ); 121 mut->base = const_cast<ast::AdtDecl *>( decl ); 109 122 type = mut; 110 123 } -
src/Validate/NoIdSymbolTable.hpp
r044ae62 rfa2c005 41 41 FORWARD_1( lookupUnion , const std::string & ) 42 42 FORWARD_1( lookupTrait , const std::string & ) 43 FORWARD_1( lookupAdt , const std::string & ) 43 44 FORWARD_1( addType , const ast::NamedTypeDecl * ) 44 45 FORWARD_1( addStruct, const ast::StructDecl * ) … … 49 50 FORWARD_1( addStruct, const std::string & ) 50 51 FORWARD_1( addUnion , const std::string & ) 52 FORWARD_1( addAdt , const std::string & ) 51 53 FORWARD_2( addWith , const std::vector< ast::ptr<ast::Expr> > &, const ast::Decl * ) 52 54 -
src/Validate/ReplaceTypedef.cpp
r044ae62 rfa2c005 60 60 ast::StructDecl const * previsit( ast::StructDecl const * ); 61 61 ast::UnionDecl const * previsit( ast::UnionDecl const * ); 62 ast::AdtDecl const * previsit( ast::AdtDecl const * ); 62 63 void previsit( ast::EnumDecl const * ); 63 64 void previsit( ast::TraitDecl const * ); … … 90 91 } 91 92 93 // Here, 5/30 92 94 ast::Type const * ReplaceTypedefCore::postvisit( 93 95 ast::TypeInstType const * type ) { 94 96 // Instances of typedef types will come here. If it is an instance 95 97 // of a typedef type, link the instance to its actual type. 96 TypedefMap::const_iterator def = typedefNames.find( type->name ); 98 TypedefMap::const_iterator def = typedefNames.find( type->name ); // because of this 97 99 if ( def != typedefNames.end() ) { 98 100 ast::Type * ret = ast::deepCopy( def->second.first->base ); … … 260 262 } 261 263 264 ast::AdtDecl const * ReplaceTypedefCore::previsit( ast::AdtDecl const * decl ) { 265 visit_children = false; 266 addImplicitTypedef( decl ); 267 return handleAggregate( decl ); 268 } 269 262 270 ast::UnionDecl const * ReplaceTypedefCore::previsit( ast::UnionDecl const * decl ) { 263 271 visit_children = false; … … 287 295 } else if ( auto enumDecl = dynamic_cast<const ast::EnumDecl *>( aggrDecl ) ) { 288 296 type = new ast::EnumInstType( enumDecl->name ); 297 } else if ( auto adtDecl = dynamic_cast<const ast::AdtDecl *>( aggrDecl )) { 298 type = new ast::AdtInstType( adtDecl->name ); 289 299 } 290 300 assert( type );
Note: See TracChangeset
for help on using the changeset viewer.