mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 14:08:04 +00:00
Rename RelationalExpression to BinaryExpression.
Match the more common usage for the expression type. Bug: tint:37 Change-Id: Ia5d48a0444742ec4e304ea1036e499b3d7cad682 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18981 Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
@@ -17,8 +17,8 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "spirv/unified1/spirv.h"
|
||||
#include "spirv/unified1/spirv.hpp11"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/float_literal.h"
|
||||
#include "src/ast/relational_expression.h"
|
||||
#include "src/ast/scalar_constructor_expression.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/vector_type.h"
|
||||
@@ -96,8 +96,8 @@ TEST_F(BuilderTest, Constructor_Type_Dedups) {
|
||||
TEST_F(BuilderTest, Constructor_NonConst_Type_Fails) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::VectorType vec(&f32, 2);
|
||||
auto rel = std::make_unique<ast::RelationalExpression>(
|
||||
ast::Relation::kAdd,
|
||||
auto rel = std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kAdd,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
#include <memory>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/binding_decoration.h"
|
||||
#include "src/ast/builtin.h"
|
||||
#include "src/ast/builtin_decoration.h"
|
||||
#include "src/ast/decorated_variable.h"
|
||||
#include "src/ast/float_literal.h"
|
||||
#include "src/ast/location_decoration.h"
|
||||
#include "src/ast/relational_expression.h"
|
||||
#include "src/ast/scalar_constructor_expression.h"
|
||||
#include "src/ast/set_decoration.h"
|
||||
#include "src/ast/storage_class.h"
|
||||
@@ -97,13 +97,13 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
||||
)");
|
||||
}
|
||||
|
||||
// DISABLED until we have RelationalExpression Output
|
||||
// DISABLED until we have BinaryExpression Output
|
||||
TEST_F(BuilderTest, DISABLED_FunctionVar_WithNonConstantConstructor) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::VectorType vec(&f32, 2);
|
||||
|
||||
auto rel = std::make_unique<ast::RelationalExpression>(
|
||||
ast::Relation::kAdd,
|
||||
auto rel = std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kAdd,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "src/ast/array_accessor_expression.h"
|
||||
#include "src/ast/as_expression.h"
|
||||
#include "src/ast/assignment_statement.h"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/binding_decoration.h"
|
||||
#include "src/ast/bool_literal.h"
|
||||
#include "src/ast/break_statement.h"
|
||||
@@ -39,7 +40,6 @@
|
||||
#include "src/ast/loop_statement.h"
|
||||
#include "src/ast/member_accessor_expression.h"
|
||||
#include "src/ast/regardless_statement.h"
|
||||
#include "src/ast/relational_expression.h"
|
||||
#include "src/ast/return_statement.h"
|
||||
#include "src/ast/scalar_constructor_expression.h"
|
||||
#include "src/ast/set_decoration.h"
|
||||
@@ -149,6 +149,9 @@ bool GeneratorImpl::EmitExpression(ast::Expression* expr) {
|
||||
if (expr->IsAs()) {
|
||||
return EmitAs(expr->AsAs());
|
||||
}
|
||||
if (expr->IsBinary()) {
|
||||
return EmitBinary(expr->AsBinary());
|
||||
}
|
||||
if (expr->IsCall()) {
|
||||
return EmitCall(expr->AsCall());
|
||||
}
|
||||
@@ -164,9 +167,6 @@ bool GeneratorImpl::EmitExpression(ast::Expression* expr) {
|
||||
if (expr->IsMemberAccessor()) {
|
||||
return EmitMemberAccessor(expr->AsMemberAccessor());
|
||||
}
|
||||
if (expr->IsRelational()) {
|
||||
return EmitRelational(expr->AsRelational());
|
||||
}
|
||||
if (expr->IsUnaryDerivative()) {
|
||||
return EmitUnaryDerivative(expr->AsUnaryDerivative());
|
||||
}
|
||||
@@ -518,7 +518,7 @@ bool GeneratorImpl::EmitVariableDecorations(ast::DecoratedVariable* var) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitRelational(ast::RelationalExpression* expr) {
|
||||
bool GeneratorImpl::EmitBinary(ast::BinaryExpression* expr) {
|
||||
out_ << "(";
|
||||
|
||||
if (!EmitExpression(expr->lhs())) {
|
||||
@@ -526,66 +526,66 @@ bool GeneratorImpl::EmitRelational(ast::RelationalExpression* expr) {
|
||||
}
|
||||
out_ << " ";
|
||||
|
||||
switch (expr->relation()) {
|
||||
case ast::Relation::kAnd:
|
||||
switch (expr->op()) {
|
||||
case ast::BinaryOp::kAnd:
|
||||
out_ << "&";
|
||||
break;
|
||||
case ast::Relation::kOr:
|
||||
case ast::BinaryOp::kOr:
|
||||
out_ << "|";
|
||||
break;
|
||||
case ast::Relation::kXor:
|
||||
case ast::BinaryOp::kXor:
|
||||
out_ << "^";
|
||||
break;
|
||||
case ast::Relation::kLogicalAnd:
|
||||
case ast::BinaryOp::kLogicalAnd:
|
||||
out_ << "&&";
|
||||
break;
|
||||
case ast::Relation::kLogicalOr:
|
||||
case ast::BinaryOp::kLogicalOr:
|
||||
out_ << "||";
|
||||
break;
|
||||
case ast::Relation::kEqual:
|
||||
case ast::BinaryOp::kEqual:
|
||||
out_ << "==";
|
||||
break;
|
||||
case ast::Relation::kNotEqual:
|
||||
case ast::BinaryOp::kNotEqual:
|
||||
out_ << "!=";
|
||||
break;
|
||||
case ast::Relation::kLessThan:
|
||||
case ast::BinaryOp::kLessThan:
|
||||
out_ << "<";
|
||||
break;
|
||||
case ast::Relation::kGreaterThan:
|
||||
case ast::BinaryOp::kGreaterThan:
|
||||
out_ << ">";
|
||||
break;
|
||||
case ast::Relation::kLessThanEqual:
|
||||
case ast::BinaryOp::kLessThanEqual:
|
||||
out_ << "<=";
|
||||
break;
|
||||
case ast::Relation::kGreaterThanEqual:
|
||||
case ast::BinaryOp::kGreaterThanEqual:
|
||||
out_ << ">=";
|
||||
break;
|
||||
case ast::Relation::kShiftLeft:
|
||||
case ast::BinaryOp::kShiftLeft:
|
||||
out_ << "<<";
|
||||
break;
|
||||
case ast::Relation::kShiftRight:
|
||||
case ast::BinaryOp::kShiftRight:
|
||||
out_ << ">>";
|
||||
break;
|
||||
case ast::Relation::kShiftRightArith:
|
||||
case ast::BinaryOp::kShiftRightArith:
|
||||
out_ << ">>>";
|
||||
break;
|
||||
case ast::Relation::kAdd:
|
||||
case ast::BinaryOp::kAdd:
|
||||
out_ << "+";
|
||||
break;
|
||||
case ast::Relation::kSubtract:
|
||||
case ast::BinaryOp::kSubtract:
|
||||
out_ << "-";
|
||||
break;
|
||||
case ast::Relation::kMultiply:
|
||||
case ast::BinaryOp::kMultiply:
|
||||
out_ << "*";
|
||||
break;
|
||||
case ast::Relation::kDivide:
|
||||
case ast::BinaryOp::kDivide:
|
||||
out_ << "/";
|
||||
break;
|
||||
case ast::Relation::kModulo:
|
||||
case ast::BinaryOp::kModulo:
|
||||
out_ << "%";
|
||||
break;
|
||||
case ast::Relation::kNone:
|
||||
error_ = "missing relation type";
|
||||
case ast::BinaryOp::kNone:
|
||||
error_ = "missing binary operation type";
|
||||
return false;
|
||||
}
|
||||
out_ << " ";
|
||||
|
||||
@@ -82,6 +82,10 @@ class GeneratorImpl {
|
||||
/// @param stmt the statement to emit
|
||||
/// @returns true if the statement was emitted successfully
|
||||
bool EmitAssign(ast::AssignmentStatement* stmt);
|
||||
/// Handles generating a binary expression
|
||||
/// @param expr the binary expression
|
||||
/// @returns true if the expression was emitted, false otherwise
|
||||
bool EmitBinary(ast::BinaryExpression* expr);
|
||||
/// Handles a break statement
|
||||
/// @param stmt the statement to emit
|
||||
/// @returns true if the statement was emitted successfully
|
||||
@@ -166,10 +170,6 @@ class GeneratorImpl {
|
||||
/// @param stmt the statement to emit
|
||||
/// @returns true if the statement was successfully emitted
|
||||
bool EmitRegardless(ast::RegardlessStatement* stmt);
|
||||
/// Handles generating a relational expression
|
||||
/// @param expr the relational expression
|
||||
/// @returns true if the expression was emitted, false otherwise
|
||||
bool EmitRelational(ast::RelationalExpression* expr);
|
||||
/// Handles return statements
|
||||
/// @param stmt the statement to emit
|
||||
/// @returns true if the statement was successfully emitted
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
#include <memory>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/identifier_expression.h"
|
||||
#include "src/ast/relational_expression.h"
|
||||
#include "src/writer/wgsl/generator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
@@ -24,23 +24,22 @@ namespace writer {
|
||||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
struct RelationData {
|
||||
struct BinaryData {
|
||||
const char* result;
|
||||
ast::Relation relation;
|
||||
ast::BinaryOp op;
|
||||
};
|
||||
inline std::ostream& operator<<(std::ostream& out, RelationData data) {
|
||||
out << data.relation;
|
||||
inline std::ostream& operator<<(std::ostream& out, BinaryData data) {
|
||||
out << data.op;
|
||||
return out;
|
||||
}
|
||||
using RelationTest = testing::TestWithParam<RelationData>;
|
||||
TEST_P(RelationTest, Emit) {
|
||||
using BinaryTest = testing::TestWithParam<BinaryData>;
|
||||
TEST_P(BinaryTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
auto left = std::make_unique<ast::IdentifierExpression>("left");
|
||||
auto right = std::make_unique<ast::IdentifierExpression>("right");
|
||||
|
||||
ast::RelationalExpression expr(params.relation, std::move(left),
|
||||
std::move(right));
|
||||
ast::BinaryExpression expr(params.op, std::move(left), std::move(right));
|
||||
|
||||
GeneratorImpl g;
|
||||
ASSERT_TRUE(g.EmitExpression(&expr)) << g.error();
|
||||
@@ -48,27 +47,27 @@ TEST_P(RelationTest, Emit) {
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
GeneratorImplTest,
|
||||
RelationTest,
|
||||
BinaryTest,
|
||||
testing::Values(
|
||||
RelationData{"(left & right)", ast::Relation::kAnd},
|
||||
RelationData{"(left | right)", ast::Relation::kOr},
|
||||
RelationData{"(left ^ right)", ast::Relation::kXor},
|
||||
RelationData{"(left && right)", ast::Relation::kLogicalAnd},
|
||||
RelationData{"(left || right)", ast::Relation::kLogicalOr},
|
||||
RelationData{"(left == right)", ast::Relation::kEqual},
|
||||
RelationData{"(left != right)", ast::Relation::kNotEqual},
|
||||
RelationData{"(left < right)", ast::Relation::kLessThan},
|
||||
RelationData{"(left > right)", ast::Relation::kGreaterThan},
|
||||
RelationData{"(left <= right)", ast::Relation::kLessThanEqual},
|
||||
RelationData{"(left >= right)", ast::Relation::kGreaterThanEqual},
|
||||
RelationData{"(left << right)", ast::Relation::kShiftLeft},
|
||||
RelationData{"(left >> right)", ast::Relation::kShiftRight},
|
||||
RelationData{"(left >>> right)", ast::Relation::kShiftRightArith},
|
||||
RelationData{"(left + right)", ast::Relation::kAdd},
|
||||
RelationData{"(left - right)", ast::Relation::kSubtract},
|
||||
RelationData{"(left * right)", ast::Relation::kMultiply},
|
||||
RelationData{"(left / right)", ast::Relation::kDivide},
|
||||
RelationData{"(left % right)", ast::Relation::kModulo}));
|
||||
BinaryData{"(left & right)", ast::BinaryOp::kAnd},
|
||||
BinaryData{"(left | right)", ast::BinaryOp::kOr},
|
||||
BinaryData{"(left ^ right)", ast::BinaryOp::kXor},
|
||||
BinaryData{"(left && right)", ast::BinaryOp::kLogicalAnd},
|
||||
BinaryData{"(left || right)", ast::BinaryOp::kLogicalOr},
|
||||
BinaryData{"(left == right)", ast::BinaryOp::kEqual},
|
||||
BinaryData{"(left != right)", ast::BinaryOp::kNotEqual},
|
||||
BinaryData{"(left < right)", ast::BinaryOp::kLessThan},
|
||||
BinaryData{"(left > right)", ast::BinaryOp::kGreaterThan},
|
||||
BinaryData{"(left <= right)", ast::BinaryOp::kLessThanEqual},
|
||||
BinaryData{"(left >= right)", ast::BinaryOp::kGreaterThanEqual},
|
||||
BinaryData{"(left << right)", ast::BinaryOp::kShiftLeft},
|
||||
BinaryData{"(left >> right)", ast::BinaryOp::kShiftRight},
|
||||
BinaryData{"(left >>> right)", ast::BinaryOp::kShiftRightArith},
|
||||
BinaryData{"(left + right)", ast::BinaryOp::kAdd},
|
||||
BinaryData{"(left - right)", ast::BinaryOp::kSubtract},
|
||||
BinaryData{"(left * right)", ast::BinaryOp::kMultiply},
|
||||
BinaryData{"(left / right)", ast::BinaryOp::kDivide},
|
||||
BinaryData{"(left % right)", ast::BinaryOp::kModulo}));
|
||||
|
||||
} // namespace
|
||||
} // namespace wgsl
|
||||
|
||||
Reference in New Issue
Block a user