| 37 | using ExtensionPb = cel::expr::SourceInfo::Extension; |
| 38 | |
| 39 | absl::Status SourceInfoToProto(const cel::SourceInfo& source_info, |
| 40 | cel::expr::SourceInfo* out) { |
| 41 | cel::expr::SourceInfo& result = *out; |
| 42 | result.set_syntax_version(source_info.syntax_version()); |
| 43 | result.set_location(source_info.location()); |
| 44 | |
| 45 | for (int32_t line_offset : source_info.line_offsets()) { |
| 46 | result.add_line_offsets(line_offset); |
| 47 | } |
| 48 | |
| 49 | for (auto pos_iter = source_info.positions().begin(); |
| 50 | pos_iter != source_info.positions().end(); ++pos_iter) { |
| 51 | (*result.mutable_positions())[pos_iter->first] = pos_iter->second; |
| 52 | } |
| 53 | |
| 54 | for (auto macro_iter = source_info.macro_calls().begin(); |
| 55 | macro_iter != source_info.macro_calls().end(); ++macro_iter) { |
| 56 | ExprPb& dest_macro = (*result.mutable_macro_calls())[macro_iter->first]; |
| 57 | CEL_RETURN_IF_ERROR(ExprToProto(macro_iter->second, &dest_macro)); |
| 58 | } |
| 59 | |
| 60 | for (const auto& extension : source_info.extensions()) { |
| 61 | auto* extension_pb = result.add_extensions(); |
| 62 | extension_pb->set_id(extension.id()); |
| 63 | auto* version_pb = extension_pb->mutable_version(); |
| 64 | version_pb->set_major(extension.version().major()); |
| 65 | version_pb->set_minor(extension.version().minor()); |
| 66 | |
| 67 | for (auto component : extension.affected_components()) { |
| 68 | switch (component) { |
| 69 | case cel::ExtensionSpec::Component::kParser: |
| 70 | extension_pb->add_affected_components(ExtensionPb::COMPONENT_PARSER); |
| 71 | break; |
| 72 | case cel::ExtensionSpec::Component::kTypeChecker: |
| 73 | extension_pb->add_affected_components( |
| 74 | ExtensionPb::COMPONENT_TYPE_CHECKER); |
| 75 | break; |
| 76 | case cel::ExtensionSpec::Component::kRuntime: |
| 77 | extension_pb->add_affected_components(ExtensionPb::COMPONENT_RUNTIME); |
| 78 | break; |
| 79 | default: |
| 80 | extension_pb->add_affected_components( |
| 81 | ExtensionPb::COMPONENT_UNSPECIFIED); |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return absl::OkStatus(); |
| 88 | } |
| 89 | |
| 90 | } // namespace cel::ast_internal |
no test coverage detected