Changeset 561354f
- Timestamp:
- May 17, 2023, 1:33:39 AM (12 months ago)
- Branches:
- ADT
- Children:
- d6c464d
- Parents:
- 28f8f15
- Location:
- src
- Files:
-
- 30 edited
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; -
src/CodeGen/CodeGenerator.cc
r28f8f15 r561354f 296 296 297 297 void CodeGenerator::handleData( EnumDecl * dataDecl ) { 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->tags ); 306 output << ";" << endl; 307 postvisit( dataDecl->tag_union ); 308 output << ";" << endl; 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 assert(false); 309 310 } 310 311 311 312 void CodeGenerator::postvisit( EnumDecl * enumDecl ) { 312 if ( enumDecl->data_constructors.size() > 0 ) return handleData( enumDecl );313 // if ( enumDecl->data_constructors.size() > 0 ) return handleData( enumDecl ); 313 314 extension( enumDecl ); 314 315 std::list< Declaration* > &memb = enumDecl->get_members(); -
src/Common/CodeLocationTools.cpp
r28f8f15 r561354f 105 105 macro(UnionDecl, Decl) \ 106 106 macro(EnumDecl, Decl) \ 107 macro(AdtDecl, Decl) \ 107 108 macro(TraitDecl, Decl) \ 108 109 macro(TypeDecl, Decl) \ -
src/Common/PassVisitor.h
r28f8f15 r561354f 69 69 virtual void visit( EnumDecl * aggregateDecl ) override final; 70 70 virtual void visit( const EnumDecl * aggregateDecl ) override final; 71 virtual void visit( AdtDecl * aggregateDecl ) override final; 72 virtual void visit( const AdtDecl * AggregateDecl ) override final; 71 73 virtual void visit( TraitDecl * aggregateDecl ) override final; 72 74 virtual void visit( const TraitDecl * aggregateDecl ) override final; … … 269 271 virtual Declaration * mutate( UnionDecl * aggregateDecl ) override final; 270 272 virtual Declaration * mutate( EnumDecl * aggregateDecl ) override final; 273 virtual Declaration * mutate( AdtDecl * aggregateDecl ) override final; 271 274 virtual Declaration * mutate( TraitDecl * aggregateDecl ) override final; 272 275 virtual Declaration * mutate( TypeDecl * typeDecl ) override final; … … 439 442 void indexerAddStructFwd( const StructDecl * node ) { indexer_impl_addStructFwd( pass, 0, node ); } 440 443 void indexerAddEnum ( const EnumDecl * node ) { indexer_impl_addEnum ( pass, 0, node ); } 444 void indexerAddAdt ( const AdtDecl * node ) { indexer_impl_addAdt ( pass, 0, node ); } 441 445 void indexerAddUnion ( const std::string & id ) { indexer_impl_addUnion ( pass, 0, id ); } 442 446 void indexerAddUnion ( const UnionDecl * node ) { indexer_impl_addUnion ( pass, 0, node ); } -
src/Common/PassVisitor.impl.h
r28f8f15 r561354f 754 754 755 755 // unlike structs, traits, and unions, enums inject their members into the global scope 756 maybeAccept_impl( node->data_constructors, *this );757 maybeAccept_impl( node->data_union, *this );758 maybeAccept_impl( node->tags, *this );759 756 maybeAccept_impl( node->parameters, *this ); 760 757 maybeAccept_impl( node->members , *this ); … … 785 782 786 783 // unlike structs, traits, and unions, enums inject their members into the global scope 784 maybeMutate_impl( node->parameters, *this ); 785 maybeMutate_impl( node->members , *this ); 786 maybeMutate_impl( node->attributes, *this ); 787 788 MUTATE_END( Declaration, node ); 789 } 790 791 template< typename pass_type > 792 void PassVisitor< pass_type >::visit( AdtDecl * node ) { 793 VISIT_START( node ); 794 795 indexerAddAdt( node ); 796 797 // unlike structs, traits, and unions, enums inject their members into the global scope 798 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 maybeAccept_impl( node->data_constructors, *this ); 814 maybeAccept_impl( node->data_union, *this ); 815 maybeAccept_impl( node->tag, *this ); 816 817 maybeAccept_impl( node->parameters, *this ); 818 maybeAccept_impl( node->members , *this ); 819 maybeAccept_impl( node->attributes, *this ); 820 821 822 VISIT_END( node ); 823 } 824 825 template< typename pass_type > 826 Declaration * PassVisitor< pass_type >::mutate( AdtDecl * node ) { 827 MUTATE_START( node ); 828 829 maybeMutate_impl( node->data_constructors, *this ); 830 maybeMutate_impl( node->data_union, *this ); 831 maybeMutate_impl( node->tag, *this ); 832 787 833 maybeMutate_impl( node->parameters, *this ); 788 834 maybeMutate_impl( node->members , *this ); -
src/Common/PassVisitor.proto.h
r28f8f15 r561354f 233 233 INDEXER_FUNC1( addStruct , const StructDecl * ); 234 234 INDEXER_FUNC1( addEnum , const EnumDecl * ); 235 INDEXER_FUNC1( addAdt , const AdtDecl * ); 235 236 INDEXER_FUNC1( addUnion , const UnionDecl * ); 236 237 INDEXER_FUNC1( addTrait , const TraitDecl * ); -
src/Parser/DeclarationNode.cc
r28f8f15 r561354f 279 279 } // DeclarationNode::newEnum 280 280 281 DeclarationNode * DeclarationNode::newADT( const string * name, DeclarationNode * constructors ) { 282 DeclarationNode * newnode = newEnum( name, nullptr, true, false ); 283 newnode->type->enumeration.isData = true; 284 newnode->type->enumeration.data_constructors = constructors; 285 return newnode; 286 } 281 DeclarationNode * DeclarationNode::newAdt( const string * name, DeclarationNode * constructors ) { 282 assert( name ); 283 DeclarationNode * newnode = new DeclarationNode; 284 newnode->type = new TypeData( TypeData::Adt ); 285 newnode->type->adt.name = name; 286 newnode->type->adt.data_constructors = constructors; 287 return newnode; 288 } // DeclarationNode::newAdt 287 289 288 290 … … 1098 1100 } 1099 1101 1100 void buildDataConstructors( DeclarationNode * firstNode, std::vector<ast::ptr<ast::StructDecl>> & outputList ) { 1102 std::vector<ast::ptr<ast::StructDecl>> buildDataConstructors( DeclarationNode * firstNode ) { 1103 std::vector<ast::ptr<ast::StructDecl>> outputList; 1101 1104 std::back_insert_iterator<std::vector<ast::ptr<ast::StructDecl>>> out( outputList ); 1102 1105 for ( const DeclarationNode * cur = firstNode; cur; cur = strict_next( cur ) ) { … … 1124 1127 *out++ = ctor; 1125 1128 } 1126 } 1127 1128 ast::UnionDecl * buildDataUnion( ast::EnumDecl * data, const std::vector<ast::ptr<ast::StructDecl>> & typeList ) { 1129 ast::UnionDecl * out = new ast::UnionDecl( data->location, "temp_data_union" ); 1129 return outputList; 1130 } 1131 1132 ast::UnionDecl * buildDataUnion( const CodeLocation & loc, const std::vector<ast::ptr<ast::StructDecl>> & typeList ) { 1133 ast::UnionDecl * out = new ast::UnionDecl( loc, "temp_data_union" ); 1130 1134 // size_t index = 0; 1131 1135 if ( typeList.size() > 0 ) out->set_body( true ); … … 1145 1149 } 1146 1150 1147 ast::EnumDecl * buildTag( ast::EnumDecl * data, conststd::vector<ast::ptr<ast::StructDecl>> & typeList ) {1148 ast::EnumDecl * out = new ast::EnumDecl( data->location, "temp_data_tag" );1151 ast::EnumDecl * buildTag( const CodeLocation & loc, std::vector<ast::ptr<ast::StructDecl>> & typeList ) { 1152 ast::EnumDecl * out = new ast::EnumDecl( loc, "temp_data_tag" ); 1149 1153 if ( typeList.size() > 0 ) out->set_body( true ); 1150 1154 for ( const ast::ptr<ast::StructDecl> structDecl : typeList ) { … … 1161 1165 } 1162 1166 1163 ast::StructDecl * buildTaggedUnions( const ast::EnumDecl* data, const ast::EnumDecl * tags, const ast::UnionDecl * data_union ) {1167 ast::StructDecl * buildTaggedUnions( const TypeData * data, const ast::EnumDecl * tags, const ast::UnionDecl * data_union ) { 1164 1168 assert( tags->members.size() == data_union->members.size() ); 1165 ast::StructDecl * out = new ast::StructDecl( data->location, data->name);1166 out->kind = ast::AggregateDecl::A DT;1169 ast::StructDecl * out = new ast::StructDecl( data->location, *(data->adt.name) ); 1170 out->kind = ast::AggregateDecl::Adt; 1167 1171 1168 1172 out->set_body( true ); -
src/Parser/DeclarationNode.h
r28f8f15 r561354f 77 77 78 78 // Experimental algebric data type 79 static DeclarationNode * newA DT( const std::string * name, DeclarationNode * constructors );79 static DeclarationNode * newAdt( const std::string * name, DeclarationNode * constructors ); 80 80 static DeclarationNode * newDataConstructor( const std::string * name ); 81 81 // static DeclarationNode * newDataConstructor( const std::string * name, DeclarationNode * typeSpecifiers ); … … 216 216 void buildList( DeclarationNode * firstNode, std::vector<ast::ptr<ast::DeclWithType>> & outputList ); 217 217 void buildTypeList( const DeclarationNode * firstNode, std::vector<ast::ptr<ast::Type>> & outputList ); 218 void buildDataConstructors( DeclarationNode * firstNode, std::vector<ast::ptr<ast::StructDecl>> & outputList ); 219 ast::UnionDecl * buildDataUnion( ast::EnumDecl * data, const std::vector<ast::ptr<ast::StructDecl>> & typeList ); 220 ast::EnumDecl * buildTag( ast::EnumDecl * data, const std::vector<ast::ptr<ast::StructDecl>> & typeList ); 221 ast::StructDecl * buildTaggedUnions( const ast::EnumDecl * data, const ast::EnumDecl * tags, const ast::UnionDecl * data_union ); 218 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 ); 222 ast::StructDecl * buildTaggedUnions( const TypeData * data, const ast::EnumDecl * tag, const ast::UnionDecl * data_union ); 222 223 223 224 template<typename AstType, typename NodeType, -
src/Parser/TypeData.cc
r28f8f15 r561354f 59 59 enumeration.anon = false; 60 60 break; 61 case Adt: 62 adt.name = nullptr; 63 adt.data_constructors = nullptr; 64 break; 61 65 case Aggregate: 62 66 aggregate.kind = ast::AggregateDecl::NoAggregate; … … 160 164 delete qualified.child; 161 165 break; 166 case Adt: 167 delete adt.data_constructors; 168 delete adt.name; 169 break; 162 170 } // switch 163 171 } // TypeData::~TypeData … … 217 225 newtype->enumeration.body = enumeration.body; 218 226 newtype->enumeration.anon = enumeration.anon; 227 newtype->enumeration.data_constructors = maybeClone( enumeration.data_constructors ); 228 break; 229 case Adt: 230 newtype->adt.data_constructors = maybeClone( enumeration.data_constructors ); 231 newtype->adt.name = new string ( *adt.name ); 219 232 break; 220 233 case Symbolic: … … 459 472 case Enum: 460 473 return enumeration.name; 474 case Adt: 475 return adt.name; 461 476 case Symbolic: 462 477 case SymbolicInst: … … 822 837 case TypeData::Symbolic: 823 838 case TypeData::Enum: 839 case TypeData::Adt: 824 840 case TypeData::Aggregate: 825 841 assert( false ); … … 1261 1277 buildList( td->enumeration.constants, ret->members ); 1262 1278 if ( td->enumeration.data_constructors != nullptr ) { 1263 buildDataConstructors( td->enumeration.data_constructors, ret->data_constructors ); 1264 ret->data_union = buildDataUnion( ret, ret->data_constructors ); 1265 ret->tag = buildTag( ret, ret->data_constructors ); 1266 ret->tag_union = buildTaggedUnions( ret, ret->tag.get(), ret->data_union.get() ); 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() ); 1267 1284 } 1268 1285 1269 if ( ret->data_constructors.size() > 0 ) ret->isData = true;1286 // if ( ret->data_constructors.size() > 0 ) ret->isData = true; 1270 1287 auto members = ret->members.begin(); 1271 1288 ret->hide = td->enumeration.hiding == EnumHiding::Hide ? ast::EnumDecl::EnumHiding::Hide : ast::EnumDecl::EnumHiding::Visible; … … 1294 1311 return ret; 1295 1312 } // buildEnum 1313 1314 ast::AdtDecl * buildAdt(const TypeData * td, 1315 std::vector<ast::ptr<ast::Attribute>> && attributes, 1316 ast::Linkage::Spec linkage ) { 1317 assert( td->kind == TypeData::Adt ); 1318 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 ); 1322 ret->tag_union = buildTaggedUnions( td, ret->tag.get(), ret->data_union.get() ); 1323 return ret; 1324 } 1296 1325 1297 1326 … … 1437 1466 } else if ( td->kind == TypeData::Enum ) { 1438 1467 return buildEnum( td, std::move( attributes ), linkage ); 1468 } else if ( td->kind == TypeData::Adt) { 1469 return buildAdt( td, std::move( attributes), linkage ); 1439 1470 } else if ( td->kind == TypeData::Symbolic ) { 1440 1471 return buildSymbolic( td, std::move( attributes ), name, scs, linkage ); -
src/Parser/TypeData.h
r28f8f15 r561354f 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, A DT, Ctor, Unknown };27 SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, Adt, Ctor, Unknown }; 28 28 29 29 struct Aggregate_t { … … 65 65 struct ADT_t { 66 66 const std::string * name = nullptr; 67 DeclarationNode * constructors; 68 }; 69 70 struct Constructor_t { 71 const std::string * name; 72 DeclarationNode * type; // types? 67 DeclarationNode * data_constructors; 73 68 }; 74 69 … … 112 107 Enumeration_t enumeration; 113 108 ADT_t adt; 114 Constructor_t data_constructor;115 109 116 110 Function_t function; … … 140 134 ast::TypeDecl * buildVariable( const TypeData * ); 141 135 ast::EnumDecl * buildEnum( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec ); 136 ast::EnumDecl * buildAst( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec ); 142 137 ast::TypeInstType * buildSymbolicInst( const TypeData * ); 143 138 ast::TupleType * buildTuple( const TypeData * ); -
src/Parser/parser.yy
r28f8f15 r561354f 2702 2702 '{' value_list '}' 2703 2703 { 2704 $$ = DeclarationNode::newA DT( $2, $5 );2704 $$ = DeclarationNode::newAdt( $2, $5 ); 2705 2705 } 2706 2706 ; -
src/SymTab/Indexer.cc
r28f8f15 r561354f 606 606 } 607 607 608 void Indexer::addAdt( const AdtDecl * decl ) { 609 ++*stats().add_calls; 610 const std::string & id = decl->name; 611 612 if ( ! adtTable ) { 613 adtTable = AdtTable::new_ptr(); 614 } else { 615 ++* stats().map_lookups; 616 auto existing = adtTable->find( id ); 617 if ( existing != adtTable->end() 618 && existing->second.scope == scope 619 && addedDeclConflicts( existing->second.decl, decl ) ) return; 620 621 } 622 623 lazyInitScope(); 624 ++* stats().map_mutations; 625 adtTable = adtTable->set( id, Scoped<AdtDecl>{ decl, scope} ); 626 } 627 608 628 void Indexer::addUnion( const std::string & id ) { 609 629 addUnion( new UnionDecl( id ) ); -
src/SymTab/Indexer.h
r28f8f15 r561354f 89 89 void addStruct( const StructDecl * decl ); 90 90 void addEnum( const EnumDecl * decl ); 91 void addAdt( const AdtDecl * decl ); 91 92 void addUnion( const std::string & id ); 92 93 void addUnion( const UnionDecl * decl ); … … 124 125 using UnionTable = PersistentMap< std::string, Scoped<UnionDecl> >; 125 126 using TraitTable = PersistentMap< std::string, Scoped<TraitDecl> >; 127 using AdtTable = PersistentMap< std::string, Scoped<AdtDecl> >; 126 128 127 129 IdTable::Ptr idTable; ///< identifier namespace … … 131 133 UnionTable::Ptr unionTable; ///< union namespace 132 134 TraitTable::Ptr traitTable; ///< trait namespace 135 AdtTable::Ptr adtTable; ///< adt namespace 133 136 134 137 Ptr prevScope; ///< reference to indexer for parent scope -
src/SynTree/Declaration.h
r28f8f15 r561354f 342 342 enum EnumHiding { Visible, Hide } hide; 343 343 344 std::list<StructDecl*> data_constructors;345 UnionDecl * data_union;346 EnumDecl * tags;347 StructDecl * tag_union;348 349 344 EnumDecl( const std::string & name, 350 345 const std::list< Attribute * > & attributes = std::list< class Attribute * >(), … … 367 362 }; 368 363 364 class AdtDecl : public AggregateDecl { 365 typedef AggregateDecl Parent; 366 public: 367 std::list<StructDecl*> data_constructors; 368 UnionDecl * data_union; 369 EnumDecl * tag; 370 StructDecl * tag_union; 371 372 AdtDecl( const std::string & name, 373 const std::list< Attribute * > & attributes = std::list< class Attribute * >(), 374 LinkageSpec::Spec linkage = LinkageSpec::Cforall, 375 const std::list< StructDecl* > data_constructors = std::list< StructDecl * >(), 376 UnionDecl * data_union = nullptr, EnumDecl * tag = nullptr, StructDecl * tag_union = nullptr ) 377 : Parent( name, attributes, linkage ), data_constructors(data_constructors), 378 data_union( data_union ), tag( tag ), tag_union( tag_union ) {} 379 380 AdtDecl( const AdtDecl & other ) 381 : Parent( other ) {} 382 383 virtual AdtDecl * clone() const override { return new AdtDecl( *this ); } 384 virtual void accept( Visitor & v ) override { v.visit( this ); } 385 virtual void accept( Visitor & v ) const override { v.visit( this ); } 386 387 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 388 virtual void print( std::ostream & os, Indenter indent = {} ) const override final { 389 os << "AdtDecl ... " << indent; 390 } 391 392 private: 393 virtual const char * typeString() const override { 394 return "AdtDecl"; 395 } 396 }; 397 369 398 class TraitDecl : public AggregateDecl { 370 399 typedef AggregateDecl Parent; -
src/SynTree/Mutator.h
r28f8f15 r561354f 30 30 virtual Declaration * mutate( UnionDecl * aggregateDecl ) = 0; 31 31 virtual Declaration * mutate( EnumDecl * aggregateDecl ) = 0; 32 virtual Declaration * mutate( AdtDecl * aggregateDecl ) = 0; 32 33 virtual Declaration * mutate( TraitDecl * aggregateDecl ) = 0; 33 34 virtual Declaration * mutate( TypeDecl * typeDecl ) = 0; -
src/SynTree/SynTree.h
r28f8f15 r561354f 31 31 class UnionDecl; 32 32 class EnumDecl; 33 class AdtDecl; 33 34 class TraitDecl; 34 35 class NamedTypeDecl; -
src/SynTree/Visitor.h
r28f8f15 r561354f 37 37 virtual void visit( EnumDecl * node ) { visit( const_cast<const EnumDecl *>(node) ); } 38 38 virtual void visit( const EnumDecl * aggregateDecl ) = 0; 39 virtual void visit( AdtDecl * node ) { visit( const_cast<const AdtDecl *>(node) ); } 40 virtual void visit( const AdtDecl * node ) = 0; 39 41 virtual void visit( TraitDecl * node ) { visit( const_cast<const TraitDecl *>(node) ); } 40 42 virtual void visit( const TraitDecl * aggregateDecl ) = 0; -
src/Validate/Autogen.cpp
r28f8f15 r561354f 522 522 523 523 void StructFuncGenerator::genADTFuncs() { 524 if ( decl->kind != ast::AggregateDecl::A DT) return;524 if ( decl->kind != ast::AggregateDecl::Adt ) return; 525 525 assert( decl->members.size() == 2 ); 526 526 auto first = (decl->members[0]).as<ast::ObjectDecl>(); -
src/Validate/NoIdSymbolTable.hpp
r28f8f15 r561354f 44 44 FORWARD_1( addStruct, const ast::StructDecl * ) 45 45 FORWARD_1( addEnum , const ast::EnumDecl * ) 46 FORWARD_1( addAdt, const ast::AdtDecl * ) 46 47 FORWARD_1( addUnion , const ast::UnionDecl * ) 47 48 FORWARD_1( addTrait , const ast::TraitDecl * )
Note: See TracChangeset
for help on using the changeset viewer.