Skip to content

Commit c38c5a6

Browse files
committed
---
yaml --- r: 348918 b: refs/heads/master c: b0e1eb5 h: refs/heads/master
1 parent bbd8e35 commit c38c5a6

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 242f9a72733f0973be85434c89d2c889c877e403
2+
refs/heads/master: b0e1eb518e8029d1591603926f6ea4ebf25a136f
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/Parse/ASTGen.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ class ASTGen {
214214
static SourceLoc advanceLocBegin(const SourceLoc &Loc,
215215
const syntax::Syntax &Node);
216216

217+
/// Advance \p Loc to the last non-missing token of the \p Node or, if it
218+
/// doesn't contain any, the last non-missing token preceding it in the tree.
219+
/// \p Loc must be the leading trivia of the first token in the tree in which
220+
/// \p Node resides
221+
static SourceLoc advanceLocEnd(const SourceLoc &Loc,
222+
const syntax::Syntax &Node);
223+
217224
ValueDecl *lookupInScope(DeclName Name);
218225

219226
void addToScope(ValueDecl *D, bool diagnoseRedefinitions = true);

trunk/include/swift/Syntax/Syntax.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ class Syntax {
169169
/// Returns true if the node is "present" in the source.
170170
bool isPresent() const;
171171

172+
/// Get the node immediately before this current node that does contain a
173+
/// non-missing token. Return nullptr if we cannot find such node.
174+
Optional<Syntax> getPreviousNode() const;
172175

173176
/// Returns the first non-missing token in this syntax. Returns None if there
174177
/// is no non-missing token.

trunk/lib/Parse/ASTGen.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,15 @@ SourceLoc ASTGen::advanceLocBegin(const SourceLoc &Loc, const Syntax &Node) {
13021302
return Loc.getAdvancedLoc(Node.getAbsolutePosition().getOffset());
13031303
}
13041304

1305+
SourceLoc ASTGen::advanceLocEnd(const SourceLoc &Loc, const Syntax &Node) {
1306+
if (auto Tok = Node.getLastToken())
1307+
return advanceLocBegin(Loc, *Tok);
1308+
if (auto Prev = Node.getPreviousNode())
1309+
return advanceLocBegin(Loc, *Prev->getLastToken());
1310+
assert(false && "No tokens in tree?");
1311+
return Loc;
1312+
}
1313+
13051314
StringRef ASTGen::copyAndStripUnderscores(StringRef Orig) {
13061315
return copyAndStripUnderscores(Orig, Context);
13071316
}

trunk/lib/Syntax/Syntax.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ llvm::Optional<Syntax> Syntax::getChild(const size_t N) const {
9898
return Syntax {Root, ChildData.get()};
9999
}
100100

101+
Optional<Syntax> Syntax::getPreviousNode() const {
102+
if (auto prev = getData().getPreviousNode())
103+
return Syntax(Root, prev.get());
104+
return None;
105+
}
106+
101107
Optional<TokenSyntax> Syntax::getFirstToken() const {
102108
if (auto tok = getData().getFirstToken())
103109
return TokenSyntax(Root, tok.get());

trunk/lib/Syntax/SyntaxData.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ RC<SyntaxData> SyntaxData::getNextNode() const {
8585
}
8686

8787
RC<SyntaxData> SyntaxData::getFirstToken() const {
88+
if (getRaw()->isMissing())
89+
return nullptr;
8890
if (getRaw()->isToken()) {
8991
// Get a reference counted version of this
9092
assert(hasParent() && "The syntax tree should not conisist only of the root");
@@ -106,6 +108,8 @@ RC<SyntaxData> SyntaxData::getFirstToken() const {
106108
}
107109

108110
RC<SyntaxData> SyntaxData::getLastToken() const {
111+
if (getRaw()->isMissing())
112+
return nullptr;
109113
if (getRaw()->isToken()) {
110114
// Get a reference counted version of this
111115
assert(hasParent() && "The syntax tree should not conisist only of the root");

0 commit comments

Comments
 (0)