xref: /third_party/skia/include/sksl/DSLSymbols.h (revision cb93a386)
1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2021 Google LLC
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#ifndef SKSL_DSL_SYMBOLS
9cb93a386Sopenharmony_ci#define SKSL_DSL_SYMBOLS
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include "include/core/SkStringView.h"
12cb93a386Sopenharmony_ci#include "include/private/SkSLString.h"
13cb93a386Sopenharmony_ci#include "include/sksl/DSLExpression.h"
14cb93a386Sopenharmony_ci
15cb93a386Sopenharmony_ci#include <memory>
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_cinamespace SkSL {
18cb93a386Sopenharmony_ci
19cb93a386Sopenharmony_ciclass SymbolTable;
20cb93a386Sopenharmony_ci
21cb93a386Sopenharmony_cinamespace dsl {
22cb93a386Sopenharmony_ci
23cb93a386Sopenharmony_ciclass DSLVar;
24cb93a386Sopenharmony_ci
25cb93a386Sopenharmony_ci// This header provides methods for manually managing symbol tables in DSL code. They should not be
26cb93a386Sopenharmony_ci// used by normal hand-written DSL code, where we rely on C++ to manage symbols, but are instead
27cb93a386Sopenharmony_ci// needed when DSL objects are being constructed programmatically (as in DSLParser).
28cb93a386Sopenharmony_ci
29cb93a386Sopenharmony_ci/**
30cb93a386Sopenharmony_ci * Pushes a new symbol table onto the symbol table stack.
31cb93a386Sopenharmony_ci */
32cb93a386Sopenharmony_civoid PushSymbolTable();
33cb93a386Sopenharmony_ci
34cb93a386Sopenharmony_ci/**
35cb93a386Sopenharmony_ci * Pops the top symbol table from the stack. As symbol tables are shared pointers, this will only
36cb93a386Sopenharmony_ci * destroy the symbol table if it was never attached to anything (e.g. passed into a Block
37cb93a386Sopenharmony_ci * constructor).
38cb93a386Sopenharmony_ci */
39cb93a386Sopenharmony_civoid PopSymbolTable();
40cb93a386Sopenharmony_ci
41cb93a386Sopenharmony_ci/**
42cb93a386Sopenharmony_ci * Returns the current symbol table. Outside of SkSL itself, this is an opaque pointer, used only
43cb93a386Sopenharmony_ci * for passing it to DSL methods that require it.
44cb93a386Sopenharmony_ci */
45cb93a386Sopenharmony_cistd::shared_ptr<SymbolTable> CurrentSymbolTable();
46cb93a386Sopenharmony_ci
47cb93a386Sopenharmony_ci/**
48cb93a386Sopenharmony_ci * Returns an expression referring to the named symbol.
49cb93a386Sopenharmony_ci */
50cb93a386Sopenharmony_ciDSLPossibleExpression Symbol(skstd::string_view name, PositionInfo pos = PositionInfo::Capture());
51cb93a386Sopenharmony_ci
52cb93a386Sopenharmony_ci/**
53cb93a386Sopenharmony_ci * Returns true if the name refers to a type (user or built-in) in the current symbol table.
54cb93a386Sopenharmony_ci */
55cb93a386Sopenharmony_cibool IsType(skstd::string_view name);
56cb93a386Sopenharmony_ci
57cb93a386Sopenharmony_ci/**
58cb93a386Sopenharmony_ci * Returns true if the name refers to a builtin type.
59cb93a386Sopenharmony_ci */
60cb93a386Sopenharmony_cibool IsBuiltinType(skstd::string_view name);
61cb93a386Sopenharmony_ci
62cb93a386Sopenharmony_ci/**
63cb93a386Sopenharmony_ci * Adds a variable to the current symbol table.
64cb93a386Sopenharmony_ci */
65cb93a386Sopenharmony_civoid AddToSymbolTable(DSLVarBase& var, PositionInfo pos = PositionInfo::Capture());
66cb93a386Sopenharmony_ci
67cb93a386Sopenharmony_ci} // namespace dsl
68cb93a386Sopenharmony_ci
69cb93a386Sopenharmony_ci} // namespace SkSL
70cb93a386Sopenharmony_ci
71cb93a386Sopenharmony_ci#endif
72