Changeset d9fa60a
- Timestamp:
- Nov 16, 2016, 4:37:50 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:
- 186fd86
- Parents:
- 33a7b6d
- Location:
- src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/GenPoly/Box.cc ¶
r33a7b6d rd9fa60a 98 98 void passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes ); 99 99 /// passes extra type parameters into a polymorphic function application 100 void passTypeVars( ApplicationExpr *appExpr, ReferenceToType *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars );100 void passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ); 101 101 /// wraps a function application with a new temporary for the out-parameter return value 102 102 Expression *addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg ); … … 107 107 Type *replaceWithConcrete( ApplicationExpr *appExpr, Type *type, bool doClone = true ); 108 108 /// wraps a function application returning a polymorphic type with a new temporary for the out-parameter return value 109 Expression *addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, ReferenceToType *polyType, std::list< Expression *>::iterator &arg );109 Expression *addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *polyType, std::list< Expression *>::iterator &arg ); 110 110 Expression *applyAdapter( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ); 111 111 void boxParam( Type *formal, Expression *&arg, const TyVarMap &exprTyVars ); … … 769 769 } 770 770 771 void Pass1::passTypeVars( ApplicationExpr *appExpr, ReferenceToType *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {771 void Pass1::passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) { 772 772 // pass size/align for type variables 773 773 for ( TyVarMap::const_iterator tyParm = exprTyVars.begin(); tyParm != exprTyVars.end(); ++tyParm ) { … … 818 818 819 819 Expression *Pass1::addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg ) { 820 // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.821 // if ( useRetval ) {822 // assert( retval );823 // arg = appExpr->get_args().insert( arg, new VariableExpr( retval ) );824 // arg++;825 // } else {826 827 820 // Create temporary to hold return value of polymorphic function and produce that temporary as a result 828 821 // using a comma expression. Possibly change comma expression into statement expression "{}" for multiple 829 822 // return values. 823 assert( retType ); 830 824 ObjectDecl *newObj = makeTemporary( retType->clone() ); 831 825 Expression *paramExpr = new VariableExpr( newObj ); … … 843 837 appExpr->set_env( 0 ); 844 838 return commaExpr; 845 // } // if846 // return appExpr;847 839 } 848 840 … … 878 870 } 879 871 880 Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, ReferenceToType *dynType, std::list< Expression *>::iterator &arg ) {872 Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *dynType, std::list< Expression *>::iterator &arg ) { 881 873 assert( env ); 882 874 Type *concrete = replaceWithConcrete( appExpr, dynType ); … … 1288 1280 TyVarMap exprTyVars( (TypeDecl::Kind)-1 ); 1289 1281 makeTyVarMap( function, exprTyVars ); 1290 ReferenceToType *concRetType = dynamic_cast< ReferenceToType* >( appExpr->get_result() ); // xxx - is concRetType a good name?1291 1282 ReferenceToType *dynRetType = isDynRet( function, exprTyVars ); 1283 Type *concRetType = appExpr->get_result();// ?: dynRetType; // xxx - is concRetType a good name? 1292 1284 1293 1285 if ( dynRetType ) { … … 1589 1581 // move polymorphic return type to parameter list 1590 1582 if ( isDynRet( funcType ) ) { 1591 DeclarationWithType *ret = funcType->get_returnVals().front();1583 ObjectDecl *ret = safe_dynamic_cast< ObjectDecl* >( funcType->get_returnVals().front() ); 1592 1584 ret->set_type( new PointerType( Type::Qualifiers(), ret->get_type() ) ); 1593 1585 funcType->get_parameters().push_front( ret ); 1594 1586 funcType->get_returnVals().pop_front(); 1587 ret->set_init( nullptr ); // xxx - memory leak? 1595 1588 } 1596 1589 -
TabularUnified src/GenPoly/PolyMutator.cc ¶
r33a7b6d rd9fa60a 149 149 } 150 150 151 Expression *PolyMutator::mutate( StmtExpr * stmtExpr ) { 152 // don't want statements from outer CompoundStmts to be added to this StmtExpr 153 ValueGuard< std::list< Statement* > > oldStmtsToAdd( stmtsToAdd ); 154 ValueGuard< std::list< Statement* > > oldStmtsToAddAfter( stmtsToAddAfter ); 155 156 // xxx - not sure if these are needed, along with appropriate assignments, but I don't think so... 157 // ValueGuard< TyVarMap > oldScopeTyVars; 158 // ValueGuard< TypeSubstitution * > oldEnv; 159 160 stmtsToAdd.clear(); 161 stmtsToAddAfter.clear(); 162 163 stmtExpr->set_result( maybeMutate( stmtExpr->get_result(), *this ) ); 164 stmtExpr->set_statements( maybeMutate( stmtExpr->get_statements(), *this ) ); 165 return stmtExpr; 166 } 151 167 152 168 Initializer *PolyMutator::mutate( SingleInit *singleInit ) { … … 154 170 return singleInit; 155 171 } 156 157 172 } // namespace GenPoly 158 173 -
TabularUnified src/GenPoly/PolyMutator.h ¶
r33a7b6d rd9fa60a 47 47 48 48 virtual Expression* mutate(UntypedExpr *untypedExpr); 49 virtual Expression* mutate( StmtExpr *stmtExpr ); 49 50 50 51 virtual Initializer* mutate(SingleInit *SingleInit); -
TabularUnified src/InitTweak/FixInit.cc ¶
r33a7b6d rd9fa60a 904 904 // insert and resolve default/copy constructor call for each field that's unhandled 905 905 std::list< Statement * > stmt; 906 UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) ); 907 deref->get_args().push_back( new VariableExpr( thisParam ) ); 906 UntypedExpr * deref = UntypedExpr::createDeref( new VariableExpr( thisParam ) ); 908 907 909 908 Expression * arg2 = 0; -
TabularUnified src/ResolvExpr/AlternativeFinder.cc ¶
r33a7b6d rd9fa60a 218 218 std::list< Declaration* > members; 219 219 aggInst->lookup( name, members ); 220 TypeSubstitution sub = TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );221 220 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 222 221 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) { 223 MemberExpr * memExpr = new MemberExpr( dwt, expr->clone() ); 224 sub.apply( memExpr ); 225 alternatives.push_back( Alternative( memExpr, env, newCost ) ); 222 alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) ); 226 223 renameTypes( alternatives.back().expr ); 227 224 } else { -
TabularUnified src/SymTab/Autogen.cc ¶
r33a7b6d rd9fa60a 175 175 176 176 void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, TypeSubstitution & genericSubs, bool isDynamicLayout, bool forward = true ) { 177 // if ( isDynamicLayout && src ) {178 // genericSubs.apply( src );179 // }180 181 177 ObjectDecl * returnVal = NULL; 182 178 if ( ! func->get_functionType()->get_returnVals().empty() ) { … … 187 183 188 184 // assign to destination (and return value if generic) 189 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) ); 190 derefExpr->get_args().push_back( new VariableExpr( dstParam ) ); 185 UntypedExpr *derefExpr = UntypedExpr::createDeref( new VariableExpr( dstParam ) ); 191 186 Expression *dstselect = new MemberExpr( field, derefExpr ); 192 187 genImplicitCall( srcParam, dstselect, func->get_name(), back_inserter( func->get_statements()->get_kids() ), field, forward ); 193 188 194 189 if ( isDynamicLayout && returnVal ) { 195 UntypedExpr *derefRet = new UntypedExpr( new NameExpr( "*?" ) ); 196 derefRet->get_args().push_back( new VariableExpr( returnVal ) ); 197 Expression *retselect = new MemberExpr( field, derefRet ); 190 // xxx - there used to be a dereference on returnVal, but this seems to have been wrong? 191 Expression *retselect = new MemberExpr( field, new VariableExpr( returnVal ) ); 198 192 genImplicitCall( srcParam, retselect, func->get_name(), back_inserter( func->get_statements()->get_kids() ), field, forward ); 199 193 } // if -
TabularUnified src/SynTree/Expression.cc ¶
r33a7b6d rd9fa60a 332 332 } 333 333 334 namespace { 335 TypeSubstitution makeSub( Type * t ) { 336 if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) { 337 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() ); 338 } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) { 339 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() ); 340 } else { 341 assertf( false, "makeSub expects struct or union type for aggregate" ); 342 } 343 } 344 } 345 334 346 335 347 MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) : 336 348 Expression( _aname ), member(_member), aggregate(_aggregate) { 337 set_result( member->get_type()->clone() ); 349 350 TypeSubstitution sub( makeSub( aggregate->get_result() ) ); 351 Type * res = member->get_type()->clone(); 352 sub.apply( res ); 353 set_result( res ); 338 354 get_result()->set_isLvalue( true ); 339 355 } -
TabularUnified src/Tuples/TupleExpansion.cc ¶
r33a7b6d rd9fa60a 93 93 typedef Mutator Parent; 94 94 using Parent::mutate; 95 95 96 96 virtual Expression * mutate( TupleExpr * tupleExpr ) override; 97 97 }; … … 218 218 Type * TupleTypeReplacer::mutate( TupleType * tupleType ) { 219 219 std::string mangleName = SymTab::Mangler::mangleType( tupleType ); 220 TupleType * newType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) );220 tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) ); 221 221 if ( ! typeMap.count( mangleName ) ) { 222 222 // generate struct type to replace tuple type 223 223 StructDecl * decl = new StructDecl( "_tuple_type_" + mangleName ); 224 224 decl->set_body( true ); 225 int cnt = 0; 226 for ( Type * t : *newType ) { 227 decl->get_members().push_back( new ObjectDecl( toString("field_", cnt++), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, t->clone(), nullptr ) ); 225 for ( size_t i = 0; i < tupleType->size(); ++i ) { 226 TypeDecl * tyParam = new TypeDecl( toString("tuple_param_", i), DeclarationNode::NoStorageClass, nullptr, TypeDecl::Any ); 227 decl->get_members().push_back( new ObjectDecl( toString("field_", i), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new TypeInstType( Type::Qualifiers(), tyParam->get_name(), tyParam ), nullptr ) ); 228 decl->get_parameters().push_back( tyParam ); 228 229 } 229 230 typeMap[mangleName] = decl; 230 231 addDeclaration( decl ); 231 232 } 232 Type::Qualifiers qualifiers = newType->get_qualifiers(); 233 delete newType; 234 return new StructInstType( qualifiers, typeMap[mangleName] ); 233 Type::Qualifiers qualifiers = tupleType->get_qualifiers(); 234 235 StructDecl * decl = typeMap[mangleName]; 236 StructInstType * newType = new StructInstType( qualifiers, decl ); 237 for ( Type * t : *tupleType ) { 238 newType->get_parameters().push_back( new TypeExpr( t->clone() ) ); 239 } 240 delete tupleType; 241 return newType; 235 242 } 236 243 -
TabularUnified src/main.cc ¶
r33a7b6d rd9fa60a 266 266 OPTPRINT( "expandUniqueExpr" ); // xxx - is this the right place for this? want to expand ASAP so that subsequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused 267 267 Tuples::expandUniqueExpr( translationUnit ); 268 OPTPRINT( "expandTuples" ); // xxx - is this the right place for this? 269 Tuples::expandTuples( translationUnit ); 268 270 269 271 OPTPRINT("instantiateGenerics") … … 282 284 OPTPRINT( "box" ) 283 285 GenPoly::box( translationUnit ); 284 OPTPRINT( "expandTuples" ); // xxx - is this the right place for this?285 Tuples::expandTuples( translationUnit );286 286 287 287 // print tree right before code generation -
TabularUnified src/tests/tupleFunction.c ¶
r33a7b6d rd9fa60a 51 51 } 52 52 53 // forall(otype T | { T ?+?(T, T); }) 54 // [T, T, T] ?+?([T, T, T] x, [T, T, T] y) { 55 // T x1, x2, x3, y1, y2, y3; 56 // [x1, x2, x3] = x; 57 // [y1, y2, y3] = y; 58 // return [x1+y1, x2+y2, x3+y3]; 59 // } 53 int main() { 54 [int, double, int] x = [777, 2.76, 8675]; 55 int x1 = 123, x3 = 456; 56 double x2 = 999.123; 60 57 61 int main() { 62 [int, double, int] x = [777, 2.76, 8675]; 63 int x1 = 123, x3 = 456; 64 double x2 = 999.123; 65 66 printf("foo(...)=%d\n", foo(x1, x3, x2, (S){ 321, 654, 'Q', 3.14 })); 58 printf("foo(...)=%d\n", foo(x1, x3, x2, (S){ 321, 654, 'Q', 3.14 })); 67 59 68 60 // call function with tuple parameter using tuple variable arg … … 91 83 [x1, x2, x3] = quux(); 92 84 printf("x1=%d x2=%lg x3=%d\n", x1, x2, x3); 85 86 // xxx - tuples of type parameters should come out as generic types? 87 // [x1, x2, x3] = ([(int)x1, (int)x2, (int)x3]) + ([(int)1, (int)2, (int)3]); 88 // ([(int)x1, (int)x2, (int)x3]) + ([(int)1, (int)2, (int)3]); 89 // printf("%d %g %d\n", x1, x2, x3); 90 91 // xxx - comes out the back as a cast, but should come out as a tuple expression of the first n fields cast to each of the result types 92 // ([int, double])x; 93 93 } 94 94
Note: See TracChangeset
for help on using the changeset viewer.