}
}
+void ConstantConditionEliminator::visit(RefPtr<Expression> &expr)
+{
+ r_ternary_result = 0;
+ expr->visit(*this);
+ if(r_ternary_result)
+ expr = r_ternary_result;
+ r_ternary_result = 0;
+}
+
+void ConstantConditionEliminator::visit(TernaryExpression &ternary)
+{
+ ConstantStatus result = check_constant_condition(*ternary.condition);
+ if(result!=NOT_CONSTANT)
+ r_ternary_result = (result==CONSTANT_TRUE ? ternary.true_expr : ternary.false_expr);
+ else
+ r_ternary_result = 0;
+}
+
void ConstantConditionEliminator::visit(Conditional &cond)
{
ConstantStatus result = check_constant_condition(*cond.condition);
NodeList<Statement>::iterator insert_point;
std::set<Node *> nodes_to_remove;
+ RefPtr<Expression> r_ternary_result;
public:
void apply(Stage &);
ConstantStatus check_constant_condition(const Expression &);
virtual void visit(Block &);
+ virtual void visit(RefPtr<Expression> &);
+ virtual void visit(TernaryExpression &);
virtual void visit(Conditional &);
virtual void visit(Iteration &);
};
--- /dev/null
+const bool use_color = false;
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+layout(location=1) in vec4 color;
+void main()
+{
+ gl_Position = position;
+ passthrough;
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_color;
+void main()
+{
+ frag_color = (use_color ? color : vec4(1.0));
+}
+
+/* Expected output: vertex
+layout(location=0) in vec4 position;
+void main()
+{
+ gl_Position = position;
+}
+*/
+
+/* Expected output: fragment
+layout(location=0) out vec4 frag_color;
+void main()
+{
+ frag_color = vec4(1.0);
+}
+*/