Blender V5.3
blender::gpu::shader::parser::Scope Struct Reference

#include <scope.hh>

Public Member Functions

 Scope ()=delete
 Scope (const ParserBase &parser, int64_t index)
 Scope (const ParserBase &parser)
bool is_valid () const
bool is_invalid () const
Token operator[] (int i)
Token front () const
Token back () const
IndexRange range () const
Token operator[] (const int64_t index) const
size_t token_count () const
ScopeType type () const
void set_type (ScopeType type)
Scope scope () const
Scope parent () const
Scope prev_neighbor () const
Scope next_neighbor () const
Scope child_first () const
Scope prev () const
Scope next () const
bool contains (const Scope sub) const
bool contains (const std::string &str) const
std::string_view str_with_whitespace () const
std::string_view str () const
std::string_view str_exclusive () const
Token find_token (const char token_type) const
bool contains_token (const char token_type) const
Scope first_scope_of_type (const ScopeType type) const
template<bool include_preprocessor = false, typename CallbackFn>
void foreach_match (const std::string &pattern, CallbackFn callback) const
template<typename CallbackFn>
void foreach_scope (ScopeType type, CallbackFn callback) const
template<typename CallbackFn>
void foreach_attribute (CallbackFn callback) const
template<typename Callback>
void foreach_token (const TokenType token_type, Callback callback) const
template<typename Callback>
void foreach_function (Callback callback) const
template<typename Callback>
void foreach_struct (Callback callback) const
template<typename Callback>
void foreach_declaration (Callback callback) const
bool operator== (const Scope &other) const
bool operator!= (const Scope &other) const

Public Attributes

friend ScopeParser

Detailed Description

Definition at line 21 of file scope.hh.

Constructor & Destructor Documentation

◆ Scope() [1/3]

◆ Scope() [2/3]

blender::gpu::shader::parser::Scope::Scope ( const ParserBase & parser,
int64_t index )
inline

Definition at line 38 of file scope.hh.

◆ Scope() [3/3]

blender::gpu::shader::parser::Scope::Scope ( const ParserBase & parser)
inline

Definition at line 52 of file scope.hh.

References Scope().

Member Function Documentation

◆ back()

◆ child_first()

Scope blender::gpu::shader::parser::Scope::child_first ( ) const
inline

Definition at line 149 of file scope.hh.

References is_invalid(), and Scope().

◆ contains() [1/2]

bool blender::gpu::shader::parser::Scope::contains ( const Scope sub) const
inline

Definition at line 171 of file scope.hh.

References blender::gpu::shader::parser::Global, parent(), Scope(), scope(), and type().

◆ contains() [2/2]

bool blender::gpu::shader::parser::Scope::contains ( const std::string & str) const
inline

Definition at line 181 of file scope.hh.

References str().

◆ contains_token()

bool blender::gpu::shader::parser::Scope::contains_token ( const char token_type) const
inline

Definition at line 221 of file scope.hh.

References find_token(), and lexit::Token::is_valid().

◆ find_token()

Token blender::gpu::shader::parser::Scope::find_token ( const char token_type) const
inline

Definition at line 212 of file scope.hh.

References is_invalid(), range(), and lexit::Token::Token().

Referenced by contains_token().

◆ first_scope_of_type()

Scope blender::gpu::shader::parser::Scope::first_scope_of_type ( const ScopeType type) const
inline

Definition at line 228 of file scope.hh.

References blender::gpu::shader::parser::Global, Scope(), scope(), and type().

◆ foreach_attribute()

template<typename CallbackFn>
void blender::gpu::shader::parser::Scope::foreach_attribute ( CallbackFn callback) const
inline

Will iterate over all the attribute if this scope is an ScopeType::Attributes. Callback should have this signature void(Token attribute_name, Scope attribute_parameters).

Definition at line 367 of file scope.hh.

References blender::gpu::shader::metadata::assert, blender::gpu::shader::parser::Attribute, blender::gpu::shader::parser::Attributes, foreach_scope(), Scope(), scope(), and type().

◆ foreach_declaration()

template<typename Callback>
void blender::gpu::shader::parser::Scope::foreach_declaration ( Callback callback) const
inline

Run a callback for all the variable declarations (without assignment) that are direct children Callback should have this signature void(Scope attributes, Token const_tok, Token type, Scope template_scope, Token name, Scope array, Token decl_end).

Definition at line 467 of file scope.hh.

References blender::gpu::shader::parser::Attributes, foreach_match(), lexit::Token::is_valid(), lexit::Token::prev(), Scope(), scope(), and type().

◆ foreach_function()

template<typename Callback>
void blender::gpu::shader::parser::Scope::foreach_function ( Callback callback) const
inline

Run a callback for all the function scopes that are direct children of this scope. Callback should have this signature void(bool is_static, Token type, Token name, Scope args, bool is_const, Scope body).

Definition at line 399 of file scope.hh.

References lexit::Const, foreach_match(), scope(), and lexit::Static.

◆ foreach_match()

template<bool include_preprocessor = false, typename CallbackFn>
void blender::gpu::shader::parser::Scope::foreach_match ( const std::string & pattern,
CallbackFn callback ) const
inline

Small pattern matching engine.

  • pattern is expected to a be a sequence of TokenType stored as a string.
  • single '?' after a token will make this token optional.
  • double '?' will match the question mark.
  • double '.' will skip to the end of the current matched scope.
  • callback is called for each matches with a vector of token the size of the input pattern.
  • control tokens ('..' and '?') and unmatched optional tokens will be set to invalid in match vector. IMPORTANT: 2 matches cannot overlap. The pattern matching algorithm skips the whole match after a match there is no readback. This could eventually be fixed.

If include_preprocessor is true, try to match any token. Otherwise ignore tokens in preprocessor scopes.

Callback should have this signature void(const std::vector<Token>).

Definition at line 255 of file scope.hh.

References blender::gpu::shader::metadata::assert, is_invalid(), blender::gpu::shader::parser::Preprocessor, range(), scope(), blender::gpu::shader::parser::IndexRange::start, lexit::Token::Token(), and type().

Referenced by foreach_declaration(), foreach_function(), foreach_struct(), blender::gpu::shader::lower_namespace(), and blender::gpu::shader::parse_template_definition_args().

◆ foreach_scope()

template<typename CallbackFn>
void blender::gpu::shader::parser::Scope::foreach_scope ( ScopeType type,
CallbackFn callback ) const
inline

Will iterate over all the scopes that are direct children. Callback should have this signature void(Scope).

Definition at line 339 of file scope.hh.

References blender::gpu::shader::metadata::assert, front(), blender::gpu::shader::parser::Global, lexit::Token::index_, is_invalid(), Scope(), scope(), and type().

Referenced by foreach_attribute(), blender::gpu::shader::lower_namespace(), and blender::gpu::shader::SourceProcessor::template_arguments_mangle().

◆ foreach_struct()

template<typename Callback>
void blender::gpu::shader::parser::Scope::foreach_struct ( Callback callback) const
inline

Run a callback for all the struct scopes that are direct children of this scope. Callback should have this signature void(Token struct_tok, Scope attributes, Token name, Scope body).

Definition at line 440 of file scope.hh.

References foreach_match(), Scope(), and scope().

◆ foreach_token()

template<typename Callback>
void blender::gpu::shader::parser::Scope::foreach_token ( const TokenType token_type,
Callback callback ) const
inline

Will iterate over all tokens of the scope (and its contained scopes). Callback should have this signature void(Token).

Definition at line 380 of file scope.hh.

References blender::gpu::shader::parser::IndexRange::size, blender::gpu::shader::parser::IndexRange::start, and lexit::Token::Token().

Referenced by blender::gpu::shader::lower_namespace().

◆ front()

◆ is_invalid()

bool blender::gpu::shader::parser::Scope::is_invalid ( ) const
inline

◆ is_valid()

bool blender::gpu::shader::parser::Scope::is_valid ( ) const
inline

Definition at line 54 of file scope.hh.

Referenced by blender::gpu::shader::lower_namespace().

◆ next()

Scope blender::gpu::shader::parser::Scope::next ( ) const
inline

Definition at line 166 of file scope.hh.

References back(), is_invalid(), lexit::Token::next(), and Scope().

Referenced by str_exclusive().

◆ next_neighbor()

Scope blender::gpu::shader::parser::Scope::next_neighbor ( ) const
inline

Definition at line 141 of file scope.hh.

References is_invalid(), and Scope().

◆ operator!=()

bool blender::gpu::shader::parser::Scope::operator!= ( const Scope & other) const
inline

Definition at line 536 of file scope.hh.

References Scope().

◆ operator==()

bool blender::gpu::shader::parser::Scope::operator== ( const Scope & other) const
inline

Definition at line 532 of file scope.hh.

References Scope().

◆ operator[]() [1/2]

Token blender::gpu::shader::parser::Scope::operator[] ( const int64_t index) const
inline

Definition at line 85 of file scope.hh.

References range(), and lexit::Token::Token().

◆ operator[]() [2/2]

Token blender::gpu::shader::parser::Scope::operator[] ( int i)
inline

Definition at line 63 of file scope.hh.

References is_invalid(), range(), and lexit::Token::Token().

◆ parent()

Scope blender::gpu::shader::parser::Scope::parent ( ) const
inline

Definition at line 125 of file scope.hh.

References is_invalid(), and Scope().

Referenced by contains().

◆ prev()

Scope blender::gpu::shader::parser::Scope::prev ( ) const
inline

Definition at line 159 of file scope.hh.

References front(), is_invalid(), lexit::Token::prev(), and Scope().

Referenced by scope(), and str_exclusive().

◆ prev_neighbor()

Scope blender::gpu::shader::parser::Scope::prev_neighbor ( ) const
inline

Definition at line 133 of file scope.hh.

References is_invalid(), and Scope().

◆ range()

IndexRange blender::gpu::shader::parser::Scope::range ( ) const
inline

◆ scope()

◆ set_type()

void blender::gpu::shader::parser::Scope::set_type ( ScopeType type)
inline

Definition at line 102 of file scope.hh.

References type().

◆ str()

std::string_view blender::gpu::shader::parser::Scope::str ( ) const
inline

◆ str_exclusive()

std::string_view blender::gpu::shader::parser::Scope::str_exclusive ( ) const
inline

Definition at line 203 of file scope.hh.

References back(), front(), is_invalid(), next(), prev(), and token_count().

◆ str_with_whitespace()

std::string_view blender::gpu::shader::parser::Scope::str_with_whitespace ( ) const
inline

Definition at line 186 of file scope.hh.

References back(), front(), and is_invalid().

◆ token_count()

size_t blender::gpu::shader::parser::Scope::token_count ( ) const
inline

Definition at line 90 of file scope.hh.

References is_invalid(), range(), and blender::gpu::shader::parser::IndexRange::size.

Referenced by str_exclusive().

◆ type()

ScopeType blender::gpu::shader::parser::Scope::type ( ) const
inline

Member Data Documentation

◆ ScopeParser

friend blender::gpu::shader::parser::Scope::ScopeParser

Definition at line 22 of file scope.hh.


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