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