Changeset f006f01 for src/Tuples
- Timestamp:
- Sep 12, 2016, 7:08:41 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- fd782b2
- Parents:
- 6eb8948
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/TupleExpansion.cc
r6eb8948 rf006f01 18 18 #include <cassert> 19 19 #include "Tuples.h" 20 #include "GenPoly/PolyMutator.h" 20 #include "GenPoly/DeclMutator.h" 21 #include "SynTree/Mutator.h" 21 22 #include "SynTree/Statement.h" 23 #include "SynTree/Declaration.h" 24 #include "SynTree/Type.h" 25 #include "SymTab/Mangler.h" 26 #include "Common/ScopedMap.h" 22 27 23 28 namespace Tuples { 24 class TupleAssignExpander : public GenPoly::PolyMutator {29 class TupleAssignExpander : public Mutator { 25 30 public: 26 31 virtual Expression * mutate( TupleAssignExpr * tupleExpr ); 32 }; 33 34 class TupleTypeReplacer : public GenPoly::DeclMutator { 35 public: 36 typedef GenPoly::DeclMutator Parent; 37 38 virtual Type * mutate( TupleType * tupleType ); 39 40 virtual CompoundStmt * mutate( CompoundStmt * stmt ) { 41 typeMap.beginScope(); 42 stmt = Parent::mutate( stmt ); 43 typeMap.endScope(); 44 return stmt; 45 } 46 private: 47 ScopedMap< std::string, StructDecl * > typeMap; 27 48 }; 28 49 … … 30 51 TupleAssignExpander expander; 31 52 mutateAll( translationUnit, expander ); 53 54 TupleTypeReplacer replacer; 55 replacer.mutateDeclarationList( translationUnit ); 32 56 } 33 57 … … 47 71 } 48 72 73 Type * TupleTypeReplacer::mutate( TupleType * tupleType ) { 74 std::string mangleName = SymTab::Mangler::mangleType( tupleType ); 75 TupleType * newType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) ); 76 if ( ! typeMap.count( mangleName ) ) { 77 // generate struct type to replace tuple type 78 StructDecl * decl = new StructDecl( "_tuple_type_" + mangleName ); 79 decl->set_body( true ); 80 int cnt = 0; 81 for ( Type * t : *newType ) { 82 decl->get_members().push_back( new ObjectDecl( "field_"+std::to_string(++cnt), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, t->clone(), nullptr ) ); 83 } 84 typeMap[mangleName] = decl; 85 addDeclaration( decl ); 86 } 87 delete newType; 88 return new StructInstType( newType->get_qualifiers(), typeMap[mangleName] ); 89 } 90 49 91 } // namespace Tuples 50 92
Note: See TracChangeset
for help on using the changeset viewer.