28 #include "google/protobuf/compiler/code_generator.h"
29 #include "google/protobuf/compiler/plugin.h"
30 #include "google/protobuf/descriptor.h"
31 #include "google/protobuf/descriptor.pb.h"
37 namespace protoc = ::google::protobuf::compiler;
38 namespace protobuf = ::google::protobuf;
53 output(
"UPB_INLINE const upb_MessageDef *$0_getmsgdef(upb_DefPool *s) {\n",
55 output(
" _upb_DefPool_LoadDefInit(s, &$0);\n", DefInitSymbol(
d->file()));
56 output(
" return upb_DefPool_FindMessageByName(s, \"$0\");\n",
61 for (
int i = 0;
i <
d->nested_type_count();
i++) {
62 GenerateMessageDefAccessor(
d->nested_type(
i),
output);
70 "#ifndef $0_UPBDEFS_H_\n"
71 "#define $0_UPBDEFS_H_\n\n"
72 "#include \"upb/def.h\"\n"
73 "#include \"upb/port_def.inc\"\n"
74 "#ifdef __cplusplus\n"
79 output(
"#include \"upb/def.h\"\n");
81 output(
"#include \"upb/port_def.inc\"\n");
84 output(
"extern _upb_DefPool_Init $0;\n", DefInitSymbol(
file));
87 for (
int i = 0;
i <
file->message_type_count();
i++) {
88 GenerateMessageDefAccessor(
file->message_type(
i),
output);
92 "#ifdef __cplusplus\n"
93 "} /* extern \"C\" */\n"
96 "#include \"upb/port_undef.inc\"\n"
98 "#endif /* $0_UPBDEFS_H_ */\n",
105 output(
"#include \"upb/def.h\"\n");
110 for (
int i = 0;
i <
file->dependency_count();
i++) {
111 output(
"extern _upb_DefPool_Init $0;\n",
112 DefInitSymbol(
file->dependency(
i)));
116 file->CopyTo(&file_proto);
118 file_proto.SerializeToString(&
file_data);
127 for (
size_t j = 0;
j < 25 &&
i <
file_data.size(); ++
i, ++
j) {
134 output(
"static _upb_DefPool_Init *deps[$0] = {\n",
135 file->dependency_count() + 1);
136 for (
int i = 0;
i <
file->dependency_count();
i++) {
137 output(
" &$0,\n", DefInitSymbol(
file->dependency(
i)));
143 output(
"_upb_DefPool_Init $0 = {\n", DefInitSymbol(
file));
156 uint64_t GetSupportedFeatures()
const override {
157 return FEATURE_PROTO3_OPTIONAL;
165 std::vector<std::pair<std::string, std::string>> params;
168 for (
const auto&
pair : params) {
169 *
error =
"Unknown parameter: " +
pair.first;
173 std::unique_ptr<protobuf::io::ZeroCopyOutputStream> h_output_stream(
175 Output h_def_output(h_output_stream.get());
176 WriteDefHeader(
file, h_def_output);
178 std::unique_ptr<protobuf::io::ZeroCopyOutputStream> c_output_stream(
180 Output c_def_output(c_output_stream.get());
181 WriteDefSource(
file, c_def_output);
189 int main(
int argc,
char** argv) {
190 std::unique_ptr<google::protobuf::compiler::CodeGenerator> generator(