]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/syntax.h
Use default member initializers for simple types
[libs/gl.git] / source / glsl / syntax.h
index 1caf4d9568c10f5b3c45faed04fd25cab14a606b..a3b217d40895f2d6e4ae790abec56082094b6e95 100644 (file)
@@ -6,7 +6,7 @@
 #include <set>
 #include <string>
 #include <vector>
-#include <msp/core/inttypes.h>
+#include <cstdint>
 #include <msp/core/refptr.h>
 #include <msp/core/variant.h>
 #include "features.h"
@@ -40,7 +40,7 @@ struct Operator
 
        char token[4];
        char token2[2];
-       UInt8 precedence;
+       std::uint8_t precedence;
        Type type;
        Associativity assoc;
 
@@ -60,15 +60,15 @@ struct NodeVisitor;
 
 struct Node
 {
-       int source;
-       unsigned line;
+       int source = GENERATED_SOURCE;
+       unsigned line = 1;
 
-       Node(): source(GENERATED_SOURCE), line(1) { }
-       Node(const Node &n): source(n.source), line(n.line) { }
+       Node() = default;
+       Node(const Node &) = default;
 private:
        Node &operator=(const Node &);
 public:
-       virtual ~Node() { }
+       virtual ~Node() = default;
 
        virtual Node *clone() const = 0;
        virtual void visit(NodeVisitor &) = 0;
@@ -78,10 +78,10 @@ template<typename T>
 class NodePtr: public RefPtr<T>
 {
 public:
-       NodePtr() { }
+       NodePtr() = default;
        NodePtr(T *p): RefPtr<T>(p) { }
        NodePtr(const NodePtr &p): RefPtr<T>(p ? p->clone() : 0) { }
-       NodePtr &operator=(const NodePtr &p) { RefPtr<T>::operator=(p); return *this; }
+       NodePtr &operator=(const NodePtr &p) = default;
 
        template<typename U>
        NodePtr(const RefPtr<U> &p): RefPtr<T>(p) { }
@@ -94,7 +94,7 @@ template<typename C>
 class NodeContainer: public C
 {
 public:
-       NodeContainer() { }
+       NodeContainer() = default;
        NodeContainer(const NodeContainer &);
 
        void push_back_nocopy(const typename C::value_type &v)
@@ -122,12 +122,12 @@ struct Statement: Node
 struct Block: Node
 {
        NodeList<Statement> body;
-       bool use_braces;
+       bool use_braces = false;
 
        std::map<std::string, VariableDeclaration *> variables;
-       Block *parent;
+       Block *parent = 0;
 
-       Block();
+       Block() = default;
        Block(const Block &);
 
        virtual Block *clone() const { return new Block(*this); }
@@ -136,12 +136,10 @@ struct Block: Node
 
 struct Expression: Node
 {
-       const Operator *oper;
+       const Operator *oper = 0;
 
-       TypeDeclaration *type;
-       bool lvalue;
-
-       Expression();
+       TypeDeclaration *type = 0;
+       bool lvalue = false;
 
        virtual Expression *clone() const = 0;
 };
@@ -159,9 +157,9 @@ struct VariableReference: Expression
 {
        std::string name;
 
-       VariableDeclaration *declaration;
+       VariableDeclaration *declaration = 0;
 
-       VariableReference();
+       VariableReference() = default;
        VariableReference(const VariableReference &);
 
        virtual VariableReference *clone() const { return new VariableReference(*this); }
@@ -172,9 +170,9 @@ struct InterfaceBlockReference: Expression
 {
        std::string name;
 
-       InterfaceBlock *declaration;
+       InterfaceBlock *declaration = 0;
 
-       InterfaceBlockReference();
+       InterfaceBlockReference() = default;
        InterfaceBlockReference(const InterfaceBlockReference &);
 
        virtual InterfaceBlockReference *clone() const { return new InterfaceBlockReference(*this); }
@@ -186,9 +184,10 @@ struct MemberAccess: Expression
        NodePtr<Expression> left;
        std::string member;
 
-       VariableDeclaration *declaration;
+       VariableDeclaration *declaration = 0;
+       int index = -1;
 
-       MemberAccess();
+       MemberAccess() = default;
        MemberAccess(const MemberAccess &);
 
        virtual MemberAccess *clone() const { return new MemberAccess(*this); }
@@ -199,10 +198,8 @@ struct Swizzle: Expression
 {
        NodePtr<Expression> left;
        std::string component_group;
-       unsigned count;
-       UInt8 components[4];
-
-       Swizzle();
+       unsigned count = 0;
+       std::uint8_t components[4] = { 0, 0, 0, 0 };
 
        virtual Swizzle *clone() const { return new Swizzle(*this); }
        virtual void visit(NodeVisitor &);
@@ -236,20 +233,20 @@ struct Assignment: BinaryExpression
                        ARRAY = 0xC0
                };
 
-               Statement *declaration;
-               Msp::UInt8 chain_len;
-               Msp::UInt8 chain[7];
+               Statement *declaration = 0;
+               std::uint8_t chain_len = 0;
+               std::uint8_t chain[7] = { };
 
-               Target(Statement * = 0);
+               Target(Statement *d = 0): declaration(d) { }
 
                bool operator<(const Target &) const;
        };
 
-       bool self_referencing;
+       bool self_referencing = false;
 
        Target target;
 
-       Assignment();
+       Assignment() = default;
        Assignment(const Assignment &);
 
        virtual Assignment *clone() const { return new Assignment(*this); }
@@ -269,12 +266,12 @@ struct TernaryExpression: Expression
 struct FunctionCall: Expression
 {
        std::string name;
-       bool constructor;
+       bool constructor = false;
        NodeArray<Expression> arguments;
 
-       FunctionDeclaration *declaration;
+       FunctionDeclaration *declaration = 0;
 
-       FunctionCall();
+       FunctionCall() = default;
        FunctionCall(const FunctionCall &);
 
        virtual FunctionCall *clone() const { return new FunctionCall(*this); }
@@ -313,6 +310,9 @@ struct Layout: Node
                std::string name;
                bool has_value;
                int value;
+
+               Qualifier(const std::string &n = std::string()): name(n), has_value(false), value(0) { }
+               Qualifier(const std::string &n, int v): name(n), has_value(true), value(v) { }
        };
 
        std::vector<Qualifier> qualifiers;
@@ -351,13 +351,14 @@ struct BasicTypeDeclaration: TypeDeclaration
                ARRAY
        };
 
-       Kind kind;
-       unsigned size;
+       Kind kind = ALIAS;
+       unsigned size = 0;
+       bool sign = true;
        std::string base;
 
-       TypeDeclaration *base_type;
+       TypeDeclaration *base_type = 0;
 
-       BasicTypeDeclaration();
+       BasicTypeDeclaration() = default;
        BasicTypeDeclaration(const BasicTypeDeclaration &);
 
        virtual BasicTypeDeclaration *clone() const { return new BasicTypeDeclaration(*this); }
@@ -374,15 +375,13 @@ struct ImageTypeDeclaration: TypeDeclaration
                CUBE
        };
 
-       Dimensions dimensions;
-       bool array;
-       bool sampled;
-       bool shadow;
+       Dimensions dimensions = TWO;
+       bool array = false;
+       bool sampled = true;
+       bool shadow = false;
        std::string base;
 
-       TypeDeclaration *base_type;
-
-       ImageTypeDeclaration();
+       TypeDeclaration *base_type = 0;
 
        virtual ImageTypeDeclaration *clone() const { return new ImageTypeDeclaration(*this); }
        virtual void visit(NodeVisitor &);
@@ -392,7 +391,7 @@ struct StructDeclaration: TypeDeclaration
 {
        Block members;
 
-       InterfaceBlock *interface_block;
+       InterfaceBlock *interface_block = 0;
 
        StructDeclaration();
        StructDeclaration(const StructDeclaration &);
@@ -405,21 +404,21 @@ struct StructDeclaration: TypeDeclaration
 struct VariableDeclaration: Statement
 {
        NodePtr<Layout> layout;
-       bool constant;
+       bool constant = false;
        std::string sampling;
        std::string interpolation;
        std::string interface;
        std::string precision;
        std::string type;
        std::string name;
-       bool array;
+       bool array = false;
        NodePtr<Expression> array_size;
        NodePtr<Expression> init_expression;
 
-       TypeDeclaration *type_declaration;
-       VariableDeclaration *linked_declaration;
+       TypeDeclaration *type_declaration = 0;
+       VariableDeclaration *linked_declaration = 0;
 
-       VariableDeclaration();
+       VariableDeclaration() = default;
        VariableDeclaration(const VariableDeclaration &);
        ~VariableDeclaration();
 
@@ -434,15 +433,15 @@ struct InterfaceBlock: Statement
        std::string block_name;
        NodePtr<Block> members;
        std::string instance_name;
-       bool array;
+       bool array = false;
 
        /* An interface block's ultimate base type is always a struct.  The
        immediate type may be either that same struct or an array of it. */
-       TypeDeclaration *type_declaration;
-       StructDeclaration *struct_declaration;
-       InterfaceBlock *linked_block;
+       TypeDeclaration *type_declaration = 0;
+       StructDeclaration *struct_declaration = 0;
+       InterfaceBlock *linked_block = 0;
 
-       InterfaceBlock();
+       InterfaceBlock() = default;
        InterfaceBlock(const InterfaceBlock &);
        ~InterfaceBlock();
 
@@ -455,15 +454,15 @@ struct FunctionDeclaration: Statement
        std::string return_type;
        std::string name;
        NodeArray<VariableDeclaration> parameters;
-       bool virtua;
-       bool overrd;
+       bool virtua = false;
+       bool overrd = false;
        Block body;
 
        std::string signature;
-       FunctionDeclaration *definition;
-       TypeDeclaration *return_type_declaration;
+       FunctionDeclaration *definition = 0;
+       TypeDeclaration *return_type_declaration = 0;
 
-       FunctionDeclaration();
+       FunctionDeclaration() = default;
        FunctionDeclaration(const FunctionDeclaration &);
 
        virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
@@ -532,6 +531,8 @@ struct Stage
        std::map<std::string, InterfaceBlock *> interface_blocks;
        std::map<std::string, FunctionDeclaration *> functions;
        std::map<std::string, unsigned> locations;
+       std::map<std::string, unsigned> texture_bindings;
+       std::map<std::string, unsigned> uniform_block_bindings;
        Features required_features;
        std::vector<Diagnostic> diagnostics;
 
@@ -551,6 +552,9 @@ struct Module
 
 std::string get_unused_variable_name(const Block &, const std::string &);
 
+int get_layout_value(const Layout &, const std::string &, int = -1);
+void add_to_chain(Assignment::Target &, Assignment::Target::ChainType, unsigned);
+
 } // namespace SL
 } // namespace GL
 } // namespace Msp