summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
diff options
context:
space:
mode:
authorVlad Tsyrklevich <vlad@tsyrklevich.net>2017-08-18 23:21:11 +0000
committerVlad Tsyrklevich <vlad@tsyrklevich.net>2017-08-18 23:21:11 +0000
commitdeb2a2adc87fa69da694d15fe1dfd45b99218529 (patch)
tree496bce5bc13c4d6959e9b3fc56fa61c7b4a487ae /clang/lib/Tooling/ASTDiff/ASTDiff.cpp
parentebcb773f7d27aeff6a67cce8197e1285157dac06 (diff)
downloadbcm5719-llvm-deb2a2adc87fa69da694d15fe1dfd45b99218529.tar.gz
bcm5719-llvm-deb2a2adc87fa69da694d15fe1dfd45b99218529.zip
Revert "[clang-diff] Move the JSON export function to clang-diff"
This reverts commit r311199, it was causing widespread build failures. llvm-svn: 311211
Diffstat (limited to 'clang/lib/Tooling/ASTDiff/ASTDiff.cpp')
-rw-r--r--clang/lib/Tooling/ASTDiff/ASTDiff.cpp54
1 files changed, 26 insertions, 28 deletions
diff --git a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
index 0441dbc78da..3c8d0024dd6 100644
--- a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
+++ b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -176,6 +176,9 @@ 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;
@@ -435,6 +438,28 @@ 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;
@@ -649,12 +674,6 @@ 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 {
@@ -980,28 +999,7 @@ void ASTDiff::printMatch(raw_ostream &OS, const Match &M) const {
SyntaxTree::~SyntaxTree() = default;
-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};
-}
+void SyntaxTree::printAsJson(raw_ostream &OS) { TreeImpl->printAsJsonImpl(OS); }
std::string SyntaxTree::getNodeValue(const DynTypedNode &DTN) const {
return TreeImpl->getNodeValue(DTN);
OpenPOWER on IntegriCloud