2020-11-03 21:40:20 +00:00
|
|
|
// 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/decoration.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
2020-11-18 19:33:30 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <unordered_set>
|
2020-11-03 21:40:20 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2020-11-19 18:55:01 +00:00
|
|
|
#include "src/ast/access_decoration.h"
|
2020-11-03 21:40:20 +00:00
|
|
|
#include "src/ast/array_decoration.h"
|
2020-11-18 19:33:30 +00:00
|
|
|
#include "src/ast/binding_decoration.h"
|
|
|
|
#include "src/ast/builtin_decoration.h"
|
2020-11-03 21:40:20 +00:00
|
|
|
#include "src/ast/constant_id_decoration.h"
|
2020-11-18 19:33:30 +00:00
|
|
|
#include "src/ast/function_decoration.h"
|
|
|
|
#include "src/ast/location_decoration.h"
|
|
|
|
#include "src/ast/stage_decoration.h"
|
|
|
|
#include "src/ast/stride_decoration.h"
|
|
|
|
#include "src/ast/struct_decoration.h"
|
|
|
|
#include "src/ast/struct_member_decoration.h"
|
|
|
|
#include "src/ast/struct_member_offset_decoration.h"
|
2020-11-13 21:58:28 +00:00
|
|
|
#include "src/ast/test_helper.h"
|
2020-11-19 18:55:01 +00:00
|
|
|
#include "src/ast/type_decoration.h"
|
2020-11-18 19:33:30 +00:00
|
|
|
#include "src/ast/variable_decoration.h"
|
|
|
|
#include "src/ast/workgroup_decoration.h"
|
2020-11-03 21:40:20 +00:00
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
namespace ast {
|
|
|
|
namespace {
|
|
|
|
|
2020-11-13 21:58:28 +00:00
|
|
|
using DecorationTest = TestHelper;
|
2020-11-03 21:40:20 +00:00
|
|
|
|
|
|
|
TEST_F(DecorationTest, AsCorrectType) {
|
2020-12-14 22:30:57 +00:00
|
|
|
auto* decoration = create<ConstantIdDecoration>(1);
|
2020-11-16 16:31:07 +00:00
|
|
|
auto* upcast = static_cast<Decoration*>(decoration);
|
|
|
|
auto* downcast = As<VariableDecoration>(upcast);
|
|
|
|
EXPECT_EQ(decoration, downcast);
|
2020-11-03 21:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DecorationTest, AsIncorrectType) {
|
2020-12-14 22:30:57 +00:00
|
|
|
auto* decoration = create<ConstantIdDecoration>(1);
|
2020-11-16 16:31:07 +00:00
|
|
|
auto* upcast = static_cast<Decoration*>(decoration);
|
|
|
|
auto* downcast = As<ArrayDecoration>(upcast);
|
|
|
|
EXPECT_EQ(nullptr, downcast);
|
2020-11-03 21:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DecorationTest, Is) {
|
2020-12-14 22:30:57 +00:00
|
|
|
Decoration* decoration = create<ConstantIdDecoration>(1);
|
2020-11-03 21:40:20 +00:00
|
|
|
EXPECT_TRUE(decoration->Is<VariableDecoration>());
|
|
|
|
EXPECT_FALSE(decoration->Is<ArrayDecoration>());
|
|
|
|
}
|
|
|
|
|
2020-11-18 19:33:30 +00:00
|
|
|
TEST_F(DecorationTest, Kinds) {
|
|
|
|
EXPECT_EQ(ArrayDecoration::Kind, DecorationKind::kArray);
|
ast: Remove non-group DecorationKind enums
The following DecorationKinds were sub-types of core decoration types:
kStride, kStage, kWorkgroup, kStructMemberOffset, kAccess, kBinding, kBuiltin, kConstantId, kLocation
These only existed for casting (not for error messages), and are no longer needed, so remove them.
Change-Id: I1e4bb9bf51952c6e86bac984d0d667a071ca80bf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34303
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-11-30 23:30:58 +00:00
|
|
|
EXPECT_EQ(StrideDecoration::Kind, DecorationKind::kArray);
|
2020-11-18 19:33:30 +00:00
|
|
|
EXPECT_EQ(FunctionDecoration::Kind, DecorationKind::kFunction);
|
ast: Remove non-group DecorationKind enums
The following DecorationKinds were sub-types of core decoration types:
kStride, kStage, kWorkgroup, kStructMemberOffset, kAccess, kBinding, kBuiltin, kConstantId, kLocation
These only existed for casting (not for error messages), and are no longer needed, so remove them.
Change-Id: I1e4bb9bf51952c6e86bac984d0d667a071ca80bf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34303
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-11-30 23:30:58 +00:00
|
|
|
EXPECT_EQ(StageDecoration::Kind, DecorationKind::kFunction);
|
|
|
|
EXPECT_EQ(WorkgroupDecoration::Kind, DecorationKind::kFunction);
|
2020-11-18 19:33:30 +00:00
|
|
|
EXPECT_EQ(StructDecoration::Kind, DecorationKind::kStruct);
|
|
|
|
EXPECT_EQ(StructMemberDecoration::Kind, DecorationKind::kStructMember);
|
ast: Remove non-group DecorationKind enums
The following DecorationKinds were sub-types of core decoration types:
kStride, kStage, kWorkgroup, kStructMemberOffset, kAccess, kBinding, kBuiltin, kConstantId, kLocation
These only existed for casting (not for error messages), and are no longer needed, so remove them.
Change-Id: I1e4bb9bf51952c6e86bac984d0d667a071ca80bf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34303
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-11-30 23:30:58 +00:00
|
|
|
EXPECT_EQ(StructMemberOffsetDecoration::Kind, DecorationKind::kStructMember);
|
2020-11-19 18:55:01 +00:00
|
|
|
EXPECT_EQ(TypeDecoration::Kind, DecorationKind::kType);
|
ast: Remove non-group DecorationKind enums
The following DecorationKinds were sub-types of core decoration types:
kStride, kStage, kWorkgroup, kStructMemberOffset, kAccess, kBinding, kBuiltin, kConstantId, kLocation
These only existed for casting (not for error messages), and are no longer needed, so remove them.
Change-Id: I1e4bb9bf51952c6e86bac984d0d667a071ca80bf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34303
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-11-30 23:30:58 +00:00
|
|
|
EXPECT_EQ(AccessDecoration::Kind, DecorationKind::kType);
|
2020-11-18 19:33:30 +00:00
|
|
|
EXPECT_EQ(VariableDecoration::Kind, DecorationKind::kVariable);
|
ast: Remove non-group DecorationKind enums
The following DecorationKinds were sub-types of core decoration types:
kStride, kStage, kWorkgroup, kStructMemberOffset, kAccess, kBinding, kBuiltin, kConstantId, kLocation
These only existed for casting (not for error messages), and are no longer needed, so remove them.
Change-Id: I1e4bb9bf51952c6e86bac984d0d667a071ca80bf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34303
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-11-30 23:30:58 +00:00
|
|
|
EXPECT_EQ(BindingDecoration::Kind, DecorationKind::kVariable);
|
|
|
|
EXPECT_EQ(BuiltinDecoration::Kind, DecorationKind::kVariable);
|
|
|
|
EXPECT_EQ(ConstantIdDecoration::Kind, DecorationKind::kVariable);
|
|
|
|
EXPECT_EQ(LocationDecoration::Kind, DecorationKind::kVariable);
|
2020-11-18 19:33:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 21:40:20 +00:00
|
|
|
} // namespace
|
|
|
|
} // namespace ast
|
|
|
|
} // namespace tint
|