Changeset 74ec742 for src/SymTab
- Timestamp:
- May 20, 2022, 10:36:45 AM (4 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 25fa20a
- Parents:
- 29d8c02 (diff), 7831e8fb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/SymTab
- Files:
-
- 3 added
- 7 edited
-
Autogen.h (modified) (14 diffs)
-
Demangle.cc (modified) (1 diff)
-
Demangle.h (added)
-
Mangler.h (modified) (1 diff)
-
Validate.cc (modified) (12 diffs)
-
Validate.h (modified) (3 diffs)
-
ValidateType.cc (added)
-
ValidateType.h (added)
-
demangler.cc (modified) (1 diff)
-
module.mk (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.h
r29d8c02 r74ec742 21 21 22 22 #include "AST/Decl.hpp" 23 #include "AST/Eval.hpp"24 23 #include "AST/Expr.hpp" 25 24 #include "AST/Init.hpp" … … 71 70 template< typename OutIter > 72 71 ast::ptr< ast::Stmt > genCall( 73 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 74 const CodeLocation & loc, const std::string & fname, OutIter && out, 72 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 73 const CodeLocation & loc, const std::string & fname, OutIter && out, 75 74 const ast::Type * type, const ast::Type * addCast, LoopDirection forward = LoopForward ); 76 75 … … 128 127 } 129 128 130 /// inserts into out a generated call expression to function fname with arguments dstParam and 129 /// inserts into out a generated call expression to function fname with arguments dstParam and 131 130 /// srcParam. Should only be called with non-array types. 132 /// optionally returns a statement which must be inserted prior to the containing loop, if 131 /// optionally returns a statement which must be inserted prior to the containing loop, if 133 132 /// there is one 134 133 template< typename OutIter > 135 ast::ptr< ast::Stmt > genScalarCall( 136 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 137 const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type, 134 ast::ptr< ast::Stmt > genScalarCall( 135 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 136 const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type, 138 137 const ast::Type * addCast = nullptr 139 138 ) { … … 153 152 154 153 if ( addCast ) { 155 // cast to T& with qualifiers removed, so that qualified objects can be constructed and 156 // destructed with the same functions as non-qualified objects. Unfortunately, lvalue 157 // is considered a qualifier - for AddressExpr to resolve, its argument must have an 154 // cast to T& with qualifiers removed, so that qualified objects can be constructed and 155 // destructed with the same functions as non-qualified objects. Unfortunately, lvalue 156 // is considered a qualifier - for AddressExpr to resolve, its argument must have an 158 157 // lvalue-qualified type, so remove all qualifiers except lvalue. 159 158 // xxx -- old code actually removed lvalue too... 160 159 ast::ptr< ast::Type > guard = addCast; // prevent castType from mutating addCast 161 160 ast::ptr< ast::Type > castType = addCast; 162 ast::remove_qualifiers( 163 castType, 161 ast::remove_qualifiers( 162 castType, 164 163 ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Atomic ); 165 164 dstParam = new ast::CastExpr{ dstParam, new ast::ReferenceType{ castType } }; … … 181 180 182 181 srcParam.clearArrayIndices(); 183 182 184 183 return listInit; 185 184 } … … 249 248 } 250 249 251 /// Store in out a loop which calls fname on each element of the array with srcParam and 250 /// Store in out a loop which calls fname on each element of the array with srcParam and 252 251 /// dstParam as arguments. If forward is true, loop goes from 0 to N-1, else N-1 to 0 253 252 template< typename OutIter > 254 253 void genArrayCall( 255 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 256 const CodeLocation & loc, const std::string & fname, OutIter && out, 257 const ast::ArrayType * array, const ast::Type * addCast = nullptr, 258 LoopDirection forward = LoopForward 254 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 255 const CodeLocation & loc, const std::string & fname, OutIter && out, 256 const ast::ArrayType * array, const ast::Type * addCast = nullptr, 257 LoopDirection forward = LoopForward 259 258 ) { 260 259 static UniqueName indexName( "_index" ); … … 279 278 } else { 280 279 // generate: for ( int i = N-1; i >= 0; --i ) 281 begin = ast:: call(282 loc, "?-?", array->dimension, ast::ConstantExpr::from_int( loc, 1 ));280 begin = ast::UntypedExpr::createCall( loc, "?-?", 281 { array->dimension, ast::ConstantExpr::from_int( loc, 1 ) } ); 283 282 end = ast::ConstantExpr::from_int( loc, 0 ); 284 283 cmp = "?>=?"; … … 286 285 } 287 286 288 ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{ 289 loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt }, 287 ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{ 288 loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt }, 290 289 new ast::SingleInit{ loc, begin } }; 291 290 ast::ptr< ast::Expr > indexVar = new ast::VariableExpr{ loc, index }; 292 293 ast::ptr< ast::Expr > cond = ast::call( loc, cmp, indexVar, end ); 294 295 ast::ptr< ast::Expr > inc = ast::call( loc, update, indexVar ); 296 297 ast::ptr< ast::Expr > dstIndex = ast::call( loc, "?[?]", dstParam, indexVar ); 298 299 // srcParam must keep track of the array indices to build the source parameter and/or 291 292 ast::ptr< ast::Expr > cond = ast::UntypedExpr::createCall( 293 loc, cmp, { indexVar, end } ); 294 295 ast::ptr< ast::Expr > inc = ast::UntypedExpr::createCall( 296 loc, update, { indexVar } ); 297 298 ast::ptr< ast::Expr > dstIndex = ast::UntypedExpr::createCall( 299 loc, "?[?]", { dstParam, indexVar } ); 300 301 // srcParam must keep track of the array indices to build the source parameter and/or 300 302 // array list initializer 301 303 srcParam.addArrayIndex( indexVar, array->dimension ); … … 303 305 // for stmt's body, eventually containing call 304 306 ast::CompoundStmt * body = new ast::CompoundStmt{ loc }; 305 ast::ptr< ast::Stmt > listInit = genCall( 306 srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast, 307 ast::ptr< ast::Stmt > listInit = genCall( 308 srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast, 307 309 forward ); 308 310 309 311 // block containing the stmt and index variable 310 312 ast::CompoundStmt * block = new ast::CompoundStmt{ loc }; … … 328 330 template< typename OutIter > 329 331 ast::ptr< ast::Stmt > genCall( 330 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 331 const CodeLocation & loc, const std::string & fname, OutIter && out, 332 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 333 const CodeLocation & loc, const std::string & fname, OutIter && out, 332 334 const ast::Type * type, const ast::Type * addCast, LoopDirection forward 333 335 ) { 334 336 if ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) { 335 genArrayCall( 336 srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast, 337 genArrayCall( 338 srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast, 337 339 forward ); 338 340 return {}; 339 341 } else { 340 return genScalarCall( 342 return genScalarCall( 341 343 srcParam, dstParam, loc, fname, std::forward< OutIter >( out ), type, addCast ); 342 344 } … … 377 379 } 378 380 379 static inline ast::ptr< ast::Stmt > genImplicitCall( 380 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 381 const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj, 382 LoopDirection forward = LoopForward 381 static inline ast::ptr< ast::Stmt > genImplicitCall( 382 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 383 const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj, 384 LoopDirection forward = LoopForward 383 385 ) { 384 386 // unnamed bit fields are not copied as they cannot be accessed … … 392 394 393 395 std::vector< ast::ptr< ast::Stmt > > stmts; 394 genCall( 396 genCall( 395 397 srcParam, dstParam, loc, fname, back_inserter( stmts ), obj->type, addCast, forward ); 396 398 … … 400 402 const ast::Stmt * callStmt = stmts.front(); 401 403 if ( addCast ) { 402 // implicitly generated ctor/dtor calls should be wrapped so that later passes are 404 // implicitly generated ctor/dtor calls should be wrapped so that later passes are 403 405 // aware they were generated. 404 406 callStmt = new ast::ImplicitCtorDtorStmt{ callStmt->location, callStmt }; … … 417 419 // compile-command: "make install" // 418 420 // End: // 419 -
src/SymTab/Demangle.cc
r29d8c02 r74ec742 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Demangle r.cc --7 // Demangle.cc -- Convert a mangled name into a human readable name. 8 8 // 9 9 // Author : Rob Schluntz -
src/SymTab/Mangler.h
r29d8c02 r74ec742 111 111 } 112 112 113 extern "C" {114 char * cforall_demangle(const char *, int);115 }116 117 113 // Local Variables: // 118 114 // tab-width: 4 // -
src/SymTab/Validate.cc
r29d8c02 r74ec742 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Nov 12 11:00:00 202113 // Update Count : 36 412 // Last Modified On : Tue May 17 14:36:00 2022 13 // Update Count : 366 14 14 // 15 15 … … 74 74 #include "ResolvExpr/ResolveTypeof.h" // for resolveTypeof 75 75 #include "SymTab/Autogen.h" // for SizeType 76 #include "SymTab/ValidateType.h" // for decayEnumsAndPointers, decayFo... 76 77 #include "SynTree/LinkageSpec.h" // for C 77 78 #include "SynTree/Attribute.h" // for noAttributes, Attribute … … 134 135 }; 135 136 136 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.137 struct EnumAndPointerDecay_old {138 void previsit( EnumDecl * aggregateDecl );139 void previsit( FunctionType * func );140 };141 142 /// Associates forward declarations of aggregates with their definitions143 struct LinkReferenceToTypes_old final : public WithIndexer, public WithGuards, public WithVisitorRef<LinkReferenceToTypes_old>, public WithShortCircuiting {144 LinkReferenceToTypes_old( const Indexer * indexer );145 void postvisit( TypeInstType * typeInst );146 147 void postvisit( EnumInstType * enumInst );148 void postvisit( StructInstType * structInst );149 void postvisit( UnionInstType * unionInst );150 void postvisit( TraitInstType * traitInst );151 void previsit( QualifiedType * qualType );152 void postvisit( QualifiedType * qualType );153 154 void postvisit( EnumDecl * enumDecl );155 void postvisit( StructDecl * structDecl );156 void postvisit( UnionDecl * unionDecl );157 void postvisit( TraitDecl * traitDecl );158 159 void previsit( StructDecl * structDecl );160 void previsit( UnionDecl * unionDecl );161 162 void renameGenericParams( std::list< TypeDecl * > & params );163 164 private:165 const Indexer * local_indexer;166 167 typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType;168 typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType;169 typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType;170 ForwardEnumsType forwardEnums;171 ForwardStructsType forwardStructs;172 ForwardUnionsType forwardUnions;173 /// true if currently in a generic type body, so that type parameter instances can be renamed appropriately174 bool inGeneric = false;175 };176 177 137 /// Does early resolution on the expressions that give enumeration constants their values 178 138 struct ResolveEnumInitializers final : public WithIndexer, public WithGuards, public WithVisitorRef<ResolveEnumInitializers>, public WithShortCircuiting { … … 192 152 void previsit( StructDecl * aggrDecl ); 193 153 void previsit( UnionDecl * aggrDecl ); 194 };195 196 // These structs are the sub-sub-passes of ForallPointerDecay_old.197 198 struct TraitExpander_old final {199 void previsit( FunctionType * );200 void previsit( StructDecl * );201 void previsit( UnionDecl * );202 };203 204 struct AssertionFixer_old final {205 void previsit( FunctionType * );206 void previsit( StructDecl * );207 void previsit( UnionDecl * );208 };209 210 struct CheckOperatorTypes_old final {211 void previsit( ObjectDecl * );212 };213 214 struct FixUniqueIds_old final {215 void previsit( DeclarationWithType * );216 154 }; 217 155 … … 357 295 358 296 void validate_A( std::list< Declaration * > & translationUnit ) { 359 PassVisitor<EnumAndPointerDecay_old> epc;360 297 PassVisitor<HoistTypeDecls> hoistDecls; 361 298 { … … 366 303 ReplaceTypedef::replaceTypedef( translationUnit ); 367 304 ReturnTypeFixer::fix( translationUnit ); // must happen before autogen 368 acceptAll( translationUnit, epc); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes_old because it is an indexer and needs correct types for mangling305 decayEnumsAndPointers( translationUnit ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes_old because it is an indexer and needs correct types for mangling 369 306 } 370 307 } 371 308 372 309 void validate_B( std::list< Declaration * > & translationUnit ) { 373 PassVisitor<LinkReferenceToTypes_old> lrt( nullptr );374 310 PassVisitor<FixQualifiedTypes> fixQual; 375 311 { 376 312 Stats::Heap::newPass("validate-B"); 377 313 Stats::Time::BlockGuard guard("validate-B"); 378 acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions314 //linkReferenceToTypes( translationUnit ); 379 315 mutateAll( translationUnit, fixQual ); // must happen after LinkReferenceToTypes_old, because aggregate members are accessed 380 316 HoistStruct::hoistStruct( translationUnit ); … … 407 343 }); 408 344 } 409 }410 411 static void decayForallPointers( std::list< Declaration * > & translationUnit ) {412 PassVisitor<TraitExpander_old> te;413 acceptAll( translationUnit, te );414 PassVisitor<AssertionFixer_old> af;415 acceptAll( translationUnit, af );416 PassVisitor<CheckOperatorTypes_old> cot;417 acceptAll( translationUnit, cot );418 PassVisitor<FixUniqueIds_old> fui;419 acceptAll( translationUnit, fui );420 345 } 421 346 … … 496 421 } 497 422 498 void validateType( Type * type, const Indexer * indexer ) {499 PassVisitor<EnumAndPointerDecay_old> epc;500 PassVisitor<LinkReferenceToTypes_old> lrt( indexer );501 PassVisitor<TraitExpander_old> te;502 PassVisitor<AssertionFixer_old> af;503 PassVisitor<CheckOperatorTypes_old> cot;504 PassVisitor<FixUniqueIds_old> fui;505 type->accept( epc );506 type->accept( lrt );507 type->accept( te );508 type->accept( af );509 type->accept( cot );510 type->accept( fui );511 }512 513 423 void HoistTypeDecls::handleType( Type * type ) { 514 424 // some type declarations are buried in expressions and not easy to hoist during parsing; hoist them here … … 703 613 } 704 614 705 void EnumAndPointerDecay_old::previsit( EnumDecl * enumDecl ) {706 // Set the type of each member of the enumeration to be EnumConstant707 for ( std::list< Declaration * >::iterator i = enumDecl->members.begin(); i != enumDecl->members.end(); ++i ) {708 ObjectDecl * obj = dynamic_cast< ObjectDecl * >( * i );709 assert( obj );710 obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->name ) );711 } // for712 }713 714 namespace {715 template< typename DWTList >716 void fixFunctionList( DWTList & dwts, bool isVarArgs, FunctionType * func ) {717 auto nvals = dwts.size();718 bool containsVoid = false;719 for ( auto & dwt : dwts ) {720 // fix each DWT and record whether a void was found721 containsVoid |= fixFunction( dwt );722 }723 724 // the only case in which "void" is valid is where it is the only one in the list725 if ( containsVoid && ( nvals > 1 || isVarArgs ) ) {726 SemanticError( func, "invalid type void in function type " );727 }728 729 // one void is the only thing in the list; remove it.730 if ( containsVoid ) {731 delete dwts.front();732 dwts.clear();733 }734 }735 }736 737 void EnumAndPointerDecay_old::previsit( FunctionType * func ) {738 // Fix up parameters and return types739 fixFunctionList( func->parameters, func->isVarArgs, func );740 fixFunctionList( func->returnVals, false, func );741 }742 743 LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer * other_indexer ) : WithIndexer( false ) {744 if ( other_indexer ) {745 local_indexer = other_indexer;746 } else {747 local_indexer = &indexer;748 } // if749 }750 751 void LinkReferenceToTypes_old::postvisit( EnumInstType * enumInst ) {752 const EnumDecl * st = local_indexer->lookupEnum( enumInst->name );753 // it's not a semantic error if the enum is not found, just an implicit forward declaration754 if ( st ) {755 enumInst->baseEnum = const_cast<EnumDecl *>(st); // Just linking in the node756 } // if757 if ( ! st || ! st->body ) {758 // use of forward declaration759 forwardEnums[ enumInst->name ].push_back( enumInst );760 } // if761 }762 763 void LinkReferenceToTypes_old::postvisit( StructInstType * structInst ) {764 const StructDecl * st = local_indexer->lookupStruct( structInst->name );765 // it's not a semantic error if the struct is not found, just an implicit forward declaration766 if ( st ) {767 structInst->baseStruct = const_cast<StructDecl *>(st); // Just linking in the node768 } // if769 if ( ! st || ! st->body ) {770 // use of forward declaration771 forwardStructs[ structInst->name ].push_back( structInst );772 } // if773 }774 775 void LinkReferenceToTypes_old::postvisit( UnionInstType * unionInst ) {776 const UnionDecl * un = local_indexer->lookupUnion( unionInst->name );777 // it's not a semantic error if the union is not found, just an implicit forward declaration778 if ( un ) {779 unionInst->baseUnion = const_cast<UnionDecl *>(un); // Just linking in the node780 } // if781 if ( ! un || ! un->body ) {782 // use of forward declaration783 forwardUnions[ unionInst->name ].push_back( unionInst );784 } // if785 }786 787 void LinkReferenceToTypes_old::previsit( QualifiedType * ) {788 visit_children = false;789 }790 791 void LinkReferenceToTypes_old::postvisit( QualifiedType * qualType ) {792 // linking only makes sense for the 'oldest ancestor' of the qualified type793 qualType->parent->accept( * visitor );794 }795 796 template< typename Decl >797 void normalizeAssertions( std::list< Decl * > & assertions ) {798 // ensure no duplicate trait members after the clone799 auto pred = [](Decl * d1, Decl * d2) {800 // only care if they're equal801 DeclarationWithType * dwt1 = dynamic_cast<DeclarationWithType *>( d1 );802 DeclarationWithType * dwt2 = dynamic_cast<DeclarationWithType *>( d2 );803 if ( dwt1 && dwt2 ) {804 if ( dwt1->name == dwt2->name && ResolvExpr::typesCompatible( dwt1->get_type(), dwt2->get_type(), SymTab::Indexer() ) ) {805 // std::cerr << "=========== equal:" << std::endl;806 // std::cerr << "d1: " << d1 << std::endl;807 // std::cerr << "d2: " << d2 << std::endl;808 return false;809 }810 }811 return d1 < d2;812 };813 std::set<Decl *, decltype(pred)> unique_members( assertions.begin(), assertions.end(), pred );814 // if ( unique_members.size() != assertions.size() ) {815 // std::cerr << "============different" << std::endl;816 // std::cerr << unique_members.size() << " " << assertions.size() << std::endl;817 // }818 819 std::list< Decl * > order;820 order.splice( order.end(), assertions );821 std::copy_if( order.begin(), order.end(), back_inserter( assertions ), [&]( Decl * decl ) {822 return unique_members.count( decl );823 });824 }825 826 615 // expand assertions from trait instance, performing the appropriate type variable substitutions 827 616 template< typename Iterator > … … 834 623 // substitute trait decl parameters for instance parameters 835 624 applySubstitution( inst->baseTrait->parameters.begin(), inst->baseTrait->parameters.end(), inst->parameters.begin(), asserts.begin(), asserts.end(), out ); 836 }837 838 void LinkReferenceToTypes_old::postvisit( TraitDecl * traitDecl ) {839 if ( traitDecl->name == "sized" ) {840 // "sized" is a special trait - flick the sized status on for the type variable841 assertf( traitDecl->parameters.size() == 1, "Built-in trait 'sized' has incorrect number of parameters: %zd", traitDecl->parameters.size() );842 TypeDecl * td = traitDecl->parameters.front();843 td->set_sized( true );844 }845 846 // move assertions from type parameters into the body of the trait847 for ( TypeDecl * td : traitDecl->parameters ) {848 for ( DeclarationWithType * assert : td->assertions ) {849 if ( TraitInstType * inst = dynamic_cast< TraitInstType * >( assert->get_type() ) ) {850 expandAssertions( inst, back_inserter( traitDecl->members ) );851 } else {852 traitDecl->members.push_back( assert->clone() );853 }854 }855 deleteAll( td->assertions );856 td->assertions.clear();857 } // for858 }859 860 void LinkReferenceToTypes_old::postvisit( TraitInstType * traitInst ) {861 // handle other traits862 const TraitDecl * traitDecl = local_indexer->lookupTrait( traitInst->name );863 if ( ! traitDecl ) {864 SemanticError( traitInst->location, "use of undeclared trait " + traitInst->name );865 } // if866 if ( traitDecl->parameters.size() != traitInst->parameters.size() ) {867 SemanticError( traitInst, "incorrect number of trait parameters: " );868 } // if869 traitInst->baseTrait = const_cast<TraitDecl *>(traitDecl); // Just linking in the node870 871 // need to carry over the 'sized' status of each decl in the instance872 for ( auto p : group_iterate( traitDecl->parameters, traitInst->parameters ) ) {873 TypeExpr * expr = dynamic_cast< TypeExpr * >( std::get<1>(p) );874 if ( ! expr ) {875 SemanticError( std::get<1>(p), "Expression parameters for trait instances are currently unsupported: " );876 }877 if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) {878 TypeDecl * formalDecl = std::get<0>(p);879 TypeDecl * instDecl = inst->baseType;880 if ( formalDecl->get_sized() ) instDecl->set_sized( true );881 }882 }883 // normalizeAssertions( traitInst->members );884 }885 886 void LinkReferenceToTypes_old::postvisit( EnumDecl * enumDecl ) {887 // visit enum members first so that the types of self-referencing members are updated properly888 if ( enumDecl->body ) {889 ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->name );890 if ( fwds != forwardEnums.end() ) {891 for ( std::list< EnumInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {892 (* inst)->baseEnum = enumDecl;893 } // for894 forwardEnums.erase( fwds );895 } // if896 } // if897 }898 899 void LinkReferenceToTypes_old::renameGenericParams( std::list< TypeDecl * > & params ) {900 // rename generic type parameters uniquely so that they do not conflict with user-defined function forall parameters, e.g.901 // forall(otype T)902 // struct Box {903 // T x;904 // };905 // forall(otype T)906 // void f(Box(T) b) {907 // ...908 // }909 // The T in Box and the T in f are different, so internally the naming must reflect that.910 GuardValue( inGeneric );911 inGeneric = ! params.empty();912 for ( TypeDecl * td : params ) {913 td->name = "__" + td->name + "_generic_";914 }915 }916 917 void LinkReferenceToTypes_old::previsit( StructDecl * structDecl ) {918 renameGenericParams( structDecl->parameters );919 }920 921 void LinkReferenceToTypes_old::previsit( UnionDecl * unionDecl ) {922 renameGenericParams( unionDecl->parameters );923 }924 925 void LinkReferenceToTypes_old::postvisit( StructDecl * structDecl ) {926 // visit struct members first so that the types of self-referencing members are updated properly927 // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and their defaults)928 if ( structDecl->body ) {929 ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->name );930 if ( fwds != forwardStructs.end() ) {931 for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {932 (* inst)->baseStruct = structDecl;933 } // for934 forwardStructs.erase( fwds );935 } // if936 } // if937 }938 939 void LinkReferenceToTypes_old::postvisit( UnionDecl * unionDecl ) {940 if ( unionDecl->body ) {941 ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->name );942 if ( fwds != forwardUnions.end() ) {943 for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {944 (* inst)->baseUnion = unionDecl;945 } // for946 forwardUnions.erase( fwds );947 } // if948 } // if949 }950 951 void LinkReferenceToTypes_old::postvisit( TypeInstType * typeInst ) {952 // ensure generic parameter instances are renamed like the base type953 if ( inGeneric && typeInst->baseType ) typeInst->name = typeInst->baseType->name;954 if ( const NamedTypeDecl * namedTypeDecl = local_indexer->lookupType( typeInst->name ) ) {955 if ( const TypeDecl * typeDecl = dynamic_cast< const TypeDecl * >( namedTypeDecl ) ) {956 typeInst->set_isFtype( typeDecl->kind == TypeDecl::Ftype );957 } // if958 } // if959 625 } 960 626 … … 985 651 } 986 652 } 987 988 653 } 989 654 } … … 1073 738 void ForallPointerDecay_old::previsit( UnionDecl * aggrDecl ) { 1074 739 forallFixer( aggrDecl->parameters, aggrDecl ); 1075 }1076 1077 void TraitExpander_old::previsit( FunctionType * ftype ) {1078 expandTraits( ftype->forall );1079 }1080 1081 void TraitExpander_old::previsit( StructDecl * aggrDecl ) {1082 expandTraits( aggrDecl->parameters );1083 }1084 1085 void TraitExpander_old::previsit( UnionDecl * aggrDecl ) {1086 expandTraits( aggrDecl->parameters );1087 }1088 1089 void AssertionFixer_old::previsit( FunctionType * ftype ) {1090 fixAssertions( ftype->forall, ftype );1091 }1092 1093 void AssertionFixer_old::previsit( StructDecl * aggrDecl ) {1094 fixAssertions( aggrDecl->parameters, aggrDecl );1095 }1096 1097 void AssertionFixer_old::previsit( UnionDecl * aggrDecl ) {1098 fixAssertions( aggrDecl->parameters, aggrDecl );1099 }1100 1101 void CheckOperatorTypes_old::previsit( ObjectDecl * object ) {1102 // ensure that operator names only apply to functions or function pointers1103 if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) {1104 SemanticError( object->location, toCString( "operator ", object->name.c_str(), " is not a function or function pointer." ) );1105 }1106 }1107 1108 void FixUniqueIds_old::previsit( DeclarationWithType * decl ) {1109 decl->fixUniqueId();1110 740 } 1111 741 -
src/SymTab/Validate.h
r29d8c02 r74ec742 10 10 // Author : Richard C. Bilson 11 11 // Created On : Sun May 17 21:53:34 2015 12 // Last Modified By : Peter A. Buhr13 // Last Modified On : Sat Jul 22 09:46:07 201714 // Update Count : 412 // Last Modified By : Andrew Beach 13 // Last Modified On : Tue May 17 14:35:00 2022 14 // Update Count : 5 15 15 // 16 16 … … 33 33 /// Normalizes struct and function declarations 34 34 void validate( std::list< Declaration * > &translationUnit, bool doDebug = false ); 35 void validateType( Type *type, const Indexer *indexer );36 35 37 36 // Sub-passes of validate. … … 42 41 void validate_E( std::list< Declaration * > &translationUnit ); 43 42 void validate_F( std::list< Declaration * > &translationUnit ); 44 45 const ast::Type * validateType(46 const CodeLocation & loc, const ast::Type * type, const ast::SymbolTable & symtab );47 43 } // namespace SymTab 48 44 -
src/SymTab/demangler.cc
r29d8c02 r74ec742 1 #include " Mangler.h"1 #include "Demangle.h" 2 2 #include <iostream> 3 3 #include <fstream> -
src/SymTab/module.mk
r29d8c02 r74ec742 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 12 ## Last Modified By : Andrew Beach 13 ## Last Modified On : T hr Aug 10 16:08:00 201714 ## Update Count : 413 ## Last Modified On : Tue May 17 14:46:00 2022 14 ## Update Count : 5 15 15 ############################################################################### 16 16 17 17 SRC_SYMTAB = \ 18 SymTab/Autogen.cc \19 SymTab/Autogen.h \20 SymTab/FixFunction.cc \21 SymTab/FixFunction.h \22 SymTab/Indexer.cc \23 SymTab/Indexer.h \24 SymTab/Mangler.cc \25 SymTab/ManglerCommon.cc \26 SymTab/Mangler.h \27 SymTab/Validate.cc \28 SymTab/Validate.h18 SymTab/Autogen.cc \ 19 SymTab/Autogen.h \ 20 SymTab/FixFunction.cc \ 21 SymTab/FixFunction.h \ 22 SymTab/Indexer.cc \ 23 SymTab/Indexer.h \ 24 SymTab/Mangler.cc \ 25 SymTab/ManglerCommon.cc \ 26 SymTab/Mangler.h \ 27 SymTab/ValidateType.cc \ 28 SymTab/ValidateType.h 29 29 30 SRC += $(SRC_SYMTAB) 31 SRCDEMANGLE += $(SRC_SYMTAB) SymTab/Demangle.cc 30 SRC += $(SRC_SYMTAB) \ 31 SymTab/Validate.cc \ 32 SymTab/Validate.h 33 34 SRCDEMANGLE += $(SRC_SYMTAB) \ 35 SymTab/Demangle.cc \ 36 SymTab/Demangle.h
Note:
See TracChangeset
for help on using the changeset viewer.