diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2019-05-15 12:47:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-15 12:47:41 -0500 |
commit | 184cc8ecfa5767577844f452e7d645465650df10 (patch) | |
tree | 87772b59a9f1a62a1140fab7bbeded50eef3f536 /upbc | |
parent | 04350e1d1b7ff5457b1a36150d98d5a5efc0ed89 (diff) | |
parent | a126b9a046d8a5e0b73e363d815ae45f0ae748b6 (diff) |
Merge pull request #167 from haberman/bazel25
Fixes to make upb and upb_proto_library() work with Blaze inside Google
Diffstat (limited to 'upbc')
-rw-r--r-- | upbc/generator.cc | 39 | ||||
-rw-r--r-- | upbc/message_layout.h | 10 |
2 files changed, 32 insertions, 17 deletions
diff --git a/upbc/generator.cc b/upbc/generator.cc index 5843597..53d849e 100644 --- a/upbc/generator.cc +++ b/upbc/generator.cc @@ -1,8 +1,7 @@ -#include <unordered_map> -#include <unordered_set> #include <memory> +#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/str_replace.h" #include "absl/strings/substitute.h" @@ -488,7 +487,7 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output } } - output("\n\n"); + output("\n"); } void WriteHeader(const protobuf::FileDescriptor* file, Output& output) { @@ -496,15 +495,30 @@ void WriteHeader(const protobuf::FileDescriptor* file, Output& output) { output( "#ifndef $0_UPB_H_\n" "#define $0_UPB_H_\n\n" - "#include \"upb/generated_util.h\"\n\n" - "#include \"upb/msg.h\"\n\n" + "#include \"upb/generated_util.h\"\n" + "#include \"upb/msg.h\"\n" "#include \"upb/decode.h\"\n" - "#include \"upb/encode.h\"\n" + "#include \"upb/encode.h\"\n\n", + ToPreproc(file->name())); + + for (int i = 0; i < file->public_dependency_count(); i++) { + const auto& name = file->public_dependency(i)->name(); + if (i == 0) { + output("/* Public Imports. */\n"); + } + output("#include \"$0\"\n", HeaderFilename(name)); + if (i == file->public_dependency_count() - 1) { + output("\n"); + } + } + + output( "#include \"upb/port_def.inc\"\n" + "\n" "#ifdef __cplusplus\n" "extern \"C\" {\n" - "#endif\n\n", - ToPreproc(file->name())); + "#endif\n" + "\n"); std::vector<const protobuf::Descriptor*> this_file_messages = SortedMessages(file); @@ -541,12 +555,13 @@ void WriteHeader(const protobuf::FileDescriptor* file, Output& output) { output("extern const upb_msglayout $0;\n", MessageInit(pair.second)); } + if (!this_file_messages.empty()) { + output("\n"); + } + std::vector<const protobuf::EnumDescriptor*> this_file_enums = SortedEnums(file); - output( - "\n" - "/* Enums */\n\n"); for (auto enumdesc : this_file_enums) { output("typedef enum {\n"); DumpEnumValues(enumdesc, output); @@ -594,7 +609,7 @@ void WriteSource(const protobuf::FileDescriptor* file, Output& output) { std::string fields_array_ref = "NULL"; std::string submsgs_array_ref = "NULL"; std::string oneofs_array_ref = "NULL"; - std::unordered_map<const protobuf::Descriptor*, int> submsg_indexes; + absl::flat_hash_map<const protobuf::Descriptor*, int> submsg_indexes; MessageLayout layout(message); std::vector<const protobuf::FieldDescriptor*> sorted_submsgs = SortedSubmessages(message); diff --git a/upbc/message_layout.h b/upbc/message_layout.h index a4cb289..c2446a0 100644 --- a/upbc/message_layout.h +++ b/upbc/message_layout.h @@ -2,8 +2,8 @@ #ifndef UPBC_MESSAGE_LAYOUT_H #define UPBC_MESSAGE_LAYOUT_H -#include <unordered_map> #include "absl/base/macros.h" +#include "absl/container/flat_hash_map.h" #include "google/protobuf/descriptor.h" namespace upbc { @@ -70,7 +70,7 @@ class MessageLayout { Size Place(SizeAndAlign size_and_align); template <class K, class V> - static V GetMapValue(const std::unordered_map<K, V>& map, K key) { + static V GetMapValue(const absl::flat_hash_map<K, V>& map, K key) { auto iter = map.find(key); if (iter == map.end()) { fprintf(stderr, "No value for field.\n"); @@ -92,11 +92,11 @@ class MessageLayout { static int64_t FieldLayoutRank( const google::protobuf::FieldDescriptor* field); - std::unordered_map<const google::protobuf::FieldDescriptor*, Size> + absl::flat_hash_map<const google::protobuf::FieldDescriptor*, Size> field_offsets_; - std::unordered_map<const google::protobuf::FieldDescriptor*, int> + absl::flat_hash_map<const google::protobuf::FieldDescriptor*, int> hasbit_indexes_; - std::unordered_map<const google::protobuf::OneofDescriptor*, Size> + absl::flat_hash_map<const google::protobuf::OneofDescriptor*, Size> oneof_case_offsets_; Size maxalign_; Size size_; |