diff options
author | Tom Cherry <tomcherry@google.com> | 2017-04-19 15:31:58 -0700 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2017-04-21 18:26:40 -0700 |
commit | 30a6f276fd8850b0a78689d7bff3cb06a18cb286 (patch) | |
tree | 6d07dc78662207e7300c42c9362dc7b198d98194 /init/import_parser.cpp | |
parent | a0bf415cad6dddcc1cdb154a95c795b5a8ecb7aa (diff) |
init: clean up the SectionParser interface and Parser class
Remove the dependency on Action and Service from what should be a
generic Parser class.
Make ActionParser, ImportParser, and ServiceParser take a pointer to
their associated classes instead of accessing them through a
singleton.
Misc fixes to SectionParser Interface:
1) Make SectionParser::ParseLineSection() non-const as it always should
have been.
2) Use Rvalue references where appropriate
3) Remove extra std::string& filename in SectionParser::EndFile()
4) Only have SectionParser::ParseSection() as pure virtual
Document SectionParser.
Make ImportParser report the filename and line number of failed imports.
Make ServiceParser report the filename and line number of duplicated services.
Test: Boot bullhead
Change-Id: I86568a5b375fb4f27f4cb235ed1e37635f01d630
Diffstat (limited to 'init/import_parser.cpp')
-rw-r--r-- | init/import_parser.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/init/import_parser.cpp b/init/import_parser.cpp index f66b2bae6..99275e5e7 100644 --- a/init/import_parser.cpp +++ b/init/import_parser.cpp @@ -20,7 +20,7 @@ #include "util.h" -bool ImportParser::ParseSection(const std::vector<std::string>& args, const std::string& filename, +bool ImportParser::ParseSection(std::vector<std::string>&& args, const std::string& filename, int line, std::string* err) { if (args.size() != 2) { *err = "single argument needed for import\n"; @@ -35,16 +35,18 @@ bool ImportParser::ParseSection(const std::vector<std::string>& args, const std: } LOG(INFO) << "Added '" << conf_file << "' to import list"; - imports_.emplace_back(std::move(conf_file)); + if (filename_.empty()) filename_ = filename; + imports_.emplace_back(std::move(conf_file), line); return true; } -void ImportParser::EndFile(const std::string& filename) { +void ImportParser::EndFile() { auto current_imports = std::move(imports_); imports_.clear(); - for (const auto& s : current_imports) { - if (!Parser::GetInstance().ParseConfig(s)) { - PLOG(ERROR) << "could not import file '" << s << "' from '" << filename << "'"; + for (const auto& [import, line_num] : current_imports) { + if (!parser_->ParseConfig(import)) { + PLOG(ERROR) << filename_ << ": " << line_num << ": Could not import file '" << import + << "'"; } } } |