Changeset b0b958a for src/GenPoly
- Timestamp:
- Nov 30, 2015, 1:46:36 PM (9 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:
- 5bf4712, cf16f94
- Parents:
- ed1065c
- Location:
- src/GenPoly
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/InstantiateGeneric.cc
red1065c rb0b958a 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // InstantiateGeneric. h--7 // InstantiateGeneric.cc -- 8 8 // 9 9 // Author : Aaron B. Moss … … 21 21 22 22 #include "InstantiateGeneric.h" 23 #include " PolyMutator.h"23 #include "DeclMutator.h" 24 24 25 25 #include "ResolvExpr/typeops.h" … … 138 138 139 139 /// Mutator pass that replaces concrete instantiations of generic types with actual struct declarations, scoped appropriately 140 class Instantiate : public PolyMutator {140 class Instantiate : public DeclMutator { 141 141 InstantiationMap instantiations; 142 142 UniqueName typeNamer; 143 143 144 144 public: 145 Instantiate() : instantiations(), typeNamer("_conc_") {} 146 147 /// Mutates the whole translation unit, inserting new struct declarations as appropriate 148 void mutateAll( std::list< Declaration* >& translationUnit ); 149 145 Instantiate() : DeclMutator(), instantiations(), typeNamer("_conc_") {} 146 150 147 virtual Type* mutate( StructInstType *inst ); 151 148 virtual Type* mutate( UnionInstType *inst ); … … 153 150 virtual void doBeginScope(); 154 151 virtual void doEndScope(); 155 156 private:157 /// Adds a declaration to the current environment and the statements to add158 void addDeclaration( AggregateDecl *decl ) {159 std::list< Label > nolabels;160 DeclStmt *stmt = new DeclStmt( nolabels, decl );161 PolyMutator::stmtsToAdd.push_back( stmt );162 }163 152 }; 164 153 165 154 void instantiateGeneric( std::list< Declaration* >& translationUnit ) { 166 155 Instantiate instantiator; 167 // mutateAll( translationUnit, instantiator ); 168 instantiator.mutateAll( translationUnit ); 169 } 170 171 void Instantiate::mutateAll( std::list< Declaration* >& translationUnit ) { 172 // below copied and modified from Mutator.h:mutateAll() 173 SemanticError errors; 174 for ( std::list< Declaration* >::iterator decl = translationUnit.begin(); decl != translationUnit.end(); ++decl ) { 175 try { 176 if ( *decl ) { 177 *decl = dynamic_cast< Declaration* >( (*decl)->acceptMutator( *this ) ); 178 assert( *decl ); 179 // account for missing top-level declarations 180 for ( std::list< Statement* >::const_iterator stmt = PolyMutator::stmtsToAdd.begin(); stmt != PolyMutator::stmtsToAdd.end(); ++stmt ) { 181 DeclStmt *declStmt = dynamic_cast< DeclStmt* >( *stmt ); 182 assert( declStmt ); 183 translationUnit.insert( decl, declStmt->get_decl() ); 184 } 185 PolyMutator::stmtsToAdd.clear(); 186 } // if 187 } catch( SemanticError &e ) { 188 errors.append( e ); 189 } // try 190 } // for 191 if ( ! errors.isEmpty() ) { 192 throw errors; 193 } // if 156 instantiator.mutateDeclarationList( translationUnit ); 194 157 } 195 158 … … 225 188 *inst->get_baseParameters(), inst->get_parameters(), 226 189 concDecl->get_members() ); 227 addDeclaration( concDecl );190 DeclMutator::addDeclaration( concDecl ); 228 191 instantiations.insert( inst, concDecl ); 229 192 } … … 252 215 *inst->get_baseParameters(), inst->get_parameters(), 253 216 concDecl->get_members() ); 254 addDeclaration( concDecl );217 DeclMutator::addDeclaration( concDecl ); 255 218 instantiations.insert( inst, concDecl ); 256 219 } … … 262 225 263 226 void Instantiate::doBeginScope() { 227 DeclMutator::doBeginScope(); 264 228 // push a new concrete type scope 265 229 instantiations.beginScope(); … … 267 231 268 232 void Instantiate::doEndScope() { 233 DeclMutator::doEndScope(); 269 234 // pop the last concrete type scope 270 235 instantiations.endScope(); -
src/GenPoly/module.mk
red1065c rb0b958a 23 23 GenPoly/CopyParams.cc \ 24 24 GenPoly/FindFunction.cc \ 25 GenPoly/InstantiateGeneric.cc 25 GenPoly/InstantiateGeneric.cc \ 26 GenPoly/DeclMutator.cc
Note: See TracChangeset
for help on using the changeset viewer.