Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the file a symbol is declared in to Reflection #6613

Merged
merged 23 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ function(compile_flatbuffers_schema_to_binary SRC_FBS)
OUTPUT ${GEN_BINARY_SCHEMA}
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
-b --schema --bfbs-comments --bfbs-builtins
--bfbs-filenames ${SRC_FBS_DIR}
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
-o "${SRC_FBS_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
Expand All @@ -468,6 +469,7 @@ function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
${OPT}
--bfbs-comments --bfbs-builtins --bfbs-gen-embed
--bfbs-filenames ${SRC_FBS_DIR}
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
-o "${SRC_FBS_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
Expand Down
8 changes: 4 additions & 4 deletions grpc/examples/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ generator="--grpc $current_dir/greeter.fbs"
cd go

cd greeter
fbc --go ${generator}
fbc --bfbs-filenames ../.. --go ${generator}

cd ${current_dir}

Expand All @@ -50,22 +50,22 @@ cd python

cd greeter

fbc --python ${generator}
fbc --bfbs-filenames ../.. --python ${generator}

cd ${current_dir}

# Regenerate Swift code
cd swift

cd Greeter/Sources/Model
fbc --swift ${generator}
fbc --bfbs-filenames ../../../.. --swift ${generator}

cd ${current_dir}

# Regenerate Typescript code
cd ts

cd greeter/src
fbc --ts ${generator}
fbc --bfbs-filenames ../../.. --ts ${generator}

cd ${current_dir}
19 changes: 15 additions & 4 deletions include/flatbuffers/idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>>>
Expand All @@ -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 {
Expand Down Expand Up @@ -587,6 +589,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 {
Expand Down Expand Up @@ -672,6 +675,7 @@ struct IDLOptions {
filename_suffix("_generated"),
filename_extension(),
no_warnings(false),
project_root(""),
lang(IDLOptions::kJava),
mini_reflect(IDLOptions::kNone),
require_explicit_ids(false),
Expand Down Expand Up @@ -936,14 +940,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();
Expand Down Expand Up @@ -980,6 +985,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_;
Expand Down Expand Up @@ -1015,6 +1022,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
};
Expand Down
Loading