diff options
author | Josh Haberman <jhaberman@gmail.com> | 2016-03-16 18:07:32 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2016-04-05 17:52:21 -0700 |
commit | e9d79d2441732264e2b990a5b2dc76d13724db07 (patch) | |
tree | 7faaccbd62043ef5652f891e61577a218a74adbc /tests/test_cpp.cc | |
parent | d0b9d0a9b782e46a483d4d72515f9ab4f72e402a (diff) |
Added upb::FileDef, which represents the file defs are declared in.
It is entirely optional: MessageDef/EnumDef can still exist
on their own. But this can represent a def's file when it is
desirable to do so (eg. for code generators).
This approach will require that we change the way we handle
extensions. But I think it will be a good change overall.
Specifically, we previously handled extensions by duplicating
the extended message and then adding the extension as a regular
field to the duplicated message. This required also duplicating
any messages that could reach the extended message.
In the new world we will need a way of declaring and looking up
extensions separately from the message being extended.
This change also involves some notable changes to the generated
code:
- files are now called foo.upbdefs.h instead of foo.upb.h.
This reflects the fact that we might possibly generate several
different output files for a .proto file, and this one is just
for defs.
- we no longer generate selectors in the .h file.
- the upbdefs.c no longer vends a SymbolTable. Now it vends the
individual messages (and possibly a FileDef later). I think this
will compose better once we can generate files where one
generated files imports another.
We also make the descriptor reader vend a list of FileDefs now.
This is the best conceptual match for parsing a FileDescriptorSet.
Diffstat (limited to 'tests/test_cpp.cc')
-rw-r--r-- | tests/test_cpp.cc | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/test_cpp.cc b/tests/test_cpp.cc index 48f0a3f..c27526b 100644 --- a/tests/test_cpp.cc +++ b/tests/test_cpp.cc @@ -6,6 +6,7 @@ #include <stdio.h> #include <string.h> +#include <fstream> #include <iostream> #include <set> #include <sstream> @@ -144,12 +145,22 @@ static void TestCastsConst10() { } static void TestSymbolTable(const char *descriptor_file) { - upb::reffed_ptr<upb::SymbolTable> s(upb::SymbolTable::New()); upb::Status status; - if (!upb::LoadDescriptorFileIntoSymtab(s.get(), descriptor_file, &status)) { + std::ifstream file_in(descriptor_file, std::ios::binary); + std::string descriptor((std::istreambuf_iterator<char>(file_in)), + (std::istreambuf_iterator<char>())); + std::vector<upb::reffed_ptr<upb::FileDef> > files; + if (!upb::LoadDescriptor(descriptor, &status, &files)) { std::cerr << "Couldn't load descriptor: " << status.error_message(); exit(1); } + + upb::reffed_ptr<upb::SymbolTable> s(upb::SymbolTable::New()); + + for (size_t i = 0; i < files.size(); i++) { + ASSERT(s->AddFile(files[i].get(), &status)); + } + ASSERT(!s->IsFrozen()); s->Freeze(); ASSERT(s->IsFrozen()); |