Changeset a08ba92 for translator/SymTab
- Timestamp:
- May 19, 2015, 4:58:14 PM (11 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, stuck-waitfor-destruct, with_gc
- Children:
- 843054c2
- Parents:
- 01aeade
- Location:
- translator/SymTab
- Files:
-
- 11 edited
-
IdTable.cc (modified) (1 diff)
-
IdTable.h (modified) (4 diffs)
-
Indexer.cc (modified) (15 diffs)
-
Indexer.h (modified) (2 diffs)
-
Mangler.cc (modified) (9 diffs)
-
Mangler.h (modified) (4 diffs)
-
StackTable.cc (modified) (6 diffs)
-
StackTable.h (modified) (4 diffs)
-
TypeTable.h (modified) (3 diffs)
-
Validate.cc (modified) (38 diffs)
-
Validate.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
translator/SymTab/IdTable.cc
r01aeade ra08ba92 139 139 std::stack<DeclEntry> stack = inner->second; 140 140 os << "dumping a stack" << std::endl; 141 while ( ! stack.empty()) {141 while ( ! stack.empty()) { 142 142 DeclEntry d = stack.top(); 143 143 os << outer->first << " (" << inner->first << ") (" << d.second << ") " << std::endl; -
translator/SymTab/IdTable.h
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:30:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:31:45201513 // Update Count : 312 // Last Modified On : Tue May 19 16:49:33 2015 13 // Update Count : 4 14 14 // 15 15 … … 25 25 26 26 namespace SymTab { 27 class IdTable {28 public:27 class IdTable { 28 public: 29 29 IdTable(); 30 30 … … 36 36 37 37 void dump( std::ostream &os ) const; // debugging 38 private:38 private: 39 39 typedef std::pair< DeclarationWithType*, int > DeclEntry; 40 40 typedef std::map< std::string, std::stack< DeclEntry > > InnerTableType; … … 43 43 OuterTableType table; 44 44 int scopeLevel; 45 };45 }; 46 46 } // namespace SymTab 47 47 -
translator/SymTab/Indexer.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:37:33 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:38:44201513 // Update Count : 212 // Last Modified On : Tue May 19 16:49:55 2015 13 // Update Count : 3 14 14 // 15 15 … … 26 26 27 27 namespace SymTab { 28 Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {}29 30 Indexer::~Indexer() {}31 32 void Indexer::visit( ObjectDecl *objectDecl ) {28 Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {} 29 30 Indexer::~Indexer() {} 31 32 void Indexer::visit( ObjectDecl *objectDecl ) { 33 33 maybeAccept( objectDecl->get_type(), *this ); 34 34 maybeAccept( objectDecl->get_init(), *this ); … … 38 38 idTable.addDecl( objectDecl ); 39 39 } // if 40 }41 42 void Indexer::visit( FunctionDecl *functionDecl ) {40 } 41 42 void Indexer::visit( FunctionDecl *functionDecl ) { 43 43 if ( functionDecl->get_name() == "" ) return; 44 44 debugPrint( "Adding function " << functionDecl->get_name() << std::endl ); … … 49 49 maybeAccept( functionDecl->get_statements(), *this ); 50 50 leaveScope(); 51 }51 } 52 52 53 53 /******** … … 70 70 */ 71 71 72 void Indexer::visit( TypeDecl *typeDecl ) {72 void Indexer::visit( TypeDecl *typeDecl ) { 73 73 // see A NOTE ON THE ORDER OF TRAVERSAL, above 74 74 // note that assertions come after the type is added to the symtab, since they aren't part … … 81 81 typeTable.add( typeDecl ); 82 82 acceptAll( typeDecl->get_assertions(), *this ); 83 }84 85 void Indexer::visit( TypedefDecl *typeDecl ) {83 } 84 85 void Indexer::visit( TypedefDecl *typeDecl ) { 86 86 enterScope(); 87 87 acceptAll( typeDecl->get_parameters(), *this ); … … 90 90 debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl ); 91 91 typeTable.add( typeDecl ); 92 }93 94 void Indexer::visit( StructDecl *aggregateDecl ) {92 } 93 94 void Indexer::visit( StructDecl *aggregateDecl ) { 95 95 // make up a forward declaration and add it before processing the members 96 96 StructDecl fwdDecl( aggregateDecl->get_name() ); … … 107 107 // this addition replaces the forward declaration 108 108 structTable.add( aggregateDecl ); 109 }110 111 void Indexer::visit( UnionDecl *aggregateDecl ) {109 } 110 111 void Indexer::visit( UnionDecl *aggregateDecl ) { 112 112 // make up a forward declaration and add it before processing the members 113 113 UnionDecl fwdDecl( aggregateDecl->get_name() ); … … 123 123 debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl ); 124 124 unionTable.add( aggregateDecl ); 125 }126 127 void Indexer::visit( EnumDecl *aggregateDecl ) {125 } 126 127 void Indexer::visit( EnumDecl *aggregateDecl ) { 128 128 debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl ); 129 129 enumTable.add( aggregateDecl ); 130 130 // unlike structs, contexts, and unions, enums inject their members into the global scope 131 131 acceptAll( aggregateDecl->get_members(), *this ); 132 }133 134 void Indexer::visit( ContextDecl *aggregateDecl ) {132 } 133 134 void Indexer::visit( ContextDecl *aggregateDecl ) { 135 135 enterScope(); 136 136 acceptAll( aggregateDecl->get_parameters(), *this ); … … 140 140 debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl ); 141 141 contextTable.add( aggregateDecl ); 142 }143 144 void Indexer::visit( CompoundStmt *compoundStmt ) {142 } 143 144 void Indexer::visit( CompoundStmt *compoundStmt ) { 145 145 enterScope(); 146 146 acceptAll( compoundStmt->get_kids(), *this ); 147 147 leaveScope(); 148 }149 150 void Indexer::visit( ContextInstType *contextInst ) {148 } 149 150 void Indexer::visit( ContextInstType *contextInst ) { 151 151 acceptAll( contextInst->get_parameters(), *this ); 152 152 acceptAll( contextInst->get_members(), *this ); 153 }154 155 void Indexer::visit( StructInstType *structInst ) {153 } 154 155 void Indexer::visit( StructInstType *structInst ) { 156 156 if ( ! structTable.lookup( structInst->get_name() ) ) { 157 157 debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl ); … … 161 161 acceptAll( structInst->get_parameters(), *this ); 162 162 leaveScope(); 163 }164 165 void Indexer::visit( UnionInstType *unionInst ) {163 } 164 165 void Indexer::visit( UnionInstType *unionInst ) { 166 166 if ( ! unionTable.lookup( unionInst->get_name() ) ) { 167 167 debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl ); … … 171 171 acceptAll( unionInst->get_parameters(), *this ); 172 172 leaveScope(); 173 }174 175 void Indexer::visit( ForStmt *forStmt ) {176 // for statements introduce a level of scope177 enterScope();178 Visitor::visit( forStmt );179 leaveScope();180 }181 182 183 void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const {173 } 174 175 void Indexer::visit( ForStmt *forStmt ) { 176 // for statements introduce a level of scope 177 enterScope(); 178 Visitor::visit( forStmt ); 179 leaveScope(); 180 } 181 182 183 void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const { 184 184 idTable.lookupId( id, list ); 185 }186 187 DeclarationWithType* Indexer::lookupId( const std::string &id) const {185 } 186 187 DeclarationWithType* Indexer::lookupId( const std::string &id) const { 188 188 return idTable.lookupId(id); 189 }190 191 NamedTypeDecl *Indexer::lookupType( const std::string &id ) const {189 } 190 191 NamedTypeDecl *Indexer::lookupType( const std::string &id ) const { 192 192 return typeTable.lookup( id ); 193 }194 195 StructDecl *Indexer::lookupStruct( const std::string &id ) const {193 } 194 195 StructDecl *Indexer::lookupStruct( const std::string &id ) const { 196 196 return structTable.lookup( id ); 197 }198 199 EnumDecl *Indexer::lookupEnum( const std::string &id ) const {197 } 198 199 EnumDecl *Indexer::lookupEnum( const std::string &id ) const { 200 200 return enumTable.lookup( id ); 201 }202 203 UnionDecl *Indexer::lookupUnion( const std::string &id ) const {201 } 202 203 UnionDecl *Indexer::lookupUnion( const std::string &id ) const { 204 204 return unionTable.lookup( id ); 205 }206 207 ContextDecl * Indexer::lookupContext( const std::string &id ) const {205 } 206 207 ContextDecl * Indexer::lookupContext( const std::string &id ) const { 208 208 return contextTable.lookup( id ); 209 }210 211 void Indexer::enterScope() {209 } 210 211 void Indexer::enterScope() { 212 212 if ( doDebug ) { 213 213 std::cout << "--- Entering scope" << std::endl; … … 219 219 unionTable.enterScope(); 220 220 contextTable.enterScope(); 221 }222 223 void Indexer::leaveScope() {221 } 222 223 void Indexer::leaveScope() { 224 224 using std::cout; 225 225 using std::endl; … … 240 240 unionTable.leaveScope(); 241 241 contextTable.leaveScope(); 242 }243 244 void Indexer::print( std::ostream &os, int indent ) const {245 using std::cerr;246 using std::endl;247 248 cerr << "===idTable===" << endl;249 idTable.dump( os );250 cerr << "===typeTable===" << endl;251 typeTable.dump( os );252 cerr << "===structTable===" << endl;253 structTable.dump( os );254 cerr << "===enumTable===" << endl;255 enumTable.dump( os );256 cerr << "===unionTable===" << endl;257 unionTable.dump( os );258 cerr << "===contextTable===" << endl;259 contextTable.dump( os );242 } 243 244 void Indexer::print( std::ostream &os, int indent ) const { 245 using std::cerr; 246 using std::endl; 247 248 cerr << "===idTable===" << endl; 249 idTable.dump( os ); 250 cerr << "===typeTable===" << endl; 251 typeTable.dump( os ); 252 cerr << "===structTable===" << endl; 253 structTable.dump( os ); 254 cerr << "===enumTable===" << endl; 255 enumTable.dump( os ); 256 cerr << "===unionTable===" << endl; 257 unionTable.dump( os ); 258 cerr << "===contextTable===" << endl; 259 contextTable.dump( os ); 260 260 #if 0 261 261 idTable.dump( os ); … … 266 266 contextTable.dump( os ); 267 267 #endif 268 }268 } 269 269 } // namespace SymTab 270 270 -
translator/SymTab/Indexer.h
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:38:55 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:40:17201513 // Update Count : 212 // Last Modified On : Tue May 19 16:51:21 2015 13 // Update Count : 3 14 14 // 15 15 … … 27 27 28 28 namespace SymTab { 29 class Indexer : public Visitor {30 public:31 Indexer( bool useDebug = false );32 virtual ~Indexer();29 class Indexer : public Visitor { 30 public: 31 Indexer( bool useDebug = false ); 32 virtual ~Indexer(); 33 33 34 //using Visitor::visit;35 virtual void visit( ObjectDecl *objectDecl );36 virtual void visit( FunctionDecl *functionDecl );37 virtual void visit( TypeDecl *typeDecl );38 virtual void visit( TypedefDecl *typeDecl );39 virtual void visit( StructDecl *aggregateDecl );40 virtual void visit( UnionDecl *aggregateDecl );41 virtual void visit( EnumDecl *aggregateDecl );42 virtual void visit( ContextDecl *aggregateDecl );34 //using Visitor::visit; 35 virtual void visit( ObjectDecl *objectDecl ); 36 virtual void visit( FunctionDecl *functionDecl ); 37 virtual void visit( TypeDecl *typeDecl ); 38 virtual void visit( TypedefDecl *typeDecl ); 39 virtual void visit( StructDecl *aggregateDecl ); 40 virtual void visit( UnionDecl *aggregateDecl ); 41 virtual void visit( EnumDecl *aggregateDecl ); 42 virtual void visit( ContextDecl *aggregateDecl ); 43 43 44 virtual void visit( CompoundStmt *compoundStmt );44 virtual void visit( CompoundStmt *compoundStmt ); 45 45 46 virtual void visit( ContextInstType *contextInst );47 virtual void visit( StructInstType *contextInst );48 virtual void visit( UnionInstType *contextInst );46 virtual void visit( ContextInstType *contextInst ); 47 virtual void visit( StructInstType *contextInst ); 48 virtual void visit( UnionInstType *contextInst ); 49 49 50 virtual void visit( ForStmt *forStmt );50 virtual void visit( ForStmt *forStmt ); 51 51 52 // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer53 // explicitly when scopes begin and end54 void enterScope();55 void leaveScope();52 // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer 53 // explicitly when scopes begin and end 54 void enterScope(); 55 void leaveScope(); 56 56 57 void lookupId( const std::string &id, std::list< DeclarationWithType* >& ) const;58 DeclarationWithType* lookupId( const std::string &id) const;59 NamedTypeDecl *lookupType( const std::string &id ) const;60 StructDecl *lookupStruct( const std::string &id ) const;61 EnumDecl *lookupEnum( const std::string &id ) const;62 UnionDecl *lookupUnion( const std::string &id ) const;63 ContextDecl *lookupContext( const std::string &id ) const;57 void lookupId( const std::string &id, std::list< DeclarationWithType* >& ) const; 58 DeclarationWithType* lookupId( const std::string &id) const; 59 NamedTypeDecl *lookupType( const std::string &id ) const; 60 StructDecl *lookupStruct( const std::string &id ) const; 61 EnumDecl *lookupEnum( const std::string &id ) const; 62 UnionDecl *lookupUnion( const std::string &id ) const; 63 ContextDecl *lookupContext( const std::string &id ) const; 64 64 65 void print( std::ostream &os, int indent = 0 ) const;66 private:67 IdTable idTable;68 TypeTable typeTable;69 StructTable structTable;70 EnumTable enumTable;71 UnionTable unionTable;72 ContextTable contextTable;65 void print( std::ostream &os, int indent = 0 ) const; 66 private: 67 IdTable idTable; 68 TypeTable typeTable; 69 StructTable structTable; 70 EnumTable enumTable; 71 UnionTable unionTable; 72 ContextTable contextTable; 73 73 74 bool doDebug; // display debugging trace75 };74 bool doDebug; // display debugging trace 75 }; 76 76 } // namespace SymTab 77 77 -
translator/SymTab/Mangler.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:40:29 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:43:49201513 // Update Count : 212 // Last Modified On : Tue May 19 16:50:47 2015 13 // Update Count : 3 14 14 // 15 15 … … 30 30 31 31 namespace SymTab { 32 Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) {32 Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) { 33 33 } 34 34 … … 37 37 //{ 38 38 //} 39 Mangler::Mangler( const Mangler &rhs ) : mangleName() {39 Mangler::Mangler( const Mangler &rhs ) : mangleName() { 40 40 varNums = rhs.varNums; 41 41 nextVarNum = rhs.nextVarNum; 42 42 isTopLevel = rhs.isTopLevel; 43 }44 45 void Mangler::mangleDecl( DeclarationWithType *declaration ) {43 } 44 45 void Mangler::mangleDecl( DeclarationWithType *declaration ) { 46 46 bool wasTopLevel = isTopLevel; 47 47 if ( isTopLevel ) { … … 60 60 maybeAccept( declaration->get_type(), *this ); 61 61 isTopLevel = wasTopLevel; 62 }63 64 void Mangler::visit( ObjectDecl *declaration ) {62 } 63 64 void Mangler::visit( ObjectDecl *declaration ) { 65 65 mangleDecl( declaration ); 66 }67 68 void Mangler::visit( FunctionDecl *declaration ) {66 } 67 68 void Mangler::visit( FunctionDecl *declaration ) { 69 69 mangleDecl( declaration ); 70 }71 72 void Mangler::visit( VoidType *voidType ) {70 } 71 72 void Mangler::visit( VoidType *voidType ) { 73 73 printQualifiers( voidType ); 74 74 mangleName << "v"; 75 }76 77 void Mangler::visit( BasicType *basicType ) {75 } 76 77 void Mangler::visit( BasicType *basicType ) { 78 78 static const char *btLetter[] = { 79 79 "b", // Bool … … 102 102 printQualifiers( basicType ); 103 103 mangleName << btLetter[ basicType->get_kind() ]; 104 }105 106 void Mangler::visit( PointerType *pointerType ) {104 } 105 106 void Mangler::visit( PointerType *pointerType ) { 107 107 printQualifiers( pointerType ); 108 108 mangleName << "P"; 109 109 maybeAccept( pointerType->get_base(), *this ); 110 }111 112 void Mangler::visit( ArrayType *arrayType ) {110 } 111 112 void Mangler::visit( ArrayType *arrayType ) { 113 113 // TODO: encode dimension 114 114 printQualifiers( arrayType ); 115 115 mangleName << "A0"; 116 116 maybeAccept( arrayType->get_base(), *this ); 117 }118 119 namespace {117 } 118 119 namespace { 120 120 inline std::list< Type* > getTypes( const std::list< DeclarationWithType* > decls ) { 121 121 std::list< Type* > ret; … … 124 124 return ret; 125 125 } 126 }127 128 void Mangler::visit( FunctionType *functionType ) {126 } 127 128 void Mangler::visit( FunctionType *functionType ) { 129 129 printQualifiers( functionType ); 130 130 mangleName << "F"; … … 135 135 acceptAll( paramTypes, *this ); 136 136 mangleName << "_"; 137 }138 139 void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) {137 } 138 139 void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) { 140 140 printQualifiers( refType ); 141 141 mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name(); 142 }143 144 void Mangler::visit( StructInstType *aggregateUseType ) {142 } 143 144 void Mangler::visit( StructInstType *aggregateUseType ) { 145 145 mangleRef( aggregateUseType, "s" ); 146 }147 148 void Mangler::visit( UnionInstType *aggregateUseType ) {146 } 147 148 void Mangler::visit( UnionInstType *aggregateUseType ) { 149 149 mangleRef( aggregateUseType, "u" ); 150 }151 152 void Mangler::visit( EnumInstType *aggregateUseType ) {150 } 151 152 void Mangler::visit( EnumInstType *aggregateUseType ) { 153 153 mangleRef( aggregateUseType, "e" ); 154 }155 156 void Mangler::visit( TypeInstType *typeInst ) {154 } 155 156 void Mangler::visit( TypeInstType *typeInst ) { 157 157 VarMapType::iterator varNum = varNums.find( typeInst->get_name() ); 158 158 if ( varNum == varNums.end() ) { … … 176 176 mangleName << std::string( numStream.str(), numStream.pcount() ); 177 177 } // if 178 }179 180 void Mangler::visit( TupleType *tupleType ) {178 } 179 180 void Mangler::visit( TupleType *tupleType ) { 181 181 printQualifiers( tupleType ); 182 182 mangleName << "T"; 183 183 acceptAll( tupleType->get_types(), *this ); 184 184 mangleName << "_"; 185 }186 187 void Mangler::visit( TypeDecl *decl ) {185 } 186 187 void Mangler::visit( TypeDecl *decl ) { 188 188 static const char *typePrefix[] = { "BT", "BD", "BF" }; 189 189 mangleName << typePrefix[ decl->get_kind() ] << ( decl->get_name().length() + 1 ) << decl->get_name(); 190 }191 192 void printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) {190 } 191 192 void printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) { 193 193 for ( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) { 194 194 os << i->first << "(" << i->second.first << "/" << i->second.second << ")" << std::endl; 195 195 } // for 196 }197 198 void Mangler::printQualifiers( Type *type ) {196 } 197 198 void Mangler::printQualifiers( Type *type ) { 199 199 if ( ! type->get_forall().empty() ) { 200 200 std::list< std::string > assertionNames; … … 242 242 mangleName << "A"; 243 243 } // if 244 }244 } 245 245 } // namespace SymTab 246 246 -
translator/SymTab/Mangler.h
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:44:03 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:45:05201513 // Update Count : 212 // Last Modified On : Tue May 19 16:49:21 2015 13 // Update Count : 3 14 14 // 15 15 … … 22 22 23 23 namespace SymTab { 24 class Mangler : public Visitor {25 public:24 class Mangler : public Visitor { 25 public: 26 26 template< typename SynTreeClass > 27 27 static std::string mangle( SynTreeClass *decl ); // interface to clients … … 44 44 45 45 std::string get_mangleName() { return std::string( mangleName.str(), mangleName.pcount() ); } 46 private:46 private: 47 47 std::ostrstream mangleName; 48 48 typedef std::map< std::string, std::pair< int, int > > VarMapType; … … 58 58 59 59 void printQualifiers( Type *type ); 60 }; // Mangler60 }; // Mangler 61 61 62 template< typename SynTreeClass >63 std::string Mangler::mangle( SynTreeClass *decl ) {62 template< typename SynTreeClass > 63 std::string Mangler::mangle( SynTreeClass *decl ) { 64 64 Mangler mangler; 65 65 maybeAccept( decl, mangler ); 66 66 return mangler.get_mangleName(); 67 }67 } 68 68 } // SymTab 69 69 -
translator/SymTab/StackTable.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:45:15 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:46:59201513 // Update Count : 212 // Last Modified On : Tue May 19 16:51:53 2015 13 // Update Count : 3 14 14 // 15 15 … … 19 19 20 20 namespace SymTab { 21 template< typename Element, typename ConflictFunction >22 StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) {21 template< typename Element, typename ConflictFunction > 22 StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) { 23 23 } 24 24 25 template< typename Element, typename ConflictFunction >26 void StackTable< Element, ConflictFunction >::enterScope() {25 template< typename Element, typename ConflictFunction > 26 void StackTable< Element, ConflictFunction >::enterScope() { 27 27 scopeLevel++; 28 }28 } 29 29 30 template< typename Element, typename ConflictFunction >31 void StackTable< Element, ConflictFunction >::leaveScope() {30 template< typename Element, typename ConflictFunction > 31 void StackTable< Element, ConflictFunction >::leaveScope() { 32 32 for ( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) { 33 33 std::stack< Entry >& entry = it->second; … … 38 38 scopeLevel--; 39 39 assert( scopeLevel >= 0 ); 40 }40 } 41 41 42 template< typename Element, typename ConflictFunction >43 void StackTable< Element, ConflictFunction >::add( Element *type ) {42 template< typename Element, typename ConflictFunction > 43 void StackTable< Element, ConflictFunction >::add( Element *type ) { 44 44 std::stack< Entry >& entry = table[ type->get_name() ]; 45 45 if ( ! entry.empty() && entry.top().second == scopeLevel ) { … … 48 48 entry.push( Entry( type, scopeLevel ) ); 49 49 } // if 50 }50 } 51 51 52 template< typename Element, typename ConflictFunction >53 void StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) {52 template< typename Element, typename ConflictFunction > 53 void StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) { 54 54 add( new Element( fwdDeclName ) ); 55 }55 } 56 56 57 template< typename Element, typename ConflictFunction >58 Element *StackTable< Element, ConflictFunction >::lookup( std::string id ) const {57 template< typename Element, typename ConflictFunction > 58 Element *StackTable< Element, ConflictFunction >::lookup( std::string id ) const { 59 59 typename TableType::const_iterator it = table.find( id ); 60 60 if ( it == table.end() ) { … … 65 65 return 0; 66 66 } // if 67 }67 } 68 68 69 template< typename Element, typename ConflictFunction >70 void StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const {69 template< typename Element, typename ConflictFunction > 70 void StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const { 71 71 for ( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) { 72 72 const std::stack< Entry >& entry = it->second; … … 75 75 } // if 76 76 } // for 77 }77 } 78 78 } // namespace SymTab 79 79 -
translator/SymTab/StackTable.h
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:47:10 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:48:15201513 // Update Count : 312 // Last Modified On : Tue May 19 16:50:36 2015 13 // Update Count : 4 14 14 // 15 15 … … 23 23 24 24 namespace SymTab { 25 template< typename Element, typename ConflictFunction >25 template< typename Element, typename ConflictFunction > 26 26 class StackTable { 27 public:27 public: 28 28 StackTable(); 29 29 … … 35 35 36 36 void dump( std::ostream &os ) const; // debugging 37 private:37 private: 38 38 typedef std::pair< Element*, int > Entry; 39 39 typedef std::map< std::string, std::stack< Entry > > TableType; … … 42 42 TableType table; 43 43 int scopeLevel; 44 };44 }; 45 45 } // SymTab 46 46 -
translator/SymTab/TypeTable.h
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:48:32 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:49:49201513 // Update Count : 212 // Last Modified On : Tue May 19 16:50:25 2015 13 // Update Count : 3 14 14 // 15 15 … … 27 27 28 28 namespace SymTab { 29 class TypeTableConflictFunction : public std::binary_function< NamedTypeDecl *, NamedTypeDecl *, NamedTypeDecl * > {30 public:29 class TypeTableConflictFunction : public std::binary_function< NamedTypeDecl *, NamedTypeDecl *, NamedTypeDecl * > { 30 public: 31 31 NamedTypeDecl *operator()( NamedTypeDecl *existing, NamedTypeDecl *added ) { 32 32 if ( existing->get_base() == 0 ) { … … 40 40 return 0; 41 41 } 42 };42 }; 43 43 44 typedef StackTable< NamedTypeDecl, TypeTableConflictFunction > TypeTable;44 typedef StackTable< NamedTypeDecl, TypeTableConflictFunction > TypeTable; 45 45 } // namespace SymTab 46 46 -
translator/SymTab/Validate.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:53:16201513 // Update Count : 212 // Last Modified On : Tue May 19 16:50:09 2015 13 // Update Count : 3 14 14 // 15 15 … … 57 57 58 58 namespace SymTab { 59 class HoistStruct : public Visitor {60 public:59 class HoistStruct : public Visitor { 60 public: 61 61 static void hoistStruct( std::list< Declaration * > &translationUnit ); 62 62 … … 74 74 virtual void visit( CaseStmt *caseStmt ); 75 75 virtual void visit( CatchStmt *catchStmt ); 76 private:76 private: 77 77 HoistStruct(); 78 78 … … 81 81 std::list< Declaration * > declsToAdd; 82 82 bool inStruct; 83 };84 85 class Pass1 : public Visitor {83 }; 84 85 class Pass1 : public Visitor { 86 86 typedef Visitor Parent; 87 87 virtual void visit( EnumDecl *aggregateDecl ); 88 88 virtual void visit( FunctionType *func ); 89 };90 91 class Pass2 : public Indexer {89 }; 90 91 class Pass2 : public Indexer { 92 92 typedef Indexer Parent; 93 public:93 public: 94 94 Pass2( bool doDebug, const Indexer *indexer ); 95 private:95 private: 96 96 virtual void visit( StructInstType *structInst ); 97 97 virtual void visit( UnionInstType *unionInst ); … … 107 107 ForwardStructsType forwardStructs; 108 108 ForwardUnionsType forwardUnions; 109 };110 111 class Pass3 : public Indexer {109 }; 110 111 class Pass3 : public Indexer { 112 112 typedef Indexer Parent; 113 public:113 public: 114 114 Pass3( const Indexer *indexer ); 115 private:115 private: 116 116 virtual void visit( ObjectDecl *object ); 117 117 virtual void visit( FunctionDecl *func ); 118 118 119 119 const Indexer *indexer; 120 };121 122 class AddStructAssignment : public Visitor {123 public:120 }; 121 122 class AddStructAssignment : public Visitor { 123 public: 124 124 static void addStructAssignment( std::list< Declaration * > &translationUnit ); 125 125 … … 145 145 146 146 AddStructAssignment() : functionNesting( 0 ) {} 147 private:147 private: 148 148 template< typename StmtClass > void visitStatement( StmtClass *stmt ); 149 149 … … 151 151 std::set< std::string > structsDone; 152 152 unsigned int functionNesting; // current level of nested functions 153 };154 155 class EliminateTypedef : public Mutator {156 public:153 }; 154 155 class EliminateTypedef : public Mutator { 156 public: 157 157 static void eliminateTypedef( std::list< Declaration * > &translationUnit ); 158 private:158 private: 159 159 virtual Declaration *mutate( TypedefDecl *typeDecl ); 160 160 virtual TypeDecl *mutate( TypeDecl *typeDecl ); … … 166 166 167 167 std::map< std::string, TypedefDecl * > typedefNames; 168 };169 170 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {168 }; 169 170 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 171 171 Pass1 pass1; 172 172 Pass2 pass2( doDebug, 0 ); … … 178 178 AddStructAssignment::addStructAssignment( translationUnit ); 179 179 acceptAll( translationUnit, pass3 ); 180 }181 182 void validateType( Type *type, const Indexer *indexer ) {180 } 181 182 void validateType( Type *type, const Indexer *indexer ) { 183 183 Pass1 pass1; 184 184 Pass2 pass2( false, indexer ); … … 187 187 type->accept( pass2 ); 188 188 type->accept( pass3 ); 189 }190 191 template< typename Visitor >192 void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) {189 } 190 191 template< typename Visitor > 192 void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) { 193 193 std::list< Declaration * >::iterator i = translationUnit.begin(); 194 194 while ( i != translationUnit.end() ) { … … 201 201 i = next; 202 202 } // while 203 }204 205 void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) {203 } 204 205 void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) { 206 206 HoistStruct hoister; 207 207 acceptAndAdd( translationUnit, hoister, true ); 208 }209 210 HoistStruct::HoistStruct() : inStruct( false ) {211 }212 213 void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) {208 } 209 210 HoistStruct::HoistStruct() : inStruct( false ) { 211 } 212 213 void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) { 214 214 std::list< Declaration * >::iterator i = declList.begin(); 215 215 while ( i != declList.end() ) { … … 224 224 i = next; 225 225 } // while 226 }227 228 bool isStructOrUnion( Declaration *decl ) {226 } 227 228 bool isStructOrUnion( Declaration *decl ) { 229 229 return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl ); 230 }231 232 template< typename AggDecl >233 void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {230 } 231 232 template< typename AggDecl > 233 void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) { 234 234 if ( inStruct ) { 235 235 // Add elements in stack order corresponding to nesting structure. … … 243 243 // Always remove the hoisted aggregate from the inner structure. 244 244 filter( aggregateDecl->get_members(), isStructOrUnion, false ); 245 }246 247 void HoistStruct::visit( StructDecl *aggregateDecl ) {245 } 246 247 void HoistStruct::visit( StructDecl *aggregateDecl ) { 248 248 handleAggregate( aggregateDecl ); 249 }250 251 void HoistStruct::visit( UnionDecl *aggregateDecl ) {249 } 250 251 void HoistStruct::visit( UnionDecl *aggregateDecl ) { 252 252 handleAggregate( aggregateDecl ); 253 }254 255 void HoistStruct::visit( CompoundStmt *compoundStmt ) {253 } 254 255 void HoistStruct::visit( CompoundStmt *compoundStmt ) { 256 256 addVisit( compoundStmt, *this ); 257 }258 259 void HoistStruct::visit( IfStmt *ifStmt ) {257 } 258 259 void HoistStruct::visit( IfStmt *ifStmt ) { 260 260 addVisit( ifStmt, *this ); 261 }262 263 void HoistStruct::visit( WhileStmt *whileStmt ) {261 } 262 263 void HoistStruct::visit( WhileStmt *whileStmt ) { 264 264 addVisit( whileStmt, *this ); 265 }266 267 void HoistStruct::visit( ForStmt *forStmt ) {265 } 266 267 void HoistStruct::visit( ForStmt *forStmt ) { 268 268 addVisit( forStmt, *this ); 269 }270 271 void HoistStruct::visit( SwitchStmt *switchStmt ) {269 } 270 271 void HoistStruct::visit( SwitchStmt *switchStmt ) { 272 272 addVisit( switchStmt, *this ); 273 }274 275 void HoistStruct::visit( ChooseStmt *switchStmt ) {273 } 274 275 void HoistStruct::visit( ChooseStmt *switchStmt ) { 276 276 addVisit( switchStmt, *this ); 277 }278 279 void HoistStruct::visit( CaseStmt *caseStmt ) {277 } 278 279 void HoistStruct::visit( CaseStmt *caseStmt ) { 280 280 addVisit( caseStmt, *this ); 281 }282 283 void HoistStruct::visit( CatchStmt *cathStmt ) {281 } 282 283 void HoistStruct::visit( CatchStmt *cathStmt ) { 284 284 addVisit( cathStmt, *this ); 285 }286 287 void Pass1::visit( EnumDecl *enumDecl ) {285 } 286 287 void Pass1::visit( EnumDecl *enumDecl ) { 288 288 // Set the type of each member of the enumeration to be EnumConstant 289 289 … … 294 294 } // for 295 295 Parent::visit( enumDecl ); 296 }297 298 namespace {296 } 297 298 namespace { 299 299 template< typename DWTIterator > 300 300 void fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) { … … 323 323 } // if 324 324 } 325 }326 327 void Pass1::visit( FunctionType *func ) {325 } 326 327 void Pass1::visit( FunctionType *func ) { 328 328 // Fix up parameters and return types 329 329 fixFunctionList( func->get_parameters().begin(), func->get_parameters().end(), func ); 330 330 fixFunctionList( func->get_returnVals().begin(), func->get_returnVals().end(), func ); 331 331 Visitor::visit( func ); 332 }333 334 Pass2::Pass2( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug ) {332 } 333 334 Pass2::Pass2( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug ) { 335 335 if ( other_indexer ) { 336 336 indexer = other_indexer; … … 338 338 indexer = this; 339 339 } // if 340 }341 342 void Pass2::visit( StructInstType *structInst ) {340 } 341 342 void Pass2::visit( StructInstType *structInst ) { 343 343 Parent::visit( structInst ); 344 344 StructDecl *st = indexer->lookupStruct( structInst->get_name() ); … … 352 352 forwardStructs[ structInst->get_name() ].push_back( structInst ); 353 353 } // if 354 }355 356 void Pass2::visit( UnionInstType *unionInst ) {354 } 355 356 void Pass2::visit( UnionInstType *unionInst ) { 357 357 Parent::visit( unionInst ); 358 358 UnionDecl *un = indexer->lookupUnion( unionInst->get_name() ); … … 365 365 forwardUnions[ unionInst->get_name() ].push_back( unionInst ); 366 366 } // if 367 }368 369 void Pass2::visit( ContextInstType *contextInst ) {367 } 368 369 void Pass2::visit( ContextInstType *contextInst ) { 370 370 Parent::visit( contextInst ); 371 371 ContextDecl *ctx = indexer->lookupContext( contextInst->get_name() ); … … 383 383 } // for 384 384 applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) ); 385 }386 387 void Pass2::visit( StructDecl *structDecl ) {385 } 386 387 void Pass2::visit( StructDecl *structDecl ) { 388 388 if ( ! structDecl->get_members().empty() ) { 389 389 ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() ); … … 396 396 } // if 397 397 Indexer::visit( structDecl ); 398 }399 400 void Pass2::visit( UnionDecl *unionDecl ) {398 } 399 400 void Pass2::visit( UnionDecl *unionDecl ) { 401 401 if ( ! unionDecl->get_members().empty() ) { 402 402 ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() ); … … 409 409 } // if 410 410 Indexer::visit( unionDecl ); 411 }412 413 void Pass2::visit( TypeInstType *typeInst ) {411 } 412 413 void Pass2::visit( TypeInstType *typeInst ) { 414 414 if ( NamedTypeDecl *namedTypeDecl = lookupType( typeInst->get_name() ) ) { 415 415 if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) { … … 417 417 } // if 418 418 } // if 419 }420 421 Pass3::Pass3( const Indexer *other_indexer ) : Indexer( false ) {419 } 420 421 Pass3::Pass3( const Indexer *other_indexer ) : Indexer( false ) { 422 422 if ( other_indexer ) { 423 423 indexer = other_indexer; … … 425 425 indexer = this; 426 426 } // if 427 }428 429 void forallFixer( Type *func ) {427 } 428 429 void forallFixer( Type *func ) { 430 430 // Fix up assertions 431 431 for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) { … … 454 454 } // while 455 455 } // for 456 }457 458 void Pass3::visit( ObjectDecl *object ) {456 } 457 458 void Pass3::visit( ObjectDecl *object ) { 459 459 forallFixer( object->get_type() ); 460 460 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) { … … 463 463 Parent::visit( object ); 464 464 object->fixUniqueId(); 465 }466 467 void Pass3::visit( FunctionDecl *func ) {465 } 466 467 void Pass3::visit( FunctionDecl *func ) { 468 468 forallFixer( func->get_type() ); 469 469 Parent::visit( func ); 470 470 func->fixUniqueId(); 471 }472 473 static const std::list< std::string > noLabels;474 475 void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) {471 } 472 473 static const std::list< std::string > noLabels; 474 475 void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) { 476 476 AddStructAssignment visitor; 477 477 acceptAndAdd( translationUnit, visitor, false ); 478 }479 480 template< typename OutputIterator >481 void makeScalarAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, OutputIterator out ) {478 } 479 480 template< typename OutputIterator > 481 void makeScalarAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, OutputIterator out ) { 482 482 ObjectDecl *obj = dynamic_cast<ObjectDecl *>( member ); 483 483 // unnamed bit fields are not copied as they cannot be accessed … … 497 497 498 498 *out++ = new ExprStmt( noLabels, assignExpr ); 499 }500 501 template< typename OutputIterator >502 void makeArrayAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, ArrayType *array, OutputIterator out ) {499 } 500 501 template< typename OutputIterator > 502 void makeArrayAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, ArrayType *array, OutputIterator out ) { 503 503 static UniqueName indexName( "_index" ); 504 504 … … 539 539 540 540 *out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) ); 541 }542 543 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) {541 } 542 543 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 544 544 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 545 545 … … 570 570 571 571 return assignDecl; 572 }573 574 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) {572 } 573 574 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) { 575 575 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 576 576 … … 598 598 599 599 return assignDecl; 600 }601 602 void AddStructAssignment::visit( StructDecl *structDecl ) {600 } 601 602 void AddStructAssignment::visit( StructDecl *structDecl ) { 603 603 if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) { 604 604 StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() ); … … 607 607 structsDone.insert( structDecl->get_name() ); 608 608 } // if 609 }610 611 void AddStructAssignment::visit( UnionDecl *unionDecl ) {609 } 610 611 void AddStructAssignment::visit( UnionDecl *unionDecl ) { 612 612 if ( ! unionDecl->get_members().empty() ) { 613 613 UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() ); … … 615 615 declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) ); 616 616 } // if 617 }618 619 void AddStructAssignment::visit( TypeDecl *typeDecl ) {617 } 618 619 void AddStructAssignment::visit( TypeDecl *typeDecl ) { 620 620 CompoundStmt *stmts = 0; 621 621 TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false ); … … 636 636 FunctionDecl *func = new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::AutoGen, type, stmts, false ); 637 637 declsToAdd.push_back( func ); 638 }639 640 void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) {638 } 639 640 void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) { 641 641 if ( ! declsToAdd.empty() ) { 642 642 for ( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) { … … 645 645 declsToAdd.clear(); 646 646 } // if 647 }648 649 void AddStructAssignment::visit( FunctionType *) {647 } 648 649 void AddStructAssignment::visit( FunctionType *) { 650 650 // ensure that we don't add assignment ops for types defined as part of the function 651 }652 653 void AddStructAssignment::visit( PointerType *) {651 } 652 653 void AddStructAssignment::visit( PointerType *) { 654 654 // ensure that we don't add assignment ops for types defined as part of the pointer 655 }656 657 void AddStructAssignment::visit( ContextDecl *) {655 } 656 657 void AddStructAssignment::visit( ContextDecl *) { 658 658 // ensure that we don't add assignment ops for types defined as part of the context 659 }660 661 template< typename StmtClass >662 inline void AddStructAssignment::visitStatement( StmtClass *stmt ) {659 } 660 661 template< typename StmtClass > 662 inline void AddStructAssignment::visitStatement( StmtClass *stmt ) { 663 663 std::set< std::string > oldStructs = structsDone; 664 664 addVisit( stmt, *this ); 665 665 structsDone = oldStructs; 666 }667 668 void AddStructAssignment::visit( FunctionDecl *functionDecl ) {666 } 667 668 void AddStructAssignment::visit( FunctionDecl *functionDecl ) { 669 669 maybeAccept( functionDecl->get_functionType(), *this ); 670 670 acceptAll( functionDecl->get_oldDecls(), *this ); … … 672 672 maybeAccept( functionDecl->get_statements(), *this ); 673 673 functionNesting -= 1; 674 }675 676 void AddStructAssignment::visit( CompoundStmt *compoundStmt ) {674 } 675 676 void AddStructAssignment::visit( CompoundStmt *compoundStmt ) { 677 677 visitStatement( compoundStmt ); 678 }679 680 void AddStructAssignment::visit( IfStmt *ifStmt ) {678 } 679 680 void AddStructAssignment::visit( IfStmt *ifStmt ) { 681 681 visitStatement( ifStmt ); 682 }683 684 void AddStructAssignment::visit( WhileStmt *whileStmt ) {682 } 683 684 void AddStructAssignment::visit( WhileStmt *whileStmt ) { 685 685 visitStatement( whileStmt ); 686 }687 688 void AddStructAssignment::visit( ForStmt *forStmt ) {686 } 687 688 void AddStructAssignment::visit( ForStmt *forStmt ) { 689 689 visitStatement( forStmt ); 690 }691 692 void AddStructAssignment::visit( SwitchStmt *switchStmt ) {690 } 691 692 void AddStructAssignment::visit( SwitchStmt *switchStmt ) { 693 693 visitStatement( switchStmt ); 694 }695 696 void AddStructAssignment::visit( ChooseStmt *switchStmt ) {694 } 695 696 void AddStructAssignment::visit( ChooseStmt *switchStmt ) { 697 697 visitStatement( switchStmt ); 698 }699 700 void AddStructAssignment::visit( CaseStmt *caseStmt ) {698 } 699 700 void AddStructAssignment::visit( CaseStmt *caseStmt ) { 701 701 visitStatement( caseStmt ); 702 }703 704 void AddStructAssignment::visit( CatchStmt *cathStmt ) {702 } 703 704 void AddStructAssignment::visit( CatchStmt *cathStmt ) { 705 705 visitStatement( cathStmt ); 706 }707 708 bool isTypedef( Declaration *decl ) {706 } 707 708 bool isTypedef( Declaration *decl ) { 709 709 return dynamic_cast< TypedefDecl * >( decl ); 710 }711 712 void EliminateTypedef::eliminateTypedef( std::list< Declaration * > &translationUnit ) {710 } 711 712 void EliminateTypedef::eliminateTypedef( std::list< Declaration * > &translationUnit ) { 713 713 EliminateTypedef eliminator; 714 714 mutateAll( translationUnit, eliminator ); 715 715 filter( translationUnit, isTypedef, true ); 716 }717 718 Type *EliminateTypedef::mutate( TypeInstType *typeInst ) {716 } 717 718 Type *EliminateTypedef::mutate( TypeInstType *typeInst ) { 719 719 std::map< std::string, TypedefDecl * >::const_iterator def = typedefNames.find( typeInst->get_name() ); 720 720 if ( def != typedefNames.end() ) { … … 725 725 } // if 726 726 return typeInst; 727 }728 729 Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {727 } 728 729 Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) { 730 730 Declaration *ret = Mutator::mutate( tyDecl ); 731 731 typedefNames[ tyDecl->get_name() ] = tyDecl; … … 745 745 return ret; 746 746 } // if 747 }748 749 TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {747 } 748 749 TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) { 750 750 std::map< std::string, TypedefDecl * >::iterator i = typedefNames.find( typeDecl->get_name() ); 751 751 if ( i != typedefNames.end() ) { … … 753 753 } // if 754 754 return typeDecl; 755 }756 757 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {755 } 756 757 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) { 758 758 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 759 759 DeclarationWithType *ret = Mutator::mutate( funcDecl ); 760 760 typedefNames = oldNames; 761 761 return ret; 762 }763 764 ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {762 } 763 764 ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) { 765 765 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 766 766 ObjectDecl *ret = Mutator::mutate( objDecl ); 767 767 typedefNames = oldNames; 768 768 return ret; 769 }770 771 Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {769 } 770 771 Expression *EliminateTypedef::mutate( CastExpr *castExpr ) { 772 772 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 773 773 Expression *ret = Mutator::mutate( castExpr ); 774 774 typedefNames = oldNames; 775 775 return ret; 776 }777 778 CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {776 } 777 778 CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) { 779 779 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 780 780 CompoundStmt *ret = Mutator::mutate( compoundStmt ); … … 793 793 typedefNames = oldNames; 794 794 return ret; 795 }795 } 796 796 } // namespace SymTab 797 797 -
translator/SymTab/Validate.h
r01aeade ra08ba92 11 11 // Created On : Sun May 17 21:53:34 2015 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Sun May 17 21:55:09201514 // Update Count : 213 // Last Modified On : Tue May 19 16:49:43 2015 14 // Update Count : 3 15 15 // 16 16 … … 21 21 22 22 namespace SymTab { 23 class Indexer;23 class Indexer; 24 24 25 void validate( std::list< Declaration * > &translationUnit, bool doDebug = false );26 void validateType( Type *type, const Indexer *indexer );25 void validate( std::list< Declaration * > &translationUnit, bool doDebug = false ); 26 void validateType( Type *type, const Indexer *indexer ); 27 27 } // namespace SymTab 28 28
Note:
See TracChangeset
for help on using the changeset viewer.