]> git.tdb.fi Git - libs/gl.git/commitdiff
Avoid copying raw pointers in the syntax tree
authorMikko Rasa <tdb@tdb.fi>
Sat, 20 Feb 2021 22:59:07 +0000 (00:59 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 21 Feb 2021 02:20:27 +0000 (04:20 +0200)
They will potentially point to incorrect nodes and must be resolved
again.

source/glsl/compiler.cpp
source/glsl/syntax.cpp
source/glsl/syntax.h

index 35977cb42be534077bca6c9f3427fbbcc158d443..02f4ea13b7fbe864245898af9658b40d3e81116d 100644 (file)
@@ -185,6 +185,7 @@ bool Compiler::optimize(Stage &stage)
        ConstantConditionEliminator().apply(stage);
 
        FunctionInliner().apply(stage);
+       VariableResolver().apply(stage);
 
        bool result = UnusedVariableRemover().apply(stage);
        result |= UnusedFunctionRemover().apply(stage);
index affc09adfad7badff8ca65d7e39a4730fc9629be..957b49cea61a149fc213f9dbe71ecc9fa9774d1b 100644 (file)
@@ -98,12 +98,27 @@ VariableReference::VariableReference():
        declaration(0)
 { }
 
+VariableReference::VariableReference(const VariableReference &other):
+       name(other.name),
+       declaration(0)
+{ }
+
 void VariableReference::visit(NodeVisitor &visitor)
 {
        visitor.visit(*this);
 }
 
 
+MemberAccess::MemberAccess():
+       declaration(0)
+{ }
+
+MemberAccess::MemberAccess(const MemberAccess &other):
+       left(other.left),
+       member(other.member),
+       declaration(0)
+{ }
+
 void MemberAccess::visit(NodeVisitor &visitor)
 {
        visitor.visit(*this);
@@ -131,6 +146,11 @@ Assignment::Assignment():
        target_declaration(0)
 { }
 
+Assignment::Assignment(const Assignment &other):
+       self_referencing(other.self_referencing),
+       target_declaration(0)
+{ }
+
 void Assignment::visit(NodeVisitor &visitor)
 {
        visitor.visit(*this);
@@ -142,6 +162,13 @@ FunctionCall::FunctionCall():
        constructor(false)
 { }
 
+FunctionCall::FunctionCall(const FunctionCall &other):
+       name(other.name),
+       declaration(0),
+       constructor(other.constructor),
+       arguments(other.arguments)
+{ }
+
 void FunctionCall::visit(NodeVisitor &visitor)
 {
        visitor.visit(*this);
@@ -196,6 +223,22 @@ VariableDeclaration::VariableDeclaration():
        linked_declaration(0)
 { }
 
+VariableDeclaration::VariableDeclaration(const VariableDeclaration &other):
+       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)
+{ }
+
 void VariableDeclaration::visit(NodeVisitor &visitor)
 {
        visitor.visit(*this);
@@ -222,7 +265,7 @@ FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other):
        return_type(other.return_type),
        name(other.name),
        parameters(other.parameters),
-       definition(other.definition==&other ? this : other.definition),
+       definition(other.definition==&other ? this : 0),
        body(other.body)
 { }
 
index 7764712498bb3106666f3e8bee98de72881516df..05bcee545f4a62431ddf8c00978d766e6c670565 100644 (file)
@@ -143,6 +143,7 @@ struct VariableReference: Expression
        VariableDeclaration *declaration;
 
        VariableReference();
+       VariableReference(const VariableReference &);
 
        virtual VariableReference *clone() const { return new VariableReference(*this); }
        virtual void visit(NodeVisitor &);
@@ -154,6 +155,9 @@ struct MemberAccess: Expression
        std::string member;
        VariableDeclaration *declaration;
 
+       MemberAccess();
+       MemberAccess(const MemberAccess &);
+
        virtual MemberAccess *clone() const { return new MemberAccess(*this); }
        virtual void visit(NodeVisitor &);
 };
@@ -187,6 +191,7 @@ struct Assignment: BinaryExpression
        VariableDeclaration *target_declaration;
 
        Assignment();
+       Assignment(const Assignment &);
 
        virtual Assignment *clone() const { return new Assignment(*this); }
        virtual void visit(NodeVisitor &);
@@ -200,6 +205,7 @@ struct FunctionCall: Expression
        NodeArray<Expression> arguments;
 
        FunctionCall();
+       FunctionCall(const FunctionCall &);
 
        virtual FunctionCall *clone() const { return new FunctionCall(*this); }
        virtual void visit(NodeVisitor &);
@@ -282,6 +288,7 @@ struct VariableDeclaration: Statement
        NodePtr<Layout> layout;
 
        VariableDeclaration();
+       VariableDeclaration(const VariableDeclaration &);
 
        virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
        virtual void visit(NodeVisitor &);