Commit 45d9ee46 authored by lahiker42's avatar lahiker42

Support for deprecation annotations (Andrey Nigmatulin).


git-svn-id: https://protobuf-c.googlecode.com/svn/trunk@241 00440858-1255-0410-a3e6-75ea37f81c3a
parent e9acaa58
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
- support for packed repeated fields (Dave Benson) - support for packed repeated fields (Dave Benson)
- bug in dsk_dispatch_close_fd(), which usually only - bug in dsk_dispatch_close_fd(), which usually only
showed up in later function calls. showed up in later function calls.
- support for deprecated fields -- enable a GCC warning
if a field has the "deprecated" option enabled. (Andrey Nigmatulin)
0.13: 0.13:
- Fix for when the number of connections gets too great in RPC. - Fix for when the number of connections gets too great in RPC.
......
...@@ -29,6 +29,12 @@ ...@@ -29,6 +29,12 @@
# define PROTOBUF_C_END_DECLS # define PROTOBUF_C_END_DECLS
#endif #endif
#if !defined(PROTOBUF_C_NO_DEPRECATED) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
#define PROTOBUF_C_DEPRECATED __attribute__((__deprecated__))
#else
#define PROTOBUF_C_DEPRECATED
#endif
/* Define int32_t, int64_t, uint32_t, uint64_t, uint8_t. /* Define int32_t, int64_t, uint32_t, uint64_t, uint8_t.
Usually, just include <inttypes.h> to do the work. Usually, just include <inttypes.h> to do the work.
......
...@@ -38,6 +38,7 @@ void SetBytesVariables(const FieldDescriptor* descriptor, ...@@ -38,6 +38,7 @@ void SetBytesVariables(const FieldDescriptor* descriptor,
(*variables)["name"] = FieldName(descriptor); (*variables)["name"] = FieldName(descriptor);
(*variables)["default"] = (*variables)["default"] =
"\"" + CEscape(descriptor->default_value_string()) + "\""; "\"" + CEscape(descriptor->default_value_string()) + "\"";
(*variables)["deprecated"] = FieldDeprecated(descriptor);
} }
// =================================================================== // ===================================================================
...@@ -57,15 +58,15 @@ void BytesFieldGenerator::GenerateStructMembers(io::Printer* printer) const ...@@ -57,15 +58,15 @@ void BytesFieldGenerator::GenerateStructMembers(io::Printer* printer) const
{ {
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case FieldDescriptor::LABEL_REQUIRED:
printer->Print(variables_, "ProtobufCBinaryData $name$;\n"); printer->Print(variables_, "ProtobufCBinaryData $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_OPTIONAL: case FieldDescriptor::LABEL_OPTIONAL:
printer->Print(variables_, "protobuf_c_boolean has_$name$;\n"); printer->Print(variables_, "protobuf_c_boolean has_$name$$deprecated$;\n");
printer->Print(variables_, "ProtobufCBinaryData $name$;\n"); printer->Print(variables_, "ProtobufCBinaryData $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_REPEATED: case FieldDescriptor::LABEL_REPEATED:
printer->Print(variables_, "size_t n_$name$;\n"); printer->Print(variables_, "size_t n_$name$$deprecated$;\n");
printer->Print(variables_, "ProtobufCBinaryData *$name$;\n"); printer->Print(variables_, "ProtobufCBinaryData *$name$$deprecated$;\n");
break; break;
} }
} }
......
...@@ -45,6 +45,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor, ...@@ -45,6 +45,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor,
+ "__" + ToUpper(default_value->name()); + "__" + ToUpper(default_value->name());
} else } else
(*variables)["default"] = "0"; (*variables)["default"] = "0";
(*variables)["deprecated"] = FieldDeprecated(descriptor);
} }
// =================================================================== // ===================================================================
...@@ -62,15 +63,15 @@ void EnumFieldGenerator::GenerateStructMembers(io::Printer* printer) const ...@@ -62,15 +63,15 @@ void EnumFieldGenerator::GenerateStructMembers(io::Printer* printer) const
{ {
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case FieldDescriptor::LABEL_REQUIRED:
printer->Print(variables_, "$type$ $name$;\n"); printer->Print(variables_, "$type$ $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_OPTIONAL: case FieldDescriptor::LABEL_OPTIONAL:
printer->Print(variables_, "protobuf_c_boolean has_$name$;\n"); printer->Print(variables_, "protobuf_c_boolean has_$name$$deprecated$;\n");
printer->Print(variables_, "$type$ $name$;\n"); printer->Print(variables_, "$type$ $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_REPEATED: case FieldDescriptor::LABEL_REPEATED:
printer->Print(variables_, "size_t n_$name$;\n"); printer->Print(variables_, "size_t n_$name$$deprecated$;\n");
printer->Print(variables_, "$type$ *$name$;\n"); printer->Print(variables_, "$type$ *$name$$deprecated$;\n");
break; break;
} }
} }
......
...@@ -181,6 +181,11 @@ void FileGenerator::GenerateSource(io::Printer* printer) { ...@@ -181,6 +181,11 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
printer->Print( printer->Print(
"/* Generated by the protocol buffer compiler. DO NOT EDIT! */\n" "/* Generated by the protocol buffer compiler. DO NOT EDIT! */\n"
"\n" "\n"
"/* Do not generate deprecated warnings for self */\n"
"#ifndef PROTOBUF_C_NO_DEPRECATED\n"
"#define PROTOBUF_C_NO_DEPRECATED\n"
"#endif\n"
"\n"
"#include \"$basename$.pb-c.h\"\n", "#include \"$basename$.pb-c.h\"\n",
"basename", StripProto(file_->name())); "basename", StripProto(file_->name()));
......
...@@ -238,6 +238,13 @@ string FieldName(const FieldDescriptor* field) { ...@@ -238,6 +238,13 @@ string FieldName(const FieldDescriptor* field) {
return result; return result;
} }
string FieldDeprecated(const FieldDescriptor* field) {
if (field->options().deprecated()) {
return " PROTOBUF_C_DEPRECATED";
}
return "";
}
string StripProto(const string& filename) { string StripProto(const string& filename) {
if (HasSuffixString(filename, ".protodevel")) { if (HasSuffixString(filename, ".protodevel")) {
return StripSuffixString(filename, ".protodevel"); return StripSuffixString(filename, ".protodevel");
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
namespace google { namespace google {
...@@ -62,6 +63,9 @@ char* FastHexToBuffer(int i, char* buffer); ...@@ -62,6 +63,9 @@ char* FastHexToBuffer(int i, char* buffer);
// anyway, so normally this just returns field->name(). // anyway, so normally this just returns field->name().
string FieldName(const FieldDescriptor* field); string FieldName(const FieldDescriptor* field);
// Get macro string for deprecated field
string FieldDeprecated(const FieldDescriptor* field);
// Returns the scope where the field was defined (for extensions, this is // Returns the scope where the field was defined (for extensions, this is
// different from the message type to which the field applies). // different from the message type to which the field applies).
inline const Descriptor* FieldScope(const FieldDescriptor* field) { inline const Descriptor* FieldScope(const FieldDescriptor* field) {
......
...@@ -46,14 +46,15 @@ void MessageFieldGenerator::GenerateStructMembers(io::Printer* printer) const ...@@ -46,14 +46,15 @@ void MessageFieldGenerator::GenerateStructMembers(io::Printer* printer) const
map<string, string> vars; map<string, string> vars;
vars["name"] = FieldName(descriptor_); vars["name"] = FieldName(descriptor_);
vars["type"] = FullNameToC(descriptor_->message_type()->full_name()); vars["type"] = FullNameToC(descriptor_->message_type()->full_name());
vars["deprecated"] = FieldDeprecated(descriptor_);
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case FieldDescriptor::LABEL_REQUIRED:
case FieldDescriptor::LABEL_OPTIONAL: case FieldDescriptor::LABEL_OPTIONAL:
printer->Print(vars, "$type$ *$name$;\n"); printer->Print(vars, "$type$ *$name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_REPEATED: case FieldDescriptor::LABEL_REPEATED:
printer->Print(vars, "size_t n_$name$;\n"); printer->Print(vars, "size_t n_$name$$deprecated$;\n");
printer->Print(vars, "$type$ **$name$;\n"); printer->Print(vars, "$type$ **$name$$deprecated$;\n");
break; break;
} }
} }
......
...@@ -66,18 +66,19 @@ void PrimitiveFieldGenerator::GenerateStructMembers(io::Printer* printer) const ...@@ -66,18 +66,19 @@ void PrimitiveFieldGenerator::GenerateStructMembers(io::Printer* printer) const
} }
vars["c_type"] = c_type; vars["c_type"] = c_type;
vars["name"] = FieldName(descriptor_); vars["name"] = FieldName(descriptor_);
vars["deprecated"] = FieldDeprecated(descriptor_);
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case FieldDescriptor::LABEL_REQUIRED:
printer->Print(vars, "$c_type$ $name$;\n"); printer->Print(vars, "$c_type$ $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_OPTIONAL: case FieldDescriptor::LABEL_OPTIONAL:
printer->Print(vars, "protobuf_c_boolean has_$name$;\n"); printer->Print(vars, "protobuf_c_boolean has_$name$$deprecated$;\n");
printer->Print(vars, "$c_type$ $name$;\n"); printer->Print(vars, "$c_type$ $name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_REPEATED: case FieldDescriptor::LABEL_REPEATED:
printer->Print(vars, "size_t n_$name$;\n"); printer->Print(vars, "size_t n_$name$$deprecated$;\n");
printer->Print(vars, "$c_type$ *$name$;\n"); printer->Print(vars, "$c_type$ *$name$$deprecated$;\n");
break; break;
} }
} }
......
...@@ -38,6 +38,7 @@ void SetStringVariables(const FieldDescriptor* descriptor, ...@@ -38,6 +38,7 @@ void SetStringVariables(const FieldDescriptor* descriptor,
(*variables)["name"] = FieldName(descriptor); (*variables)["name"] = FieldName(descriptor);
(*variables)["default"] = FullNameToLower(descriptor->full_name()) (*variables)["default"] = FullNameToLower(descriptor->full_name())
+ "__default_value"; + "__default_value";
(*variables)["deprecated"] = FieldDeprecated(descriptor);
} }
// =================================================================== // ===================================================================
...@@ -55,11 +56,11 @@ void StringFieldGenerator::GenerateStructMembers(io::Printer* printer) const ...@@ -55,11 +56,11 @@ void StringFieldGenerator::GenerateStructMembers(io::Printer* printer) const
switch (descriptor_->label()) { switch (descriptor_->label()) {
case FieldDescriptor::LABEL_REQUIRED: case FieldDescriptor::LABEL_REQUIRED:
case FieldDescriptor::LABEL_OPTIONAL: case FieldDescriptor::LABEL_OPTIONAL:
printer->Print(variables_, "char *$name$;\n"); printer->Print(variables_, "char *$name$$deprecated$;\n");
break; break;
case FieldDescriptor::LABEL_REPEATED: case FieldDescriptor::LABEL_REPEATED:
printer->Print(variables_, "size_t n_$name$;\n"); printer->Print(variables_, "size_t n_$name$$deprecated$;\n");
printer->Print(variables_, "char **$name$;\n"); printer->Print(variables_, "char **$name$$deprecated$;\n");
break; break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment