summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/clang/lib/Tooling/Syntax/Synthesis.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/llvm/clang/lib/Tooling/Syntax/Synthesis.cpp')
-rw-r--r--gnu/llvm/clang/lib/Tooling/Syntax/Synthesis.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/gnu/llvm/clang/lib/Tooling/Syntax/Synthesis.cpp b/gnu/llvm/clang/lib/Tooling/Syntax/Synthesis.cpp
new file mode 100644
index 00000000000..aa01a34c761
--- /dev/null
+++ b/gnu/llvm/clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -0,0 +1,45 @@
+//===- Synthesis.cpp ------------------------------------------*- C++ -*-=====//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#include "clang/Tooling/Syntax/BuildTree.h"
+
+using namespace clang;
+
+/// Exposes private syntax tree APIs required to implement node synthesis.
+/// Should not be used for anything else.
+class syntax::FactoryImpl {
+public:
+ static void setCanModify(syntax::Node *N) { N->CanModify = true; }
+
+ static void prependChildLowLevel(syntax::Tree *T, syntax::Node *Child,
+ syntax::NodeRole R) {
+ T->prependChildLowLevel(Child, R);
+ }
+};
+
+clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
+ clang::tok::TokenKind K) {
+ auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
+ clang::tok::getPunctuatorSpelling(K)))
+ .second;
+ assert(Tokens.size() == 1);
+ assert(Tokens.front().kind() == K);
+ auto *L = new (A.allocator()) clang::syntax::Leaf(Tokens.begin());
+ FactoryImpl::setCanModify(L);
+ L->assertInvariants();
+ return L;
+}
+
+clang::syntax::EmptyStatement *
+syntax::createEmptyStatement(clang::syntax::Arena &A) {
+ auto *S = new (A.allocator()) clang::syntax::EmptyStatement;
+ FactoryImpl::setCanModify(S);
+ FactoryImpl::prependChildLowLevel(S, createPunctuation(A, clang::tok::semi),
+ NodeRole::Unknown);
+ S->assertInvariants();
+ return S;
+}