1 //===- Synthesis.cpp ------------------------------------------*- C++ -*-=====// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 #include "clang/Tooling/Syntax/BuildTree.h" 9 10 using namespace clang; 11 12 /// Exposes private syntax tree APIs required to implement node synthesis. 13 /// Should not be used for anything else. 14 class syntax::FactoryImpl { 15 public: 16 static void prependChildLowLevel(syntax::Tree *T, syntax::Node *Child, 17 syntax::NodeRole R) { 18 T->prependChildLowLevel(Child, R); 19 } 20 }; 21 22 clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A, 23 clang::tok::TokenKind K) { 24 auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer( 25 clang::tok::getPunctuatorSpelling(K))) 26 .second; 27 assert(Tokens.size() == 1); 28 assert(Tokens.front().kind() == K); 29 return new (A.allocator()) clang::syntax::Leaf(Tokens.begin()); 30 } 31 32 clang::syntax::EmptyStatement * 33 syntax::createEmptyStatement(clang::syntax::Arena &A) { 34 auto *S = new (A.allocator()) clang::syntax::EmptyStatement; 35 FactoryImpl::prependChildLowLevel(S, createPunctuation(A, clang::tok::semi), 36 NodeRole::Unknown); 37 return S; 38 } 39