clang  10.0.0git
Synthesis.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
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.
15 public:
16  static void setCanModify(syntax::Node *N) { N->CanModify = true; }
17 
19  syntax::NodeRole R) {
20  T->prependChildLowLevel(Child, R);
21  }
22 };
23 
26  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
28  .second;
29  assert(Tokens.size() == 1);
30  assert(Tokens.front().kind() == K);
31  auto *L = new (A.allocator()) clang::syntax::Leaf(Tokens.begin());
33  L->assertInvariants();
34  return L;
35 }
36 
39  auto *S = new (A.allocator()) clang::syntax::EmptyStatement;
43  S->assertInvariants();
44  return S;
45 }
Children of an unknown semantic nature, e.g. skipped tokens, comments.
std::pair< FileID, llvm::ArrayRef< syntax::Token > > lexBuffer(std::unique_ptr< llvm::MemoryBuffer > Buffer)
Add Buffer to the underlying source manager, tokenize it and store the resulting tokens.
Definition: Tree.cpp:44
A node in a syntax tree.
Definition: Tree.h:76
llvm::BumpPtrAllocator & allocator()
Definition: Tree.h:48
A memory arena for syntax trees.
Definition: Tree.h:39
The no-op statement, i.e. &#39;;&#39;.
Definition: Nodes.h:170
clang::syntax::Leaf * createPunctuation(clang::syntax::Arena &A, clang::tok::TokenKind K)
Definition: Synthesis.cpp:24
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like &#39;!&#39; or &#39;&#39;, and returns NULL for literal and...
Definition: TokenKinds.cpp:31
clang::syntax::EmptyStatement * createEmptyStatement(clang::syntax::Arena &A)
Definition: Synthesis.cpp:38
A node that has children and represents a syntactic language construct.
Definition: Tree.h:150
Exposes private syntax tree APIs required to implement node synthesis.
Definition: Synthesis.cpp:14
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:24
static void prependChildLowLevel(syntax::Tree *T, syntax::Node *Child, syntax::NodeRole R)
Definition: Synthesis.cpp:18
NodeRole
A relation between a parent and child node, e.g.
Definition: Nodes.h:78
Dataflow Directional Tag Classes.
A leaf node points to a single token inside the expanded token stream.
Definition: Tree.h:138
static void setCanModify(syntax::Node *N)
Definition: Synthesis.cpp:16