@@ -307,73 +307,6 @@ struct CallingParent {
307307 CallExpr *Call;
308308};
309309
310-
311- // / Finds the parse-only AST nodes and corresponding name and param/argument
312- // / label ranges for a given list of input name start locations
313- // /
314- // / Resolved locations also indicate the nature of the matched occurrence (e.g.
315- // / whether it is within active/inactive code, or a selector or string literal).
316- class NameMatcher : public ASTWalker {
317- SourceFile &SrcFile;
318- std::vector<SourceLoc> LocsToResolve;
319- std::vector<ResolvedLoc> ResolvedLocs;
320- ArrayRef<Token> TokensToCheck;
321-
322- // / The \c ArgumentList of a parent \c CustomAttr (if one exists) and
323- // / the \c SourceLoc of the type name it applies to.
324- llvm::Optional<Located<ArgumentList *>> CustomAttrArgList;
325- unsigned InactiveConfigRegionNestings = 0 ;
326- unsigned SelectorNestings = 0 ;
327-
328- // / The stack of parent CallExprs and the innermost expression they apply to.
329- std::vector<CallingParent> ParentCalls;
330-
331- SourceManager &getSourceMgr () const ;
332-
333- SourceLoc nextLoc () const ;
334- bool isDone () const { return LocsToResolve.empty (); };
335- bool isActive () const { return !InactiveConfigRegionNestings; };
336- bool isInSelector () const { return SelectorNestings; };
337- bool checkComments ();
338- void skipLocsBefore (SourceLoc Start);
339- bool shouldSkip (Expr *E);
340- bool shouldSkip (SourceRange Range);
341- bool shouldSkip (CharSourceRange Range);
342- bool tryResolve (ASTWalker::ParentTy Node, SourceLoc NameLoc);
343- bool tryResolve (ASTWalker::ParentTy Node, DeclNameLoc NameLoc,
344- ArgumentList *Args);
345- bool tryResolve (ASTWalker::ParentTy Node, SourceLoc NameLoc,
346- LabelRangeType RangeType, ArrayRef<CharSourceRange> LabelLocs,
347- llvm::Optional<unsigned > FirstTrailingLabel);
348- bool handleCustomAttrs (Decl *D);
349- ArgumentList *getApplicableArgsFor (Expr* E);
350-
351- MacroWalking getMacroWalkingBehavior () const override {
352- return MacroWalking::Arguments;
353- }
354-
355- PreWalkResult<Expr *> walkToExprPre (Expr *E) override ;
356- PostWalkResult<Expr *> walkToExprPost (Expr *E) override ;
357- PreWalkAction walkToDeclPre (Decl *D) override ;
358- PreWalkResult<Stmt *> walkToStmtPre (Stmt *S) override ;
359- PreWalkAction walkToTypeReprPre (TypeRepr *T) override ;
360- PreWalkResult<Pattern *> walkToPatternPre (Pattern *P) override ;
361- bool shouldWalkIntoGenericParams () override { return true ; }
362- bool shouldWalkIntoUncheckedMacroDefinitions () override { return true ; }
363-
364- PreWalkResult<ArgumentList *>
365- walkToArgumentListPre (ArgumentList *ArgList) override ;
366-
367- // FIXME: Remove this
368- bool shouldWalkAccessorsTheOldWay () override { return true ; }
369-
370- public:
371- explicit NameMatcher (SourceFile &SrcFile) : SrcFile(SrcFile) { }
372- std::vector<ResolvedLoc> resolve (ArrayRef<SourceLoc> Locs,
373- ArrayRef<Token> Tokens);
374- ResolvedLoc resolve (SourceLoc Loc);
375- };
376-
377310enum class RangeKind : int8_t {
378311 Invalid = -1 ,
379312 SingleExpression,
@@ -715,6 +648,19 @@ bool isDynamicRef(Expr *Base, ValueDecl *D, llvm::function_ref<Type(Expr *)> get
715648void getReceiverType (Expr *Base,
716649 SmallVectorImpl<NominalTypeDecl *> &Types);
717650
651+ #if SWIFT_BUILD_SWIFT_SYNTAX
652+ // / Entry point to run the NameMatcher written in swift-syntax.
653+ // /
654+ // / - Parameters:
655+ // / - sourceFile: The source file from which to load the SwiftSyntax tree
656+ // / - locations: The locations to resolve
657+ // / - Returns: A list of `ResolvedLoc` that have been resolved. This list might
658+ // / be shorteder than `locations` if some locations could not be resolved and
659+ // / the resolved locations might be in a different order than `locations`.
660+ std::vector<ResolvedLoc> runNameMatcher (const SourceFile &sourceFile,
661+ ArrayRef<SourceLoc> locations);
662+ #endif
663+
718664} // namespace ide
719665} // namespace swift
720666
0 commit comments