@@ -85,6 +85,9 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
85
85
void visitDeclRefExpr (swift::DeclRefExpr* expr) {
86
86
auto label = dispatcher_.assignNewLabel (expr);
87
87
dispatcher_.emit (DeclRefExprsTrap{label, dispatcher_.fetchLabel (expr->getDecl ())});
88
+ emitAccessorSemantics<DeclRefExprHasDirectToStorageSemanticsTrap,
89
+ DeclRefExprHasDirectToImplementationSemanticsTrap,
90
+ DeclRefExprHasOrdinarySemanticsTrap>(expr, label);
88
91
auto i = 0u ;
89
92
for (auto t : expr->getDeclRef ().getSubstitutions ().getReplacementTypes ()) {
90
93
dispatcher_.emit (DeclRefExprReplacementTypesTrap{label, i++, dispatcher_.fetchLabel (t)});
@@ -398,16 +401,24 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
398
401
emitExplicitCastExpr (expr, label);
399
402
}
400
403
404
+ void visitLookupExpr (swift::LookupExpr* expr) {
405
+ auto label = dispatcher_.assignNewLabel (expr);
406
+ emitLookupExpr (expr, label);
407
+ }
408
+
401
409
void visitSubscriptExpr (swift::SubscriptExpr* expr) {
402
410
auto label = dispatcher_.assignNewLabel (expr);
403
- assert (expr->getBase () && " SubscriptExpr has getBase()" );
404
- auto baseLabel = dispatcher_.fetchLabel (expr->getBase ());
405
- dispatcher_.emit (SubscriptExprsTrap{label, baseLabel});
411
+ dispatcher_.emit (SubscriptExprsTrap{label});
412
+
413
+ emitAccessorSemantics<SubscriptExprHasDirectToStorageSemanticsTrap,
414
+ SubscriptExprHasDirectToImplementationSemanticsTrap,
415
+ SubscriptExprHasOrdinarySemanticsTrap>(expr, label);
406
416
407
417
auto i = 0u ;
408
418
for (const auto & arg : *expr->getArgs ()) {
409
419
dispatcher_.emit (SubscriptExprArgumentsTrap{label, i++, emitArgument (arg)});
410
420
}
421
+ emitLookupExpr (expr, label);
411
422
}
412
423
413
424
void visitDictionaryExpr (swift::DictionaryExpr* expr) {
@@ -434,10 +445,13 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
434
445
435
446
void visitMemberRefExpr (swift::MemberRefExpr* expr) {
436
447
auto label = dispatcher_.assignNewLabel (expr);
437
- assert (expr-> getBase () && " MemberRefExpr has getBase() " );
448
+ dispatcher_. emit (MemberRefExprsTrap{label} );
438
449
439
- auto baseLabel = dispatcher_.fetchLabel (expr->getBase ());
440
- dispatcher_.emit (MemberRefExprsTrap{label, baseLabel});
450
+ emitAccessorSemantics<MemberRefExprHasDirectToStorageSemanticsTrap,
451
+ MemberRefExprHasDirectToImplementationSemanticsTrap,
452
+ MemberRefExprHasOrdinarySemanticsTrap>(expr, label);
453
+
454
+ emitLookupExpr (expr, label);
441
455
}
442
456
443
457
void visitDerivedToBaseExpr (swift::DerivedToBaseExpr* expr) {
@@ -542,6 +556,38 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
542
556
dispatcher_.emit (SelfApplyExprsTrap{label, baseLabel});
543
557
emitApplyExpr (expr, label);
544
558
}
559
+
560
+ void emitLookupExpr (const swift::LookupExpr* expr, TrapLabel<LookupExprTag> label) {
561
+ assert (expr->getBase () && " LookupExpr has getBase()" );
562
+ auto baseLabel = dispatcher_.fetchLabel (expr->getBase ());
563
+ assert (expr->hasDecl () && " LookupExpr has decl" );
564
+ auto declLabel = dispatcher_.fetchLabel (expr->getDecl ().getDecl ());
565
+ dispatcher_.emit (LookupExprsTrap{label, baseLabel, declLabel});
566
+ }
567
+
568
+ /*
569
+ * `DirectToStorage`, `DirectToImplementation`, and `DirectToImplementation` must be
570
+ * constructable from a `Label` argument, and values of `T` must have a
571
+ * `getAccessSemantics` member that returns a `swift::AccessSemantics`.
572
+ */
573
+ template <typename DirectToStorage,
574
+ typename DirectToImplementation,
575
+ typename Ordinary,
576
+ typename T,
577
+ typename Label>
578
+ void emitAccessorSemantics (T* ast, Label label) {
579
+ switch (ast->getAccessSemantics ()) {
580
+ case swift::AccessSemantics::DirectToStorage:
581
+ dispatcher_.emit (DirectToStorage{label});
582
+ break ;
583
+ case swift::AccessSemantics::DirectToImplementation:
584
+ dispatcher_.emit (DirectToImplementation{label});
585
+ break ;
586
+ case swift::AccessSemantics::Ordinary:
587
+ dispatcher_.emit (Ordinary{label});
588
+ break ;
589
+ }
590
+ }
545
591
};
546
592
547
593
} // namespace codeql
0 commit comments