|
Blender V5.0
|
#include <algorithm>#include <cassert>#include <chrono>#include <cstdint>#include <functional>#include <iostream>#include <stack>#include <string>#include <vector>Go to the source code of this file.
Namespaces | |
| namespace | blender |
| namespace | blender::gpu |
| namespace | blender::gpu::shader |
| namespace | blender::gpu::shader::parser |
Very simple parsing of our shader file that are a subset of C++. It allows to traverse the semantic using tokens and scopes instead of trying to match string patterns throughout the whole input string.
The goal of this representation is to output code that doesn't modify the style of the input string and keep the same line numbers (to match compilation error with input source).
The Parser class contain a copy of the given string to apply string substitutions (called Mutation). It is usually faster to record all of them and apply them all at once after scanning through the whole semantic representation. In the rare case where mutation need to overlap (recursive processing), it is better to do them in passes until there is no mutation to do.
Token and Scope are read only interfaces to the data stored inside the ParserData. The data is stored as SoA (Structure of Arrays) for fast traversal. The types of token and scopes are defined as readable chars to easily create sequences of token type.
The Parser object needs to be fed a well formed source (without preprocessor directive, see below), otherwise a crash can occur. The Parser doesn't apply any preprocessor. All preprocessor directive are parsed as Preprocessor scope but they are not expanded.
By default, whitespaces are merged with the previous token. Only a handful of processing requires access to whitespaces as individual tokens.
Definition in file shader_parser.hh.