Changeset 62423350 for src/ResolvExpr
- Timestamp:
- Jun 29, 2017, 5:06:24 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:
- a12d5aa
- Parents:
- bb1cd95
- Location:
- src/ResolvExpr
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
rbb1cd95 r62423350 809 809 } 810 810 811 Expression * restructureCast( Expression * argExpr, Type * toType ) { 812 if ( argExpr->get_result()->size() > 1 && ! toType->isVoid() ) { 813 // Argument expression is a tuple and the target type is not void. Cast each member of the tuple 814 // to its corresponding target type, producing the tuple of those cast expressions. If there are 815 // more components of the tuple than components in the target type, then excess components do not 816 // come out in the result expression (but UniqueExprs ensure that side effects will still be done). 817 if ( Tuples::maybeImpure( argExpr ) && ! dynamic_cast< UniqueExpr * >( argExpr ) ) { 818 // expressions which may contain side effects require a single unique instance of the expression. 819 argExpr = new UniqueExpr( argExpr ); 820 } 821 std::list< Expression * > componentExprs; 822 for ( unsigned int i = 0; i < toType->size(); i++ ) { 823 // cast each component 824 TupleIndexExpr * idx = new TupleIndexExpr( argExpr->clone(), i ); 825 componentExprs.push_back( restructureCast( idx, toType->getComponent( i ) ) ); 826 } 827 delete argExpr; 828 assert( componentExprs.size() > 0 ); 829 // produce the tuple of casts 830 return new TupleExpr( componentExprs ); 831 } else { 832 // handle normally 833 return new CastExpr( argExpr, toType->clone() ); 834 } 835 } 836 811 837 void AlternativeFinder::visit( CastExpr *castExpr ) { 812 838 Type *& toType = castExpr->get_result(); … … 840 866 thisCost += Cost( 0, 0, discardedValues ); 841 867 842 Expression * argExpr = i->expr->clone(); 843 if ( argExpr->get_result()->size() > 1 && ! castExpr->get_result()->isVoid() ) { 844 // Argument expression is a tuple and the target type is not void. Cast each member of the tuple 845 // to its corresponding target type, producing the tuple of those cast expressions. If there are 846 // more components of the tuple than components in the target type, then excess components do not 847 // come out in the result expression (but UniqueExprs ensure that side effects will still be done). 848 if ( Tuples::maybeImpure( argExpr ) && ! dynamic_cast< UniqueExpr * >( argExpr ) ) { 849 // expressions which may contain side effects require a single unique instance of the expression. 850 argExpr = new UniqueExpr( argExpr ); 851 } 852 std::list< Expression * > componentExprs; 853 for ( unsigned int i = 0; i < castExpr->get_result()->size(); i++ ) { 854 // cast each component 855 TupleIndexExpr * idx = new TupleIndexExpr( argExpr->clone(), i ); 856 componentExprs.push_back( new CastExpr( idx, castExpr->get_result()->getComponent( i )->clone() ) ); 857 } 858 delete argExpr; 859 assert( componentExprs.size() > 0 ); 860 // produce the tuple of casts 861 candidates.push_back( Alternative( new TupleExpr( componentExprs ), i->env, i->cost, thisCost ) ); 862 } else { 863 // handle normally 864 candidates.push_back( Alternative( new CastExpr( argExpr->clone(), toType->clone() ), i->env, i->cost, thisCost ) ); 865 } 868 candidates.push_back( Alternative( restructureCast( i->expr->clone(), toType ), i->env, i->cost, thisCost ) ); 866 869 } // if 867 870 } // for … … 1183 1186 1184 1187 void AlternativeFinder::visit( UntypedInitExpr *initExpr ) { 1185 AlternativeFinder finder( indexer, env ); 1186 finder.findWithAdjustment( initExpr->get_expr() ); 1187 // handle each option like a cast -- should probably push this info into AltFinder as a kind of expression, both to keep common code close and to have less 'reach-in', but more 'push-in' 1188 // handle each option like a cast 1188 1189 AltList candidates; 1189 std::cerr << "untyped init expr: " << initExpr << std::endl;1190 PRINT( std::cerr << "untyped init expr: " << initExpr << std::endl; ) 1190 1191 // O(N^2) checks of d-types with e-types 1191 for ( Alternative & alt : finder.get_alternatives() ) { 1192 for ( InitAlternative & initAlt : initExpr->get_initAlts() ) { 1192 for ( InitAlternative & initAlt : initExpr->get_initAlts() ) { 1193 Type * toType = resolveTypeof( initAlt.type, indexer ); 1194 SymTab::validateType( toType, &indexer ); 1195 adjustExprType( toType, env, indexer ); 1196 // Ideally the call to findWithAdjustment could be moved out of the loop, but unfortunately it currently has to occur inside or else 1197 // polymorphic return types are not properly bound to the initialization type, since return type variables are only open for the duration of resolving 1198 // the UntypedExpr. This is only actually an issue in initialization contexts that allow more than one possible initialization type, but it is still suboptimal. 1199 AlternativeFinder finder( indexer, env ); 1200 finder.targetType = toType; 1201 finder.findWithAdjustment( initExpr->get_expr() ); 1202 for ( Alternative & alt : finder.get_alternatives() ) { 1203 TypeEnvironment newEnv( alt.env ); 1193 1204 AssertionSet needAssertions, haveAssertions; 1194 OpenVarSet openVars; 1195 std::cerr << " " << initAlt.type << " " << initAlt.designation << std::endl;1205 OpenVarSet openVars; // find things in env that don't have a "representative type" and claim those are open vars? 1206 PRINT( std::cerr << " @ " << toType << " " << initAlt.designation << std::endl; ) 1196 1207 // It's possible that a cast can throw away some values in a multiply-valued expression. (An example is a 1197 1208 // cast-to-void, which casts from one value to zero.) Figure out the prefix of the subexpression results 1198 1209 // that are cast directly. The candidate is invalid if it has fewer results than there are types to cast 1199 1210 // to. 1200 int discardedValues = alt.expr->get_result()->size() - initAlt.type->size();1211 int discardedValues = alt.expr->get_result()->size() - toType->size(); 1201 1212 if ( discardedValues < 0 ) continue; 1202 1213 // xxx - may need to go into tuple types and extract relevant types and use unifyList. Note that currently, this does not 1203 1214 // allow casting a tuple to an atomic type (e.g. (int)([1, 2, 3])) 1204 1215 // unification run for side-effects 1205 unify( initAlt.type, alt.expr->get_result(), alt.env, needAssertions, haveAssertions, openVars, indexer );1206 1207 Cost thisCost = castCost( alt.expr->get_result(), initAlt.type, indexer, alt.env );1216 unify( toType, alt.expr->get_result(), newEnv, needAssertions, haveAssertions, openVars, indexer ); // xxx - do some inspecting on this line... why isn't result bound to initAlt.type?? 1217 1218 Cost thisCost = castCost( alt.expr->get_result(), toType, indexer, newEnv ); 1208 1219 if ( thisCost != Cost::infinity ) { 1209 1220 // count one safe conversion for each value that is thrown away 1210 1221 thisCost += Cost( 0, 0, discardedValues ); 1211 candidates.push_back( Alternative( new InitExpr( alt.expr->clone(), initAlt.type->clone(), initAlt.designation->clone() ), alt.env, alt.cost, thisCost ) );1222 candidates.push_back( Alternative( new InitExpr( restructureCast( alt.expr->clone(), toType ), initAlt.designation->clone() ), newEnv, alt.cost, thisCost ) ); 1212 1223 } 1213 1224 } -
src/ResolvExpr/CurrentObject.cc
rbb1cd95 r62423350 22 22 #include "SynTree/Initializer.h" 23 23 #include "SynTree/Type.h" 24 #include "SynTree/TypeSubstitution.h" 24 25 25 26 #if 0 … … 32 33 long long int getConstValue( ConstantExpr * constExpr ) { 33 34 if ( BasicType * basicType = dynamic_cast< BasicType * >( constExpr->get_result() ) ) { 34 if ( basicType->get_kind() == BasicType::Char || basicType->get_kind() == BasicType::SignedChar || basicType->get_kind() == BasicType::UnsignedChar ) { 35 assertf( constExpr->get_constant()->get_value().size() == 3, "constant value with unusual length: %s", constExpr->get_constant()->get_value().c_str() ); 36 return constExpr->get_constant()->get_value()[1]; 35 if ( basicType->isInteger() ) { 36 return constExpr->get_constant()->get_ival(); 37 37 } else { 38 return stoll( constExpr->get_constant()->get_value() ); 39 } 38 assertf( false, "Non-integer constant expression in getConstValue", toString( constExpr ).c_str() ); // xxx - might be semantic error 39 } 40 } else if ( dynamic_cast< OneType * >( constExpr->get_result() ) ) { 41 return 1; 42 } else if ( dynamic_cast< ZeroType * >( constExpr->get_result() ) ) { 43 return 0; 40 44 } else { 41 assertf( false, "unhandled type on getConstValue %s", constExpr->get_result() );45 assertf( false, "unhandled type on getConstValue %s", toString( constExpr->get_result() ).c_str() ); // xxx - might be semantic error 42 46 } 43 47 } … … 56 60 std::ostream & operator<<( std::ostream & out, Indenter & indent ) { 57 61 return out << std::string(indent.indent, ' '); 62 } 63 64 template< typename AggrInst > 65 TypeSubstitution makeGenericSubstitution( AggrInst * inst ) { 66 assert( inst ); 67 assert( inst->get_baseParameters() ); 68 std::list< TypeDecl * > baseParams = *inst->get_baseParameters(); 69 std::list< Expression * > typeSubs = inst->get_parameters(); 70 TypeSubstitution subs( baseParams.begin(), baseParams.end(), typeSubs.begin() ); 71 return subs; 72 } 73 74 TypeSubstitution makeGenericSubstitution( Type * type ) { 75 if ( StructInstType * inst = dynamic_cast< StructInstType * >( type ) ) { 76 return makeGenericSubstitution( inst ); 77 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( type ) ) { 78 return makeGenericSubstitution( inst ); 79 } else { 80 return TypeSubstitution(); 81 } 58 82 } 59 83 … … 135 159 void setSize( Expression * expr ) { 136 160 if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) { 137 size = getConstValue( constExpr ); // xxx - if not a constant expression, it's not simple to determine how long the array actually is, which is necessary for initialization to be done correctly -- fix this161 size = getConstValue( constExpr ); 138 162 PRINT( std::cerr << "array type with size: " << size << std::endl; ) 139 163 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 140 setSize( castExpr->get_arg() ); 164 setSize( castExpr->get_arg() ); // xxx - need to perform the conversion specified by the cast 141 165 } else { 142 assertf( false, "unhandled expression in setSize: %s", toString( expr ).c_str() ); 166 assertf( false, "unhandled expression in setSize: %s", toString( expr ).c_str() ); // xxx - if not a constant expression, it's not simple to determine how long the array actually is, which is necessary for initialization to be done correctly -- fix this 143 167 } 144 168 } … … 231 255 class AggregateIterator : public MemberIterator { 232 256 public: 233 typedef std::list<Declaration *>::iterator iterator; 234 const char * kind = ""; // for debug 235 ReferenceToType * inst = nullptr; 236 AggregateDecl * decl = nullptr; 257 typedef std::list<Declaration *> MemberList; 258 typedef MemberList::const_iterator iterator; 259 std::string kind = ""; // for debug 260 std::string name; 261 Type * inst = nullptr; 262 const MemberList & members; 237 263 iterator curMember; 238 bool atbegin = true; // false at first {small,big}Step -- this structtype is only added to the possibilities at the beginning264 bool atbegin = true; // false at first {small,big}Step -- this aggr type is only added to the possibilities at the beginning 239 265 Type * curType = nullptr; 240 266 MemberIterator * memberIter = nullptr; 241 242 AggregateIterator( const char * kind, ReferenceToType * inst, AggregateDecl * decl ) : kind( kind ), inst( inst ), decl( decl ), curMember( decl->get_members().begin() ) { 267 mutable TypeSubstitution sub; 268 269 AggregateIterator( const std::string & kind, const std::string & name, Type * inst, const MemberList & members ) : kind( kind ), name( name ), inst( inst ), members( members ), curMember( members.begin() ), sub( makeGenericSubstitution( inst ) ) { 243 270 init(); 244 271 } … … 249 276 250 277 bool init() { 251 PRINT( std::cerr << "--init()--" << std::endl; )252 if ( curMember != decl->get_members().end() ) {278 PRINT( std::cerr << "--init()--" << members.size() << std::endl; ) 279 if ( curMember != members.end() ) { 253 280 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( *curMember ) ) { 254 281 PRINT( std::cerr << "incremented to field: " << field << std::endl; ) … … 264 291 if (memberIter && *memberIter) { 265 292 std::list<InitAlternative> ret = memberIter->first(); 293 PRINT( std::cerr << "sub: " << sub << std::endl; ) 266 294 for ( InitAlternative & alt : ret ) { 267 295 PRINT( std::cerr << "iterating and adding designators" << std::endl; ) 268 296 alt.designation->get_designators().push_front( new VariableExpr( safe_dynamic_cast< ObjectDecl * >( *curMember ) ) ); 297 // need to substitute for generic types, so that casts are to concrete types 298 PRINT( std::cerr << " type is: " << alt.type; ) 299 sub.apply( alt.type ); // also apply to designation?? 300 PRINT( std::cerr << " ==> " << alt.type << std::endl; ) 269 301 } 270 302 return ret; … … 276 308 if ( ! designators.empty() ) { 277 309 if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( designators.front() ) ) { 278 for ( curMember = decl->get_members().begin(); curMember != decl->get_members().end(); ++curMember ) {310 for ( curMember = members.begin(); curMember != members.end(); ++curMember ) { 279 311 if ( *curMember == varExpr->get_var() ) { 280 312 designators.pop_front(); … … 282 314 memberIter = createMemberIterator( varExpr->get_result() ); 283 315 curType = varExpr->get_result(); 284 atbegin = curMember == decl->get_members().begin() && designators.empty(); // xxx - is this right??316 atbegin = curMember == members.begin() && designators.empty(); // xxx - is this the right condition for atbegin?? 285 317 memberIter->setPosition( designators ); 286 318 return; 287 319 } // if 288 320 } // for 289 assertf( false, "could not find member in %s: %s", kind , toString( varExpr ).c_str() );321 assertf( false, "could not find member in %s: %s", kind.c_str(), toString( varExpr ).c_str() ); 290 322 } else { 291 assertf( false, "bad designator given to %s: %s", kind , toString( designators.front() ).c_str() );323 assertf( false, "bad designator given to %s: %s", kind.c_str(), toString( designators.front() ).c_str() ); 292 324 } // if 293 325 } // if … … 336 368 337 369 virtual void print( std::ostream & out, Indenter indent ) const { 338 out << kind << "(" << decl->get_name()<< ")";370 out << kind << "(" << name << ")"; 339 371 if ( memberIter ) { 340 372 Indenter childIndent = indent+1; … … 347 379 class UnionIterator : public AggregateIterator { 348 380 public: 349 UnionIterator( UnionInstType * inst ) : AggregateIterator( "UnionIterator", inst , inst->get_baseUnion() ) {}381 UnionIterator( UnionInstType * inst ) : AggregateIterator( "UnionIterator", inst->get_name(), inst, inst->get_baseUnion()->get_members() ) {} 350 382 351 383 virtual operator bool() const { return (memberIter && *memberIter); } … … 357 389 memberIter = nullptr; 358 390 curType = nullptr; 359 curMember = decl->get_members().end();391 curMember = members.end(); 360 392 return *this; 361 393 } … … 365 397 class StructIterator : public AggregateIterator { 366 398 public: 367 StructIterator( StructInstType * inst ) : AggregateIterator( "StructIterator", inst , inst->get_baseStruct() ) {}368 369 virtual operator bool() const { return curMember != decl->get_members().end() || (memberIter && *memberIter); }399 StructIterator( StructInstType * inst ) : AggregateIterator( "StructIterator", inst->get_name(), inst, inst->get_baseStruct()->get_members() ) {} 400 401 virtual operator bool() const { return curMember != members.end() || (memberIter && *memberIter); } 370 402 371 403 virtual MemberIterator & bigStep() { … … 375 407 memberIter = nullptr; 376 408 curType = nullptr; 377 for ( ; curMember != decl->get_members().end(); ) { 409 for ( ; curMember != members.end(); ) { 410 ++curMember; 411 if ( init() ) { 412 return *this; 413 } 414 } 415 return *this; 416 } 417 }; 418 419 class TupleIterator : public AggregateIterator { 420 public: 421 TupleIterator( TupleType * inst ) : AggregateIterator( "TupleIterator", toString("Tuple", inst->size()), inst, inst->get_members() ) {} 422 423 virtual operator bool() const { return curMember != members.end() || (memberIter && *memberIter); } 424 425 virtual MemberIterator & bigStep() { 426 PRINT( std::cerr << "bigStep in " << kind << std::endl; ) 427 atbegin = false; 428 delete memberIter; 429 memberIter = nullptr; 430 curType = nullptr; 431 for ( ; curMember != members.end(); ) { 378 432 ++curMember; 379 433 if ( init() ) { … … 392 446 return new UnionIterator( uit ); 393 447 } else { 394 assertf( false, "some other reftotype" ); 448 assertf( dynamic_cast< TypeInstType * >( type ), "some other reftotype" ); 449 return new SimpleIterator( type ); 395 450 } 396 451 } else if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 397 452 return new ArrayIterator( at ); 453 } else if ( TupleType * tt = dynamic_cast< TupleType * >( type ) ) { 454 return new TupleIterator( tt ); 398 455 } else { 399 456 return new SimpleIterator( type ); … … 494 551 Type * type = objStack.top()->getNext(); 495 552 if ( type ) { 496 // xxx - record types.front()?497 553 objStack.push( createMemberIterator( type ) ); 498 554 } else { … … 517 573 return **objStack.top(); 518 574 } 575 576 Type * CurrentObject::getCurrentType() { 577 PRINT( std::cerr << "____getting current type" << std::endl; ) 578 assertf( ! objStack.empty(), "objstack empty in getCurrentType" ); 579 return objStack.top()->getNext(); 580 } 519 581 } // namespace ResolvExpr 520 582 -
src/ResolvExpr/CurrentObject.h
rbb1cd95 r62423350 42 42 /// produces a list of alternatives (Type *, Designation *) for the current sub-object's initializer 43 43 std::list< InitAlternative > getOptions(); 44 /// produces the type of the current object but no subobjects 45 Type * getCurrentType(); 44 46 45 47 private: -
src/ResolvExpr/Resolver.cc
rbb1cd95 r62423350 375 375 } 376 376 377 template< typename Aggr >378 void lookupDesignation( Aggr * aggr, const std::list< Expression > & designators ) {379 380 }381 382 377 void Resolver::visit( SingleInit *singleInit ) { 378 // resolve initialization using the possibilities as determined by the currentObject cursor 383 379 UntypedInitExpr * untyped = new UntypedInitExpr( singleInit->get_value(), currentObject.getOptions() ); 384 380 Expression * newExpr = findSingleExpression( untyped, *this ); 385 381 InitExpr * initExpr = safe_dynamic_cast< InitExpr * >( newExpr ); 386 singleInit->set_value( new CastExpr( initExpr->get_expr()->clone(), initExpr->get_result()->clone() ) ); 382 383 // move cursor to the object that is actually initialized 387 384 currentObject.setNext( initExpr->get_designation() ); 385 386 // discard InitExpr wrapper and retain relevant pieces 387 newExpr = initExpr->get_expr(); 388 singleInit->get_value()->set_env( initExpr->get_env() ); 389 initExpr->set_expr( nullptr ); 390 initExpr->set_env( nullptr ); 391 delete initExpr; 392 393 // get the actual object's type (may not exactly match what comes back from the resolver due to conversions) 394 Type * initContext = currentObject.getCurrentType(); 395 396 // check if actual object's type is char[] 397 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) { 398 if ( isCharType( at->get_base() ) ) { 399 // check if the resolved type is char * 400 if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_result() ) ) { 401 if ( isCharType( pt->get_base() ) ) { 402 // strip cast if we're initializing a char[] with a char *, e.g. char x[] = "hello"; 403 CastExpr *ce = safe_dynamic_cast< CastExpr * >( newExpr ); 404 newExpr = ce->get_arg(); 405 ce->set_arg( nullptr ); 406 delete ce; 407 } 408 } 409 } 410 } 411 412 // set initializer expr to resolved express 413 singleInit->set_value( newExpr ); 414 415 // move cursor to next object in preparation for next initializer 388 416 currentObject.increment(); 389 delete initExpr; 390 391 // // check if initializing type is char[] 392 // if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) { 393 // if ( isCharType( at->get_base() ) ) { 394 // // check if the resolved type is char * 395 // if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_result() ) ) { 396 // if ( isCharType( pt->get_base() ) ) { 397 // // strip cast if we're initializing a char[] with a char *, e.g. char x[] = "hello"; 398 // CastExpr *ce = dynamic_cast< CastExpr * >( newExpr ); 399 // singleInit->set_value( ce->get_arg() ); 400 // ce->set_arg( NULL ); 401 // delete ce; 402 // } 403 // } 404 // } 405 // } 406 } 407 408 // template< typename AggrInst > 409 // TypeSubstitution makeGenericSubstitution( AggrInst * inst ) { 410 // assert( inst ); 411 // assert( inst->get_baseParameters() ); 412 // std::list< TypeDecl * > baseParams = *inst->get_baseParameters(); 413 // std::list< Expression * > typeSubs = inst->get_parameters(); 414 // TypeSubstitution subs( baseParams.begin(), baseParams.end(), typeSubs.begin() ); 415 // return subs; 416 // } 417 418 // ReferenceToType * isStructOrUnion( Type * type ) { 419 // if ( StructInstType * sit = dynamic_cast< StructInstType * >( type ) ) { 420 // return sit; 421 // } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( type ) ) { 422 // return uit; 423 // } 424 // return nullptr; 425 // } 426 427 // void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd, TypeSubstitution sub ) { 428 // ObjectDecl * obj = dynamic_cast< ObjectDecl * >( dcl ); 429 // assert( obj ); 430 // // need to substitute for generic types, so that casts are to concrete types 431 // currentObject = obj->clone(); // xxx - delete this 432 // sub.apply( currentObject ); 433 434 // try { 435 // if ( init == initEnd ) return; // stop when there are no more initializers 436 // (*init)->accept( *this ); 437 // ++init; // made it past an initializer 438 // } catch( SemanticError & ) { 439 // // need to delve deeper, if you can 440 // if ( ReferenceToType * type = isStructOrUnion( currentObject->get_type() ) ) { 441 // resolveAggrInit( type, init, initEnd ); 442 // } else { 443 // // member is not an aggregate type, so can't go any deeper 444 445 // // might need to rethink what is being thrown 446 // throw; 447 // } // if 448 // } 449 // } 450 451 // void Resolver::resolveAggrInit( ReferenceToType * inst, InitIterator & init, InitIterator & initEnd ) { 452 // if ( StructInstType * sit = dynamic_cast< StructInstType * >( inst ) ) { 453 // TypeSubstitution sub = makeGenericSubstitution( sit ); 454 // StructDecl * st = sit->get_baseStruct(); 455 // if(st->get_members().empty()) return; 456 // // want to resolve each initializer to the members of the struct, 457 // // but if there are more initializers than members we should stop 458 // list< Declaration * >::iterator it = st->get_members().begin(); 459 // for ( ; it != st->get_members().end(); ++it) { 460 // resolveSingleAggrInit( *it, init, initEnd, sub ); 461 // } 462 // } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( inst ) ) { 463 // TypeSubstitution sub = makeGenericSubstitution( uit ); 464 // UnionDecl * un = uit->get_baseUnion(); 465 // if(un->get_members().empty()) return; 466 // // only resolve to the first member of a union 467 // resolveSingleAggrInit( *un->get_members().begin(), init, initEnd, sub ); 468 // } // if 469 // } 417 } 470 418 471 419 void Resolver::visit( ListInit * listInit ) { 420 // move cursor into brace-enclosed initializer-list 472 421 currentObject.enterListInit(); 473 422 // xxx - fix this so that the list isn't copied, iterator should be used to change current element 474 423 std::list<Designation *> newDesignations; 475 424 for ( auto p : group_iterate(listInit->get_designations(), listInit->get_initializers()) ) { 425 // iterate designations and initializers in pairs, moving the cursor to the current designated object and resolving 426 // the initializer against that object. 476 427 Designation * des = std::get<0>(p); 477 428 Initializer * init = std::get<1>(p); … … 479 430 init->accept( *this ); 480 431 } 432 // set the set of 'resolved' designations and leave the brace-enclosed initializer-list 481 433 listInit->get_designations() = newDesignations; // xxx - memory management 482 434 currentObject.exitListInit(); 483 435 436 // xxx - this part has not be folded into CurrentObject yet 484 437 // } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) { 485 438 // Type * base = tt->get_baseType()->get_base(); -
src/ResolvExpr/Unify.cc
rbb1cd95 r62423350 606 606 } else if ( tupleParam ) { 607 607 // bundle other parameters into tuple to match 608 TupleType* binder = new TupleType{ paramTy->get_qualifiers() };608 std::list< Type * > binderTypes; 609 609 610 610 do { 611 binder ->get_types().push_back( otherParam->get_type()->clone() );611 binderTypes.push_back( otherParam->get_type()->clone() ); 612 612 ++jt; 613 613 … … 618 618 } while (true); 619 619 620 otherParamTy = binder;620 otherParamTy = new TupleType{ paramTy->get_qualifiers(), binderTypes }; 621 621 ++it; // skip ttype parameter for break 622 622 } else if ( otherTupleParam ) { 623 623 // bundle parameters into tuple to match other 624 TupleType* binder = new TupleType{ otherParamTy->get_qualifiers() };624 std::list< Type * > binderTypes; 625 625 626 626 do { 627 binder ->get_types().push_back( param->get_type()->clone() );627 binderTypes.push_back( param->get_type()->clone() ); 628 628 ++it; 629 629 … … 634 634 } while (true); 635 635 636 paramTy = binder;636 paramTy = new TupleType{ otherParamTy->get_qualifiers(), binderTypes }; 637 637 ++jt; // skip ttype parameter for break 638 638 } … … 756 756 return function->get_returnVals().front()->get_type()->clone(); 757 757 } else { 758 TupleType * tupleType = new TupleType( Type::Qualifiers() );758 std::list< Type * > types; 759 759 for ( DeclarationWithType * decl : function->get_returnVals() ) { 760 t upleType->get_types().push_back( decl->get_type()->clone() );760 types.push_back( decl->get_type()->clone() ); 761 761 } // for 762 return tupleType;762 return new TupleType( Type::Qualifiers(), types ); 763 763 } 764 764 }
Note:
See TracChangeset
for help on using the changeset viewer.