Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r3b0c8cb r7d01cf44  
    6969                void postvisit( CastExpr * castExpr );
    7070                void postvisit( VirtualCastExpr * castExpr );
    71                 void postvisit( KeywordCastExpr * castExpr );
    7271                void postvisit( UntypedMemberExpr * memberExpr );
    7372                void postvisit( MemberExpr * memberExpr );
     
    11891188                assert( toType );
    11901189                toType = resolveTypeof( toType, indexer );
    1191                 assert(!dynamic_cast<TypeofType *>(toType));
    11921190                SymTab::validateType( toType, &indexer );
    11931191                adjustExprType( toType, env, indexer );
     
    12541252                                alt.cost } );
    12551253                }
    1256         }
    1257 
    1258         void AlternativeFinder::Finder::postvisit( KeywordCastExpr * castExpr ) {
    1259                 assertf( castExpr->get_result(), "Cast target should have been set in Validate." );
    1260                 auto ref = dynamic_cast<ReferenceType*>(castExpr->get_result());
    1261                 assert(ref);
    1262                 auto inst = dynamic_cast<StructInstType*>(ref->base);
    1263                 assert(inst);
    1264                 auto target = inst->baseStruct;
    1265 
    1266                 AlternativeFinder finder( indexer, env );
    1267 
    1268                 auto pick_alternatives = [target, this](AltList & found, bool expect_ref) {
    1269                         for(auto & alt : found) {
    1270                                 Type * expr = alt.expr->get_result();
    1271                                 if(expect_ref) {
    1272                                         auto res = dynamic_cast<ReferenceType*>(expr);
    1273                                         if(!res) { continue; }
    1274                                         expr = res->base;
    1275                                 }
    1276 
    1277                                 if(auto insttype = dynamic_cast<TypeInstType*>(expr)) {
    1278                                         auto td = alt.env.lookup(insttype->name);
    1279                                         if(!td) { continue; }
    1280                                         expr = td->type;
    1281                                 }
    1282 
    1283                                 if(auto base = dynamic_cast<StructInstType*>(expr)) {
    1284                                         if(base->baseStruct == target) {
    1285                                                 alternatives.push_back(
    1286                                                         std::move(alt)
    1287                                                 );
    1288                                         }
    1289                                 }
    1290                         }
    1291                 };
    1292 
    1293                 try {
    1294                         // Attempt 1 : turn (thread&)X into (thread_desc&)X.__thrd
    1295                         // Clone is purely for memory management
    1296                         std::unique_ptr<Expression> tech1 { new UntypedMemberExpr(new NameExpr(castExpr->concrete_target.field), castExpr->arg->clone()) };
    1297 
    1298                         // don't prune here, since it's guaranteed all alternatives will have the same type
    1299                         finder.findWithoutPrune( tech1.get() );
    1300                         pick_alternatives(finder.alternatives, false);
    1301 
    1302                         return;
    1303                 } catch(SemanticErrorException & ) {}
    1304 
    1305                 // Fallback : turn (thread&)X into (thread_desc&)get_thread(X)
    1306                 std::unique_ptr<Expression> fallback { UntypedExpr::createDeref( new UntypedExpr(new NameExpr(castExpr->concrete_target.getter), { castExpr->arg->clone() })) };
    1307                 // don't prune here, since it's guaranteed all alternatives will have the same type
    1308                 finder.findWithoutPrune( fallback.get() );
    1309 
    1310                 pick_alternatives(finder.alternatives, true);
    1311 
    1312                 // Whatever happens here, we have no more fallbacks
    13131254        }
    13141255
Note: See TracChangeset for help on using the changeset viewer.