123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__
- #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__
- #include <string>
- #include <vector>
- #include <google/protobuf/descriptor.h>
- #include <google/protobuf/descriptor.pb.h>
- #include <google/protobuf/port_def.inc>
- namespace google {
- namespace protobuf {
- namespace compiler {
- namespace objectivec {
- bool PROTOC_EXPORT UseProtoPackageAsDefaultPrefix();
- void PROTOC_EXPORT SetUseProtoPackageAsDefaultPrefix(bool on_or_off);
- std::string PROTOC_EXPORT GetProtoPackagePrefixExceptionList();
- void PROTOC_EXPORT SetProtoPackagePrefixExceptionList(
- const std::string& file_path);
- struct Options {
- Options();
- std::string expected_prefixes_path;
- std::vector<std::string> expected_prefixes_suppressions;
- std::string generate_for_named_framework;
- std::string named_framework_to_proto_path_mappings_path;
- std::string runtime_import_prefix;
- };
- std::string PROTOC_EXPORT EscapeTrigraphs(const std::string& to_escape);
- void PROTOC_EXPORT TrimWhitespace(StringPiece* input);
- bool PROTOC_EXPORT IsRetainedName(const std::string& name);
- bool PROTOC_EXPORT IsInitName(const std::string& name);
- std::string PROTOC_EXPORT FileClassPrefix(const FileDescriptor* file);
- std::string PROTOC_EXPORT FilePath(const FileDescriptor* file);
- std::string PROTOC_EXPORT FilePathBasename(const FileDescriptor* file);
- std::string PROTOC_EXPORT FileClassName(const FileDescriptor* file);
- std::string PROTOC_EXPORT ClassName(const Descriptor* descriptor);
- std::string PROTOC_EXPORT ClassName(const Descriptor* descriptor,
- std::string* out_suffix_added);
- std::string PROTOC_EXPORT EnumName(const EnumDescriptor* descriptor);
- std::string PROTOC_EXPORT EnumValueName(const EnumValueDescriptor* descriptor);
- std::string PROTOC_EXPORT EnumValueShortName(const EnumValueDescriptor* descriptor);
- std::string PROTOC_EXPORT UnCamelCaseEnumShortName(const std::string& name);
- std::string PROTOC_EXPORT ExtensionMethodName(const FieldDescriptor* descriptor);
- std::string PROTOC_EXPORT FieldName(const FieldDescriptor* field);
- std::string PROTOC_EXPORT FieldNameCapitalized(const FieldDescriptor* field);
- std::string PROTOC_EXPORT OneofEnumName(const OneofDescriptor* descriptor);
- std::string PROTOC_EXPORT OneofName(const OneofDescriptor* descriptor);
- std::string PROTOC_EXPORT OneofNameCapitalized(const OneofDescriptor* descriptor);
- std::string PROTOC_EXPORT ObjCClass(const std::string& class_name);
- std::string PROTOC_EXPORT ObjCClassDeclaration(const std::string& class_name);
- inline bool HasPreservingUnknownEnumSemantics(const FileDescriptor* file) {
- return file->syntax() == FileDescriptor::SYNTAX_PROTO3;
- }
- inline bool IsMapEntryMessage(const Descriptor* descriptor) {
- return descriptor->options().map_entry();
- }
- std::string PROTOC_EXPORT UnCamelCaseFieldName(const std::string& name,
- const FieldDescriptor* field);
- enum ObjectiveCType {
- OBJECTIVECTYPE_INT32,
- OBJECTIVECTYPE_UINT32,
- OBJECTIVECTYPE_INT64,
- OBJECTIVECTYPE_UINT64,
- OBJECTIVECTYPE_FLOAT,
- OBJECTIVECTYPE_DOUBLE,
- OBJECTIVECTYPE_BOOLEAN,
- OBJECTIVECTYPE_STRING,
- OBJECTIVECTYPE_DATA,
- OBJECTIVECTYPE_ENUM,
- OBJECTIVECTYPE_MESSAGE
- };
- enum FlagType {
- FLAGTYPE_DESCRIPTOR_INITIALIZATION,
- FLAGTYPE_EXTENSION,
- FLAGTYPE_FIELD
- };
- template <class TDescriptor>
- std::string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor,
- const FileDescriptor* file = NULL,
- bool preSpace = true,
- bool postNewline = false) {
- bool isDeprecated = descriptor->options().deprecated();
-
-
-
- bool isFileLevelDeprecation = false;
- if (!isDeprecated && file) {
- isFileLevelDeprecation = file->options().deprecated();
- isDeprecated = isFileLevelDeprecation;
- }
- if (isDeprecated) {
- std::string message;
- const FileDescriptor* sourceFile = descriptor->file();
- if (isFileLevelDeprecation) {
- message = sourceFile->name() + " is deprecated.";
- } else {
- message = descriptor->full_name() + " is deprecated (see " +
- sourceFile->name() + ").";
- }
- std::string result = std::string("GPB_DEPRECATED_MSG(\"") + message + "\")";
- if (preSpace) {
- result.insert(0, " ");
- }
- if (postNewline) {
- result.append("\n");
- }
- return result;
- } else {
- return "";
- }
- }
- std::string PROTOC_EXPORT GetCapitalizedType(const FieldDescriptor* field);
- ObjectiveCType PROTOC_EXPORT
- GetObjectiveCType(FieldDescriptor::Type field_type);
- inline ObjectiveCType GetObjectiveCType(const FieldDescriptor* field) {
- return GetObjectiveCType(field->type());
- }
- bool PROTOC_EXPORT IsPrimitiveType(const FieldDescriptor* field);
- bool PROTOC_EXPORT IsReferenceType(const FieldDescriptor* field);
- std::string PROTOC_EXPORT
- GPBGenericValueFieldName(const FieldDescriptor* field);
- std::string PROTOC_EXPORT DefaultValue(const FieldDescriptor* field);
- bool PROTOC_EXPORT HasNonZeroDefaultValue(const FieldDescriptor* field);
- std::string PROTOC_EXPORT
- BuildFlagsString(const FlagType type, const std::vector<std::string>& strings);
- std::string PROTOC_EXPORT BuildCommentsString(const SourceLocation& location,
- bool prefer_single_line);
- extern PROTOC_EXPORT const char* const ProtobufLibraryFrameworkName;
- std::string PROTOC_EXPORT
- ProtobufFrameworkImportSymbol(const std::string& framework_name);
- bool PROTOC_EXPORT
- IsProtobufLibraryBundledProtoFile(const FileDescriptor* file);
- bool PROTOC_EXPORT ValidateObjCClassPrefixes(
- const std::vector<const FileDescriptor*>& files,
- const Options& generation_options, std::string* out_error);
- class PROTOC_EXPORT TextFormatDecodeData {
- public:
- TextFormatDecodeData();
- ~TextFormatDecodeData();
- TextFormatDecodeData(const TextFormatDecodeData&) = delete;
- TextFormatDecodeData& operator=(const TextFormatDecodeData&) = delete;
- void AddString(int32 key, const std::string& input_for_decode,
- const std::string& desired_output);
- size_t num_entries() const { return entries_.size(); }
- std::string Data() const;
- static std::string DecodeDataForString(const std::string& input_for_decode,
- const std::string& desired_output);
- private:
- typedef std::pair<int32, std::string> DataEntry;
- std::vector<DataEntry> entries_;
- };
- class PROTOC_EXPORT LineConsumer {
- public:
- LineConsumer();
- virtual ~LineConsumer();
- virtual bool ConsumeLine(const StringPiece& line, std::string* out_error) = 0;
- };
- bool PROTOC_EXPORT ParseSimpleFile(const std::string& path,
- LineConsumer* line_consumer,
- std::string* out_error);
- class PROTOC_EXPORT ImportWriter {
- public:
- ImportWriter(const std::string& generate_for_named_framework,
- const std::string& named_framework_to_proto_path_mappings_path,
- const std::string& runtime_import_prefix,
- bool include_wkt_imports);
- ~ImportWriter();
- void AddFile(const FileDescriptor* file, const std::string& header_extension);
- void Print(io::Printer* printer) const;
- static void PrintRuntimeImports(io::Printer* printer,
- const std::vector<std::string>& header_to_import,
- const std::string& runtime_import_prefix,
- bool default_cpp_symbol = false);
- private:
- class ProtoFrameworkCollector : public LineConsumer {
- public:
- ProtoFrameworkCollector(std::map<std::string, std::string>* inout_proto_file_to_framework_name)
- : map_(inout_proto_file_to_framework_name) {}
- virtual bool ConsumeLine(const StringPiece& line, std::string* out_error) override;
- private:
- std::map<std::string, std::string>* map_;
- };
- void ParseFrameworkMappings();
- const std::string generate_for_named_framework_;
- const std::string named_framework_to_proto_path_mappings_path_;
- const std::string runtime_import_prefix_;
- const bool include_wkt_imports_;
- std::map<std::string, std::string> proto_file_to_framework_name_;
- bool need_to_parse_mapping_file_;
- std::vector<std::string> protobuf_imports_;
- std::vector<std::string> other_framework_imports_;
- std::vector<std::string> other_imports_;
- };
- }
- }
- }
- }
- #include <google/protobuf/port_undef.inc>
- #endif
|