]> git.tdb.fi Git - libs/gl.git/commitdiff
Remove the ParenthesizedExpression node type
authorMikko Rasa <tdb@tdb.fi>
Sat, 13 Mar 2021 19:30:48 +0000 (21:30 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 14 Mar 2021 00:23:37 +0000 (02:23 +0200)
Since this is a proper compiler now, it's no longer necessary to
reproduce the parentheses from the input.

15 files changed:
source/glsl/debug.cpp
source/glsl/debug.h
source/glsl/evaluate.cpp
source/glsl/evaluate.h
source/glsl/generate.cpp
source/glsl/generate.h
source/glsl/output.cpp
source/glsl/output.h
source/glsl/parser.cpp
source/glsl/syntax.cpp
source/glsl/syntax.h
source/glsl/visitor.cpp
source/glsl/visitor.h
tests/glsl/binary_operators.glsl
tests/glsl/parentheses.glsl [new file with mode: 0644]

index ddf1013dda2b5a70b00619c821652ae7d50f9e15..308fbad73225999efa4a742e2d5ad679b9f80a50 100644 (file)
@@ -146,11 +146,6 @@ void DumpTree::visit(Literal &literal)
        append(format("Literal: %s -> %s", literal.token, format_type(literal.type)));
 }
 
-void DumpTree::visit(ParenthesizedExpression &parexpr)
-{
-       annotated_branch(format("(expr) -> %s", format_type(parexpr.type)), *parexpr.expression);
-}
-
 void DumpTree::visit(VariableReference &var)
 {
        string text;
index a5dae0905c3dec3b5d0b01f644a4da8a18eac4fc..a0da24425faa70006af7ad2ce09b49fa67575195 100644 (file)
@@ -54,7 +54,6 @@ private:
 
        virtual void visit(Block &);
        virtual void visit(Literal &);
-       virtual void visit(ParenthesizedExpression &);
        virtual void visit(VariableReference &);
        virtual void visit(InterfaceBlockReference &);
        virtual void visit(MemberAccess &);
index f290002b61a14c0fefb15b92398a821c7ec7f529..2b3f50a651b808217061895197384ec87c8764e9 100644 (file)
@@ -28,11 +28,6 @@ void ExpressionEvaluator::visit(Literal &literal)
        r_result_valid = true;
 }
 
-void ExpressionEvaluator::visit(ParenthesizedExpression &parexp)
-{
-       parexp.expression->visit(*this);
-}
-
 void ExpressionEvaluator::visit(VariableReference &var)
 {
        if(!var.declaration)
index f3d3755ff62b602ead868278aa3ad8c0e17141a1..4ad267797152050de9e44b34605119c58484b110 100644 (file)
@@ -28,7 +28,6 @@ public:
 
        using NodeVisitor::visit;
        virtual void visit(Literal &);
-       virtual void visit(ParenthesizedExpression &);
        virtual void visit(VariableReference &);
        virtual void visit(UnaryExpression &);
        virtual void visit(BinaryExpression &);
index 2ff751946528f75e2a39f6a512565231ed10ce8c..9dff1e607ae40f6fd7019cdbac2f2338ff81de23 100644 (file)
@@ -619,12 +619,6 @@ void ExpressionResolver::visit(Literal &literal)
                resolve(literal, find_type(BasicTypeDeclaration::FLOAT, 32), false);
 }
 
-void ExpressionResolver::visit(ParenthesizedExpression &parexpr)
-{
-       TraversingVisitor::visit(parexpr);
-       resolve(parexpr, parexpr.expression->type, parexpr.expression->lvalue);
-}
-
 void ExpressionResolver::visit(VariableReference &var)
 {
        if(var.declaration)
index bfd15a694d8341e6e281a529cc5ae77d185a4274..51d86a536854b129dc44fcbc9b06ff5927e0422f 100644 (file)
@@ -140,7 +140,6 @@ private:
        void resolve(Expression &, TypeDeclaration *, bool);
 
        virtual void visit(Literal &);
-       virtual void visit(ParenthesizedExpression &);
        virtual void visit(VariableReference &);
        virtual void visit(InterfaceBlockReference &);
        virtual void visit(MemberAccess &);
index f1e9b4be99ca8a2582e7a97944c0c16666f80540..b85c45e30149cf38cfc7c8bc415124d6d3cc6eff 100644 (file)
@@ -145,13 +145,6 @@ void Formatter::visit(Literal &literal)
        append(literal.token);
 }
 
-void Formatter::visit(ParenthesizedExpression &parexpr)
-{
-       append('(');
-       parexpr.expression->visit(*this);
-       append(')');
-}
-
 void Formatter::visit(VariableReference &var)
 {
        append(var.name);
index efcde5d66f30440bfbcbe24bee9c39ce86d34c29..6bdb1ab76d054ce64d7fd250590ebc44c762f41b 100644 (file)
@@ -35,7 +35,6 @@ private:
        virtual void visit(Block &);
        void visit_expression(Expression &, const Operator *, bool);
        virtual void visit(Literal &);
-       virtual void visit(ParenthesizedExpression &);
        virtual void visit(VariableReference &);
        virtual void visit(InterfaceBlockReference &);
        virtual void visit(MemberAccess &);
index 7b034a4c671f1d854a06cfabcaad83d94859aa88..a2e3296d81b9c52ff70139a3cf91f747aed03485 100644 (file)
@@ -496,10 +496,8 @@ RefPtr<Expression> Parser::parse_expression(const Operator *outer_oper)
                        if(token=="(")
                        {
                                tokenizer.parse_token();
-                               RefPtr<ParenthesizedExpression> parexpr = create_node<ParenthesizedExpression>();
-                               parexpr->expression = parse_expression();
+                               left = parse_expression();
                                tokenizer.expect(")");
-                               left = parexpr;
                        }
                        else if(isdigit(token[0]) || token=="true" || token=="false")
                                left = parse_literal();
index bbd364c0730d7cca157376ad34bbdbd028ec1581..469ce5a602c2f22a464a5896c003c5aa209d29ef 100644 (file)
@@ -105,12 +105,6 @@ void Literal::visit(NodeVisitor &visitor)
 }
 
 
-void ParenthesizedExpression::visit(NodeVisitor &visitor)
-{
-       visitor.visit(*this);
-}
-
-
 VariableReference::VariableReference():
        declaration(0)
 { }
index b8d9c1a6e98ab8325569a78a1242a6a4a44cff00..ac876db44e2e6b0f95c9224f5df6a74333a6ce0a 100644 (file)
@@ -152,14 +152,6 @@ struct Literal: Expression
        virtual void visit(NodeVisitor &);
 };
 
-struct ParenthesizedExpression: Expression
-{
-       NodePtr<Expression> expression;
-
-       virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
-       virtual void visit(NodeVisitor &);
-};
-
 struct VariableReference: Expression
 {
        std::string name;
index 5da89f54e69b608d1202f13fd2bdbced0a787f72..fd9e9792b303cac8060d5b7b14b6f2fd74576b36 100644 (file)
@@ -21,11 +21,6 @@ void TraversingVisitor::visit(RefPtr<Expression> &expr)
        expr->visit(*this);
 }
 
-void TraversingVisitor::visit(ParenthesizedExpression &parexpr)
-{
-       visit(parexpr.expression);
-}
-
 void TraversingVisitor::visit(MemberAccess &memacc)
 {
        visit(memacc.left);
index 3b558bd195c5cf6a9f0e68d57127d1d8159aa9b0..ed2534cb31b865900e142a141632fc4f35be497a 100644 (file)
@@ -19,7 +19,6 @@ public:
 
        virtual void visit(Block &) { }
        virtual void visit(Literal &) { }
-       virtual void visit(ParenthesizedExpression &) { }
        virtual void visit(VariableReference &) { }
        virtual void visit(InterfaceBlockReference &) { }
        virtual void visit(MemberAccess &) { }
@@ -59,7 +58,6 @@ public:
        virtual void enter(Block &) { }
        virtual void visit(Block &);
        virtual void visit(RefPtr<Expression> &);
-       virtual void visit(ParenthesizedExpression &);
        virtual void visit(MemberAccess &);
        virtual void visit(Swizzle &);
        virtual void visit(UnaryExpression &);
index a99b4446f9e2a22efcd9a8615e10f88a9d955b97..0782b15a0a1bad76ed1aae2a5e2d029d20c4234f 100644 (file)
@@ -43,7 +43,7 @@ void main()
        b = b&&float(i)==f;
        int j = 1;
        i = i|1;
-       j = j<<(i%5);
+       j = j<<i%5;
        b = b||i!=j;
        ivec2 iv;
        i = i<<j;
diff --git a/tests/glsl/parentheses.glsl b/tests/glsl/parentheses.glsl
new file mode 100644 (file)
index 0000000..9899c49
--- /dev/null
@@ -0,0 +1,69 @@
+struct LightParams
+{
+       uniform vec3 ambient;
+       uniform vec3 color;
+       uniform float intensity;
+       uniform vec3 dir;
+};
+uniform LightParams light;
+uniform vec3 material_color;
+uniform mat4 mvp;
+uniform vec3 offset;
+uniform sampler2D occlusion_map;
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+layout(location=1) in vec3 normal;
+layout(location=2) in vec2 texcoord;
+void main()
+{
+       vec4 p = position+vec4(offset, 1.0);
+       gl_Position = mvp*p;
+       passthrough;
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_color;
+void main()
+{
+       float occlusion = float(texture(occlusion_map, texcoord));
+       vec3 light_color = light.color*light.intensity;
+       vec3 l = light.ambient+light_color*max(dot(light.dir, normalize(normal)), 0.0);
+       frag_color = vec4(material_color*l*occlusion, 1.0);
+}
+
+/* Expected output: vertex
+uniform mat4 mvp;
+uniform vec3 offset;
+layout(location=0) in vec4 position;
+layout(location=1) in vec3 normal;
+layout(location=2) in vec2 texcoord;
+out vec3 _vs_out_normal;
+out vec2 _vs_out_texcoord;
+void main()
+{
+       gl_Position = mvp*(position+vec4(offset, 1.0));
+       _vs_out_normal = normal;
+       _vs_out_texcoord = texcoord;
+}
+*/
+
+/* Expected output: fragment
+struct LightParams
+{
+  uniform vec3 ambient;
+  uniform vec3 color;
+  uniform float intensity;
+  uniform vec3 dir;
+};
+uniform LightParams light;
+uniform vec3 material_color;
+uniform sampler2D occlusion_map;
+layout(location=0) out vec4 frag_color;
+in vec2 _vs_out_texcoord;
+in vec3 _vs_out_normal;
+void main()
+{
+       frag_color = vec4(material_color*(light.ambient+light.color*light.intensity*max(dot(light.dir, normalize(_vs_out_normal)), 0.0))*float(texture(occlusion_map, _vs_out_texcoord)), 1.0);
+}
+*/