- Timestamp:
- Dec 5, 2019, 5:49:23 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 924c5ce
- Parents:
- 1805b1b
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
r1805b1b r3b0c8cb 309 309 if( !type_decl ) SemanticError( cast, context_error ); 310 310 if( !dtor_decl ) SemanticError( cast, context_error ); 311 Expression * arg = cast->arg; 312 cast->arg = nullptr; 313 delete cast; 314 return new CastExpr( 315 UntypedExpr::createDeref( 316 new UntypedExpr( new NameExpr( getter_name ), { arg } ) 317 ), 318 new ReferenceType( 319 noQualifiers, 320 new StructInstType( noQualifiers, type_decl ) ) 321 ); 311 assert( cast->result == nullptr ); 312 cast->set_result( new ReferenceType( noQualifiers, new StructInstType( noQualifiers, type_decl ) ) ); 313 cast->concrete_target.field = field_name; 314 cast->concrete_target.getter = getter_name; 322 315 } 323 316 return cast; -
src/ResolvExpr/AlternativeFinder.cc
r1805b1b r3b0c8cb 69 69 void postvisit( CastExpr * castExpr ); 70 70 void postvisit( VirtualCastExpr * castExpr ); 71 void postvisit( KeywordCastExpr * castExpr ); 71 72 void postvisit( UntypedMemberExpr * memberExpr ); 72 73 void postvisit( MemberExpr * memberExpr ); … … 1255 1256 } 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 1313 } 1314 1257 1315 namespace { 1258 1316 /// Gets name from untyped member expression (member must be NameExpr) -
src/SynTree/Expression.h
r1805b1b r3b0c8cb 231 231 enum Target { 232 232 Coroutine, Thread, Monitor, NUMBER_OF_TARGETS 233 } target; 233 }; 234 struct Concrete { 235 std::string field; 236 std::string getter; 237 }; 238 Target target; 239 Concrete concrete_target; 234 240 235 241 KeywordCastExpr( Expression * arg, Target target );
Note: See TracChangeset
for help on using the changeset viewer.