• 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 #ifndef SKSL_DSL_STATEMENT
9 #define SKSL_DSL_STATEMENT
10 
11 #include "include/core/SkString.h"
12 #include "include/core/SkTypes.h"
13 #include "include/private/SkSLStatement.h"
14 #include "include/sksl/SkSLErrorReporter.h"
15 
16 #include <memory>
17 
18 class GrGLSLShaderBuilder;
19 
20 namespace SkSL {
21 
22 class Expression;
23 class Statement;
24 
25 namespace dsl {
26 
27 class DSLBlock;
28 class DSLExpression;
29 class DSLPossibleExpression;
30 class DSLPossibleStatement;
31 class DSLVar;
32 
33 class DSLStatement {
34 public:
35     DSLStatement();
36 
37     DSLStatement(DSLExpression expr);
38 
39     DSLStatement(DSLPossibleExpression expr, PositionInfo pos = PositionInfo::Capture());
40 
41     DSLStatement(DSLPossibleStatement stmt, PositionInfo pos = PositionInfo::Capture());
42 
43     DSLStatement(DSLBlock block);
44 
45     DSLStatement(DSLStatement&&) = default;
46 
47     DSLStatement(std::unique_ptr<SkSL::Statement> stmt);
48 
49     DSLStatement(std::unique_ptr<SkSL::Expression> expr);
50 
51     ~DSLStatement();
52 
53     DSLStatement& operator=(DSLStatement&& other) = default;
54 
hasValue()55     bool hasValue() { return fStatement != nullptr; }
56 
release()57     std::unique_ptr<SkSL::Statement> release() {
58         SkASSERT(this->hasValue());
59         return std::move(fStatement);
60     }
61 
62 private:
releaseIfPossible()63     std::unique_ptr<SkSL::Statement> releaseIfPossible() {
64         return std::move(fStatement);
65     }
66 
67     std::unique_ptr<SkSL::Statement> fStatement;
68 
69     friend class DSLBlock;
70     friend class DSLCore;
71     friend class DSLExpression;
72     friend class DSLPossibleStatement;
73     friend class DSLWriter;
74     friend DSLStatement operator,(DSLStatement left, DSLStatement right);
75 };
76 
77 /**
78  * Represents a Statement which may have failed and/or have pending errors to report. Converting a
79  * PossibleStatement into a Statement requires PositionInfo so that any pending errors can be
80  * reported at the correct position.
81  *
82  * PossibleStatement is used instead of Statement in situations where it is not possible to capture
83  * the PositionInfo at the time of Statement construction.
84  */
85 class DSLPossibleStatement {
86 public:
87     DSLPossibleStatement(std::unique_ptr<SkSL::Statement> stmt);
88 
89     DSLPossibleStatement(DSLPossibleStatement&& other) = default;
90 
91     ~DSLPossibleStatement();
92 
hasValue()93     bool hasValue() { return fStatement != nullptr; }
94 
release()95     std::unique_ptr<SkSL::Statement> release() {
96         return DSLStatement(std::move(*this)).release();
97     }
98 
99 private:
100     std::unique_ptr<SkSL::Statement> fStatement;
101 
102     friend class DSLStatement;
103 };
104 
105 DSLStatement operator,(DSLStatement left, DSLStatement right);
106 
107 } // namespace dsl
108 
109 } // namespace SkSL
110 
111 #endif
112