Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLSymbol.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 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
9
19
20#include <utility>
21
22namespace SkSL {
23
24std::unique_ptr<Expression> Symbol::instantiate(const Context& context, Position pos) const {
25 switch (this->kind()) {
26 case Symbol::Kind::kFunctionDeclaration:
27 return std::make_unique<FunctionReference>(
28 context, pos, &this->as<FunctionDeclaration>());
29
30 case Symbol::Kind::kVariable: {
31 const Variable* var = &this->as<Variable>();
32 // default to kRead_RefKind; this will be corrected later if the variable is written to
33 return VariableReference::Make(pos, var, VariableReference::RefKind::kRead);
34 }
35 case Symbol::Kind::kField: {
36 const FieldSymbol* field = &this->as<FieldSymbol>();
38 pos, &field->owner(), VariableReference::RefKind::kRead);
39 return FieldAccess::Make(context,
40 pos,
41 std::move(base),
42 field->fieldIndex(),
43 FieldAccess::OwnerKind::kAnonymousInterfaceBlock);
44 }
45 case Symbol::Kind::kType:
46 return TypeReference::Convert(context, pos, &this->as<Type>());
47
48 default:
49 SkDEBUGFAILF("unsupported symbol type %d\n", fKind);
50 return nullptr;
51 }
52}
53
54} // namespace SkSL
SkPoint pos
#define SkDEBUGFAILF(fmt,...)
Definition SkAssert.h:119
static std::unique_ptr< Expression > Make(const Context &context, Position pos, std::unique_ptr< Expression > base, int fieldIndex, OwnerKind ownerKind=OwnerKind::kDefault)
const Variable & owner() const
int fieldIndex() const
Kind kind() const
Definition SkSLSymbol.h:47
std::unique_ptr< Expression > instantiate(const Context &context, Position pos) const
static std::unique_ptr< TypeReference > Convert(const Context &context, Position pos, const Type *type)
static std::unique_ptr< Expression > Make(Position pos, const Variable *variable, RefKind refKind=RefKind::kRead)