-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathmap_type.cc
More file actions
81 lines (66 loc) · 2.53 KB
/
Copy pathmap_type.cc
File metadata and controls
81 lines (66 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2022 Google LLC
//
// 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
//
// https://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 "base/types/map_type.h"
#include <string>
#include <utility>
#include "absl/base/macros.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "base/internal/data.h"
#include "base/types/dyn_type.h"
namespace cel {
CEL_INTERNAL_TYPE_IMPL(MapType);
absl::Span<const absl::string_view> MapType::aliases() const {
static constexpr absl::string_view kAliases[] = {"google.protobuf.Struct"};
if (key()->kind() == Kind::kString && value()->kind() == Kind::kDyn) {
// Currently google.protobuf.Struct resolves to map<string, dyn>.
return absl::MakeConstSpan(kAliases);
}
return absl::Span<const absl::string_view>();
}
std::string MapType::DebugString() const {
return absl::StrCat(name(), "(", key()->DebugString(), ", ",
value()->DebugString(), ")");
}
const Handle<Type>& MapType::key() const {
if (base_internal::Metadata::IsStoredInline(*this)) {
return static_cast<const base_internal::LegacyMapType&>(*this).key();
}
return static_cast<const base_internal::ModernMapType&>(*this).key();
}
const Handle<Type>& MapType::value() const {
if (base_internal::Metadata::IsStoredInline(*this)) {
return static_cast<const base_internal::LegacyMapType&>(*this).value();
}
return static_cast<const base_internal::ModernMapType&>(*this).value();
}
namespace base_internal {
const Handle<Type>& LegacyMapType::key() const {
return DynType::Get().As<Type>();
}
const Handle<Type>& LegacyMapType::value() const {
return DynType::Get().As<Type>();
}
ModernMapType::ModernMapType(Handle<Type> key, Handle<Type> value)
: MapType(),
HeapData(kKind),
key_(std::move(key)),
value_(std::move(value)) {
// Ensure `Type*` and `HeapData*` are not thunked.
ABSL_ASSERT(reinterpret_cast<uintptr_t>(static_cast<Type*>(this)) ==
reinterpret_cast<uintptr_t>(static_cast<HeapData*>(this)));
}
} // namespace base_internal
} // namespace cel