@@ -85,6 +85,9 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
8585 void visitDeclRefExpr (swift::DeclRefExpr* expr) {
8686 auto label = dispatcher_.assignNewLabel (expr);
8787 dispatcher_.emit (DeclRefExprsTrap{label, dispatcher_.fetchLabel (expr->getDecl ())});
88+ emitAccessorSemantics<DeclRefExprHasDirectToStorageSemanticsTrap,
89+ DeclRefExprHasDirectToImplementationSemanticsTrap,
90+ DeclRefExprHasOrdinarySemanticsTrap>(expr, label);
8891 auto i = 0u ;
8992 for (auto t : expr->getDeclRef ().getSubstitutions ().getReplacementTypes ()) {
9093 dispatcher_.emit (DeclRefExprReplacementTypesTrap{label, i++, dispatcher_.fetchLabel (t)});
@@ -398,16 +401,24 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
398401 emitExplicitCastExpr (expr, label);
399402 }
400403
404+ void visitLookupExpr (swift::LookupExpr* expr) {
405+ auto label = dispatcher_.assignNewLabel (expr);
406+ emitLookupExpr (expr, label);
407+ }
408+
401409 void visitSubscriptExpr (swift::SubscriptExpr* expr) {
402410 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);
406416
407417 auto i = 0u ;
408418 for (const auto & arg : *expr->getArgs ()) {
409419 dispatcher_.emit (SubscriptExprArgumentsTrap{label, i++, emitArgument (arg)});
410420 }
421+ emitLookupExpr (expr, label);
411422 }
412423
413424 void visitDictionaryExpr (swift::DictionaryExpr* expr) {
@@ -434,10 +445,13 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
434445
435446 void visitMemberRefExpr (swift::MemberRefExpr* expr) {
436447 auto label = dispatcher_.assignNewLabel (expr);
437- assert (expr-> getBase () && " MemberRefExpr has getBase() " );
448+ dispatcher_. emit (MemberRefExprsTrap{label} );
438449
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);
441455 }
442456
443457 void visitDerivedToBaseExpr (swift::DerivedToBaseExpr* expr) {
@@ -542,6 +556,38 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
542556 dispatcher_.emit (SelfApplyExprsTrap{label, baseLabel});
543557 emitApplyExpr (expr, label);
544558 }
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+ }
545591};
546592
547593} // namespace codeql
0 commit comments