TraversingVisitor::visit(func);
}
+void ExpressionValidator::visit(Conditional &cond)
+{
+ if(cond.condition->type)
+ {
+ BasicTypeDeclaration *basic_cond = dynamic_cast<BasicTypeDeclaration *>(cond.condition->type);
+ if(!basic_cond || basic_cond->kind!=BasicTypeDeclaration::BOOL)
+ error(cond, "Condition is not a boolean");
+ }
+ TraversingVisitor::visit(cond);
+}
+
+void ExpressionValidator::visit(Iteration &iter)
+{
+ if(iter.condition->type)
+ {
+ BasicTypeDeclaration *basic_cond = dynamic_cast<BasicTypeDeclaration *>(iter.condition->type);
+ if(!basic_cond || basic_cond->kind!=BasicTypeDeclaration::BOOL)
+ error(iter, "Loop condition is not a boolean");
+ }
+ TraversingVisitor::visit(iter);
+}
+
void ExpressionValidator::visit(Return &ret)
{
if(current_function && current_function->return_type_declaration)
virtual void visit(TernaryExpression &);
virtual void visit(VariableDeclaration &);
virtual void visit(FunctionDeclaration &);
+ virtual void visit(Conditional &);
+ virtual void visit(Iteration &);
virtual void visit(Return &);
};
--- /dev/null
+uniform vec3 light_dir[8];
+uniform int light_count;
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+layout(location=1) in vec3 normal;
+void main()
+{
+ out float light_intensity = 0.0;
+ if(light_count)
+ {
+ for(int i=light_count; i--; )
+ light_intensity += dot(normal, light_dir[i]);
+ }
+ gl_Position = position;
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_color;
+void main()
+{
+ frag_color = vec4(vec3(light_intensity), 1.0);
+}
+
+/* Expected error:
+<test>:10: Condition is not a boolean
+<test>:12: Loop condition is not a boolean
+*/