mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-22 20:18:51 +00:00
Add the file a symbol is declared in to Reflection (#6613)
* Add the file a symbol is declared in to Reflection If we move a code-generator to depend on Reflection, it may need to know which file something was declared in to properly name generated files. * Doc comments in reflection, and more precise tests * Add --project-root flag to flatc, normalize declaraion_file to this root * fix --project-root stuff * posixpath * fix scripts * format * rename --project-root to --bfbs-filenames Also, make it optional, rather than defaulting to `./`, if its not specified, then don't serialize the filenames. * bfbs generation * fix some tests * uncomment a thing * add to project root directory conditionally * fix * git clang format * Added help description and removed != nullptr * " * Remove accidental change to docs * Remove accidental change to docs * Pool strings Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
@@ -266,7 +266,8 @@ struct Definition {
|
||||
defined_namespace(nullptr),
|
||||
serialized_location(0),
|
||||
index(-1),
|
||||
refcount(1) {}
|
||||
refcount(1),
|
||||
declaration_file(nullptr) {}
|
||||
|
||||
flatbuffers::Offset<
|
||||
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
|
||||
@@ -286,6 +287,7 @@ struct Definition {
|
||||
uoffset_t serialized_location;
|
||||
int index; // Inside the vector it is stored.
|
||||
int refcount;
|
||||
const std::string *declaration_file;
|
||||
};
|
||||
|
||||
struct FieldDef : public Definition {
|
||||
@@ -591,6 +593,7 @@ struct IDLOptions {
|
||||
std::string filename_suffix;
|
||||
std::string filename_extension;
|
||||
bool no_warnings;
|
||||
std::string project_root;
|
||||
|
||||
// Possible options for the more general generator below.
|
||||
enum Language {
|
||||
@@ -677,6 +680,7 @@ struct IDLOptions {
|
||||
filename_suffix("_generated"),
|
||||
filename_extension(),
|
||||
no_warnings(false),
|
||||
project_root(""),
|
||||
lang(IDLOptions::kJava),
|
||||
mini_reflect(IDLOptions::kNone),
|
||||
require_explicit_ids(false),
|
||||
@@ -941,14 +945,15 @@ class Parser : public ParserState {
|
||||
StructDef *LookupCreateStruct(const std::string &name,
|
||||
bool create_if_new = true,
|
||||
bool definition = false);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseEnum(bool is_union, EnumDef **dest);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseEnum(bool is_union, EnumDef **dest,
|
||||
const char *filename);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseNamespace();
|
||||
FLATBUFFERS_CHECKED_ERROR StartStruct(const std::string &name,
|
||||
StructDef **dest);
|
||||
FLATBUFFERS_CHECKED_ERROR StartEnum(const std::string &name, bool is_union,
|
||||
EnumDef **dest);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseDecl();
|
||||
FLATBUFFERS_CHECKED_ERROR ParseService();
|
||||
FLATBUFFERS_CHECKED_ERROR ParseDecl(const char *filename);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseService(const char *filename);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef *struct_def,
|
||||
bool isextend, bool inside_oneof);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseProtoOption();
|
||||
@@ -985,6 +990,8 @@ class Parser : public ParserState {
|
||||
FLATBUFFERS_CHECKED_ERROR RecurseError();
|
||||
template<typename F> CheckedError Recurse(F f);
|
||||
|
||||
const std::string &GetPooledString(const std::string &s) const;
|
||||
|
||||
public:
|
||||
SymbolTable<Type> types_;
|
||||
SymbolTable<StructDef> structs_;
|
||||
@@ -1020,6 +1027,10 @@ class Parser : public ParserState {
|
||||
|
||||
std::vector<std::pair<Value, FieldDef *>> field_stack_;
|
||||
|
||||
// TODO(cneo): Refactor parser to use string_cache more often to save
|
||||
// on memory usage.
|
||||
mutable std::set<std::string> string_cache_;
|
||||
|
||||
int anonymous_counter_;
|
||||
int parse_depth_counter_; // stack-overflow guard
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user