X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fsyntax.h;h=62c289d9fbb6ec48f61be268b7eec67072718e98;hb=4c805f55d89919d6971d600102ab4d6d65d56dc3;hp=55f47402f514538b959a459a07b3532e2a0d5efd;hpb=7f29c6d2a4eee36538d7ccf24980e749592e2444;p=libs%2Fgl.git diff --git a/source/glsl/syntax.h b/source/glsl/syntax.h index 55f47402..62c289d9 100644 --- a/source/glsl/syntax.h +++ b/source/glsl/syntax.h @@ -8,6 +8,7 @@ #include #include #include "features.h" +#include "glsl_error.h" #include "sourcemap.h" #pragma push_macro("interface") @@ -30,7 +31,8 @@ struct Operator enum Associativity { LEFT_TO_RIGHT, - RIGHT_TO_LEFT + RIGHT_TO_LEFT, + ASSOCIATIVE }; char token[4]; @@ -39,15 +41,25 @@ 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; struct Node { -protected: - Node() { } - Node(const Node &) { } + int source; + unsigned line; + + Node(): source(GENERATED_SOURCE), line(1) { } + Node(const Node &n): source(n.source), line(n.line) { } private: Node &operator=(const Node &); public: @@ -96,11 +108,6 @@ struct FunctionDeclaration; struct Statement: Node { - unsigned source; - unsigned line; - - Statement(); - virtual Statement *clone() const = 0; }; @@ -121,6 +128,10 @@ struct Block: Node struct Expression: Node { + const Operator *oper; + + Expression(); + virtual Expression *clone() const = 0; }; @@ -182,11 +193,7 @@ struct MemberAccess: Expression struct UnaryExpression: Expression { - std::string oper; NodePtr expression; - bool prefix; - - UnaryExpression(); virtual UnaryExpression *clone() const { return new UnaryExpression(*this); } virtual void visit(NodeVisitor &); @@ -195,9 +202,7 @@ struct UnaryExpression: Expression struct BinaryExpression: Expression { NodePtr left; - std::string oper; NodePtr right; - std::string after; virtual BinaryExpression *clone() const { return new BinaryExpression(*this); } virtual void visit(NodeVisitor &); @@ -280,9 +285,66 @@ struct InterfaceLayout: Statement virtual void visit(NodeVisitor &); }; -struct StructDeclaration: Statement +struct TypeDeclaration: Statement { std::string name; + + virtual TypeDeclaration *clone() const = 0; +}; + +struct BasicTypeDeclaration: TypeDeclaration +{ + enum Kind + { + ALIAS, + VOID, + BOOL, + INT, + FLOAT, + VECTOR, + MATRIX, + ARRAY + }; + + Kind kind; + unsigned size; + std::string base; + + TypeDeclaration *base_type; + + BasicTypeDeclaration(); + BasicTypeDeclaration(const BasicTypeDeclaration &); + + virtual BasicTypeDeclaration *clone() const { return new BasicTypeDeclaration(*this); } + virtual void visit(NodeVisitor &); +}; + +struct ImageTypeDeclaration: TypeDeclaration +{ + enum Dimensions + { + ONE = 1, + TWO, + THREE, + CUBE + }; + + Dimensions dimensions; + bool array; + bool sampled; + bool shadow; + std::string base; + + TypeDeclaration *base_type; + + ImageTypeDeclaration(); + + virtual ImageTypeDeclaration *clone() const { return new ImageTypeDeclaration(*this); } + virtual void visit(NodeVisitor &); +}; + +struct StructDeclaration: TypeDeclaration +{ Block members; StructDeclaration(); @@ -305,7 +367,7 @@ struct VariableDeclaration: Statement NodePtr array_size; NodePtr init_expression; - StructDeclaration *type_declaration; + TypeDeclaration *type_declaration; VariableDeclaration *linked_declaration; VariableDeclaration(); @@ -362,7 +424,7 @@ struct Conditional: Statement struct Iteration: Statement { - NodePtr init_statement; + NodePtr init_statement; NodePtr condition; NodePtr loop_expression; Block body; @@ -408,10 +470,12 @@ struct Stage Type type; Stage *previous; Block content; - std::map types; + std::map types; std::map interface_blocks; + std::map functions; std::map locations; Features required_features; + std::vector diagnostics; Stage(Type);