Replace Expression::(Is|As)* with Castable
Change-Id: I6ab98ed8b198f1b3b42ce1f09a6c4f992d65fe95 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34316 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
1d8098ae94
commit
d6ae990811
|
@ -33,10 +33,6 @@ ArrayAccessorExpression::ArrayAccessorExpression(ArrayAccessorExpression&&) =
|
||||||
|
|
||||||
ArrayAccessorExpression::~ArrayAccessorExpression() = default;
|
ArrayAccessorExpression::~ArrayAccessorExpression() = default;
|
||||||
|
|
||||||
bool ArrayAccessorExpression::IsArrayAccessor() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ArrayAccessorExpression::IsValid() const {
|
bool ArrayAccessorExpression::IsValid() const {
|
||||||
if (array_ == nullptr || !array_->IsValid())
|
if (array_ == nullptr || !array_->IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -57,9 +57,6 @@ class ArrayAccessorExpression
|
||||||
/// @returns the index expression
|
/// @returns the index expression
|
||||||
Expression* idx_expr() const { return idx_expr_; }
|
Expression* idx_expr() const { return idx_expr_; }
|
||||||
|
|
||||||
/// @returns true if this is an array accessor expression
|
|
||||||
bool IsArrayAccessor() const override;
|
|
||||||
|
|
||||||
/// @returns true if the node is valid
|
/// @returns true if the node is valid
|
||||||
bool IsValid() const override;
|
bool IsValid() const override;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
|
||||||
|
|
||||||
TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) {
|
TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) {
|
||||||
ArrayAccessorExpression exp;
|
ArrayAccessorExpression exp;
|
||||||
EXPECT_TRUE(exp.IsArrayAccessor());
|
EXPECT_TRUE(exp.Is<ast::ArrayAccessorExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ArrayAccessorExpressionTest, IsValid) {
|
TEST_F(ArrayAccessorExpressionTest, IsValid) {
|
||||||
|
|
|
@ -34,10 +34,6 @@ BinaryExpression::BinaryExpression(BinaryExpression&&) = default;
|
||||||
|
|
||||||
BinaryExpression::~BinaryExpression() = default;
|
BinaryExpression::~BinaryExpression() = default;
|
||||||
|
|
||||||
bool BinaryExpression::IsBinary() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BinaryExpression::IsValid() const {
|
bool BinaryExpression::IsValid() const {
|
||||||
if (lhs_ == nullptr || !lhs_->IsValid()) {
|
if (lhs_ == nullptr || !lhs_->IsValid()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -125,9 +125,6 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
|
||||||
/// @returns the right side expression
|
/// @returns the right side expression
|
||||||
Expression* rhs() const { return rhs_; }
|
Expression* rhs() const { return rhs_; }
|
||||||
|
|
||||||
/// @returns true if this is a op expression
|
|
||||||
bool IsBinary() const override;
|
|
||||||
|
|
||||||
/// @returns true if the node is valid
|
/// @returns true if the node is valid
|
||||||
bool IsValid() const override;
|
bool IsValid() const override;
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) {
|
||||||
|
|
||||||
TEST_F(BinaryExpressionTest, IsBinaryal) {
|
TEST_F(BinaryExpressionTest, IsBinaryal) {
|
||||||
BinaryExpression r;
|
BinaryExpression r;
|
||||||
EXPECT_TRUE(r.IsBinary());
|
EXPECT_TRUE(r.Is<ast::BinaryExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BinaryExpressionTest, IsValid) {
|
TEST_F(BinaryExpressionTest, IsValid) {
|
||||||
|
|
|
@ -30,10 +30,6 @@ BitcastExpression::BitcastExpression(const Source& source,
|
||||||
BitcastExpression::BitcastExpression(BitcastExpression&&) = default;
|
BitcastExpression::BitcastExpression(BitcastExpression&&) = default;
|
||||||
BitcastExpression::~BitcastExpression() = default;
|
BitcastExpression::~BitcastExpression() = default;
|
||||||
|
|
||||||
bool BitcastExpression::IsBitcast() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BitcastExpression::IsValid() const {
|
bool BitcastExpression::IsValid() const {
|
||||||
if (expr_ == nullptr || !expr_->IsValid())
|
if (expr_ == nullptr || !expr_->IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -55,9 +55,6 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
|
||||||
/// @returns the expression
|
/// @returns the expression
|
||||||
Expression* expr() const { return expr_; }
|
Expression* expr() const { return expr_; }
|
||||||
|
|
||||||
/// @returns true if this is a bitcast expression
|
|
||||||
bool IsBitcast() const override;
|
|
||||||
|
|
||||||
/// @returns true if the node is valid
|
/// @returns true if the node is valid
|
||||||
bool IsValid() const override;
|
bool IsValid() const override;
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ TEST_F(BitcastExpressionTest, CreateWithSource) {
|
||||||
|
|
||||||
TEST_F(BitcastExpressionTest, IsBitcast) {
|
TEST_F(BitcastExpressionTest, IsBitcast) {
|
||||||
BitcastExpression exp;
|
BitcastExpression exp;
|
||||||
EXPECT_TRUE(exp.IsBitcast());
|
EXPECT_TRUE(exp.Is<ast::BitcastExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BitcastExpressionTest, IsValid) {
|
TEST_F(BitcastExpressionTest, IsValid) {
|
||||||
|
|
|
@ -31,10 +31,6 @@ CallExpression::CallExpression(CallExpression&&) = default;
|
||||||
|
|
||||||
CallExpression::~CallExpression() = default;
|
CallExpression::~CallExpression() = default;
|
||||||
|
|
||||||
bool CallExpression::IsCall() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CallExpression::IsValid() const {
|
bool CallExpression::IsValid() const {
|
||||||
if (func_ == nullptr || !func_->IsValid())
|
if (func_ == nullptr || !func_->IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -54,9 +54,6 @@ class CallExpression : public Castable<CallExpression, Expression> {
|
||||||
/// @returns the parameters
|
/// @returns the parameters
|
||||||
const ExpressionList& params() const { return params_; }
|
const ExpressionList& params() const { return params_; }
|
||||||
|
|
||||||
/// @returns true if this is a call expression
|
|
||||||
bool IsCall() const override;
|
|
||||||
|
|
||||||
/// @returns true if the node is valid
|
/// @returns true if the node is valid
|
||||||
bool IsValid() const override;
|
bool IsValid() const override;
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ TEST_F(CallExpressionTest, Creation_WithSource) {
|
||||||
TEST_F(CallExpressionTest, IsCall) {
|
TEST_F(CallExpressionTest, IsCall) {
|
||||||
auto* func = create<IdentifierExpression>("func");
|
auto* func = create<IdentifierExpression>("func");
|
||||||
CallExpression stmt(func, {});
|
CallExpression stmt(func, {});
|
||||||
EXPECT_TRUE(stmt.IsCall());
|
EXPECT_TRUE(stmt.Is<ast::CallExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CallExpressionTest, IsValid) {
|
TEST_F(CallExpressionTest, IsValid) {
|
||||||
|
|
|
@ -31,10 +31,6 @@ ConstructorExpression::ConstructorExpression(ConstructorExpression&&) = default;
|
||||||
ConstructorExpression::ConstructorExpression(const Source& source)
|
ConstructorExpression::ConstructorExpression(const Source& source)
|
||||||
: Base(source) {}
|
: Base(source) {}
|
||||||
|
|
||||||
bool ConstructorExpression::IsConstructor() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ConstructorExpression::IsScalarConstructor() const {
|
bool ConstructorExpression::IsScalarConstructor() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,6 @@ class ConstructorExpression
|
||||||
public:
|
public:
|
||||||
~ConstructorExpression() override;
|
~ConstructorExpression() override;
|
||||||
|
|
||||||
/// @returns true if this is an constructor expression
|
|
||||||
bool IsConstructor() const override;
|
|
||||||
|
|
||||||
/// @returns true if this is a scalar constructor
|
/// @returns true if this is a scalar constructor
|
||||||
virtual bool IsScalarConstructor() const;
|
virtual bool IsScalarConstructor() const;
|
||||||
/// @returns true if this is a type constructor
|
/// @returns true if this is a type constructor
|
||||||
|
|
|
@ -14,18 +14,6 @@
|
||||||
|
|
||||||
#include "src/ast/expression.h"
|
#include "src/ast/expression.h"
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "src/ast/array_accessor_expression.h"
|
|
||||||
#include "src/ast/binary_expression.h"
|
|
||||||
#include "src/ast/bitcast_expression.h"
|
|
||||||
#include "src/ast/call_expression.h"
|
|
||||||
#include "src/ast/constructor_expression.h"
|
|
||||||
#include "src/ast/identifier_expression.h"
|
|
||||||
#include "src/ast/member_accessor_expression.h"
|
|
||||||
#include "src/ast/type/alias_type.h"
|
|
||||||
#include "src/ast/unary_op_expression.h"
|
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
|
@ -42,116 +30,5 @@ void Expression::set_result_type(type::Type* type) {
|
||||||
result_type_ = type->UnwrapIfNeeded();
|
result_type_ = type->UnwrapIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Expression::IsArrayAccessor() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Expression::IsBitcast() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Expression::IsCall() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Expression::IsIdentifier() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Expression::IsConstructor() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Expression::IsMemberAccessor() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Expression::IsBinary() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Expression::IsUnaryOp() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const ArrayAccessorExpression* Expression::AsArrayAccessor() const {
|
|
||||||
assert(IsArrayAccessor());
|
|
||||||
return static_cast<const ArrayAccessorExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const BitcastExpression* Expression::AsBitcast() const {
|
|
||||||
assert(IsBitcast());
|
|
||||||
return static_cast<const BitcastExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const BinaryExpression* Expression::AsBinary() const {
|
|
||||||
assert(IsBinary());
|
|
||||||
return static_cast<const BinaryExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const CallExpression* Expression::AsCall() const {
|
|
||||||
assert(IsCall());
|
|
||||||
return static_cast<const CallExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const ConstructorExpression* Expression::AsConstructor() const {
|
|
||||||
assert(IsConstructor());
|
|
||||||
return static_cast<const ConstructorExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const IdentifierExpression* Expression::AsIdentifier() const {
|
|
||||||
assert(IsIdentifier());
|
|
||||||
return static_cast<const IdentifierExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const MemberAccessorExpression* Expression::AsMemberAccessor() const {
|
|
||||||
assert(IsMemberAccessor());
|
|
||||||
return static_cast<const MemberAccessorExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const UnaryOpExpression* Expression::AsUnaryOp() const {
|
|
||||||
assert(IsUnaryOp());
|
|
||||||
return static_cast<const UnaryOpExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayAccessorExpression* Expression::AsArrayAccessor() {
|
|
||||||
assert(IsArrayAccessor());
|
|
||||||
return static_cast<ArrayAccessorExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
BitcastExpression* Expression::AsBitcast() {
|
|
||||||
assert(IsBitcast());
|
|
||||||
return static_cast<BitcastExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
BinaryExpression* Expression::AsBinary() {
|
|
||||||
assert(IsBinary());
|
|
||||||
return static_cast<BinaryExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
CallExpression* Expression::AsCall() {
|
|
||||||
assert(IsCall());
|
|
||||||
return static_cast<CallExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConstructorExpression* Expression::AsConstructor() {
|
|
||||||
assert(IsConstructor());
|
|
||||||
return static_cast<ConstructorExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
IdentifierExpression* Expression::AsIdentifier() {
|
|
||||||
assert(IsIdentifier());
|
|
||||||
return static_cast<IdentifierExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
MemberAccessorExpression* Expression::AsMemberAccessor() {
|
|
||||||
assert(IsMemberAccessor());
|
|
||||||
return static_cast<MemberAccessorExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
UnaryOpExpression* Expression::AsUnaryOp() {
|
|
||||||
assert(IsUnaryOp());
|
|
||||||
return static_cast<UnaryOpExpression*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
|
@ -25,15 +25,6 @@
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
class ArrayAccessorExpression;
|
|
||||||
class BinaryExpression;
|
|
||||||
class BitcastExpression;
|
|
||||||
class CallExpression;
|
|
||||||
class IdentifierExpression;
|
|
||||||
class ConstructorExpression;
|
|
||||||
class MemberAccessorExpression;
|
|
||||||
class UnaryOpExpression;
|
|
||||||
|
|
||||||
/// Base expression class
|
/// Base expression class
|
||||||
class Expression : public Castable<Expression, Node> {
|
class Expression : public Castable<Expression, Node> {
|
||||||
public:
|
public:
|
||||||
|
@ -51,57 +42,6 @@ class Expression : public Castable<Expression, Node> {
|
||||||
return result_type_ ? result_type_->type_name() : "not set";
|
return result_type_ ? result_type_->type_name() : "not set";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @returns true if this is an array accessor expression
|
|
||||||
virtual bool IsArrayAccessor() const;
|
|
||||||
/// @returns true if this is a bitcast expression
|
|
||||||
virtual bool IsBitcast() const;
|
|
||||||
/// @returns true if this is a call expression
|
|
||||||
virtual bool IsCall() const;
|
|
||||||
/// @returns true if this is an identifier expression
|
|
||||||
virtual bool IsIdentifier() const;
|
|
||||||
/// @returns true if this is an constructor expression
|
|
||||||
virtual bool IsConstructor() const;
|
|
||||||
/// @returns true if this is a member accessor expression
|
|
||||||
virtual bool IsMemberAccessor() const;
|
|
||||||
/// @returns true if this is a binary expression
|
|
||||||
virtual bool IsBinary() const;
|
|
||||||
/// @returns true if this is a unary op expression
|
|
||||||
virtual bool IsUnaryOp() const;
|
|
||||||
|
|
||||||
/// @returns the expression as an array accessor
|
|
||||||
const ArrayAccessorExpression* AsArrayAccessor() const;
|
|
||||||
/// @returns the expression as a bitcast
|
|
||||||
const BitcastExpression* AsBitcast() const;
|
|
||||||
/// @returns the expression as a call
|
|
||||||
const CallExpression* AsCall() const;
|
|
||||||
/// @returns the expression as an identifier
|
|
||||||
const IdentifierExpression* AsIdentifier() const;
|
|
||||||
/// @returns the expression as an constructor
|
|
||||||
const ConstructorExpression* AsConstructor() const;
|
|
||||||
/// @returns the expression as a member accessor
|
|
||||||
const MemberAccessorExpression* AsMemberAccessor() const;
|
|
||||||
/// @returns the expression as a binary expression
|
|
||||||
const BinaryExpression* AsBinary() const;
|
|
||||||
/// @returns the expression as a unary op expression
|
|
||||||
const UnaryOpExpression* AsUnaryOp() const;
|
|
||||||
|
|
||||||
/// @returns the expression as an array accessor
|
|
||||||
ArrayAccessorExpression* AsArrayAccessor();
|
|
||||||
/// @returns the expression as a bitcast
|
|
||||||
BitcastExpression* AsBitcast();
|
|
||||||
/// @returns the expression as a call
|
|
||||||
CallExpression* AsCall();
|
|
||||||
/// @returns the expression as an identifier
|
|
||||||
IdentifierExpression* AsIdentifier();
|
|
||||||
/// @returns the expression as an constructor
|
|
||||||
ConstructorExpression* AsConstructor();
|
|
||||||
/// @returns the expression as a member accessor
|
|
||||||
MemberAccessorExpression* AsMemberAccessor();
|
|
||||||
/// @returns the expression as a binary expression
|
|
||||||
BinaryExpression* AsBinary();
|
|
||||||
/// @returns the expression as a unary op expression
|
|
||||||
UnaryOpExpression* AsUnaryOp();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
Expression();
|
Expression();
|
||||||
|
|
|
@ -28,10 +28,6 @@ IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;
|
||||||
|
|
||||||
IdentifierExpression::~IdentifierExpression() = default;
|
IdentifierExpression::~IdentifierExpression() = default;
|
||||||
|
|
||||||
bool IdentifierExpression::IsIdentifier() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IdentifierExpression::IsValid() const {
|
bool IdentifierExpression::IsValid() const {
|
||||||
return !name_.empty();
|
return !name_.empty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,9 +61,6 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
|
||||||
/// @returns true if this identifier is for an intrinsic
|
/// @returns true if this identifier is for an intrinsic
|
||||||
bool IsIntrinsic() const { return intrinsic_ != Intrinsic::kNone; }
|
bool IsIntrinsic() const { return intrinsic_ != Intrinsic::kNone; }
|
||||||
|
|
||||||
/// @returns true if this is an identifier expression
|
|
||||||
bool IsIdentifier() const override;
|
|
||||||
|
|
||||||
/// @returns true if the node is valid
|
/// @returns true if the node is valid
|
||||||
bool IsValid() const override;
|
bool IsValid() const override;
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ TEST_F(IdentifierExpressionTest, Creation_WithSource) {
|
||||||
|
|
||||||
TEST_F(IdentifierExpressionTest, IsIdentifier) {
|
TEST_F(IdentifierExpressionTest, IsIdentifier) {
|
||||||
IdentifierExpression i("ident");
|
IdentifierExpression i("ident");
|
||||||
EXPECT_TRUE(i.IsIdentifier());
|
EXPECT_TRUE(i.Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(IdentifierExpressionTest, IsValid) {
|
TEST_F(IdentifierExpressionTest, IsValid) {
|
||||||
|
|
|
@ -33,10 +33,6 @@ MemberAccessorExpression::MemberAccessorExpression(MemberAccessorExpression&&) =
|
||||||
|
|
||||||
MemberAccessorExpression::~MemberAccessorExpression() = default;
|
MemberAccessorExpression::~MemberAccessorExpression() = default;
|
||||||
|
|
||||||
bool MemberAccessorExpression::IsMemberAccessor() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MemberAccessorExpression::IsValid() const {
|
bool MemberAccessorExpression::IsValid() const {
|
||||||
if (struct_ == nullptr || !struct_->IsValid()) {
|
if (struct_ == nullptr || !struct_->IsValid()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -59,9 +59,6 @@ class MemberAccessorExpression
|
||||||
/// @returns the member expression
|
/// @returns the member expression
|
||||||
IdentifierExpression* member() const { return member_; }
|
IdentifierExpression* member() const { return member_; }
|
||||||
|
|
||||||
/// @returns true if this is a member accessor expression
|
|
||||||
bool IsMemberAccessor() const override;
|
|
||||||
|
|
||||||
/// @returns true if the node is valid
|
/// @returns true if the node is valid
|
||||||
bool IsValid() const override;
|
bool IsValid() const override;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ TEST_F(MemberAccessorExpressionTest, Creation_WithSource) {
|
||||||
|
|
||||||
TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) {
|
TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) {
|
||||||
MemberAccessorExpression stmt;
|
MemberAccessorExpression stmt;
|
||||||
EXPECT_TRUE(stmt.IsMemberAccessor());
|
EXPECT_TRUE(stmt.Is<ast::MemberAccessorExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MemberAccessorExpressionTest, IsValid) {
|
TEST_F(MemberAccessorExpressionTest, IsValid) {
|
||||||
|
|
|
@ -31,10 +31,6 @@ UnaryOpExpression::UnaryOpExpression(UnaryOpExpression&&) = default;
|
||||||
|
|
||||||
UnaryOpExpression::~UnaryOpExpression() = default;
|
UnaryOpExpression::~UnaryOpExpression() = default;
|
||||||
|
|
||||||
bool UnaryOpExpression::IsUnaryOp() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UnaryOpExpression::IsValid() const {
|
bool UnaryOpExpression::IsValid() const {
|
||||||
return expr_ != nullptr && expr_->IsValid();
|
return expr_ != nullptr && expr_->IsValid();
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,9 +55,6 @@ class UnaryOpExpression : public Castable<UnaryOpExpression, Expression> {
|
||||||
/// @returns the expression
|
/// @returns the expression
|
||||||
Expression* expr() const { return expr_; }
|
Expression* expr() const { return expr_; }
|
||||||
|
|
||||||
/// @returns true if this is an as expression
|
|
||||||
bool IsUnaryOp() const override;
|
|
||||||
|
|
||||||
/// @returns true if the node is valid
|
/// @returns true if the node is valid
|
||||||
bool IsValid() const override;
|
bool IsValid() const override;
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
|
||||||
|
|
||||||
TEST_F(UnaryOpExpressionTest, IsUnaryOp) {
|
TEST_F(UnaryOpExpressionTest, IsUnaryOp) {
|
||||||
UnaryOpExpression u;
|
UnaryOpExpression u;
|
||||||
EXPECT_TRUE(u.IsUnaryOp());
|
EXPECT_TRUE(u.Is<ast::UnaryOpExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UnaryOpExpressionTest, IsValid) {
|
TEST_F(UnaryOpExpressionTest, IsValid) {
|
||||||
|
|
|
@ -124,13 +124,13 @@ std::map<uint32_t, Scalar> Inspector::GetConstantIDs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* expression = var->constructor();
|
auto* expression = var->constructor();
|
||||||
if (!expression->IsConstructor()) {
|
if (!expression->Is<ast::ConstructorExpression>()) {
|
||||||
// This is invalid WGSL, but handling gracefully.
|
// This is invalid WGSL, but handling gracefully.
|
||||||
result[constant_id] = Scalar();
|
result[constant_id] = Scalar();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* constructor = expression->AsConstructor();
|
auto* constructor = expression->As<ast::ConstructorExpression>();
|
||||||
if (!constructor->IsScalarConstructor()) {
|
if (!constructor->IsScalarConstructor()) {
|
||||||
// This is invalid WGSL, but handling gracefully.
|
// This is invalid WGSL, but handling gracefully.
|
||||||
result[constant_id] = Scalar();
|
result[constant_id] = Scalar();
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "source/opt/type_manager.h"
|
#include "source/opt/type_manager.h"
|
||||||
#include "src/ast/case_statement.h"
|
#include "src/ast/case_statement.h"
|
||||||
#include "src/ast/expression.h"
|
#include "src/ast/expression.h"
|
||||||
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/module.h"
|
#include "src/ast/module.h"
|
||||||
#include "src/ast/statement.h"
|
#include "src/ast/statement.h"
|
||||||
#include "src/ast/storage_class.h"
|
#include "src/ast/storage_class.h"
|
||||||
|
|
|
@ -33,17 +33,17 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kAdd, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kAdd, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -56,17 +56,17 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kSubtract, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kSubtract, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ TEST_F(ParserImplTest, AdditiveExpression_NoOr_ReturnsLHS) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -33,17 +33,17 @@ TEST_F(ParserImplTest, AndExpression_Parses) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kAnd, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kAnd, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ TEST_F(ParserImplTest, AndExpression_NoOr_ReturnsLHS) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/array_accessor_expression.h"
|
#include "src/ast/array_accessor_expression.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
#include "src/ast/sint_literal.h"
|
#include "src/ast/sint_literal.h"
|
||||||
|
@ -33,7 +34,7 @@ TEST_F(ParserImplTest, ArgumentExpressionList_Parses) {
|
||||||
ASSERT_FALSE(e.errored);
|
ASSERT_FALSE(e.errored);
|
||||||
|
|
||||||
ASSERT_EQ(e.value.size(), 1u);
|
ASSERT_EQ(e.value.size(), 1u);
|
||||||
ASSERT_TRUE(e.value[0]->IsIdentifier());
|
ASSERT_TRUE(e.value[0]->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ArgumentExpressionList_ParsesMultiple) {
|
TEST_F(ParserImplTest, ArgumentExpressionList_ParsesMultiple) {
|
||||||
|
@ -43,9 +44,9 @@ TEST_F(ParserImplTest, ArgumentExpressionList_ParsesMultiple) {
|
||||||
ASSERT_FALSE(e.errored);
|
ASSERT_FALSE(e.errored);
|
||||||
|
|
||||||
ASSERT_EQ(e.value.size(), 3u);
|
ASSERT_EQ(e.value.size(), 3u);
|
||||||
ASSERT_TRUE(e.value[0]->IsIdentifier());
|
ASSERT_TRUE(e.value[0]->Is<ast::IdentifierExpression>());
|
||||||
ASSERT_TRUE(e.value[1]->IsConstructor());
|
ASSERT_TRUE(e.value[1]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(e.value[2]->IsBinary());
|
ASSERT_TRUE(e.value[2]->Is<ast::BinaryExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ArgumentExpressionList_HandlesMissingExpression) {
|
TEST_F(ParserImplTest, ArgumentExpressionList_HandlesMissingExpression) {
|
||||||
|
|
|
@ -40,14 +40,14 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
|
||||||
ASSERT_NE(e->lhs(), nullptr);
|
ASSERT_NE(e->lhs(), nullptr);
|
||||||
ASSERT_NE(e->rhs(), nullptr);
|
ASSERT_NE(e->rhs(), nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->lhs()->IsIdentifier());
|
ASSERT_TRUE(e->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = e->lhs()->AsIdentifier();
|
auto* ident = e->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(e->rhs()->IsConstructor());
|
ASSERT_TRUE(e->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(e->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(e->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* init = e->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = e->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_NE(init->literal(), nullptr);
|
ASSERT_NE(init->literal(), nullptr);
|
||||||
ASSERT_TRUE(init->literal()->IsSint());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
EXPECT_EQ(init->literal()->AsSint()->value(), 123);
|
EXPECT_EQ(init->literal()->AsSint()->value(), 123);
|
||||||
|
@ -65,45 +65,45 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
|
||||||
ASSERT_NE(e->lhs(), nullptr);
|
ASSERT_NE(e->lhs(), nullptr);
|
||||||
ASSERT_NE(e->rhs(), nullptr);
|
ASSERT_NE(e->rhs(), nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->rhs()->IsConstructor());
|
ASSERT_TRUE(e->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(e->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(e->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = e->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = e->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_NE(init->literal(), nullptr);
|
ASSERT_NE(init->literal(), nullptr);
|
||||||
ASSERT_TRUE(init->literal()->IsSint());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
EXPECT_EQ(init->literal()->AsSint()->value(), 123);
|
EXPECT_EQ(init->literal()->AsSint()->value(), 123);
|
||||||
|
|
||||||
ASSERT_TRUE(e->lhs()->IsMemberAccessor());
|
ASSERT_TRUE(e->lhs()->Is<ast::MemberAccessorExpression>());
|
||||||
auto* mem = e->lhs()->AsMemberAccessor();
|
auto* mem = e->lhs()->As<ast::MemberAccessorExpression>();
|
||||||
|
|
||||||
ASSERT_TRUE(mem->member()->IsIdentifier());
|
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = mem->member()->AsIdentifier();
|
auto* ident = mem->member()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "d");
|
EXPECT_EQ(ident->name(), "d");
|
||||||
|
|
||||||
ASSERT_TRUE(mem->structure()->IsArrayAccessor());
|
ASSERT_TRUE(mem->structure()->Is<ast::ArrayAccessorExpression>());
|
||||||
auto* ary = mem->structure()->AsArrayAccessor();
|
auto* ary = mem->structure()->As<ast::ArrayAccessorExpression>();
|
||||||
|
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
init = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
init = ary->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_NE(init->literal(), nullptr);
|
ASSERT_NE(init->literal(), nullptr);
|
||||||
ASSERT_TRUE(init->literal()->IsSint());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
EXPECT_EQ(init->literal()->AsSint()->value(), 2);
|
EXPECT_EQ(init->literal()->AsSint()->value(), 2);
|
||||||
|
|
||||||
ASSERT_TRUE(ary->array()->IsMemberAccessor());
|
ASSERT_TRUE(ary->array()->Is<ast::MemberAccessorExpression>());
|
||||||
mem = ary->array()->AsMemberAccessor();
|
mem = ary->array()->As<ast::MemberAccessorExpression>();
|
||||||
ASSERT_TRUE(mem->member()->IsIdentifier());
|
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
|
||||||
ident = mem->member()->AsIdentifier();
|
ident = mem->member()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "c");
|
EXPECT_EQ(ident->name(), "c");
|
||||||
|
|
||||||
ASSERT_TRUE(mem->structure()->IsMemberAccessor());
|
ASSERT_TRUE(mem->structure()->Is<ast::MemberAccessorExpression>());
|
||||||
mem = mem->structure()->AsMemberAccessor();
|
mem = mem->structure()->As<ast::MemberAccessorExpression>();
|
||||||
|
|
||||||
ASSERT_TRUE(mem->structure()->IsIdentifier());
|
ASSERT_TRUE(mem->structure()->Is<ast::IdentifierExpression>());
|
||||||
ident = mem->structure()->AsIdentifier();
|
ident = mem->structure()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(mem->member()->IsIdentifier());
|
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
|
||||||
ident = mem->member()->AsIdentifier();
|
ident = mem->member()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "b");
|
EXPECT_EQ(ident->name(), "b");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/ast/call_expression.h"
|
#include "src/ast/call_expression.h"
|
||||||
#include "src/ast/call_statement.h"
|
#include "src/ast/call_statement.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
|
@ -35,8 +36,8 @@ TEST_F(ParserImplTest, Statement_Call) {
|
||||||
ASSERT_TRUE(e->Is<ast::CallStatement>());
|
ASSERT_TRUE(e->Is<ast::CallStatement>());
|
||||||
auto* c = e->As<ast::CallStatement>()->expr();
|
auto* c = e->As<ast::CallStatement>()->expr();
|
||||||
|
|
||||||
ASSERT_TRUE(c->func()->IsIdentifier());
|
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
|
||||||
auto* func = c->func()->AsIdentifier();
|
auto* func = c->func()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(func->name(), "a");
|
EXPECT_EQ(func->name(), "a");
|
||||||
|
|
||||||
EXPECT_EQ(c->params().size(), 0u);
|
EXPECT_EQ(c->params().size(), 0u);
|
||||||
|
@ -53,14 +54,14 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) {
|
||||||
ASSERT_TRUE(e->Is<ast::CallStatement>());
|
ASSERT_TRUE(e->Is<ast::CallStatement>());
|
||||||
auto* c = e->As<ast::CallStatement>()->expr();
|
auto* c = e->As<ast::CallStatement>()->expr();
|
||||||
|
|
||||||
ASSERT_TRUE(c->func()->IsIdentifier());
|
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
|
||||||
auto* func = c->func()->AsIdentifier();
|
auto* func = c->func()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(func->name(), "a");
|
EXPECT_EQ(func->name(), "a");
|
||||||
|
|
||||||
EXPECT_EQ(c->params().size(), 3u);
|
EXPECT_EQ(c->params().size(), 3u);
|
||||||
EXPECT_TRUE(c->params()[0]->IsConstructor());
|
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
EXPECT_TRUE(c->params()[1]->IsIdentifier());
|
EXPECT_TRUE(c->params()[1]->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_TRUE(c->params()[2]->IsBinary());
|
EXPECT_TRUE(c->params()[2]->Is<ast::BinaryExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, Statement_Call_Missing_RightParen) {
|
TEST_F(ParserImplTest, Statement_Call_Missing_RightParen) {
|
||||||
|
|
|
@ -31,25 +31,25 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl) {
|
||||||
auto e = p->expect_const_expr();
|
auto e = p->expect_const_expr();
|
||||||
ASSERT_FALSE(p->has_error()) << p->error();
|
ASSERT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_FALSE(e.errored);
|
ASSERT_FALSE(e.errored);
|
||||||
ASSERT_TRUE(e->IsConstructor());
|
ASSERT_TRUE(e->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(e->AsConstructor()->IsTypeConstructor());
|
ASSERT_TRUE(e->Is<ast::TypeConstructorExpression>());
|
||||||
|
|
||||||
auto* t = e->AsConstructor()->AsTypeConstructor();
|
auto* t = e->As<ast::TypeConstructorExpression>();
|
||||||
ASSERT_TRUE(t->type()->Is<ast::type::VectorType>());
|
ASSERT_TRUE(t->type()->Is<ast::type::VectorType>());
|
||||||
EXPECT_EQ(t->type()->As<ast::type::VectorType>()->size(), 2u);
|
EXPECT_EQ(t->type()->As<ast::type::VectorType>()->size(), 2u);
|
||||||
|
|
||||||
ASSERT_EQ(t->values().size(), 2u);
|
ASSERT_EQ(t->values().size(), 2u);
|
||||||
auto& v = t->values();
|
auto& v = t->values();
|
||||||
|
|
||||||
ASSERT_TRUE(v[0]->IsConstructor());
|
ASSERT_TRUE(v[0]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(v[0]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(v[0]->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* c = v[0]->AsConstructor()->AsScalarConstructor();
|
auto* c = v[0]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(c->literal()->IsFloat());
|
ASSERT_TRUE(c->literal()->IsFloat());
|
||||||
EXPECT_FLOAT_EQ(c->literal()->AsFloat()->value(), 1.);
|
EXPECT_FLOAT_EQ(c->literal()->AsFloat()->value(), 1.);
|
||||||
|
|
||||||
ASSERT_TRUE(v[1]->IsConstructor());
|
ASSERT_TRUE(v[1]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(v[1]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(v[1]->Is<ast::ScalarConstructorExpression>());
|
||||||
c = v[1]->AsConstructor()->AsScalarConstructor();
|
c = v[1]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(c->literal()->IsFloat());
|
ASSERT_TRUE(c->literal()->IsFloat());
|
||||||
EXPECT_FLOAT_EQ(c->literal()->AsFloat()->value(), 2.);
|
EXPECT_FLOAT_EQ(c->literal()->AsFloat()->value(), 2.);
|
||||||
}
|
}
|
||||||
|
@ -114,9 +114,9 @@ TEST_F(ParserImplTest, ConstExpr_ConstLiteral) {
|
||||||
ASSERT_FALSE(p->has_error()) << p->error();
|
ASSERT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_FALSE(e.errored);
|
ASSERT_FALSE(e.errored);
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsConstructor());
|
ASSERT_TRUE(e->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(e->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(e->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* c = e->AsConstructor()->AsScalarConstructor();
|
auto* c = e->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(c->literal()->IsBool());
|
ASSERT_TRUE(c->literal()->IsBool());
|
||||||
EXPECT_TRUE(c->literal()->AsBool()->IsTrue());
|
EXPECT_TRUE(c->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/ast/else_statement.h"
|
#include "src/ast/else_statement.h"
|
||||||
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/reader/wgsl/parser_impl.h"
|
#include "src/reader/wgsl/parser_impl.h"
|
||||||
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
||||||
|
|
||||||
|
@ -32,7 +34,7 @@ TEST_F(ParserImplTest, ElseIfStmt) {
|
||||||
|
|
||||||
ASSERT_TRUE(e.value[0]->Is<ast::ElseStatement>());
|
ASSERT_TRUE(e.value[0]->Is<ast::ElseStatement>());
|
||||||
ASSERT_NE(e.value[0]->condition(), nullptr);
|
ASSERT_NE(e.value[0]->condition(), nullptr);
|
||||||
ASSERT_TRUE(e.value[0]->condition()->IsBinary());
|
ASSERT_TRUE(e.value[0]->condition()->Is<ast::BinaryExpression>());
|
||||||
EXPECT_EQ(e.value[0]->body()->size(), 2u);
|
EXPECT_EQ(e.value[0]->body()->size(), 2u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,12 +48,12 @@ TEST_F(ParserImplTest, ElseIfStmt_Multiple) {
|
||||||
|
|
||||||
ASSERT_TRUE(e.value[0]->Is<ast::ElseStatement>());
|
ASSERT_TRUE(e.value[0]->Is<ast::ElseStatement>());
|
||||||
ASSERT_NE(e.value[0]->condition(), nullptr);
|
ASSERT_NE(e.value[0]->condition(), nullptr);
|
||||||
ASSERT_TRUE(e.value[0]->condition()->IsBinary());
|
ASSERT_TRUE(e.value[0]->condition()->Is<ast::BinaryExpression>());
|
||||||
EXPECT_EQ(e.value[0]->body()->size(), 2u);
|
EXPECT_EQ(e.value[0]->body()->size(), 2u);
|
||||||
|
|
||||||
ASSERT_TRUE(e.value[1]->Is<ast::ElseStatement>());
|
ASSERT_TRUE(e.value[1]->Is<ast::ElseStatement>());
|
||||||
ASSERT_NE(e.value[1]->condition(), nullptr);
|
ASSERT_NE(e.value[1]->condition(), nullptr);
|
||||||
ASSERT_TRUE(e.value[1]->condition()->IsIdentifier());
|
ASSERT_TRUE(e.value[1]->condition()->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_EQ(e.value[1]->body()->size(), 1u);
|
EXPECT_EQ(e.value[1]->body()->size(), 1u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,17 +33,17 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_Equal) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kEqual, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kEqual, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -56,17 +56,17 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kNotEqual, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kNotEqual, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ TEST_F(ParserImplTest, EqualityExpression_NoOr_ReturnsLHS) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -33,17 +33,17 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_Parses) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kXor, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kXor, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_NoOr_ReturnsLHS) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -43,7 +43,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl) {
|
||||||
EXPECT_EQ(e->source().range.end.column, 8u);
|
EXPECT_EQ(e->source().range.end.column, 8u);
|
||||||
|
|
||||||
ASSERT_NE(e->constructor(), nullptr);
|
ASSERT_NE(e->constructor(), nullptr);
|
||||||
EXPECT_TRUE(e->constructor()->IsConstructor());
|
EXPECT_TRUE(e->constructor()->Is<ast::ConstructorExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, GlobalConstantDecl_MissingEqual) {
|
TEST_F(ParserImplTest, GlobalConstantDecl_MissingEqual) {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/decorated_variable.h"
|
#include "src/ast/decorated_variable.h"
|
||||||
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
#include "src/ast/type/f32_type.h"
|
#include "src/ast/type/f32_type.h"
|
||||||
#include "src/ast/variable_decoration.h"
|
#include "src/ast/variable_decoration.h"
|
||||||
#include "src/reader/wgsl/parser_impl.h"
|
#include "src/reader/wgsl/parser_impl.h"
|
||||||
|
@ -69,8 +70,8 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) {
|
||||||
EXPECT_EQ(e->source().range.end.column, 11u);
|
EXPECT_EQ(e->source().range.end.column, 11u);
|
||||||
|
|
||||||
ASSERT_NE(e->constructor(), nullptr);
|
ASSERT_NE(e->constructor(), nullptr);
|
||||||
ASSERT_TRUE(e->constructor()->IsConstructor());
|
ASSERT_TRUE(e->constructor()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(e->constructor()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(e->constructor()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
ASSERT_FALSE(e->IsDecorated());
|
ASSERT_FALSE(e->IsDecorated());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/ast/else_statement.h"
|
#include "src/ast/else_statement.h"
|
||||||
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/if_statement.h"
|
#include "src/ast/if_statement.h"
|
||||||
#include "src/reader/wgsl/parser_impl.h"
|
#include "src/reader/wgsl/parser_impl.h"
|
||||||
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
||||||
|
@ -33,7 +35,7 @@ TEST_F(ParserImplTest, IfStmt) {
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::IfStatement>());
|
ASSERT_TRUE(e->Is<ast::IfStatement>());
|
||||||
ASSERT_NE(e->condition(), nullptr);
|
ASSERT_NE(e->condition(), nullptr);
|
||||||
ASSERT_TRUE(e->condition()->IsBinary());
|
ASSERT_TRUE(e->condition()->Is<ast::BinaryExpression>());
|
||||||
EXPECT_EQ(e->body()->size(), 2u);
|
EXPECT_EQ(e->body()->size(), 2u);
|
||||||
EXPECT_EQ(e->else_statements().size(), 0u);
|
EXPECT_EQ(e->else_statements().size(), 0u);
|
||||||
}
|
}
|
||||||
|
@ -48,12 +50,13 @@ TEST_F(ParserImplTest, IfStmt_WithElse) {
|
||||||
|
|
||||||
ASSERT_TRUE(e->Is<ast::IfStatement>());
|
ASSERT_TRUE(e->Is<ast::IfStatement>());
|
||||||
ASSERT_NE(e->condition(), nullptr);
|
ASSERT_NE(e->condition(), nullptr);
|
||||||
ASSERT_TRUE(e->condition()->IsBinary());
|
ASSERT_TRUE(e->condition()->Is<ast::BinaryExpression>());
|
||||||
EXPECT_EQ(e->body()->size(), 2u);
|
EXPECT_EQ(e->body()->size(), 2u);
|
||||||
|
|
||||||
ASSERT_EQ(e->else_statements().size(), 2u);
|
ASSERT_EQ(e->else_statements().size(), 2u);
|
||||||
ASSERT_NE(e->else_statements()[0]->condition(), nullptr);
|
ASSERT_NE(e->else_statements()[0]->condition(), nullptr);
|
||||||
ASSERT_TRUE(e->else_statements()[0]->condition()->IsIdentifier());
|
ASSERT_TRUE(
|
||||||
|
e->else_statements()[0]->condition()->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_EQ(e->else_statements()[0]->body()->size(), 1u);
|
EXPECT_EQ(e->else_statements()[0]->body()->size(), 1u);
|
||||||
|
|
||||||
ASSERT_EQ(e->else_statements()[1]->condition(), nullptr);
|
ASSERT_EQ(e->else_statements()[1]->condition(), nullptr);
|
||||||
|
|
|
@ -33,17 +33,17 @@ TEST_F(ParserImplTest, InclusiveOrExpression_Parses) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kOr, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kOr, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ TEST_F(ParserImplTest, InclusiveOrExpression_NoOr_ReturnsLHS) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -33,17 +33,17 @@ TEST_F(ParserImplTest, LogicalAndExpression_Parses) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kLogicalAnd, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kLogicalAnd, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ TEST_F(ParserImplTest, LogicalAndExpression_NoOr_ReturnsLHS) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -33,17 +33,17 @@ TEST_F(ParserImplTest, LogicalOrExpression_Parses) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kLogicalOr, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kLogicalOr, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ TEST_F(ParserImplTest, LogicalOrExpression_NoOr_ReturnsLHS) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -33,17 +33,17 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kMultiply, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kMultiply, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -56,17 +56,17 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kDivide, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kDivide, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -79,17 +79,17 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kModulo, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kModulo, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ TEST_F(ParserImplTest, MultiplicativeExpression_NoOr_ReturnsLHS) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/reader/wgsl/parser_impl.h"
|
#include "src/reader/wgsl/parser_impl.h"
|
||||||
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@ TEST_F(ParserImplTest, ParenRhsStmt) {
|
||||||
ASSERT_FALSE(p->has_error()) << p->error();
|
ASSERT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_FALSE(e.errored);
|
ASSERT_FALSE(e.errored);
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ParenRhsStmt_MissingLeftParen) {
|
TEST_F(ParserImplTest, ParenRhsStmt_MissingLeftParen) {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/array_accessor_expression.h"
|
#include "src/ast/array_accessor_expression.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/ast/call_expression.h"
|
#include "src/ast/call_expression.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/member_accessor_expression.h"
|
#include "src/ast/member_accessor_expression.h"
|
||||||
|
@ -36,16 +37,16 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ConstantIndex) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsArrayAccessor());
|
ASSERT_TRUE(e->Is<ast::ArrayAccessorExpression>());
|
||||||
auto* ary = e->AsArrayAccessor();
|
auto* ary = e->As<ast::ArrayAccessorExpression>();
|
||||||
|
|
||||||
ASSERT_TRUE(ary->array()->IsIdentifier());
|
ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = ary->array()->AsIdentifier();
|
auto* ident = ary->array()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* c = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* c = ary->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(c->literal()->IsSint());
|
ASSERT_TRUE(c->literal()->IsSint());
|
||||||
EXPECT_EQ(c->literal()->AsSint()->value(), 1);
|
EXPECT_EQ(c->literal()->AsSint()->value(), 1);
|
||||||
}
|
}
|
||||||
|
@ -58,14 +59,14 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ExpressionIndex) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsArrayAccessor());
|
ASSERT_TRUE(e->Is<ast::ArrayAccessorExpression>());
|
||||||
auto* ary = e->AsArrayAccessor();
|
auto* ary = e->As<ast::ArrayAccessorExpression>();
|
||||||
|
|
||||||
ASSERT_TRUE(ary->array()->IsIdentifier());
|
ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = ary->array()->AsIdentifier();
|
auto* ident = ary->array()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsBinary());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::BinaryExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, PostfixExpression_Array_MissingIndex) {
|
TEST_F(ParserImplTest, PostfixExpression_Array_MissingIndex) {
|
||||||
|
@ -106,11 +107,11 @@ TEST_F(ParserImplTest, PostfixExpression_Call_Empty) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsCall());
|
ASSERT_TRUE(e->Is<ast::CallExpression>());
|
||||||
auto* c = e->AsCall();
|
auto* c = e->As<ast::CallExpression>();
|
||||||
|
|
||||||
ASSERT_TRUE(c->func()->IsIdentifier());
|
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
|
||||||
auto* func = c->func()->AsIdentifier();
|
auto* func = c->func()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(func->name(), "a");
|
EXPECT_EQ(func->name(), "a");
|
||||||
|
|
||||||
EXPECT_EQ(c->params().size(), 0u);
|
EXPECT_EQ(c->params().size(), 0u);
|
||||||
|
@ -124,17 +125,17 @@ TEST_F(ParserImplTest, PostfixExpression_Call_WithArgs) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsCall());
|
ASSERT_TRUE(e->Is<ast::CallExpression>());
|
||||||
auto* c = e->AsCall();
|
auto* c = e->As<ast::CallExpression>();
|
||||||
|
|
||||||
ASSERT_TRUE(c->func()->IsIdentifier());
|
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
|
||||||
auto* func = c->func()->AsIdentifier();
|
auto* func = c->func()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(func->name(), "test");
|
EXPECT_EQ(func->name(), "test");
|
||||||
|
|
||||||
EXPECT_EQ(c->params().size(), 3u);
|
EXPECT_EQ(c->params().size(), 3u);
|
||||||
EXPECT_TRUE(c->params()[0]->IsConstructor());
|
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
EXPECT_TRUE(c->params()[1]->IsIdentifier());
|
EXPECT_TRUE(c->params()[1]->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_TRUE(c->params()[2]->IsBinary());
|
EXPECT_TRUE(c->params()[2]->Is<ast::BinaryExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, PostfixExpression_Call_InvalidArg) {
|
TEST_F(ParserImplTest, PostfixExpression_Call_InvalidArg) {
|
||||||
|
@ -174,14 +175,14 @@ TEST_F(ParserImplTest, PostfixExpression_MemberAccessor) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsMemberAccessor());
|
ASSERT_TRUE(e->Is<ast::MemberAccessorExpression>());
|
||||||
|
|
||||||
auto* m = e->AsMemberAccessor();
|
auto* m = e->As<ast::MemberAccessorExpression>();
|
||||||
ASSERT_TRUE(m->structure()->IsIdentifier());
|
ASSERT_TRUE(m->structure()->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_EQ(m->structure()->AsIdentifier()->name(), "a");
|
EXPECT_EQ(m->structure()->As<ast::IdentifierExpression>()->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(m->member()->IsIdentifier());
|
ASSERT_TRUE(m->member()->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_EQ(m->member()->AsIdentifier()->name(), "b");
|
EXPECT_EQ(m->member()->As<ast::IdentifierExpression>()->name(), "b");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, PostfixExpression_MemberAccesssor_InvalidIdent) {
|
TEST_F(ParserImplTest, PostfixExpression_MemberAccesssor_InvalidIdent) {
|
||||||
|
@ -211,7 +212,7 @@ TEST_F(ParserImplTest, PostfixExpression_NonMatch_returnLHS) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/array_accessor_expression.h"
|
#include "src/ast/array_accessor_expression.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/ast/bitcast_expression.h"
|
#include "src/ast/bitcast_expression.h"
|
||||||
#include "src/ast/bool_literal.h"
|
#include "src/ast/bool_literal.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
|
@ -38,8 +39,8 @@ TEST_F(ParserImplTest, PrimaryExpression_Ident) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = e->AsIdentifier();
|
auto* ident = e->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,33 +51,33 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsConstructor());
|
ASSERT_TRUE(e->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(e->AsConstructor()->IsTypeConstructor());
|
ASSERT_TRUE(e->Is<ast::TypeConstructorExpression>());
|
||||||
auto* ty = e->AsConstructor()->AsTypeConstructor();
|
auto* ty = e->As<ast::TypeConstructorExpression>();
|
||||||
|
|
||||||
ASSERT_EQ(ty->values().size(), 4u);
|
ASSERT_EQ(ty->values().size(), 4u);
|
||||||
const auto& val = ty->values();
|
const auto& val = ty->values();
|
||||||
ASSERT_TRUE(val[0]->IsConstructor());
|
ASSERT_TRUE(val[0]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(val[0]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(val[0]->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* ident = val[0]->AsConstructor()->AsScalarConstructor();
|
auto* ident = val[0]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(ident->literal()->IsSint());
|
ASSERT_TRUE(ident->literal()->IsSint());
|
||||||
EXPECT_EQ(ident->literal()->AsSint()->value(), 1);
|
EXPECT_EQ(ident->literal()->AsSint()->value(), 1);
|
||||||
|
|
||||||
ASSERT_TRUE(val[1]->IsConstructor());
|
ASSERT_TRUE(val[1]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(val[1]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(val[1]->Is<ast::ScalarConstructorExpression>());
|
||||||
ident = val[1]->AsConstructor()->AsScalarConstructor();
|
ident = val[1]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(ident->literal()->IsSint());
|
ASSERT_TRUE(ident->literal()->IsSint());
|
||||||
EXPECT_EQ(ident->literal()->AsSint()->value(), 2);
|
EXPECT_EQ(ident->literal()->AsSint()->value(), 2);
|
||||||
|
|
||||||
ASSERT_TRUE(val[2]->IsConstructor());
|
ASSERT_TRUE(val[2]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(val[2]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(val[2]->Is<ast::ScalarConstructorExpression>());
|
||||||
ident = val[2]->AsConstructor()->AsScalarConstructor();
|
ident = val[2]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(ident->literal()->IsSint());
|
ASSERT_TRUE(ident->literal()->IsSint());
|
||||||
EXPECT_EQ(ident->literal()->AsSint()->value(), 3);
|
EXPECT_EQ(ident->literal()->AsSint()->value(), 3);
|
||||||
|
|
||||||
ASSERT_TRUE(val[3]->IsConstructor());
|
ASSERT_TRUE(val[3]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(val[3]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(val[3]->Is<ast::ScalarConstructorExpression>());
|
||||||
ident = val[3]->AsConstructor()->AsScalarConstructor();
|
ident = val[3]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(ident->literal()->IsSint());
|
ASSERT_TRUE(ident->literal()->IsSint());
|
||||||
EXPECT_EQ(ident->literal()->AsSint()->value(), 4);
|
EXPECT_EQ(ident->literal()->AsSint()->value(), 4);
|
||||||
}
|
}
|
||||||
|
@ -88,9 +89,9 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_ZeroConstructor) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsConstructor());
|
ASSERT_TRUE(e->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(e->AsConstructor()->IsTypeConstructor());
|
ASSERT_TRUE(e->Is<ast::TypeConstructorExpression>());
|
||||||
auto* ty = e->AsConstructor()->AsTypeConstructor();
|
auto* ty = e->As<ast::TypeConstructorExpression>();
|
||||||
|
|
||||||
ASSERT_EQ(ty->values().size(), 0u);
|
ASSERT_EQ(ty->values().size(), 0u);
|
||||||
}
|
}
|
||||||
|
@ -142,9 +143,9 @@ TEST_F(ParserImplTest, PrimaryExpression_ConstLiteral_True) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsConstructor());
|
ASSERT_TRUE(e->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(e->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(e->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = e->AsConstructor()->AsScalarConstructor();
|
auto* init = e->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
EXPECT_TRUE(init->literal()->AsBool()->IsTrue());
|
EXPECT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -156,7 +157,7 @@ TEST_F(ParserImplTest, PrimaryExpression_ParenExpr) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, PrimaryExpression_ParenExpr_MissingRightParen) {
|
TEST_F(ParserImplTest, PrimaryExpression_ParenExpr_MissingRightParen) {
|
||||||
|
@ -200,15 +201,15 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsConstructor());
|
ASSERT_TRUE(e->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(e->AsConstructor()->IsTypeConstructor());
|
ASSERT_TRUE(e->Is<ast::TypeConstructorExpression>());
|
||||||
|
|
||||||
auto* c = e->AsConstructor()->AsTypeConstructor();
|
auto* c = e->As<ast::TypeConstructorExpression>();
|
||||||
ASSERT_EQ(c->type(), f32);
|
ASSERT_EQ(c->type(), f32);
|
||||||
ASSERT_EQ(c->values().size(), 1u);
|
ASSERT_EQ(c->values().size(), 1u);
|
||||||
|
|
||||||
ASSERT_TRUE(c->values()[0]->IsConstructor());
|
ASSERT_TRUE(c->values()[0]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(c->values()[0]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(c->values()[0]->Is<ast::ScalarConstructorExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
|
TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
|
||||||
|
@ -222,13 +223,13 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsBitcast());
|
ASSERT_TRUE(e->Is<ast::BitcastExpression>());
|
||||||
|
|
||||||
auto* c = e->AsBitcast();
|
auto* c = e->As<ast::BitcastExpression>();
|
||||||
ASSERT_EQ(c->type(), f32);
|
ASSERT_EQ(c->type(), f32);
|
||||||
|
|
||||||
ASSERT_TRUE(c->expr()->IsConstructor());
|
ASSERT_TRUE(c->expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(c->expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(c->expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingGreaterThan) {
|
TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingGreaterThan) {
|
||||||
|
|
|
@ -33,17 +33,17 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThan) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kLessThan, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kLessThan, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -56,17 +56,17 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kGreaterThan, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kGreaterThan, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -79,17 +79,17 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kLessThanEqual, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kLessThanEqual, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -102,17 +102,17 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kGreaterThanEqual, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kGreaterThanEqual, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ TEST_F(ParserImplTest, RelationalExpression_NoOr_ReturnsLHS) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -33,17 +33,17 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftLeft) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kShiftLeft, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kShiftLeft, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -56,17 +56,17 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsBinary());
|
ASSERT_TRUE(e->Is<ast::BinaryExpression>());
|
||||||
auto* rel = e->AsBinary();
|
auto* rel = e->As<ast::BinaryExpression>();
|
||||||
EXPECT_EQ(ast::BinaryOp::kShiftRight, rel->op());
|
EXPECT_EQ(ast::BinaryOp::kShiftRight, rel->op());
|
||||||
|
|
||||||
ASSERT_TRUE(rel->lhs()->IsIdentifier());
|
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = rel->lhs()->AsIdentifier();
|
auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(rel->rhs()->IsConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = rel->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = rel->rhs()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsBool());
|
ASSERT_TRUE(init->literal()->IsBool());
|
||||||
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ TEST_F(ParserImplTest, ShiftExpression_NoOr_ReturnsLHS) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsIdentifier());
|
ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/ast/discard_statement.h"
|
#include "src/ast/discard_statement.h"
|
||||||
#include "src/ast/return_statement.h"
|
#include "src/ast/return_statement.h"
|
||||||
#include "src/ast/statement.h"
|
#include "src/ast/statement.h"
|
||||||
|
@ -60,7 +61,7 @@ TEST_F(ParserImplTest, Statement_Return_Value) {
|
||||||
ASSERT_TRUE(e->Is<ast::ReturnStatement>());
|
ASSERT_TRUE(e->Is<ast::ReturnStatement>());
|
||||||
auto* ret = e->As<ast::ReturnStatement>();
|
auto* ret = e->As<ast::ReturnStatement>();
|
||||||
ASSERT_NE(ret->value(), nullptr);
|
ASSERT_NE(ret->value(), nullptr);
|
||||||
EXPECT_TRUE(ret->value()->IsBinary());
|
EXPECT_TRUE(ret->value()->Is<ast::BinaryExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, Statement_Return_MissingSemi) {
|
TEST_F(ParserImplTest, Statement_Return_MissingSemi) {
|
||||||
|
|
|
@ -34,15 +34,15 @@ TEST_F(ParserImplTest, UnaryExpression_Postix) {
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(e->IsArrayAccessor());
|
ASSERT_TRUE(e->Is<ast::ArrayAccessorExpression>());
|
||||||
auto* ary = e->AsArrayAccessor();
|
auto* ary = e->As<ast::ArrayAccessorExpression>();
|
||||||
ASSERT_TRUE(ary->array()->IsIdentifier());
|
ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>());
|
||||||
auto* ident = ary->array()->AsIdentifier();
|
auto* ident = ary->array()->As<ast::IdentifierExpression>();
|
||||||
EXPECT_EQ(ident->name(), "a");
|
EXPECT_EQ(ident->name(), "a");
|
||||||
|
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* init = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* init = ary->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsSint());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
ASSERT_EQ(init->literal()->AsSint()->value(), 2);
|
ASSERT_EQ(init->literal()->AsSint()->value(), 2);
|
||||||
}
|
}
|
||||||
|
@ -54,15 +54,15 @@ TEST_F(ParserImplTest, UnaryExpression_Minus) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsUnaryOp());
|
ASSERT_TRUE(e->Is<ast::UnaryOpExpression>());
|
||||||
|
|
||||||
auto* u = e->AsUnaryOp();
|
auto* u = e->As<ast::UnaryOpExpression>();
|
||||||
ASSERT_EQ(u->op(), ast::UnaryOp::kNegation);
|
ASSERT_EQ(u->op(), ast::UnaryOp::kNegation);
|
||||||
|
|
||||||
ASSERT_TRUE(u->expr()->IsConstructor());
|
ASSERT_TRUE(u->expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(u->expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(u->expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* init = u->expr()->AsConstructor()->AsScalarConstructor();
|
auto* init = u->expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsSint());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
EXPECT_EQ(init->literal()->AsSint()->value(), 1);
|
EXPECT_EQ(init->literal()->AsSint()->value(), 1);
|
||||||
}
|
}
|
||||||
|
@ -84,15 +84,15 @@ TEST_F(ParserImplTest, UnaryExpression_Bang) {
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
ASSERT_TRUE(e->IsUnaryOp());
|
ASSERT_TRUE(e->Is<ast::UnaryOpExpression>());
|
||||||
|
|
||||||
auto* u = e->AsUnaryOp();
|
auto* u = e->As<ast::UnaryOpExpression>();
|
||||||
ASSERT_EQ(u->op(), ast::UnaryOp::kNot);
|
ASSERT_EQ(u->op(), ast::UnaryOp::kNot);
|
||||||
|
|
||||||
ASSERT_TRUE(u->expr()->IsConstructor());
|
ASSERT_TRUE(u->expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(u->expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(u->expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* init = u->expr()->AsConstructor()->AsScalarConstructor();
|
auto* init = u->expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(init->literal()->IsSint());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
EXPECT_EQ(init->literal()->AsSint()->value(), 1);
|
EXPECT_EQ(init->literal()->AsSint()->value(), 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
|
||||||
ASSERT_EQ(e->source().range.end.column, 6u);
|
ASSERT_EQ(e->source().range.end.column, 6u);
|
||||||
|
|
||||||
ASSERT_NE(e->variable()->constructor(), nullptr);
|
ASSERT_NE(e->variable()->constructor(), nullptr);
|
||||||
EXPECT_TRUE(e->variable()->constructor()->IsConstructor());
|
EXPECT_TRUE(e->variable()->constructor()->Is<ast::ConstructorExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_VariableDecl_Invalid) {
|
TEST_F(ParserImplTest, VariableStmt_VariableDecl_Invalid) {
|
||||||
|
|
|
@ -135,24 +135,22 @@ bool BoundArrayAccessorsTransform::ProcessStatement(ast::Statement* stmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BoundArrayAccessorsTransform::ProcessExpression(ast::Expression* expr) {
|
bool BoundArrayAccessorsTransform::ProcessExpression(ast::Expression* expr) {
|
||||||
if (expr->IsArrayAccessor()) {
|
if (auto* array = expr->As<ast::ArrayAccessorExpression>()) {
|
||||||
return ProcessArrayAccessor(expr->AsArrayAccessor());
|
return ProcessArrayAccessor(array);
|
||||||
} else if (expr->IsBitcast()) {
|
} else if (auto* bitcast = expr->As<ast::BitcastExpression>()) {
|
||||||
return ProcessExpression(expr->AsBitcast()->expr());
|
return ProcessExpression(bitcast->expr());
|
||||||
} else if (expr->IsCall()) {
|
} else if (auto* call = expr->As<ast::CallExpression>()) {
|
||||||
auto* c = expr->AsCall();
|
if (!ProcessExpression(call->func())) {
|
||||||
if (!ProcessExpression(c->func())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (auto* e : c->params()) {
|
for (auto* e : call->params()) {
|
||||||
if (!ProcessExpression(e)) {
|
if (!ProcessExpression(e)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (expr->IsIdentifier()) {
|
} else if (expr->Is<ast::IdentifierExpression>()) {
|
||||||
/* nop */
|
/* nop */
|
||||||
} else if (expr->IsConstructor()) {
|
} else if (auto* c = expr->As<ast::ConstructorExpression>()) {
|
||||||
auto* c = expr->AsConstructor();
|
|
||||||
if (c->IsTypeConstructor()) {
|
if (c->IsTypeConstructor()) {
|
||||||
for (auto* e : c->AsTypeConstructor()->values()) {
|
for (auto* e : c->AsTypeConstructor()->values()) {
|
||||||
if (!ProcessExpression(e)) {
|
if (!ProcessExpression(e)) {
|
||||||
|
@ -160,14 +158,12 @@ bool BoundArrayAccessorsTransform::ProcessExpression(ast::Expression* expr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (expr->IsMemberAccessor()) {
|
} else if (auto* m = expr->As<ast::MemberAccessorExpression>()) {
|
||||||
auto* m = expr->AsMemberAccessor();
|
|
||||||
return ProcessExpression(m->structure()) && ProcessExpression(m->member());
|
return ProcessExpression(m->structure()) && ProcessExpression(m->member());
|
||||||
} else if (expr->IsBinary()) {
|
} else if (auto* b = expr->As<ast::BinaryExpression>()) {
|
||||||
auto* b = expr->AsBinary();
|
|
||||||
return ProcessExpression(b->lhs()) && ProcessExpression(b->rhs());
|
return ProcessExpression(b->lhs()) && ProcessExpression(b->rhs());
|
||||||
} else if (expr->IsUnaryOp()) {
|
} else if (auto* u = expr->As<ast::UnaryOpExpression>()) {
|
||||||
return ProcessExpression(expr->AsUnaryOp()->expr());
|
return ProcessExpression(u->expr());
|
||||||
} else {
|
} else {
|
||||||
error_ = "unknown statement in bound array accessors transform";
|
error_ = "unknown statement in bound array accessors transform";
|
||||||
return false;
|
return false;
|
||||||
|
@ -217,10 +213,8 @@ bool BoundArrayAccessorsTransform::ProcessAccessExpression(
|
||||||
ast::ArrayAccessorExpression* expr,
|
ast::ArrayAccessorExpression* expr,
|
||||||
uint32_t size) {
|
uint32_t size) {
|
||||||
// Scalar constructor we can re-write the value to be within bounds.
|
// Scalar constructor we can re-write the value to be within bounds.
|
||||||
if (expr->idx_expr()->IsConstructor() &&
|
if (auto* c = expr->idx_expr()->As<ast::ScalarConstructorExpression>()) {
|
||||||
expr->idx_expr()->AsConstructor()->IsScalarConstructor()) {
|
auto* lit = c->literal();
|
||||||
auto* lit =
|
|
||||||
expr->idx_expr()->AsConstructor()->AsScalarConstructor()->literal();
|
|
||||||
if (lit->IsSint()) {
|
if (lit->IsSint()) {
|
||||||
int32_t val = lit->AsSint()->value();
|
int32_t val = lit->AsSint()->value();
|
||||||
if (val < 0) {
|
if (val < 0) {
|
||||||
|
|
|
@ -129,25 +129,25 @@ TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsCall());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>());
|
||||||
|
|
||||||
auto* idx = ptr->idx_expr()->AsCall();
|
auto* idx = ptr->idx_expr()->As<ast::CallExpression>();
|
||||||
ASSERT_TRUE(idx->func()->IsIdentifier());
|
ASSERT_TRUE(idx->func()->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_EQ(idx->func()->AsIdentifier()->name(), "min");
|
EXPECT_EQ(idx->func()->As<ast::IdentifierExpression>()->name(), "min");
|
||||||
|
|
||||||
ASSERT_EQ(idx->params().size(), 2u);
|
ASSERT_EQ(idx->params().size(), 2u);
|
||||||
|
|
||||||
ASSERT_TRUE(idx->params()[0]->IsConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::TypeConstructorExpression>());
|
||||||
auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor();
|
auto* tc = idx->params()[0]->As<ast::TypeConstructorExpression>();
|
||||||
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
||||||
ASSERT_EQ(tc->values().size(), 1u);
|
ASSERT_EQ(tc->values().size(), 1u);
|
||||||
ASSERT_EQ(tc->values()[0], access_idx);
|
ASSERT_EQ(tc->values()[0], access_idx);
|
||||||
|
|
||||||
ASSERT_TRUE(idx->params()[1]->IsConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[1]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* scalar = idx->params()[1]->AsConstructor()->AsScalarConstructor();
|
auto* scalar = idx->params()[1]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
||||||
|
|
||||||
|
@ -192,45 +192,49 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Nested_Scalar) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsCall());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>());
|
||||||
|
|
||||||
auto* idx = ptr->idx_expr()->AsCall();
|
auto* idx = ptr->idx_expr()->As<ast::CallExpression>();
|
||||||
ASSERT_TRUE(idx->func()->IsIdentifier());
|
ASSERT_TRUE(idx->func()->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_EQ(idx->func()->AsIdentifier()->name(), "min");
|
EXPECT_EQ(idx->func()->As<ast::IdentifierExpression>()->name(), "min");
|
||||||
|
|
||||||
ASSERT_EQ(idx->params().size(), 2u);
|
ASSERT_EQ(idx->params().size(), 2u);
|
||||||
|
|
||||||
ASSERT_TRUE(idx->params()[0]->IsConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::TypeConstructorExpression>());
|
||||||
auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor();
|
auto* tc = idx->params()[0]->As<ast::TypeConstructorExpression>();
|
||||||
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
||||||
ASSERT_EQ(tc->values().size(), 1u);
|
ASSERT_EQ(tc->values().size(), 1u);
|
||||||
|
|
||||||
auto* sub = tc->values()[0];
|
auto* sub = tc->values()[0];
|
||||||
ASSERT_TRUE(sub->IsArrayAccessor());
|
ASSERT_TRUE(sub->Is<ast::ArrayAccessorExpression>());
|
||||||
ASSERT_TRUE(sub->AsArrayAccessor()->idx_expr()->IsCall());
|
ASSERT_TRUE(sub->As<ast::ArrayAccessorExpression>()
|
||||||
|
->idx_expr()
|
||||||
|
->Is<ast::CallExpression>());
|
||||||
|
|
||||||
auto* sub_idx = sub->AsArrayAccessor()->idx_expr()->AsCall();
|
auto* sub_idx = sub->As<ast::ArrayAccessorExpression>()
|
||||||
ASSERT_TRUE(sub_idx->func()->IsIdentifier());
|
->idx_expr()
|
||||||
EXPECT_EQ(sub_idx->func()->AsIdentifier()->name(), "min");
|
->As<ast::CallExpression>();
|
||||||
|
ASSERT_TRUE(sub_idx->func()->Is<ast::IdentifierExpression>());
|
||||||
|
EXPECT_EQ(sub_idx->func()->As<ast::IdentifierExpression>()->name(), "min");
|
||||||
|
|
||||||
ASSERT_TRUE(sub_idx->params()[0]->IsConstructor());
|
ASSERT_TRUE(sub_idx->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(sub_idx->params()[0]->AsConstructor()->IsTypeConstructor());
|
ASSERT_TRUE(sub_idx->params()[0]->Is<ast::TypeConstructorExpression>());
|
||||||
tc = sub_idx->params()[0]->AsConstructor()->AsTypeConstructor();
|
tc = sub_idx->params()[0]->As<ast::TypeConstructorExpression>();
|
||||||
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
||||||
ASSERT_EQ(tc->values().size(), 1u);
|
ASSERT_EQ(tc->values().size(), 1u);
|
||||||
ASSERT_EQ(tc->values()[0], b_access_idx);
|
ASSERT_EQ(tc->values()[0], b_access_idx);
|
||||||
|
|
||||||
ASSERT_TRUE(sub_idx->params()[1]->IsConstructor());
|
ASSERT_TRUE(sub_idx->params()[1]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(sub_idx->params()[1]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(sub_idx->params()[1]->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* scalar = sub_idx->params()[1]->AsConstructor()->AsScalarConstructor();
|
auto* scalar = sub_idx->params()[1]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 4u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 4u);
|
||||||
|
|
||||||
ASSERT_TRUE(idx->params()[1]->IsConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[1]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ScalarConstructorExpression>());
|
||||||
scalar = idx->params()[1]->AsConstructor()->AsScalarConstructor();
|
scalar = idx->params()[1]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
||||||
|
|
||||||
|
@ -265,11 +269,11 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Scalar) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
||||||
|
|
||||||
|
@ -313,25 +317,25 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Expr) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsCall());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>());
|
||||||
|
|
||||||
auto* idx = ptr->idx_expr()->AsCall();
|
auto* idx = ptr->idx_expr()->As<ast::CallExpression>();
|
||||||
ASSERT_TRUE(idx->func()->IsIdentifier());
|
ASSERT_TRUE(idx->func()->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_EQ(idx->func()->AsIdentifier()->name(), "min");
|
EXPECT_EQ(idx->func()->As<ast::IdentifierExpression>()->name(), "min");
|
||||||
|
|
||||||
ASSERT_EQ(idx->params().size(), 2u);
|
ASSERT_EQ(idx->params().size(), 2u);
|
||||||
|
|
||||||
ASSERT_TRUE(idx->params()[0]->IsConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::TypeConstructorExpression>());
|
||||||
auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor();
|
auto* tc = idx->params()[0]->As<ast::TypeConstructorExpression>();
|
||||||
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
||||||
ASSERT_EQ(tc->values().size(), 1u);
|
ASSERT_EQ(tc->values().size(), 1u);
|
||||||
ASSERT_EQ(tc->values()[0], access_idx);
|
ASSERT_EQ(tc->values()[0], access_idx);
|
||||||
|
|
||||||
ASSERT_TRUE(idx->params()[1]->IsConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[1]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* scalar = idx->params()[1]->AsConstructor()->AsScalarConstructor();
|
auto* scalar = idx->params()[1]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
||||||
|
|
||||||
|
@ -366,11 +370,11 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Negative) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsSint());
|
ASSERT_TRUE(scalar->literal()->IsSint());
|
||||||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
||||||
|
|
||||||
|
@ -405,11 +409,11 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_OutOfBounds) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
||||||
|
|
||||||
|
@ -444,11 +448,11 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Scalar) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
||||||
|
|
||||||
|
@ -492,24 +496,24 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Expr) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsCall());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>());
|
||||||
|
|
||||||
auto* idx = ptr->idx_expr()->AsCall();
|
auto* idx = ptr->idx_expr()->As<ast::CallExpression>();
|
||||||
ASSERT_TRUE(idx->func()->IsIdentifier());
|
ASSERT_TRUE(idx->func()->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_EQ(idx->func()->AsIdentifier()->name(), "min");
|
EXPECT_EQ(idx->func()->As<ast::IdentifierExpression>()->name(), "min");
|
||||||
|
|
||||||
ASSERT_EQ(idx->params().size(), 2u);
|
ASSERT_EQ(idx->params().size(), 2u);
|
||||||
ASSERT_TRUE(idx->params()[0]->IsConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::TypeConstructorExpression>());
|
||||||
auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor();
|
auto* tc = idx->params()[0]->As<ast::TypeConstructorExpression>();
|
||||||
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
||||||
ASSERT_EQ(tc->values().size(), 1u);
|
ASSERT_EQ(tc->values().size(), 1u);
|
||||||
ASSERT_EQ(tc->values()[0], access_idx);
|
ASSERT_EQ(tc->values()[0], access_idx);
|
||||||
|
|
||||||
ASSERT_TRUE(idx->params()[1]->IsConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[1]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* scalar = idx->params()[1]->AsConstructor()->AsScalarConstructor();
|
auto* scalar = idx->params()[1]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
||||||
|
|
||||||
|
@ -544,11 +548,11 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsSint());
|
ASSERT_TRUE(scalar->literal()->IsSint());
|
||||||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
||||||
|
|
||||||
|
@ -583,11 +587,11 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_OutOfBounds) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
||||||
|
|
||||||
|
@ -625,24 +629,24 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Scalar) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->array()->IsArrayAccessor());
|
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
|
||||||
auto* ary = ptr->array()->AsArrayAccessor();
|
auto* ary = ptr->array()->As<ast::ArrayAccessorExpression>();
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ary->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
||||||
|
|
||||||
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
||||||
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::U32Type>());
|
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::U32Type>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
||||||
|
|
||||||
|
@ -689,38 +693,38 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->array()->IsArrayAccessor());
|
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
|
||||||
auto* ary = ptr->array()->AsArrayAccessor();
|
auto* ary = ptr->array()->As<ast::ArrayAccessorExpression>();
|
||||||
|
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsCall());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::CallExpression>());
|
||||||
auto* idx = ary->idx_expr()->AsCall();
|
auto* idx = ary->idx_expr()->As<ast::CallExpression>();
|
||||||
ASSERT_TRUE(idx->func()->IsIdentifier());
|
ASSERT_TRUE(idx->func()->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_EQ(idx->func()->AsIdentifier()->name(), "min");
|
EXPECT_EQ(idx->func()->As<ast::IdentifierExpression>()->name(), "min");
|
||||||
|
|
||||||
ASSERT_EQ(idx->params().size(), 2u);
|
ASSERT_EQ(idx->params().size(), 2u);
|
||||||
|
|
||||||
ASSERT_TRUE(idx->params()[0]->IsConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::TypeConstructorExpression>());
|
||||||
auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor();
|
auto* tc = idx->params()[0]->As<ast::TypeConstructorExpression>();
|
||||||
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
||||||
ASSERT_EQ(tc->values().size(), 1u);
|
ASSERT_EQ(tc->values().size(), 1u);
|
||||||
ASSERT_EQ(tc->values()[0], access_idx);
|
ASSERT_EQ(tc->values()[0], access_idx);
|
||||||
|
|
||||||
ASSERT_TRUE(idx->params()[1]->IsConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[1]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ScalarConstructorExpression>());
|
||||||
auto* scalar = idx->params()[1]->AsConstructor()->AsScalarConstructor();
|
auto* scalar = idx->params()[1]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
||||||
|
|
||||||
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
||||||
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::U32Type>());
|
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::U32Type>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
||||||
|
|
||||||
|
@ -768,35 +772,35 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Row) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->array()->IsArrayAccessor());
|
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
|
||||||
auto* ary = ptr->array()->AsArrayAccessor();
|
auto* ary = ptr->array()->As<ast::ArrayAccessorExpression>();
|
||||||
|
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ary->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsCall());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>());
|
||||||
auto* idx = ptr->idx_expr()->AsCall();
|
auto* idx = ptr->idx_expr()->As<ast::CallExpression>();
|
||||||
ASSERT_TRUE(idx->func()->IsIdentifier());
|
ASSERT_TRUE(idx->func()->Is<ast::IdentifierExpression>());
|
||||||
EXPECT_EQ(idx->func()->AsIdentifier()->name(), "min");
|
EXPECT_EQ(idx->func()->As<ast::IdentifierExpression>()->name(), "min");
|
||||||
|
|
||||||
ASSERT_EQ(idx->params().size(), 2u);
|
ASSERT_EQ(idx->params().size(), 2u);
|
||||||
|
|
||||||
ASSERT_TRUE(idx->params()[0]->IsConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[0]->AsConstructor()->IsTypeConstructor());
|
ASSERT_TRUE(idx->params()[0]->Is<ast::TypeConstructorExpression>());
|
||||||
auto* tc = idx->params()[0]->AsConstructor()->AsTypeConstructor();
|
auto* tc = idx->params()[0]->As<ast::TypeConstructorExpression>();
|
||||||
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
EXPECT_TRUE(tc->type()->Is<ast::type::U32Type>());
|
||||||
ASSERT_EQ(tc->values().size(), 1u);
|
ASSERT_EQ(tc->values().size(), 1u);
|
||||||
ASSERT_EQ(tc->values()[0], access_idx);
|
ASSERT_EQ(tc->values()[0], access_idx);
|
||||||
|
|
||||||
ASSERT_TRUE(idx->params()[1]->IsConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(idx->params()[1]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(idx->params()[1]->Is<ast::ScalarConstructorExpression>());
|
||||||
scalar = idx->params()[1]->AsConstructor()->AsScalarConstructor();
|
scalar = idx->params()[1]->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
||||||
|
|
||||||
|
@ -836,24 +840,24 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Column) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->array()->IsArrayAccessor());
|
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
|
||||||
auto* ary = ptr->array()->AsArrayAccessor();
|
auto* ary = ptr->array()->As<ast::ArrayAccessorExpression>();
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ary->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsSint());
|
ASSERT_TRUE(scalar->literal()->IsSint());
|
||||||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
||||||
|
|
||||||
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
||||||
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::I32Type>());
|
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::I32Type>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsSint());
|
ASSERT_TRUE(scalar->literal()->IsSint());
|
||||||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 1);
|
EXPECT_EQ(scalar->literal()->AsSint()->value(), 1);
|
||||||
|
|
||||||
|
@ -890,24 +894,24 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Row) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->array()->IsArrayAccessor());
|
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
|
||||||
auto* ary = ptr->array()->AsArrayAccessor();
|
auto* ary = ptr->array()->As<ast::ArrayAccessorExpression>();
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ary->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsSint());
|
ASSERT_TRUE(scalar->literal()->IsSint());
|
||||||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 2);
|
EXPECT_EQ(scalar->literal()->AsSint()->value(), 2);
|
||||||
|
|
||||||
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
||||||
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::I32Type>());
|
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::I32Type>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsSint());
|
ASSERT_TRUE(scalar->literal()->IsSint());
|
||||||
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
EXPECT_EQ(scalar->literal()->AsSint()->value(), 0);
|
||||||
|
|
||||||
|
@ -945,24 +949,24 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Column) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->array()->IsArrayAccessor());
|
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
|
||||||
auto* ary = ptr->array()->AsArrayAccessor();
|
auto* ary = ptr->array()->As<ast::ArrayAccessorExpression>();
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ary->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
||||||
|
|
||||||
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
||||||
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::U32Type>());
|
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::U32Type>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
||||||
|
|
||||||
|
@ -1000,24 +1004,24 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Row) {
|
||||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ASSERT_TRUE(manager()->Run());
|
ASSERT_TRUE(manager()->Run());
|
||||||
ASSERT_TRUE(ptr->IsArrayAccessor());
|
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->array()->IsArrayAccessor());
|
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
|
||||||
auto* ary = ptr->array()->AsArrayAccessor();
|
auto* ary = ptr->array()->As<ast::ArrayAccessorExpression>();
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
auto* scalar = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* scalar = ary->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 2u);
|
||||||
|
|
||||||
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
ASSERT_NE(ary->idx_expr()->result_type(), nullptr);
|
||||||
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::U32Type>());
|
ASSERT_TRUE(ary->idx_expr()->result_type()->Is<ast::type::U32Type>());
|
||||||
|
|
||||||
ASSERT_TRUE(ptr->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||||
ASSERT_TRUE(ptr->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
|
||||||
|
|
||||||
scalar = ptr->idx_expr()->AsConstructor()->AsScalarConstructor();
|
scalar = ptr->idx_expr()->As<ast::ScalarConstructorExpression>();
|
||||||
ASSERT_TRUE(scalar->literal()->IsUint());
|
ASSERT_TRUE(scalar->literal()->IsUint());
|
||||||
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
EXPECT_EQ(scalar->literal()->AsUint()->value(), 1u);
|
||||||
|
|
||||||
|
|
|
@ -289,29 +289,29 @@ bool TypeDeterminer::DetermineResultType(ast::Expression* expr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expr->IsArrayAccessor()) {
|
if (auto* a = expr->As<ast::ArrayAccessorExpression>()) {
|
||||||
return DetermineArrayAccessor(expr->AsArrayAccessor());
|
return DetermineArrayAccessor(a);
|
||||||
}
|
}
|
||||||
if (expr->IsBinary()) {
|
if (auto* b = expr->As<ast::BinaryExpression>()) {
|
||||||
return DetermineBinary(expr->AsBinary());
|
return DetermineBinary(b);
|
||||||
}
|
}
|
||||||
if (expr->IsBitcast()) {
|
if (auto* b = expr->As<ast::BitcastExpression>()) {
|
||||||
return DetermineBitcast(expr->AsBitcast());
|
return DetermineBitcast(b);
|
||||||
}
|
}
|
||||||
if (expr->IsCall()) {
|
if (auto* c = expr->As<ast::CallExpression>()) {
|
||||||
return DetermineCall(expr->AsCall());
|
return DetermineCall(c);
|
||||||
}
|
}
|
||||||
if (expr->IsConstructor()) {
|
if (auto* c = expr->As<ast::ConstructorExpression>()) {
|
||||||
return DetermineConstructor(expr->AsConstructor());
|
return DetermineConstructor(c);
|
||||||
}
|
}
|
||||||
if (expr->IsIdentifier()) {
|
if (auto* i = expr->As<ast::IdentifierExpression>()) {
|
||||||
return DetermineIdentifier(expr->AsIdentifier());
|
return DetermineIdentifier(i);
|
||||||
}
|
}
|
||||||
if (expr->IsMemberAccessor()) {
|
if (auto* m = expr->As<ast::MemberAccessorExpression>()) {
|
||||||
return DetermineMemberAccessor(expr->AsMemberAccessor());
|
return DetermineMemberAccessor(m);
|
||||||
}
|
}
|
||||||
if (expr->IsUnaryOp()) {
|
if (auto* u = expr->As<ast::UnaryOpExpression>()) {
|
||||||
return DetermineUnaryOp(expr->AsUnaryOp());
|
return DetermineUnaryOp(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
set_error(expr->source(), "unknown expression for type determination");
|
set_error(expr->source(), "unknown expression for type determination");
|
||||||
|
@ -380,9 +380,7 @@ bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
|
||||||
// The expression has to be an identifier as you can't store function pointers
|
// The expression has to be an identifier as you can't store function pointers
|
||||||
// but, if it isn't we'll just use the normal result determination to be on
|
// but, if it isn't we'll just use the normal result determination to be on
|
||||||
// the safe side.
|
// the safe side.
|
||||||
if (expr->func()->IsIdentifier()) {
|
if (auto* ident = expr->func()->As<ast::IdentifierExpression>()) {
|
||||||
auto* ident = expr->func()->AsIdentifier();
|
|
||||||
|
|
||||||
if (ident->IsIntrinsic()) {
|
if (ident->IsIntrinsic()) {
|
||||||
if (!DetermineIntrinsic(ident, expr)) {
|
if (!DetermineIntrinsic(ident, expr)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -417,7 +415,7 @@ bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expr->func()->result_type()) {
|
if (!expr->func()->result_type()) {
|
||||||
auto func_name = expr->func()->AsIdentifier()->name();
|
auto func_name = expr->func()->As<ast::IdentifierExpression>()->name();
|
||||||
set_error(
|
set_error(
|
||||||
expr->source(),
|
expr->source(),
|
||||||
"v-0005: function must be declared before use: '" + func_name + "'");
|
"v-0005: function must be declared before use: '" + func_name + "'");
|
||||||
|
|
|
@ -394,8 +394,7 @@ bool ValidatorImpl::ValidateCallExpr(const ast::CallExpression* expr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expr->func()->IsIdentifier()) {
|
if (auto* ident = expr->func()->As<ast::IdentifierExpression>()) {
|
||||||
auto* ident = expr->func()->AsIdentifier();
|
|
||||||
auto func_name = ident->name();
|
auto func_name = ident->name();
|
||||||
if (ident->IsIntrinsic()) {
|
if (ident->IsIntrinsic()) {
|
||||||
// TODO(sarahM0): validate intrinsics - tied with type-determiner
|
// TODO(sarahM0): validate intrinsics - tied with type-determiner
|
||||||
|
@ -441,9 +440,8 @@ bool ValidatorImpl::ValidateConstant(const ast::AssignmentStatement* assign) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (assign->lhs()->IsIdentifier()) {
|
if (auto* ident = assign->lhs()->As<ast::IdentifierExpression>()) {
|
||||||
ast::Variable* var;
|
ast::Variable* var;
|
||||||
auto* ident = assign->lhs()->AsIdentifier();
|
|
||||||
if (variable_stack_.get(ident->name(), &var)) {
|
if (variable_stack_.get(ident->name(), &var)) {
|
||||||
if (var->is_const()) {
|
if (var->is_const()) {
|
||||||
add_error(assign->source(), "v-0021",
|
add_error(assign->source(), "v-0021",
|
||||||
|
@ -477,12 +475,12 @@ bool ValidatorImpl::ValidateExpression(const ast::Expression* expr) {
|
||||||
if (!expr) {
|
if (!expr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (expr->IsIdentifier()) {
|
if (auto* i = expr->As<ast::IdentifierExpression>()) {
|
||||||
return ValidateIdentifier(expr->AsIdentifier());
|
return ValidateIdentifier(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expr->IsCall()) {
|
if (auto* c = expr->As<ast::CallExpression>()) {
|
||||||
return ValidateCallExpr(expr->AsCall());
|
return ValidateCallExpr(c);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,12 +82,12 @@ bool last_is_break_or_fallthrough(const ast::BlockStatement* stmts) {
|
||||||
|
|
||||||
std::string get_buffer_name(ast::Expression* expr) {
|
std::string get_buffer_name(ast::Expression* expr) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (expr->IsIdentifier()) {
|
if (auto* ident = expr->As<ast::IdentifierExpression>()) {
|
||||||
return expr->AsIdentifier()->name();
|
return ident->name();
|
||||||
} else if (expr->IsMemberAccessor()) {
|
} else if (auto* member = expr->As<ast::MemberAccessorExpression>()) {
|
||||||
expr = expr->AsMemberAccessor()->structure();
|
expr = member->structure();
|
||||||
} else if (expr->IsArrayAccessor()) {
|
} else if (auto* array = expr->As<ast::ArrayAccessorExpression>()) {
|
||||||
expr = expr->AsArrayAccessor()->array();
|
expr = array->array();
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -299,8 +299,7 @@ bool GeneratorImpl::EmitAssign(std::ostream& out,
|
||||||
|
|
||||||
// If the LHS is an accessor into a storage buffer then we have to
|
// If the LHS is an accessor into a storage buffer then we have to
|
||||||
// emit a Store operation instead of an ='s.
|
// emit a Store operation instead of an ='s.
|
||||||
if (stmt->lhs()->IsMemberAccessor()) {
|
if (auto* mem = stmt->lhs()->As<ast::MemberAccessorExpression>()) {
|
||||||
auto* mem = stmt->lhs()->AsMemberAccessor();
|
|
||||||
if (is_storage_buffer_access(mem)) {
|
if (is_storage_buffer_access(mem)) {
|
||||||
std::ostringstream accessor_out;
|
std::ostringstream accessor_out;
|
||||||
if (!EmitStorageBufferAccessor(pre, accessor_out, mem, stmt->rhs())) {
|
if (!EmitStorageBufferAccessor(pre, accessor_out, mem, stmt->rhs())) {
|
||||||
|
@ -310,8 +309,7 @@ bool GeneratorImpl::EmitAssign(std::ostream& out,
|
||||||
out << accessor_out.str() << ";" << std::endl;
|
out << accessor_out.str() << ";" << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (stmt->lhs()->IsArrayAccessor()) {
|
} else if (auto* ary = stmt->lhs()->As<ast::ArrayAccessorExpression>()) {
|
||||||
auto* ary = stmt->lhs()->AsArrayAccessor();
|
|
||||||
if (is_storage_buffer_access(ary)) {
|
if (is_storage_buffer_access(ary)) {
|
||||||
std::ostringstream accessor_out;
|
std::ostringstream accessor_out;
|
||||||
if (!EmitStorageBufferAccessor(pre, accessor_out, ary, stmt->rhs())) {
|
if (!EmitStorageBufferAccessor(pre, accessor_out, ary, stmt->rhs())) {
|
||||||
|
@ -577,12 +575,12 @@ std::string GeneratorImpl::generate_intrinsic_name(ast::Intrinsic intrinsic) {
|
||||||
bool GeneratorImpl::EmitCall(std::ostream& pre,
|
bool GeneratorImpl::EmitCall(std::ostream& pre,
|
||||||
std::ostream& out,
|
std::ostream& out,
|
||||||
ast::CallExpression* expr) {
|
ast::CallExpression* expr) {
|
||||||
if (!expr->func()->IsIdentifier()) {
|
auto* ident = expr->func()->As<ast::IdentifierExpression>();
|
||||||
|
if (ident == nullptr) {
|
||||||
error_ = "invalid function name";
|
error_ = "invalid function name";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* ident = expr->func()->AsIdentifier();
|
|
||||||
if (ident->IsIntrinsic()) {
|
if (ident->IsIntrinsic()) {
|
||||||
const auto& params = expr->params();
|
const auto& params = expr->params();
|
||||||
if (ident->intrinsic() == ast::Intrinsic::kSelect) {
|
if (ident->intrinsic() == ast::Intrinsic::kSelect) {
|
||||||
|
@ -731,7 +729,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre,
|
||||||
ast::CallExpression* expr) {
|
ast::CallExpression* expr) {
|
||||||
make_indent(out);
|
make_indent(out);
|
||||||
|
|
||||||
auto* ident = expr->func()->AsIdentifier();
|
auto* ident = expr->func()->As<ast::IdentifierExpression>();
|
||||||
|
|
||||||
auto params = expr->params();
|
auto params = expr->params();
|
||||||
auto* signature = static_cast<const ast::intrinsic::TextureSignature*>(
|
auto* signature = static_cast<const ast::intrinsic::TextureSignature*>(
|
||||||
|
@ -801,7 +799,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre,
|
||||||
|
|
||||||
std::string GeneratorImpl::generate_builtin_name(ast::CallExpression* expr) {
|
std::string GeneratorImpl::generate_builtin_name(ast::CallExpression* expr) {
|
||||||
std::string out;
|
std::string out;
|
||||||
auto* ident = expr->func()->AsIdentifier();
|
auto* ident = expr->func()->As<ast::IdentifierExpression>();
|
||||||
switch (ident->intrinsic()) {
|
switch (ident->intrinsic()) {
|
||||||
case ast::Intrinsic::kAcos:
|
case ast::Intrinsic::kAcos:
|
||||||
case ast::Intrinsic::kAsin:
|
case ast::Intrinsic::kAsin:
|
||||||
|
@ -976,29 +974,29 @@ bool GeneratorImpl::EmitDiscard(std::ostream& out, ast::DiscardStatement*) {
|
||||||
bool GeneratorImpl::EmitExpression(std::ostream& pre,
|
bool GeneratorImpl::EmitExpression(std::ostream& pre,
|
||||||
std::ostream& out,
|
std::ostream& out,
|
||||||
ast::Expression* expr) {
|
ast::Expression* expr) {
|
||||||
if (expr->IsArrayAccessor()) {
|
if (auto* a = expr->As<ast::ArrayAccessorExpression>()) {
|
||||||
return EmitArrayAccessor(pre, out, expr->AsArrayAccessor());
|
return EmitArrayAccessor(pre, out, a);
|
||||||
}
|
}
|
||||||
if (expr->IsBinary()) {
|
if (auto* b = expr->As<ast::BinaryExpression>()) {
|
||||||
return EmitBinary(pre, out, expr->AsBinary());
|
return EmitBinary(pre, out, b);
|
||||||
}
|
}
|
||||||
if (expr->IsBitcast()) {
|
if (auto* b = expr->As<ast::BitcastExpression>()) {
|
||||||
return EmitBitcast(pre, out, expr->AsBitcast());
|
return EmitBitcast(pre, out, b);
|
||||||
}
|
}
|
||||||
if (expr->IsCall()) {
|
if (auto* c = expr->As<ast::CallExpression>()) {
|
||||||
return EmitCall(pre, out, expr->AsCall());
|
return EmitCall(pre, out, c);
|
||||||
}
|
}
|
||||||
if (expr->IsConstructor()) {
|
if (auto* c = expr->As<ast::ConstructorExpression>()) {
|
||||||
return EmitConstructor(pre, out, expr->AsConstructor());
|
return EmitConstructor(pre, out, c);
|
||||||
}
|
}
|
||||||
if (expr->IsIdentifier()) {
|
if (auto* i = expr->As<ast::IdentifierExpression>()) {
|
||||||
return EmitIdentifier(pre, out, expr->AsIdentifier());
|
return EmitIdentifier(pre, out, i);
|
||||||
}
|
}
|
||||||
if (expr->IsMemberAccessor()) {
|
if (auto* m = expr->As<ast::MemberAccessorExpression>()) {
|
||||||
return EmitMemberAccessor(pre, out, expr->AsMemberAccessor());
|
return EmitMemberAccessor(pre, out, m);
|
||||||
}
|
}
|
||||||
if (expr->IsUnaryOp()) {
|
if (auto* u = expr->As<ast::UnaryOpExpression>()) {
|
||||||
return EmitUnaryOp(pre, out, expr->AsUnaryOp());
|
return EmitUnaryOp(pre, out, u);
|
||||||
}
|
}
|
||||||
|
|
||||||
error_ = "unknown expression type: " + expr->str();
|
error_ = "unknown expression type: " + expr->str();
|
||||||
|
@ -1016,7 +1014,7 @@ bool GeneratorImpl::global_is_in_struct(ast::Variable* var) const {
|
||||||
bool GeneratorImpl::EmitIdentifier(std::ostream&,
|
bool GeneratorImpl::EmitIdentifier(std::ostream&,
|
||||||
std::ostream& out,
|
std::ostream& out,
|
||||||
ast::IdentifierExpression* expr) {
|
ast::IdentifierExpression* expr) {
|
||||||
auto* ident = expr->AsIdentifier();
|
auto* ident = expr->As<ast::IdentifierExpression>();
|
||||||
ast::Variable* var = nullptr;
|
ast::Variable* var = nullptr;
|
||||||
if (global_variables_.get(ident->name(), &var)) {
|
if (global_variables_.get(ident->name(), &var)) {
|
||||||
if (global_is_in_struct(var)) {
|
if (global_is_in_struct(var)) {
|
||||||
|
@ -1683,7 +1681,7 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression(
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (expr->IsIdentifier()) {
|
if (expr->Is<ast::IdentifierExpression>()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1691,8 +1689,7 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression(
|
||||||
out << " + ";
|
out << " + ";
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
if (expr->IsMemberAccessor()) {
|
if (auto* mem = expr->As<ast::MemberAccessorExpression>()) {
|
||||||
auto* mem = expr->AsMemberAccessor();
|
|
||||||
auto* res_type = mem->structure()->result_type()->UnwrapAll();
|
auto* res_type = mem->structure()->result_type()->UnwrapAll();
|
||||||
if (res_type->Is<ast::type::StructType>()) {
|
if (res_type->Is<ast::type::StructType>()) {
|
||||||
auto* str_type = res_type->As<ast::type::StructType>()->impl();
|
auto* str_type = res_type->As<ast::type::StructType>()->impl();
|
||||||
|
@ -1726,8 +1723,7 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression(
|
||||||
}
|
}
|
||||||
|
|
||||||
expr = mem->structure();
|
expr = mem->structure();
|
||||||
} else if (expr->IsArrayAccessor()) {
|
} else if (auto* ary = expr->As<ast::ArrayAccessorExpression>()) {
|
||||||
auto* ary = expr->AsArrayAccessor();
|
|
||||||
auto* ary_type = ary->array()->result_type()->UnwrapAll();
|
auto* ary_type = ary->array()->result_type()->UnwrapAll();
|
||||||
|
|
||||||
out << "(";
|
out << "(";
|
||||||
|
@ -1885,10 +1881,10 @@ bool GeneratorImpl::is_storage_buffer_access(
|
||||||
// If it isn't an array or a member accessor we can stop looking as it won't
|
// If it isn't an array or a member accessor we can stop looking as it won't
|
||||||
// be a storage buffer.
|
// be a storage buffer.
|
||||||
auto* ary = expr->array();
|
auto* ary = expr->array();
|
||||||
if (ary->IsMemberAccessor()) {
|
if (auto* member = ary->As<ast::MemberAccessorExpression>()) {
|
||||||
return is_storage_buffer_access(ary->AsMemberAccessor());
|
return is_storage_buffer_access(member);
|
||||||
} else if (ary->IsArrayAccessor()) {
|
} else if (auto* array = ary->As<ast::ArrayAccessorExpression>()) {
|
||||||
return is_storage_buffer_access(ary->AsArrayAccessor());
|
return is_storage_buffer_access(array);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1905,17 +1901,16 @@ bool GeneratorImpl::is_storage_buffer_access(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is a storage buffer variable
|
// Check if this is a storage buffer variable
|
||||||
if (structure->IsIdentifier()) {
|
if (auto* ident = expr->structure()->As<ast::IdentifierExpression>()) {
|
||||||
auto* ident = expr->structure()->AsIdentifier();
|
|
||||||
ast::Variable* var = nullptr;
|
ast::Variable* var = nullptr;
|
||||||
if (!global_variables_.get(ident->name(), &var)) {
|
if (!global_variables_.get(ident->name(), &var)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return var->storage_class() == ast::StorageClass::kStorageBuffer;
|
return var->storage_class() == ast::StorageClass::kStorageBuffer;
|
||||||
} else if (structure->IsMemberAccessor()) {
|
} else if (auto* member = structure->As<ast::MemberAccessorExpression>()) {
|
||||||
return is_storage_buffer_access(structure->AsMemberAccessor());
|
return is_storage_buffer_access(member);
|
||||||
} else if (structure->IsArrayAccessor()) {
|
} else if (auto* array = structure->As<ast::ArrayAccessorExpression>()) {
|
||||||
return is_storage_buffer_access(structure->AsArrayAccessor());
|
return is_storage_buffer_access(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Technically I don't think this is possible, but if we don't have a struct
|
// Technically I don't think this is possible, but if we don't have a struct
|
||||||
|
|
|
@ -19,21 +19,28 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
#include "src/ast/array_accessor_expression.h"
|
||||||
#include "src/ast/assignment_statement.h"
|
#include "src/ast/assignment_statement.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
|
#include "src/ast/bitcast_expression.h"
|
||||||
#include "src/ast/break_statement.h"
|
#include "src/ast/break_statement.h"
|
||||||
|
#include "src/ast/call_expression.h"
|
||||||
#include "src/ast/case_statement.h"
|
#include "src/ast/case_statement.h"
|
||||||
#include "src/ast/continue_statement.h"
|
#include "src/ast/continue_statement.h"
|
||||||
#include "src/ast/discard_statement.h"
|
#include "src/ast/discard_statement.h"
|
||||||
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/if_statement.h"
|
#include "src/ast/if_statement.h"
|
||||||
#include "src/ast/intrinsic.h"
|
#include "src/ast/intrinsic.h"
|
||||||
#include "src/ast/literal.h"
|
#include "src/ast/literal.h"
|
||||||
#include "src/ast/loop_statement.h"
|
#include "src/ast/loop_statement.h"
|
||||||
|
#include "src/ast/member_accessor_expression.h"
|
||||||
#include "src/ast/module.h"
|
#include "src/ast/module.h"
|
||||||
#include "src/ast/return_statement.h"
|
#include "src/ast/return_statement.h"
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
#include "src/ast/switch_statement.h"
|
#include "src/ast/switch_statement.h"
|
||||||
#include "src/ast/type/struct_type.h"
|
#include "src/ast/type/struct_type.h"
|
||||||
#include "src/ast/type_constructor_expression.h"
|
#include "src/ast/type_constructor_expression.h"
|
||||||
|
#include "src/ast/unary_op_expression.h"
|
||||||
#include "src/context.h"
|
#include "src/context.h"
|
||||||
#include "src/scope_stack.h"
|
#include "src/scope_stack.h"
|
||||||
#include "src/writer/hlsl/namer.h"
|
#include "src/writer/hlsl/namer.h"
|
||||||
|
|
|
@ -484,12 +484,13 @@ std::string GeneratorImpl::generate_intrinsic_name(ast::Intrinsic intrinsic) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
|
bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
|
||||||
if (!expr->func()->IsIdentifier()) {
|
auto* ident = expr->func()->As<ast::IdentifierExpression>();
|
||||||
|
|
||||||
|
if (ident == nullptr) {
|
||||||
error_ = "invalid function name";
|
error_ = "invalid function name";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* ident = expr->func()->AsIdentifier();
|
|
||||||
if (ident->IsIntrinsic()) {
|
if (ident->IsIntrinsic()) {
|
||||||
const auto& params = expr->params();
|
const auto& params = expr->params();
|
||||||
if (ident->intrinsic() == ast::Intrinsic::kOuterProduct) {
|
if (ident->intrinsic() == ast::Intrinsic::kOuterProduct) {
|
||||||
|
@ -658,7 +659,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorImpl::EmitTextureCall(ast::CallExpression* expr) {
|
bool GeneratorImpl::EmitTextureCall(ast::CallExpression* expr) {
|
||||||
auto* ident = expr->func()->AsIdentifier();
|
auto* ident = expr->func()->As<ast::IdentifierExpression>();
|
||||||
|
|
||||||
auto params = expr->params();
|
auto params = expr->params();
|
||||||
auto* signature = static_cast<const ast::intrinsic::TextureSignature*>(
|
auto* signature = static_cast<const ast::intrinsic::TextureSignature*>(
|
||||||
|
@ -1094,29 +1095,29 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorImpl::EmitExpression(ast::Expression* expr) {
|
bool GeneratorImpl::EmitExpression(ast::Expression* expr) {
|
||||||
if (expr->IsArrayAccessor()) {
|
if (auto* a = expr->As<ast::ArrayAccessorExpression>()) {
|
||||||
return EmitArrayAccessor(expr->AsArrayAccessor());
|
return EmitArrayAccessor(a);
|
||||||
}
|
}
|
||||||
if (expr->IsBinary()) {
|
if (auto* b = expr->As<ast::BinaryExpression>()) {
|
||||||
return EmitBinary(expr->AsBinary());
|
return EmitBinary(b);
|
||||||
}
|
}
|
||||||
if (expr->IsBitcast()) {
|
if (auto* b = expr->As<ast::BitcastExpression>()) {
|
||||||
return EmitBitcast(expr->AsBitcast());
|
return EmitBitcast(b);
|
||||||
}
|
}
|
||||||
if (expr->IsCall()) {
|
if (auto* c = expr->As<ast::CallExpression>()) {
|
||||||
return EmitCall(expr->AsCall());
|
return EmitCall(c);
|
||||||
}
|
}
|
||||||
if (expr->IsConstructor()) {
|
if (auto* c = expr->As<ast::ConstructorExpression>()) {
|
||||||
return EmitConstructor(expr->AsConstructor());
|
return EmitConstructor(c);
|
||||||
}
|
}
|
||||||
if (expr->IsIdentifier()) {
|
if (auto* i = expr->As<ast::IdentifierExpression>()) {
|
||||||
return EmitIdentifier(expr->AsIdentifier());
|
return EmitIdentifier(i);
|
||||||
}
|
}
|
||||||
if (expr->IsMemberAccessor()) {
|
if (auto* m = expr->As<ast::MemberAccessorExpression>()) {
|
||||||
return EmitMemberAccessor(expr->AsMemberAccessor());
|
return EmitMemberAccessor(m);
|
||||||
}
|
}
|
||||||
if (expr->IsUnaryOp()) {
|
if (auto* u = expr->As<ast::UnaryOpExpression>()) {
|
||||||
return EmitUnaryOp(expr->AsUnaryOp());
|
return EmitUnaryOp(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
error_ = "unknown expression type: " + expr->str();
|
error_ = "unknown expression type: " + expr->str();
|
||||||
|
@ -1501,7 +1502,7 @@ bool GeneratorImpl::global_is_in_struct(ast::Variable* var) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) {
|
bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) {
|
||||||
auto* ident = expr->AsIdentifier();
|
auto* ident = expr->As<ast::IdentifierExpression>();
|
||||||
ast::Variable* var = nullptr;
|
ast::Variable* var = nullptr;
|
||||||
if (global_variables_.get(ident->name(), &var)) {
|
if (global_variables_.get(ident->name(), &var)) {
|
||||||
if (global_is_in_struct(var)) {
|
if (global_is_in_struct(var)) {
|
||||||
|
|
|
@ -19,22 +19,29 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "src/ast/array_accessor_expression.h"
|
||||||
#include "src/ast/assignment_statement.h"
|
#include "src/ast/assignment_statement.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
|
#include "src/ast/bitcast_expression.h"
|
||||||
#include "src/ast/break_statement.h"
|
#include "src/ast/break_statement.h"
|
||||||
|
#include "src/ast/call_expression.h"
|
||||||
#include "src/ast/case_statement.h"
|
#include "src/ast/case_statement.h"
|
||||||
#include "src/ast/continue_statement.h"
|
#include "src/ast/continue_statement.h"
|
||||||
#include "src/ast/discard_statement.h"
|
#include "src/ast/discard_statement.h"
|
||||||
#include "src/ast/else_statement.h"
|
#include "src/ast/else_statement.h"
|
||||||
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/if_statement.h"
|
#include "src/ast/if_statement.h"
|
||||||
#include "src/ast/intrinsic.h"
|
#include "src/ast/intrinsic.h"
|
||||||
#include "src/ast/literal.h"
|
#include "src/ast/literal.h"
|
||||||
#include "src/ast/loop_statement.h"
|
#include "src/ast/loop_statement.h"
|
||||||
|
#include "src/ast/member_accessor_expression.h"
|
||||||
#include "src/ast/module.h"
|
#include "src/ast/module.h"
|
||||||
#include "src/ast/return_statement.h"
|
#include "src/ast/return_statement.h"
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
#include "src/ast/switch_statement.h"
|
#include "src/ast/switch_statement.h"
|
||||||
#include "src/ast/type/struct_type.h"
|
#include "src/ast/type/struct_type.h"
|
||||||
#include "src/ast/type_constructor_expression.h"
|
#include "src/ast/type_constructor_expression.h"
|
||||||
|
#include "src/ast/unary_op_expression.h"
|
||||||
#include "src/scope_stack.h"
|
#include "src/scope_stack.h"
|
||||||
#include "src/writer/msl/namer.h"
|
#include "src/writer/msl/namer.h"
|
||||||
#include "src/writer/text_generator.h"
|
#include "src/writer/text_generator.h"
|
||||||
|
|
|
@ -26,13 +26,10 @@ namespace writer {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
ast::TypeConstructorExpression* AsVectorConstructor(ast::Expression* expr) {
|
ast::TypeConstructorExpression* AsVectorConstructor(ast::Expression* expr) {
|
||||||
if (!expr->IsConstructor())
|
auto* type_constructor = expr->As<ast::TypeConstructorExpression>();
|
||||||
return nullptr;
|
if (type_constructor == nullptr) {
|
||||||
auto* constructor = expr->AsConstructor();
|
|
||||||
if (!constructor->IsTypeConstructor()) {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto* type_constructor = constructor->AsTypeConstructor();
|
|
||||||
if (!type_constructor->type()->Is<ast::type::VectorType>()) {
|
if (!type_constructor->type()->Is<ast::type::VectorType>()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -484,29 +484,29 @@ bool Builder::GenerateExecutionModes(ast::Function* func, uint32_t id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Builder::GenerateExpression(ast::Expression* expr) {
|
uint32_t Builder::GenerateExpression(ast::Expression* expr) {
|
||||||
if (expr->IsArrayAccessor()) {
|
if (auto* a = expr->As<ast::ArrayAccessorExpression>()) {
|
||||||
return GenerateAccessorExpression(expr->AsArrayAccessor());
|
return GenerateAccessorExpression(a);
|
||||||
}
|
}
|
||||||
if (expr->IsBinary()) {
|
if (auto* b = expr->As<ast::BinaryExpression>()) {
|
||||||
return GenerateBinaryExpression(expr->AsBinary());
|
return GenerateBinaryExpression(b);
|
||||||
}
|
}
|
||||||
if (expr->IsBitcast()) {
|
if (auto* b = expr->As<ast::BitcastExpression>()) {
|
||||||
return GenerateBitcastExpression(expr->AsBitcast());
|
return GenerateBitcastExpression(b);
|
||||||
}
|
}
|
||||||
if (expr->IsCall()) {
|
if (auto* c = expr->As<ast::CallExpression>()) {
|
||||||
return GenerateCallExpression(expr->AsCall());
|
return GenerateCallExpression(c);
|
||||||
}
|
}
|
||||||
if (expr->IsConstructor()) {
|
if (auto* c = expr->As<ast::ConstructorExpression>()) {
|
||||||
return GenerateConstructorExpression(nullptr, expr->AsConstructor(), false);
|
return GenerateConstructorExpression(nullptr, c, false);
|
||||||
}
|
}
|
||||||
if (expr->IsIdentifier()) {
|
if (auto* i = expr->As<ast::IdentifierExpression>()) {
|
||||||
return GenerateIdentifierExpression(expr->AsIdentifier());
|
return GenerateIdentifierExpression(i);
|
||||||
}
|
}
|
||||||
if (expr->IsMemberAccessor()) {
|
if (auto* m = expr->As<ast::MemberAccessorExpression>()) {
|
||||||
return GenerateAccessorExpression(expr->AsMemberAccessor());
|
return GenerateAccessorExpression(m);
|
||||||
}
|
}
|
||||||
if (expr->IsUnaryOp()) {
|
if (auto* u = expr->As<ast::UnaryOpExpression>()) {
|
||||||
return GenerateUnaryOpExpression(expr->AsUnaryOp());
|
return GenerateUnaryOpExpression(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
error_ = "unknown expression type: " + expr->str();
|
error_ = "unknown expression type: " + expr->str();
|
||||||
|
@ -672,13 +672,13 @@ void Builder::GenerateStore(uint32_t to, uint32_t from) {
|
||||||
bool Builder::GenerateGlobalVariable(ast::Variable* var) {
|
bool Builder::GenerateGlobalVariable(ast::Variable* var) {
|
||||||
uint32_t init_id = 0;
|
uint32_t init_id = 0;
|
||||||
if (var->has_constructor()) {
|
if (var->has_constructor()) {
|
||||||
if (!var->constructor()->IsConstructor()) {
|
if (!var->constructor()->Is<ast::ConstructorExpression>()) {
|
||||||
error_ = "scalar constructor expected";
|
error_ = "scalar constructor expected";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
init_id = GenerateConstructorExpression(
|
init_id = GenerateConstructorExpression(
|
||||||
var, var->constructor()->AsConstructor(), true);
|
var, var->constructor()->As<ast::ConstructorExpression>(), true);
|
||||||
if (init_id == 0) {
|
if (init_id == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -981,7 +981,8 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr,
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Builder::GenerateAccessorExpression(ast::Expression* expr) {
|
uint32_t Builder::GenerateAccessorExpression(ast::Expression* expr) {
|
||||||
assert(expr->IsArrayAccessor() || expr->IsMemberAccessor());
|
assert(expr->Is<ast::ArrayAccessorExpression>() ||
|
||||||
|
expr->Is<ast::MemberAccessorExpression>());
|
||||||
|
|
||||||
// Gather a list of all the member and array accessors that are in this chain.
|
// Gather a list of all the member and array accessors that are in this chain.
|
||||||
// The list is built in reverse order as that's the order we need to access
|
// The list is built in reverse order as that's the order we need to access
|
||||||
|
@ -989,12 +990,12 @@ uint32_t Builder::GenerateAccessorExpression(ast::Expression* expr) {
|
||||||
std::vector<ast::Expression*> accessors;
|
std::vector<ast::Expression*> accessors;
|
||||||
ast::Expression* source = expr;
|
ast::Expression* source = expr;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (source->IsArrayAccessor()) {
|
if (auto* array = source->As<ast::ArrayAccessorExpression>()) {
|
||||||
accessors.insert(accessors.begin(), source);
|
accessors.insert(accessors.begin(), source);
|
||||||
source = source->AsArrayAccessor()->array();
|
source = array->array();
|
||||||
} else if (source->IsMemberAccessor()) {
|
} else if (auto* member = source->As<ast::MemberAccessorExpression>()) {
|
||||||
accessors.insert(accessors.begin(), source);
|
accessors.insert(accessors.begin(), source);
|
||||||
source = source->AsMemberAccessor()->structure();
|
source = member->structure();
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1010,9 +1011,8 @@ uint32_t Builder::GenerateAccessorExpression(ast::Expression* expr) {
|
||||||
// If our initial access is into an array of non-scalar types, and that array
|
// If our initial access is into an array of non-scalar types, and that array
|
||||||
// is not a pointer, then we need to load that array into a variable in order
|
// is not a pointer, then we need to load that array into a variable in order
|
||||||
// to access chain into the array.
|
// to access chain into the array.
|
||||||
if (accessors[0]->IsArrayAccessor()) {
|
if (auto* array = accessors[0]->As<ast::ArrayAccessorExpression>()) {
|
||||||
auto* ary_res_type =
|
auto* ary_res_type = array->array()->result_type();
|
||||||
accessors[0]->AsArrayAccessor()->array()->result_type();
|
|
||||||
|
|
||||||
if (!ary_res_type->Is<ast::type::PointerType>() &&
|
if (!ary_res_type->Is<ast::type::PointerType>() &&
|
||||||
(ary_res_type->Is<ast::type::ArrayType>() &&
|
(ary_res_type->Is<ast::type::ArrayType>() &&
|
||||||
|
@ -1043,12 +1043,12 @@ uint32_t Builder::GenerateAccessorExpression(ast::Expression* expr) {
|
||||||
|
|
||||||
std::vector<uint32_t> access_chain_indices;
|
std::vector<uint32_t> access_chain_indices;
|
||||||
for (auto* accessor : accessors) {
|
for (auto* accessor : accessors) {
|
||||||
if (accessor->IsArrayAccessor()) {
|
if (auto* array = accessor->As<ast::ArrayAccessorExpression>()) {
|
||||||
if (!GenerateArrayAccessor(accessor->AsArrayAccessor(), &info)) {
|
if (!GenerateArrayAccessor(array, &info)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (accessor->IsMemberAccessor()) {
|
} else if (auto* member = accessor->As<ast::MemberAccessorExpression>()) {
|
||||||
if (!GenerateMemberAccessor(accessor->AsMemberAccessor(), &info)) {
|
if (!GenerateMemberAccessor(member, &info)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1170,19 +1170,20 @@ uint32_t Builder::GenerateConstructorExpression(
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) {
|
bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) {
|
||||||
if (!expr->IsConstructor()) {
|
auto* constructor = expr->As<ast::ConstructorExpression>();
|
||||||
|
if (constructor == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (expr->AsConstructor()->IsScalarConstructor()) {
|
if (constructor->Is<ast::ScalarConstructorExpression>()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* tc = expr->AsConstructor()->AsTypeConstructor();
|
auto* tc = constructor->AsTypeConstructor();
|
||||||
auto* result_type = tc->type()->UnwrapAll();
|
auto* result_type = tc->type()->UnwrapAll();
|
||||||
for (size_t i = 0; i < tc->values().size(); ++i) {
|
for (size_t i = 0; i < tc->values().size(); ++i) {
|
||||||
auto* e = tc->values()[i];
|
auto* e = tc->values()[i];
|
||||||
|
|
||||||
if (!e->IsConstructor()) {
|
if (!e->Is<ast::ConstructorExpression>()) {
|
||||||
if (is_global_init) {
|
if (is_global_init) {
|
||||||
error_ = "constructor must be a constant expression";
|
error_ = "constructor must be a constant expression";
|
||||||
return false;
|
return false;
|
||||||
|
@ -1197,16 +1198,16 @@ bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result_type->Is<ast::type::VectorType>() &&
|
if (result_type->Is<ast::type::VectorType>() &&
|
||||||
!e->AsConstructor()->IsScalarConstructor()) {
|
!e->Is<ast::ScalarConstructorExpression>()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This should all be handled by |is_constructor_const| call above
|
// This should all be handled by |is_constructor_const| call above
|
||||||
if (!e->AsConstructor()->IsScalarConstructor()) {
|
if (!e->Is<ast::ScalarConstructorExpression>()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* sc = e->AsConstructor()->AsScalarConstructor();
|
auto* sc = e->As<ast::ScalarConstructorExpression>();
|
||||||
ast::type::Type* subtype = result_type->UnwrapAll();
|
ast::type::Type* subtype = result_type->UnwrapAll();
|
||||||
if (subtype->Is<ast::type::VectorType>()) {
|
if (subtype->Is<ast::type::VectorType>()) {
|
||||||
subtype = subtype->As<ast::type::VectorType>()->type()->UnwrapAll();
|
subtype = subtype->As<ast::type::VectorType>()->type()->UnwrapAll();
|
||||||
|
@ -1279,8 +1280,8 @@ uint32_t Builder::GenerateTypeConstructorExpression(
|
||||||
for (auto* e : values) {
|
for (auto* e : values) {
|
||||||
uint32_t id = 0;
|
uint32_t id = 0;
|
||||||
if (constructor_is_const) {
|
if (constructor_is_const) {
|
||||||
id = GenerateConstructorExpression(nullptr, e->AsConstructor(),
|
id = GenerateConstructorExpression(
|
||||||
is_global_init);
|
nullptr, e->As<ast::ConstructorExpression>(), is_global_init);
|
||||||
} else {
|
} else {
|
||||||
id = GenerateExpression(e);
|
id = GenerateExpression(e);
|
||||||
id = GenerateLoadIfNeeded(e->result_type(), id);
|
id = GenerateLoadIfNeeded(e->result_type(), id);
|
||||||
|
@ -1751,13 +1752,13 @@ bool Builder::GenerateBlockStatement(const ast::BlockStatement* stmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Builder::GenerateCallExpression(ast::CallExpression* expr) {
|
uint32_t Builder::GenerateCallExpression(ast::CallExpression* expr) {
|
||||||
if (!expr->func()->IsIdentifier()) {
|
auto* ident = expr->func()->As<ast::IdentifierExpression>();
|
||||||
|
|
||||||
|
if (ident == nullptr) {
|
||||||
error_ = "invalid function name";
|
error_ = "invalid function name";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* ident = expr->func()->AsIdentifier();
|
|
||||||
|
|
||||||
if (ident->IsIntrinsic()) {
|
if (ident->IsIntrinsic()) {
|
||||||
return GenerateIntrinsic(ident, expr);
|
return GenerateIntrinsic(ident, expr);
|
||||||
}
|
}
|
||||||
|
@ -1826,7 +1827,7 @@ uint32_t Builder::GenerateIntrinsic(ast::IdentifierExpression* ident,
|
||||||
if (call->params().empty()) {
|
if (call->params().empty()) {
|
||||||
error_ = "missing param for runtime array length";
|
error_ = "missing param for runtime array length";
|
||||||
return 0;
|
return 0;
|
||||||
} else if (!call->params()[0]->IsMemberAccessor()) {
|
} else if (!call->params()[0]->Is<ast::MemberAccessorExpression>()) {
|
||||||
if (call->params()[0]->result_type()->Is<ast::type::PointerType>()) {
|
if (call->params()[0]->result_type()->Is<ast::type::PointerType>()) {
|
||||||
error_ = "pointer accessors not supported yet";
|
error_ = "pointer accessors not supported yet";
|
||||||
} else {
|
} else {
|
||||||
|
@ -1834,7 +1835,7 @@ uint32_t Builder::GenerateIntrinsic(ast::IdentifierExpression* ident,
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
auto* accessor = call->params()[0]->AsMemberAccessor();
|
auto* accessor = call->params()[0]->As<ast::MemberAccessorExpression>();
|
||||||
auto struct_id = GenerateExpression(accessor->structure());
|
auto struct_id = GenerateExpression(accessor->structure());
|
||||||
if (struct_id == 0) {
|
if (struct_id == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -22,15 +22,21 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "spirv/unified1/spirv.h"
|
#include "spirv/unified1/spirv.h"
|
||||||
|
#include "src/ast/array_accessor_expression.h"
|
||||||
#include "src/ast/assignment_statement.h"
|
#include "src/ast/assignment_statement.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
|
#include "src/ast/bitcast_expression.h"
|
||||||
#include "src/ast/break_statement.h"
|
#include "src/ast/break_statement.h"
|
||||||
#include "src/ast/builtin.h"
|
#include "src/ast/builtin.h"
|
||||||
|
#include "src/ast/call_expression.h"
|
||||||
#include "src/ast/continue_statement.h"
|
#include "src/ast/continue_statement.h"
|
||||||
#include "src/ast/discard_statement.h"
|
#include "src/ast/discard_statement.h"
|
||||||
#include "src/ast/else_statement.h"
|
#include "src/ast/else_statement.h"
|
||||||
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/if_statement.h"
|
#include "src/ast/if_statement.h"
|
||||||
#include "src/ast/literal.h"
|
#include "src/ast/literal.h"
|
||||||
#include "src/ast/loop_statement.h"
|
#include "src/ast/loop_statement.h"
|
||||||
|
#include "src/ast/member_accessor_expression.h"
|
||||||
#include "src/ast/module.h"
|
#include "src/ast/module.h"
|
||||||
#include "src/ast/return_statement.h"
|
#include "src/ast/return_statement.h"
|
||||||
#include "src/ast/struct_member.h"
|
#include "src/ast/struct_member.h"
|
||||||
|
@ -43,6 +49,7 @@
|
||||||
#include "src/ast/type/struct_type.h"
|
#include "src/ast/type/struct_type.h"
|
||||||
#include "src/ast/type/vector_type.h"
|
#include "src/ast/type/vector_type.h"
|
||||||
#include "src/ast/type_constructor_expression.h"
|
#include "src/ast/type_constructor_expression.h"
|
||||||
|
#include "src/ast/unary_op_expression.h"
|
||||||
#include "src/ast/variable_decl_statement.h"
|
#include "src/ast/variable_decl_statement.h"
|
||||||
#include "src/context.h"
|
#include "src/context.h"
|
||||||
#include "src/scope_stack.h"
|
#include "src/scope_stack.h"
|
||||||
|
|
|
@ -193,29 +193,29 @@ bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorImpl::EmitExpression(ast::Expression* expr) {
|
bool GeneratorImpl::EmitExpression(ast::Expression* expr) {
|
||||||
if (expr->IsArrayAccessor()) {
|
if (auto* a = expr->As<ast::ArrayAccessorExpression>()) {
|
||||||
return EmitArrayAccessor(expr->AsArrayAccessor());
|
return EmitArrayAccessor(a);
|
||||||
}
|
}
|
||||||
if (expr->IsBinary()) {
|
if (auto* b = expr->As<ast::BinaryExpression>()) {
|
||||||
return EmitBinary(expr->AsBinary());
|
return EmitBinary(b);
|
||||||
}
|
}
|
||||||
if (expr->IsBitcast()) {
|
if (auto* b = expr->As<ast::BitcastExpression>()) {
|
||||||
return EmitBitcast(expr->AsBitcast());
|
return EmitBitcast(b);
|
||||||
}
|
}
|
||||||
if (expr->IsCall()) {
|
if (auto* c = expr->As<ast::CallExpression>()) {
|
||||||
return EmitCall(expr->AsCall());
|
return EmitCall(c);
|
||||||
}
|
}
|
||||||
if (expr->IsIdentifier()) {
|
if (auto* i = expr->As<ast::IdentifierExpression>()) {
|
||||||
return EmitIdentifier(expr->AsIdentifier());
|
return EmitIdentifier(i);
|
||||||
}
|
}
|
||||||
if (expr->IsConstructor()) {
|
if (auto* c = expr->As<ast::ConstructorExpression>()) {
|
||||||
return EmitConstructor(expr->AsConstructor());
|
return EmitConstructor(c);
|
||||||
}
|
}
|
||||||
if (expr->IsMemberAccessor()) {
|
if (auto* m = expr->As<ast::MemberAccessorExpression>()) {
|
||||||
return EmitMemberAccessor(expr->AsMemberAccessor());
|
return EmitMemberAccessor(m);
|
||||||
}
|
}
|
||||||
if (expr->IsUnaryOp()) {
|
if (auto* u = expr->As<ast::UnaryOpExpression>()) {
|
||||||
return EmitUnaryOp(expr->AsUnaryOp());
|
return EmitUnaryOp(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
error_ = "unknown expression type";
|
error_ = "unknown expression type";
|
||||||
|
@ -337,7 +337,7 @@ bool GeneratorImpl::EmitLiteral(ast::Literal* lit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) {
|
bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) {
|
||||||
auto* ident = expr->AsIdentifier();
|
auto* ident = expr->As<ast::IdentifierExpression>();
|
||||||
out_ << ident->name();
|
out_ << ident->name();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,10 @@
|
||||||
|
|
||||||
#include "src/ast/array_accessor_expression.h"
|
#include "src/ast/array_accessor_expression.h"
|
||||||
#include "src/ast/assignment_statement.h"
|
#include "src/ast/assignment_statement.h"
|
||||||
|
#include "src/ast/binary_expression.h"
|
||||||
|
#include "src/ast/bitcast_expression.h"
|
||||||
#include "src/ast/break_statement.h"
|
#include "src/ast/break_statement.h"
|
||||||
|
#include "src/ast/call_expression.h"
|
||||||
#include "src/ast/case_statement.h"
|
#include "src/ast/case_statement.h"
|
||||||
#include "src/ast/constructor_expression.h"
|
#include "src/ast/constructor_expression.h"
|
||||||
#include "src/ast/continue_statement.h"
|
#include "src/ast/continue_statement.h"
|
||||||
|
@ -29,6 +32,7 @@
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/if_statement.h"
|
#include "src/ast/if_statement.h"
|
||||||
#include "src/ast/loop_statement.h"
|
#include "src/ast/loop_statement.h"
|
||||||
|
#include "src/ast/member_accessor_expression.h"
|
||||||
#include "src/ast/module.h"
|
#include "src/ast/module.h"
|
||||||
#include "src/ast/return_statement.h"
|
#include "src/ast/return_statement.h"
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
@ -37,6 +41,7 @@
|
||||||
#include "src/ast/type/struct_type.h"
|
#include "src/ast/type/struct_type.h"
|
||||||
#include "src/ast/type/type.h"
|
#include "src/ast/type/type.h"
|
||||||
#include "src/ast/type_constructor_expression.h"
|
#include "src/ast/type_constructor_expression.h"
|
||||||
|
#include "src/ast/unary_op_expression.h"
|
||||||
#include "src/ast/variable.h"
|
#include "src/ast/variable.h"
|
||||||
#include "src/writer/text_generator.h"
|
#include "src/writer/text_generator.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue