1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Random Shader Generator
3 * ----------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Expression generator.
22 *//*--------------------------------------------------------------------*/
24 #include "rsgExpressionGenerator.hpp"
29 ExpressionGenerator::ExpressionGenerator (GeneratorState& state)
34 ExpressionGenerator::~ExpressionGenerator (void)
38 Expression* ExpressionGenerator::generate (const ValueRange& valueRange, int initialDepth)
41 m_state.setExpressionDepth(initialDepth);
42 Expression* root = Expression::createRandom(m_state, valueRange);
46 // Generate full expression
49 catch (const std::exception&)
52 m_expressionStack.clear();
59 void ExpressionGenerator::generate (Expression* root)
61 DE_ASSERT(m_expressionStack.empty());
64 m_expressionStack.push_back(root);
65 m_state.setExpressionDepth(m_state.getExpressionDepth()+1);
68 while (!m_expressionStack.empty())
70 DE_ASSERT(m_state.getExpressionDepth() <= m_state.getShaderParameters().maxExpressionDepth);
72 Expression* curExpr = m_expressionStack[m_expressionStack.size()-1];
73 Expression* child = curExpr->createNextChild(m_state);
77 m_expressionStack.push_back(child);
78 m_state.setExpressionDepth(m_state.getExpressionDepth()+1);
82 m_expressionStack.pop_back();
83 m_state.setExpressionDepth(m_state.getExpressionDepth()-1);