File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -590,6 +590,30 @@ ASTWalker::PreWalkResult<Expr *> SemaAnnotator::walkToExprPre(Expr *E) {
590
590
return Action::Stop ();
591
591
// We already visited the children.
592
592
return doSkipChildren ();
593
+ } else if (auto ME = dyn_cast<MacroExpansionExpr>(E)) {
594
+ // The macro itself.
595
+ auto macroRef = ME->getMacroRef ();
596
+ auto macroDecl = macroRef.getDecl ();
597
+ auto macroRefType =
598
+ macroDecl->getInterfaceType ().subst (macroRef.getSubstitutions ());
599
+ if (!passReference (
600
+ macroDecl, macroRefType, ME->getMacroNameLoc (),
601
+ ReferenceMetaData (SemaReferenceKind::DeclRef, None)))
602
+ return Action::Stop ();
603
+
604
+ // Walk the arguments, since they were written directly by the user.
605
+ if (auto argList = ME->getArgs ()) {
606
+ if (!argList->walk (*this ))
607
+ return Action::Stop ();
608
+ }
609
+
610
+ if (auto rewritten = ME->getRewritten ()) {
611
+ if (!rewritten->walk (*this ))
612
+ return Action::Stop ();
613
+ }
614
+
615
+ // Already walked the children.
616
+ return doSkipChildren ();
593
617
}
594
618
595
619
return Action::Continue (E);
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ //
3
+ // RUN: %target-swift-ide-test -print-indexed-symbols -source-filename %s -enable-experimental-feature Macros | %FileCheck %s
4
+
5
+
6
+ macro myLine: Int = _SwiftSyntaxMacros. LineMacro
7
+ macro myFilename< T: ExpressibleByStringLiteral > : T = _SwiftSyntaxMacros. FilePathMacro
8
+ macro myStringify< T> ( _: T ) -> ( T , String ) = _SwiftSyntaxMacros. StringifyMacro
9
+
10
+ func test( x: Int ) {
11
+ _ = #myLine
12
+ let _: String = #myFilename
13
+ _ = #myStringify ( x + x)
14
+ }
15
+
16
+ // CHECK: 6:7 | macro/Swift | myLine | s:14swift_ide_test6myLineSifm | Def | rel: 0
17
+ // CHECK: 6:15 | struct/Swift | Int | s:Si | Ref | rel: 0
18
+ // CHECK: 7:7 | macro/Swift | myFilename | s:14swift_ide_test10myFilenamexfm | Def | rel: 0
19
+ // CHECK: 7:21 | protocol/Swift | ExpressibleByStringLiteral | s:s26ExpressibleByStringLiteralP | Ref | rel: 0
20
+ // CHECK: 8:7 | macro/Swift | myStringify(_:) | s:14swift_ide_test11myStringifyyx_SStxcfm | Def | rel: 0
21
+
22
+ // CHECK: 11:8 | macro/Swift | myLine | s:14swift_ide_test6myLineSifm | Ref,RelCont | rel: 1
23
+ // CHECK: 12:20 | macro/Swift | myFilename | s:14swift_ide_test10myFilenamexfm | Ref,RelCont | rel: 1
24
+ // CHECK: 13:8 | macro/Swift | myStringify(_:) | s:14swift_ide_test11myStringifyyx_SStxcfm | Ref,RelCont | rel: 1
You can’t perform that action at this time.
0 commit comments