Changeset ea3eb06 for translator/SymTab
- Timestamp:
- Nov 22, 2014, 4:51:46 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- d11f789
- Parents:
- 3c70d38
- Location:
- translator/SymTab
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SymTab/Mangler.cc
r3c70d38 rea3eb06 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Mangler.cc,v 1.13 2005/08/29 20:14:18 rcbilson Exp $5 *6 */7 8 1 #include <cassert> 9 2 #include <string> … … 22 15 23 16 namespace SymTab { 24 25 Mangler::Mangler() 26 : nextVarNum( 0 ), isTopLevel( true ) 27 { 28 } 17 Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) 18 {} 29 19 30 20 //Mangler::Mangler( const Mangler & ) … … 32 22 //{ 33 23 //} 34 Mangler::Mangler( const Mangler &rhs ) 35 : mangleName() 36 { 37 varNums = rhs.varNums; 38 nextVarNum = rhs.nextVarNum; 39 isTopLevel = rhs.isTopLevel; 40 } 41 42 void 43 Mangler::mangleDecl(DeclarationWithType *declaration) 44 { 45 bool wasTopLevel = isTopLevel; 46 if( isTopLevel ) { 47 varNums.clear(); 48 nextVarNum = 0; 49 isTopLevel = false; 50 } 51 mangleName << "__"; 52 CodeGen::OperatorInfo opInfo; 53 if( operatorLookup( declaration->get_name(), opInfo ) ) { 54 mangleName << opInfo.outputName; 55 } else { 56 mangleName << declaration->get_name(); 57 } 58 mangleName << "__"; 59 maybeAccept( declaration->get_type(), *this ); 60 isTopLevel = wasTopLevel; 61 } 62 63 void 64 Mangler::visit(ObjectDecl *declaration) 65 { 66 mangleDecl( declaration ); 67 } 68 69 void 70 Mangler::visit(FunctionDecl *declaration) 71 { 72 mangleDecl( declaration ); 73 } 74 75 void 76 Mangler::visit(VoidType *voidType) 77 { 78 printQualifiers( voidType ); 79 mangleName << "v"; 80 } 81 82 void 83 Mangler::visit(BasicType *basicType) 84 { 85 static const char *btLetter[] = { 86 "b", // Bool 87 "c", // Char 88 "Sc", // SignedChar 89 "Uc", // UnsignedChar 90 "s", // ShortSignedInt 91 "Us", // ShortUnsignedInt 92 "i", // SignedInt 93 "Ui", // UnsignedInt 94 "l", // LongSignedInt 95 "Ul", // LongUnsignedInt 96 "q", // LongLongSignedInt 97 "Uq", // LongLongUnsignedInt 98 "f", // Float 99 "d", // Double 100 "r", // LongDouble 101 "Xf", // FloatComplex 102 "Xd", // DoubleComplex 103 "Xr", // LongDoubleComplex 104 "If", // FloatImaginary 105 "Id", // DoubleImaginary 106 "Ir", // LongDoubleImaginary 107 }; 24 Mangler::Mangler( const Mangler &rhs ) : mangleName() { 25 varNums = rhs.varNums; 26 nextVarNum = rhs.nextVarNum; 27 isTopLevel = rhs.isTopLevel; 28 } 29 30 void Mangler::mangleDecl( DeclarationWithType *declaration ) { 31 bool wasTopLevel = isTopLevel; 32 if ( isTopLevel ) { 33 varNums.clear(); 34 nextVarNum = 0; 35 isTopLevel = false; 36 } 37 mangleName << "__"; 38 CodeGen::OperatorInfo opInfo; 39 if ( operatorLookup( declaration->get_name(), opInfo ) ) { 40 mangleName << opInfo.outputName; 41 } else { 42 mangleName << declaration->get_name(); 43 } 44 mangleName << "__"; 45 maybeAccept( declaration->get_type(), *this ); 46 isTopLevel = wasTopLevel; 47 } 48 49 void Mangler::visit( ObjectDecl *declaration ) { 50 mangleDecl( declaration ); 51 } 52 53 void Mangler::visit( FunctionDecl *declaration ) { 54 mangleDecl( declaration ); 55 } 56 57 void Mangler::visit( VoidType *voidType ) { 58 printQualifiers( voidType ); 59 mangleName << "v"; 60 } 61 62 void Mangler::visit( BasicType *basicType ) { 63 static const char *btLetter[] = { 64 "b", // Bool 65 "c", // Char 66 "Sc", // SignedChar 67 "Uc", // UnsignedChar 68 "s", // ShortSignedInt 69 "Us", // ShortUnsignedInt 70 "i", // SignedInt 71 "Ui", // UnsignedInt 72 "l", // LongSignedInt 73 "Ul", // LongUnsignedInt 74 "q", // LongLongSignedInt 75 "Uq", // LongLongUnsignedInt 76 "f", // Float 77 "d", // Double 78 "r", // LongDouble 79 "Xf", // FloatComplex 80 "Xd", // DoubleComplex 81 "Xr", // LongDoubleComplex 82 "If", // FloatImaginary 83 "Id", // DoubleImaginary 84 "Ir", // LongDoubleImaginary 85 }; 108 86 109 printQualifiers( basicType ); 110 mangleName << btLetter[ basicType->get_kind() ]; 111 } 112 113 void 114 Mangler::visit(PointerType *pointerType) 115 { 116 printQualifiers( pointerType ); 117 mangleName << "P"; 118 maybeAccept( pointerType->get_base(), *this ); 119 } 120 121 void 122 Mangler::visit(ArrayType *arrayType) 123 { 124 // TODO: encode dimension 125 printQualifiers( arrayType ); 126 mangleName << "A0"; 127 maybeAccept( arrayType->get_base(), *this ); 128 } 129 130 namespace { 131 inline std::list< Type* > 132 getTypes( const std::list< DeclarationWithType* > decls ) 133 { 134 std::list< Type* > ret; 135 std::transform( decls.begin(), decls.end(), std::back_inserter( ret ), 136 std::mem_fun( &DeclarationWithType::get_type ) ); 137 return ret; 138 } 139 } 140 141 void 142 Mangler::visit(FunctionType *functionType) 143 { 144 printQualifiers( functionType ); 145 mangleName << "F"; 146 std::list< Type* > returnTypes = getTypes( functionType->get_returnVals() ); 147 acceptAll( returnTypes, *this ); 148 mangleName << "_"; 149 std::list< Type* > paramTypes = getTypes( functionType->get_parameters() ); 150 acceptAll( paramTypes, *this ); 151 mangleName << "_"; 152 } 153 154 void 155 Mangler::mangleRef(ReferenceToType *refType, std::string prefix) 156 { 157 printQualifiers( refType ); 158 mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name(); 159 } 160 161 void 162 Mangler::visit(StructInstType *aggregateUseType) 163 { 164 mangleRef( aggregateUseType, "s" ); 165 } 166 167 void 168 Mangler::visit(UnionInstType *aggregateUseType) 169 { 170 mangleRef( aggregateUseType, "u" ); 171 } 172 173 void 174 Mangler::visit(EnumInstType *aggregateUseType) 175 { 176 mangleRef( aggregateUseType, "e" ); 177 } 178 179 void 180 Mangler::visit(TypeInstType *typeInst) 181 { 182 VarMapType::iterator varNum = varNums.find( typeInst->get_name() ); 183 if( varNum == varNums.end() ) { 184 mangleRef( typeInst, "t" ); 185 } else { 186 printQualifiers( typeInst ); 187 std::ostrstream numStream; 188 numStream << varNum->second.first; 189 mangleName << (numStream.pcount() + 1); 190 switch( (TypeDecl::Kind)varNum->second.second ) { 191 case TypeDecl::Any: 192 mangleName << "t"; 193 break; 194 case TypeDecl::Dtype: 195 mangleName << "d"; 196 break; 197 case TypeDecl::Ftype: 198 mangleName << "f"; 199 break; 200 } 201 mangleName << std::string( numStream.str(), numStream.pcount() ); 202 } 203 } 204 205 void 206 Mangler::visit(TupleType *tupleType) 207 { 208 printQualifiers( tupleType ); 209 mangleName << "T"; 210 acceptAll( tupleType->get_types(), *this ); 211 mangleName << "_"; 212 } 213 214 void 215 Mangler::visit(TypeDecl *decl) 216 { 217 static const char *typePrefix[] = { "BT", "BD", "BF" }; 218 mangleName << typePrefix[ decl->get_kind() ] << ( decl->get_name().length() + 1 ) << decl->get_name(); 219 } 220 221 void 222 printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) 223 { 224 for( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) { 225 os << i->first << "(" << i->second.first << "/" << i->second.second << ")" << std::endl; 226 } 227 } 228 229 void 230 Mangler::printQualifiers( Type *type ) 231 { 232 if( !type->get_forall().empty() ) { 233 std::list< std::string > assertionNames; 234 int tcount = 0, dcount = 0, fcount = 0; 235 mangleName << "A"; 236 for( std::list< TypeDecl* >::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) { 237 switch( (*i)->get_kind() ) { 238 case TypeDecl::Any: 239 tcount++; 240 break; 241 case TypeDecl::Dtype: 242 dcount++; 243 break; 244 case TypeDecl::Ftype: 245 fcount++; 246 break; 247 } 248 varNums[ (*i)->get_name() ] = std::pair< int, int >( nextVarNum++, (int)(*i)->get_kind() ); 249 for( std::list< DeclarationWithType* >::iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) { 250 Mangler sub_mangler; 251 sub_mangler.nextVarNum = nextVarNum; 252 sub_mangler.isTopLevel = false; 253 sub_mangler.varNums = varNums; 254 (*assert)->accept( sub_mangler ); 255 assertionNames.push_back( std::string( sub_mangler.mangleName.str(), sub_mangler.mangleName.pcount() ) ); 256 } 257 } 258 mangleName << tcount << "_" << dcount << "_" << fcount << "_"; 259 std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) ); 260 mangleName << "_"; 261 } 262 if( type->get_isConst() ) { 263 mangleName << "C"; 264 } 265 if( type->get_isVolatile() ) { 266 mangleName << "V"; 267 } 268 if( type->get_isRestrict() ) { 269 mangleName << "R"; 270 } 271 if( type->get_isLvalue() ) { 272 mangleName << "L"; 273 } 274 } 275 276 277 } // namespace SymTab 87 printQualifiers( basicType ); 88 mangleName << btLetter[ basicType->get_kind() ]; 89 } 90 91 void Mangler::visit( PointerType *pointerType ) { 92 printQualifiers( pointerType ); 93 mangleName << "P"; 94 maybeAccept( pointerType->get_base(), *this ); 95 } 96 97 void Mangler::visit( ArrayType *arrayType ) { 98 // TODO: encode dimension 99 printQualifiers( arrayType ); 100 mangleName << "A0"; 101 maybeAccept( arrayType->get_base(), *this ); 102 } 103 104 namespace { 105 inline std::list< Type* > 106 getTypes( const std::list< DeclarationWithType* > decls ) 107 { 108 std::list< Type* > ret; 109 std::transform( decls.begin(), decls.end(), std::back_inserter( ret ), 110 std::mem_fun( &DeclarationWithType::get_type ) ); 111 return ret; 112 } 113 } 114 115 void Mangler::visit( FunctionType *functionType ) { 116 printQualifiers( functionType ); 117 mangleName << "F"; 118 std::list< Type* > returnTypes = getTypes( functionType->get_returnVals() ); 119 acceptAll( returnTypes, *this ); 120 mangleName << "_"; 121 std::list< Type* > paramTypes = getTypes( functionType->get_parameters() ); 122 acceptAll( paramTypes, *this ); 123 mangleName << "_"; 124 } 125 126 void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) { 127 printQualifiers( refType ); 128 mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name(); 129 } 130 131 void Mangler::visit( StructInstType *aggregateUseType ) { 132 mangleRef( aggregateUseType, "s" ); 133 } 134 135 void Mangler::visit( UnionInstType *aggregateUseType ) { 136 mangleRef( aggregateUseType, "u" ); 137 } 138 139 void Mangler::visit( EnumInstType *aggregateUseType ) { 140 mangleRef( aggregateUseType, "e" ); 141 } 142 143 void Mangler::visit( TypeInstType *typeInst ) { 144 VarMapType::iterator varNum = varNums.find( typeInst->get_name() ); 145 if ( varNum == varNums.end() ) { 146 mangleRef( typeInst, "t" ); 147 } else { 148 printQualifiers( typeInst ); 149 std::ostrstream numStream; 150 numStream << varNum->second.first; 151 mangleName << (numStream.pcount() + 1); 152 switch ( (TypeDecl::Kind )varNum->second.second ) { 153 case TypeDecl::Any: 154 mangleName << "t"; 155 break; 156 case TypeDecl::Dtype: 157 mangleName << "d"; 158 break; 159 case TypeDecl::Ftype: 160 mangleName << "f"; 161 break; 162 } 163 mangleName << std::string( numStream.str(), numStream.pcount() ); 164 } 165 } 166 167 void Mangler::visit( TupleType *tupleType ) { 168 printQualifiers( tupleType ); 169 mangleName << "T"; 170 acceptAll( tupleType->get_types(), *this ); 171 mangleName << "_"; 172 } 173 174 void Mangler::visit( TypeDecl *decl ) { 175 static const char *typePrefix[] = { "BT", "BD", "BF" }; 176 mangleName << typePrefix[ decl->get_kind() ] << ( decl->get_name().length() + 1 ) << decl->get_name(); 177 } 178 179 void printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) { 180 for ( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) { 181 os << i->first << "(" << i->second.first << "/" << i->second.second << ")" << std::endl; 182 } 183 } 184 185 void Mangler::printQualifiers( Type *type ) { 186 if ( !type->get_forall().empty() ) { 187 std::list< std::string > assertionNames; 188 int tcount = 0, dcount = 0, fcount = 0; 189 mangleName << "A"; 190 for ( std::list< TypeDecl* >::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) { 191 switch ( (*i)->get_kind() ) { 192 case TypeDecl::Any: 193 tcount++; 194 break; 195 case TypeDecl::Dtype: 196 dcount++; 197 break; 198 case TypeDecl::Ftype: 199 fcount++; 200 break; 201 } 202 varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() ); 203 for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) { 204 Mangler sub_mangler; 205 sub_mangler.nextVarNum = nextVarNum; 206 sub_mangler.isTopLevel = false; 207 sub_mangler.varNums = varNums; 208 (*assert)->accept( sub_mangler ); 209 assertionNames.push_back( std::string( sub_mangler.mangleName.str(), sub_mangler.mangleName.pcount() ) ); 210 } 211 } 212 mangleName << tcount << "_" << dcount << "_" << fcount << "_"; 213 std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) ); 214 mangleName << "_"; 215 } 216 if ( type->get_isConst() ) { 217 mangleName << "C"; 218 } 219 if ( type->get_isVolatile() ) { 220 mangleName << "V"; 221 } 222 if ( type->get_isRestrict() ) { 223 mangleName << "R"; 224 } 225 if ( type->get_isLvalue() ) { 226 mangleName << "L"; 227 } 228 } 229 } // SymTab -
translator/SymTab/Mangler.h
r3c70d38 rea3eb06 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Mangler.h,v 1.6 2005/08/29 20:14:18 rcbilson Exp $5 *6 */7 8 1 #ifndef SYMTAB_MANGLER_H 9 2 #define SYMTAB_MANGLER_H … … 14 7 15 8 namespace SymTab { 16 17 class Mangler : public Visitor 18 { 19 public: 20 template< typename SynTreeClass > 21 static std::string mangle( SynTreeClass *decl ); // interface to clients 9 class Mangler : public Visitor { 10 public: 11 template< typename SynTreeClass > 12 static std::string mangle( SynTreeClass *decl ); // interface to clients 22 13 23 14 /// using Visitor::visit; 24 virtual void visit(ObjectDecl *declaration);25 virtual void visit(FunctionDecl *declaration);26 virtual void visit(TypeDecl *declaration);15 virtual void visit( ObjectDecl *declaration ); 16 virtual void visit( FunctionDecl *declaration ); 17 virtual void visit( TypeDecl *declaration ); 27 18 28 virtual void visit(VoidType *voidType);29 virtual void visit(BasicType *basicType);30 virtual void visit(PointerType *pointerType);31 virtual void visit(ArrayType *arrayType);32 virtual void visit(FunctionType *functionType);33 virtual void visit(StructInstType *aggregateUseType);34 virtual void visit(UnionInstType *aggregateUseType);35 virtual void visit(EnumInstType *aggregateUseType);36 virtual void visit(TypeInstType *aggregateUseType);37 virtual void visit(TupleType *tupleType);19 virtual void visit( VoidType *voidType ); 20 virtual void visit( BasicType *basicType ); 21 virtual void visit( PointerType *pointerType ); 22 virtual void visit( ArrayType *arrayType ); 23 virtual void visit( FunctionType *functionType ); 24 virtual void visit( StructInstType *aggregateUseType ); 25 virtual void visit( UnionInstType *aggregateUseType ); 26 virtual void visit( EnumInstType *aggregateUseType ); 27 virtual void visit( TypeInstType *aggregateUseType ); 28 virtual void visit( TupleType *tupleType ); 38 29 39 std::string get_mangleName() { return std::string( mangleName.str(), mangleName.pcount() ); } 30 std::string get_mangleName() { return std::string( mangleName.str(), mangleName.pcount() ); } 31 private: 32 std::ostrstream mangleName; 33 typedef std::map< std::string, std::pair< int, int > > VarMapType; 34 VarMapType varNums; 35 int nextVarNum; 36 bool isTopLevel; 37 38 Mangler(); 39 Mangler( const Mangler & ); 40 41 void mangleDecl( DeclarationWithType *declaration ); 42 void mangleRef( ReferenceToType *refType, std::string prefix ); 43 44 void printQualifiers( Type *type ); 45 }; // Mangler 40 46 41 private: 42 std::ostrstream mangleName; 43 typedef std::map< std::string, std::pair< int, int > > VarMapType; 44 VarMapType varNums; 45 int nextVarNum; 46 bool isTopLevel; 47 48 Mangler(); 49 Mangler( const Mangler & ); 50 51 void mangleDecl(DeclarationWithType *declaration); 52 void mangleRef(ReferenceToType *refType, std::string prefix); 53 54 void printQualifiers( Type *type ); 55 }; 47 template< typename SynTreeClass > 48 std::string Mangler::mangle( SynTreeClass *decl ) { 49 Mangler mangler; 50 maybeAccept( decl, mangler ); 51 return mangler.get_mangleName(); 52 } 53 } // SymTab 56 54 57 /* static class method */ 58 template< typename SynTreeClass > 59 std::string 60 Mangler::mangle( SynTreeClass *decl ) 61 { 62 Mangler mangler; 63 maybeAccept( decl, mangler ); 64 return mangler.get_mangleName(); 65 } 66 67 } // namespace SymTab 68 69 #endif /* #ifndef SYMTAB_MANGLER_H */ 55 #endif // SYMTAB_MANGLER_H -
translator/SymTab/StackTable.cc
r3c70d38 rea3eb06 1 /*2 * This file is part of the Cforall project3 *4 * $Id: StackTable.cc,v 1.3 2002/09/19 21:02:44 rcbilson Exp $5 *6 */7 8 1 #include <cassert> 9 2 … … 11 4 12 5 namespace SymTab { 6 template< typename Element, typename ConflictFunction > 7 StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) 8 {} 13 9 14 template< typename Element, typename ConflictFunction > 15 StackTable< Element, ConflictFunction >::StackTable() 16 : scopeLevel( 0 ) 17 { 18 } 10 template< typename Element, typename ConflictFunction > 11 void StackTable< Element, ConflictFunction >::enterScope() { 12 scopeLevel++; 13 } 19 14 20 template< typename Element, typename ConflictFunction > 21 void 22 StackTable< Element, ConflictFunction >::enterScope() 23 { 24 scopeLevel++; 25 } 15 template< typename Element, typename ConflictFunction > 16 void StackTable< Element, ConflictFunction >::leaveScope() { 17 for ( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) { 18 std::stack< Entry >& entry = it->second; 19 if ( !entry.empty() && entry.top().second == scopeLevel ) { 20 entry.pop(); 21 } 22 } 23 scopeLevel--; 24 assert( scopeLevel >= 0 ); 25 } 26 26 27 template< typename Element, typename ConflictFunction >28 void 29 StackTable< Element, ConflictFunction >::leaveScope() 30 {31 for( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) { 32 std::stack< Entry >& entry = it->second; 33 if( !entry.empty() && entry.top().second == scopeLevel ) { 34 entry.pop(); 27 template< typename Element, typename ConflictFunction > 28 void StackTable< Element, ConflictFunction >::add( Element *type ) { 29 std::stack< Entry >& entry = table[ type->get_name() ]; 30 if ( !entry.empty() && entry.top().second == scopeLevel ) { 31 entry.top().first = conflictFunction( entry.top().first, type ); 32 } else { 33 entry.push( Entry( type, scopeLevel ) ); 34 } 35 35 } 36 }37 38 scopeLevel--;39 assert( scopeLevel >= 0 );40 }41 36 42 template< typename Element, typename ConflictFunction > 43 void 44 StackTable< Element, ConflictFunction >::add( Element *type ) 45 { 46 std::stack< Entry >& entry = table[ type->get_name() ]; 47 if( !entry.empty() && entry.top().second == scopeLevel ) { 48 entry.top().first = conflictFunction( entry.top().first, type ); 49 } else { 50 entry.push( Entry( type, scopeLevel ) ); 51 } 52 } 37 template< typename Element, typename ConflictFunction > 38 void StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) { 39 add( new Element( fwdDeclName ) ); 40 } 53 41 54 template< typename Element, typename ConflictFunction > 55 void 56 StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) 57 { 58 add( new Element( fwdDeclName ) ); 59 } 42 template< typename Element, typename ConflictFunction > 43 Element *StackTable< Element, ConflictFunction >::lookup( std::string id ) const { 44 typename TableType::const_iterator it = table.find( id ); 45 if ( it == table.end() ) { 46 return 0; 47 } else if ( !it->second.empty() ) { 48 return it->second.top().first; 49 } else { 50 return 0; 51 } 52 } 60 53 61 template< typename Element, typename ConflictFunction > 62 Element * 63 StackTable< Element, ConflictFunction >::lookup( std::string id ) const 64 { 65 typename TableType::const_iterator it = table.find( id ); 66 if( it == table.end() ) { 67 return 0; 68 } else if( !it->second.empty() ) { 69 return it->second.top().first; 70 } else { 71 return 0; 72 } 73 } 74 75 template< typename Element, typename ConflictFunction > 76 void 77 StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const 78 { 79 for( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) { 80 const std::stack< Entry >& entry = it->second; 81 if( !entry.empty() && entry.top().second == scopeLevel ) { 82 os << it->first << std::endl; 54 template< typename Element, typename ConflictFunction > 55 void StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const { 56 for ( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) { 57 const std::stack< Entry >& entry = it->second; 58 if ( !entry.empty() && entry.top().second == scopeLevel ) { 59 os << it->first << std::endl; 60 } 61 } 83 62 } 84 } 85 } 86 87 } // namespace SymTab 63 } // SymTab -
translator/SymTab/StackTable.h
r3c70d38 rea3eb06 1 /*2 * This file is part of the Cforall project3 *4 * $Id: StackTable.h,v 1.2 2002/09/19 21:02:44 rcbilson Exp $5 *6 */7 8 1 #ifndef SYMTAB_STACKTABLE_H 9 2 #define SYMTAB_STACKTABLE_H … … 15 8 16 9 namespace SymTab { 10 template< typename Element, typename ConflictFunction > 11 class StackTable { 12 public: 13 StackTable(); 17 14 18 template< typename Element, typename ConflictFunction > 19 class StackTable 20 { 21 public: 22 StackTable();15 void enterScope(); 16 void leaveScope(); 17 void add( Element *type ); 18 void add( std::string fwdDeclName ); 19 Element *lookup( std::string id ) const; 23 20 24 void enterScope(); 25 void leaveScope(); 26 void add( Element *type ); 27 void add( std::string fwdDeclName ); 28 Element *lookup( std::string id ) const; 29 30 void dump( std::ostream &os ) const; // debugging 21 void dump( std::ostream &os ) const; // debugging 22 private: 23 typedef std::pair< Element*, int > Entry; 24 typedef std::map< std::string, std::stack< Entry > > TableType; 31 25 32 private: 33 typedef std::pair< Element*, int > Entry; 34 typedef std::map< std::string, std::stack< Entry > > TableType; 35 36 ConflictFunction conflictFunction; 37 TableType table; 38 int scopeLevel; 39 }; 40 41 } // namespace SymTab 26 ConflictFunction conflictFunction; 27 TableType table; 28 int scopeLevel; 29 }; 30 } // SymTab 42 31 43 32 #include "StackTable.cc" 44 33 45 #endif / * #ifndef SYMTAB_STACKTABLE_H */34 #endif // SYMTAB_STACKTABLE_H
Note: See TracChangeset
for help on using the changeset viewer.