summaryrefslogtreecommitdiff
path: root/upbc
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2019-03-27 15:32:05 -0700
committerGitHub <noreply@github.com>2019-03-27 15:32:05 -0700
commitcf35baa1ad70f0dca734f93bcc2b54d8d059bcdd (patch)
tree3c9881fcceaba1dbb5f04fe01ddc5f2dc5c647d1 /upbc
parent928ef7f2c02f18d9945dd750884dffbdebef1b98 (diff)
Moved macros from upb.h to port_def.inc to avoid leaking them to users. (#160)
* Use port_def.inc to prevent macros from leaking to users. * Added helpful comments to port_def.inc/port_undef.inc.
Diffstat (limited to 'upbc')
-rw-r--r--upbc/generator.cc28
1 files changed, 25 insertions, 3 deletions
diff --git a/upbc/generator.cc b/upbc/generator.cc
index 3b581f4..2760069 100644
--- a/upbc/generator.cc
+++ b/upbc/generator.cc
@@ -352,12 +352,12 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output
const protobuf::OneofDescriptor* oneof = message->oneof_decl(i);
std::string fullname = ToCIdent(oneof->full_name());
output("typedef enum {\n");
- for (int i = 0; i < oneof->field_count(); i++) {
- const protobuf::FieldDescriptor* field = oneof->field(i);
+ for (int j = 0; j < oneof->field_count(); j++) {
+ const protobuf::FieldDescriptor* field = oneof->field(j);
output(" $0_$1 = $2,\n", fullname, field->name(), field->number());
}
output(
- " $0_NOT_SET = 0,\n"
+ " $0_NOT_SET = 0\n"
"} $0_oneofcases;\n",
fullname);
output(
@@ -689,8 +689,20 @@ void GenerateMessageDefAccessor(const protobuf::Descriptor* d, Output& output) {
void WriteDefHeader(const protobuf::FileDescriptor* file, Output& output) {
EmitFileWarning(file, output);
+ output(
+ "#ifndef $0_UPBDEFS_H_\n"
+ "#define $0_UPBDEFS_H_\n\n"
+ "#include \"upb/def.h\"\n"
+ "#include \"upb/port_def.inc\"\n"
+ "#ifdef __cplusplus\n"
+ "extern \"C\" {\n"
+ "#endif\n\n",
+ ToPreproc(file->name()));
+
output("#include \"upb/def.h\"\n");
output("\n");
+ output("#include \"upb/port_def.inc\"\n");
+ output("\n");
output("extern upb_def_init $0;\n", DefInitSymbol(file));
output("\n");
@@ -698,6 +710,16 @@ void WriteDefHeader(const protobuf::FileDescriptor* file, Output& output) {
for (int i = 0; i < file->message_type_count(); i++) {
GenerateMessageDefAccessor(file->message_type(i), output);
}
+
+ output(
+ "#ifdef __cplusplus\n"
+ "} /* extern \"C\" */\n"
+ "#endif\n"
+ "\n"
+ "#include \"upb/port_undef.inc\"\n"
+ "\n"
+ "#endif /* $0_UPBDEFS_H_ */\n",
+ ToPreproc(file->name()));
}
// Escape C++ trigraphs by escaping question marks to \?
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback