[ast] Add constant_id decoration
This CL adds AST support for the constant_id decoration. Bug: tint:150 Change-Id: Ifde5a5325f770567ea24129e786953d89f3f514b Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29100 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
parent
095f5f71b5
commit
9e7f9dc96c
3
BUILD.gn
3
BUILD.gn
|
@ -243,6 +243,8 @@ source_set("libtint_core_src") {
|
|||
"src/ast/call_statement.h",
|
||||
"src/ast/case_statement.cc",
|
||||
"src/ast/case_statement.h",
|
||||
"src/ast/constant_id_decoration.cc",
|
||||
"src/ast/constant_id_decoration.h",
|
||||
"src/ast/constructor_expression.cc",
|
||||
"src/ast/constructor_expression.h",
|
||||
"src/ast/continue_statement.cc",
|
||||
|
@ -695,6 +697,7 @@ source_set("tint_unittests_core_src") {
|
|||
"src/ast/call_expression_test.cc",
|
||||
"src/ast/call_statement_test.cc",
|
||||
"src/ast/case_statement_test.cc",
|
||||
"src/ast/constant_id_decoration_test.cc",
|
||||
"src/ast/continue_statement_test.cc",
|
||||
"src/ast/decorated_variable_test.cc",
|
||||
"src/ast/discard_statement_test.cc",
|
||||
|
|
|
@ -64,6 +64,8 @@ set(TINT_LIB_SRCS
|
|||
ast/call_statement.h
|
||||
ast/case_statement.cc
|
||||
ast/case_statement.h
|
||||
ast/constant_id_decoration.cc
|
||||
ast/constant_id_decoration.h
|
||||
ast/constructor_expression.cc
|
||||
ast/constructor_expression.h
|
||||
ast/continue_statement.cc
|
||||
|
@ -304,6 +306,7 @@ set(TINT_TEST_SRCS
|
|||
ast/call_expression_test.cc
|
||||
ast/call_statement_test.cc
|
||||
ast/case_statement_test.cc
|
||||
ast/constant_id_decoration_test.cc
|
||||
ast/continue_statement_test.cc
|
||||
ast/discard_statement_test.cc
|
||||
ast/decorated_variable_test.cc
|
||||
|
|
|
@ -31,6 +31,7 @@ TEST_F(BindingDecorationTest, Is) {
|
|||
BindingDecoration d{2};
|
||||
EXPECT_TRUE(d.IsBinding());
|
||||
EXPECT_FALSE(d.IsBuiltin());
|
||||
EXPECT_FALSE(d.IsConstantId());
|
||||
EXPECT_FALSE(d.IsLocation());
|
||||
EXPECT_FALSE(d.IsSet());
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ TEST_F(BuiltinDecorationTest, Is) {
|
|||
BuiltinDecoration d{Builtin::kFragDepth};
|
||||
EXPECT_FALSE(d.IsBinding());
|
||||
EXPECT_TRUE(d.IsBuiltin());
|
||||
EXPECT_FALSE(d.IsConstantId());
|
||||
EXPECT_FALSE(d.IsLocation());
|
||||
EXPECT_FALSE(d.IsSet());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
ConstantIdDecoration::ConstantIdDecoration(uint32_t val) : value_(val) {}
|
||||
|
||||
ConstantIdDecoration::~ConstantIdDecoration() = default;
|
||||
|
||||
bool ConstantIdDecoration::IsConstantId() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConstantIdDecoration::to_str(std::ostream& out) const {
|
||||
out << "ConstantIdDecoration{" << value_ << "}" << std::endl;
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_AST_CONSTANT_ID_DECORATION_H_
|
||||
#define SRC_AST_CONSTANT_ID_DECORATION_H_
|
||||
|
||||
#include "src/ast/builtin.h"
|
||||
#include "src/ast/variable_decoration.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A constant id decoration
|
||||
class ConstantIdDecoration : public VariableDecoration {
|
||||
public:
|
||||
/// constructor
|
||||
/// @param val the constant_id value
|
||||
explicit ConstantIdDecoration(uint32_t val);
|
||||
~ConstantIdDecoration() override;
|
||||
|
||||
/// @returns true if this is a constant_id decoration
|
||||
bool IsConstantId() const override;
|
||||
|
||||
/// @returns the constant id value
|
||||
uint32_t value() const { return value_; }
|
||||
|
||||
/// Outputs the decoration to the given stream
|
||||
/// @param out the stream to output too
|
||||
void to_str(std::ostream& out) const override;
|
||||
|
||||
private:
|
||||
uint32_t value_ = 0;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_AST_CONSTANT_ID_DECORATION_H_
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using ConstantIdDecorationTest = testing::Test;
|
||||
|
||||
TEST_F(ConstantIdDecorationTest, Creation) {
|
||||
ConstantIdDecoration d{12};
|
||||
EXPECT_EQ(12u, d.value());
|
||||
}
|
||||
|
||||
TEST_F(ConstantIdDecorationTest, Is) {
|
||||
ConstantIdDecoration d{27};
|
||||
EXPECT_FALSE(d.IsBinding());
|
||||
EXPECT_FALSE(d.IsBuiltin());
|
||||
EXPECT_TRUE(d.IsConstantId());
|
||||
EXPECT_FALSE(d.IsLocation());
|
||||
EXPECT_FALSE(d.IsSet());
|
||||
}
|
||||
|
||||
TEST_F(ConstantIdDecorationTest, ToStr) {
|
||||
ConstantIdDecoration d{1200};
|
||||
std::ostringstream out;
|
||||
d.to_str(out);
|
||||
EXPECT_EQ(out.str(), R"(ConstantIdDecoration{1200}
|
||||
)");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
|
@ -33,6 +33,7 @@ TEST_F(LocationDecorationTest, Is) {
|
|||
LocationDecoration d{2};
|
||||
EXPECT_FALSE(d.IsBinding());
|
||||
EXPECT_FALSE(d.IsBuiltin());
|
||||
EXPECT_FALSE(d.IsConstantId());
|
||||
EXPECT_TRUE(d.IsLocation());
|
||||
EXPECT_FALSE(d.IsSet());
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ TEST_F(SetDecorationTest, Is) {
|
|||
SetDecoration d{2};
|
||||
EXPECT_FALSE(d.IsBinding());
|
||||
EXPECT_FALSE(d.IsBuiltin());
|
||||
EXPECT_FALSE(d.IsConstantId());
|
||||
EXPECT_FALSE(d.IsLocation());
|
||||
EXPECT_TRUE(d.IsSet());
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "src/ast/binding_decoration.h"
|
||||
#include "src/ast/builtin_decoration.h"
|
||||
#include "src/ast/constant_id_decoration.h"
|
||||
#include "src/ast/location_decoration.h"
|
||||
#include "src/ast/set_decoration.h"
|
||||
|
||||
|
@ -40,6 +41,10 @@ bool VariableDecoration::IsLocation() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool VariableDecoration::IsConstantId() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VariableDecoration::IsSet() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -54,6 +59,11 @@ BuiltinDecoration* VariableDecoration::AsBuiltin() {
|
|||
return static_cast<BuiltinDecoration*>(this);
|
||||
}
|
||||
|
||||
ConstantIdDecoration* VariableDecoration::AsConstantId() {
|
||||
assert(IsConstantId());
|
||||
return static_cast<ConstantIdDecoration*>(this);
|
||||
}
|
||||
|
||||
LocationDecoration* VariableDecoration::AsLocation() {
|
||||
assert(IsLocation());
|
||||
return static_cast<LocationDecoration*>(this);
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace ast {
|
|||
|
||||
class BindingDecoration;
|
||||
class BuiltinDecoration;
|
||||
class ConstantIdDecoration;
|
||||
class LocationDecoration;
|
||||
class SetDecoration;
|
||||
|
||||
|
@ -37,6 +38,8 @@ class VariableDecoration {
|
|||
virtual bool IsBinding() const;
|
||||
/// @returns true if this is a builtin decoration
|
||||
virtual bool IsBuiltin() const;
|
||||
/// @returns true if this is a constant id decoration
|
||||
virtual bool IsConstantId() const;
|
||||
/// @returns true if this is a location decoration
|
||||
virtual bool IsLocation() const;
|
||||
/// @returns true if this is a set decoration
|
||||
|
@ -46,6 +49,8 @@ class VariableDecoration {
|
|||
BindingDecoration* AsBinding();
|
||||
/// @returns the decoration as a builtin decoration
|
||||
BuiltinDecoration* AsBuiltin();
|
||||
/// @returns the decoration as a constant id decoration
|
||||
ConstantIdDecoration* AsConstantId();
|
||||
/// @returns the decoration as a location decoration
|
||||
LocationDecoration* AsLocation();
|
||||
/// @returns the decoration as a set decoration
|
||||
|
|
Loading…
Reference in New Issue