Changeset bd9bcc8 for src/Tuples/TupleExpansion.cc
- Timestamp:
- Feb 20, 2017, 12:05:49 PM (9 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:
- 3bff885
- Parents:
- facc44f (diff), d150ea2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
src/Tuples/TupleExpansion.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/TupleExpansion.cc
rfacc44f rbd9bcc8 29 29 #include "ResolvExpr/typeops.h" 30 30 #include "InitTweak/GenInit.h" 31 #include "InitTweak/InitTweak.h" 31 32 32 33 namespace Tuples { … … 78 79 } 79 80 private: 80 ScopedMap< std::string, StructDecl * > typeMap;81 ScopedMap< int, StructDecl * > typeMap; 81 82 }; 82 83 … … 213 214 214 215 Type * TupleTypeReplacer::mutate( TupleType * tupleType ) { 215 std::string mangleName = SymTab::Mangler::mangleType( tupleType );216 216 tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) ); 217 if ( ! typeMap.count( mangleName ) ) {218 // generate struct type to replace tuple type219 // xxx - should fix this to only generate one tuple struct for each number of type parameters220 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 ) ); 221 221 decl->set_body( true ); 222 for ( size_t i = 0; i < tuple Type->size(); ++i ) {222 for ( size_t i = 0; i < tupleSize; ++i ) { 223 223 TypeDecl * tyParam = new TypeDecl( toString("tuple_param_", i), DeclarationNode::NoStorageClass, nullptr, TypeDecl::Any ); 224 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 ) ); 225 225 decl->get_parameters().push_back( tyParam ); 226 226 } 227 if ( tuple Type->size()== 0 ) {227 if ( tupleSize == 0 ) { 228 228 // empty structs are not standard C. Add a dummy field to empty tuples to silence warnings when a compound literal Tuple0 is created. 229 229 decl->get_members().push_back( new ObjectDecl( "dummy", DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) ); 230 230 } 231 typeMap[ mangleName] = decl;231 typeMap[tupleSize] = decl; 232 232 addDeclaration( decl ); 233 233 } 234 234 Type::Qualifiers qualifiers = tupleType->get_qualifiers(); 235 235 236 StructDecl * decl = typeMap[ mangleName];236 StructDecl * decl = typeMap[tupleSize]; 237 237 StructInstType * newType = new StructInstType( qualifiers, decl ); 238 238 for ( Type * t : *tupleType ) { … … 337 337 public: 338 338 typedef Visitor Parent; 339 virtual void visit( ApplicationExpr * appExpr ) { maybeImpure = true; } 339 virtual void visit( ApplicationExpr * appExpr ) { 340 if ( DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) { 341 if ( function->get_linkage() == LinkageSpec::Intrinsic ) { 342 if ( function->get_name() == "*?" || function->get_name() == "?[?]" ) { 343 // intrinsic dereference, subscript are pure, but need to recursively look for impurity 344 Parent::visit( appExpr ); 345 return; 346 } 347 } 348 } 349 maybeImpure = true; 350 } 340 351 virtual void visit( UntypedExpr * untypedExpr ) { maybeImpure = true; } 341 352 bool maybeImpure = false;
Note:
See TracChangeset
for help on using the changeset viewer.