- Timestamp:
- Feb 15, 2017, 8:42:12 AM (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:
- 32b8144
- Parents:
- 97f65d5
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/Generate.cc
r97f65d5 re6512c8 22 22 #include "SynTree/Declaration.h" 23 23 #include "CodeGenerator.h" 24 #include "Tuples/Tuples.h" 24 25 25 26 using namespace std; … … 28 29 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty ) { 29 30 CodeGen::CodeGenerator cgv( os, pretty ); 30 31 for ( std::list<Declaration *>::iterator i = translationUnit.begin(); i != translationUnit.end(); i++ ) { 32 if ( LinkageSpec::isGeneratable( (*i)->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( (*i)->get_linkage() ) ) ) { 33 (*i)->accept(cgv); 34 if ( doSemicolon( *i ) ) { 31 for ( auto & dcl : translationUnit ) { 32 if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) { 33 dcl->accept(cgv); 34 if ( doSemicolon( dcl ) ) { 35 35 os << ";"; 36 36 } // if -
src/Tuples/TupleExpansion.cc
r97f65d5 re6512c8 79 79 } 80 80 private: 81 ScopedMap< std::string, StructDecl * > typeMap;81 ScopedMap< int, StructDecl * > typeMap; 82 82 }; 83 83 … … 214 214 215 215 Type * TupleTypeReplacer::mutate( TupleType * tupleType ) { 216 std::string mangleName = SymTab::Mangler::mangleType( tupleType );217 216 tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) ); 218 if ( ! typeMap.count( mangleName ) ) {219 // generate struct type to replace tuple type220 // xxx - should fix this to only generate one tuple struct for each number of type parameters221 StructDecl * decl = new StructDecl( "_tuple_type_" + mangleName);217 unsigned tupleSize = tupleType->size(); 218 if ( ! typeMap.count( tupleSize ) ) { 219 // generate struct type to replace tuple type based on the number of components in the tuple 220 StructDecl * decl = new StructDecl( toString( "_tuple_type_", tupleSize ) ); 222 221 decl->set_body( true ); 223 for ( size_t i = 0; i < tuple Type->size(); ++i ) {222 for ( size_t i = 0; i < tupleSize; ++i ) { 224 223 TypeDecl * tyParam = new TypeDecl( toString("tuple_param_", i), DeclarationNode::NoStorageClass, nullptr, TypeDecl::Any ); 225 224 decl->get_members().push_back( new ObjectDecl( toString("field_", i), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new TypeInstType( Type::Qualifiers(), tyParam->get_name(), tyParam ), nullptr ) ); 226 225 decl->get_parameters().push_back( tyParam ); 227 226 } 228 if ( tuple Type->size()== 0 ) {227 if ( tupleSize == 0 ) { 229 228 // empty structs are not standard C. Add a dummy field to empty tuples to silence warnings when a compound literal Tuple0 is created. 230 229 decl->get_members().push_back( new ObjectDecl( "dummy", DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) ); 231 230 } 232 typeMap[ mangleName] = decl;231 typeMap[tupleSize] = decl; 233 232 addDeclaration( decl ); 234 233 } 235 234 Type::Qualifiers qualifiers = tupleType->get_qualifiers(); 236 235 237 StructDecl * decl = typeMap[ mangleName];236 StructDecl * decl = typeMap[tupleSize]; 238 237 StructInstType * newType = new StructInstType( qualifiers, decl ); 239 238 for ( Type * t : *tupleType ) {
Note: See TracChangeset
for help on using the changeset viewer.