clang-tools 20.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
clang::clangd::DirectiveTree Struct Reference

Describes the structure of a source file, as seen by the preprocessor. More...

#include <DirectiveTree.h>

Classes

struct  Code
 A range of code (and possibly comments) containing no directives. More...
 
struct  Conditional
 A preprocessor conditional section. More...
 
struct  Directive
 A preprocessor directive. More...
 

Public Types

using Chunk = std::variant< Code, Directive, Conditional >
 Some piece of the file. {One of Code, Directive, Conditional}.
 

Public Member Functions

TokenStream stripDirectives (const TokenStream &) const
 Produce a parseable token stream by stripping all directive tokens.
 

Static Public Member Functions

static DirectiveTree parse (const TokenStream &)
 Extract preprocessor structure by examining the raw tokens.
 

Public Attributes

std::vector< ChunkChunks
 

Detailed Description

Describes the structure of a source file, as seen by the preprocessor.

The structure is a tree, whose leaves are plain source code and directives, and whose internal nodes are #if...#endif sections.

(root) |-+ Directive #include <stdio.h> |-+ Code int main() { | ` printf("hello, "); |-+ Conditional -+ Directive #ifndef NDEBUG | |-+ Code printf("debug\n"); | |-+ Directive #else | |-+ Code printf("production\n"); | `-+ Directive #endif |-+ Code return 0; ` }

Unlike the clang preprocessor, we model the full tree explicitly. This class does not recognize macro usage, only directives.

Definition at line 59 of file DirectiveTree.h.

Member Typedef Documentation

◆ Chunk

Some piece of the file. {One of Code, Directive, Conditional}.

Definition at line 90 of file DirectiveTree.h.

Member Function Documentation

◆ parse()

DirectiveTree clang::clangd::DirectiveTree::parse ( const TokenStream Code)
static

Extract preprocessor structure by examining the raw tokens.

Definition at line 179 of file DirectiveTree.cpp.

Referenced by clang::clangd::getFoldingRanges().

◆ stripDirectives()

TokenStream clang::clangd::DirectiveTree::stripDirectives ( const TokenStream In) const

Produce a parseable token stream by stripping all directive tokens.

Conditional sections are replaced by the taken branch, if any. This tree must describe the provided token stream.

Definition at line 353 of file DirectiveTree.cpp.

References Out.

Member Data Documentation

◆ Chunks

std::vector<Chunk> clang::clangd::DirectiveTree::Chunks

Definition at line 91 of file DirectiveTree.h.


The documentation for this struct was generated from the following files: