]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/syntax.cpp
Add GLSL keywords for overriding functions
[libs/gl.git] / source / glsl / syntax.cpp
index c8058c4fe9a228b102cbe4792daa83dc3f921f70..025af2710bb55da807fb686b6876eaef41d4ce22 100644 (file)
@@ -40,8 +40,8 @@ const Operator Operator::operators[] =
        { "&&", 12, BINARY, ASSOCIATIVE },
        { "^^", 13, BINARY, ASSOCIATIVE },
        { "||", 14, BINARY, ASSOCIATIVE },
-       { "?", 15, BINARY, RIGHT_TO_LEFT },
-       { ":", 15, BINARY, RIGHT_TO_LEFT },
+       { "?", 15, TERNARY, RIGHT_TO_LEFT },
+       { ":", 15, TERNARY, RIGHT_TO_LEFT },
        { "=", 16, BINARY, RIGHT_TO_LEFT },
        { "+=", 16, BINARY, RIGHT_TO_LEFT },
        { "-=", 16, BINARY, RIGHT_TO_LEFT },
@@ -94,7 +94,9 @@ void Block::visit(NodeVisitor &visitor)
 
 
 Expression::Expression():
-       oper(0)
+       oper(0),
+       type(0),
+       lvalue(false)
 { }
 
 
@@ -159,6 +161,18 @@ void MemberAccess::visit(NodeVisitor &visitor)
 }
 
 
+Swizzle::Swizzle():
+       count(0)
+{
+       fill(components, components+4, 0);
+}
+
+void Swizzle::visit(NodeVisitor &visitor)
+{
+       visitor.visit(*this);
+}
+
+
 void UnaryExpression::visit(NodeVisitor &visitor)
 {
        visitor.visit(*this);
@@ -172,14 +186,12 @@ void BinaryExpression::visit(NodeVisitor &visitor)
 
 
 Assignment::Assignment():
-       self_referencing(false),
-       target_declaration(0)
+       self_referencing(false)
 { }
 
 Assignment::Assignment(const Assignment &other):
        BinaryExpression(other),
-       self_referencing(other.self_referencing),
-       target_declaration(0)
+       self_referencing(other.self_referencing)
 { }
 
 void Assignment::visit(NodeVisitor &visitor)
@@ -188,6 +200,30 @@ void Assignment::visit(NodeVisitor &visitor)
 }
 
 
+Assignment::Target::Target(Statement *d):
+       declaration(d),
+       chain_len(0)
+{
+       fill(chain, chain+7, 0);
+}
+
+bool Assignment::Target::operator<(const Target &other) const
+{
+       if(declaration!=other.declaration)
+               return declaration<other.declaration;
+       for(unsigned i=0; (i<7 && i<chain_len && i<other.chain_len); ++i)
+               if(chain[i]!=other.chain[i])
+                       return chain[i]<other.chain[i];
+       return chain_len<other.chain_len;
+}
+
+
+void TernaryExpression::visit(NodeVisitor &visitor)
+{
+       visitor.visit(*this);
+}
+
+
 FunctionCall::FunctionCall():
        constructor(false),
        declaration(0)
@@ -270,11 +306,24 @@ void ImageTypeDeclaration::visit(NodeVisitor &visitor)
 }
 
 
-StructDeclaration::StructDeclaration()
+StructDeclaration::StructDeclaration():
+       interface_block(0)
 {
        members.use_braces = true;
 }
 
+StructDeclaration::StructDeclaration(const StructDeclaration &other):
+       TypeDeclaration(other),
+       members(other.members),
+       interface_block(0)
+{ }
+
+StructDeclaration::~StructDeclaration()
+{
+       if(interface_block && interface_block->struct_declaration==this)
+               interface_block->struct_declaration = 0;
+}
+
 void StructDeclaration::visit(NodeVisitor &visitor)
 {
        visitor.visit(*this);
@@ -319,10 +368,10 @@ void VariableDeclaration::visit(NodeVisitor &visitor)
 
 InterfaceBlock::InterfaceBlock():
        array(false),
+       type_declaration(0),
+       struct_declaration(0),
        linked_block(0)
-{
-       members.use_braces = true;
-}
+{ }
 
 InterfaceBlock::InterfaceBlock(const InterfaceBlock &other):
        Statement(other),
@@ -331,6 +380,8 @@ InterfaceBlock::InterfaceBlock(const InterfaceBlock &other):
        members(other.members),
        instance_name(other.instance_name),
        array(other.array),
+       type_declaration(0),
+       struct_declaration(0),
        linked_block(0)
 { }
 
@@ -338,6 +389,8 @@ InterfaceBlock::~InterfaceBlock()
 {
        if(linked_block && linked_block->linked_block==this)
                linked_block->linked_block = 0;
+       if(struct_declaration && struct_declaration->interface_block==this)
+               struct_declaration->interface_block = 0;
 }
 
 void InterfaceBlock::visit(NodeVisitor &visitor)
@@ -347,6 +400,8 @@ void InterfaceBlock::visit(NodeVisitor &visitor)
 
 
 FunctionDeclaration::FunctionDeclaration():
+       virtua(false),
+       overrd(false),
        definition(0),
        return_type_declaration(0)
 { }
@@ -356,7 +411,10 @@ FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other):
        return_type(other.return_type),
        name(other.name),
        parameters(other.parameters),
+       virtua(other.virtua),
+       overrd(other.overrd),
        body(other.body),
+       signature(other.signature),
        definition(other.definition==&other ? this : 0),
        return_type_declaration(0)
 { }