Changeset 6f096d2 for src/SymTab
- Timestamp:
- Jul 12, 2019, 4:34:56 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- e3d7f9f
- Parents:
- 8fd52e90
- Location:
- src/SymTab
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/SymTab/Indexer.cc ¶
r8fd52e90 r6f096d2 188 188 } 189 189 190 bool isFunction( DeclarationWithType * decl ) {190 bool isFunction( const DeclarationWithType * decl ) { 191 191 return GenPoly::getFunctionType( decl->get_type() ); 192 192 } 193 193 194 bool isObject( DeclarationWithType * decl ) {194 bool isObject( const DeclarationWithType * decl ) { 195 195 return ! isFunction( decl ); 196 196 } 197 197 198 bool isDefinition( DeclarationWithType * decl ) {199 if ( FunctionDecl * func = dynamic_cast<FunctionDecl * >( decl ) ) {198 bool isDefinition( const DeclarationWithType * decl ) { 199 if ( const FunctionDecl * func = dynamic_cast< const FunctionDecl * >( decl ) ) { 200 200 // a function is a definition if it has a body 201 201 return func->statements; … … 209 209 210 210 bool Indexer::addedIdConflicts( 211 const Indexer::IdData & existing, DeclarationWithType * added,212 Indexer::OnConflict handleConflicts, BaseSyntaxNode * deleteStmt ) {211 const Indexer::IdData & existing, const DeclarationWithType * added, 212 Indexer::OnConflict handleConflicts, const BaseSyntaxNode * deleteStmt ) { 213 213 // if we're giving the same name mangling to things of different types then there is 214 214 // something wrong … … 274 274 } 275 275 276 bool Indexer::hasIncompatibleCDecl( 277 const std::string & id, const std::string &mangleName ) const { 276 bool Indexer::hasIncompatibleCDecl(const std::string & id, const std::string &mangleName ) const { 278 277 if ( ! idTable ) return false; 279 278 … … 295 294 296 295 /// gets the base type of the first parameter; decl must be a ctor/dtor/assignment function 297 std::string getOtypeKey( FunctionDecl * function ) {296 std::string getOtypeKey( const FunctionDecl * function ) { 298 297 auto& params = function->type->parameters; 299 298 assert( ! params.empty() ); … … 306 305 /// gets the declaration for the function acting on a type specified by otype key, 307 306 /// nullptr if none such 308 FunctionDecl * getFunctionForOtype(DeclarationWithType * decl, const std::string& otypeKey ) {309 FunctionDecl * func = dynamic_cast<FunctionDecl * >( decl );307 const FunctionDecl * getFunctionForOtype( const DeclarationWithType * decl, const std::string& otypeKey ) { 308 const FunctionDecl * func = dynamic_cast< const FunctionDecl * >( decl ); 310 309 if ( ! func || otypeKey != getOtypeKey( func ) ) return nullptr; 311 310 return func; 312 311 } 313 312 314 bool Indexer::removeSpecialOverrides( 315 Indexer::IdData& data, Indexer::MangleTable::Ptr& mangleTable ) { 313 bool Indexer::removeSpecialOverrides(Indexer::IdData& data, Indexer::MangleTable::Ptr& mangleTable ) { 316 314 // if a type contains user defined ctor/dtor/assign, then special rules trigger, which 317 315 // determinethe set of ctor/dtor/assign that can be used by the requester. In particular, … … 324 322 325 323 // only relevant on function declarations 326 FunctionDecl * function = dynamic_cast<FunctionDecl * >( data.id );324 const FunctionDecl * function = dynamic_cast< const FunctionDecl * >( data.id ); 327 325 if ( ! function ) return true; 328 326 // only need to perform this check for constructors, destructors, and assignment functions … … 343 341 for ( const auto& entry : * mangleTable ) { 344 342 // skip decls that aren't functions or are for the wrong type 345 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );343 const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey ); 346 344 if ( ! decl ) continue; 347 345 … … 382 380 for ( const auto& entry : * mangleTable ) { 383 381 // skip decls that aren't functions or are for the wrong type 384 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );382 const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey ); 385 383 if ( ! decl ) continue; 386 384 … … 410 408 for ( const auto& entry : * mangleTable ) { 411 409 // skip decls that aren't functions or are for the wrong type 412 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );410 const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey ); 413 411 if ( ! decl ) continue; 414 412 … … 433 431 } 434 432 435 void Indexer::addId( 436 DeclarationWithType * decl, OnConflict handleConflicts, Expression * baseExpr, 437 BaseSyntaxNode * deleteStmt ) { 433 void Indexer::addId(const DeclarationWithType * decl, OnConflict handleConflicts, const Expression * baseExpr, 434 const BaseSyntaxNode * deleteStmt ) { 438 435 ++* stats().add_calls; 439 436 const std::string &name = decl->name; … … 508 505 } 509 506 510 void Indexer::addId( DeclarationWithType * decl,Expression * baseExpr ) {507 void Indexer::addId( const DeclarationWithType * decl, const Expression * baseExpr ) { 511 508 // default handling of conflicts is to raise an error 512 509 addId( decl, OnConflict::error(), baseExpr, decl->isDeleted ? decl : nullptr ); 513 510 } 514 511 515 void Indexer::addDeletedId( DeclarationWithType * decl,BaseSyntaxNode * deleteStmt ) {512 void Indexer::addDeletedId( const DeclarationWithType * decl, const BaseSyntaxNode * deleteStmt ) { 516 513 // default handling of conflicts is to raise an error 517 514 addId( decl, OnConflict::error(), nullptr, deleteStmt ); 518 515 } 519 516 520 bool addedTypeConflicts( NamedTypeDecl * existing,NamedTypeDecl * added ) {517 bool addedTypeConflicts( const NamedTypeDecl * existing, const NamedTypeDecl * added ) { 521 518 if ( existing->base == nullptr ) { 522 519 return false; … … 535 532 } 536 533 537 void Indexer::addType( NamedTypeDecl * decl ) {534 void Indexer::addType( const NamedTypeDecl * decl ) { 538 535 ++* stats().add_calls; 539 536 const std::string & id = decl->name; … … 554 551 } 555 552 556 bool addedDeclConflicts( AggregateDecl * existing,AggregateDecl * added ) {553 bool addedDeclConflicts( const AggregateDecl * existing, const AggregateDecl * added ) { 557 554 if ( ! existing->body ) { 558 555 return false; … … 567 564 } 568 565 569 void Indexer::addStruct( StructDecl * decl ) {566 void Indexer::addStruct( const StructDecl * decl ) { 570 567 ++* stats().add_calls; 571 568 const std::string & id = decl->name; … … 586 583 } 587 584 588 void Indexer::addEnum( EnumDecl * decl ) {585 void Indexer::addEnum( const EnumDecl * decl ) { 589 586 ++* stats().add_calls; 590 587 const std::string & id = decl->name; … … 609 606 } 610 607 611 void Indexer::addUnion( UnionDecl * decl ) {608 void Indexer::addUnion( const UnionDecl * decl ) { 612 609 ++* stats().add_calls; 613 610 const std::string & id = decl->name; … … 628 625 } 629 626 630 void Indexer::addTrait( TraitDecl * decl ) {627 void Indexer::addTrait( const TraitDecl * decl ) { 631 628 ++* stats().add_calls; 632 629 const std::string & id = decl->name; … … 647 644 } 648 645 649 void Indexer::addMembers( AggregateDecl * aggr, Expression * expr, 650 OnConflict handleConflicts ) { 646 void Indexer::addMembers( const AggregateDecl * aggr, const Expression * expr, OnConflict handleConflicts ) { 651 647 for ( Declaration * decl : aggr->members ) { 652 648 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) { 653 649 addId( dwt, handleConflicts, expr ); 654 650 if ( dwt->name == "" ) { 655 Type * t = dwt->get_type()->stripReferences();656 if ( dynamic_cast< StructInstType *>( t ) || dynamic_cast<UnionInstType *>( t ) ) {651 const Type * t = dwt->get_type()->stripReferences(); 652 if ( dynamic_cast<const StructInstType *>( t ) || dynamic_cast<const UnionInstType *>( t ) ) { 657 653 Expression * base = expr->clone(); 658 654 ResolvExpr::Cost cost = ResolvExpr::Cost::zero; // xxx - carry this cost into the indexer as a base cost? … … 665 661 } 666 662 667 void Indexer::addWith( std::list< Expression * > & withExprs,BaseSyntaxNode * withStmt ) {668 for ( Expression * expr : withExprs ) {663 void Indexer::addWith( const std::list< Expression * > & withExprs, const BaseSyntaxNode * withStmt ) { 664 for ( const Expression * expr : withExprs ) { 669 665 if ( expr->result ) { 670 666 AggregateDecl * aggr = expr->result->stripReferences()->getAggr(); … … 689 685 } 690 686 691 void Indexer::addFunctionType( FunctionType * ftype ) {687 void Indexer::addFunctionType( const FunctionType * ftype ) { 692 688 addTypes( ftype->forall ); 693 689 addIds( ftype->returnVals ); … … 700 696 Expression * base = baseExpr->clone(); 701 697 ResolvExpr::referenceToRvalueConversion( base, cost ); 702 ret = new MemberExpr( id, base );698 ret = new MemberExpr( const_cast<DeclarationWithType *>(id), base ); 703 699 // xxx - this introduces hidden environments, for now remove them. 704 700 // std::swap( base->env, ret->env ); … … 706 702 base->env = nullptr; 707 703 } else { 708 ret = new VariableExpr( id);709 } 710 if ( deleteStmt ) ret = new DeletedExpr( ret, deleteStmt);704 ret = new VariableExpr( const_cast<DeclarationWithType *>(id) ); 705 } 706 if ( deleteStmt ) ret = new DeletedExpr( ret, const_cast<BaseSyntaxNode *>(deleteStmt) ); 711 707 return ret; 712 708 } -
TabularUnified src/SymTab/Indexer.h ¶
r8fd52e90 r6f096d2 40 40 41 41 struct IdData { 42 DeclarationWithType * id = nullptr;43 Expression * baseExpr = nullptr; // WithExpr42 const DeclarationWithType * id = nullptr; 43 const Expression * baseExpr = nullptr; // WithExpr 44 44 45 45 /// non-null if this declaration is deleted 46 BaseSyntaxNode * deleteStmt = nullptr;46 const BaseSyntaxNode * deleteStmt = nullptr; 47 47 /// scope of identifier 48 48 unsigned long scope = 0; … … 51 51 IdData() = default; 52 52 IdData( 53 DeclarationWithType * id, Expression * baseExpr,BaseSyntaxNode * deleteStmt,53 const DeclarationWithType * id, const Expression * baseExpr, const BaseSyntaxNode * deleteStmt, 54 54 unsigned long scope ) 55 55 : id( id ), baseExpr( baseExpr ), deleteStmt( deleteStmt ), scope( scope ) {} 56 IdData( const IdData& o, BaseSyntaxNode * deleteStmt )56 IdData( const IdData& o, const BaseSyntaxNode * deleteStmt ) 57 57 : id( o.id ), baseExpr( o.baseExpr ), deleteStmt( deleteStmt ), scope( o.scope ) {} 58 58 … … 82 82 const EnumDecl * globalLookupEnum( const std::string & id ) const; 83 83 84 void addId( DeclarationWithType * decl,Expression * baseExpr = nullptr );85 void addDeletedId( DeclarationWithType * decl,BaseSyntaxNode * deleteStmt );84 void addId( const DeclarationWithType * decl, const Expression * baseExpr = nullptr ); 85 void addDeletedId( const DeclarationWithType * decl, const BaseSyntaxNode * deleteStmt ); 86 86 87 void addType( NamedTypeDecl * decl );87 void addType( const NamedTypeDecl * decl ); 88 88 void addStruct( const std::string & id ); 89 void addStruct( StructDecl * decl );90 void addEnum( EnumDecl * decl );89 void addStruct( const StructDecl * decl ); 90 void addEnum( const EnumDecl * decl ); 91 91 void addUnion( const std::string & id ); 92 void addUnion( UnionDecl * decl );93 void addTrait( TraitDecl * decl );92 void addUnion( const UnionDecl * decl ); 93 void addTrait( const TraitDecl * decl ); 94 94 95 95 /// adds all of the IDs from WithStmt exprs 96 void addWith( std::list< Expression * > & withExprs,BaseSyntaxNode * withStmt );96 void addWith( const std::list< Expression * > & withExprs, const BaseSyntaxNode * withStmt ); 97 97 98 98 /// convenience function for adding a list of Ids to the indexer … … 103 103 104 104 /// convenience function for adding all of the declarations in a function type to the indexer 105 void addFunctionType( FunctionType * ftype );105 void addFunctionType( const FunctionType * ftype ); 106 106 107 107 private: … … 109 109 template<typename Decl> 110 110 struct Scoped { 111 Decl * decl; ///< declaration111 const Decl * decl; ///< declaration 112 112 unsigned long scope; ///< scope of this declaration 113 113 114 Scoped( Decl * d, unsigned long s) : decl(d), scope(s) {}114 Scoped(const Decl * d, unsigned long s) : decl(d), scope(s) {} 115 115 }; 116 116 … … 144 144 /// Removes matching autogenerated constructors and destructors so that they will not be 145 145 /// selected. If returns false, passed decl should not be added. 146 bool removeSpecialOverrides( IdData & decl, MangleTable::Ptr& mangleTable );146 bool removeSpecialOverrides( IdData & decl, MangleTable::Ptr & mangleTable ); 147 147 148 148 /// Options for handling identifier conflicts … … 152 152 Delete ///< Delete the earlier version with the delete statement 153 153 } mode; 154 BaseSyntaxNode * deleteStmt; ///< Statement that deletes this expression154 const BaseSyntaxNode * deleteStmt; ///< Statement that deletes this expression 155 155 156 156 private: 157 157 OnConflict() : mode(Error), deleteStmt(nullptr) {} 158 OnConflict( BaseSyntaxNode * d ) : mode(Delete), deleteStmt(d) {}158 OnConflict( const BaseSyntaxNode * d ) : mode(Delete), deleteStmt(d) {} 159 159 public: 160 160 OnConflict( const OnConflict& ) = default; 161 161 162 162 static OnConflict error() { return {}; } 163 static OnConflict deleteWith( BaseSyntaxNode * d ) { return { d }; }163 static OnConflict deleteWith( const BaseSyntaxNode * d ) { return { d }; } 164 164 }; 165 165 166 166 /// true if the existing identifier conflicts with the added identifier 167 167 bool addedIdConflicts( 168 const IdData & existing,DeclarationWithType * added, OnConflict handleConflicts,169 BaseSyntaxNode * deleteStmt );168 const IdData & existing, const DeclarationWithType * added, OnConflict handleConflicts, 169 const BaseSyntaxNode * deleteStmt ); 170 170 171 171 /// common code for addId, addDeletedId, etc. 172 void addId( 173 DeclarationWithType * decl, OnConflict handleConflicts, 174 Expression * baseExpr = nullptr, BaseSyntaxNode * deleteStmt = nullptr ); 172 void addId(const DeclarationWithType * decl, OnConflict handleConflicts, 173 const Expression * baseExpr = nullptr, const BaseSyntaxNode * deleteStmt = nullptr ); 175 174 176 175 /// adds all of the members of the Aggregate (addWith helper) 177 void addMembers( AggregateDecl * aggr,Expression * expr, OnConflict handleConflicts );176 void addMembers( const AggregateDecl * aggr, const Expression * expr, OnConflict handleConflicts ); 178 177 179 178 /// returns true if there exists a declaration with C linkage and the given name with the same mangled name 180 bool hasCompatibleCDecl( const std::string & id, const std::string & mangleName ) const;179 bool hasCompatibleCDecl( const std::string & id, const std::string & mangleName ) const; 181 180 /// returns true if there exists a declaration with C linkage and the given name with a different mangled name 182 bool hasIncompatibleCDecl( const std::string & id, const std::string & mangleName ) const;181 bool hasIncompatibleCDecl( const std::string & id, const std::string & mangleName ) const; 183 182 }; 184 183 } // namespace SymTab -
TabularUnified src/SymTab/Mangler.cc ¶
r8fd52e90 r6f096d2 42 42 Mangler_old( const Mangler_old & ) = delete; 43 43 44 void previsit( BaseSyntaxNode * ) { visit_children = false; }45 46 void postvisit( ObjectDecl * declaration );47 void postvisit( FunctionDecl * declaration );48 void postvisit( TypeDecl * declaration );49 50 void postvisit( VoidType * voidType );51 void postvisit( BasicType * basicType );52 void postvisit( PointerType * pointerType );53 void postvisit( ArrayType * arrayType );54 void postvisit( ReferenceType * refType );55 void postvisit( FunctionType * functionType );56 void postvisit( StructInstType * aggregateUseType );57 void postvisit( UnionInstType * aggregateUseType );58 void postvisit( EnumInstType * aggregateUseType );59 void postvisit( TypeInstType * aggregateUseType );60 void postvisit( TraitInstType * inst );61 void postvisit( TupleType * tupleType );62 void postvisit( VarArgsType * varArgsType );63 void postvisit( ZeroType * zeroType );64 void postvisit( OneType * oneType );65 void postvisit( QualifiedType * qualType );44 void previsit( const BaseSyntaxNode * ) { visit_children = false; } 45 46 void postvisit( const ObjectDecl * declaration ); 47 void postvisit( const FunctionDecl * declaration ); 48 void postvisit( const TypeDecl * declaration ); 49 50 void postvisit( const VoidType * voidType ); 51 void postvisit( const BasicType * basicType ); 52 void postvisit( const PointerType * pointerType ); 53 void postvisit( const ArrayType * arrayType ); 54 void postvisit( const ReferenceType * refType ); 55 void postvisit( const FunctionType * functionType ); 56 void postvisit( const StructInstType * aggregateUseType ); 57 void postvisit( const UnionInstType * aggregateUseType ); 58 void postvisit( const EnumInstType * aggregateUseType ); 59 void postvisit( const TypeInstType * aggregateUseType ); 60 void postvisit( const TraitInstType * inst ); 61 void postvisit( const TupleType * tupleType ); 62 void postvisit( const VarArgsType * varArgsType ); 63 void postvisit( const ZeroType * zeroType ); 64 void postvisit( const OneType * oneType ); 65 void postvisit( const QualifiedType * qualType ); 66 66 67 67 std::string get_mangleName() { return mangleName.str(); } … … 79 79 80 80 public: 81 Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 81 Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 82 82 int nextVarNum, const VarMapType& varNums ); 83 83 84 84 private: 85 void mangleDecl( DeclarationWithType *declaration );86 void mangleRef( ReferenceToType *refType, std::string prefix );87 88 void printQualifiers( Type *type );85 void mangleDecl( const DeclarationWithType * declaration ); 86 void mangleRef( const ReferenceToType * refType, std::string prefix ); 87 88 void printQualifiers( const Type *type ); 89 89 }; // Mangler_old 90 90 } // namespace 91 91 92 std::string mangle( BaseSyntaxNode * decl, bool mangleOverridable, bool typeMode, bool mangleGenericParams ) {92 std::string mangle( const BaseSyntaxNode * decl, bool mangleOverridable, bool typeMode, bool mangleGenericParams ) { 93 93 PassVisitor<Mangler_old> mangler( mangleOverridable, typeMode, mangleGenericParams ); 94 94 maybeAccept( decl, mangler ); … … 96 96 } 97 97 98 std::string mangleType( Type * ty ) {98 std::string mangleType( const Type * ty ) { 99 99 PassVisitor<Mangler_old> mangler( false, true, true ); 100 100 maybeAccept( ty, mangler ); … … 102 102 } 103 103 104 std::string mangleConcrete( Type * ty ) {104 std::string mangleConcrete( const Type * ty ) { 105 105 PassVisitor<Mangler_old> mangler( false, false, false ); 106 106 maybeAccept( ty, mangler ); … … 110 110 namespace { 111 111 Mangler_old::Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams ) 112 : nextVarNum( 0 ), isTopLevel( true ), 113 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 112 : nextVarNum( 0 ), isTopLevel( true ), 113 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 114 114 mangleGenericParams( mangleGenericParams ) {} 115 116 Mangler_old::Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 115 116 Mangler_old::Mangler_old( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 117 117 int nextVarNum, const VarMapType& varNums ) 118 : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ), 119 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 118 : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ), 119 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 120 120 mangleGenericParams( mangleGenericParams ) {} 121 121 122 void Mangler_old::mangleDecl( DeclarationWithType * declaration ) {122 void Mangler_old::mangleDecl( const DeclarationWithType * declaration ) { 123 123 bool wasTopLevel = isTopLevel; 124 124 if ( isTopLevel ) { … … 150 150 } 151 151 152 void Mangler_old::postvisit( ObjectDecl * declaration ) {152 void Mangler_old::postvisit( const ObjectDecl * declaration ) { 153 153 mangleDecl( declaration ); 154 154 } 155 155 156 void Mangler_old::postvisit( FunctionDecl * declaration ) {156 void Mangler_old::postvisit( const FunctionDecl * declaration ) { 157 157 mangleDecl( declaration ); 158 158 } 159 159 160 void Mangler_old::postvisit( VoidType * voidType ) {160 void Mangler_old::postvisit( const VoidType * voidType ) { 161 161 printQualifiers( voidType ); 162 162 mangleName << Encoding::void_t; 163 163 } 164 164 165 void Mangler_old::postvisit( BasicType * basicType ) {165 void Mangler_old::postvisit( const BasicType * basicType ) { 166 166 printQualifiers( basicType ); 167 assertf( basicType-> get_kind() < BasicType::NUMBER_OF_BASIC_TYPES, "Unhandled basic type: %d", basicType->get_kind());168 mangleName << Encoding::basicTypes[ basicType-> get_kind()];169 } 170 171 void Mangler_old::postvisit( PointerType * pointerType ) {167 assertf( basicType->kind < BasicType::NUMBER_OF_BASIC_TYPES, "Unhandled basic type: %d", basicType->kind ); 168 mangleName << Encoding::basicTypes[ basicType->kind ]; 169 } 170 171 void Mangler_old::postvisit( const PointerType * pointerType ) { 172 172 printQualifiers( pointerType ); 173 173 // mangle void (*f)() and void f() to the same name to prevent overloading on functions and function pointers … … 176 176 } 177 177 178 void Mangler_old::postvisit( ArrayType * arrayType ) {178 void Mangler_old::postvisit( const ArrayType * arrayType ) { 179 179 // TODO: encode dimension 180 180 printQualifiers( arrayType ); … … 183 183 } 184 184 185 void Mangler_old::postvisit( ReferenceType * refType ) {185 void Mangler_old::postvisit( const ReferenceType * refType ) { 186 186 // don't print prefix (e.g. 'R') for reference types so that references and non-references do not overload. 187 187 // Further, do not print the qualifiers for a reference type (but do run printQualifers because of TypeDecls, etc.), … … 202 202 } 203 203 204 void Mangler_old::postvisit( FunctionType * functionType ) {204 void Mangler_old::postvisit( const FunctionType * functionType ) { 205 205 printQualifiers( functionType ); 206 206 mangleName << Encoding::function; … … 219 219 } 220 220 221 void Mangler_old::mangleRef( ReferenceToType * refType, std::string prefix ) {221 void Mangler_old::mangleRef( const ReferenceToType * refType, std::string prefix ) { 222 222 printQualifiers( refType ); 223 223 … … 225 225 226 226 if ( mangleGenericParams ) { 227 std::list< Expression* >& params = refType->parameters;227 const std::list< Expression* > & params = refType->parameters; 228 228 if ( ! params.empty() ) { 229 229 mangleName << "_"; 230 for ( std::list< Expression* >::const_iterator param = params.begin(); param != params.end(); ++param) {231 TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );232 assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString( *param));230 for ( const Expression * param : params ) { 231 const TypeExpr * paramType = dynamic_cast< const TypeExpr * >( param ); 232 assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString(param)); 233 233 maybeAccept( paramType->type, *visitor ); 234 234 } … … 238 238 } 239 239 240 void Mangler_old::postvisit( StructInstType * aggregateUseType ) {240 void Mangler_old::postvisit( const StructInstType * aggregateUseType ) { 241 241 mangleRef( aggregateUseType, Encoding::struct_t ); 242 242 } 243 243 244 void Mangler_old::postvisit( UnionInstType * aggregateUseType ) {244 void Mangler_old::postvisit( const UnionInstType * aggregateUseType ) { 245 245 mangleRef( aggregateUseType, Encoding::union_t ); 246 246 } 247 247 248 void Mangler_old::postvisit( EnumInstType * aggregateUseType ) {248 void Mangler_old::postvisit( const EnumInstType * aggregateUseType ) { 249 249 mangleRef( aggregateUseType, Encoding::enum_t ); 250 250 } 251 251 252 void Mangler_old::postvisit( TypeInstType * typeInst ) {252 void Mangler_old::postvisit( const TypeInstType * typeInst ) { 253 253 VarMapType::iterator varNum = varNums.find( typeInst->get_name() ); 254 254 if ( varNum == varNums.end() ) { … … 266 266 } 267 267 268 void Mangler_old::postvisit( TraitInstType * inst ) {268 void Mangler_old::postvisit( const TraitInstType * inst ) { 269 269 printQualifiers( inst ); 270 270 mangleName << inst->name.size() << inst->name; 271 271 } 272 272 273 void Mangler_old::postvisit( TupleType * tupleType ) {273 void Mangler_old::postvisit( const TupleType * tupleType ) { 274 274 printQualifiers( tupleType ); 275 275 mangleName << Encoding::tuple << tupleType->types.size(); … … 277 277 } 278 278 279 void Mangler_old::postvisit( VarArgsType * varArgsType ) {279 void Mangler_old::postvisit( const VarArgsType * varArgsType ) { 280 280 printQualifiers( varArgsType ); 281 281 static const std::string vargs = "__builtin_va_list"; … … 283 283 } 284 284 285 void Mangler_old::postvisit( ZeroType * ) {285 void Mangler_old::postvisit( const ZeroType * ) { 286 286 mangleName << Encoding::zero; 287 287 } 288 288 289 void Mangler_old::postvisit( OneType * ) {289 void Mangler_old::postvisit( const OneType * ) { 290 290 mangleName << Encoding::one; 291 291 } 292 292 293 void Mangler_old::postvisit( QualifiedType * qualType ) {293 void Mangler_old::postvisit( const QualifiedType * qualType ) { 294 294 bool inqual = inQualifiedType; 295 295 if (! inqual ) { … … 307 307 } 308 308 309 void Mangler_old::postvisit( TypeDecl * decl ) {309 void Mangler_old::postvisit( const TypeDecl * decl ) { 310 310 // TODO: is there any case where mangling a TypeDecl makes sense? If so, this code needs to be 311 311 // fixed to ensure that two TypeDecls mangle to the same name when they are the same type and vice versa. … … 314 314 // aside from the assert false. 315 315 assertf(false, "Mangler_old should not visit typedecl: %s", toCString(decl)); 316 assertf( decl-> get_kind() < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->get_kind());317 mangleName << Encoding::typeVariables[ decl-> get_kind()] << ( decl->name.length() ) << decl->name;316 assertf( decl->kind < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind ); 317 mangleName << Encoding::typeVariables[ decl->kind ] << ( decl->name.length() ) << decl->name; 318 318 } 319 319 … … 324 324 } 325 325 326 void Mangler_old::printQualifiers( Type * type ) {326 void Mangler_old::printQualifiers( const Type * type ) { 327 327 // skip if not including qualifiers 328 328 if ( typeMode ) return; 329 if ( ! type-> get_forall().empty() ) {329 if ( ! type->forall.empty() ) { 330 330 std::list< std::string > assertionNames; 331 331 int dcount = 0, fcount = 0, vcount = 0, acount = 0; 332 332 mangleName << Encoding::forall; 333 for ( Type::ForallList::iterator i = type->forall.begin(); i != type->forall.end(); ++i) {334 switch ( (*i)->get_kind()) {333 for ( const TypeDecl * i : type->forall ) { 334 switch ( i->kind ) { 335 335 case TypeDecl::Dtype: 336 336 dcount++; … … 345 345 assert( false ); 346 346 } // switch 347 varNums[ (*i)->name ] = std::make_pair( nextVarNum, (int)(*i)->get_kind());348 for ( std::list< DeclarationWithType* >::iterator assert = (*i)->assertions.begin(); assert != (*i)->assertions.end(); ++assert) {349 PassVisitor<Mangler_old> sub_mangler( 347 varNums[ i->name ] = std::make_pair( nextVarNum, (int)i->kind ); 348 for ( const DeclarationWithType * assert : i->assertions ) { 349 PassVisitor<Mangler_old> sub_mangler( 350 350 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums ); 351 (*assert)->accept( sub_mangler );351 assert->accept( sub_mangler ); 352 352 assertionNames.push_back( sub_mangler.pass.get_mangleName() ); 353 353 acount++; … … 436 436 437 437 private: 438 Mangler_new( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 438 Mangler_new( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 439 439 int nextVarNum, const VarMapType& varNums ); 440 440 friend class ast::Pass<Mangler_new>; … … 457 457 namespace { 458 458 Mangler_new::Mangler_new( Mangle::Mode mode ) 459 : nextVarNum( 0 ), isTopLevel( true ), 459 : nextVarNum( 0 ), isTopLevel( true ), 460 460 mangleOverridable ( ! mode.no_overrideable ), 461 typeMode ( mode.type ), 461 typeMode ( mode.type ), 462 462 mangleGenericParams( ! mode.no_generic_params ) {} 463 464 Mangler_new::Mangler_new( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 463 464 Mangler_new::Mangler_new( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 465 465 int nextVarNum, const VarMapType& varNums ) 466 : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ), 467 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 466 : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ), 467 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 468 468 mangleGenericParams( mangleGenericParams ) {} 469 469 … … 693 693 varNums[ decl->name ] = std::make_pair( nextVarNum, (int)decl->kind ); 694 694 for ( const ast::DeclWithType * assert : decl->assertions ) { 695 ast::Pass<Mangler_new> sub_mangler( 695 ast::Pass<Mangler_new> sub_mangler( 696 696 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums ); 697 697 assert->accept( sub_mangler ); -
TabularUnified src/SymTab/Mangler.h ¶
r8fd52e90 r6f096d2 40 40 namespace Mangler { 41 41 /// Mangle syntax tree object; primary interface to clients 42 std::string mangle( BaseSyntaxNode * decl, bool mangleOverridable = true, bool typeMode = false, bool mangleGenericParams = true );42 std::string mangle( const BaseSyntaxNode * decl, bool mangleOverridable = true, bool typeMode = false, bool mangleGenericParams = true ); 43 43 44 44 /// Mangle a type name; secondary interface 45 std::string mangleType( Type* ty );45 std::string mangleType( const Type * ty ); 46 46 /// Mangle ignoring generic type parameters 47 std::string mangleConcrete( Type* ty );47 std::string mangleConcrete( const Type * ty ); 48 48 49 49 namespace Encoding {
Note: See TracChangeset
for help on using the changeset viewer.