diff --color -Naur protobuf-c-1.5.2.orig/protoc-gen-c/c_bytes_field.cc protobuf-c-1.5.2/protoc-gen-c/c_bytes_field.cc
|
old
|
new
|
|
| 94 | 94 | |
| 95 | 95 | void BytesFieldGenerator::GenerateStructMembers(google::protobuf::io::Printer* printer) const |
| 96 | 96 | { |
| 97 | | switch (descriptor_->label()) { |
| 98 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: |
| | 97 | if (descriptor_->is_required()) |
| 99 | 98 | printer->Print(variables_, "ProtobufCBinaryData $name$$deprecated$;\n"); |
| 100 | | break; |
| 101 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: |
| | 99 | else if (!descriptor_->is_repeated()) { |
| 102 | 100 | if (descriptor_->containing_oneof() == NULL && FieldSyntax(descriptor_) == 2) |
| 103 | 101 | printer->Print(variables_, "protobuf_c_boolean has_$name$$deprecated$;\n"); |
| 104 | 102 | printer->Print(variables_, "ProtobufCBinaryData $name$$deprecated$;\n"); |
| 105 | | break; |
| 106 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: |
| | 103 | } else { |
| 107 | 104 | printer->Print(variables_, "size_t n_$name$$deprecated$;\n"); |
| 108 | 105 | printer->Print(variables_, "ProtobufCBinaryData *$name$$deprecated$;\n"); |
| 109 | | break; |
| 110 | 106 | } |
| 111 | 107 | } |
| 112 | 108 | void BytesFieldGenerator::GenerateDefaultValueDeclarations(google::protobuf::io::Printer* printer) const |
| … |
… |
|
| 135 | 131 | } |
| 136 | 132 | void BytesFieldGenerator::GenerateStaticInit(google::protobuf::io::Printer* printer) const |
| 137 | 133 | { |
| 138 | | switch (descriptor_->label()) { |
| 139 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: |
| | 134 | if (descriptor_->is_required()) |
| 140 | 135 | printer->Print(variables_, "$default_value$"); |
| 141 | | break; |
| 142 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: |
| | 136 | else if (!descriptor_->is_repeated()) { |
| 143 | 137 | if (FieldSyntax(descriptor_) == 2) |
| 144 | 138 | printer->Print(variables_, "0, "); |
| 145 | 139 | printer->Print(variables_, "$default_value$"); |
| 146 | | break; |
| 147 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: |
| | 140 | } else |
| 148 | 141 | // no support for default? |
| 149 | 142 | printer->Print("0,NULL"); |
| 150 | | break; |
| 151 | | } |
| 152 | 143 | } |
| 153 | 144 | void BytesFieldGenerator::GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const |
| 154 | 145 | { |
diff --color -Naur protobuf-c-1.5.2.orig/protoc-gen-c/c_enum_field.cc protobuf-c-1.5.2/protoc-gen-c/c_enum_field.cc
|
old
|
new
|
|
| 95 | 95 | |
| 96 | 96 | void EnumFieldGenerator::GenerateStructMembers(google::protobuf::io::Printer* printer) const |
| 97 | 97 | { |
| 98 | | switch (descriptor_->label()) { |
| 99 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: |
| | 98 | if (descriptor_->is_required()) |
| 100 | 99 | printer->Print(variables_, "$type$ $name$$deprecated$;\n"); |
| 101 | | break; |
| 102 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: |
| | 100 | else if (!descriptor_->is_repeated()) { |
| 103 | 101 | if (descriptor_->containing_oneof() == NULL && FieldSyntax(descriptor_) == 2) |
| 104 | 102 | printer->Print(variables_, "protobuf_c_boolean has_$name$$deprecated$;\n"); |
| 105 | 103 | printer->Print(variables_, "$type$ $name$$deprecated$;\n"); |
| 106 | | break; |
| 107 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: |
| | 104 | } else { |
| 108 | 105 | printer->Print(variables_, "size_t n_$name$$deprecated$;\n"); |
| 109 | 106 | printer->Print(variables_, "$type$ *$name$$deprecated$;\n"); |
| 110 | | break; |
| 111 | 107 | } |
| 112 | 108 | } |
| 113 | 109 | |
| … |
… |
|
| 117 | 113 | } |
| 118 | 114 | void EnumFieldGenerator::GenerateStaticInit(google::protobuf::io::Printer* printer) const |
| 119 | 115 | { |
| 120 | | switch (descriptor_->label()) { |
| 121 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: |
| | 116 | if (descriptor_->is_required()) |
| 122 | 117 | printer->Print(variables_, "$default$"); |
| 123 | | break; |
| 124 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: |
| | 118 | else if (!descriptor_->is_repeated()) { |
| 125 | 119 | if (FieldSyntax(descriptor_) == 2) |
| 126 | 120 | printer->Print(variables_, "0, "); |
| 127 | 121 | printer->Print(variables_, "$default$"); |
| 128 | | break; |
| 129 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: |
| | 122 | } else |
| 130 | 123 | // no support for default? |
| 131 | 124 | printer->Print("0,NULL"); |
| 132 | | break; |
| 133 | | } |
| 134 | 125 | } |
| 135 | 126 | |
| 136 | 127 | void EnumFieldGenerator::GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const |
diff --color -Naur protobuf-c-1.5.2.orig/protoc-gen-c/c_field.cc protobuf-c-1.5.2/protoc-gen-c/c_field.cc
|
old
|
new
|
|
| 125 | 125 | variables["oneofname"] = CamelToLower(oneof->name()); |
| 126 | 126 | |
| 127 | 127 | if (FieldSyntax(descriptor_) == 3 && |
| 128 | | descriptor_->label() == google::protobuf::FieldDescriptor::LABEL_OPTIONAL) { |
| | 128 | !descriptor_->is_required() && !descriptor_->is_repeated()) { |
| 129 | 129 | variables["LABEL"] = "NONE"; |
| 130 | 130 | optional_uses_has = false; |
| 131 | 131 | } else { |
| 132 | | variables["LABEL"] = CamelToUpper(GetLabelName(descriptor_->label())); |
| | 132 | variables["LABEL"] = CamelToUpper(GetLabelName(*descriptor_)); |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if (descriptor_->has_default_value()) { |
| … |
… |
|
| 145 | 145 | |
| 146 | 146 | variables["flags"] = "0"; |
| 147 | 147 | |
| 148 | | if (descriptor_->label() == google::protobuf::FieldDescriptor::LABEL_REPEATED |
| | 148 | if (descriptor_->is_repeated() |
| 149 | 149 | && is_packable_type (descriptor_->type()) |
| 150 | 150 | && descriptor_->options().packed()) { |
| 151 | 151 | variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_PACKED"; |
| 152 | | } else if (descriptor_->label() == google::protobuf::FieldDescriptor::LABEL_REPEATED |
| | 152 | } else if (descriptor_->is_repeated() |
| 153 | 153 | && is_packable_type (descriptor_->type()) |
| 154 | 154 | && FieldSyntax(descriptor_) == 3 |
| 155 | 155 | && !descriptor_->options().has_packed()) { |
| … |
… |
|
| 179 | 179 | " $value$,\n" |
| 180 | 180 | " PROTOBUF_C_LABEL_$LABEL$,\n" |
| 181 | 181 | " PROTOBUF_C_TYPE_$TYPE$,\n"); |
| 182 | | switch (descriptor_->label()) { |
| 183 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: |
| | 182 | if (descriptor_->is_required()) |
| 184 | 183 | printer->Print(variables, " 0, /* quantifier_offset */\n"); |
| 185 | | break; |
| 186 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: |
| | 184 | else if (!descriptor_->is_repeated()) { |
| 187 | 185 | if (oneof != NULL) { |
| 188 | 186 | printer->Print(variables, " offsetof($classname$, $oneofname$_case),\n"); |
| 189 | 187 | } else if (optional_uses_has) { |
| … |
… |
|
| 191 | 189 | } else { |
| 192 | 190 | printer->Print(variables, " 0, /* quantifier_offset */\n"); |
| 193 | 191 | } |
| 194 | | break; |
| 195 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: |
| | 192 | } else |
| 196 | 193 | printer->Print(variables, " offsetof($classname$, n_$name$),\n"); |
| 197 | | break; |
| 198 | | } |
| 199 | 194 | printer->Print(variables, " offsetof($classname$, $name$),\n"); |
| 200 | 195 | printer->Print(variables, " $descriptor_addr$,\n"); |
| 201 | 196 | printer->Print(variables, " $default_value$,\n"); |
diff --color -Naur protobuf-c-1.5.2.orig/protoc-gen-c/c_helpers.cc protobuf-c-1.5.2/protoc-gen-c/c_helpers.cc
|
old
|
new
|
|
| 329 | 329 | return result; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | | std::string GetLabelName(google::protobuf::FieldDescriptor::Label label) { |
| 333 | | switch (label) { |
| 334 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: return "optional"; |
| 335 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: return "required"; |
| 336 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: return "repeated"; |
| 337 | | } |
| 338 | | return "bad-label"; |
| | 332 | std::string GetLabelName(const google::protobuf::FieldDescriptor &desc) { |
| | 333 | if (desc.is_required()) return "required"; |
| | 334 | if (desc.is_repeated()) return "repeated"; |
| | 335 | return "optional"; |
| 339 | 336 | } |
| 340 | 337 | |
| 341 | 338 | unsigned |
diff --color -Naur protobuf-c-1.5.2.orig/protoc-gen-c/c_helpers.h protobuf-c-1.5.2/protoc-gen-c/c_helpers.h
|
old
|
new
|
|
| 151 | 151 | std::string FilenameIdentifier(compat::StringView filename); |
| 152 | 152 | |
| 153 | 153 | // return 'required', 'optional', or 'repeated' |
| 154 | | std::string GetLabelName(google::protobuf::FieldDescriptor::Label label); |
| | 154 | std::string GetLabelName(const google::protobuf::FieldDescriptor &desc); |
| 155 | 155 | |
| 156 | 156 | // write IntRanges entries for a bunch of sorted values. |
| 157 | 157 | // returns the number of ranges there are to bsearch. |
diff --color -Naur protobuf-c-1.5.2.orig/protoc-gen-c/c_message_field.cc protobuf-c-1.5.2/protoc-gen-c/c_message_field.cc
|
old
|
new
|
|
| 83 | 83 | vars["name"] = FieldName(descriptor_); |
| 84 | 84 | vars["type"] = FullNameToC(descriptor_->message_type()->full_name(), descriptor_->message_type()->file()); |
| 85 | 85 | vars["deprecated"] = FieldDeprecated(descriptor_); |
| 86 | | switch (descriptor_->label()) { |
| 87 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: |
| 88 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: |
| | 86 | if (!descriptor_->is_repeated()) |
| 89 | 87 | printer->Print(vars, "$type$ *$name$$deprecated$;\n"); |
| 90 | | break; |
| 91 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: |
| | 88 | else { |
| 92 | 89 | printer->Print(vars, "size_t n_$name$$deprecated$;\n"); |
| 93 | 90 | printer->Print(vars, "$type$ **$name$$deprecated$;\n"); |
| 94 | | break; |
| 95 | 91 | } |
| 96 | 92 | } |
| 97 | 93 | std::string MessageFieldGenerator::GetDefaultValue(void) const |
| … |
… |
|
| 103 | 99 | } |
| 104 | 100 | void MessageFieldGenerator::GenerateStaticInit(google::protobuf::io::Printer* printer) const |
| 105 | 101 | { |
| 106 | | switch (descriptor_->label()) { |
| 107 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: |
| 108 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: |
| | 102 | if (!descriptor_->is_repeated()) |
| 109 | 103 | printer->Print("NULL"); |
| 110 | | break; |
| 111 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: |
| | 104 | else |
| 112 | 105 | printer->Print("0,NULL"); |
| 113 | | break; |
| 114 | | } |
| 115 | 106 | } |
| 116 | 107 | void MessageFieldGenerator::GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const |
| 117 | 108 | { |
diff --color -Naur protobuf-c-1.5.2.orig/protoc-gen-c/c_primitive_field.cc protobuf-c-1.5.2/protoc-gen-c/c_primitive_field.cc
|
old
|
new
|
|
| 109 | 109 | vars["name"] = FieldName(descriptor_); |
| 110 | 110 | vars["deprecated"] = FieldDeprecated(descriptor_); |
| 111 | 111 | |
| 112 | | switch (descriptor_->label()) { |
| 113 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: |
| | 112 | if (descriptor_->is_required()) |
| 114 | 113 | printer->Print(vars, "$c_type$ $name$$deprecated$;\n"); |
| 115 | | break; |
| 116 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: |
| | 114 | else if (!descriptor_->is_repeated()) { |
| 117 | 115 | if (descriptor_->containing_oneof() == NULL && FieldSyntax(descriptor_) == 2) |
| 118 | 116 | printer->Print(vars, "protobuf_c_boolean has_$name$$deprecated$;\n"); |
| 119 | 117 | printer->Print(vars, "$c_type$ $name$$deprecated$;\n"); |
| 120 | | break; |
| 121 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: |
| | 118 | } else { |
| 122 | 119 | printer->Print(vars, "size_t n_$name$$deprecated$;\n"); |
| 123 | 120 | printer->Print(vars, "$c_type$ *$name$$deprecated$;\n"); |
| 124 | | break; |
| 125 | 121 | } |
| 126 | 122 | } |
| 127 | 123 | std::string PrimitiveFieldGenerator::GetDefaultValue() const |
| … |
… |
|
| 156 | 152 | } else { |
| 157 | 153 | vars["default_value"] = "0"; |
| 158 | 154 | } |
| 159 | | switch (descriptor_->label()) { |
| 160 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: |
| | 155 | if (descriptor_->is_required()) |
| 161 | 156 | printer->Print(vars, "$default_value$"); |
| 162 | | break; |
| 163 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: |
| | 157 | else if (!descriptor_->is_repeated()) { |
| 164 | 158 | if (FieldSyntax(descriptor_) == 2) |
| 165 | 159 | printer->Print(vars, "0, "); |
| 166 | 160 | printer->Print(vars, "$default_value$"); |
| 167 | | break; |
| 168 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: |
| | 161 | } else |
| 169 | 162 | printer->Print("0,NULL"); |
| 170 | | break; |
| 171 | | } |
| 172 | 163 | } |
| 173 | 164 | |
| 174 | 165 | void PrimitiveFieldGenerator::GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const |
diff --color -Naur protobuf-c-1.5.2.orig/protoc-gen-c/c_string_field.cc protobuf-c-1.5.2/protoc-gen-c/c_string_field.cc
|
old
|
new
|
|
| 94 | 94 | { |
| 95 | 95 | const ProtobufCFileOptions opt = descriptor_->file()->options().GetExtension(pb_c_file); |
| 96 | 96 | |
| 97 | | switch (descriptor_->label()) { |
| 98 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: |
| 99 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: |
| | 97 | if (!descriptor_->is_repeated()) { |
| 100 | 98 | if (opt.const_strings()) |
| 101 | 99 | printer->Print(variables_, "const "); |
| 102 | 100 | printer->Print(variables_, "char *$name$$deprecated$;\n"); |
| 103 | | break; |
| 104 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: |
| | 101 | } else { |
| 105 | 102 | printer->Print(variables_, "size_t n_$name$$deprecated$;\n"); |
| 106 | 103 | if (opt.const_strings()) |
| 107 | 104 | printer->Print(variables_, "const "); |
| 108 | 105 | printer->Print(variables_, "char **$name$$deprecated$;\n"); |
| 109 | | break; |
| 110 | 106 | } |
| 111 | 107 | } |
| 112 | 108 | void StringFieldGenerator::GenerateDefaultValueDeclarations(google::protobuf::io::Printer* printer) const |
| … |
… |
|
| 138 | 134 | } else { |
| 139 | 135 | vars["default"] = "(char *)protobuf_c_empty_string"; |
| 140 | 136 | } |
| 141 | | switch (descriptor_->label()) { |
| 142 | | case google::protobuf::FieldDescriptor::LABEL_REQUIRED: |
| 143 | | case google::protobuf::FieldDescriptor::LABEL_OPTIONAL: |
| | 137 | if (!descriptor_->is_repeated()) |
| 144 | 138 | printer->Print(vars, "$default$"); |
| 145 | | break; |
| 146 | | case google::protobuf::FieldDescriptor::LABEL_REPEATED: |
| | 139 | else |
| 147 | 140 | printer->Print(vars, "0,NULL"); |
| 148 | | break; |
| 149 | | } |
| 150 | 141 | } |
| 151 | 142 | void StringFieldGenerator::GenerateDescriptorInitializer(google::protobuf::io::Printer* printer) const |
| 152 | 143 | { |