Rename the IntLiteral to SintLiteral.
This Cl clarifies that IntLiteral is a signed value, which matches with the usage of UintLiteral. Change-Id: Ic8f0e2382cb66eb6b09daed096886dcc55e6b0f0 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22540 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
1649dfadd7
commit
c6f2947ceb
6
BUILD.gn
6
BUILD.gn
|
@ -248,8 +248,6 @@ source_set("libtint_core_src") {
|
||||||
"src/ast/if_statement.h",
|
"src/ast/if_statement.h",
|
||||||
"src/ast/import.cc",
|
"src/ast/import.cc",
|
||||||
"src/ast/import.h",
|
"src/ast/import.h",
|
||||||
"src/ast/int_literal.cc",
|
|
||||||
"src/ast/int_literal.h",
|
|
||||||
"src/ast/kill_statement.cc",
|
"src/ast/kill_statement.cc",
|
||||||
"src/ast/kill_statement.h",
|
"src/ast/kill_statement.h",
|
||||||
"src/ast/literal.cc",
|
"src/ast/literal.cc",
|
||||||
|
@ -274,6 +272,8 @@ source_set("libtint_core_src") {
|
||||||
"src/ast/scalar_constructor_expression.h",
|
"src/ast/scalar_constructor_expression.h",
|
||||||
"src/ast/set_decoration.cc",
|
"src/ast/set_decoration.cc",
|
||||||
"src/ast/set_decoration.h",
|
"src/ast/set_decoration.h",
|
||||||
|
"src/ast/sint_literal.cc",
|
||||||
|
"src/ast/sint_literal.h",
|
||||||
"src/ast/statement.cc",
|
"src/ast/statement.cc",
|
||||||
"src/ast/statement.h",
|
"src/ast/statement.h",
|
||||||
"src/ast/statement_condition.cc",
|
"src/ast/statement_condition.cc",
|
||||||
|
@ -587,7 +587,6 @@ source_set("tint_unittests_core_src") {
|
||||||
"src/ast/identifier_expression_test.cc",
|
"src/ast/identifier_expression_test.cc",
|
||||||
"src/ast/if_statement_test.cc",
|
"src/ast/if_statement_test.cc",
|
||||||
"src/ast/import_test.cc",
|
"src/ast/import_test.cc",
|
||||||
"src/ast/int_literal_test.cc",
|
|
||||||
"src/ast/kill_statement_test.cc",
|
"src/ast/kill_statement_test.cc",
|
||||||
"src/ast/location_decoration_test.cc",
|
"src/ast/location_decoration_test.cc",
|
||||||
"src/ast/loop_statement_test.cc",
|
"src/ast/loop_statement_test.cc",
|
||||||
|
@ -597,6 +596,7 @@ source_set("tint_unittests_core_src") {
|
||||||
"src/ast/return_statement_test.cc",
|
"src/ast/return_statement_test.cc",
|
||||||
"src/ast/scalar_constructor_expression_test.cc",
|
"src/ast/scalar_constructor_expression_test.cc",
|
||||||
"src/ast/set_decoration_test.cc",
|
"src/ast/set_decoration_test.cc",
|
||||||
|
"src/ast/sint_literal_test.cc",
|
||||||
"src/ast/struct_member_offset_decoration_test.cc",
|
"src/ast/struct_member_offset_decoration_test.cc",
|
||||||
"src/ast/struct_member_test.cc",
|
"src/ast/struct_member_test.cc",
|
||||||
"src/ast/struct_test.cc",
|
"src/ast/struct_test.cc",
|
||||||
|
|
|
@ -85,8 +85,6 @@ set(TINT_LIB_SRCS
|
||||||
ast/if_statement.h
|
ast/if_statement.h
|
||||||
ast/import.cc
|
ast/import.cc
|
||||||
ast/import.h
|
ast/import.h
|
||||||
ast/int_literal.cc
|
|
||||||
ast/int_literal.h
|
|
||||||
ast/kill_statement.cc
|
ast/kill_statement.cc
|
||||||
ast/kill_statement.h
|
ast/kill_statement.h
|
||||||
ast/literal.h
|
ast/literal.h
|
||||||
|
@ -111,6 +109,8 @@ set(TINT_LIB_SRCS
|
||||||
ast/scalar_constructor_expression.h
|
ast/scalar_constructor_expression.h
|
||||||
ast/set_decoration.cc
|
ast/set_decoration.cc
|
||||||
ast/set_decoration.h
|
ast/set_decoration.h
|
||||||
|
ast/sint_literal.cc
|
||||||
|
ast/sint_literal.h
|
||||||
ast/statement.cc
|
ast/statement.cc
|
||||||
ast/statement.h
|
ast/statement.h
|
||||||
ast/statement_condition.cc
|
ast/statement_condition.cc
|
||||||
|
@ -266,7 +266,6 @@ set(TINT_TEST_SRCS
|
||||||
ast/identifier_expression_test.cc
|
ast/identifier_expression_test.cc
|
||||||
ast/if_statement_test.cc
|
ast/if_statement_test.cc
|
||||||
ast/import_test.cc
|
ast/import_test.cc
|
||||||
ast/int_literal_test.cc
|
|
||||||
ast/kill_statement_test.cc
|
ast/kill_statement_test.cc
|
||||||
ast/location_decoration_test.cc
|
ast/location_decoration_test.cc
|
||||||
ast/loop_statement_test.cc
|
ast/loop_statement_test.cc
|
||||||
|
@ -277,6 +276,7 @@ set(TINT_TEST_SRCS
|
||||||
ast/return_statement_test.cc
|
ast/return_statement_test.cc
|
||||||
ast/scalar_constructor_expression_test.cc
|
ast/scalar_constructor_expression_test.cc
|
||||||
ast/set_decoration_test.cc
|
ast/set_decoration_test.cc
|
||||||
|
ast/sint_literal_test.cc
|
||||||
ast/struct_member_test.cc
|
ast/struct_member_test.cc
|
||||||
ast/struct_member_offset_decoration_test.cc
|
ast/struct_member_offset_decoration_test.cc
|
||||||
ast/struct_test.cc
|
ast/struct_test.cc
|
||||||
|
|
|
@ -43,7 +43,7 @@ TEST_F(BoolLiteralTest, Is) {
|
||||||
ast::type::BoolType bool_type;
|
ast::type::BoolType bool_type;
|
||||||
BoolLiteral b{&bool_type, false};
|
BoolLiteral b{&bool_type, false};
|
||||||
EXPECT_TRUE(b.IsBool());
|
EXPECT_TRUE(b.IsBool());
|
||||||
EXPECT_FALSE(b.IsInt());
|
EXPECT_FALSE(b.IsSint());
|
||||||
EXPECT_FALSE(b.IsFloat());
|
EXPECT_FALSE(b.IsFloat());
|
||||||
EXPECT_FALSE(b.IsUint());
|
EXPECT_FALSE(b.IsUint());
|
||||||
EXPECT_FALSE(b.IsNull());
|
EXPECT_FALSE(b.IsNull());
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/bool_literal.h"
|
#include "src/ast/bool_literal.h"
|
||||||
#include "src/ast/if_statement.h"
|
#include "src/ast/if_statement.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/kill_statement.h"
|
#include "src/ast/kill_statement.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/type/bool_type.h"
|
#include "src/ast/type/bool_type.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
|
|
||||||
|
@ -136,8 +136,8 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
|
|
||||||
CaseSelectorList b;
|
CaseSelectorList b;
|
||||||
b.push_back(std::make_unique<IntLiteral>(&i32, 1));
|
b.push_back(std::make_unique<SintLiteral>(&i32, 1));
|
||||||
b.push_back(std::make_unique<IntLiteral>(&i32, 2));
|
b.push_back(std::make_unique<SintLiteral>(&i32, 2));
|
||||||
StatementList stmts;
|
StatementList stmts;
|
||||||
stmts.push_back(std::make_unique<KillStatement>());
|
stmts.push_back(std::make_unique<KillStatement>());
|
||||||
CaseStatement c(std::move(b), std::move(stmts));
|
CaseStatement c(std::move(b), std::move(stmts));
|
||||||
|
|
|
@ -34,7 +34,7 @@ TEST_F(FloatLiteralTest, Is) {
|
||||||
ast::type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
FloatLiteral f{&f32, 42.f};
|
FloatLiteral f{&f32, 42.f};
|
||||||
EXPECT_FALSE(f.IsBool());
|
EXPECT_FALSE(f.IsBool());
|
||||||
EXPECT_FALSE(f.IsInt());
|
EXPECT_FALSE(f.IsSint());
|
||||||
EXPECT_TRUE(f.IsFloat());
|
EXPECT_TRUE(f.IsFloat());
|
||||||
EXPECT_FALSE(f.IsUint());
|
EXPECT_FALSE(f.IsUint());
|
||||||
EXPECT_FALSE(f.IsNull());
|
EXPECT_FALSE(f.IsNull());
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
#include "src/ast/bool_literal.h"
|
#include "src/ast/bool_literal.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/null_literal.h"
|
#include "src/ast/null_literal.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/uint_literal.h"
|
#include "src/ast/uint_literal.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
|
@ -37,7 +37,7 @@ bool Literal::IsFloat() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Literal::IsInt() const {
|
bool Literal::IsSint() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +59,9 @@ FloatLiteral* Literal::AsFloat() {
|
||||||
return static_cast<FloatLiteral*>(this);
|
return static_cast<FloatLiteral*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
IntLiteral* Literal::AsInt() {
|
SintLiteral* Literal::AsSint() {
|
||||||
assert(IsInt());
|
assert(IsSint());
|
||||||
return static_cast<IntLiteral*>(this);
|
return static_cast<SintLiteral*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
NullLiteral* Literal::AsNull() {
|
NullLiteral* Literal::AsNull() {
|
||||||
|
|
|
@ -24,8 +24,8 @@ namespace ast {
|
||||||
|
|
||||||
class BoolLiteral;
|
class BoolLiteral;
|
||||||
class FloatLiteral;
|
class FloatLiteral;
|
||||||
class IntLiteral;
|
|
||||||
class NullLiteral;
|
class NullLiteral;
|
||||||
|
class SintLiteral;
|
||||||
class UintLiteral;
|
class UintLiteral;
|
||||||
|
|
||||||
/// Base class for a literal value
|
/// Base class for a literal value
|
||||||
|
@ -38,7 +38,7 @@ class Literal {
|
||||||
/// @returns true if this is a float literal
|
/// @returns true if this is a float literal
|
||||||
virtual bool IsFloat() const;
|
virtual bool IsFloat() const;
|
||||||
/// @returns true if this is a signed int literal
|
/// @returns true if this is a signed int literal
|
||||||
virtual bool IsInt() const;
|
virtual bool IsSint() const;
|
||||||
/// @returns true if this is a null literal
|
/// @returns true if this is a null literal
|
||||||
virtual bool IsNull() const;
|
virtual bool IsNull() const;
|
||||||
/// @returns true if this is a unsigned int literal
|
/// @returns true if this is a unsigned int literal
|
||||||
|
@ -48,8 +48,8 @@ class Literal {
|
||||||
BoolLiteral* AsBool();
|
BoolLiteral* AsBool();
|
||||||
/// @returns the literal as a float literal
|
/// @returns the literal as a float literal
|
||||||
FloatLiteral* AsFloat();
|
FloatLiteral* AsFloat();
|
||||||
/// @returns the literal as a int literal
|
/// @returns the literal as a signed int literal
|
||||||
IntLiteral* AsInt();
|
SintLiteral* AsSint();
|
||||||
/// @returns the literal as a null literal
|
/// @returns the literal as a null literal
|
||||||
NullLiteral* AsNull();
|
NullLiteral* AsNull();
|
||||||
/// @returns the literal as a unsigned int literal
|
/// @returns the literal as a unsigned int literal
|
||||||
|
|
|
@ -27,7 +27,7 @@ TEST_F(NullLiteralTest, Is) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
NullLiteral i{&i32};
|
NullLiteral i{&i32};
|
||||||
EXPECT_FALSE(i.IsBool());
|
EXPECT_FALSE(i.IsBool());
|
||||||
EXPECT_FALSE(i.IsInt());
|
EXPECT_FALSE(i.IsSint());
|
||||||
EXPECT_FALSE(i.IsFloat());
|
EXPECT_FALSE(i.IsFloat());
|
||||||
EXPECT_FALSE(i.IsUint());
|
EXPECT_FALSE(i.IsUint());
|
||||||
EXPECT_TRUE(i.IsNull());
|
EXPECT_TRUE(i.IsNull());
|
||||||
|
|
|
@ -12,26 +12,26 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "src/ast/int_literal.h"
|
#include "src/ast/sint_literal.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
IntLiteral::IntLiteral(ast::type::Type* type, int32_t value)
|
SintLiteral::SintLiteral(ast::type::Type* type, int32_t value)
|
||||||
: Literal(type), value_(value) {}
|
: Literal(type), value_(value) {}
|
||||||
|
|
||||||
IntLiteral::~IntLiteral() = default;
|
SintLiteral::~SintLiteral() = default;
|
||||||
|
|
||||||
bool IntLiteral::IsInt() const {
|
bool SintLiteral::IsSint() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string IntLiteral::to_str() const {
|
std::string SintLiteral::to_str() const {
|
||||||
return std::to_string(value_);
|
return std::to_string(value_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string IntLiteral::name() const {
|
std::string SintLiteral::name() const {
|
||||||
return "__int" + type()->type_name() + "_" + std::to_string(value_);
|
return "__sint" + type()->type_name() + "_" + std::to_string(value_);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
|
@ -12,8 +12,8 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef SRC_AST_INT_LITERAL_H_
|
#ifndef SRC_AST_SINT_LITERAL_H_
|
||||||
#define SRC_AST_INT_LITERAL_H_
|
#define SRC_AST_SINT_LITERAL_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -22,17 +22,17 @@
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
/// A int literal
|
/// A signed int literal
|
||||||
class IntLiteral : public Literal {
|
class SintLiteral : public Literal {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param type the type
|
/// @param type the type
|
||||||
/// @param value the int literals value
|
/// @param value the signed int literals value
|
||||||
IntLiteral(ast::type::Type* type, int32_t value);
|
SintLiteral(ast::type::Type* type, int32_t value);
|
||||||
~IntLiteral() override;
|
~SintLiteral() override;
|
||||||
|
|
||||||
/// @returns true if this is a int literal
|
/// @returns true if this is a signed int literal
|
||||||
bool IsInt() const override;
|
bool IsSint() const override;
|
||||||
|
|
||||||
/// @returns the int literal value
|
/// @returns the int literal value
|
||||||
int32_t value() const { return value_; }
|
int32_t value() const { return value_; }
|
||||||
|
@ -50,4 +50,4 @@ class IntLiteral : public Literal {
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
||||||
#endif // SRC_AST_INT_LITERAL_H_
|
#endif // SRC_AST_SINT_LITERAL_H_
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "src/ast/int_literal.h"
|
#include "src/ast/sint_literal.h"
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
|
@ -22,42 +22,42 @@ namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using IntLiteralTest = testing::Test;
|
using SintLiteralTest = testing::Test;
|
||||||
|
|
||||||
TEST_F(IntLiteralTest, Value) {
|
TEST_F(SintLiteralTest, Value) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
IntLiteral i{&i32, 47};
|
SintLiteral i{&i32, 47};
|
||||||
ASSERT_TRUE(i.IsInt());
|
ASSERT_TRUE(i.IsSint());
|
||||||
EXPECT_EQ(i.value(), 47);
|
EXPECT_EQ(i.value(), 47);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(IntLiteralTest, Is) {
|
TEST_F(SintLiteralTest, Is) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
IntLiteral i{&i32, 42};
|
SintLiteral i{&i32, 42};
|
||||||
EXPECT_FALSE(i.IsBool());
|
EXPECT_FALSE(i.IsBool());
|
||||||
EXPECT_TRUE(i.IsInt());
|
EXPECT_TRUE(i.IsSint());
|
||||||
EXPECT_FALSE(i.IsFloat());
|
EXPECT_FALSE(i.IsFloat());
|
||||||
EXPECT_FALSE(i.IsUint());
|
EXPECT_FALSE(i.IsUint());
|
||||||
EXPECT_FALSE(i.IsNull());
|
EXPECT_FALSE(i.IsNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(IntLiteralTest, ToStr) {
|
TEST_F(SintLiteralTest, ToStr) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
IntLiteral i{&i32, -42};
|
SintLiteral i{&i32, -42};
|
||||||
|
|
||||||
EXPECT_EQ(i.to_str(), "-42");
|
EXPECT_EQ(i.to_str(), "-42");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(IntLiteralTest, Name_I32) {
|
TEST_F(SintLiteralTest, Name_I32) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
IntLiteral i{&i32, 2};
|
SintLiteral i{&i32, 2};
|
||||||
EXPECT_EQ("__int__i32_2", i.name());
|
EXPECT_EQ("__sint__i32_2", i.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(IntLiteralTest, Name_U32) {
|
TEST_F(SintLiteralTest, Name_U32) {
|
||||||
ast::type::U32Type u32;
|
ast::type::U32Type u32;
|
||||||
IntLiteral i{&u32, 2};
|
SintLiteral i{&u32, 2};
|
||||||
EXPECT_EQ("__int__u32_2", i.name());
|
EXPECT_EQ("__sint__u32_2", i.name());
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace ast
|
} // namespace ast
|
|
@ -34,7 +34,7 @@ TEST_F(UintLiteralTest, Is) {
|
||||||
ast::type::U32Type u32;
|
ast::type::U32Type u32;
|
||||||
UintLiteral u{&u32, 42};
|
UintLiteral u{&u32, 42};
|
||||||
EXPECT_FALSE(u.IsBool());
|
EXPECT_FALSE(u.IsBool());
|
||||||
EXPECT_FALSE(u.IsInt());
|
EXPECT_FALSE(u.IsSint());
|
||||||
EXPECT_FALSE(u.IsFloat());
|
EXPECT_FALSE(u.IsFloat());
|
||||||
EXPECT_TRUE(u.IsUint());
|
EXPECT_TRUE(u.IsUint());
|
||||||
EXPECT_FALSE(u.IsNull());
|
EXPECT_FALSE(u.IsNull());
|
||||||
|
|
|
@ -39,8 +39,8 @@
|
||||||
#include "src/ast/builtin_decoration.h"
|
#include "src/ast/builtin_decoration.h"
|
||||||
#include "src/ast/decorated_variable.h"
|
#include "src/ast/decorated_variable.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/struct.h"
|
#include "src/ast/struct.h"
|
||||||
#include "src/ast/struct_decoration.h"
|
#include "src/ast/struct_decoration.h"
|
||||||
#include "src/ast/struct_member.h"
|
#include "src/ast/struct_member.h"
|
||||||
|
@ -882,7 +882,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
|
||||||
}
|
}
|
||||||
if (ast_type->IsI32()) {
|
if (ast_type->IsI32()) {
|
||||||
return {ast_type, std::make_unique<ast::ScalarConstructorExpression>(
|
return {ast_type, std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(
|
std::make_unique<ast::SintLiteral>(
|
||||||
ast_type, spirv_const->GetS32()))};
|
ast_type, spirv_const->GetS32()))};
|
||||||
}
|
}
|
||||||
if (ast_type->IsF32()) {
|
if (ast_type->IsF32()) {
|
||||||
|
@ -954,7 +954,7 @@ std::unique_ptr<ast::Expression> ParserImpl::MakeNullValue(
|
||||||
}
|
}
|
||||||
if (type->IsI32()) {
|
if (type->IsI32()) {
|
||||||
return std::make_unique<ast::ScalarConstructorExpression>(
|
return std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(type, 0));
|
std::make_unique<ast::SintLiteral>(type, 0));
|
||||||
}
|
}
|
||||||
if (type->IsF32()) {
|
if (type->IsF32()) {
|
||||||
return std::make_unique<ast::ScalarConstructorExpression>(
|
return std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
|
|
@ -201,7 +201,7 @@ TEST_P(IntegerTest_HexSigned, Matches) {
|
||||||
Lexer l(std::string(params.input));
|
Lexer l(std::string(params.input));
|
||||||
|
|
||||||
auto t = l.next();
|
auto t = l.next();
|
||||||
EXPECT_TRUE(t.IsIntLiteral());
|
EXPECT_TRUE(t.IsSintLiteral());
|
||||||
EXPECT_EQ(t.line(), 1u);
|
EXPECT_EQ(t.line(), 1u);
|
||||||
EXPECT_EQ(t.column(), 1u);
|
EXPECT_EQ(t.column(), 1u);
|
||||||
EXPECT_EQ(t.to_i32(), params.result);
|
EXPECT_EQ(t.to_i32(), params.result);
|
||||||
|
@ -308,7 +308,7 @@ TEST_P(IntegerTest_Signed, Matches) {
|
||||||
Lexer l(params.input);
|
Lexer l(params.input);
|
||||||
|
|
||||||
auto t = l.next();
|
auto t = l.next();
|
||||||
EXPECT_TRUE(t.IsIntLiteral());
|
EXPECT_TRUE(t.IsSintLiteral());
|
||||||
EXPECT_EQ(t.to_i32(), params.result);
|
EXPECT_EQ(t.to_i32(), params.result);
|
||||||
EXPECT_EQ(1u, t.line());
|
EXPECT_EQ(1u, t.line());
|
||||||
EXPECT_EQ(1u, t.column());
|
EXPECT_EQ(1u, t.column());
|
||||||
|
@ -328,7 +328,7 @@ TEST_P(IntegerTest_Invalid, Parses) {
|
||||||
Lexer l(GetParam());
|
Lexer l(GetParam());
|
||||||
|
|
||||||
auto t = l.next();
|
auto t = l.next();
|
||||||
EXPECT_FALSE(t.IsIntLiteral());
|
EXPECT_FALSE(t.IsSintLiteral());
|
||||||
EXPECT_FALSE(t.IsUintLiteral());
|
EXPECT_FALSE(t.IsUintLiteral());
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(LexerTest,
|
INSTANTIATE_TEST_SUITE_P(LexerTest,
|
||||||
|
|
|
@ -34,13 +34,13 @@
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#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/int_literal.h"
|
|
||||||
#include "src/ast/kill_statement.h"
|
#include "src/ast/kill_statement.h"
|
||||||
#include "src/ast/location_decoration.h"
|
#include "src/ast/location_decoration.h"
|
||||||
#include "src/ast/member_accessor_expression.h"
|
#include "src/ast/member_accessor_expression.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/set_decoration.h"
|
#include "src/ast/set_decoration.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/statement_condition.h"
|
#include "src/ast/statement_condition.h"
|
||||||
#include "src/ast/struct_member_offset_decoration.h"
|
#include "src/ast/struct_member_offset_decoration.h"
|
||||||
#include "src/ast/switch_statement.h"
|
#include "src/ast/switch_statement.h"
|
||||||
|
@ -497,7 +497,7 @@ std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
|
||||||
next(); // consume the peek
|
next(); // consume the peek
|
||||||
|
|
||||||
t = next();
|
t = next();
|
||||||
if (!t.IsIntLiteral()) {
|
if (!t.IsSintLiteral()) {
|
||||||
set_error(t, "invalid value for location decoration");
|
set_error(t, "invalid value for location decoration");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -525,7 +525,7 @@ std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
|
||||||
next(); // consume the peek
|
next(); // consume the peek
|
||||||
|
|
||||||
t = next();
|
t = next();
|
||||||
if (!t.IsIntLiteral()) {
|
if (!t.IsSintLiteral()) {
|
||||||
set_error(t, "invalid value for binding decoration");
|
set_error(t, "invalid value for binding decoration");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -536,7 +536,7 @@ std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
|
||||||
next(); // consume the peek
|
next(); // consume the peek
|
||||||
|
|
||||||
t = next();
|
t = next();
|
||||||
if (!t.IsIntLiteral()) {
|
if (!t.IsSintLiteral()) {
|
||||||
set_error(t, "invalid value for set decoration");
|
set_error(t, "invalid value for set decoration");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -837,7 +837,7 @@ ast::type::Type* ParserImpl::type_decl_array(Token t) {
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
if (t.IsComma()) {
|
if (t.IsComma()) {
|
||||||
t = next();
|
t = next();
|
||||||
if (!t.IsIntLiteral()) {
|
if (!t.IsSintLiteral()) {
|
||||||
set_error(t, "missing size of array declaration");
|
set_error(t, "missing size of array declaration");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -1143,7 +1143,7 @@ ParserImpl::struct_member_decoration() {
|
||||||
next(); // Consume the peek
|
next(); // Consume the peek
|
||||||
|
|
||||||
t = next();
|
t = next();
|
||||||
if (!t.IsIntLiteral()) {
|
if (!t.IsSintLiteral()) {
|
||||||
set_error(t, "invalid value for offset decoration");
|
set_error(t, "invalid value for offset decoration");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -2741,13 +2741,13 @@ std::unique_ptr<ast::Literal> ParserImpl::const_literal() {
|
||||||
}
|
}
|
||||||
return std::make_unique<ast::BoolLiteral>(type, false);
|
return std::make_unique<ast::BoolLiteral>(type, false);
|
||||||
}
|
}
|
||||||
if (t.IsIntLiteral()) {
|
if (t.IsSintLiteral()) {
|
||||||
next(); // Consume the peek
|
next(); // Consume the peek
|
||||||
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
|
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
|
||||||
if (!type) {
|
if (!type) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return std::make_unique<ast::IntLiteral>(type, t.to_i32());
|
return std::make_unique<ast::SintLiteral>(type, t.to_i32());
|
||||||
}
|
}
|
||||||
if (t.IsUintLiteral()) {
|
if (t.IsUintLiteral()) {
|
||||||
next(); // Consume the peek
|
next(); // Consume the peek
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#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/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/unary_op_expression.h"
|
#include "src/ast/unary_op_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"
|
||||||
|
|
|
@ -16,10 +16,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/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/literal.h"
|
#include "src/ast/literal.h"
|
||||||
#include "src/ast/member_accessor_expression.h"
|
#include "src/ast/member_accessor_expression.h"
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.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"
|
||||||
|
|
||||||
|
@ -47,8 +47,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
|
||||||
|
|
||||||
auto* init = e->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = e->rhs()->AsConstructor()->AsScalarConstructor();
|
||||||
ASSERT_NE(init->literal(), nullptr);
|
ASSERT_NE(init->literal(), nullptr);
|
||||||
ASSERT_TRUE(init->literal()->IsInt());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
EXPECT_EQ(init->literal()->AsInt()->value(), 123);
|
EXPECT_EQ(init->literal()->AsSint()->value(), 123);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
|
TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
|
||||||
|
@ -65,8 +65,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
|
||||||
ASSERT_TRUE(e->rhs()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(e->rhs()->AsConstructor()->IsScalarConstructor());
|
||||||
auto* init = e->rhs()->AsConstructor()->AsScalarConstructor();
|
auto* init = e->rhs()->AsConstructor()->AsScalarConstructor();
|
||||||
ASSERT_NE(init->literal(), nullptr);
|
ASSERT_NE(init->literal(), nullptr);
|
||||||
ASSERT_TRUE(init->literal()->IsInt());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
EXPECT_EQ(init->literal()->AsInt()->value(), 123);
|
EXPECT_EQ(init->literal()->AsSint()->value(), 123);
|
||||||
|
|
||||||
ASSERT_TRUE(e->lhs()->IsMemberAccessor());
|
ASSERT_TRUE(e->lhs()->IsMemberAccessor());
|
||||||
auto* mem = e->lhs()->AsMemberAccessor();
|
auto* mem = e->lhs()->AsMemberAccessor();
|
||||||
|
@ -82,8 +82,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
||||||
init = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
init = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
||||||
ASSERT_NE(init->literal(), nullptr);
|
ASSERT_NE(init->literal(), nullptr);
|
||||||
ASSERT_TRUE(init->literal()->IsInt());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
EXPECT_EQ(init->literal()->AsInt()->value(), 2);
|
EXPECT_EQ(init->literal()->AsSint()->value(), 2);
|
||||||
|
|
||||||
ASSERT_TRUE(ary->array()->IsMemberAccessor());
|
ASSERT_TRUE(ary->array()->IsMemberAccessor());
|
||||||
mem = ary->array()->AsMemberAccessor();
|
mem = ary->array()->AsMemberAccessor();
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/bool_literal.h"
|
#include "src/ast/bool_literal.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#include "src/ast/int_literal.h"
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/uint_literal.h"
|
#include "src/ast/uint_literal.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"
|
||||||
|
@ -30,8 +30,8 @@ TEST_F(ParserImplTest, ConstLiteral_Int) {
|
||||||
auto c = p->const_literal();
|
auto c = p->const_literal();
|
||||||
ASSERT_FALSE(p->has_error());
|
ASSERT_FALSE(p->has_error());
|
||||||
ASSERT_NE(c, nullptr);
|
ASSERT_NE(c, nullptr);
|
||||||
ASSERT_TRUE(c->IsInt());
|
ASSERT_TRUE(c->IsSint());
|
||||||
EXPECT_EQ(c->AsInt()->value(), -234);
|
EXPECT_EQ(c->AsSint()->value(), -234);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ConstLiteral_Uint) {
|
TEST_F(ParserImplTest, ConstLiteral_Uint) {
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
#include "src/ast/array_accessor_expression.h"
|
#include "src/ast/array_accessor_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/int_literal.h"
|
|
||||||
#include "src/ast/member_accessor_expression.h"
|
#include "src/ast/member_accessor_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/unary_op_expression.h"
|
#include "src/ast/unary_op_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"
|
||||||
|
@ -44,8 +44,8 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ConstantIndex) {
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
||||||
auto* c = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* c = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
||||||
ASSERT_TRUE(c->literal()->IsInt());
|
ASSERT_TRUE(c->literal()->IsSint());
|
||||||
EXPECT_EQ(c->literal()->AsInt()->value(), 1);
|
EXPECT_EQ(c->literal()->AsSint()->value(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, PostfixExpression_Array_ExpressionIndex) {
|
TEST_F(ParserImplTest, PostfixExpression_Array_ExpressionIndex) {
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
#include "src/ast/bool_literal.h"
|
#include "src/ast/bool_literal.h"
|
||||||
#include "src/ast/cast_expression.h"
|
#include "src/ast/cast_expression.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/type/f32_type.h"
|
#include "src/ast/type/f32_type.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
#include "src/ast/type_constructor_expression.h"
|
#include "src/ast/type_constructor_expression.h"
|
||||||
|
@ -76,26 +76,26 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) {
|
||||||
ASSERT_TRUE(val[0]->IsConstructor());
|
ASSERT_TRUE(val[0]->IsConstructor());
|
||||||
ASSERT_TRUE(val[0]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(val[0]->AsConstructor()->IsScalarConstructor());
|
||||||
auto* ident = val[0]->AsConstructor()->AsScalarConstructor();
|
auto* ident = val[0]->AsConstructor()->AsScalarConstructor();
|
||||||
ASSERT_TRUE(ident->literal()->IsInt());
|
ASSERT_TRUE(ident->literal()->IsSint());
|
||||||
EXPECT_EQ(ident->literal()->AsInt()->value(), 1);
|
EXPECT_EQ(ident->literal()->AsSint()->value(), 1);
|
||||||
|
|
||||||
ASSERT_TRUE(val[1]->IsConstructor());
|
ASSERT_TRUE(val[1]->IsConstructor());
|
||||||
ASSERT_TRUE(val[1]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(val[1]->AsConstructor()->IsScalarConstructor());
|
||||||
ident = val[1]->AsConstructor()->AsScalarConstructor();
|
ident = val[1]->AsConstructor()->AsScalarConstructor();
|
||||||
ASSERT_TRUE(ident->literal()->IsInt());
|
ASSERT_TRUE(ident->literal()->IsSint());
|
||||||
EXPECT_EQ(ident->literal()->AsInt()->value(), 2);
|
EXPECT_EQ(ident->literal()->AsSint()->value(), 2);
|
||||||
|
|
||||||
ASSERT_TRUE(val[2]->IsConstructor());
|
ASSERT_TRUE(val[2]->IsConstructor());
|
||||||
ASSERT_TRUE(val[2]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(val[2]->AsConstructor()->IsScalarConstructor());
|
||||||
ident = val[2]->AsConstructor()->AsScalarConstructor();
|
ident = val[2]->AsConstructor()->AsScalarConstructor();
|
||||||
ASSERT_TRUE(ident->literal()->IsInt());
|
ASSERT_TRUE(ident->literal()->IsSint());
|
||||||
EXPECT_EQ(ident->literal()->AsInt()->value(), 3);
|
EXPECT_EQ(ident->literal()->AsSint()->value(), 3);
|
||||||
|
|
||||||
ASSERT_TRUE(val[3]->IsConstructor());
|
ASSERT_TRUE(val[3]->IsConstructor());
|
||||||
ASSERT_TRUE(val[3]->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(val[3]->AsConstructor()->IsScalarConstructor());
|
||||||
ident = val[3]->AsConstructor()->AsScalarConstructor();
|
ident = val[3]->AsConstructor()->AsScalarConstructor();
|
||||||
ASSERT_TRUE(ident->literal()->IsInt());
|
ASSERT_TRUE(ident->literal()->IsSint());
|
||||||
EXPECT_EQ(ident->literal()->AsInt()->value(), 4);
|
EXPECT_EQ(ident->literal()->AsSint()->value(), 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_InvalidTypeDecl) {
|
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_InvalidTypeDecl) {
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#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/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/unary_op_expression.h"
|
#include "src/ast/unary_op_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"
|
||||||
|
@ -41,8 +41,8 @@ TEST_F(ParserImplTest, UnaryExpression_Postix) {
|
||||||
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
ASSERT_TRUE(ary->idx_expr()->IsConstructor());
|
||||||
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
|
||||||
auto* init = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
auto* init = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
|
||||||
ASSERT_TRUE(init->literal()->IsInt());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
ASSERT_EQ(init->literal()->AsInt()->value(), 2);
|
ASSERT_EQ(init->literal()->AsSint()->value(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, UnaryExpression_Minus) {
|
TEST_F(ParserImplTest, UnaryExpression_Minus) {
|
||||||
|
@ -59,8 +59,8 @@ TEST_F(ParserImplTest, UnaryExpression_Minus) {
|
||||||
ASSERT_TRUE(u->expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(u->expr()->AsConstructor()->IsScalarConstructor());
|
||||||
|
|
||||||
auto* init = u->expr()->AsConstructor()->AsScalarConstructor();
|
auto* init = u->expr()->AsConstructor()->AsScalarConstructor();
|
||||||
ASSERT_TRUE(init->literal()->IsInt());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
EXPECT_EQ(init->literal()->AsInt()->value(), 1);
|
EXPECT_EQ(init->literal()->AsSint()->value(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, UnaryExpression_Minus_InvalidRHS) {
|
TEST_F(ParserImplTest, UnaryExpression_Minus_InvalidRHS) {
|
||||||
|
@ -85,8 +85,8 @@ TEST_F(ParserImplTest, UnaryExpression_Bang) {
|
||||||
ASSERT_TRUE(u->expr()->AsConstructor()->IsScalarConstructor());
|
ASSERT_TRUE(u->expr()->AsConstructor()->IsScalarConstructor());
|
||||||
|
|
||||||
auto* init = u->expr()->AsConstructor()->AsScalarConstructor();
|
auto* init = u->expr()->AsConstructor()->AsScalarConstructor();
|
||||||
ASSERT_TRUE(init->literal()->IsInt());
|
ASSERT_TRUE(init->literal()->IsSint());
|
||||||
EXPECT_EQ(init->literal()->AsInt()->value(), 1);
|
EXPECT_EQ(init->literal()->AsSint()->value(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, UnaryExpression_Bang_InvalidRHS) {
|
TEST_F(ParserImplTest, UnaryExpression_Bang_InvalidRHS) {
|
||||||
|
|
|
@ -69,7 +69,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_InvalidIdent) {
|
||||||
ASSERT_EQ(type, nullptr);
|
ASSERT_EQ(type, nullptr);
|
||||||
|
|
||||||
auto t = p->next();
|
auto t = p->next();
|
||||||
ASSERT_TRUE(t.IsIntLiteral());
|
ASSERT_TRUE(t.IsSintLiteral());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableIdentDecl_InvalidType) {
|
TEST_F(ParserImplTest, VariableIdentDecl_InvalidType) {
|
||||||
|
|
|
@ -33,8 +33,8 @@ std::string Token::TypeToName(Type type) {
|
||||||
return "kStringLiteral";
|
return "kStringLiteral";
|
||||||
case Token::Type::kFloatLiteral:
|
case Token::Type::kFloatLiteral:
|
||||||
return "kFloatLiteral";
|
return "kFloatLiteral";
|
||||||
case Token::Type::kIntLiteral:
|
case Token::Type::kSintLiteral:
|
||||||
return "kIntLiteral";
|
return "kSintLiteral";
|
||||||
case Token::Type::kUintLiteral:
|
case Token::Type::kUintLiteral:
|
||||||
return "kUintLiteral";
|
return "kUintLiteral";
|
||||||
case Token::Type::kUninitialized:
|
case Token::Type::kUninitialized:
|
||||||
|
@ -247,7 +247,7 @@ Token::Token(const Source& source, uint32_t val)
|
||||||
: type_(Type::kUintLiteral), source_(source), val_uint_(val) {}
|
: type_(Type::kUintLiteral), source_(source), val_uint_(val) {}
|
||||||
|
|
||||||
Token::Token(const Source& source, int32_t val)
|
Token::Token(const Source& source, int32_t val)
|
||||||
: type_(Type::kIntLiteral), source_(source), val_int_(val) {}
|
: type_(Type::kSintLiteral), source_(source), val_int_(val) {}
|
||||||
|
|
||||||
Token::Token(const Source& source, float val)
|
Token::Token(const Source& source, float val)
|
||||||
: type_(Type::kFloatLiteral), source_(source), val_float_(val) {}
|
: type_(Type::kFloatLiteral), source_(source), val_float_(val) {}
|
||||||
|
@ -266,7 +266,7 @@ std::string Token::to_str() const {
|
||||||
if (type_ == Type::kFloatLiteral) {
|
if (type_ == Type::kFloatLiteral) {
|
||||||
return std::to_string(val_float_);
|
return std::to_string(val_float_);
|
||||||
}
|
}
|
||||||
if (type_ == Type::kIntLiteral) {
|
if (type_ == Type::kSintLiteral) {
|
||||||
return std::to_string(val_int_);
|
return std::to_string(val_int_);
|
||||||
}
|
}
|
||||||
if (type_ == Type::kUintLiteral) {
|
if (type_ == Type::kUintLiteral) {
|
||||||
|
|
|
@ -46,9 +46,9 @@ class Token {
|
||||||
kStringLiteral,
|
kStringLiteral,
|
||||||
/// A float value
|
/// A float value
|
||||||
kFloatLiteral,
|
kFloatLiteral,
|
||||||
/// An int value
|
/// An signed int value
|
||||||
kIntLiteral,
|
kSintLiteral,
|
||||||
/// A uint value
|
/// A unsigned int value
|
||||||
kUintLiteral,
|
kUintLiteral,
|
||||||
|
|
||||||
/// A '&'
|
/// A '&'
|
||||||
|
@ -305,8 +305,8 @@ class Token {
|
||||||
bool IsStringLiteral() const { return type_ == Type::kStringLiteral; }
|
bool IsStringLiteral() const { return type_ == Type::kStringLiteral; }
|
||||||
/// @returns true if the token is a float
|
/// @returns true if the token is a float
|
||||||
bool IsFloatLiteral() const { return type_ == Type::kFloatLiteral; }
|
bool IsFloatLiteral() const { return type_ == Type::kFloatLiteral; }
|
||||||
/// @returns true if the token is an int
|
/// @returns true if the token is an signed int
|
||||||
bool IsIntLiteral() const { return type_ == Type::kIntLiteral; }
|
bool IsSintLiteral() const { return type_ == Type::kSintLiteral; }
|
||||||
/// @returns true if the token is a unsigned int
|
/// @returns true if the token is a unsigned int
|
||||||
bool IsUintLiteral() const { return type_ == Type::kUintLiteral; }
|
bool IsUintLiteral() const { return type_ == Type::kUintLiteral; }
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#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/int_literal.h"
|
|
||||||
#include "src/ast/loop_statement.h"
|
#include "src/ast/loop_statement.h"
|
||||||
#include "src/ast/member_accessor_expression.h"
|
#include "src/ast/member_accessor_expression.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/sint_literal.h"
|
||||||
#include "src/ast/struct.h"
|
#include "src/ast/struct.h"
|
||||||
#include "src/ast/struct_member.h"
|
#include "src/ast/struct_member.h"
|
||||||
#include "src/ast/switch_statement.h"
|
#include "src/ast/switch_statement.h"
|
||||||
|
@ -112,7 +112,7 @@ TEST_F(TypeDeterminerTest, Stmt_Assign) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
|
|
||||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* lhs_ptr = lhs.get();
|
auto* lhs_ptr = lhs.get();
|
||||||
|
|
||||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
@ -133,7 +133,7 @@ TEST_F(TypeDeterminerTest, Stmt_Break) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
|
|
||||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* cond_ptr = cond.get();
|
auto* cond_ptr = cond.get();
|
||||||
|
|
||||||
ast::BreakStatement brk(ast::StatementCondition::kIf, std::move(cond));
|
ast::BreakStatement brk(ast::StatementCondition::kIf, std::move(cond));
|
||||||
|
@ -154,7 +154,7 @@ TEST_F(TypeDeterminerTest, Stmt_Case) {
|
||||||
ast::type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
|
|
||||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* lhs_ptr = lhs.get();
|
auto* lhs_ptr = lhs.get();
|
||||||
|
|
||||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
@ -166,7 +166,7 @@ TEST_F(TypeDeterminerTest, Stmt_Case) {
|
||||||
std::move(rhs)));
|
std::move(rhs)));
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(std::make_unique<ast::IntLiteral>(&i32, 3));
|
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 3));
|
||||||
ast::CaseStatement cse(std::move(lit), std::move(body));
|
ast::CaseStatement cse(std::move(lit), std::move(body));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&cse));
|
EXPECT_TRUE(td()->DetermineResultType(&cse));
|
||||||
|
@ -180,7 +180,7 @@ TEST_F(TypeDeterminerTest, Stmt_Continue) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
|
|
||||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* cond_ptr = cond.get();
|
auto* cond_ptr = cond.get();
|
||||||
|
|
||||||
ast::ContinueStatement stmt(ast::StatementCondition::kIf, std::move(cond));
|
ast::ContinueStatement stmt(ast::StatementCondition::kIf, std::move(cond));
|
||||||
|
@ -201,7 +201,7 @@ TEST_F(TypeDeterminerTest, Stmt_Else) {
|
||||||
ast::type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
|
|
||||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* lhs_ptr = lhs.get();
|
auto* lhs_ptr = lhs.get();
|
||||||
|
|
||||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
@ -213,7 +213,7 @@ TEST_F(TypeDeterminerTest, Stmt_Else) {
|
||||||
std::move(rhs)));
|
std::move(rhs)));
|
||||||
|
|
||||||
ast::ElseStatement stmt(std::make_unique<ast::ScalarConstructorExpression>(
|
ast::ElseStatement stmt(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3)),
|
std::make_unique<ast::SintLiteral>(&i32, 3)),
|
||||||
std::move(body));
|
std::move(body));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&stmt));
|
EXPECT_TRUE(td()->DetermineResultType(&stmt));
|
||||||
|
@ -230,7 +230,7 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
|
||||||
ast::type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
|
|
||||||
auto else_lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto else_lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* else_lhs_ptr = else_lhs.get();
|
auto* else_lhs_ptr = else_lhs.get();
|
||||||
|
|
||||||
auto else_rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto else_rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
@ -243,14 +243,14 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
|
||||||
|
|
||||||
auto else_stmt = std::make_unique<ast::ElseStatement>(
|
auto else_stmt = std::make_unique<ast::ElseStatement>(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3)),
|
std::make_unique<ast::SintLiteral>(&i32, 3)),
|
||||||
std::move(else_body));
|
std::move(else_body));
|
||||||
|
|
||||||
ast::ElseStatementList else_stmts;
|
ast::ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(std::move(else_stmt));
|
else_stmts.push_back(std::move(else_stmt));
|
||||||
|
|
||||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* lhs_ptr = lhs.get();
|
auto* lhs_ptr = lhs.get();
|
||||||
|
|
||||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
@ -262,7 +262,7 @@ TEST_F(TypeDeterminerTest, Stmt_If) {
|
||||||
std::move(rhs)));
|
std::move(rhs)));
|
||||||
|
|
||||||
ast::IfStatement stmt(std::make_unique<ast::ScalarConstructorExpression>(
|
ast::IfStatement stmt(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3)),
|
std::make_unique<ast::SintLiteral>(&i32, 3)),
|
||||||
std::move(body));
|
std::move(body));
|
||||||
stmt.set_else_statements(std::move(else_stmts));
|
stmt.set_else_statements(std::move(else_stmts));
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) {
|
||||||
ast::type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
|
|
||||||
auto body_lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto body_lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* body_lhs_ptr = body_lhs.get();
|
auto* body_lhs_ptr = body_lhs.get();
|
||||||
|
|
||||||
auto body_rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto body_rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
@ -296,7 +296,7 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) {
|
||||||
std::move(body_lhs), std::move(body_rhs)));
|
std::move(body_lhs), std::move(body_rhs)));
|
||||||
|
|
||||||
auto continuing_lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto continuing_lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* continuing_lhs_ptr = continuing_lhs.get();
|
auto* continuing_lhs_ptr = continuing_lhs.get();
|
||||||
|
|
||||||
auto continuing_rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto continuing_rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
@ -324,7 +324,7 @@ TEST_F(TypeDeterminerTest, Stmt_Return) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
|
|
||||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* cond_ptr = cond.get();
|
auto* cond_ptr = cond.get();
|
||||||
|
|
||||||
ast::ReturnStatement ret(std::move(cond));
|
ast::ReturnStatement ret(std::move(cond));
|
||||||
|
@ -345,7 +345,7 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) {
|
||||||
ast::type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
|
|
||||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* lhs_ptr = lhs.get();
|
auto* lhs_ptr = lhs.get();
|
||||||
|
|
||||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
@ -357,14 +357,14 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) {
|
||||||
std::move(rhs)));
|
std::move(rhs)));
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(std::make_unique<ast::IntLiteral>(&i32, 3));
|
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 3));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(
|
cases.push_back(
|
||||||
std::make_unique<ast::CaseStatement>(std::move(lit), std::move(body)));
|
std::make_unique<ast::CaseStatement>(std::move(lit), std::move(body)));
|
||||||
|
|
||||||
ast::SwitchStatement stmt(std::make_unique<ast::ScalarConstructorExpression>(
|
ast::SwitchStatement stmt(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2)),
|
std::make_unique<ast::SintLiteral>(&i32, 2)),
|
||||||
std::move(cases));
|
std::move(cases));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&stmt)) << td()->error();
|
EXPECT_TRUE(td()->DetermineResultType(&stmt)) << td()->error();
|
||||||
|
@ -382,7 +382,7 @@ TEST_F(TypeDeterminerTest, Stmt_Unless) {
|
||||||
ast::type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
|
|
||||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto* lhs_ptr = lhs.get();
|
auto* lhs_ptr = lhs.get();
|
||||||
|
|
||||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
@ -395,7 +395,7 @@ TEST_F(TypeDeterminerTest, Stmt_Unless) {
|
||||||
|
|
||||||
ast::UnlessStatement unless(
|
ast::UnlessStatement unless(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3)),
|
std::make_unique<ast::SintLiteral>(&i32, 3)),
|
||||||
std::move(body));
|
std::move(body));
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&unless));
|
EXPECT_TRUE(td()->DetermineResultType(&unless));
|
||||||
|
@ -412,7 +412,7 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl) {
|
||||||
auto var =
|
auto var =
|
||||||
std::make_unique<ast::Variable>("my_var", ast::StorageClass::kNone, &i32);
|
std::make_unique<ast::Variable>("my_var", ast::StorageClass::kNone, &i32);
|
||||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2)));
|
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||||
auto* init_ptr = var->constructor();
|
auto* init_ptr = var->constructor();
|
||||||
|
|
||||||
ast::VariableDeclStatement decl(std::move(var));
|
ast::VariableDeclStatement decl(std::move(var));
|
||||||
|
@ -436,7 +436,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array) {
|
||||||
ast::type::ArrayType ary(&f32, 3);
|
ast::type::ArrayType ary(&f32, 3);
|
||||||
|
|
||||||
auto idx = std::make_unique<ast::ScalarConstructorExpression>(
|
auto idx = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto var = std::make_unique<ast::Variable>(
|
auto var = std::make_unique<ast::Variable>(
|
||||||
"my_var", ast::StorageClass::kFunction, &ary);
|
"my_var", ast::StorageClass::kFunction, &ary);
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
@ -460,7 +460,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array_Constant) {
|
||||||
ast::type::ArrayType ary(&f32, 3);
|
ast::type::ArrayType ary(&f32, 3);
|
||||||
|
|
||||||
auto idx = std::make_unique<ast::ScalarConstructorExpression>(
|
auto idx = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto var = std::make_unique<ast::Variable>(
|
auto var = std::make_unique<ast::Variable>(
|
||||||
"my_var", ast::StorageClass::kFunction, &ary);
|
"my_var", ast::StorageClass::kFunction, &ary);
|
||||||
var->set_is_const(true);
|
var->set_is_const(true);
|
||||||
|
@ -482,7 +482,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix) {
|
||||||
ast::type::MatrixType mat(&f32, 3, 2);
|
ast::type::MatrixType mat(&f32, 3, 2);
|
||||||
|
|
||||||
auto idx = std::make_unique<ast::ScalarConstructorExpression>(
|
auto idx = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto var =
|
auto var =
|
||||||
std::make_unique<ast::Variable>("my_var", ast::StorageClass::kNone, &mat);
|
std::make_unique<ast::Variable>("my_var", ast::StorageClass::kNone, &mat);
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
@ -507,9 +507,9 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix_BothDimensions) {
|
||||||
ast::type::MatrixType mat(&f32, 3, 2);
|
ast::type::MatrixType mat(&f32, 3, 2);
|
||||||
|
|
||||||
auto idx1 = std::make_unique<ast::ScalarConstructorExpression>(
|
auto idx1 = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto idx2 = std::make_unique<ast::ScalarConstructorExpression>(
|
auto idx2 = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1));
|
std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||||
auto var =
|
auto var =
|
||||||
std::make_unique<ast::Variable>("my_var", ast::StorageClass::kNone, &mat);
|
std::make_unique<ast::Variable>("my_var", ast::StorageClass::kNone, &mat);
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
@ -537,7 +537,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Vector) {
|
||||||
ast::type::VectorType vec(&f32, 3);
|
ast::type::VectorType vec(&f32, 3);
|
||||||
|
|
||||||
auto idx = std::make_unique<ast::ScalarConstructorExpression>(
|
auto idx = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2));
|
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
auto var =
|
auto var =
|
||||||
std::make_unique<ast::Variable>("my_var", ast::StorageClass::kNone, &vec);
|
std::make_unique<ast::Variable>("my_var", ast::StorageClass::kNone, &vec);
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
@ -953,7 +953,7 @@ TEST_F(TypeDeterminerTest, Expr_Accessor_MultiLevel) {
|
||||||
auto mem_ident = std::make_unique<ast::IdentifierExpression>("mem");
|
auto mem_ident = std::make_unique<ast::IdentifierExpression>("mem");
|
||||||
auto foo_ident = std::make_unique<ast::IdentifierExpression>("foo");
|
auto foo_ident = std::make_unique<ast::IdentifierExpression>("foo");
|
||||||
auto idx = std::make_unique<ast::ScalarConstructorExpression>(
|
auto idx = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 0));
|
std::make_unique<ast::SintLiteral>(&i32, 0));
|
||||||
auto swizzle = std::make_unique<ast::IdentifierExpression>("yx");
|
auto swizzle = std::make_unique<ast::IdentifierExpression>("yx");
|
||||||
|
|
||||||
ast::MemberAccessorExpression mem(
|
ast::MemberAccessorExpression mem(
|
||||||
|
@ -1851,7 +1851,7 @@ TEST_P(ImportData_SingleParamTest, Error_Integer) {
|
||||||
|
|
||||||
ast::ExpressionList params;
|
ast::ExpressionList params;
|
||||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
|
|
||||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||||
|
|
||||||
|
@ -1978,7 +1978,7 @@ TEST_F(TypeDeterminerTest, ImportData_Length_Error_Integer) {
|
||||||
|
|
||||||
ast::ExpressionList params;
|
ast::ExpressionList params;
|
||||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
|
|
||||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||||
|
|
||||||
|
@ -2090,9 +2090,9 @@ TEST_P(ImportData_TwoParamTest, Error_Integer) {
|
||||||
|
|
||||||
ast::ExpressionList params;
|
ast::ExpressionList params;
|
||||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2)));
|
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||||
|
|
||||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||||
|
|
||||||
|
@ -2295,9 +2295,9 @@ TEST_F(TypeDeterminerTest, ImportData_Distance_Error_Integer) {
|
||||||
|
|
||||||
ast::ExpressionList params;
|
ast::ExpressionList params;
|
||||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2)));
|
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||||
|
|
||||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||||
|
|
||||||
|
@ -2498,11 +2498,11 @@ TEST_P(ImportData_ThreeParamTest, Error_Integer) {
|
||||||
|
|
||||||
ast::ExpressionList params;
|
ast::ExpressionList params;
|
||||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2)));
|
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3)));
|
std::make_unique<ast::SintLiteral>(&i32, 3)));
|
||||||
|
|
||||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#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/int_literal.h"
|
|
||||||
#include "src/ast/location_decoration.h"
|
#include "src/ast/location_decoration.h"
|
||||||
#include "src/ast/loop_statement.h"
|
#include "src/ast/loop_statement.h"
|
||||||
#include "src/ast/member_accessor_expression.h"
|
#include "src/ast/member_accessor_expression.h"
|
||||||
|
@ -41,6 +40,7 @@
|
||||||
#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/set_decoration.h"
|
#include "src/ast/set_decoration.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/struct.h"
|
#include "src/ast/struct.h"
|
||||||
#include "src/ast/struct_member.h"
|
#include "src/ast/struct_member.h"
|
||||||
#include "src/ast/struct_member_offset_decoration.h"
|
#include "src/ast/struct_member_offset_decoration.h"
|
||||||
|
@ -218,7 +218,7 @@ void Builder::iterate(std::function<void(const Instruction&)> cb) const {
|
||||||
|
|
||||||
uint32_t Builder::GenerateU32Literal(uint32_t val) {
|
uint32_t Builder::GenerateU32Literal(uint32_t val) {
|
||||||
ast::type::U32Type u32;
|
ast::type::U32Type u32;
|
||||||
ast::IntLiteral lit(&u32, val);
|
ast::SintLiteral lit(&u32, val);
|
||||||
return GenerateLiteralIfNeeded(&lit);
|
return GenerateLiteralIfNeeded(&lit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -995,9 +995,9 @@ uint32_t Builder::GenerateLiteralIfNeeded(ast::Literal* lit) {
|
||||||
} else {
|
} else {
|
||||||
push_type(spv::Op::OpConstantFalse, {Operand::Int(type_id), result});
|
push_type(spv::Op::OpConstantFalse, {Operand::Int(type_id), result});
|
||||||
}
|
}
|
||||||
} else if (lit->IsInt()) {
|
} else if (lit->IsSint()) {
|
||||||
push_type(spv::Op::OpConstant, {Operand::Int(type_id), result,
|
push_type(spv::Op::OpConstant, {Operand::Int(type_id), result,
|
||||||
Operand::Int(lit->AsInt()->value())});
|
Operand::Int(lit->AsSint()->value())});
|
||||||
} else if (lit->IsUint()) {
|
} else if (lit->IsUint()) {
|
||||||
push_type(spv::Op::OpConstant, {Operand::Int(type_id), result,
|
push_type(spv::Op::OpConstant, {Operand::Int(type_id), result,
|
||||||
Operand::Int(lit->AsUint()->value())});
|
Operand::Int(lit->AsUint()->value())});
|
||||||
|
@ -1366,12 +1366,12 @@ bool Builder::GenerateSwitchStatement(ast::SwitchStatement* stmt) {
|
||||||
|
|
||||||
case_ids.push_back(block_id);
|
case_ids.push_back(block_id);
|
||||||
for (const auto& selector : item->selectors()) {
|
for (const auto& selector : item->selectors()) {
|
||||||
if (!selector->IsInt()) {
|
if (!selector->IsSint()) {
|
||||||
error_ = "expected integer literal for switch case label";
|
error_ = "expected integer literal for switch case label";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
params.push_back(Operand::Int(selector->AsInt()->value()));
|
params.push_back(Operand::Int(selector->AsSint()->value()));
|
||||||
params.push_back(Operand::Int(block_id));
|
params.push_back(Operand::Int(block_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
#include "src/ast/binary_expression.h"
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/member_accessor_expression.h"
|
#include "src/ast/member_accessor_expression.h"
|
||||||
#include "src/ast/module.h"
|
#include "src/ast/module.h"
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/struct.h"
|
#include "src/ast/struct.h"
|
||||||
#include "src/ast/struct_member.h"
|
#include "src/ast/struct_member.h"
|
||||||
#include "src/ast/type/array_type.h"
|
#include "src/ast/type/array_type.h"
|
||||||
|
@ -54,7 +54,7 @@ TEST_F(BuilderTest, ArrayAccessor) {
|
||||||
|
|
||||||
auto ary = std::make_unique<ast::IdentifierExpression>("ary");
|
auto ary = std::make_unique<ast::IdentifierExpression>("ary");
|
||||||
auto idx_expr = std::make_unique<ast::ScalarConstructorExpression>(
|
auto idx_expr = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1));
|
std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||||
|
|
||||||
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr));
|
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr));
|
||||||
|
|
||||||
|
@ -152,9 +152,9 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) {
|
||||||
std::move(ary), std::make_unique<ast::BinaryExpression>(
|
std::move(ary), std::make_unique<ast::BinaryExpression>(
|
||||||
ast::BinaryOp::kAdd,
|
ast::BinaryOp::kAdd,
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)),
|
std::make_unique<ast::SintLiteral>(&i32, 1)),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))));
|
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
ast::Module mod;
|
ast::Module mod;
|
||||||
|
@ -201,9 +201,9 @@ TEST_F(BuilderTest, ArrayAccessor_MultiLevel) {
|
||||||
std::make_unique<ast::ArrayAccessorExpression>(
|
std::make_unique<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("ary"),
|
std::make_unique<ast::IdentifierExpression>("ary"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3))),
|
std::make_unique<ast::SintLiteral>(&i32, 3))),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2)));
|
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
ast::Module mod;
|
ast::Module mod;
|
||||||
|
@ -252,7 +252,7 @@ TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) {
|
||||||
std::make_unique<ast::ArrayAccessorExpression>(
|
std::make_unique<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("ary"),
|
std::make_unique<ast::IdentifierExpression>("ary"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))),
|
std::make_unique<ast::SintLiteral>(&i32, 2))),
|
||||||
std::make_unique<ast::IdentifierExpression>("xy"));
|
std::make_unique<ast::IdentifierExpression>("xy"));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
|
@ -811,7 +811,7 @@ TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
|
||||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||||
std::make_unique<ast::IdentifierExpression>("yxz")),
|
std::make_unique<ast::IdentifierExpression>("yxz")),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
ast::Module mod;
|
ast::Module mod;
|
||||||
|
@ -896,10 +896,10 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
|
||||||
std::make_unique<ast::ArrayAccessorExpression>(
|
std::make_unique<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("index"),
|
std::make_unique<ast::IdentifierExpression>("index"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 0))),
|
std::make_unique<ast::SintLiteral>(&i32, 0))),
|
||||||
std::make_unique<ast::IdentifierExpression>("foo")),
|
std::make_unique<ast::IdentifierExpression>("foo")),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))),
|
std::make_unique<ast::SintLiteral>(&i32, 2))),
|
||||||
std::make_unique<ast::IdentifierExpression>("bar")),
|
std::make_unique<ast::IdentifierExpression>("bar")),
|
||||||
std::make_unique<ast::IdentifierExpression>("baz")),
|
std::make_unique<ast::IdentifierExpression>("baz")),
|
||||||
std::make_unique<ast::IdentifierExpression>("yx"));
|
std::make_unique<ast::IdentifierExpression>("yx"));
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
#include "src/ast/assignment_statement.h"
|
#include "src/ast/assignment_statement.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/member_accessor_expression.h"
|
#include "src/ast/member_accessor_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/struct.h"
|
#include "src/ast/struct.h"
|
||||||
#include "src/ast/struct_member.h"
|
#include "src/ast/struct_member.h"
|
||||||
#include "src/ast/type/f32_type.h"
|
#include "src/ast/type/f32_type.h"
|
||||||
|
@ -252,7 +252,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
|
||||||
auto ident = std::make_unique<ast::ArrayAccessorExpression>(
|
auto ident = std::make_unique<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("var"),
|
std::make_unique<ast::IdentifierExpression>("var"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
auto val = std::make_unique<ast::ScalarConstructorExpression>(
|
auto val = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f));
|
std::make_unique<ast::FloatLiteral>(&f32, 1.0f));
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,15 @@
|
||||||
#include "src/ast/binary_expression.h"
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/type/f32_type.h"
|
#include "src/ast/type/f32_type.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
#include "src/ast/type/matrix_type.h"
|
#include "src/ast/type/matrix_type.h"
|
||||||
#include "src/ast/type/u32_type.h"
|
#include "src/ast/type/u32_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/uint_literal.h"
|
||||||
#include "src/context.h"
|
#include "src/context.h"
|
||||||
#include "src/type_determiner.h"
|
#include "src/type_determiner.h"
|
||||||
#include "src/writer/spirv/builder.h"
|
#include "src/writer/spirv/builder.h"
|
||||||
|
@ -54,9 +55,9 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
|
|
||||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3));
|
std::make_unique<ast::SintLiteral>(&i32, 3));
|
||||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 4));
|
std::make_unique<ast::SintLiteral>(&i32, 4));
|
||||||
|
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
|
@ -84,20 +85,20 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
|
||||||
|
|
||||||
ast::ExpressionList vals;
|
ast::ExpressionList vals;
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
auto lhs =
|
auto lhs =
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
auto rhs =
|
auto rhs =
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
|
@ -144,9 +145,9 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
|
||||||
ast::type::U32Type u32;
|
ast::type::U32Type u32;
|
||||||
|
|
||||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 3));
|
std::make_unique<ast::UintLiteral>(&u32, 3));
|
||||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 4));
|
std::make_unique<ast::UintLiteral>(&u32, 4));
|
||||||
|
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
|
@ -174,20 +175,20 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
|
||||||
|
|
||||||
ast::ExpressionList vals;
|
ast::ExpressionList vals;
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
auto lhs =
|
auto lhs =
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
auto rhs =
|
auto rhs =
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
|
@ -318,9 +319,9 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
|
||||||
ast::type::U32Type u32;
|
ast::type::U32Type u32;
|
||||||
|
|
||||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 3));
|
std::make_unique<ast::UintLiteral>(&u32, 3));
|
||||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 4));
|
std::make_unique<ast::UintLiteral>(&u32, 4));
|
||||||
|
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
|
@ -350,20 +351,20 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
|
||||||
|
|
||||||
ast::ExpressionList vals;
|
ast::ExpressionList vals;
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
auto lhs =
|
auto lhs =
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&u32, 1)));
|
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||||
auto rhs =
|
auto rhs =
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
|
@ -407,9 +408,9 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
|
|
||||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3));
|
std::make_unique<ast::SintLiteral>(&i32, 3));
|
||||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 4));
|
std::make_unique<ast::SintLiteral>(&i32, 4));
|
||||||
|
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
|
@ -439,20 +440,20 @@ TEST_P(BinaryCompareSignedIntegerTest, Vector) {
|
||||||
|
|
||||||
ast::ExpressionList vals;
|
ast::ExpressionList vals;
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
auto lhs =
|
auto lhs =
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
auto rhs =
|
auto rhs =
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
#include "src/ast/cast_expression.h"
|
#include "src/ast/cast_expression.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/module.h"
|
#include "src/ast/module.h"
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/type/f32_type.h"
|
#include "src/ast/type/f32_type.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
#include "src/ast/type/u32_type.h"
|
#include "src/ast/type/u32_type.h"
|
||||||
|
@ -93,7 +93,7 @@ TEST_F(BuilderTest, Cast_I32ToFloat) {
|
||||||
|
|
||||||
ast::CastExpression cast(&f32,
|
ast::CastExpression cast(&f32,
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2)));
|
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
ast::Module mod;
|
ast::Module mod;
|
||||||
|
@ -211,7 +211,7 @@ TEST_F(BuilderTest, Cast_I32ToU32) {
|
||||||
|
|
||||||
ast::CastExpression cast(&u32,
|
ast::CastExpression cast(&u32,
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2)));
|
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
ast::Module mod;
|
ast::Module mod;
|
||||||
|
@ -262,7 +262,7 @@ TEST_F(BuilderTest, Cast_I32ToI32) {
|
||||||
|
|
||||||
ast::CastExpression cast(&i32,
|
ast::CastExpression cast(&i32,
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2)));
|
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
ast::Module mod;
|
ast::Module mod;
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
#include "src/ast/binary_expression.h"
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/type/f32_type.h"
|
#include "src/ast/type/f32_type.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
#include "src/ast/type/vector_type.h"
|
#include "src/ast/type/vector_type.h"
|
||||||
|
@ -220,7 +220,7 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
|
||||||
|
|
||||||
ast::Variable var("var", ast::StorageClass::kNone, &i32);
|
ast::Variable var("var", ast::StorageClass::kNone, &i32);
|
||||||
var.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
var.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2)));
|
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||||
var.set_is_const(true);
|
var.set_is_const(true);
|
||||||
|
|
||||||
td.RegisterVariableForTesting(&var);
|
td.RegisterVariableForTesting(&var);
|
||||||
|
|
|
@ -22,10 +22,10 @@
|
||||||
#include "src/ast/else_statement.h"
|
#include "src/ast/else_statement.h"
|
||||||
#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/int_literal.h"
|
|
||||||
#include "src/ast/loop_statement.h"
|
#include "src/ast/loop_statement.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/sint_literal.h"
|
||||||
#include "src/ast/statement_condition.h"
|
#include "src/ast/statement_condition.h"
|
||||||
#include "src/ast/type/bool_type.h"
|
#include "src/ast/type/bool_type.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
|
@ -86,7 +86,7 @@ TEST_F(BuilderTest, If_WithStatements) {
|
||||||
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))));
|
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||||
|
|
||||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||||
|
@ -138,13 +138,13 @@ TEST_F(BuilderTest, If_WithElse) {
|
||||||
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))));
|
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||||
|
|
||||||
ast::StatementList else_body;
|
ast::StatementList else_body;
|
||||||
else_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
else_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3))));
|
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||||
|
|
||||||
ast::ElseStatementList else_stmts;
|
ast::ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(
|
else_stmts.push_back(
|
||||||
|
@ -206,13 +206,13 @@ TEST_F(BuilderTest, If_WithElseIf) {
|
||||||
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))));
|
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||||
|
|
||||||
ast::StatementList else_body;
|
ast::StatementList else_body;
|
||||||
else_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
else_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3))));
|
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||||
|
|
||||||
auto else_cond = std::make_unique<ast::ScalarConstructorExpression>(
|
auto else_cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||||
|
@ -286,22 +286,22 @@ TEST_F(BuilderTest, If_WithMultiple) {
|
||||||
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))));
|
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||||
ast::StatementList elseif_1_body;
|
ast::StatementList elseif_1_body;
|
||||||
elseif_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
elseif_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3))));
|
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||||
ast::StatementList elseif_2_body;
|
ast::StatementList elseif_2_body;
|
||||||
elseif_2_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
elseif_2_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 4))));
|
std::make_unique<ast::SintLiteral>(&i32, 4))));
|
||||||
ast::StatementList else_body;
|
ast::StatementList else_body;
|
||||||
else_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
else_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 5))));
|
std::make_unique<ast::SintLiteral>(&i32, 5))));
|
||||||
|
|
||||||
auto elseif_1_cond = std::make_unique<ast::ScalarConstructorExpression>(
|
auto elseif_1_cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
#include "spirv/unified1/spirv.h"
|
#include "spirv/unified1/spirv.h"
|
||||||
#include "src/ast/bool_literal.h"
|
#include "src/ast/bool_literal.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/literal.h"
|
#include "src/ast/literal.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/type/bool_type.h"
|
#include "src/ast/type/bool_type.h"
|
||||||
#include "src/ast/type/f32_type.h"
|
#include "src/ast/type/f32_type.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
|
@ -84,7 +84,7 @@ TEST_F(BuilderTest, Literal_Bool_Dedup) {
|
||||||
|
|
||||||
TEST_F(BuilderTest, Literal_I32) {
|
TEST_F(BuilderTest, Literal_I32) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
ast::IntLiteral i(&i32, -23);
|
ast::SintLiteral i(&i32, -23);
|
||||||
|
|
||||||
ast::Module mod;
|
ast::Module mod;
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
|
@ -99,8 +99,8 @@ TEST_F(BuilderTest, Literal_I32) {
|
||||||
|
|
||||||
TEST_F(BuilderTest, Literal_I32_Dedup) {
|
TEST_F(BuilderTest, Literal_I32_Dedup) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
ast::IntLiteral i1(&i32, -23);
|
ast::SintLiteral i1(&i32, -23);
|
||||||
ast::IntLiteral i2(&i32, -23);
|
ast::SintLiteral i2(&i32, -23);
|
||||||
|
|
||||||
ast::Module mod;
|
ast::Module mod;
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
#include "src/ast/break_statement.h"
|
#include "src/ast/break_statement.h"
|
||||||
#include "src/ast/continue_statement.h"
|
#include "src/ast/continue_statement.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/loop_statement.h"
|
#include "src/ast/loop_statement.h"
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
#include "src/context.h"
|
#include "src/context.h"
|
||||||
#include "src/type_determiner.h"
|
#include "src/type_determiner.h"
|
||||||
|
@ -76,7 +76,7 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
|
||||||
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))));
|
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||||
|
|
||||||
ast::StatementList continuing;
|
ast::StatementList continuing;
|
||||||
ast::LoopStatement expr(std::move(body), std::move(continuing));
|
ast::LoopStatement expr(std::move(body), std::move(continuing));
|
||||||
|
@ -128,13 +128,13 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
|
||||||
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))));
|
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||||
|
|
||||||
ast::StatementList continuing;
|
ast::StatementList continuing;
|
||||||
continuing.push_back(std::make_unique<ast::AssignmentStatement>(
|
continuing.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3))));
|
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||||
ast::LoopStatement expr(std::move(body), std::move(continuing));
|
ast::LoopStatement expr(std::move(body), std::move(continuing));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
#include "src/ast/fallthrough_statement.h"
|
#include "src/ast/fallthrough_statement.h"
|
||||||
#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/int_literal.h"
|
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/switch_statement.h"
|
#include "src/ast/switch_statement.h"
|
||||||
#include "src/ast/type/bool_type.h"
|
#include "src/ast/type/bool_type.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
|
@ -45,7 +45,7 @@ TEST_F(BuilderTest, Switch_Empty) {
|
||||||
// switch (1) {
|
// switch (1) {
|
||||||
// }
|
// }
|
||||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1));
|
std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||||
|
|
||||||
ast::SwitchStatement expr(std::move(cond), ast::CaseStatementList{});
|
ast::SwitchStatement expr(std::move(cond), ast::CaseStatementList{});
|
||||||
|
|
||||||
|
@ -89,19 +89,19 @@ TEST_F(BuilderTest, Switch_WithCase) {
|
||||||
case_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
case_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1))));
|
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||||
|
|
||||||
ast::StatementList case_2_body;
|
ast::StatementList case_2_body;
|
||||||
case_2_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
case_2_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))));
|
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||||
|
|
||||||
ast::CaseSelectorList selector_1;
|
ast::CaseSelectorList selector_1;
|
||||||
selector_1.push_back(std::make_unique<ast::IntLiteral>(&i32, 1));
|
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||||
|
|
||||||
ast::CaseSelectorList selector_2;
|
ast::CaseSelectorList selector_2;
|
||||||
selector_2.push_back(std::make_unique<ast::IntLiteral>(&i32, 2));
|
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
||||||
|
@ -174,7 +174,7 @@ TEST_F(BuilderTest, Switch_WithDefault) {
|
||||||
default_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
default_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1))));
|
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(
|
cases.push_back(
|
||||||
|
@ -243,26 +243,26 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
|
||||||
case_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
case_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1))));
|
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||||
|
|
||||||
ast::StatementList case_2_body;
|
ast::StatementList case_2_body;
|
||||||
case_2_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
case_2_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))));
|
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||||
|
|
||||||
ast::StatementList default_body;
|
ast::StatementList default_body;
|
||||||
default_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
default_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3))));
|
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||||
|
|
||||||
ast::CaseSelectorList selector_1;
|
ast::CaseSelectorList selector_1;
|
||||||
selector_1.push_back(std::make_unique<ast::IntLiteral>(&i32, 1));
|
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||||
|
|
||||||
ast::CaseSelectorList selector_2;
|
ast::CaseSelectorList selector_2;
|
||||||
selector_2.push_back(std::make_unique<ast::IntLiteral>(&i32, 2));
|
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
selector_2.push_back(std::make_unique<ast::IntLiteral>(&i32, 3));
|
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 3));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
||||||
|
@ -344,26 +344,26 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
|
||||||
case_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
case_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1))));
|
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||||
case_1_body.push_back(std::make_unique<ast::FallthroughStatement>());
|
case_1_body.push_back(std::make_unique<ast::FallthroughStatement>());
|
||||||
|
|
||||||
ast::StatementList case_2_body;
|
ast::StatementList case_2_body;
|
||||||
case_2_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
case_2_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 2))));
|
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||||
|
|
||||||
ast::StatementList default_body;
|
ast::StatementList default_body;
|
||||||
default_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
default_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 3))));
|
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||||
|
|
||||||
ast::CaseSelectorList selector_1;
|
ast::CaseSelectorList selector_1;
|
||||||
selector_1.push_back(std::make_unique<ast::IntLiteral>(&i32, 1));
|
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||||
|
|
||||||
ast::CaseSelectorList selector_2;
|
ast::CaseSelectorList selector_2;
|
||||||
selector_2.push_back(std::make_unique<ast::IntLiteral>(&i32, 2));
|
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
||||||
|
@ -441,11 +441,11 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
|
||||||
case_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
case_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1))));
|
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||||
case_1_body.push_back(std::make_unique<ast::FallthroughStatement>());
|
case_1_body.push_back(std::make_unique<ast::FallthroughStatement>());
|
||||||
|
|
||||||
ast::CaseSelectorList selector_1;
|
ast::CaseSelectorList selector_1;
|
||||||
selector_1.push_back(std::make_unique<ast::IntLiteral>(&i32, 1));
|
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
||||||
|
@ -511,10 +511,10 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
|
||||||
case_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
case_1_body.push_back(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<ast::IdentifierExpression>("v"),
|
std::make_unique<ast::IdentifierExpression>("v"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1))));
|
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||||
|
|
||||||
ast::CaseSelectorList selector_1;
|
ast::CaseSelectorList selector_1;
|
||||||
selector_1.push_back(std::make_unique<ast::IntLiteral>(&i32, 1));
|
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||||
|
|
||||||
ast::CaseStatementList cases;
|
ast::CaseStatementList cases;
|
||||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/type/f32_type.h"
|
#include "src/ast/type/f32_type.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
#include "src/ast/unary_op_expression.h"
|
#include "src/ast/unary_op_expression.h"
|
||||||
|
@ -40,7 +40,7 @@ TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
|
||||||
ast::UnaryOpExpression expr(
|
ast::UnaryOpExpression expr(
|
||||||
ast::UnaryOp::kNegation,
|
ast::UnaryOp::kNegation,
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
ast::Module mod;
|
ast::Module mod;
|
||||||
|
@ -89,7 +89,7 @@ TEST_F(BuilderTest, UnaryOp_Not) {
|
||||||
|
|
||||||
ast::UnaryOpExpression expr(
|
ast::UnaryOpExpression expr(
|
||||||
ast::UnaryOp::kNot, std::make_unique<ast::ScalarConstructorExpression>(
|
ast::UnaryOp::kNot, std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::IntLiteral>(&i32, 1)));
|
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
ast::Module mod;
|
ast::Module mod;
|
||||||
|
|
|
@ -35,13 +35,13 @@
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#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/int_literal.h"
|
|
||||||
#include "src/ast/location_decoration.h"
|
#include "src/ast/location_decoration.h"
|
||||||
#include "src/ast/loop_statement.h"
|
#include "src/ast/loop_statement.h"
|
||||||
#include "src/ast/member_accessor_expression.h"
|
#include "src/ast/member_accessor_expression.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/set_decoration.h"
|
#include "src/ast/set_decoration.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/statement.h"
|
#include "src/ast/statement.h"
|
||||||
#include "src/ast/struct.h"
|
#include "src/ast/struct.h"
|
||||||
#include "src/ast/struct_member.h"
|
#include "src/ast/struct_member.h"
|
||||||
|
@ -299,8 +299,8 @@ bool GeneratorImpl::EmitLiteral(ast::Literal* lit) {
|
||||||
|
|
||||||
out_.precision(precision);
|
out_.precision(precision);
|
||||||
out_.flags(flags);
|
out_.flags(flags);
|
||||||
} else if (lit->IsInt()) {
|
} else if (lit->IsSint()) {
|
||||||
out_ << lit->AsInt()->value();
|
out_ << lit->AsSint()->value();
|
||||||
} else if (lit->IsUint()) {
|
} else if (lit->IsUint()) {
|
||||||
out_ << lit->AsUint()->value() << "u";
|
out_ << lit->AsUint()->value() << "u";
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#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/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
#include "src/writer/wgsl/generator_impl.h"
|
#include "src/writer/wgsl/generator_impl.h"
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ using GeneratorImplTest = testing::Test;
|
||||||
|
|
||||||
TEST_F(GeneratorImplTest, EmitExpression_ArrayAccessor) {
|
TEST_F(GeneratorImplTest, EmitExpression_ArrayAccessor) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
auto lit = std::make_unique<ast::IntLiteral>(&i32, 5);
|
auto lit = std::make_unique<ast::SintLiteral>(&i32, 5);
|
||||||
auto idx = std::make_unique<ast::ScalarConstructorExpression>(std::move(lit));
|
auto idx = std::make_unique<ast::ScalarConstructorExpression>(std::move(lit));
|
||||||
auto ary = std::make_unique<ast::IdentifierExpression>("ary");
|
auto ary = std::make_unique<ast::IdentifierExpression>("ary");
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include "src/ast/break_statement.h"
|
#include "src/ast/break_statement.h"
|
||||||
#include "src/ast/case_statement.h"
|
#include "src/ast/case_statement.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
#include "src/writer/wgsl/generator_impl.h"
|
#include "src/writer/wgsl/generator_impl.h"
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ TEST_F(GeneratorImplTest, Emit_Case) {
|
||||||
body.push_back(std::make_unique<ast::BreakStatement>());
|
body.push_back(std::make_unique<ast::BreakStatement>());
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(std::make_unique<ast::IntLiteral>(&i32, 5));
|
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||||
ast::CaseStatement c(std::move(lit), std::move(body));
|
ast::CaseStatement c(std::move(lit), std::move(body));
|
||||||
|
|
||||||
GeneratorImpl g;
|
GeneratorImpl g;
|
||||||
|
@ -56,8 +56,8 @@ TEST_F(GeneratorImplTest, Emit_Case_MultipleSelectors) {
|
||||||
body.push_back(std::make_unique<ast::BreakStatement>());
|
body.push_back(std::make_unique<ast::BreakStatement>());
|
||||||
|
|
||||||
ast::CaseSelectorList lit;
|
ast::CaseSelectorList lit;
|
||||||
lit.push_back(std::make_unique<ast::IntLiteral>(&i32, 5));
|
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||||
lit.push_back(std::make_unique<ast::IntLiteral>(&i32, 6));
|
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 6));
|
||||||
ast::CaseStatement c(std::move(lit), std::move(body));
|
ast::CaseStatement c(std::move(lit), std::move(body));
|
||||||
|
|
||||||
GeneratorImpl g;
|
GeneratorImpl g;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/bool_literal.h"
|
#include "src/ast/bool_literal.h"
|
||||||
#include "src/ast/float_literal.h"
|
#include "src/ast/float_literal.h"
|
||||||
#include "src/ast/int_literal.h"
|
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/type/array_type.h"
|
#include "src/ast/type/array_type.h"
|
||||||
#include "src/ast/type/bool_type.h"
|
#include "src/ast/type/bool_type.h"
|
||||||
#include "src/ast/type/f32_type.h"
|
#include "src/ast/type/f32_type.h"
|
||||||
|
@ -46,7 +46,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Bool) {
|
||||||
|
|
||||||
TEST_F(GeneratorImplTest, EmitConstructor_Int) {
|
TEST_F(GeneratorImplTest, EmitConstructor_Int) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
auto lit = std::make_unique<ast::IntLiteral>(&i32, -12345);
|
auto lit = std::make_unique<ast::SintLiteral>(&i32, -12345);
|
||||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||||
|
|
||||||
GeneratorImpl g;
|
GeneratorImpl g;
|
||||||
|
@ -107,7 +107,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Bool) {
|
||||||
TEST_F(GeneratorImplTest, EmitConstructor_Type_Int) {
|
TEST_F(GeneratorImplTest, EmitConstructor_Type_Int) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
|
|
||||||
auto lit = std::make_unique<ast::IntLiteral>(&i32, -12345);
|
auto lit = std::make_unique<ast::SintLiteral>(&i32, -12345);
|
||||||
ast::ExpressionList values;
|
ast::ExpressionList values;
|
||||||
values.push_back(
|
values.push_back(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
|
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include "src/ast/break_statement.h"
|
#include "src/ast/break_statement.h"
|
||||||
#include "src/ast/case_statement.h"
|
#include "src/ast/case_statement.h"
|
||||||
#include "src/ast/identifier_expression.h"
|
#include "src/ast/identifier_expression.h"
|
||||||
#include "src/ast/int_literal.h"
|
#include "src/ast/sint_literal.h"
|
||||||
#include "src/ast/switch_statement.h"
|
#include "src/ast/switch_statement.h"
|
||||||
#include "src/ast/type/i32_type.h"
|
#include "src/ast/type/i32_type.h"
|
||||||
#include "src/writer/wgsl/generator_impl.h"
|
#include "src/writer/wgsl/generator_impl.h"
|
||||||
|
@ -38,7 +38,7 @@ TEST_F(GeneratorImplTest, Emit_Switch) {
|
||||||
|
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
ast::CaseSelectorList case_val;
|
ast::CaseSelectorList case_val;
|
||||||
case_val.push_back(std::make_unique<ast::IntLiteral>(&i32, 5));
|
case_val.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||||
|
|
||||||
ast::StatementList case_body;
|
ast::StatementList case_body;
|
||||||
case_body.push_back(std::make_unique<ast::BreakStatement>());
|
case_body.push_back(std::make_unique<ast::BreakStatement>());
|
||||||
|
|
Loading…
Reference in New Issue