MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / ConvertProtoSourceInfoToNative

Function ConvertProtoSourceInfoToNative

common/ast_proto.cc:64–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64absl::StatusOr<SourceInfo> ConvertProtoSourceInfoToNative(
65 const cel::expr::SourceInfo& source_info) {
66 absl::flat_hash_map<int64_t, Expr> macro_calls;
67 for (const auto& pair : source_info.macro_calls()) {
68 auto native_expr = ExprValueFromProto(pair.second);
69 if (!native_expr.ok()) {
70 return native_expr.status();
71 }
72 macro_calls.emplace(pair.first, *(std::move(native_expr)));
73 }
74 std::vector<ExtensionSpec> extensions;
75 extensions.reserve(source_info.extensions_size());
76 for (const auto& extension : source_info.extensions()) {
77 std::vector<ExtensionSpec::Component> components;
78 components.reserve(extension.affected_components().size());
79 for (const auto& component : extension.affected_components()) {
80 switch (component) {
81 case ExtensionPb::COMPONENT_PARSER:
82 components.push_back(ExtensionSpec::Component::kParser);
83 break;
84 case ExtensionPb::COMPONENT_TYPE_CHECKER:
85 components.push_back(ExtensionSpec::Component::kTypeChecker);
86 break;
87 case ExtensionPb::COMPONENT_RUNTIME:
88 components.push_back(ExtensionSpec::Component::kRuntime);
89 break;
90 default:
91 components.push_back(ExtensionSpec::Component::kUnspecified);
92 break;
93 }
94 }
95 extensions.push_back(ExtensionSpec(
96 extension.id(),
97 std::make_unique<ExtensionSpec::Version>(extension.version().major(),
98 extension.version().minor()),
99 std::move(components)));
100 }
101 return SourceInfo(
102 source_info.syntax_version(), source_info.location(),
103 std::vector<int32_t>(source_info.line_offsets().begin(),
104 source_info.line_offsets().end()),
105 absl::flat_hash_map<int64_t, int32_t>(source_info.positions().begin(),
106 source_info.positions().end()),
107 std::move(macro_calls), std::move(extensions));
108}
109
110absl::StatusOr<TypeSpec> ConvertProtoTypeToNative(
111 const cel::expr::Type& type);

Callers 1

CreateAstFromParsedExprFunction · 0.85

Calls 13

ExprValueFromProtoFunction · 0.85
ExtensionSpecClass · 0.85
SourceInfoClass · 0.85
majorMethod · 0.80
versionMethod · 0.80
minorMethod · 0.80
locationMethod · 0.80
line_offsetsMethod · 0.80
okMethod · 0.45
sizeMethod · 0.45
idMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected