• 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/DSLErrorHandling.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());
40 
41     DSLStatement(DSLPossibleStatement stmt, PositionInfo pos = PositionInfo());
42 
43     DSLStatement(DSLBlock block);
44 
45     DSLStatement(DSLStatement&&) = default;
46 
47     ~DSLStatement();
48 
49     DSLStatement& operator=(DSLStatement&& other) = default;
50 
release()51     std::unique_ptr<SkSL::Statement> release() {
52         return std::move(fStatement);
53     }
54 
55 private:
56     DSLStatement(std::unique_ptr<SkSL::Statement> stmt);
57 
58     DSLStatement(std::unique_ptr<SkSL::Expression> expr);
59 
60     std::unique_ptr<SkSL::Statement> fStatement;
61 
62     friend class DSLBlock;
63     friend class DSLCore;
64     friend class DSLExpression;
65     friend class DSLPossibleStatement;
66     friend class DSLWriter;
67     friend DSLStatement operator,(DSLStatement left, DSLStatement right);
68 };
69 
70 /**
71  * Represents a Statement which may have failed and/or have pending errors to report. Converting a
72  * PossibleStatement into a Statement requires PositionInfo so that any pending errors can be
73  * reported at the correct position.
74  *
75  * PossibleStatement is used instead of Statement in situations where it is not possible to capture
76  * the PositionInfo at the time of Statement construction.
77  */
78 class DSLPossibleStatement {
79 public:
80     DSLPossibleStatement(std::unique_ptr<SkSL::Statement> stmt);
81 
82     DSLPossibleStatement(DSLPossibleStatement&& other) = default;
83 
84     ~DSLPossibleStatement();
85 
release()86     std::unique_ptr<SkSL::Statement> release() {
87         return std::move(fStatement);
88     }
89 
90 private:
91     std::unique_ptr<SkSL::Statement> fStatement;
92 
93     friend class DSLStatement;
94 };
95 
96 DSLStatement operator,(DSLStatement left, DSLStatement right);
97 
98 } // namespace dsl
99 
100 } // namespace SkSL
101 
102 #endif
103