Skip to content

Commit 53e5145

Browse files
committed
[IDE] Add SourceFile property to ResolvedCursorInfo
1 parent d442fb8 commit 53e5145

File tree

2 files changed

+40
-42
lines changed

2 files changed

+40
-42
lines changed

include/swift/IDE/Utils.h

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ enum class CursorInfoKind {
157157

158158
struct ResolvedCursorInfo {
159159
CursorInfoKind Kind = CursorInfoKind::Invalid;
160+
SourceFile *SF;
161+
SourceLoc Loc;
160162
ValueDecl *ValueD = nullptr;
161163
TypeDecl *CtorTyRef = nullptr;
162164
ExtensionDecl *ExtTyRef = nullptr;
163-
SourceFile *SF = nullptr;
164165
ModuleEntity Mod;
165-
SourceLoc Loc;
166166
bool IsRef = true;
167167
bool IsKeywordArgument = false;
168168
Type Ty;
@@ -172,39 +172,36 @@ struct ResolvedCursorInfo {
172172
Expr *TrailingExpr = nullptr;
173173

174174
ResolvedCursorInfo() = default;
175-
ResolvedCursorInfo(ValueDecl *ValueD,
176-
TypeDecl *CtorTyRef,
177-
ExtensionDecl *ExtTyRef,
178-
SourceFile *SF,
179-
SourceLoc Loc,
180-
bool IsRef,
181-
Type Ty,
182-
Type ContainerType) :
183-
Kind(CursorInfoKind::ValueRef),
184-
ValueD(ValueD),
185-
CtorTyRef(CtorTyRef),
186-
ExtTyRef(ExtTyRef),
187-
SF(SF),
188-
Loc(Loc),
189-
IsRef(IsRef),
190-
Ty(Ty),
191-
DC(ValueD->getDeclContext()),
192-
ContainerType(ContainerType) {}
193-
ResolvedCursorInfo(ModuleEntity Mod,
194-
SourceFile *SF,
195-
SourceLoc Loc) :
196-
Kind(CursorInfoKind::ModuleRef),
197-
SF(SF),
198-
Mod(Mod),
199-
Loc(Loc) {}
200-
ResolvedCursorInfo(Stmt *TrailingStmt, SourceFile *SF) :
201-
Kind(CursorInfoKind::StmtStart),
202-
SF(SF),
203-
TrailingStmt(TrailingStmt) {}
204-
ResolvedCursorInfo(Expr* TrailingExpr, SourceFile *SF) :
205-
Kind(CursorInfoKind::ExprStart),
206-
SF(SF),
207-
TrailingExpr(TrailingExpr) {}
175+
ResolvedCursorInfo(SourceFile *SF) : SF(SF) {}
176+
177+
void setValueRef(ValueDecl *ValueD,
178+
TypeDecl *CtorTyRef,
179+
ExtensionDecl *ExtTyRef,
180+
bool IsRef,
181+
Type Ty,
182+
Type ContainerType) {
183+
Kind = CursorInfoKind::ValueRef;
184+
this->ValueD = ValueD;
185+
this->CtorTyRef = CtorTyRef;
186+
this->ExtTyRef = ExtTyRef;
187+
this->IsRef = IsRef;
188+
this->Ty = Ty;
189+
this->DC = ValueD->getDeclContext();
190+
this->ContainerType = ContainerType;
191+
}
192+
void setModuleRef(ModuleEntity Mod) {
193+
Kind = CursorInfoKind::ModuleRef;
194+
this->Mod = Mod;
195+
}
196+
void setTrailingStmt(Stmt *TrailingStmt) {
197+
Kind = CursorInfoKind::StmtStart;
198+
this->TrailingStmt = TrailingStmt;
199+
}
200+
void setTrailingExpr(Expr* TrailingExpr) {
201+
Kind = CursorInfoKind::ExprStart;
202+
this->TrailingExpr = TrailingExpr;
203+
}
204+
208205
bool isValid() const { return !isInvalid(); }
209206
bool isInvalid() const { return Kind == CursorInfoKind::Invalid; }
210207
};
@@ -217,7 +214,8 @@ class CursorInfoResolver : public SourceEntityWalker {
217214
llvm::SmallVector<Expr*, 4> TrailingExprStack;
218215

219216
public:
220-
explicit CursorInfoResolver(SourceFile &SrcFile) : SrcFile(SrcFile) { }
217+
explicit CursorInfoResolver(SourceFile &SrcFile) :
218+
SrcFile(SrcFile), CursorInfo(&SrcFile) {}
221219
ResolvedCursorInfo resolve(SourceLoc Loc);
222220
SourceManager &getSourceMgr() const;
223221
private:

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ bool CursorInfoResolver::tryResolve(ValueDecl *D, TypeDecl *CtorTyRef,
8080
return false;
8181

8282
if (Loc == LocToResolve) {
83-
CursorInfo = { D, CtorTyRef, ExtTyRef, &SrcFile, Loc, IsRef, Ty, ContainerType };
83+
CursorInfo.setValueRef(D, CtorTyRef, ExtTyRef, IsRef, Ty, ContainerType);
8484
return true;
8585
}
8686
return false;
8787
}
8888

8989
bool CursorInfoResolver::tryResolve(ModuleEntity Mod, SourceLoc Loc) {
9090
if (Loc == LocToResolve) {
91-
CursorInfo = { Mod, &SrcFile, Loc };
91+
CursorInfo.setModuleRef(Mod);
9292
return true;
9393
}
9494
return false;
@@ -97,13 +97,13 @@ bool CursorInfoResolver::tryResolve(ModuleEntity Mod, SourceLoc Loc) {
9797
bool CursorInfoResolver::tryResolve(Stmt *St) {
9898
if (auto *LST = dyn_cast<LabeledStmt>(St)) {
9999
if (LST->getStartLoc() == LocToResolve) {
100-
CursorInfo = { St, &SrcFile };
100+
CursorInfo.setTrailingStmt(St);
101101
return true;
102102
}
103103
}
104104
if (auto *CS = dyn_cast<CaseStmt>(St)) {
105105
if (CS->getStartLoc() == LocToResolve) {
106-
CursorInfo = { St, &SrcFile };
106+
CursorInfo.setTrailingStmt(St);
107107
return true;
108108
}
109109
}
@@ -120,7 +120,7 @@ bool CursorInfoResolver::visitSubscriptReference(ValueDecl *D, CharSourceRange R
120120
ResolvedCursorInfo CursorInfoResolver::resolve(SourceLoc Loc) {
121121
assert(Loc.isValid());
122122
LocToResolve = Loc;
123-
CursorInfo = ResolvedCursorInfo();
123+
CursorInfo.Loc = Loc;
124124
walk(SrcFile);
125125
return CursorInfo;
126126
}
@@ -211,7 +211,7 @@ bool CursorInfoResolver::walkToExprPost(Expr *E) {
211211
return false;
212212
if (!TrailingExprStack.empty() && TrailingExprStack.back() == E) {
213213
// We return the outtermost expression in the token info.
214-
CursorInfo = { TrailingExprStack.front(), &SrcFile };
214+
CursorInfo.setTrailingExpr(TrailingExprStack.front());
215215
return false;
216216
}
217217
return true;

0 commit comments

Comments
 (0)