- Timestamp:
- May 17, 2023, 1:33:39 AM (3 years ago)
- Branches:
- ADT
- Children:
- d6c464d
- Parents:
- 28f8f15
- Location:
- src/AST
- Files:
-
- 12 edited
-
Convert.cpp (modified) (3 diffs)
-
Decl.cpp (modified) (1 diff)
-
Decl.hpp (modified) (5 diffs)
-
Fwd.hpp (modified) (1 diff)
-
Node.cpp (modified) (1 diff)
-
Pass.hpp (modified) (1 diff)
-
Pass.impl.hpp (modified) (2 diffs)
-
Pass.proto.hpp (modified) (1 diff)
-
Print.cpp (modified) (1 diff)
-
SymbolTable.cpp (modified) (1 diff)
-
SymbolTable.hpp (modified) (3 diffs)
-
Visitor.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r28f8f15 r561354f 283 283 decl->parent = get<AggregateDecl>().accept1( node->parent ); 284 284 declPostamble( decl, node ); 285 return nullptr; // ??285 return nullptr; 286 286 } 287 287 … … 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->tags = get<EnumDecl>().accept1( node->tag ); 326 decl->tag_union = get<StructDecl>().accept1( node->tag_union ); 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 return aggregatePostamble( decl, node ); 328 } 329 330 const ast::Decl * visit( const ast::AdtDecl * node ) override final { 331 if ( inCache(node) ) return nullptr; 332 auto decl = new AdtDecl( 333 node->name, 334 get<Attribute>().acceptL( node->attributes ), 335 LinkageSpec::Spec( node->linkage.val ), 336 get<StructDecl>().acceptL( node->data_constructors ), 337 get<UnionDecl>().accept1( node->data_union ), 338 get<EnumDecl>().accept1( node->tag ), 339 get<StructDecl>().accept1( node->tag_union ) 340 ); 327 341 return aggregatePostamble( decl, node ); 328 342 } … … 1782 1796 } 1783 1797 1798 virtual void visit( const AdtDecl * old ) override final { 1799 if ( inCache( old ) ) return; 1800 auto decl = new ast::AdtDecl( 1801 old->location, 1802 old->name, 1803 GET_ACCEPT_V(attributes, Attribute), 1804 { old->linkage.val } 1805 ); 1806 cache.emplace( old, decl ); 1807 decl->parent = GET_ACCEPT_1(parent, AggregateDecl); 1808 decl->body = old->body; 1809 decl->params = GET_ACCEPT_V(parameters, TypeDecl); 1810 decl->members = GET_ACCEPT_V(members, Decl); 1811 decl->extension = old->extension; 1812 decl->uniqueId = old->uniqueId; 1813 decl->storage = { old->storageClasses.val }; 1814 decl->data_constructors = GET_ACCEPT_V( data_constructors, StructDecl ); 1815 decl->data_union = GET_ACCEPT_1( data_union, UnionDecl ); 1816 decl->tag = GET_ACCEPT_1( tag, EnumDecl ); 1817 decl->tag_union = GET_ACCEPT_1( tag_union, StructDecl ); 1818 this->node = decl; 1819 } 1820 1784 1821 virtual void visit( const TraitDecl * old ) override final { 1785 1822 if ( inCache( old ) ) return; -
src/AST/Decl.cpp
r28f8f15 r561354f 132 132 133 133 // These must harmonize with the corresponding AggregateDecl::Aggregate enumerations. 134 static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName", " data" };134 static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName", "adt" }; 135 135 136 136 const char * AggregateDecl::aggrString( AggregateDecl::Aggregate aggr ) { -
src/AST/Decl.hpp
r28f8f15 r561354f 248 248 class AggregateDecl : public Decl { 249 249 public: 250 enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate, A DT};250 enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate, Adt }; 251 251 static const char * aggrString( Aggregate aggr ); 252 252 … … 286 286 bool is_monitor () const { return kind == Monitor ; } 287 287 bool is_thread () const { return kind == Thread ; } 288 bool is_adt () const { return kind == A DT; }288 bool is_adt () const { return kind == Adt ; } 289 289 290 290 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } … … 320 320 ptr<Type> base; // if isTyped == true && base.get() == nullptr, it is a "void" type enum 321 321 enum class EnumHiding { Visible, Hide } hide; 322 323 std::vector<ptr<StructDecl>> data_constructors;324 bool isData = false;325 ptr<UnionDecl> data_union;326 ptr<EnumDecl> tag;327 ptr<StructDecl> tag_union;328 322 329 323 EnumDecl( const CodeLocation& loc, const std::string& name, bool isTyped = false, … … 350 344 }; 351 345 346 class AdtDecl final : public AggregateDecl { 347 public: 348 std::vector<ptr<StructDecl>> data_constructors; // Todo: members? 349 ptr<UnionDecl> data_union; 350 ptr<EnumDecl> tag; 351 ptr<StructDecl> tag_union; 352 353 AdtDecl( const CodeLocation& loc, const std::string& name, 354 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall ) 355 : AggregateDecl( loc, name, std::move(attrs), linkage ) {} 356 357 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 358 359 const char * typeString() const override { return aggrString( Adt ); } 360 361 private: 362 AdtDecl * clone() const override { return new AdtDecl{ *this }; } 363 MUTATE_FRIEND 364 }; 365 352 366 /// trait declaration `trait Foo( ... ) { ... };` 353 367 class TraitDecl final : public AggregateDecl { … … 358 372 359 373 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 360 361 374 const char * typeString() const override { return "trait"; } 362 375 -
src/AST/Fwd.hpp
r28f8f15 r561354f 32 32 class UnionDecl; 33 33 class EnumDecl; 34 class AdtDecl; 34 35 class TraitDecl; 35 36 class NamedTypeDecl; -
src/AST/Node.cpp
r28f8f15 r561354f 128 128 template class ast::ptr_base< ast::EnumDecl, ast::Node::ref_type::weak >; 129 129 template class ast::ptr_base< ast::EnumDecl, ast::Node::ref_type::strong >; 130 template class ast::ptr_base< ast::AdtDecl, ast::Node::ref_type::weak >; 131 template class ast::ptr_base< ast::AdtDecl, ast::Node::ref_type::strong >; 130 132 template class ast::ptr_base< ast::TraitDecl, ast::Node::ref_type::weak >; 131 133 template class ast::ptr_base< ast::TraitDecl, ast::Node::ref_type::strong >; -
src/AST/Pass.hpp
r28f8f15 r561354f 139 139 const ast::Decl * visit( const ast::UnionDecl * ) override final; 140 140 const ast::Decl * visit( const ast::EnumDecl * ) override final; 141 const ast::Decl * visit( const ast::AdtDecl * ) override final; 141 142 const ast::Decl * visit( const ast::TraitDecl * ) override final; 142 143 const ast::Decl * visit( const ast::TypeDecl * ) override final; -
src/AST/Pass.impl.hpp
r28f8f15 r561354f 693 693 maybe_accept( node, &EnumDecl::members ); 694 694 maybe_accept( node, &EnumDecl::attributes ); 695 maybe_accept( node, &EnumDecl::data_constructors ); 696 maybe_accept( node, &EnumDecl::data_union ); 697 maybe_accept( node, &EnumDecl::tag ); 698 maybe_accept( node, &EnumDecl::tag_union ); 695 696 // maybe_accept( node, &EnumDecl::data_constructors ); 697 // maybe_accept( node, &EnumDecl::data_union ); 698 // maybe_accept( node, &EnumDecl::tag ); 699 // maybe_accept( node, &EnumDecl::tag_union ); 699 700 } else { 700 701 maybe_accept( node, &EnumDecl::base ); … … 702 703 maybe_accept( node, &EnumDecl::members ); 703 704 maybe_accept( node, &EnumDecl::attributes ); 704 maybe_accept( node, &EnumDecl::data_constructors ); 705 maybe_accept( node, &EnumDecl::data_union ); 706 maybe_accept( node, &EnumDecl::tag ); 707 maybe_accept( node, &EnumDecl::tag_union ); 708 } 705 706 // maybe_accept( node, &EnumDecl::data_constructors ); 707 // maybe_accept( node, &EnumDecl::data_union ); 708 // maybe_accept( node, &EnumDecl::tag ); 709 // maybe_accept( node, &EnumDecl::tag_union ); 710 } 711 } 712 713 VISIT_END( Decl, node ); 714 } 715 716 template< typename core_t > 717 const ast::Decl * ast::Pass< core_t >::visit( const ast::AdtDecl * node ) { 718 VISIT_START( node ); 719 720 __pass::symtab::addAdt( core, 0, node ); 721 722 if ( __visit_children() ) { 723 guard_symtab guard { *this }; 724 maybe_accept( node, &AdtDecl::params ); 725 maybe_accept( node, &AdtDecl::members ); 726 maybe_accept( node, &AdtDecl::attributes ); 727 728 maybe_accept( node, &AdtDecl::data_constructors ); 729 maybe_accept( node, &AdtDecl::data_union ); 730 maybe_accept( node, &AdtDecl::tag ); 731 maybe_accept( node, &AdtDecl::tag_union ); 709 732 } 710 733 -
src/AST/Pass.proto.hpp
r28f8f15 r561354f 399 399 SYMTAB_FUNC1( addStruct , const StructDecl * ); 400 400 SYMTAB_FUNC1( addEnum , const EnumDecl * ); 401 SYMTAB_FUNC1( addAdt , const AdtDecl * ); 401 402 SYMTAB_FUNC1( addUnion , const UnionDecl * ); 402 403 SYMTAB_FUNC1( addTrait , const TraitDecl * ); -
src/AST/Print.cpp
r28f8f15 r561354f 407 407 408 408 virtual const ast::Decl * visit( const ast::EnumDecl * node ) override final { 409 print(node); 410 return node; 411 } 412 413 virtual const ast::Decl * visit( const ast::AdtDecl * node ) override final { 409 414 print(node); 410 415 return node; -
src/AST/SymbolTable.cpp
r28f8f15 r561354f 358 358 } 359 359 360 void SymbolTable::addAdt( const AdtDecl *decl ) { 361 ++*stats().add_calls; 362 const std::string &id = decl->name; 363 364 if ( ! adtTable ) { 365 adtTable = AdtTable::new_ptr(); 366 } else { 367 ++*stats().map_lookups; 368 auto existing = adtTable->find( id ); 369 if ( existing != adtTable->end() 370 && existing->second.scope == scope 371 && addedDeclConflicts( existing->second.decl, decl ) ) return; 372 373 } 374 375 lazyInitScope(); 376 ++*stats().map_mutations; 377 adtTable = adtTable->set( id, scoped<AdtDecl>{ decl, scope }); 378 } 379 360 380 void SymbolTable::addUnion( const std::string &id ) { 361 381 addUnion( new UnionDecl( CodeLocation(), id ) ); -
src/AST/SymbolTable.hpp
r28f8f15 r561354f 72 72 using StructTable = PersistentMap< std::string, scoped<StructDecl> >; 73 73 using EnumTable = PersistentMap< std::string, scoped<EnumDecl> >; 74 using AdtTable = PersistentMap< std::string, scoped<AdtDecl> >; 74 75 using UnionTable = PersistentMap< std::string, scoped<UnionDecl> >; 75 76 using TraitTable = PersistentMap< std::string, scoped<TraitDecl> >; … … 80 81 EnumTable::Ptr enumTable; ///< enum namespace 81 82 UnionTable::Ptr unionTable; ///< union namespace 83 AdtTable::Ptr adtTable; ///< adt namespace 82 84 TraitTable::Ptr traitTable; ///< trait namespace 83 85 IdTable::Ptr specialFunctionTable[NUMBER_OF_KINDS]; … … 138 140 /// Adds an enum declaration to the symbol table 139 141 void addEnum( const EnumDecl * decl ); 142 /// Adds an adt declaration to the symbol table 143 void addAdt( const AdtDecl * decl ); 140 144 /// Adds a union declaration to the symbol table by name 141 145 void addUnion( const std::string & id ); -
src/AST/Visitor.hpp
r28f8f15 r561354f 27 27 virtual const ast::Decl * visit( const ast::UnionDecl * ) = 0; 28 28 virtual const ast::Decl * visit( const ast::EnumDecl * ) = 0; 29 virtual const ast::Decl * visit( const ast::AdtDecl * ) = 0; 29 30 virtual const ast::Decl * visit( const ast::TraitDecl * ) = 0; 30 31 virtual const ast::Decl * visit( const ast::TypeDecl * ) = 0;
Note:
See TracChangeset
for help on using the changeset viewer.