clang 10.0.0git

Classes | Enumerations | Functions
clang::syntax Namespace Reference

## Classes
class | Arena
| A memory arena for syntax trees. More...
class | BreakStatement
| break; More...
class | CaseStatement
| case : <body> More...
class | CompoundStatement
| { statement1; statement2; … } More...
class | ContinueStatement
| continue; More...
class | Declaration
| A declaration that can appear at the top-level. More...
class | DeclarationStatement
| E.g. 'int a, b = 10;'. More...
class | DefaultStatement
| default: <body> More...
class | EmptyDeclaration
| A semicolon in the top-level context. Does not declare anything. More...
class | EmptyStatement
| The no-op statement, i.e. ';'. More...
class | Expression
| A base class for all expressions. More...
class | ExpressionStatement
| Expression in a statement position, e.g. More...
class | FactoryImpl
| Exposes private syntax tree APIs required to implement node synthesis. More...
struct | FileRange
| A half-open character range inside a particular file, the start offset is included and the end offset is excluded from the range. More...
class | ForStatement
| for (<init>; <cond>; <increment>) <body> More...
class | IfStatement
| if (cond) <then-statement> else <else-statement> FIXME: add condition that models 'expression or variable declaration' More...
class | Leaf
| A leaf node points to a single token inside the expanded token stream. More...
class | LinkageSpecificationDeclaration
| extern <string-literal> declaration extern <string-literal> { <decls> } More...
class | MutationsImpl
class | NamespaceAliasDefinition
| namespace <name> = <namespace-reference> More...
class | NamespaceDefinition
| namespace <name> { <decls> } More...
class | Node
| A node in a syntax tree. More...
class | RangeBasedForStatement
| for (<decl> : <init>) <body> More...
class | ReturnStatement
| return <expr>; return; More...
class | SimpleDeclaration
| Groups multiple declarators (e.g. More...
class | Statement
| An abstract node for C++ statements, e.g. More...
class | StaticAssertDeclaration
| static_assert(<condition>, <message>) static_assert(<condition>) More...
class | SwitchStatement
| switch (<cond>) <body> More...
class | Token
| A token coming directly from a file or from a macro invocation. More...
class | TokenBuffer
| A list of tokens obtained by preprocessing a text buffer and operations to map between the expanded and spelled tokens, i.e. More...
class | TokenCollector
| Collects tokens for the main file while running the frontend action. More...
class | TranslationUnit
| A root node for a translation unit. Parent is always null. More...
class | Tree
| A node that has children and represents a syntactic language construct. More...
class | TreeBuilder
| A helper class for constructing the syntax tree while traversing a clang AST. More...
class | TypeAliasDeclaration
| using <name> = <type> More...
class | UnknownDeclaration
| Declaration of an unknown kind, e.g. not yet supported in syntax trees. More...
class | UnknownExpression
| An expression of an unknown kind, i.e. More...
class | UnknownStatement
| A statement of an unknown kind, i.e. More...
class | UsingDeclaration
| using <scope>::<name> using typename <scope>::<name> More...
class | UsingNamespaceDirective
| using namespace <name> More...
class | WhileStatement
| while (<cond>) <body> More...

## Enumerations
enum | NodeKind : uint16_t { NodeKind::Leaf, NodeKind::TranslationUnit, NodeKind::UnknownExpression, NodeKind::UnknownStatement, NodeKind::DeclarationStatement, NodeKind::EmptyStatement, NodeKind::SwitchStatement, NodeKind::CaseStatement, NodeKind::DefaultStatement, NodeKind::IfStatement, NodeKind::ForStatement, NodeKind::WhileStatement, NodeKind::ContinueStatement, NodeKind::BreakStatement, NodeKind::ReturnStatement, NodeKind::RangeBasedForStatement, NodeKind::ExpressionStatement, NodeKind::CompoundStatement, NodeKind::UnknownDeclaration, NodeKind::EmptyDeclaration, NodeKind::StaticAssertDeclaration, NodeKind::LinkageSpecificationDeclaration, NodeKind::SimpleDeclaration, NodeKind::NamespaceDefinition, NodeKind::NamespaceAliasDefinition, NodeKind::UsingNamespaceDirective, NodeKind::UsingDeclaration, NodeKind::TypeAliasDeclaration }
| A kind of a syntax node, used for implementing casts. More...
enum | NodeRole : uint8_t { NodeRole::Detached, NodeRole::Unknown, NodeRole::OpenParen, NodeRole::CloseParen, NodeRole::IntroducerKeyword, NodeRole::BodyStatement, NodeRole::CaseStatement_value, NodeRole::IfStatement_thenStatement, NodeRole::IfStatement_elseKeyword, NodeRole::IfStatement_elseStatement, NodeRole::ReturnStatement_value, NodeRole::ExpressionStatement_expression, NodeRole::CompoundStatement_statement, NodeRole::StaticAssertDeclaration_condition, NodeRole::StaticAssertDeclaration_message }
| A relation between a parent and child node, e.g. More...

## Functions
syntax::TranslationUnit * | buildSyntaxTree (Arena &A, const clang::TranslationUnitDecl &TU)
| Build a syntax tree for the main file. More...
clang::syntax::Leaf * | createPunctuation (clang::syntax::Arena &A, clang::tok::TokenKind K)
clang::syntax::EmptyStatement * | createEmptyStatement (clang::syntax::Arena &A)
tooling::Replacements | computeReplacements (const Arena &A, const syntax::TranslationUnit &TU)
| Computes textual replacements required to mimic the tree modifications made to the syntax tree. More...
void | removeStatement (syntax::Arena &A, syntax::Statement *S)
| Removes a statement or replaces it with an empty statement where one is required syntactically. More...
llvm::raw_ostream & | operator<< (llvm::raw_ostream &OS, NodeKind K)
| For debugging purposes. More...
llvm::raw_ostream & | operator<< (llvm::raw_ostream &OS, NodeRole R)
| For debugging purposes. More...
llvm::raw_ostream & | operator<< (llvm::raw_ostream &OS, const FileRange &R)
| For debugging purposes. More...
llvm::raw_ostream & | operator<< (llvm::raw_ostream &OS, const Token &T)
| For debugging purposes. Equivalent to a call to Token::str(). More...
llvm::ArrayRef< syntax::Token > | spelledTokensTouching (SourceLocation Loc, const syntax::TokenBuffer &Tokens)
| The spelled tokens that overlap or touch a spelling location Loc. More...
const syntax::Token * | spelledIdentifierTouching (SourceLocation Loc, const syntax::TokenBuffer &Tokens)
| The identifier token that overlaps or touches a spelling location Loc. More...
std::vector< syntax::Token > | tokenize (FileID FID, const SourceManager &SM, const LangOptions &LO)
| Lex the text buffer, corresponding to `FID`, in raw mode and record the resulting spelled tokens. More...

## Enumeration Type Documentation

## ◆ NodeKind

enum clang::syntax::NodeKind : uint16_t
| strong

A kind of a syntax node, used for implementing casts.

The ordering and blocks of enumerator constants must correspond to the inheritance hierarchy of syntax::Node.

Enumerator
Leaf |
TranslationUnit |
UnknownExpression |
UnknownStatement |
DeclarationStatement |
EmptyStatement |
SwitchStatement |
CaseStatement |
DefaultStatement |
IfStatement |
ForStatement |
WhileStatement |
ContinueStatement |
BreakStatement |
ReturnStatement |
RangeBasedForStatement |
ExpressionStatement |
CompoundStatement |
UnknownDeclaration |
EmptyDeclaration |
StaticAssertDeclaration |
LinkageSpecificationDeclaration |
SimpleDeclaration |
NamespaceDefinition |
NamespaceAliasDefinition |
UsingNamespaceDirective |
UsingDeclaration |
TypeAliasDeclaration |

Definition at line 37 of file Nodes.h.

## ◆ NodeRole

enum clang::syntax::NodeRole : uint8_t
| strong

A relation between a parent and child node, e.g.

'left-hand-side of a binary expression'. Used for implementing accessors.

Enumerator
Detached | A node without a parent.
Unknown | Children of an unknown semantic nature, e.g. skipped tokens, comments.
OpenParen | An opening parenthesis in argument lists and blocks, e.g. '{', '(', etc.
CloseParen | A closing parenthesis in argument lists and blocks, e.g. '}', ')', etc.
IntroducerKeyword | A keywords that introduces some grammar construct, e.g. 'if', 'try', etc.
BodyStatement | An inner statement for those that have only a single child of kind statement, e.g. loop body for while, for, etc; inner statement for case, default, etc.
CaseStatement_value |
IfStatement_thenStatement |
IfStatement_elseKeyword |
IfStatement_elseStatement |
ReturnStatement_value |
ExpressionStatement_expression |
CompoundStatement_statement |
StaticAssertDeclaration_condition |
StaticAssertDeclaration_message |

Definition at line 78 of file Nodes.h.

## Function Documentation

## ◆ buildSyntaxTree()

syntax::TranslationUnit * clang::syntax::buildSyntaxTree | ( | Arena & | A,
|  | const clang::TranslationUnitDecl & | TU
| ) |  |

Build a syntax tree for the main file.

Definition at line 662 of file BuildTree.cpp.

## ◆ computeReplacements()

tooling::Replacements clang::syntax::computeReplacements | ( | const Arena & | A,
|  | const syntax::TranslationUnit & | TU
| ) |  |

Computes textual replacements required to mimic the tree modifications made to the syntax tree.

Definition at line 85 of file ComputeReplacements.cpp.

References clang::tooling::Replacements::add(), emitReplacement(), SM, clang::syntax::Arena::sourceManager(), and clang::syntax::Arena::tokenBuffer().

## ◆ createEmptyStatement()

clang::syntax::EmptyStatement * clang::syntax::createEmptyStatement | ( | clang::syntax::Arena & | A | ) |

Definition at line 38 of file Synthesis.cpp.

## ◆ createPunctuation()

clang::syntax::Leaf * clang::syntax::createPunctuation | ( | clang::syntax::Arena & | A,
|  | clang::tok::TokenKind | K
| ) |  |

Definition at line 24 of file Synthesis.cpp.

## ◆ operator<<() [1/4]

llvm::raw_ostream & clang::syntax::operator<< | ( | llvm::raw_ostream & | OS,
|  | NodeKind | K
| ) |  |

For debugging purposes.

Definition at line 13 of file Nodes.cpp.

Referenced by clang::syntax::Token::length().

## ◆ operator<<() [2/4]

llvm::raw_ostream & clang::syntax::operator<< | ( | llvm::raw_ostream & | OS,
|  | const FileRange & | R
| ) |  |

For debugging purposes.

Definition at line 105 of file Tokens.cpp.

References clang::syntax::FileRange::beginOffset(), clang::syntax::FileRange::endOffset(), clang::syntax::FileRange::file(), and clang::FileID::getHashValue().

## ◆ operator<<() [3/4]

llvm::raw_ostream & clang::syntax::operator<< | ( | llvm::raw_ostream & | OS,
|  | NodeRole | R
| ) |  |

For debugging purposes.

Definition at line 75 of file Nodes.cpp.

References BodyStatement, CaseStatement_value, CloseParen, CompoundStatement_statement, Detached, ExpressionStatement_expression, IfStatement_elseKeyword, IfStatement_elseStatement, IfStatement_thenStatement, IntroducerKeyword, OpenParen, ReturnStatement_value, StaticAssertDeclaration_condition, StaticAssertDeclaration_message, and Unknown.

## ◆ operator<<() [4/4]

llvm::raw_ostream & clang::syntax::operator<< | ( | llvm::raw_ostream & | OS,
|  | const Token & | T
| ) |  |

For debugging purposes. Equivalent to a call to Token::str().

Definition at line 74 of file Tokens.cpp.

References clang::syntax::Token::str().

## ◆ removeStatement()

void clang::syntax::removeStatement | ( | syntax::Arena & | A,
|  | syntax::Statement * | S
| ) |  |

Removes a statement or replaces it with an empty statement where one is required syntactically.

E.g., in the following example: if (cond) { foo(); } else bar(); One can remove `foo();` completely and to remove `bar();` we would need to replace it with an empty statement. EXPECTS: S->canModify() == true

Definition at line 84 of file Mutations.cpp.

## ◆ spelledIdentifierTouching()

const syntax::Token * clang::syntax::spelledIdentifierTouching | ( | SourceLocation | Loc,
|  | const syntax::TokenBuffer & | Tokens
| ) |  |

The identifier token that overlaps or touches a spelling location Loc.

If there is none, returns nullptr.

Definition at line 272 of file Tokens.cpp.

## ◆ spelledTokensTouching()

llvm::ArrayRef< syntax::Token > clang::syntax::spelledTokensTouching | ( | SourceLocation | Loc,
|  | const syntax::TokenBuffer & | Tokens
| ) |  |

The spelled tokens that overlap or touch a spelling location Loc.

This always returns 0-2 tokens.

Definition at line 258 of file Tokens.cpp.

## ◆ tokenize()

std::vector< syntax::Token > clang::syntax::tokenize | ( | FileID | FID,
|  | const SourceManager & | SM,
|  | const LangOptions & | LO
| ) |  |

Lex the text buffer, corresponding to `FID`, in raw mode and record the resulting spelled tokens.

Does minimal post-processing on raw identifiers, setting the appropriate token kind (instead of the raw_identifier reported by lexer in raw mode). This is a very low-level function, most users should prefer to use TokenCollector. Lexing in raw mode produces wildly different results from what one might expect when running a C++ frontend, e.g. preprocessor does not run at all. The result will not have a 'eof' token at the end.

Definition at line 296 of file Tokens.cpp.

Referenced by TokenCollector::Builder::build(), and clang::syntax::Arena::lexBuffer().