[PATCH] D64576: [Syntax] Do not add a node for 'eof' into the tree
Phabricator via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 6 10:07:31 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368062: [Syntax] Do not add a node for 'eof' into the tree (authored by ibiryukov, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D64576?vs=209270&id=213650#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D64576/new/
https://reviews.llvm.org/D64576
Files:
cfe/trunk/lib/Tooling/Syntax/BuildTree.cpp
cfe/trunk/unittests/Tooling/Syntax/TreeTest.cpp
Index: cfe/trunk/lib/Tooling/Syntax/BuildTree.cpp
===================================================================
--- cfe/trunk/lib/Tooling/Syntax/BuildTree.cpp
+++ cfe/trunk/lib/Tooling/Syntax/BuildTree.cpp
@@ -58,8 +58,11 @@
/// Finish building the tree and consume the root node.
syntax::TranslationUnit *finalize() && {
auto Tokens = Arena.tokenBuffer().expandedTokens();
+ assert(!Tokens.empty());
+ assert(Tokens.back().kind() == tok::eof);
+
// Build the root of the tree, consuming all the children.
- Pending.foldChildren(Tokens,
+ Pending.foldChildren(Tokens.drop_back(),
new (Arena.allocator()) syntax::TranslationUnit);
return cast<syntax::TranslationUnit>(std::move(Pending).finalize());
@@ -96,10 +99,11 @@
/// Ensures that added nodes properly nest and cover the whole token stream.
struct Forest {
Forest(syntax::Arena &A) {
- // FIXME: do not add 'eof' to the tree.
-
+ assert(!A.tokenBuffer().expandedTokens().empty());
+ assert(A.tokenBuffer().expandedTokens().back().kind() == tok::eof);
// Create all leaf nodes.
- for (auto &T : A.tokenBuffer().expandedTokens())
+ // Note that we do not have 'eof' in the tree.
+ for (auto &T : A.tokenBuffer().expandedTokens().drop_back())
Trees.insert(Trees.end(),
{&T, NodeAndRole{new (A.allocator()) syntax::Leaf(&T)}});
}
Index: cfe/trunk/unittests/Tooling/Syntax/TreeTest.cpp
===================================================================
--- cfe/trunk/unittests/Tooling/Syntax/TreeTest.cpp
+++ cfe/trunk/unittests/Tooling/Syntax/TreeTest.cpp
@@ -138,15 +138,14 @@
| `-CompoundStatement
| |-2: {
| `-3: }
-|-TopLevelDeclaration
-| |-void
-| |-foo
-| |-(
-| |-)
-| `-CompoundStatement
-| |-2: {
-| `-3: }
-`-<eof>
+`-TopLevelDeclaration
+ |-void
+ |-foo
+ |-(
+ |-)
+ `-CompoundStatement
+ |-2: {
+ `-3: }
)txt"},
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64576.213650.patch
Type: text/x-patch
Size: 1960 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190806/6eed2895/attachment.bin>
More information about the cfe-commits
mailing list