File indexing completed on 2025-01-31 10:11:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__
0011 #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__
0012
0013 #include <string>
0014 #include <vector>
0015
0016 #include "absl/strings/str_cat.h"
0017 #include "absl/strings/string_view.h"
0018 #include "google/protobuf/compiler/objectivec/options.h"
0019 #include "google/protobuf/descriptor.h"
0020 #include "google/protobuf/descriptor.pb.h"
0021 #include "google/protobuf/io/printer.h"
0022
0023 namespace google {
0024 namespace protobuf {
0025 namespace compiler {
0026 namespace objectivec {
0027
0028
0029 std::string EscapeTrigraphs(absl::string_view to_escape);
0030
0031
0032
0033 bool ExtensionIsCustomOption(const FieldDescriptor* extension_field);
0034
0035 enum ObjectiveCType {
0036 OBJECTIVECTYPE_INT32,
0037 OBJECTIVECTYPE_UINT32,
0038 OBJECTIVECTYPE_INT64,
0039 OBJECTIVECTYPE_UINT64,
0040 OBJECTIVECTYPE_FLOAT,
0041 OBJECTIVECTYPE_DOUBLE,
0042 OBJECTIVECTYPE_BOOLEAN,
0043 OBJECTIVECTYPE_STRING,
0044 OBJECTIVECTYPE_DATA,
0045 OBJECTIVECTYPE_ENUM,
0046 OBJECTIVECTYPE_MESSAGE
0047 };
0048
0049 enum FlagType {
0050 FLAGTYPE_DESCRIPTOR_INITIALIZATION,
0051 FLAGTYPE_EXTENSION,
0052 FLAGTYPE_FIELD
0053 };
0054
0055 std::string GetCapitalizedType(const FieldDescriptor* field);
0056
0057 ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type);
0058
0059 inline ObjectiveCType GetObjectiveCType(const FieldDescriptor* field) {
0060 return GetObjectiveCType(field->type());
0061 }
0062
0063 inline bool IsPrimitiveType(const FieldDescriptor* field) {
0064 ObjectiveCType type = GetObjectiveCType(field);
0065 switch (type) {
0066 case OBJECTIVECTYPE_INT32:
0067 case OBJECTIVECTYPE_UINT32:
0068 case OBJECTIVECTYPE_INT64:
0069 case OBJECTIVECTYPE_UINT64:
0070 case OBJECTIVECTYPE_FLOAT:
0071 case OBJECTIVECTYPE_DOUBLE:
0072 case OBJECTIVECTYPE_BOOLEAN:
0073 case OBJECTIVECTYPE_ENUM:
0074 return true;
0075 break;
0076 default:
0077 return false;
0078 }
0079 }
0080
0081 inline bool IsReferenceType(const FieldDescriptor* field) {
0082 return !IsPrimitiveType(field);
0083 }
0084
0085 std::string GPBGenericValueFieldName(const FieldDescriptor* field);
0086 std::string DefaultValue(const FieldDescriptor* field);
0087
0088 std::string BuildFlagsString(FlagType type,
0089 const std::vector<std::string>& strings);
0090
0091
0092
0093 std::string ObjCClass(absl::string_view class_name);
0094
0095
0096
0097 std::string ObjCClassDeclaration(absl::string_view class_name);
0098
0099
0100 enum CommentStringFlags : unsigned int {
0101 kCommentStringFlags_None = 0,
0102
0103 kCommentStringFlags_AddLeadingNewline = 1 << 1,
0104
0105 kCommentStringFlags_ForceMultiline = 1 << 2,
0106 };
0107
0108
0109
0110 void EmitCommentsString(io::Printer* printer, const GenerationOptions& opts,
0111 const SourceLocation& location,
0112 CommentStringFlags flags = kCommentStringFlags_None);
0113
0114
0115
0116 template <class TDescriptor>
0117 void EmitCommentsString(io::Printer* printer, const GenerationOptions& opts,
0118 const TDescriptor* descriptor,
0119 CommentStringFlags flags = kCommentStringFlags_None) {
0120 SourceLocation location;
0121 if (descriptor->GetSourceLocation(&location)) {
0122 EmitCommentsString(printer, opts, location, flags);
0123 }
0124 }
0125
0126 template <class TDescriptor>
0127 std::string GetOptionalDeprecatedAttribute(
0128 const TDescriptor* descriptor, const FileDescriptor* file = nullptr) {
0129 bool isDeprecated = descriptor->options().deprecated();
0130
0131
0132
0133 bool isFileLevelDeprecation = false;
0134 if (!isDeprecated && file) {
0135 isFileLevelDeprecation = file->options().deprecated();
0136 isDeprecated = isFileLevelDeprecation;
0137 }
0138 if (isDeprecated) {
0139 std::string message;
0140 const FileDescriptor* sourceFile = descriptor->file();
0141 if (isFileLevelDeprecation) {
0142 message = absl::StrCat(sourceFile->name(), " is deprecated.");
0143 } else {
0144 message = absl::StrCat(descriptor->full_name(), " is deprecated (see ",
0145 sourceFile->name(), ").");
0146 }
0147
0148 return absl::StrCat("GPB_DEPRECATED_MSG(\"", message, "\")");
0149 } else {
0150 return "";
0151 }
0152 }
0153
0154
0155
0156 bool HasWKTWithObjCCategory(const FileDescriptor* file);
0157 bool IsWKTWithObjCCategory(const Descriptor* descriptor);
0158
0159 }
0160 }
0161 }
0162 }
0163
0164 #endif