- Timestamp:
- Jun 8, 2023, 3:19:43 PM (2 years ago)
- Branches:
- ADT
- Parents:
- 044ae62
- Location:
- src/AST
- Files:
-
- 11 edited
-
Convert.cpp (modified) (5 diffs)
-
Decl.hpp (modified) (2 diffs)
-
Fwd.hpp (modified) (1 diff)
-
Pass.hpp (modified) (1 diff)
-
Pass.impl.hpp (modified) (4 diffs)
-
Pass.proto.hpp (modified) (3 diffs)
-
Print.cpp (modified) (1 diff)
-
SymbolTable.cpp (modified) (3 diffs)
-
SymbolTable.hpp (modified) (2 diffs)
-
Type.cpp (modified) (1 diff)
-
Visitor.hpp (modified) (1 diff)
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;
Note:
See TracChangeset
for help on using the changeset viewer.