1 //===- Synthesis.cpp ------------------------------------------*- C++ -*-=====//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 #include "clang/Tooling/Syntax/BuildTree.h"
10 using namespace clang;
12 /// Exposes private syntax tree APIs required to implement node synthesis.
13 /// Should not be used for anything else.
14 class syntax::FactoryImpl {
16 static void setCanModify(syntax::Node *N) { N->CanModify = true; }
18 static void prependChildLowLevel(syntax::Tree *T, syntax::Node *Child,
20 T->prependChildLowLevel(Child, R);
24 clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
25 clang::tok::TokenKind K) {
26 auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
27 clang::tok::getPunctuatorSpelling(K)))
29 assert(Tokens.size() == 1);
30 assert(Tokens.front().kind() == K);
31 auto *L = new (A.allocator()) clang::syntax::Leaf(Tokens.begin());
32 FactoryImpl::setCanModify(L);
33 L->assertInvariants();
37 clang::syntax::EmptyStatement *
38 syntax::createEmptyStatement(clang::syntax::Arena &A) {
39 auto *S = new (A.allocator()) clang::syntax::EmptyStatement;
40 FactoryImpl::setCanModify(S);
41 FactoryImpl::prependChildLowLevel(S, createPunctuation(A, clang::tok::semi),
43 S->assertInvariants();