|
39 | 39 | #include <cstdint> |
40 | 40 | #include <iterator> |
41 | 41 | #include <string> |
| 42 | +#include <tuple> |
42 | 43 |
|
43 | 44 | #include "google/protobuf/compiler/scc.h" |
44 | 45 | #include "google/protobuf/compiler/code_generator.h" |
@@ -862,23 +863,62 @@ class PROTOC_EXPORT Formatter { |
862 | 863 | return absl::StrCat(x); |
863 | 864 | } |
864 | 865 | static std::string ToString(absl::Hex x) { return absl::StrCat(x); } |
865 | | - static std::string ToString(const FieldDescriptor* d) { return Payload(d); } |
866 | | - static std::string ToString(const Descriptor* d) { return Payload(d); } |
867 | | - static std::string ToString(const EnumDescriptor* d) { return Payload(d); } |
| 866 | + static std::string ToString(const FieldDescriptor* d) { |
| 867 | + return Payload(d, GeneratedCodeInfo::Annotation::NONE); |
| 868 | + } |
| 869 | + static std::string ToString(const Descriptor* d) { |
| 870 | + return Payload(d, GeneratedCodeInfo::Annotation::NONE); |
| 871 | + } |
| 872 | + static std::string ToString(const EnumDescriptor* d) { |
| 873 | + return Payload(d, GeneratedCodeInfo::Annotation::NONE); |
| 874 | + } |
868 | 875 | static std::string ToString(const EnumValueDescriptor* d) { |
869 | | - return Payload(d); |
| 876 | + return Payload(d, GeneratedCodeInfo::Annotation::NONE); |
| 877 | + } |
| 878 | + static std::string ToString(const OneofDescriptor* d) { |
| 879 | + return Payload(d, GeneratedCodeInfo::Annotation::NONE); |
| 880 | + } |
| 881 | + |
| 882 | + static std::string ToString( |
| 883 | + std::tuple<const FieldDescriptor*, |
| 884 | + GeneratedCodeInfo::Annotation::Semantic> |
| 885 | + p) { |
| 886 | + return Payload(std::get<0>(p), std::get<1>(p)); |
| 887 | + } |
| 888 | + static std::string ToString( |
| 889 | + std::tuple<const Descriptor*, GeneratedCodeInfo::Annotation::Semantic> |
| 890 | + p) { |
| 891 | + return Payload(std::get<0>(p), std::get<1>(p)); |
| 892 | + } |
| 893 | + static std::string ToString( |
| 894 | + std::tuple<const EnumDescriptor*, GeneratedCodeInfo::Annotation::Semantic> |
| 895 | + p) { |
| 896 | + return Payload(std::get<0>(p), std::get<1>(p)); |
| 897 | + } |
| 898 | + static std::string ToString( |
| 899 | + std::tuple<const EnumValueDescriptor*, |
| 900 | + GeneratedCodeInfo::Annotation::Semantic> |
| 901 | + p) { |
| 902 | + return Payload(std::get<0>(p), std::get<1>(p)); |
| 903 | + } |
| 904 | + static std::string ToString( |
| 905 | + std::tuple<const OneofDescriptor*, |
| 906 | + GeneratedCodeInfo::Annotation::Semantic> |
| 907 | + p) { |
| 908 | + return Payload(std::get<0>(p), std::get<1>(p)); |
870 | 909 | } |
871 | | - static std::string ToString(const OneofDescriptor* d) { return Payload(d); } |
872 | 910 |
|
873 | 911 | template <typename Descriptor> |
874 | | - static std::string Payload(const Descriptor* descriptor) { |
| 912 | + static std::string Payload(const Descriptor* descriptor, |
| 913 | + GeneratedCodeInfo::Annotation::Semantic semantic) { |
875 | 914 | std::vector<int> path; |
876 | 915 | descriptor->GetLocationPath(&path); |
877 | 916 | GeneratedCodeInfo::Annotation annotation; |
878 | 917 | for (int index : path) { |
879 | 918 | annotation.add_path(index); |
880 | 919 | } |
881 | 920 | annotation.set_source_file(descriptor->file()->name()); |
| 921 | + annotation.set_semantic(semantic); |
882 | 922 | return annotation.SerializeAsString(); |
883 | 923 | } |
884 | 924 | }; |
|
0 commit comments