Rename `upbc` to `upb_generator`

This makes the file layout a bit more consistent with the `protos ->
protos_generator` pattern. I also replaced the `upbc` namespace with
`upb::generator`.

PiperOrigin-RevId: 569264372
pull/14227/head
Adam Cozzette 1 year ago committed by Copybara-Service
parent f5e6fb02cc
commit 12c7bb0750
  1. 8
      .github/workflows/test_upb.yml
  2. 2
      bazel/upb_c_proto_library.bzl
  3. 2
      bazel/upb_minitable_proto_library.bzl
  4. 2
      bazel/upb_proto_reflection_library.bzl
  5. 12
      protos_generator/BUILD
  6. 20
      protos_generator/gen_accessors.cc
  7. 12
      protos_generator/gen_messages.cc
  8. 48
      protos_generator/gen_repeated_fields.cc
  9. 4
      protos_generator/names.cc
  10. 2
      protos_generator/output.h
  11. 2
      protos_generator/protoc-gen-upb-protos.cc
  12. 2
      src/google/protobuf/compiler/BUILD.bazel
  13. 2
      upb/BUILD
  14. 3
      upb/reflection/stage0/google/protobuf/descriptor.upb.h
  15. 6
      upb_generator/BUILD
  16. 20
      upb_generator/bootstrap_compiler.bzl
  17. 36
      upb_generator/code_generator_request.c
  18. 10
      upb_generator/code_generator_request.h
  19. 2
      upb_generator/code_generator_request.proto
  20. 11
      upb_generator/common.cc
  21. 12
      upb_generator/common.h
  22. 10
      upb_generator/file_layout.cc
  23. 14
      upb_generator/file_layout.h
  24. 2
      upb_generator/get_used_fields.c
  25. 8
      upb_generator/get_used_fields.h
  26. 8
      upb_generator/keywords.cc
  27. 6
      upb_generator/keywords.h
  28. 8
      upb_generator/names.cc
  29. 6
      upb_generator/names.h
  30. 16
      upb_generator/plugin.h
  31. 29
      upb_generator/protoc-gen-upb.cc
  32. 32
      upb_generator/protoc-gen-upb_minitable.cc
  33. 19
      upb_generator/protoc-gen-upbdefs.cc
  34. 10
      upb_generator/protoc-gen-upbdev.cc
  35. 0
      upb_generator/stage0/google/protobuf/compiler/plugin.upb.c
  36. 3
      upb_generator/stage0/google/protobuf/compiler/plugin.upb.h
  37. 8
      upb_generator/subprocess.cc
  38. 12
      upb_generator/subprocess.h
  39. 4
      upb_generator/upb_generator_so.c
  40. 14
      upb_generator/upbdev.c
  41. 8
      upb_generator/upbdev.h

@ -39,7 +39,7 @@ jobs:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize@sha256:04cd765285bc52cbbf51d66c8c66d8603579cf0f19cc42df26b09d2c270541fb
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: upb-bazel
bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upbc/... ${{ matrix.config.flags }}
bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upb_generator/... ${{ matrix.config.flags }}
exclude-targets: ${{ matrix.config.exclude-targets }}
linux-gcc:
@ -58,7 +58,7 @@ jobs:
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:12.2-6.3.0-63dd26c0c7a808d92673a3e52e848189d4ab0f17"
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "upb-bazel-gcc"
bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 -c opt //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upbc/...
bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 -c opt //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upb_generator/...
windows:
strategy:
@ -75,7 +75,7 @@ jobs:
with:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "upb-bazel-windows"
bazel: test --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 //upb/... //upbc/... //python/... //protos/... //protos_generator/...
bazel: test --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 //upb/... //upb_generator/... //python/... //protos/... //protos_generator/...
exclude-targets: -//python:conformance_test -//upb:def_builder_test
macos:
@ -97,7 +97,7 @@ jobs:
with:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "upb-bazel-macos"
bazel: ${{ matrix.config.bazel-command }} --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 ${{ matrix.config.flags }} //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upbc/...
bazel: ${{ matrix.config.bazel-command }} --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 ${{ matrix.config.flags }} //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upb_generator/...
no-python:
strategy:

@ -32,7 +32,7 @@ upb_c_proto_library_aspect = aspect(
default = "//upb:upb_proto_library_copts__for_generated_code_only_do_not_use",
),
"_upb_toolchain": attr.label(
default = Label("//upbc:protoc-gen-upb_toolchain"),
default = Label("//upb_generator:protoc-gen-upb_toolchain"),
),
"_cc_toolchain": attr.label(
default = "@bazel_tools//tools/cpp:current_cc_toolchain",

@ -44,7 +44,7 @@ upb_minitable_proto_library_aspect = aspect(
default = "//upb:upb_proto_library_copts__for_generated_code_only_do_not_use",
),
"_upb_minitable_toolchain": attr.label(
default = Label("//upbc:protoc-gen-upb_minitable_toolchain"),
default = Label("//upb_generator:protoc-gen-upb_minitable_toolchain"),
),
"_cc_toolchain": attr.label(
default = "@bazel_tools//tools/cpp:current_cc_toolchain",

@ -29,7 +29,7 @@ _upb_proto_reflection_library_aspect = aspect(
default = "//upb:upb_proto_library_copts__for_generated_code_only_do_not_use",
),
"_upbdefs_toolchain": attr.label(
default = Label("//upbc:protoc-gen-upbdefs_toolchain"),
default = Label("//upb_generator:protoc-gen-upbdefs_toolchain"),
cfg = getattr(proto_common, "proto_lang_toolchain_cfg", "target"),
),
"_cc_toolchain": attr.label(

@ -30,7 +30,7 @@ cc_binary(
":output",
"//:protobuf",
"//src/google/protobuf/compiler:code_generator",
"//upbc:file_layout",
"//upb_generator:file_layout",
],
)
@ -58,10 +58,10 @@ cc_library(
"//:protobuf",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/strings",
"//upbc:common",
"//upbc:file_layout",
"//upbc:keywords",
"//upbc:names",
"//upb_generator:common",
"//upb_generator:file_layout",
"//upb_generator:keywords",
"//upb_generator:names",
],
)
@ -96,6 +96,6 @@ cc_library(
visibility = ["//visibility:private"],
deps = [
":output",
"//upbc:keywords",
"//upb_generator:keywords",
],
)

@ -41,9 +41,9 @@
#include "protos_generator/gen_utils.h"
#include "protos_generator/names.h"
#include "protos_generator/output.h"
#include "upbc/common.h"
#include "upbc/keywords.h"
#include "upbc/names.h"
#include "upb_generator/common.h"
#include "upb_generator/keywords.h"
#include "upb_generator/names.h"
namespace protos_generator {
@ -98,12 +98,12 @@ void WriteFieldAccessorsInHeader(const protobuf::Descriptor* desc,
OutputIndenter i(output);
auto field_names = CreateFieldNameMap(desc);
auto upbc_field_names = upbc::CreateFieldNameMap(desc);
auto upbc_field_names = upb::generator::CreateFieldNameMap(desc);
for (const auto* field : FieldNumberOrder(desc)) {
std::string resolved_field_name = ResolveFieldName(field, field_names);
std::string resolved_upbc_name =
upbc::ResolveFieldName(field, upbc_field_names);
upb::generator::ResolveFieldName(field, upbc_field_names);
WriteFieldAccessorHazzer(desc, field, resolved_field_name,
resolved_upbc_name, output);
WriteFieldAccessorClear(desc, field, resolved_field_name,
@ -214,14 +214,14 @@ void WriteAccessorsInSource(const protobuf::Descriptor* desc, Output& output) {
output("namespace internal {\n");
const char arena_expression[] = "arena_";
auto field_names = CreateFieldNameMap(desc);
auto upbc_field_names = upbc::CreateFieldNameMap(desc);
auto upbc_field_names = upb::generator::CreateFieldNameMap(desc);
// Generate const methods.
OutputIndenter i(output);
for (const auto* field : FieldNumberOrder(desc)) {
std::string resolved_field_name = ResolveFieldName(field, field_names);
std::string resolved_upbc_name =
upbc::ResolveFieldName(field, upbc_field_names);
upb::generator::ResolveFieldName(field, upbc_field_names);
if (field->is_map()) {
WriteMapAccessorDefinitions(desc, field, resolved_field_name, class_name,
output);
@ -327,7 +327,7 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
MessagePtrConstType(val, /* is_const */ true), MessageName(message),
MessageName(val->message_type()), optional_conversion_code,
converted_key_name, upbc_name,
::upbc::MessageInit(val->message_type()->full_name()));
::upb::generator::MessageInit(val->message_type()->full_name()));
output(
R"cc(
bool $0::set_$1($2 key, $3 value) {
@ -341,7 +341,7 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
MessagePtrConstType(val, /* is_const */ false), MessageName(message),
MessageName(val->message_type()), optional_conversion_code,
converted_key_name, upbc_name,
::upbc::MessageInit(val->message_type()->full_name()));
::upb::generator::MessageInit(val->message_type()->full_name()));
output(
R"cc(
absl::StatusOr<$3> $0::get_$1($2 key) {
@ -586,7 +586,7 @@ std::string ResolveFieldName(const protobuf::FieldDescriptor* field,
}
}
}
return upbc::ResolveKeywordConflict(std::string(field_name));
return upb::generator::ResolveKeywordConflict(std::string(field_name));
}
} // namespace protos_generator

@ -42,8 +42,8 @@
#include "protos_generator/gen_utils.h"
#include "protos_generator/names.h"
#include "protos_generator/output.h"
#include "upbc/common.h"
#include "upbc/file_layout.h"
#include "upb_generator/common.h"
#include "upb_generator/file_layout.h"
namespace protos_generator {
@ -176,7 +176,8 @@ void WriteModelPublicDeclaration(
return *this;
}
)cc",
ClassName(descriptor), ::upbc::MessageInit(descriptor->full_name()),
ClassName(descriptor),
::upb::generator::MessageInit(descriptor->full_name()),
MessageName(descriptor), QualifiedClassName(descriptor));
WriteUsingAccessorsInHeader(descriptor, MessageClassType::kMessage, output);
@ -387,7 +388,7 @@ void WriteMessageImplementation(
}
)cc",
ClassName(descriptor), MessageName(descriptor),
::upbc::MessageInit(descriptor->full_name()),
::upb::generator::MessageInit(descriptor->full_name()),
QualifiedClassName(descriptor));
output("\n");
// Minitable
@ -395,7 +396,8 @@ void WriteMessageImplementation(
R"cc(
const upb_MiniTable* $0::minitable() { return &$1; }
)cc",
ClassName(descriptor), ::upbc::MessageInit(descriptor->full_name()));
ClassName(descriptor),
::upb::generator::MessageInit(descriptor->full_name()));
output("\n");
}

@ -41,9 +41,9 @@
#include "protos_generator/gen_utils.h"
#include "protos_generator/names.h"
#include "protos_generator/output.h"
#include "upbc/common.h"
#include "upbc/file_layout.h"
#include "upbc/names.h"
#include "upb_generator/common.h"
#include "upb_generator/file_layout.h"
#include "upb_generator/names.h"
namespace protos_generator {
namespace protobuf = ::google::protobuf;
@ -204,13 +204,13 @@ void WriteRepeatedMessageAccessor(const protobuf::Descriptor* message,
return ::protos::RepeatedField<$1>::Proxy(arr, arena_);
}
)cc",
class_name, // $0
MessageBaseType(field, /* maybe_const */ false), // $1
resolved_field_name, // $2
MessageName(message), // $3
upbc_name, // $4
upbc::kRepeatedFieldArrayGetterPostfix, // $5
upbc::kRepeatedFieldMutableArrayGetterPostfix // $6
class_name, // $0
MessageBaseType(field, /* maybe_const */ false), // $1
resolved_field_name, // $2
MessageName(message), // $3
upbc_name, // $4
upb::generator::kRepeatedFieldArrayGetterPostfix, // $5
upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6
);
}
@ -270,13 +270,13 @@ void WriteRepeatedStringAccessor(const protobuf::Descriptor* message,
return ::protos::RepeatedField<$1>::Proxy(arr, arena_);
}
)cc",
class_name, // $0
CppConstType(field), // $1
resolved_field_name, // $2
MessageName(message), // $3
upbc_name, // $4
upbc::kRepeatedFieldArrayGetterPostfix, // $5
upbc::kRepeatedFieldMutableArrayGetterPostfix // $6
class_name, // $0
CppConstType(field), // $1
resolved_field_name, // $2
MessageName(message), // $3
upbc_name, // $4
upb::generator::kRepeatedFieldArrayGetterPostfix, // $5
upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6
);
}
@ -334,13 +334,13 @@ void WriteRepeatedScalarAccessor(const protobuf::Descriptor* message,
return ::protos::RepeatedField<$1>::Proxy(arr, arena_);
}
)cc",
class_name, // $0
CppConstType(field), // $1
resolved_field_name, // $2
MessageName(message), // $3
upbc_name, // $4
upbc::kRepeatedFieldArrayGetterPostfix, // $5
upbc::kRepeatedFieldMutableArrayGetterPostfix // $6
class_name, // $0
CppConstType(field), // $1
resolved_field_name, // $2
MessageName(message), // $3
upbc_name, // $4
upb::generator::kRepeatedFieldArrayGetterPostfix, // $5
upb::generator::kRepeatedFieldMutableArrayGetterPostfix // $6
);
}

@ -32,7 +32,7 @@
#include <string>
#include "upbc/keywords.h"
#include "upb_generator/keywords.h"
namespace protos_generator {
@ -113,7 +113,7 @@ std::string ClassName(const protobuf::Descriptor* descriptor) {
}
if (parent) res += ClassName(parent) + "_";
absl::StrAppend(&res, descriptor->name());
return ::upbc::ResolveKeywordConflict(res);
return ::upb::generator::ResolveKeywordConflict(res);
}
std::string QualifiedClassName(const protobuf::Descriptor* descriptor) {

@ -129,7 +129,7 @@ class Output {
void* void_buffer;
int size;
if (!stream_->Next(&void_buffer, &size)) {
fprintf(stderr, "upbc: Failed to write to to output\n");
fprintf(stderr, "upb_generator: Failed to write to to output\n");
abort();
}
output_buffer_ = static_cast<char*>(void_buffer);

@ -40,7 +40,7 @@
#include "protos_generator/gen_utils.h"
#include "protos_generator/names.h"
#include "protos_generator/output.h"
#include "upbc/file_layout.h"
#include "upb_generator/file_layout.h"
namespace protos_generator {
namespace {

@ -212,7 +212,7 @@ filegroup(
name = "plugin_proto_src",
srcs = ["plugin.proto"],
visibility = [
"//upbc:__subpackages__",
"//upb_generator:__subpackages__",
# For compatibility with workspaces that still use the old upb repo
"@upb//:__subpackages__",
],

@ -12,7 +12,7 @@ load("//bazel:upb_minitable_proto_library.bzl", "upb_minitable_proto_library")
load("//bazel:upb_proto_library.bzl", "upb_proto_reflection_library")
load("//bazel:upb_proto_library_internal/copts.bzl", "upb_proto_library_copts")
load(
"//upbc:bootstrap_compiler.bzl",
"//upb_generator:bootstrap_compiler.bzl",
"bootstrap_cc_library",
"bootstrap_upb_proto_library",
)

@ -1,5 +1,4 @@
/* This file was generated by upbc (the upb compiler) from the input
* file:
/* This file was generated by upb_generator from the input file:
*
* google/protobuf/descriptor.proto
*

@ -20,7 +20,7 @@ load(
"upb_proto_reflection_library",
)
load(
"//upbc:bootstrap_compiler.bzl",
"//upb_generator:bootstrap_compiler.bzl",
"bootstrap_cc_binary",
"bootstrap_cc_library",
"bootstrap_upb_proto_library",
@ -191,8 +191,8 @@ bootstrap_cc_library(
)
cc_binary(
name = "libupbc.so",
srcs = ["upbc_so.c"],
name = "libupb_generator.so",
srcs = ["upb_generator_so.c"],
copts = UPB_DEFAULT_COPTS + ["-DUPB_BUILD_API"],
linkshared = 1,
linkstatic = 1,

@ -1,17 +1,17 @@
"""Macros that implement bootstrapping for the upb code generator."""
load(
"//bazel:upb_proto_library.bzl",
"upb_proto_library",
)
load(
"//upb/cmake:build_defs.bzl",
"staleness_test",
)
load(
"//bazel:upb_proto_library.bzl",
"upb_proto_library",
)
_stages = ["_stage0", "_stage1", ""]
_protoc = "//:protoc"
_upbc_base = "//upbc:protoc-gen-"
_upbc_base = "//upb_generator:protoc-gen-"
# begin:google_only
# _is_google3 = True
@ -28,7 +28,7 @@ def _upbc(generator, stage):
def bootstrap_cc_library(name, visibility, deps, bootstrap_deps, **kwargs):
for stage in _stages:
stage_visibility = visibility if stage == "" else ["//upbc:__pkg__"]
stage_visibility = visibility if stage == "" else ["//upb_generator:__pkg__"]
native.cc_library(
name = name + stage,
deps = deps + [dep + stage for dep in bootstrap_deps],
@ -93,7 +93,7 @@ def _generate_stage1_proto(name, base_dir, src_files, src_rules, generator, kwar
"=$(location " + _upbc(generator, 0) + ") " + _extra_proto_path +
"--" + generator + "_out=$(RULEDIR)/" + base_dir + "stage1 " +
" ".join(src_files),
visibility = ["//upbc:__pkg__"],
visibility = ["//upb_generator:__pkg__"],
tools = [
_protoc,
_upbc(generator, 0),
@ -140,7 +140,7 @@ def bootstrap_upb_proto_library(
srcs = _generated_srcs_for_suffix(base_dir + "stage0", oss_src_files, ".upb.c"),
hdrs = _generated_srcs_for_suffix(base_dir + "stage0", oss_src_files, ".upb.h"),
includes = [base_dir + "stage0"],
visibility = ["//upbc:__pkg__"],
visibility = ["//upb_generator:__pkg__"],
# This macro signals to the runtime that it must use OSS APIs for descriptor.proto/plugin.proto.
defines = ["UPB_BOOTSTRAP_STAGE0"],
deps = [
@ -162,7 +162,7 @@ def bootstrap_upb_proto_library(
srcs = _generated_srcs_for_suffix(base_dir + "stage1", src_files, ".upb_minitable.c"),
hdrs = _generated_srcs_for_suffix(base_dir + "stage1", src_files, ".upb_minitable.h"),
includes = [base_dir + "stage1"],
visibility = ["//upbc:__pkg__"],
visibility = ["//upb_generator:__pkg__"],
deps = [
"//upb:generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
] + [dep + "_stage1" for dep in deps],
@ -172,7 +172,7 @@ def bootstrap_upb_proto_library(
name = name + "_stage1",
hdrs = _generated_srcs_for_suffix(base_dir + "stage1", src_files, ".upb.h"),
includes = [base_dir + "stage1"],
visibility = ["//upbc:__pkg__"],
visibility = ["//upb_generator:__pkg__"],
deps = [
"//upb:generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
":" + name + "_minitable_stage1",

@ -28,7 +28,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "upbc/code_generator_request.h"
#include "upb_generator/code_generator_request.h"
#include <inttypes.h>
@ -48,7 +48,7 @@ typedef struct {
upb_Status* status;
upb_DefPool* symtab;
upbc_CodeGeneratorRequest* out;
upb_CodeGeneratorRequest* out;
jmp_buf jmp;
} upbc_State;
@ -68,7 +68,7 @@ static void upbc_State_Init(upbc_State* s) {
s->symtab = upb_DefPool_New();
if (!s->symtab) upbc_Error(s, __func__, "could not allocate def pool");
s->out = upbc_CodeGeneratorRequest_new(s->arena);
s->out = upb_CodeGeneratorRequest_new(s->arena);
if (!s->out) upbc_Error(s, __func__, "could not allocate request");
}
@ -83,11 +83,11 @@ static upb_StringView upbc_State_StrDup(upbc_State* s, const char* str) {
static void upbc_State_AddMiniDescriptor(upbc_State* s, const char* name,
upb_StringView encoding) {
const upb_StringView key = upb_StringView_FromString(name);
upbc_CodeGeneratorRequest_UpbInfo* info =
upbc_CodeGeneratorRequest_UpbInfo_new(s->arena);
upb_CodeGeneratorRequest_UpbInfo* info =
upb_CodeGeneratorRequest_UpbInfo_new(s->arena);
if (!info) upbc_Error(s, __func__, "Out of memory");
upbc_CodeGeneratorRequest_UpbInfo_set_mini_descriptor(info, encoding);
bool ok = upbc_CodeGeneratorRequest_upb_info_set(s->out, key, info, s->arena);
upb_CodeGeneratorRequest_UpbInfo_set_mini_descriptor(info, encoding);
bool ok = upb_CodeGeneratorRequest_upb_info_set(s->out, key, info, s->arena);
if (!ok) upbc_Error(s, __func__, "could not set mini descriptor in map");
}
@ -144,7 +144,7 @@ static void upbc_Scrape_File(upbc_State* s, const upb_FileDef* f) {
static void upbc_Scrape_Files(upbc_State* s) {
const google_protobuf_compiler_CodeGeneratorRequest* request =
upbc_CodeGeneratorRequest_request(s->out);
upb_CodeGeneratorRequest_request(s->out);
size_t len = 0;
const google_protobuf_FileDescriptorProto* const* files =
@ -184,7 +184,7 @@ static void upbc_Scrape_NestedMessages(upbc_State* s, const upb_MessageDef* m) {
}
static void upbc_Scrape_MessageSubs(upbc_State* s,
upbc_CodeGeneratorRequest_UpbInfo* info,
upb_CodeGeneratorRequest_UpbInfo* info,
const upb_MessageDef* m) {
const upb_MiniTableField** fields =
malloc(upb_MessageDef_FieldCount(m) * sizeof(*fields));
@ -200,7 +200,7 @@ static void upbc_Scrape_MessageSubs(upbc_State* s,
const upb_MessageDef* sub = upb_FieldDef_MessageSubDef(f);
if (!sub) upbc_Error(s, __func__, "Missing sub");
upb_StringView name = upbc_State_StrDup(s, upb_MessageDef_FullName(sub));
upbc_CodeGeneratorRequest_UpbInfo_add_sub_message(info, name, s->arena);
upb_CodeGeneratorRequest_UpbInfo_add_sub_message(info, name, s->arena);
}
for (uint32_t i = 0; i < enum_count; i++) {
@ -210,7 +210,7 @@ static void upbc_Scrape_MessageSubs(upbc_State* s,
const upb_EnumDef* sub = upb_FieldDef_EnumSubDef(f);
if (!sub) upbc_Error(s, __func__, "Missing sub (2)");
upb_StringView name = upbc_State_StrDup(s, upb_EnumDef_FullName(sub));
upbc_CodeGeneratorRequest_UpbInfo_add_sub_enum(info, name, s->arena);
upb_CodeGeneratorRequest_UpbInfo_add_sub_enum(info, name, s->arena);
}
free(fields);
@ -221,15 +221,15 @@ static void upbc_Scrape_Message(upbc_State* s, const upb_MessageDef* m) {
bool ok = upb_MessageDef_MiniDescriptorEncode(m, s->arena, &desc);
if (!ok) upbc_Error(s, __func__, "could not encode message");
upbc_CodeGeneratorRequest_UpbInfo* info =
upbc_CodeGeneratorRequest_UpbInfo_new(s->arena);
upb_CodeGeneratorRequest_UpbInfo* info =
upb_CodeGeneratorRequest_UpbInfo_new(s->arena);
if (!info) upbc_Error(s, __func__, "Out of memory");
upbc_CodeGeneratorRequest_UpbInfo_set_mini_descriptor(info, desc);
upb_CodeGeneratorRequest_UpbInfo_set_mini_descriptor(info, desc);
upbc_Scrape_MessageSubs(s, info, m);
const upb_StringView key = upbc_State_StrDup(s, upb_MessageDef_FullName(m));
ok = upbc_CodeGeneratorRequest_upb_info_set(s->out, key, info, s->arena);
ok = upb_CodeGeneratorRequest_upb_info_set(s->out, key, info, s->arena);
if (!ok) upbc_Error(s, __func__, "could not set mini descriptor in map");
upbc_Scrape_NestedEnums(s, m);
@ -237,18 +237,18 @@ static void upbc_Scrape_Message(upbc_State* s, const upb_MessageDef* m) {
upbc_Scrape_NestedMessages(s, m);
}
static upbc_CodeGeneratorRequest* upbc_State_MakeCodeGeneratorRequest(
static upb_CodeGeneratorRequest* upbc_State_MakeCodeGeneratorRequest(
upbc_State* const s, google_protobuf_compiler_CodeGeneratorRequest* const request) {
if (UPB_SETJMP(s->jmp)) return NULL;
upbc_State_Init(s);
upbc_CodeGeneratorRequest_set_request(s->out, request);
upb_CodeGeneratorRequest_set_request(s->out, request);
upbc_Scrape_Files(s);
upbc_State_Fini(s);
return s->out;
}
upbc_CodeGeneratorRequest* upbc_MakeCodeGeneratorRequest(
upb_CodeGeneratorRequest* upbc_MakeCodeGeneratorRequest(
google_protobuf_compiler_CodeGeneratorRequest* request, upb_Arena* arena,
upb_Status* status) {
upbc_State s = {

@ -28,12 +28,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UPBC_CODE_GENERATOR_REQUEST_H_
#define UPBC_CODE_GENERATOR_REQUEST_H_
#ifndef UPB_GENERATOR_CODE_GENERATOR_REQUEST_H_
#define UPB_GENERATOR_CODE_GENERATOR_REQUEST_H_
#include "upb/mem/arena.h"
#include "upb/reflection/def.h"
#include "upbc/code_generator_request.upb.h"
#include "upb_generator/code_generator_request.upb.h"
// Must be last.
#include "upb/port/def.inc"
@ -42,7 +42,7 @@
extern "C" {
#endif
upbc_CodeGeneratorRequest* upbc_MakeCodeGeneratorRequest(
upb_CodeGeneratorRequest* upbc_MakeCodeGeneratorRequest(
struct google_protobuf_compiler_CodeGeneratorRequest* request, upb_Arena* a,
upb_Status* s);
@ -52,4 +52,4 @@ upbc_CodeGeneratorRequest* upbc_MakeCodeGeneratorRequest(
#include "upb/port/undef.inc"
#endif /* UPBC_CODE_GENERATOR_REQUEST_H_ */
#endif /* UPB_GENERATOR_CODE_GENERATOR_REQUEST_H_ */

@ -30,7 +30,7 @@
syntax = "proto2";
package upbc;
package upb;
import "google/protobuf/compiler/plugin.proto";

@ -28,7 +28,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "upbc/common.h"
#include "upb_generator/common.h"
#include <assert.h>
#include <stdint.h>
@ -48,7 +48,8 @@
// Must be last
#include "upb/port/def.inc"
namespace upbc {
namespace upb {
namespace generator {
std::string StripExtension(absl::string_view fname) {
size_t lastdot = fname.find_last_of('.');
@ -68,8 +69,7 @@ std::string ToPreproc(absl::string_view str) {
void EmitFileWarning(absl::string_view name, Output& output) {
output(
"/* This file was generated by upbc (the upb compiler) from the input\n"
" * file:\n"
"/* This file was generated by upb_generator from the input file:\n"
" *\n"
" * $0\n"
" *\n"
@ -185,4 +185,5 @@ std::string GetFieldRep(const upb_MiniTableField* field32,
UPB_UNREACHABLE();
}
} // namespace upbc
} // namespace generator
} // namespace upb

@ -28,8 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UPBC_COMMON_H
#define UPBC_COMMON_H
#ifndef UPB_GENERATOR_COMMON_H
#define UPB_GENERATOR_COMMON_H
#include <vector>
@ -37,7 +37,8 @@
#include "absl/strings/substitute.h"
#include "upb/reflection/def.hpp"
namespace upbc {
namespace upb {
namespace generator {
class Output {
public:
@ -97,6 +98,7 @@ std::string GetModeInit(const upb_MiniTableField* field32,
std::string GetFieldRep(const upb_MiniTableField* field32,
const upb_MiniTableField* field64);
} // namespace upbc
} // namespace generator
} // namespace upb
#endif // UPBC_COMMON_H
#endif // UPB_GENERATOR_COMMON_H

@ -28,15 +28,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "upbc/file_layout.h"
#include "upb_generator/file_layout.h"
#include <string>
#include <unordered_set>
#include "upb/mini_table/internal/extension.h"
#include "upbc/common.h"
#include "upb_generator/common.h"
namespace upbc {
namespace upb {
namespace generator {
const char* kEnumsInit = "enums_layout";
const char* kExtensionsInit = "extensions_layout";
@ -141,4 +142,5 @@ std::vector<upb::FieldDefPtr> FieldNumberOrder(upb::MessageDefPtr message) {
return fields;
}
} // namespace upbc
} // namespace generator
} // namespace upb

@ -28,14 +28,14 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UPBC_FILE_LAYOUT_H
#define UPBC_FILE_LAYOUT_H
#ifndef UPB_GENERATOR_FILE_LAYOUT_H
#define UPB_GENERATOR_FILE_LAYOUT_H
#include <string>
// begin:google_only
// #ifndef UPB_BOOTSTRAP_STAGE0
// #include "net/proto2/proto/descriptor.upb.h"
// #include "google/protobuf/descriptor.upb.h"
// #else
// #include "google/protobuf/descriptor.upb.h"
// #endif
@ -54,7 +54,8 @@
// Must be last
#include "upb/port/def.inc"
namespace upbc {
namespace upb {
namespace generator {
std::vector<upb::EnumDefPtr> SortedEnums(upb::FileDefPtr file);
@ -122,8 +123,9 @@ class DefPoolPair {
upb::DefPool pool64_;
};
} // namespace upbc
} // namespace generator
} // namespace upb
#include "upb/port/undef.inc"
#endif // UPBC_FILE_LAYOUT_H
#endif // UPB_GENERATOR_FILE_LAYOUT_H

@ -28,7 +28,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "upbc/get_used_fields.h"
#include "upb_generator/get_used_fields.h"
#include "google/protobuf/descriptor.upb.h"
#include "google/protobuf/compiler/plugin.upb.h"

@ -28,8 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UPBC_GET_USED_FIELDS
#define UPBC_GET_USED_FIELDS
#ifndef UPB_GENERATOR_GET_USED_FIELDS
#define UPB_GENERATOR_GET_USED_FIELDS
#include "upb/base/status.h"
#include "upb/base/string_view.h"
@ -43,7 +43,7 @@ extern "C" {
#endif
// Consume |buf|, deserialize it to a Code_Generator_Request proto, then
// upbc_Code_Generator_Request, and return it as a JSON-encoded string.
// upb_Code_Generator_Request, and return it as a JSON-encoded string.
UPB_API upb_StringView upbdev_GetUsedFields(
const char* request, size_t request_size, const char* payload,
size_t payload_size, const char* message_name, upb_Arena* arena);
@ -54,4 +54,4 @@ UPB_API upb_StringView upbdev_GetUsedFields(
#include "upb/port/undef.inc"
#endif // UPBC_GET_USED_FIELDS
#endif // UPB_GENERATOR_GET_USED_FIELDS

@ -28,12 +28,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "upbc/keywords.h"
#include "upb_generator/keywords.h"
#include <string>
#include <unordered_set>
namespace upbc {
namespace upb {
namespace generator {
static const char* const kKeywordList[] = {
//
@ -149,4 +150,5 @@ std::string ResolveKeywordConflict(const std::string& name) {
return name;
}
} // namespace upbc
} // namespace generator
} // namespace upb

@ -33,11 +33,13 @@
#include <string>
namespace upbc {
namespace upb {
namespace generator {
// Resolves proto field name conflict with C++ reserved keywords.
std::string ResolveKeywordConflict(const std::string& name);
} // namespace upbc
} // namespace generator
} // namespace upb
#endif // UPB_PROTOS_GENERATOR_KEYWORDS_H

@ -28,7 +28,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "upbc/names.h"
#include "upb_generator/names.h"
#include <string>
@ -37,7 +37,8 @@
#include "google/protobuf/descriptor.h"
#include "upb/reflection/def.hpp"
namespace upbc {
namespace upb {
namespace generator {
namespace protobuf = ::google::protobuf;
@ -129,4 +130,5 @@ std::string ResolveFieldName(upb::FieldDefPtr field,
return std::string(field_name);
}
} // namespace upbc
} // namespace generator
} // namespace upb

@ -39,7 +39,8 @@
#include "google/protobuf/descriptor.h"
#include "upb/reflection/def.hpp"
namespace upbc {
namespace upb {
namespace generator {
using NameToFieldDescriptorMap =
absl::flat_hash_map<absl::string_view, const google::protobuf::FieldDescriptor*>;
@ -68,6 +69,7 @@ ABSL_CONST_INIT extern const absl::string_view kRepeatedFieldArrayGetterPostfix;
ABSL_CONST_INIT extern const absl::string_view
kRepeatedFieldMutableArrayGetterPostfix;
} // namespace upbc
} // namespace generator
} // namespace upb
#endif // UPB_PROTOS_GENERATOR_NAMES_H

@ -28,8 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UPB_UPBC_PLUGIN_H_
#define UPB_UPBC_PLUGIN_H_
#ifndef UPB_UPB_GENERATOR_PLUGIN_H_
#define UPB_UPB_GENERATOR_PLUGIN_H_
#include <stdio.h>
@ -42,8 +42,8 @@
// begin:google_only
// #ifndef UPB_BOOTSTRAP_STAGE0
// #include "net/proto2/proto/descriptor.upb.h"
// #include "third_party/protobuf/compiler/plugin.upb.h"
// #include "google/protobuf/descriptor.upb.h"
// #include "google/protobuf/compiler/plugin.upb.h"
// #else
// #include "google/protobuf/compiler/plugin.upb.h"
// #include "google/protobuf/descriptor.upb.h"
@ -64,7 +64,8 @@
// Must be last.
#include "upb/port/def.inc"
namespace upbc {
namespace upb {
namespace generator {
inline std::vector<std::pair<std::string, std::string>> ParseGeneratorParameter(
const absl::string_view text) {
@ -205,8 +206,9 @@ class Plugin {
}
};
} // namespace upbc
} // namespace generator
} // namespace upb
#include "upb/port/undef.inc"
#endif // UPB_UPBC_PLUGIN_H_
#endif // UPB_UPB_GENERATOR_PLUGIN_H_

@ -53,15 +53,16 @@
#include "upb/base/string_view.h"
#include "upb/reflection/def.hpp"
#include "upb/wire/types.h"
#include "upbc/common.h"
#include "upbc/file_layout.h"
#include "upbc/names.h"
#include "upbc/plugin.h"
#include "upb_generator/common.h"
#include "upb_generator/file_layout.h"
#include "upb_generator/names.h"
#include "upb_generator/plugin.h"
// Must be last.
#include "upb/port/def.inc"
namespace upbc {
namespace upb {
namespace generator {
namespace {
struct Options {
@ -278,7 +279,8 @@ void DumpEnumValues(upb::EnumDefPtr desc, Output& output) {
}
std::string GetFieldRep(const DefPoolPair& pools, upb::FieldDefPtr field) {
return upbc::GetFieldRep(pools.GetField32(field), pools.GetField64(field));
return upb::generator::GetFieldRep(pools.GetField32(field),
pools.GetField64(field));
}
void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext,
@ -993,7 +995,7 @@ std::string FieldInitializer(upb::FieldDefPtr field,
"*upb_MiniTable_FindFieldByNumber($0, $1)",
MessageMiniTableRef(field.containing_type(), options), field.number());
} else {
return upbc::FieldInitializer(field, field64, field32);
return upb::generator::FieldInitializer(field, field64, field32);
}
}
@ -1131,20 +1133,21 @@ absl::string_view ToStringView(upb_StringView str) {
} // namespace
} // namespace upbc
} // namespace generator
} // namespace upb
int main(int argc, char** argv) {
upbc::DefPoolPair pools;
upbc::Plugin plugin;
upbc::Options options;
upb::generator::DefPoolPair pools;
upb::generator::Plugin plugin;
upb::generator::Options options;
if (!ParseOptions(&plugin, &options)) return 0;
plugin.GenerateFilesRaw([&](const UPB_DESC(FileDescriptorProto) * file_proto,
bool generate) {
upb::Status status;
upb::FileDefPtr file = pools.AddFile(file_proto, &status);
if (!file) {
absl::string_view name =
upbc::ToStringView(UPB_DESC(FileDescriptorProto_name)(file_proto));
absl::string_view name = upb::generator::ToStringView(
UPB_DESC(FileDescriptorProto_name)(file_proto));
ABSL_LOG(FATAL) << "Couldn't add file " << name
<< " to DefPool: " << status.error_message();
}

@ -49,15 +49,16 @@
#include "upb/base/string_view.h"
#include "upb/reflection/def.hpp"
#include "upb/wire/types.h"
#include "upbc/common.h"
#include "upbc/file_layout.h"
#include "upbc/names.h"
#include "upbc/plugin.h"
#include "upb_generator/common.h"
#include "upb_generator/file_layout.h"
#include "upb_generator/names.h"
#include "upb_generator/plugin.h"
// Must be last.
#include "upb/port/def.inc"
namespace upbc {
namespace upb {
namespace generator {
namespace {
// Returns fields in order of "hotness", eg. how frequently they appear in
@ -406,15 +407,15 @@ std::string ArchDependentSize(int64_t size32, int64_t size64) {
}
std::string FieldInitializer(const DefPoolPair& pools, upb::FieldDefPtr field) {
return upbc::FieldInitializer(field, pools.GetField64(field),
pools.GetField32(field));
return upb::generator::FieldInitializer(field, pools.GetField64(field),
pools.GetField32(field));
}
// Writes a single field into a .upb.c source file.
void WriteMessageField(upb::FieldDefPtr field,
const upb_MiniTableField* field64,
const upb_MiniTableField* field32, Output& output) {
output(" $0,\n", upbc::FieldInitializer(field, field64, field32));
output(" $0,\n", upb::generator::FieldInitializer(field, field64, field32));
}
std::string GetSub(upb::FieldDefPtr field) {
@ -687,23 +688,24 @@ absl::string_view ToStringView(upb_StringView str) {
} // namespace
} // namespace upbc
} // namespace generator
} // namespace upb
int main(int argc, char** argv) {
upbc::DefPoolPair pools;
upbc::Plugin plugin;
if (!upbc::ParseOptions(&plugin)) return 0;
upb::generator::DefPoolPair pools;
upb::generator::Plugin plugin;
if (!upb::generator::ParseOptions(&plugin)) return 0;
plugin.GenerateFilesRaw([&](const UPB_DESC(FileDescriptorProto) * file_proto,
bool generate) {
upb::Status status;
upb::FileDefPtr file = pools.AddFile(file_proto, &status);
if (!file) {
absl::string_view name =
upbc::ToStringView(UPB_DESC(FileDescriptorProto_name)(file_proto));
absl::string_view name = upb::generator::ToStringView(
UPB_DESC(FileDescriptorProto_name)(file_proto));
ABSL_LOG(FATAL) << "Couldn't add file " << name
<< " to DefPool: " << status.error_message();
}
if (generate) upbc::GenerateFile(pools, file, &plugin);
if (generate) upb::generator::GenerateFile(pools, file, &plugin);
});
return 0;
}

@ -33,11 +33,12 @@
#include "google/protobuf/descriptor.upb.h"
#include "upb/reflection/def.hpp"
#include "upb/util/def_to_proto.h"
#include "upbc/common.h"
#include "upbc/file_layout.h"
#include "upbc/plugin.h"
#include "upb_generator/common.h"
#include "upb_generator/file_layout.h"
#include "upb_generator/plugin.h"
namespace upbc {
namespace upb {
namespace generator {
namespace {
std::string DefInitSymbol(upb::FileDefPtr file) {
@ -160,16 +161,18 @@ void GenerateFile(upb::FileDefPtr file, Plugin* plugin) {
}
} // namespace
} // namespace upbc
} // namespace generator
} // namespace upb
int main(int argc, char** argv) {
upbc::Plugin plugin;
upb::generator::Plugin plugin;
if (!plugin.parameter().empty()) {
plugin.SetError(
absl::StrCat("Expected no parameters, got: ", plugin.parameter()));
return 0;
}
plugin.GenerateFiles(
[&](upb::FileDefPtr file) { upbc::GenerateFile(file, &plugin); });
plugin.GenerateFiles([&](upb::FileDefPtr file) {
upb::generator::GenerateFile(file, &plugin);
});
return 0;
}

@ -32,8 +32,8 @@
#include <string>
#include "google/protobuf/compiler/plugin.upb.h"
#include "upbc/subprocess.h"
#include "upbc/upbdev.h"
#include "upb_generator/subprocess.h"
#include "upb_generator/upbdev.h"
static constexpr char kDefaultPlugin[] = "protoc_dart_plugin";
@ -57,7 +57,7 @@ int main() {
plugin = std::string(param.data, param.size);
}
// Wrap the request inside a upbc_CodeGeneratorRequest and JSON-encode it.
// Wrap the request inside a upb_CodeGeneratorRequest and JSON-encode it.
const upb_StringView sv =
upbdev_ProcessInput(input.data(), input.size(), a, &status);
if (!upb_Status_IsOk(&status)) {
@ -66,8 +66,8 @@ int main() {
}
// Launch the subprocess.
upbc::Subprocess subprocess;
subprocess.Start(plugin, upbc::Subprocess::SEARCH_PATH);
upb::generator::Subprocess subprocess;
subprocess.Start(plugin, upb::generator::Subprocess::SEARCH_PATH);
// Exchange JSON strings with the subprocess.
const std::string json_request = std::string(sv.data, sv.size);

@ -1,5 +1,4 @@
/* This file was generated by upbc (the upb compiler) from the input
* file:
/* This file was generated by upb_generator from the input file:
*
* google/protobuf/compiler/plugin.proto
*

@ -31,7 +31,7 @@
// Shamelessly copied from the protobuf compiler's subprocess.cc
// except this version passes strings instead of Messages.
#include "upbc/subprocess.h"
#include "upb_generator/subprocess.h"
#include <algorithm>
#include <cstring>
@ -50,7 +50,8 @@
// Must be last.
#include "upb/port/def.inc"
namespace upbc {
namespace upb {
namespace generator {
namespace {
char* portable_strdup(const char* s) {
@ -462,4 +463,5 @@ bool Subprocess::Communicate(const std::string& input_data,
#endif // !_WIN32
} // namespace upbc
} // namespace generator
} // namespace upb

@ -31,8 +31,8 @@
// Shamelessly copied from the protobuf compiler's subprocess.h
// except this version passes strings instead of Messages.
#ifndef THIRD_PARTY_UPB_UPBC_H_
#define THIRD_PARTY_UPB_UPBC_H_
#ifndef THIRD_PARTY_UPB_UPB_GENERATOR_H_
#define THIRD_PARTY_UPB_UPB_GENERATOR_H_
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
@ -45,7 +45,8 @@
#endif // !_WIN32
#include <string>
namespace upbc {
namespace upb {
namespace generator {
// Utility class for launching sub-processes.
class Subprocess {
@ -97,6 +98,7 @@ class Subprocess {
#endif // !_WIN32
};
} // namespace upbc
} // namespace generator
} // namespace upb
#endif // THIRD_PARTY_UPB_UPBC_H_
#endif // THIRD_PARTY_UPB_UPB_GENERATOR_H_

@ -30,5 +30,5 @@
// These headers form a spanning tree for the upbc defs needed by FFI layers.
#include "upbc/get_used_fields.h"
#include "upbc/upbdev.h"
#include "upb_generator/get_used_fields.h"
#include "upb_generator/upbdev.h"

@ -28,7 +28,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "upbc/upbdev.h"
#include "upb_generator/upbdev.h"
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
@ -45,9 +45,9 @@
#include "upb/json/decode.h"
#include "upb/json/encode.h"
#include "upb/mem/arena.h"
#include "upbc/code_generator_request.h"
#include "upbc/code_generator_request.upb.h"
#include "upbc/code_generator_request.upbdefs.h"
#include "upb_generator/code_generator_request.h"
#include "upb_generator/code_generator_request.upb.h"
#include "upb_generator/code_generator_request.upbdefs.h"
static google_protobuf_compiler_CodeGeneratorResponse* upbc_JsonDecode(
const char* data, size_t size, upb_Arena* arena, upb_Status* status) {
@ -65,12 +65,12 @@ static google_protobuf_compiler_CodeGeneratorResponse* upbc_JsonDecode(
return response;
}
static upb_StringView upbc_JsonEncode(const upbc_CodeGeneratorRequest* request,
static upb_StringView upbc_JsonEncode(const upb_CodeGeneratorRequest* request,
upb_Arena* arena, upb_Status* status) {
upb_StringView out = {.data = NULL, .size = 0};
upb_DefPool* s = upb_DefPool_New();
const upb_MessageDef* m = upbc_CodeGeneratorRequest_getmsgdef(s);
const upb_MessageDef* m = upb_CodeGeneratorRequest_getmsgdef(s);
const int options = upb_JsonEncode_FormatEnumsAsIntegers;
out.size = upb_JsonEncode(request, m, s, options, NULL, 0, status);
@ -95,7 +95,7 @@ upb_StringView upbdev_ProcessInput(const char* buf, size_t size,
google_protobuf_compiler_CodeGeneratorRequest* inner_request =
google_protobuf_compiler_CodeGeneratorRequest_parse(buf, size, arena);
const upbc_CodeGeneratorRequest* outer_request =
const upb_CodeGeneratorRequest* outer_request =
upbc_MakeCodeGeneratorRequest(inner_request, arena, status);
if (!upb_Status_IsOk(status)) return out;

@ -28,8 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UPBC_UPBDEV_H_
#define UPBC_UPBDEV_H_
#ifndef UPB_GENERATOR_UPBDEV_H_
#define UPB_GENERATOR_UPBDEV_H_
#include "upb/base/status.h"
#include "upb/base/string_view.h"
@ -43,7 +43,7 @@ extern "C" {
#endif
// Consume |buf|, deserialize it to a Code_Generator_Request proto, construct a
// upbc_Code_Generator_Request, and return it as a JSON-encoded string.
// upb_Code_Generator_Request, and return it as a JSON-encoded string.
UPB_API upb_StringView upbdev_ProcessInput(const char* buf, size_t size,
upb_Arena* arena,
upb_Status* status);
@ -68,4 +68,4 @@ UPB_API void upbdev_Status_Clear(upb_Status* status);
#include "upb/port/undef.inc"
#endif // UPBC_UPBDEV_H_
#endif // UPB_GENERATOR_UPBDEV_H_
Loading…
Cancel
Save