2021-06-10 16:07:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SKSL_DSL_SYMBOLS
|
|
|
|
#define SKSL_DSL_SYMBOLS
|
|
|
|
|
|
|
|
#include "include/sksl/DSLExpression.h"
|
2022-03-18 20:40:58 +00:00
|
|
|
#include "include/sksl/SkSLPosition.h"
|
2021-06-10 16:07:34 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2022-02-01 20:31:57 +00:00
|
|
|
#include <string_view>
|
2021-06-10 16:07:34 +00:00
|
|
|
|
|
|
|
namespace SkSL {
|
|
|
|
|
|
|
|
class SymbolTable;
|
|
|
|
|
|
|
|
namespace dsl {
|
|
|
|
|
2022-03-18 20:40:58 +00:00
|
|
|
class DSLVarBase;
|
2021-06-10 16:07:34 +00:00
|
|
|
|
|
|
|
// This header provides methods for manually managing symbol tables in DSL code. They should not be
|
|
|
|
// used by normal hand-written DSL code, where we rely on C++ to manage symbols, but are instead
|
|
|
|
// needed when DSL objects are being constructed programmatically (as in DSLParser).
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pushes a new symbol table onto the symbol table stack.
|
|
|
|
*/
|
|
|
|
void PushSymbolTable();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pops the top symbol table from the stack. As symbol tables are shared pointers, this will only
|
|
|
|
* destroy the symbol table if it was never attached to anything (e.g. passed into a Block
|
|
|
|
* constructor).
|
|
|
|
*/
|
|
|
|
void PopSymbolTable();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current symbol table. Outside of SkSL itself, this is an opaque pointer, used only
|
|
|
|
* for passing it to DSL methods that require it.
|
|
|
|
*/
|
|
|
|
std::shared_ptr<SymbolTable> CurrentSymbolTable();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an expression referring to the named symbol.
|
|
|
|
*/
|
2022-03-09 15:22:44 +00:00
|
|
|
DSLPossibleExpression Symbol(std::string_view name, Position pos = Position::Capture());
|
2021-06-10 16:07:34 +00:00
|
|
|
|
|
|
|
/**
|
2021-10-12 20:53:52 +00:00
|
|
|
* Returns true if the name refers to a type (user or built-in) in the current symbol table.
|
2021-06-10 16:07:34 +00:00
|
|
|
*/
|
2022-02-01 20:31:57 +00:00
|
|
|
bool IsType(std::string_view name);
|
2021-06-10 16:07:34 +00:00
|
|
|
|
2021-10-12 20:53:52 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the name refers to a builtin type.
|
|
|
|
*/
|
2022-02-01 20:31:57 +00:00
|
|
|
bool IsBuiltinType(std::string_view name);
|
2021-10-12 20:53:52 +00:00
|
|
|
|
2021-06-10 16:07:34 +00:00
|
|
|
/**
|
|
|
|
* Adds a variable to the current symbol table.
|
|
|
|
*/
|
2022-03-09 15:22:44 +00:00
|
|
|
void AddToSymbolTable(DSLVarBase& var, Position pos = Position::Capture());
|
2021-06-10 16:07:34 +00:00
|
|
|
|
|
|
|
} // namespace dsl
|
|
|
|
|
|
|
|
} // namespace SkSL
|
|
|
|
|
|
|
|
#endif
|