Changes in src/Tuples/TupleExpansion.cc [e6512c8:c0aa336]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/TupleExpansion.cc
re6512c8 rc0aa336 29 29 #include "ResolvExpr/typeops.h" 30 30 #include "InitTweak/GenInit.h" 31 #include "InitTweak/InitTweak.h"32 31 33 32 namespace Tuples { … … 79 78 } 80 79 private: 81 ScopedMap< int, StructDecl * > typeMap;80 ScopedMap< std::string, StructDecl * > typeMap; 82 81 }; 83 82 … … 214 213 215 214 Type * TupleTypeReplacer::mutate( TupleType * tupleType ) { 215 std::string mangleName = SymTab::Mangler::mangleType( tupleType ); 216 216 tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) ); 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 tuple220 StructDecl * decl = new StructDecl( toString( "_tuple_type_", tupleSize ));217 if ( ! typeMap.count( mangleName ) ) { 218 // generate struct type to replace tuple type 219 // xxx - should fix this to only generate one tuple struct for each number of type parameters 220 StructDecl * decl = new StructDecl( "_tuple_type_" + mangleName ); 221 221 decl->set_body( true ); 222 for ( size_t i = 0; i < tuple Size; ++i ) {222 for ( size_t i = 0; i < tupleType->size(); ++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 Size== 0 ) {227 if ( tupleType->size() == 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[ tupleSize] = decl;231 typeMap[mangleName] = decl; 232 232 addDeclaration( decl ); 233 233 } 234 234 Type::Qualifiers qualifiers = tupleType->get_qualifiers(); 235 235 236 StructDecl * decl = typeMap[ tupleSize];236 StructDecl * decl = typeMap[mangleName]; 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 ) { 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 } 339 virtual void visit( ApplicationExpr * appExpr ) { maybeImpure = true; } 351 340 virtual void visit( UntypedExpr * untypedExpr ) { maybeImpure = true; } 352 341 bool maybeImpure = false;
Note: See TracChangeset
for help on using the changeset viewer.