1 #ifndef _RSGSTATEMENT_HPP
2 #define _RSGSTATEMENT_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Random Shader Generator
5 * ----------------------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
24 *//*--------------------------------------------------------------------*/
26 #include "rsgDefs.hpp"
27 #include "rsgGeneratorState.hpp"
28 #include "rsgVariableManager.hpp"
29 #include "rsgExpression.hpp"
30 #include "rsgToken.hpp"
41 virtual ~Statement (void);
43 virtual Statement* createNextChild (GeneratorState& state) = DE_NULL;
44 virtual void tokenize (GeneratorState& state, TokenStream& str) const = DE_NULL;
45 virtual void execute (ExecutionContext& execCtx) const = DE_NULL;
55 class ExpressionStatement : public Statement
58 ExpressionStatement (GeneratorState& state);
59 virtual ~ExpressionStatement (void);
61 Statement* createNextChild (GeneratorState& state) { DE_UNREF(state); return DE_NULL; }
62 void tokenize (GeneratorState& state, TokenStream& str) const;
63 void execute (ExecutionContext& execCtx) const;
65 static float getWeight (const GeneratorState& state);
68 Expression* m_expression;
71 class DeclarationStatement : public Statement
74 DeclarationStatement (GeneratorState& state, Variable* variable = DE_NULL);
75 virtual ~DeclarationStatement (void);
77 Statement* createNextChild (GeneratorState& state) { DE_UNREF(state); return DE_NULL; }
78 void tokenize (GeneratorState& state, TokenStream& str) const;
79 void execute (ExecutionContext& execCtx) const;
81 static float getWeight (const GeneratorState& state);
84 const Variable* m_variable;
85 Expression* m_expression;
88 class BlockStatement : public Statement
91 BlockStatement (GeneratorState& state);
92 virtual ~BlockStatement (void);
94 BlockStatement (void) : m_numChildrenToCreate(0) {}
95 void init (GeneratorState& state);
97 Statement* createNextChild (GeneratorState& state);
98 void tokenize (GeneratorState& state, TokenStream& str) const;
99 void execute (ExecutionContext& execCtx) const;
101 static float getWeight (const GeneratorState& state);
103 void addChild (Statement* statement);
106 VariableScope m_scope;
108 int m_numChildrenToCreate;
109 std::vector<Statement*> m_children;
112 class ConditionalStatement : public Statement
115 ConditionalStatement (GeneratorState& state);
116 virtual ~ConditionalStatement (void);
118 Statement* createNextChild (GeneratorState& state);
119 void tokenize (GeneratorState& state, TokenStream& str) const;
120 void execute (ExecutionContext& execCtx) const;
122 static float getWeight (const GeneratorState& state);
125 bool isElseBlockRequired (const GeneratorState& state) const;
127 Expression* m_condition;
128 Statement* m_trueStatement;
129 Statement* m_falseStatement;
131 ValueScope m_conditionalScope;
134 // \note Used for generating mandatory assignments (shader outputs, function outputs).
135 // Normally assignment is handled inside ExpressionStatement where generator may
136 // choose to generate AssignOp expression.
137 class AssignStatement : public Statement
140 AssignStatement (const Variable* variable, Expression* value);
141 AssignStatement (GeneratorState& state, const Variable* variable, ConstValueRangeAccess valueRange);
142 virtual ~AssignStatement (void);
144 Statement* createNextChild (GeneratorState& state) { DE_UNREF(state); return DE_NULL; }
145 void tokenize (GeneratorState& state, TokenStream& str) const;
146 void execute (ExecutionContext& execCtx) const;
149 const Variable* m_variable;
150 Expression* m_valueExpr;
155 #endif // _RSGSTATEMENT_HPP