]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/syntax.h
Store a pointer to operator info rather than the token in expressions
[libs/gl.git] / source / glsl / syntax.h
index d646e558e9cdc44f607abb147cf45f6e840ae849..682a0f5aeeaa2246b01226df25536a23a91d9c7a 100644 (file)
@@ -3,12 +3,12 @@
 
 #include <list>
 #include <map>
+#include <set>
 #include <string>
 #include <vector>
 #include <msp/core/refptr.h>
-#include "extension.h"
+#include "features.h"
 #include "sourcemap.h"
-#include "uniform.h"
 
 #pragma push_macro("interface")
 #undef interface
@@ -39,6 +39,14 @@ struct Operator
        Associativity assoc;
 
        static const Operator operators[];
+
+       static const Operator &get_operator(const std::string &, Type);
+};
+
+enum
+{
+       BUILTIN_SOURCE = -1,
+       GENERATED_SOURCE = 0
 };
 
 struct NodeVisitor;
@@ -91,11 +99,12 @@ class NodeArray: public NodeContainer<std::vector<RefPtr<T> > >
 
 struct StructDeclaration;
 struct VariableDeclaration;
+struct InterfaceBlock;
 struct FunctionDeclaration;
 
 struct Statement: Node
 {
-       unsigned source;
+       int source;
        unsigned line;
 
        Statement();
@@ -107,8 +116,7 @@ struct Block: Node
 {
        NodeList<Statement> body;
        bool use_braces;
-       bool anonymous;
-       std::map<std::string, StructDeclaration *> types;
+
        std::map<std::string, VariableDeclaration *> variables;
        Block *parent;
 
@@ -121,6 +129,10 @@ struct Block: Node
 
 struct Expression: Node
 {
+       const Operator *oper;
+
+       Expression();
+
        virtual Expression *clone() const = 0;
 };
 
@@ -143,6 +155,7 @@ struct ParenthesizedExpression: Expression
 struct VariableReference: Expression
 {
        std::string name;
+
        VariableDeclaration *declaration;
 
        VariableReference();
@@ -152,10 +165,24 @@ struct VariableReference: Expression
        virtual void visit(NodeVisitor &);
 };
 
+struct InterfaceBlockReference: Expression
+{
+       std::string name;
+
+       InterfaceBlock *declaration;
+
+       InterfaceBlockReference();
+       InterfaceBlockReference(const InterfaceBlockReference &);
+
+       virtual InterfaceBlockReference *clone() const { return new InterfaceBlockReference(*this); }
+       virtual void visit(NodeVisitor &);
+};
+
 struct MemberAccess: Expression
 {
        NodePtr<Expression> left;
        std::string member;
+
        VariableDeclaration *declaration;
 
        MemberAccess();
@@ -167,11 +194,7 @@ struct MemberAccess: Expression
 
 struct UnaryExpression: Expression
 {
-       std::string oper;
        NodePtr<Expression> expression;
-       bool prefix;
-
-       UnaryExpression();
 
        virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
        virtual void visit(NodeVisitor &);
@@ -180,9 +203,7 @@ struct UnaryExpression: Expression
 struct BinaryExpression: Expression
 {
        NodePtr<Expression> left;
-       std::string oper;
        NodePtr<Expression> right;
-       std::string after;
 
        virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
        virtual void visit(NodeVisitor &);
@@ -191,6 +212,7 @@ struct BinaryExpression: Expression
 struct Assignment: BinaryExpression
 {
        bool self_referencing;
+
        VariableDeclaration *target_declaration;
 
        Assignment();
@@ -203,10 +225,11 @@ struct Assignment: BinaryExpression
 struct FunctionCall: Expression
 {
        std::string name;
-       FunctionDeclaration *declaration;
        bool constructor;
        NodeArray<Expression> arguments;
 
+       FunctionDeclaration *declaration;
+
        FunctionCall();
        FunctionCall(const FunctionCall &);
 
@@ -243,9 +266,9 @@ struct Layout: Node
 {
        struct Qualifier
        {
-               // TODO the standard calls this name, not identifier
-               std::string identifier;
-               std::string value;
+               std::string name;
+               bool has_value;
+               int value;
        };
 
        std::vector<Qualifier> qualifiers;
@@ -276,22 +299,24 @@ struct StructDeclaration: Statement
 
 struct VariableDeclaration: Statement
 {
+       NodePtr<Layout> layout;
        bool constant;
        std::string sampling;
        std::string interpolation;
        std::string interface;
        std::string precision;
        std::string type;
-       StructDeclaration *type_declaration;
        std::string name;
        bool array;
        NodePtr<Expression> array_size;
        NodePtr<Expression> init_expression;
+
+       StructDeclaration *type_declaration;
        VariableDeclaration *linked_declaration;
-       NodePtr<Layout> layout;
 
        VariableDeclaration();
        VariableDeclaration(const VariableDeclaration &);
+       ~VariableDeclaration();
 
        virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
        virtual void visit(NodeVisitor &);
@@ -305,7 +330,11 @@ struct InterfaceBlock: Statement
        std::string instance_name;
        bool array;
 
+       InterfaceBlock *linked_block;
+
        InterfaceBlock();
+       InterfaceBlock(const InterfaceBlock &);
+       ~InterfaceBlock();
 
        virtual InterfaceBlock *clone() const { return new InterfaceBlock(*this); }
        virtual void visit(NodeVisitor &);
@@ -316,9 +345,10 @@ struct FunctionDeclaration: Statement
        std::string return_type;
        std::string name;
        NodeArray<VariableDeclaration> parameters;
-       FunctionDeclaration *definition;
        Block body;
 
+       FunctionDeclaration *definition;
+
        FunctionDeclaration();
        FunctionDeclaration(const FunctionDeclaration &);
 
@@ -384,11 +414,11 @@ struct Stage
        Type type;
        Stage *previous;
        Block content;
-       std::map<std::string, VariableDeclaration *> in_variables;
-       std::map<std::string, VariableDeclaration *> out_variables;
+       std::map<std::string, StructDeclaration *> types;
+       std::map<std::string, InterfaceBlock *> interface_blocks;
+       std::map<std::string, FunctionDeclaration *> functions;
        std::map<std::string, unsigned> locations;
-       Version required_version;
-       std::vector<const Extension *> required_extensions;
+       Features required_features;
 
        Stage(Type);