From: Mikko Rasa Date: Sat, 13 Mar 2021 19:30:48 +0000 (+0200) Subject: Remove the ParenthesizedExpression node type X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a4cd67f1c9f1f375bacacfbb421d40f78a22644b;p=libs%2Fgl.git Remove the ParenthesizedExpression node type Since this is a proper compiler now, it's no longer necessary to reproduce the parentheses from the input. --- diff --git a/source/glsl/debug.cpp b/source/glsl/debug.cpp index ddf1013d..308fbad7 100644 --- a/source/glsl/debug.cpp +++ b/source/glsl/debug.cpp @@ -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; diff --git a/source/glsl/debug.h b/source/glsl/debug.h index a5dae090..a0da2442 100644 --- a/source/glsl/debug.h +++ b/source/glsl/debug.h @@ -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 &); diff --git a/source/glsl/evaluate.cpp b/source/glsl/evaluate.cpp index f290002b..2b3f50a6 100644 --- a/source/glsl/evaluate.cpp +++ b/source/glsl/evaluate.cpp @@ -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) diff --git a/source/glsl/evaluate.h b/source/glsl/evaluate.h index f3d3755f..4ad26779 100644 --- a/source/glsl/evaluate.h +++ b/source/glsl/evaluate.h @@ -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 &); diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index 2ff75194..9dff1e60 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -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) diff --git a/source/glsl/generate.h b/source/glsl/generate.h index bfd15a69..51d86a53 100644 --- a/source/glsl/generate.h +++ b/source/glsl/generate.h @@ -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 &); diff --git a/source/glsl/output.cpp b/source/glsl/output.cpp index f1e9b4be..b85c45e3 100644 --- a/source/glsl/output.cpp +++ b/source/glsl/output.cpp @@ -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); diff --git a/source/glsl/output.h b/source/glsl/output.h index efcde5d6..6bdb1ab7 100644 --- a/source/glsl/output.h +++ b/source/glsl/output.h @@ -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 &); diff --git a/source/glsl/parser.cpp b/source/glsl/parser.cpp index 7b034a4c..a2e3296d 100644 --- a/source/glsl/parser.cpp +++ b/source/glsl/parser.cpp @@ -496,10 +496,8 @@ RefPtr Parser::parse_expression(const Operator *outer_oper) if(token=="(") { tokenizer.parse_token(); - RefPtr parexpr = create_node(); - parexpr->expression = parse_expression(); + left = parse_expression(); tokenizer.expect(")"); - left = parexpr; } else if(isdigit(token[0]) || token=="true" || token=="false") left = parse_literal(); diff --git a/source/glsl/syntax.cpp b/source/glsl/syntax.cpp index bbd364c0..469ce5a6 100644 --- a/source/glsl/syntax.cpp +++ b/source/glsl/syntax.cpp @@ -105,12 +105,6 @@ void Literal::visit(NodeVisitor &visitor) } -void ParenthesizedExpression::visit(NodeVisitor &visitor) -{ - visitor.visit(*this); -} - - VariableReference::VariableReference(): declaration(0) { } diff --git a/source/glsl/syntax.h b/source/glsl/syntax.h index b8d9c1a6..ac876db4 100644 --- a/source/glsl/syntax.h +++ b/source/glsl/syntax.h @@ -152,14 +152,6 @@ struct Literal: Expression virtual void visit(NodeVisitor &); }; -struct ParenthesizedExpression: Expression -{ - NodePtr expression; - - virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); } - virtual void visit(NodeVisitor &); -}; - struct VariableReference: Expression { std::string name; diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index 5da89f54..fd9e9792 100644 --- a/source/glsl/visitor.cpp +++ b/source/glsl/visitor.cpp @@ -21,11 +21,6 @@ void TraversingVisitor::visit(RefPtr &expr) expr->visit(*this); } -void TraversingVisitor::visit(ParenthesizedExpression &parexpr) -{ - visit(parexpr.expression); -} - void TraversingVisitor::visit(MemberAccess &memacc) { visit(memacc.left); diff --git a/source/glsl/visitor.h b/source/glsl/visitor.h index 3b558bd1..ed2534cb 100644 --- a/source/glsl/visitor.h +++ b/source/glsl/visitor.h @@ -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 &); - virtual void visit(ParenthesizedExpression &); virtual void visit(MemberAccess &); virtual void visit(Swizzle &); virtual void visit(UnaryExpression &); diff --git a/tests/glsl/binary_operators.glsl b/tests/glsl/binary_operators.glsl index a99b4446..0782b15a 100644 --- a/tests/glsl/binary_operators.glsl +++ b/tests/glsl/binary_operators.glsl @@ -43,7 +43,7 @@ void main() b = b&&float(i)==f; int j = 1; i = i|1; - j = j<<(i%5); + j = j<