mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Fixed --keep-prefix functionality.
Changing to keep include prefixes had two side effects: the main file being parsed wasn't filtered out anymore, and include directory paths would be added to the path in the include statement. Also moved the include_test*.fbs files to sub directories so we can actually test the handling of -I etc. tested: on Linux. Change-Id: Ibae095cea7ab0cccbac15cfb5171719f6b5cad8c
This commit is contained in:
@@ -1917,15 +1917,17 @@ CheckedError Parser::SkipJsonString() {
|
||||
|
||||
bool Parser::Parse(const char *source, const char **include_paths,
|
||||
const char *source_filename) {
|
||||
return !DoParse(source, include_paths, source_filename).Check();
|
||||
return !DoParse(source, include_paths, source_filename,
|
||||
source_filename).Check();
|
||||
}
|
||||
|
||||
CheckedError Parser::DoParse(const char *source, const char **include_paths,
|
||||
const char *source_filename) {
|
||||
const char *source_filename,
|
||||
const char *include_filename) {
|
||||
file_being_parsed_ = source_filename ? source_filename : "";
|
||||
if (source_filename &&
|
||||
included_files_.find(source_filename) == included_files_.end()) {
|
||||
included_files_[source_filename] = true;
|
||||
included_files_.find(include_filename) == included_files_.end()) {
|
||||
included_files_[include_filename] = true;
|
||||
files_included_per_file_[source_filename] = std::set<std::string>();
|
||||
}
|
||||
if (!include_paths) {
|
||||
@@ -1974,13 +1976,14 @@ CheckedError Parser::DoParse(const char *source, const char **include_paths,
|
||||
return Error("unable to locate include file: " + name);
|
||||
if (source_filename)
|
||||
files_included_per_file_[source_filename].insert(filepath);
|
||||
if (included_files_.find(filepath) == included_files_.end()) {
|
||||
if (included_files_.find(name) == included_files_.end()) {
|
||||
// We found an include file that we have not parsed yet.
|
||||
// Load it and parse it.
|
||||
std::string contents;
|
||||
if (!LoadFile(filepath.c_str(), true, &contents))
|
||||
return Error("unable to load include file: " + name);
|
||||
ECHECK(DoParse(contents.c_str(), include_paths, filepath.c_str()));
|
||||
ECHECK(DoParse(contents.c_str(), include_paths, filepath.c_str(),
|
||||
name.c_str()));
|
||||
// We generally do not want to output code for any included files:
|
||||
if (!opts.generate_all) MarkGenerated();
|
||||
// This is the easiest way to continue this file after an include:
|
||||
@@ -1990,7 +1993,7 @@ CheckedError Parser::DoParse(const char *source, const char **include_paths,
|
||||
// entered into included_files_.
|
||||
// This is recursive, but only go as deep as the number of include
|
||||
// statements.
|
||||
return DoParse(source, include_paths, source_filename);
|
||||
return DoParse(source, include_paths, source_filename, include_filename);
|
||||
}
|
||||
EXPECT(';');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user