1/*
2 * Copyright 2016 Google Inc.
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_SETTING
9#define SKSL_SETTING
10
11#include "src/sksl/SkSLContext.h"
12#include "src/sksl/ir/SkSLExpression.h"
13
14namespace SkSL {
15
16/**
17 * Represents a compile-time constant setting, such as sk_Caps.fbFetchSupport. These are generally
18 * collapsed down to their constant representations during the compilation process.
19 */
20struct Setting : public Expression {
21 Setting(int offset, String name, std::unique_ptr<Expression> value)
22 : INHERITED(offset, kSetting_Kind, value->fType)
23 , fName(std::move(name))
24 , fValue(std::move(value)) {
25 SkASSERT(fValue->isCompileTimeConstant());
26 }
27
28 std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator,
29 const DefinitionMap& definitions) override;
30
31 int nodeCount() const override {
32 return 1;
33 }
34
35 std::unique_ptr<Expression> clone() const override {
36 return std::unique_ptr<Expression>(new Setting(fOffset, fName, fValue->clone()));
37 }
38
39 String description() const override {
40 return fName;
41 }
42
43 bool hasProperty(Property property) const override {
44 return false;
45 }
46
47 bool isCompileTimeConstant() const override {
48 return true;
49 }
50
51 const String fName;
52 std::unique_ptr<Expression> fValue;
53
54 typedef Expression INHERITED;
55};
56
57} // namespace SkSL
58
59#endif
60