24 T->prependChildLowLevel(Child, R);
28 T->appendChildLowLevel(Child, R);
31 static std::pair<FileID, ArrayRef<Token>>
33 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
34 return TBTM.lexBuffer(std::move(Buffer));
44 FactoryImpl::lexBuffer(TBTM, llvm::MemoryBuffer::getMemBufferCopy(Spelling))
46 assert(Tokens.size() == 1);
47 assert(Tokens.front().kind() == K &&
48 "spelling is not lexed into the expected kind of token");
64 "Cannot infer the spelling of the token from its token kind.");
72 case syntax::NodeKind::Leaf:
75 case syntax::NodeKind::TranslationUnit:
77 case syntax::NodeKind::UnknownExpression:
79 case syntax::NodeKind::ParenExpression:
81 case syntax::NodeKind::ThisExpression:
83 case syntax::NodeKind::IntegerLiteralExpression:
84 return new (A.
getAllocator()) syntax::IntegerLiteralExpression;
85 case syntax::NodeKind::CharacterLiteralExpression:
86 return new (A.
getAllocator()) syntax::CharacterLiteralExpression;
87 case syntax::NodeKind::FloatingLiteralExpression:
88 return new (A.
getAllocator()) syntax::FloatingLiteralExpression;
89 case syntax::NodeKind::StringLiteralExpression:
90 return new (A.
getAllocator()) syntax::StringLiteralExpression;
91 case syntax::NodeKind::BoolLiteralExpression:
92 return new (A.
getAllocator()) syntax::BoolLiteralExpression;
93 case syntax::NodeKind::CxxNullPtrExpression:
94 return new (A.
getAllocator()) syntax::CxxNullPtrExpression;
95 case syntax::NodeKind::IntegerUserDefinedLiteralExpression:
96 return new (A.
getAllocator()) syntax::IntegerUserDefinedLiteralExpression;
97 case syntax::NodeKind::FloatUserDefinedLiteralExpression:
98 return new (A.
getAllocator()) syntax::FloatUserDefinedLiteralExpression;
99 case syntax::NodeKind::CharUserDefinedLiteralExpression:
100 return new (A.
getAllocator()) syntax::CharUserDefinedLiteralExpression;
101 case syntax::NodeKind::StringUserDefinedLiteralExpression:
102 return new (A.
getAllocator()) syntax::StringUserDefinedLiteralExpression;
103 case syntax::NodeKind::PrefixUnaryOperatorExpression:
105 case syntax::NodeKind::PostfixUnaryOperatorExpression:
107 case syntax::NodeKind::BinaryOperatorExpression:
109 case syntax::NodeKind::UnqualifiedId:
111 case syntax::NodeKind::IdExpression:
113 case syntax::NodeKind::CallExpression:
115 case syntax::NodeKind::UnknownStatement:
117 case syntax::NodeKind::DeclarationStatement:
119 case syntax::NodeKind::EmptyStatement:
121 case syntax::NodeKind::SwitchStatement:
123 case syntax::NodeKind::CaseStatement:
125 case syntax::NodeKind::DefaultStatement:
127 case syntax::NodeKind::IfStatement:
129 case syntax::NodeKind::ForStatement:
131 case syntax::NodeKind::WhileStatement:
133 case syntax::NodeKind::ContinueStatement:
135 case syntax::NodeKind::BreakStatement:
137 case syntax::NodeKind::ReturnStatement:
139 case syntax::NodeKind::RangeBasedForStatement:
141 case syntax::NodeKind::ExpressionStatement:
143 case syntax::NodeKind::CompoundStatement:
145 case syntax::NodeKind::UnknownDeclaration:
147 case syntax::NodeKind::EmptyDeclaration:
149 case syntax::NodeKind::StaticAssertDeclaration:
151 case syntax::NodeKind::LinkageSpecificationDeclaration:
153 case syntax::NodeKind::SimpleDeclaration:
155 case syntax::NodeKind::TemplateDeclaration:
157 case syntax::NodeKind::ExplicitTemplateInstantiation:
159 case syntax::NodeKind::NamespaceDefinition:
161 case syntax::NodeKind::NamespaceAliasDefinition:
163 case syntax::NodeKind::UsingNamespaceDirective:
165 case syntax::NodeKind::UsingDeclaration:
167 case syntax::NodeKind::TypeAliasDeclaration:
169 case syntax::NodeKind::SimpleDeclarator:
171 case syntax::NodeKind::ParenDeclarator:
173 case syntax::NodeKind::ArraySubscript:
175 case syntax::NodeKind::TrailingReturnType:
177 case syntax::NodeKind::ParametersAndQualifiers:
179 case syntax::NodeKind::MemberPointer:
181 case syntax::NodeKind::GlobalNameSpecifier:
182 return new (A.
getAllocator()) syntax::GlobalNameSpecifier;
183 case syntax::NodeKind::DecltypeNameSpecifier:
184 return new (A.
getAllocator()) syntax::DecltypeNameSpecifier;
185 case syntax::NodeKind::IdentifierNameSpecifier:
186 return new (A.
getAllocator()) syntax::IdentifierNameSpecifier;
187 case syntax::NodeKind::SimpleTemplateNameSpecifier:
188 return new (A.
getAllocator()) syntax::SimpleTemplateNameSpecifier;
189 case syntax::NodeKind::NestedNameSpecifier:
191 case syntax::NodeKind::MemberExpression:
193 case syntax::NodeKind::CallArguments:
195 case syntax::NodeKind::ParameterDeclarationList:
197 case syntax::NodeKind::DeclaratorList:
200 llvm_unreachable(
"unknown node kind");
206 ArrayRef<std::pair<syntax::Node *, syntax::NodeRole>> Children,
208 auto *
T = allocateTree(A, K);
209 FactoryImpl::setCanModify(
T);
210 for (
const auto &Child : Children)
211 FactoryImpl::appendChildLowLevel(
T, Child.first, Child.second);
213 T->assertInvariants();
220 if (
const auto *L = dyn_cast<syntax::Leaf>(N))
224 TBTM.
getText(L->getTokenKey()));
226 const auto *
T = cast<syntax::Tree>(N);
227 std::vector<std::pair<syntax::Node *, syntax::NodeRole>> Children;
228 for (
const auto *Child =
T->getFirstChild(); Child;
229 Child = Child->getNextSibling())
236 return cast<EmptyStatement>(
238 NodeKind::EmptyStatement));
Defines the clang::TokenKind enum and support functions.
A memory arena for syntax trees.
llvm::BumpPtrAllocator & getAllocator()
Array size specified inside a declarator.
Models arguments of a function call.
{ statement1; statement2; … }
A semicolon in the top-level context. Does not declare anything.
The no-op statement, i.e. ';'.
template <declaration> Examples: template struct X<int> template void foo<int>() template int var<dou...
Expression in a statement position, e.g.
Exposes private syntax tree APIs required to implement node synthesis.
static void appendChildLowLevel(syntax::Tree *T, syntax::Node *Child, syntax::NodeRole R)
static void setCanModify(syntax::Node *N)
static std::pair< FileID, ArrayRef< Token > > lexBuffer(TokenBufferTokenManager &TBTM, std::unique_ptr< llvm::MemoryBuffer > Buffer)
static void prependChildLowLevel(syntax::Tree *T, syntax::Node *Child, syntax::NodeRole R)
for (<init>; <cond>; <increment>) <body>
if (cond) <then-statement> else <else-statement> FIXME: add condition that models 'expression or vari...
A leaf node points to a single token.
extern <string-literal> declaration extern <string-literal> { <decls> }
Member pointer inside a declarator E.g.
namespace <name> = <namespace-reference>
namespace <name> { <decls> }
Models a nested-name-specifier.
void assertInvariants() const
Asserts invariants on this node of the tree and its immediate children.
Models a parameter-declaration-list which appears within parameters-and-qualifiers.
Parameter list for a function type and a trailing return type, if the function has one.
Declarator inside parentheses.
for (<decl> : <init>) <body>
Groups multiple declarators (e.g.
A top-level declarator without parentheses.
static_assert(<condition>, <message>) static_assert(<condition>)
template <template-parameters> <declaration>
A TokenBuffer-powered token manager.
const syntax::Token * getToken(Key I) const
llvm::StringRef getText(Key I) const override
uintptr_t Key
A key to identify a specific token.
tok::TokenKind kind() const
Trailing return type after the parameter list, including the arrow token.
A node that has children and represents a syntactic language construct.
Declaration of an unknown kind, e.g. not yet supported in syntax trees.
An expression of an unknown kind, i.e.
A statement of an unknown kind, i.e.
Models an unqualified-id.
using <scope>::<name> using typename <scope>::<name>
NodeRole
A relation between a parent and child node, e.g.
syntax::Node * deepCopyExpandingMacros(syntax::Arena &A, TokenBufferTokenManager &TBTM, const syntax::Node *N)
Creates a completely independent copy of N with its macros expanded.
syntax::EmptyStatement * createEmptyStatement(syntax::Arena &A, TokenBufferTokenManager &TBTM)
syntax::Tree * createTree(syntax::Arena &A, ArrayRef< std::pair< syntax::Node *, syntax::NodeRole > > Children, syntax::NodeKind K)
Creates the concrete syntax node according to the specified NodeKind K.
NodeKind
A kind of a syntax node, used for implementing casts.
syntax::Leaf * createLeaf(syntax::Arena &A, TokenBufferTokenManager &TBTM, tok::TokenKind K, StringRef Spelling)
Create Leaf from token with Spelling and assert it has the desired TokenKind.
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like '!' or '', and returns NULL for literal and...
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T