Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add const to TypeProvider and ValueProvider #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/list_value_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class ListValueBuilderImpl<Value> final : public ListValueBuilder {
} // namespace

absl::StatusOr<Unique<ListValueBuilder>> ValueProvider::NewListValueBuilder(
ValueFactory& value_factory, ListTypeView type) {
ValueFactory& value_factory, ListTypeView type) const {
auto memory_manager = value_factory.GetMemoryManager();
switch (type.element().kind()) {
case TypeKind::kBool:
Expand Down
2 changes: 1 addition & 1 deletion common/map_value_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ class MapValueBuilderImpl<Value, Value> final : public MapValueBuilder {
} // namespace

absl::StatusOr<Unique<MapValueBuilder>> ValueProvider::NewMapValueBuilder(
ValueFactory& value_factory, MapTypeView type) {
ValueFactory& value_factory, MapTypeView type) const {
auto memory_manager = value_factory.GetMemoryManager();
switch (type.key().kind()) {
case TypeKind::kBool:
Expand Down
4 changes: 2 additions & 2 deletions common/type_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const WellKnownTypesMap& GetWellKnownTypesMap() {
} // namespace

absl::StatusOr<absl::optional<TypeView>> TypeProvider::FindType(
TypeFactory& type_factory, absl::string_view name, Type& scratch) {
TypeFactory& type_factory, absl::string_view name, Type& scratch) const {
const auto& well_known_types = GetWellKnownTypesMap();
if (auto it = well_known_types.find(name); it != well_known_types.end()) {
return it->second.type;
Expand All @@ -210,7 +210,7 @@ absl::StatusOr<absl::optional<StructTypeFieldView>>
TypeProvider::FindStructTypeFieldByName(TypeFactory& type_factory,
absl::string_view type,
absl::string_view name,
StructTypeField& scratch) {
StructTypeField& scratch) const {
const auto& well_known_types = GetWellKnownTypesMap();
if (auto it = well_known_types.find(type); it != well_known_types.end()) {
return it->second.FieldByName(name);
Expand Down
10 changes: 5 additions & 5 deletions common/type_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ class TypeProvider {
// `FindType` find the type corresponding to name `name`.
absl::StatusOr<absl::optional<TypeView>> FindType(
TypeFactory& type_factory, absl::string_view name,
Type& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND);
Type& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) const;

// `FindStructTypeFieldByName` find the name, number, and type of the field
// `name` in type `type`.
absl::StatusOr<absl::optional<StructTypeFieldView>> FindStructTypeFieldByName(
TypeFactory& type_factory, absl::string_view type, absl::string_view name,
StructTypeField& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND);
StructTypeField& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) const;

// `FindStructTypeFieldByName` find the name, number, and type of the field
// `name` in struct type `type`.
absl::StatusOr<absl::optional<StructTypeFieldView>> FindStructTypeFieldByName(
TypeFactory& type_factory, StructTypeView type, absl::string_view name,
StructTypeField& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) {
StructTypeField& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) const {
return FindStructTypeFieldByName(type_factory, type.name(), name, scratch);
}

protected:
virtual absl::StatusOr<absl::optional<TypeView>> FindTypeImpl(
TypeFactory& type_factory, absl::string_view name,
Type& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) = 0;
Type& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) const = 0;

virtual absl::StatusOr<absl::optional<StructTypeFieldView>>
FindStructTypeFieldByNameImpl(
TypeFactory& type_factory, absl::string_view type, absl::string_view name,
StructTypeField& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) = 0;
StructTypeField& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) const = 0;
};

Shared<TypeProvider> NewThreadCompatibleTypeProvider(
Expand Down
4 changes: 2 additions & 2 deletions common/types/legacy_type_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
namespace cel::common_internal {

absl::StatusOr<absl::optional<TypeView>> LegacyTypeProvider::FindTypeImpl(
TypeFactory&, absl::string_view, Type&) {
TypeFactory&, absl::string_view, Type&) const {
return absl::nullopt;
}

absl::StatusOr<absl::optional<StructTypeFieldView>>
LegacyTypeProvider::FindStructTypeFieldByNameImpl(TypeFactory&,
absl::string_view,
absl::string_view,
StructTypeField&) {
StructTypeField&) const {
return absl::nullopt;
}

Expand Down
4 changes: 2 additions & 2 deletions common/types/legacy_type_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class LegacyTypeProvider : public virtual TypeProvider {
protected:
absl::StatusOr<absl::optional<TypeView>> FindTypeImpl(
TypeFactory& type_factory, absl::string_view name,
Type& scratch) override;
Type& scratch) const override;

absl::StatusOr<absl::optional<StructTypeFieldView>>
FindStructTypeFieldByNameImpl(TypeFactory& type_factory,
absl::string_view type, absl::string_view name,
StructTypeField& scratch) override;
StructTypeField& scratch) const override;
};

} // namespace cel::common_internal
Expand Down
9 changes: 4 additions & 5 deletions common/types/thread_compatible_type_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ namespace cel::common_internal {

absl::StatusOr<absl::optional<TypeView>>
ThreadCompatibleTypeProvider::FindTypeImpl(TypeFactory&, absl::string_view,
Type&) {
Type&) const {
return absl::nullopt;
}

absl::StatusOr<absl::optional<StructTypeFieldView>>
ThreadCompatibleTypeProvider::FindStructTypeFieldByNameImpl(TypeFactory&,
absl::string_view,
absl::string_view,
StructTypeField&) {
ThreadCompatibleTypeProvider::FindStructTypeFieldByNameImpl(
TypeFactory&, absl::string_view, absl::string_view,
StructTypeField&) const {
return absl::nullopt;
}

Expand Down
4 changes: 2 additions & 2 deletions common/types/thread_compatible_type_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class ThreadCompatibleTypeProvider : public virtual TypeProvider {
protected:
absl::StatusOr<absl::optional<TypeView>> FindTypeImpl(
TypeFactory& type_factory, absl::string_view name,
Type& scratch) override;
Type& scratch) const override;

absl::StatusOr<absl::optional<StructTypeFieldView>>
FindStructTypeFieldByNameImpl(TypeFactory& type_factory,
absl::string_view type, absl::string_view name,
StructTypeField& scratch) override;
StructTypeField& scratch) const override;
};

} // namespace cel::common_internal
Expand Down
42 changes: 21 additions & 21 deletions common/value_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class WellKnownValueBuilder : public ValueBuilder {

class BoolValueBuilder final : public WellKnownValueBuilder {
public:
explicit BoolValueBuilder(ValueProvider& value_provider,
explicit BoolValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory) {}

absl::Status SetFieldByName(absl::string_view name, Value value) override {
Expand Down Expand Up @@ -91,7 +91,7 @@ class BoolValueBuilder final : public WellKnownValueBuilder {

class Int32ValueBuilder final : public WellKnownValueBuilder {
public:
explicit Int32ValueBuilder(ValueProvider& value_provider,
explicit Int32ValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory) {}

absl::Status SetFieldByName(absl::string_view name, Value value) override {
Expand Down Expand Up @@ -131,7 +131,7 @@ class Int32ValueBuilder final : public WellKnownValueBuilder {

class Int64ValueBuilder final : public WellKnownValueBuilder {
public:
explicit Int64ValueBuilder(ValueProvider& value_provider,
explicit Int64ValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory) {}

absl::Status SetFieldByName(absl::string_view name, Value value) override {
Expand Down Expand Up @@ -170,7 +170,7 @@ class Int64ValueBuilder final : public WellKnownValueBuilder {

class UInt32ValueBuilder final : public WellKnownValueBuilder {
public:
explicit UInt32ValueBuilder(ValueProvider& value_provider,
explicit UInt32ValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory) {}

absl::Status SetFieldByName(absl::string_view name, Value value) override {
Expand Down Expand Up @@ -210,7 +210,7 @@ class UInt32ValueBuilder final : public WellKnownValueBuilder {

class UInt64ValueBuilder final : public WellKnownValueBuilder {
public:
explicit UInt64ValueBuilder(ValueProvider& value_provider,
explicit UInt64ValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory) {}

absl::Status SetFieldByName(absl::string_view name, Value value) override {
Expand Down Expand Up @@ -249,7 +249,7 @@ class UInt64ValueBuilder final : public WellKnownValueBuilder {

class FloatValueBuilder final : public WellKnownValueBuilder {
public:
explicit FloatValueBuilder(ValueProvider& value_provider,
explicit FloatValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory) {}

absl::Status SetFieldByName(absl::string_view name, Value value) override {
Expand Down Expand Up @@ -289,7 +289,7 @@ class FloatValueBuilder final : public WellKnownValueBuilder {

class DoubleValueBuilder final : public WellKnownValueBuilder {
public:
explicit DoubleValueBuilder(ValueProvider& value_provider,
explicit DoubleValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory) {}

absl::Status SetFieldByName(absl::string_view name, Value value) override {
Expand Down Expand Up @@ -328,7 +328,7 @@ class DoubleValueBuilder final : public WellKnownValueBuilder {

class StringValueBuilder final : public WellKnownValueBuilder {
public:
explicit StringValueBuilder(ValueProvider& value_provider,
explicit StringValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory) {}

absl::Status SetFieldByName(absl::string_view name, Value value) override {
Expand Down Expand Up @@ -367,7 +367,7 @@ class StringValueBuilder final : public WellKnownValueBuilder {

class BytesValueBuilder final : public WellKnownValueBuilder {
public:
explicit BytesValueBuilder(ValueProvider& value_provider,
explicit BytesValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory) {}

absl::Status SetFieldByName(absl::string_view name, Value value) override {
Expand Down Expand Up @@ -406,7 +406,7 @@ class BytesValueBuilder final : public WellKnownValueBuilder {

class DurationValueBuilder final : public WellKnownValueBuilder {
public:
explicit DurationValueBuilder(ValueProvider& value_provider,
explicit DurationValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory) {}

absl::Status SetFieldByName(absl::string_view name, Value value) override {
Expand Down Expand Up @@ -466,7 +466,7 @@ class DurationValueBuilder final : public WellKnownValueBuilder {

class TimestampValueBuilder final : public WellKnownValueBuilder {
public:
explicit TimestampValueBuilder(ValueProvider& value_provider,
explicit TimestampValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory) {}

absl::Status SetFieldByName(absl::string_view name, Value value) override {
Expand Down Expand Up @@ -528,7 +528,7 @@ class TimestampValueBuilder final : public WellKnownValueBuilder {

class JsonValueBuilder final : public WellKnownValueBuilder {
public:
explicit JsonValueBuilder(ValueProvider& value_provider,
explicit JsonValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory)
: value_factory_(value_factory) {}

Expand Down Expand Up @@ -640,7 +640,7 @@ class JsonValueBuilder final : public WellKnownValueBuilder {

class JsonArrayValueBuilder final : public WellKnownValueBuilder {
public:
explicit JsonArrayValueBuilder(ValueProvider& value_provider,
explicit JsonArrayValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory)
: value_factory_(value_factory) {}

Expand Down Expand Up @@ -683,7 +683,7 @@ class JsonArrayValueBuilder final : public WellKnownValueBuilder {

class JsonObjectValueBuilder final : public WellKnownValueBuilder {
public:
explicit JsonObjectValueBuilder(ValueProvider& value_provider,
explicit JsonObjectValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory)
: value_factory_(value_factory) {}

Expand Down Expand Up @@ -731,7 +731,7 @@ class JsonObjectValueBuilder final : public WellKnownValueBuilder {

class AnyValueBuilder final : public WellKnownValueBuilder {
public:
explicit AnyValueBuilder(ValueProvider& value_provider,
explicit AnyValueBuilder(const ValueProvider& value_provider,
ValueFactory& value_factory)
: value_provider_(value_provider), value_factory_(value_factory) {}

Expand Down Expand Up @@ -791,18 +791,18 @@ class AnyValueBuilder final : public WellKnownValueBuilder {
return TypeConversionError(value.GetTypeName(), "bytes").NativeValue();
}

ValueProvider& value_provider_;
const ValueProvider& value_provider_;
ValueFactory& value_factory_;
std::string type_url_;
absl::Cord value_;
};

using WellKnownValueBuilderProvider = Unique<WellKnownValueBuilder> (*)(
MemoryManagerRef, ValueProvider&, ValueFactory&);
MemoryManagerRef, const ValueProvider&, ValueFactory&);

template <typename T>
Unique<WellKnownValueBuilder> WellKnownValueBuilderProviderFor(
MemoryManagerRef memory_manager, ValueProvider& value_provider,
MemoryManagerRef memory_manager, const ValueProvider& value_provider,
ValueFactory& value_factory) {
return memory_manager.MakeUnique<T>(value_provider, value_factory);
}
Expand Down Expand Up @@ -893,7 +893,7 @@ class ValueBuilderForStruct final : public ValueBuilder {

absl::StatusOr<absl::optional<Unique<ValueBuilder>>>
ValueProvider::NewValueBuilder(ValueFactory& value_factory,
absl::string_view name) {
absl::string_view name) const {
const auto& well_known_value_builders = GetWellKnownValueBuilderMap();
if (auto well_known_value_builder = well_known_value_builders.find(name);
well_known_value_builder != well_known_value_builders.end()) {
Expand All @@ -913,7 +913,7 @@ ValueProvider::NewValueBuilder(ValueFactory& value_factory,

absl::StatusOr<absl::optional<Value>> ValueProvider::DeserializeValue(
ValueFactory& value_factory, absl::string_view type_url,
const absl::Cord& value) {
const absl::Cord& value) const {
if (absl::StartsWith(type_url, kTypeGoogleApisComPrefix)) {
const auto& well_known_value_builders = GetWellKnownValueBuilderMap();
if (auto well_known_value_builder = well_known_value_builders.find(
Expand All @@ -929,7 +929,7 @@ absl::StatusOr<absl::optional<Value>> ValueProvider::DeserializeValue(
}

absl::StatusOr<absl::optional<Value>> ValueProvider::DeserializeValueImpl(
ValueFactory&, absl::string_view, const absl::Cord&) {
ValueFactory&, absl::string_view, const absl::Cord&) const {
return absl::nullopt;
}

Expand Down
15 changes: 8 additions & 7 deletions common/value_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,41 @@ class ValueProvider : public virtual TypeProvider {
// `NewListValueBuilder` returns a new `ListValueBuilderInterface` for the
// corresponding `ListType` `type`.
absl::StatusOr<Unique<ListValueBuilder>> NewListValueBuilder(
ValueFactory& value_factory, ListTypeView type);
ValueFactory& value_factory, ListTypeView type) const;

// `NewMapValueBuilder` returns a new `MapValueBuilderInterface` for the
// corresponding `MapType` `type`.
absl::StatusOr<Unique<MapValueBuilder>> NewMapValueBuilder(
ValueFactory& value_factory, MapTypeView type);
ValueFactory& value_factory, MapTypeView type) const;

// `NewStructValueBuilder` returns a new `StructValueBuilder` for the
// corresponding `StructType` `type`.
virtual absl::StatusOr<absl::optional<Unique<StructValueBuilder>>>
NewStructValueBuilder(ValueFactory& value_factory, StructTypeView type) = 0;
NewStructValueBuilder(ValueFactory& value_factory,
StructTypeView type) const = 0;

// `NewValueBuilder` returns a new `ValueBuilder` for the corresponding type
// `name`. It is primarily used to handle wrapper types which sometimes show
// up literally in expressions.
absl::StatusOr<absl::optional<Unique<ValueBuilder>>> NewValueBuilder(
ValueFactory& value_factory, absl::string_view name);
ValueFactory& value_factory, absl::string_view name) const;

// `FindValue` returns a new `Value` for the corresponding name `name`. This
// can be used to translate enum names to numeric values.
virtual absl::StatusOr<absl::optional<ValueView>> FindValue(
ValueFactory& value_factory, absl::string_view name,
Value& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) = 0;
Value& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) const = 0;

// `DeserializeValue` deserializes the bytes of `value` according to
// `type_url`. Returns `NOT_FOUND` if `type_url` is unrecognized.
absl::StatusOr<absl::optional<Value>> DeserializeValue(
ValueFactory& value_factory, absl::string_view type_url,
const absl::Cord& value);
const absl::Cord& value) const;

protected:
virtual absl::StatusOr<absl::optional<Value>> DeserializeValueImpl(
ValueFactory& value_factory, absl::string_view type_url,
const absl::Cord& value);
const absl::Cord& value) const;
};

Shared<ValueProvider> NewThreadCompatibleValueProvider(
Expand Down
5 changes: 3 additions & 2 deletions common/values/legacy_value_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
namespace cel::common_internal {

absl::StatusOr<absl::optional<Unique<StructValueBuilder>>>
LegacyValueProvider::NewStructValueBuilder(ValueFactory&, StructTypeView) {
LegacyValueProvider::NewStructValueBuilder(ValueFactory&,
StructTypeView) const {
return absl::nullopt;
}

absl::StatusOr<absl::optional<ValueView>> LegacyValueProvider::FindValue(
ValueFactory&, absl::string_view, Value&) {
ValueFactory&, absl::string_view, Value&) const {
return absl::nullopt;
}

Expand Down
Loading