]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/syntax.cpp
Store a pointer to operator info rather than the token in expressions
[libs/gl.git] / source / glsl / syntax.cpp
index 90e26c39a37c24d663dc8846bb172f65007ec694..c60b33bf5bad26b86d2b0abc53b7ba442b451ce2 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/maputils.h>
 #include "syntax.h"
 #include "visitor.h"
 
@@ -10,7 +11,7 @@ namespace SL {
 const Operator Operator::operators[] =
 {
        { "[", 2, BINARY, LEFT_TO_RIGHT },
-       { "(", 2, BINARY, LEFT_TO_RIGHT },
+       { "(", 2, POSTFIX, LEFT_TO_RIGHT },
        { ".", 2, BINARY, LEFT_TO_RIGHT },
        { "++", 2, POSTFIX, LEFT_TO_RIGHT },
        { "--", 2, POSTFIX, LEFT_TO_RIGHT },
@@ -56,6 +57,14 @@ const Operator Operator::operators[] =
        { { 0 }, 18, NO_OPERATOR, LEFT_TO_RIGHT }
 };
 
+const Operator &Operator::get_operator(const string &token, Type type)
+{
+       for(const Operator *i=operators; i->type; ++i)
+               if(i->type==type && i->token==token)
+                       return *i;
+       throw key_error(token);
+}
+
 
 template<typename C>
 NodeContainer<C>::NodeContainer(const NodeContainer &c):
@@ -90,6 +99,11 @@ void Block::visit(NodeVisitor &visitor)
 }
 
 
+Expression::Expression():
+       oper(0)
+{ }
+
+
 void Literal::visit(NodeVisitor &visitor)
 {
        visitor.visit(*this);
@@ -151,10 +165,6 @@ void MemberAccess::visit(NodeVisitor &visitor)
 }
 
 
-UnaryExpression::UnaryExpression():
-       prefix(true)
-{ }
-
 void UnaryExpression::visit(NodeVisitor &visitor)
 {
        visitor.visit(*this);