]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/evaluate.h
Split SL::Compiler into several files
[libs/gl.git] / source / glsl / evaluate.h
diff --git a/source/glsl/evaluate.h b/source/glsl/evaluate.h
new file mode 100644 (file)
index 0000000..6cbc6cb
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef MSP_GL_SL_EVALUATE_H_
+#define MSP_GL_SL_EVALUATE_H_
+
+#include "visitor.h"
+
+namespace Msp {
+namespace GL {
+namespace SL {
+
+class ExpressionEvaluator: public NodeVisitor
+{
+public:
+       typedef std::map<VariableDeclaration *, Expression *> ValueMap;
+
+private:
+       const ValueMap *variable_values;
+       float result;
+       bool result_valid;
+
+public:
+       ExpressionEvaluator();
+       ExpressionEvaluator(const ValueMap &);
+
+       float get_result() const { return result; }
+       bool is_result_valid() const { return result_valid; }
+
+       using NodeVisitor::visit;
+       virtual void visit(Literal &);
+       virtual void visit(ParenthesizedExpression &);
+       virtual void visit(VariableReference &);
+       virtual void visit(UnaryExpression &);
+       virtual void visit(BinaryExpression &);
+};
+
+} // namespace SL
+} // namespace GL
+} // namespace Msp
+
+#endif