Changes in src/SymTab/Mangler.cc [6f096d2:1346914]
- File:
-
- 1 edited
-
src/SymTab/Mangler.cc (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Mangler.cc
r6f096d2 r1346914 42 42 Mangler_old( const Mangler_old & ) = delete; 43 43 44 void previsit( constBaseSyntaxNode * ) { visit_children = false; }45 46 void postvisit( constObjectDecl * declaration );47 void postvisit( constFunctionDecl * declaration );48 void postvisit( constTypeDecl * declaration );49 50 void postvisit( constVoidType * voidType );51 void postvisit( constBasicType * basicType );52 void postvisit( constPointerType * pointerType );53 void postvisit( constArrayType * arrayType );54 void postvisit( constReferenceType * refType );55 void postvisit( constFunctionType * functionType );56 void postvisit( constStructInstType * aggregateUseType );57 void postvisit( constUnionInstType * aggregateUseType );58 void postvisit( constEnumInstType * aggregateUseType );59 void postvisit( constTypeInstType * aggregateUseType );60 void postvisit( constTraitInstType * inst );61 void postvisit( constTupleType * tupleType );62 void postvisit( constVarArgsType * varArgsType );63 void postvisit( constZeroType * zeroType );64 void postvisit( constOneType * oneType );65 void postvisit( constQualifiedType * qualType );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 ); 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( const DeclarationWithType *declaration );86 void mangleRef( const ReferenceToType *refType, std::string prefix );87 88 void printQualifiers( constType *type );85 void mangleDecl( DeclarationWithType *declaration ); 86 void mangleRef( ReferenceToType *refType, std::string prefix ); 87 88 void printQualifiers( Type *type ); 89 89 }; // Mangler_old 90 90 } // namespace 91 91 92 std::string mangle( constBaseSyntaxNode * decl, bool mangleOverridable, bool typeMode, bool mangleGenericParams ) {92 std::string mangle( 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( constType * ty ) {98 std::string mangleType( Type * ty ) { 99 99 PassVisitor<Mangler_old> mangler( false, true, true ); 100 100 maybeAccept( ty, mangler ); … … 102 102 } 103 103 104 std::string mangleConcrete( constType * ty ) {104 std::string mangleConcrete( 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( constDeclarationWithType * declaration ) {122 void Mangler_old::mangleDecl( DeclarationWithType * declaration ) { 123 123 bool wasTopLevel = isTopLevel; 124 124 if ( isTopLevel ) { … … 150 150 } 151 151 152 void Mangler_old::postvisit( constObjectDecl * declaration ) {152 void Mangler_old::postvisit( ObjectDecl * declaration ) { 153 153 mangleDecl( declaration ); 154 154 } 155 155 156 void Mangler_old::postvisit( constFunctionDecl * declaration ) {156 void Mangler_old::postvisit( FunctionDecl * declaration ) { 157 157 mangleDecl( declaration ); 158 158 } 159 159 160 void Mangler_old::postvisit( constVoidType * voidType ) {160 void Mangler_old::postvisit( VoidType * voidType ) { 161 161 printQualifiers( voidType ); 162 162 mangleName << Encoding::void_t; 163 163 } 164 164 165 void Mangler_old::postvisit( constBasicType * basicType ) {165 void Mangler_old::postvisit( BasicType * basicType ) { 166 166 printQualifiers( basicType ); 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( constPointerType * pointerType ) {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 ) { 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( constArrayType * arrayType ) {178 void Mangler_old::postvisit( ArrayType * arrayType ) { 179 179 // TODO: encode dimension 180 180 printQualifiers( arrayType ); … … 183 183 } 184 184 185 void Mangler_old::postvisit( constReferenceType * refType ) {185 void Mangler_old::postvisit( 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( constFunctionType * functionType ) {204 void Mangler_old::postvisit( FunctionType * functionType ) { 205 205 printQualifiers( functionType ); 206 206 mangleName << Encoding::function; … … 219 219 } 220 220 221 void Mangler_old::mangleRef( constReferenceToType * refType, std::string prefix ) {221 void Mangler_old::mangleRef( ReferenceToType * refType, std::string prefix ) { 222 222 printQualifiers( refType ); 223 223 … … 225 225 226 226 if ( mangleGenericParams ) { 227 const std::list< Expression* >& params = refType->parameters;227 std::list< Expression* >& params = refType->parameters; 228 228 if ( ! params.empty() ) { 229 229 mangleName << "_"; 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));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)); 233 233 maybeAccept( paramType->type, *visitor ); 234 234 } … … 238 238 } 239 239 240 void Mangler_old::postvisit( constStructInstType * aggregateUseType ) {240 void Mangler_old::postvisit( StructInstType * aggregateUseType ) { 241 241 mangleRef( aggregateUseType, Encoding::struct_t ); 242 242 } 243 243 244 void Mangler_old::postvisit( constUnionInstType * aggregateUseType ) {244 void Mangler_old::postvisit( UnionInstType * aggregateUseType ) { 245 245 mangleRef( aggregateUseType, Encoding::union_t ); 246 246 } 247 247 248 void Mangler_old::postvisit( constEnumInstType * aggregateUseType ) {248 void Mangler_old::postvisit( EnumInstType * aggregateUseType ) { 249 249 mangleRef( aggregateUseType, Encoding::enum_t ); 250 250 } 251 251 252 void Mangler_old::postvisit( constTypeInstType * typeInst ) {252 void Mangler_old::postvisit( 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( constTraitInstType * inst ) {268 void Mangler_old::postvisit( TraitInstType * inst ) { 269 269 printQualifiers( inst ); 270 270 mangleName << inst->name.size() << inst->name; 271 271 } 272 272 273 void Mangler_old::postvisit( constTupleType * tupleType ) {273 void Mangler_old::postvisit( TupleType * tupleType ) { 274 274 printQualifiers( tupleType ); 275 275 mangleName << Encoding::tuple << tupleType->types.size(); … … 277 277 } 278 278 279 void Mangler_old::postvisit( constVarArgsType * varArgsType ) {279 void Mangler_old::postvisit( 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( constZeroType * ) {285 void Mangler_old::postvisit( ZeroType * ) { 286 286 mangleName << Encoding::zero; 287 287 } 288 288 289 void Mangler_old::postvisit( constOneType * ) {289 void Mangler_old::postvisit( OneType * ) { 290 290 mangleName << Encoding::one; 291 291 } 292 292 293 void Mangler_old::postvisit( constQualifiedType * qualType ) {293 void Mangler_old::postvisit( QualifiedType * qualType ) { 294 294 bool inqual = inQualifiedType; 295 295 if (! inqual ) { … … 307 307 } 308 308 309 void Mangler_old::postvisit( constTypeDecl * decl ) {309 void Mangler_old::postvisit( 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-> kind < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind);317 mangleName << Encoding::typeVariables[ decl-> kind] << ( decl->name.length() ) << decl->name;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; 318 318 } 319 319 … … 324 324 } 325 325 326 void Mangler_old::printQualifiers( constType * type ) {326 void Mangler_old::printQualifiers( Type * type ) { 327 327 // skip if not including qualifiers 328 328 if ( typeMode ) return; 329 if ( ! type-> forall.empty() ) {329 if ( ! type->get_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 ( const TypeDecl * i : type->forall) {334 switch ( i->kind) {333 for ( Type::ForallList::iterator i = type->forall.begin(); i != type->forall.end(); ++i ) { 334 switch ( (*i)->get_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->kind);348 for ( const DeclarationWithType * assert : i->assertions) {349 PassVisitor<Mangler_old> sub_mangler( 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( 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 );
Note:
See TracChangeset
for help on using the changeset viewer.