|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
|
namespace google {
|
|
|
namespace protobuf {
|
|
|
namespace compiler {
|
|
|
namespace objectivec {
|
|
|
|
|
|
|
|
|
struct Options {
|
|
|
Options();
|
|
|
string expected_prefixes_path;
|
|
|
string generate_for_named_framework;
|
|
|
string named_framework_to_proto_path_mappings_path;
|
|
|
};
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT EscapeTrigraphs(const string& to_escape);
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT StripProto(const string& filename);
|
|
|
|
|
|
|
|
|
void LIBPROTOC_EXPORT StringPieceTrimWhitespace(StringPiece* input);
|
|
|
|
|
|
|
|
|
|
|
|
bool LIBPROTOC_EXPORT IsRetainedName(const string& name);
|
|
|
|
|
|
|
|
|
|
|
|
bool LIBPROTOC_EXPORT IsInitName(const string& name);
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT FileClassPrefix(const FileDescriptor* file);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT FilePath(const FileDescriptor* file);
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT FilePathBasename(const FileDescriptor* file);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT FileClassName(const FileDescriptor* file);
|
|
|
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT ClassName(const Descriptor* descriptor);
|
|
|
string LIBPROTOC_EXPORT ClassName(const Descriptor* descriptor, string* out_suffix_added);
|
|
|
string LIBPROTOC_EXPORT EnumName(const EnumDescriptor* descriptor);
|
|
|
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT EnumValueName(const EnumValueDescriptor* descriptor);
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT EnumValueShortName(const EnumValueDescriptor* descriptor);
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT UnCamelCaseEnumShortName(const string& name);
|
|
|
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT ExtensionMethodName(const FieldDescriptor* descriptor);
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT FieldName(const FieldDescriptor* field);
|
|
|
string LIBPROTOC_EXPORT FieldNameCapitalized(const FieldDescriptor* field);
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT OneofEnumName(const OneofDescriptor* descriptor);
|
|
|
string LIBPROTOC_EXPORT OneofName(const OneofDescriptor* descriptor);
|
|
|
string LIBPROTOC_EXPORT OneofNameCapitalized(const OneofDescriptor* descriptor);
|
|
|
|
|
|
inline bool HasFieldPresence(const FileDescriptor* file) {
|
|
|
return file->syntax() != FileDescriptor::SYNTAX_PROTO3;
|
|
|
}
|
|
|
|
|
|
inline bool HasPreservingUnknownEnumSemantics(const FileDescriptor* file) {
|
|
|
return file->syntax() == FileDescriptor::SYNTAX_PROTO3;
|
|
|
}
|
|
|
|
|
|
inline bool IsMapEntryMessage(const Descriptor* descriptor) {
|
|
|
return descriptor->options().map_entry();
|
|
|
}
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT UnCamelCaseFieldName(const 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>
|
|
|
string GetOptionalDeprecatedAttribute(
|
|
|
const TDescriptor* descriptor,
|
|
|
const FileDescriptor* file = NULL,
|
|
|
bool preSpace = true, bool postNewline = false) {
|
|
|
bool isDeprecated = descriptor->options().deprecated();
|
|
|
|
|
|
|
|
|
|
|
|
if (!isDeprecated && file) {
|
|
|
isDeprecated = file->options().deprecated();
|
|
|
}
|
|
|
if (isDeprecated) {
|
|
|
string result = "DEPRECATED_ATTRIBUTE";
|
|
|
if (preSpace) {
|
|
|
result.insert(0, " ");
|
|
|
}
|
|
|
if (postNewline) {
|
|
|
result.append("\n");
|
|
|
}
|
|
|
return result;
|
|
|
} else {
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
string LIBPROTOC_EXPORT GetCapitalizedType(const FieldDescriptor* field);
|
|
|
|
|
|
ObjectiveCType LIBPROTOC_EXPORT GetObjectiveCType(FieldDescriptor::Type field_type);
|
|
|
|
|
|
inline ObjectiveCType GetObjectiveCType(const FieldDescriptor* field) {
|
|
|
return GetObjectiveCType(field->type());
|
|
|
}
|
|
|
|
|
|
bool LIBPROTOC_EXPORT IsPrimitiveType(const FieldDescriptor* field);
|
|
|
bool LIBPROTOC_EXPORT IsReferenceType(const FieldDescriptor* field);
|
|
|
|
|
|
string LIBPROTOC_EXPORT GPBGenericValueFieldName(const FieldDescriptor* field);
|
|
|
string LIBPROTOC_EXPORT DefaultValue(const FieldDescriptor* field);
|
|
|
bool LIBPROTOC_EXPORT HasNonZeroDefaultValue(const FieldDescriptor* field);
|
|
|
|
|
|
string LIBPROTOC_EXPORT BuildFlagsString(const FlagType type, const vector<string>& strings);
|
|
|
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT BuildCommentsString(const SourceLocation& location,
|
|
|
bool prefer_single_line);
|
|
|
|
|
|
|
|
|
|
|
|
extern LIBPROTOC_EXPORT const char* const ProtobufLibraryFrameworkName;
|
|
|
|
|
|
|
|
|
string LIBPROTOC_EXPORT ProtobufFrameworkImportSymbol(const string& framework_name);
|
|
|
|
|
|
|
|
|
bool LIBPROTOC_EXPORT IsProtobufLibraryBundledProtoFile(const FileDescriptor* file);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LIBPROTOC_EXPORT ValidateObjCClassPrefixes(const vector<const FileDescriptor*>& files,
|
|
|
const Options& generation_options,
|
|
|
string* out_error);
|
|
|
|
|
|
|
|
|
|
|
|
class LIBPROTOC_EXPORT TextFormatDecodeData {
|
|
|
public:
|
|
|
TextFormatDecodeData();
|
|
|
~TextFormatDecodeData();
|
|
|
|
|
|
void AddString(int32 key, const string& input_for_decode,
|
|
|
const string& desired_output);
|
|
|
size_t num_entries() const { return entries_.size(); }
|
|
|
string Data() const;
|
|
|
|
|
|
static string DecodeDataForString(const string& input_for_decode,
|
|
|
const string& desired_output);
|
|
|
|
|
|
private:
|
|
|
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TextFormatDecodeData);
|
|
|
|
|
|
typedef std::pair<int32, string> DataEntry;
|
|
|
vector<DataEntry> entries_;
|
|
|
};
|
|
|
|
|
|
|
|
|
class LIBPROTOC_EXPORT LineConsumer {
|
|
|
public:
|
|
|
LineConsumer();
|
|
|
virtual ~LineConsumer();
|
|
|
virtual bool ConsumeLine(const StringPiece& line, string* out_error) = 0;
|
|
|
};
|
|
|
|
|
|
bool LIBPROTOC_EXPORT ParseSimpleFile(
|
|
|
const string& path, LineConsumer* line_consumer, string* out_error);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LIBPROTOC_EXPORT ImportWriter {
|
|
|
public:
|
|
|
ImportWriter(const string& generate_for_named_framework,
|
|
|
const string& named_framework_to_proto_path_mappings_path);
|
|
|
~ImportWriter();
|
|
|
|
|
|
void AddFile(const FileDescriptor* file, const string& header_extension);
|
|
|
void Print(io::Printer *printer) const;
|
|
|
|
|
|
private:
|
|
|
class ProtoFrameworkCollector : public LineConsumer {
|
|
|
public:
|
|
|
ProtoFrameworkCollector(std::map<string, string>* inout_proto_file_to_framework_name)
|
|
|
: map_(inout_proto_file_to_framework_name) {}
|
|
|
|
|
|
virtual bool ConsumeLine(const StringPiece& line, string* out_error);
|
|
|
|
|
|
private:
|
|
|
std::map<string, string>* map_;
|
|
|
};
|
|
|
|
|
|
void ParseFrameworkMappings();
|
|
|
|
|
|
const string generate_for_named_framework_;
|
|
|
const string named_framework_to_proto_path_mappings_path_;
|
|
|
std::map<string, string> proto_file_to_framework_name_;
|
|
|
bool need_to_parse_mapping_file_;
|
|
|
|
|
|
vector<string> protobuf_framework_imports_;
|
|
|
vector<string> protobuf_non_framework_imports_;
|
|
|
vector<string> other_framework_imports_;
|
|
|
vector<string> other_imports_;
|
|
|
};
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endif
|
|
|
|