Debian Codegraph @

src/sksl/ir/SkSLEmptyExpression.h

raw
1 /*
2 * Copyright 2023 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 #ifndef SkSLEmptyExpression_DEFINED
8 #define SkSLEmptyExpression_DEFINED
9
10 #include "src/sksl/SkSLBuiltinTypes.h"
11 #include "src/sksl/SkSLCompiler.h"
12 #include "src/sksl/SkSLContext.h"
13 #include "src/sksl/ir/SkSLExpression.h"
14
15 namespace SkSL {
16
17 /**
18 * The EmptyExpression is a void-typed expression with nothing inside. EmptyExpressions can exist
19 * inside an ExpressionStatement; this construct is functionally equivalent to a Nop.
20 */
21 class EmptyExpression : public Expression {
22 public:
23 inline static constexpr Kind kIRNodeKind = Kind::kEmpty;
24
25 static std::unique_ptr<Expression> Make(Position pos, const Context& context) {
26 return std::make_unique<EmptyExpression>(pos, context.fTypes.fVoid.get());
27 }
28
29 EmptyExpression(Position pos, const Type* type)
30 : INHERITED(pos, kIRNodeKind, type) {
31 SkASSERT(type->isVoid());
32 }
33
34 std::unique_ptr<Expression> clone(Position pos) const override {
35 return std::make_unique<EmptyExpression>(pos, &this->type());
36 }
37
38 std::string description(OperatorPrecedence) const override {
39 // There's no way in GLSL to directly emit a void-typed expression.
40 // `false` is used here as a placeholder expression; the value of a void-typed expression is
41 // never meaningful, so this should be a decent substitute.
42 return "false";
43 }
44
45 private:
46 using INHERITED = Expression;
47 };
48
49 } // namespace SkSL
50
51 #endif // SkSLEmptyExpression_DEFINED