diff options
author | Johannes Altmanninger <aclopte@gmail.com> | 2017-08-19 00:57:38 +0000 |
---|---|---|
committer | Johannes Altmanninger <aclopte@gmail.com> | 2017-08-19 00:57:38 +0000 |
commit | 0da12c841adee9718cd75e4ff4ddc37db89f6832 (patch) | |
tree | 15b0d7f734e3649d28f65b4c82ff3cf8484deab7 /clang/lib/Tooling/ASTDiff/ASTDiff.cpp | |
parent | 91d8af53863aec05c28b38b81c69492d6276e98e (diff) | |
download | bcm5719-llvm-0da12c841adee9718cd75e4ff4ddc37db89f6832.tar.gz bcm5719-llvm-0da12c841adee9718cd75e4ff4ddc37db89f6832.zip |
Revert "Revert "[clang-diff] Move the JSON export function to clang-diff""
This reverts commit eac4c13ac9ea8f12bc049e040c7b9c8a517f54e7, the
original commit *should* not have caused the build failure.
llvm-svn: 311216
Diffstat (limited to 'clang/lib/Tooling/ASTDiff/ASTDiff.cpp')
-rw-r--r-- | clang/lib/Tooling/ASTDiff/ASTDiff.cpp | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp index 3c8d0024dd6..0441dbc78da 100644 --- a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp +++ b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp @@ -176,9 +176,6 @@ public: void printTree(NodeId Root) const; void printTree(raw_ostream &OS, NodeId Root) const; - void printAsJsonImpl(raw_ostream &OS) const; - void printNodeAsJson(raw_ostream &OS, NodeId Id) const; - private: /// Nodes in preorder. std::vector<Node> Nodes; @@ -438,28 +435,6 @@ void SyntaxTree::Impl::printNode(raw_ostream &OS, NodeId Id) const { OS << "(" << PostorderIds[Id] << ")"; } -void SyntaxTree::Impl::printNodeAsJson(raw_ostream &OS, NodeId Id) const { - auto N = getNode(Id); - OS << R"({"type":")" << N.getTypeLabel() << R"(")"; - if (getNodeValue(Id) != "") - OS << R"(,"value":")" << getNodeValue(Id) << R"(")"; - OS << R"(,"children":[)"; - if (N.Children.size() > 0) { - printNodeAsJson(OS, N.Children[0]); - for (size_t I = 1, E = N.Children.size(); I < E; ++I) { - OS << ","; - printNodeAsJson(OS, N.Children[I]); - } - } - OS << "]}"; -} - -void SyntaxTree::Impl::printAsJsonImpl(raw_ostream &OS) const { - OS << R"({"root":)"; - printNodeAsJson(OS, getRootId()); - OS << "}\n"; -} - /// Identifies a node in a subtree by its postorder offset, starting at 1. struct SNodeId { int Id = 0; @@ -674,6 +649,12 @@ private: } }; +ast_type_traits::ASTNodeKind Node::getType() const { + return ASTNode.getNodeKind(); +} + +StringRef Node::getTypeLabel() const { return getType().asStringRef(); } + namespace { // Compares nodes by their depth. struct HeightLess { @@ -999,7 +980,28 @@ void ASTDiff::printMatch(raw_ostream &OS, const Match &M) const { SyntaxTree::~SyntaxTree() = default; -void SyntaxTree::printAsJson(raw_ostream &OS) { TreeImpl->printAsJsonImpl(OS); } +const ASTContext &SyntaxTree::getASTContext() const { return TreeImpl->AST; } + +const Node &SyntaxTree::getNode(NodeId Id) const { + return TreeImpl->getNode(Id); +} + +NodeId SyntaxTree::getRootId() const { return TreeImpl->getRootId(); } + +std::pair<unsigned, unsigned> SyntaxTree::getSourceRangeOffsets(const Node &N) const { + const SourceManager &SrcMgr = TreeImpl->AST.getSourceManager(); + SourceRange Range = N.ASTNode.getSourceRange(); + SourceLocation BeginLoc = Range.getBegin(); + SourceLocation EndLoc = Lexer::getLocForEndOfToken( + Range.getEnd(), /*Offset=*/0, SrcMgr, TreeImpl->AST.getLangOpts()); + if (auto *ThisExpr = N.ASTNode.get<CXXThisExpr>()) { + if (ThisExpr->isImplicit()) + EndLoc = BeginLoc; + } + unsigned Begin = SrcMgr.getFileOffset(SrcMgr.getExpansionLoc(BeginLoc)); + unsigned End = SrcMgr.getFileOffset(SrcMgr.getExpansionLoc(EndLoc)); + return {Begin, End}; +} std::string SyntaxTree::getNodeValue(const DynTypedNode &DTN) const { return TreeImpl->getNodeValue(DTN); |