• 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 #include "include/sksl/DSLSymbols.h"
9 
10 #include "src/sksl/SkSLCompiler.h"
11 #include "src/sksl/SkSLThreadContext.h"
12 #include "src/sksl/dsl/priv/DSLWriter.h"
13 #include "src/sksl/ir/SkSLVariable.h"
14 
15 namespace SkSL {
16 
17 namespace dsl {
18 
is_type_in_symbol_table(skstd::string_view name,SkSL::SymbolTable * symbols)19 static bool is_type_in_symbol_table(skstd::string_view name, SkSL::SymbolTable* symbols) {
20     const SkSL::Symbol* s = (*symbols)[name];
21     return s && s->is<Type>();
22 }
23 
PushSymbolTable()24 void PushSymbolTable() {
25     SymbolTable::Push(&ThreadContext::SymbolTable());
26 }
27 
PopSymbolTable()28 void PopSymbolTable() {
29     SymbolTable::Pop(&ThreadContext::SymbolTable());
30 }
31 
CurrentSymbolTable()32 std::shared_ptr<SymbolTable> CurrentSymbolTable() {
33     return ThreadContext::SymbolTable();
34 }
35 
Symbol(skstd::string_view name,PositionInfo pos)36 DSLPossibleExpression Symbol(skstd::string_view name, PositionInfo pos) {
37     return ThreadContext::Compiler().convertIdentifier(pos.line(), name);
38 }
39 
IsType(skstd::string_view name)40 bool IsType(skstd::string_view name) {
41     return is_type_in_symbol_table(name, CurrentSymbolTable().get());
42 }
43 
IsBuiltinType(skstd::string_view name)44 bool IsBuiltinType(skstd::string_view name) {
45     return is_type_in_symbol_table(name, CurrentSymbolTable()->builtinParent());
46 }
47 
AddToSymbolTable(DSLVarBase & var,PositionInfo pos)48 void AddToSymbolTable(DSLVarBase& var, PositionInfo pos) {
49     const SkSL::Variable* skslVar = DSLWriter::Var(var);
50     if (skslVar) {
51         CurrentSymbolTable()->addWithoutOwnership(skslVar);
52     }
53     ThreadContext::ReportErrors(pos);
54 }
55 
Retain(String string)56 const String* Retain(String string) {
57     return CurrentSymbolTable()->takeOwnershipOfString(std::move(string));
58 }
59 
60 } // namespace dsl
61 
62 } // namespace SkSL
63