]> 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 bda0dd1d7b2a0d673bcea91fc1fdbab23307ce37..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):
@@ -67,7 +76,7 @@ NodeContainer<C>::NodeContainer(const NodeContainer &c):
 
 
 Statement::Statement():
-       source(0),
+       source(GENERATED_SOURCE),
        line(1)
 { }
 
@@ -90,6 +99,11 @@ void Block::visit(NodeVisitor &visitor)
 }
 
 
+Expression::Expression():
+       oper(0)
+{ }
+
+
 void Literal::visit(NodeVisitor &visitor)
 {
        visitor.visit(*this);
@@ -107,6 +121,7 @@ VariableReference::VariableReference():
 { }
 
 VariableReference::VariableReference(const VariableReference &other):
+       Expression(other),
        name(other.name),
        declaration(0)
 { }
@@ -122,6 +137,7 @@ InterfaceBlockReference::InterfaceBlockReference():
 { }
 
 InterfaceBlockReference::InterfaceBlockReference(const InterfaceBlockReference &other):
+       Expression(other),
        name(other.name),
        declaration(0)
 { }
@@ -137,6 +153,7 @@ MemberAccess::MemberAccess():
 { }
 
 MemberAccess::MemberAccess(const MemberAccess &other):
+       Expression(other),
        left(other.left),
        member(other.member),
        declaration(0)
@@ -148,10 +165,6 @@ void MemberAccess::visit(NodeVisitor &visitor)
 }
 
 
-UnaryExpression::UnaryExpression():
-       prefix(true)
-{ }
-
 void UnaryExpression::visit(NodeVisitor &visitor)
 {
        visitor.visit(*this);
@@ -170,6 +183,7 @@ Assignment::Assignment():
 { }
 
 Assignment::Assignment(const Assignment &other):
+       BinaryExpression(other),
        self_referencing(other.self_referencing),
        target_declaration(0)
 { }
@@ -181,15 +195,16 @@ void Assignment::visit(NodeVisitor &visitor)
 
 
 FunctionCall::FunctionCall():
-       declaration(0),
-       constructor(false)
+       constructor(false),
+       declaration(0)
 { }
 
 FunctionCall::FunctionCall(const FunctionCall &other):
+       Expression(other),
        name(other.name),
-       declaration(0),
        constructor(other.constructor),
-       arguments(other.arguments)
+       arguments(other.arguments),
+       declaration(0)
 { }
 
 void FunctionCall::visit(NodeVisitor &visitor)
@@ -241,25 +256,26 @@ void StructDeclaration::visit(NodeVisitor &visitor)
 
 VariableDeclaration::VariableDeclaration():
        constant(false),
-       type_declaration(0),
        array(false),
+       type_declaration(0),
        linked_declaration(0)
 { }
 
 VariableDeclaration::VariableDeclaration(const VariableDeclaration &other):
+       Statement(other),
+       layout(other.layout),
        constant(other.constant),
        sampling(other.sampling),
        interpolation(other.interpolation),
        interface(other.interface),
        precision(other.precision),
        type(other.type),
-       type_declaration(0),
        name(other.name),
        array(other.array),
        array_size(other.array_size),
        init_expression(other.init_expression),
-       linked_declaration(0),
-       layout(other.layout)
+       type_declaration(0),
+       linked_declaration(0)
 { }
 
 VariableDeclaration::~VariableDeclaration()
@@ -282,6 +298,7 @@ InterfaceBlock::InterfaceBlock():
 }
 
 InterfaceBlock::InterfaceBlock(const InterfaceBlock &other):
+       Statement(other),
        interface(other.interface),
        name(other.name),
        members(other.members),
@@ -307,11 +324,12 @@ FunctionDeclaration::FunctionDeclaration():
 { }
 
 FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other):
+       Statement(other),
        return_type(other.return_type),
        name(other.name),
        parameters(other.parameters),
-       definition(other.definition==&other ? this : 0),
-       body(other.body)
+       body(other.body),
+       definition(other.definition==&other ? this : 0)
 { }
 
 void FunctionDeclaration::visit(NodeVisitor &visitor)