diff --git a/generator/codefactory.cpp b/generator/codefactory.cpp index e947095..96b3398 100644 --- a/generator/codefactory.cpp +++ b/generator/codefactory.cpp @@ -30,8 +30,8 @@ CodeFactory::ToolInvocation::ToolInvocation(CodeFactory &factory) * \brief Constructs a new instance. * \remarks The specified arguments are not copied and must remain valid for the live-time of the code factory. */ -CodeFactory::CodeFactory( - const char *applicationPath, const std::vector &sourceFiles, const std::vector &clangOptions, std::ostream &os) +CodeFactory::CodeFactory(std::string_view applicationPath, const std::vector &sourceFiles, + const std::vector &clangOptions, std::ostream &os) : m_applicationPath(applicationPath) , m_sourceFiles(sourceFiles) , m_clangOptions(clangOptions) @@ -50,7 +50,7 @@ CodeFactory::~CodeFactory() */ std::vector CodeFactory::makeClangArgs() const { - static const initializer_list flags + static const initializer_list flags = { m_applicationPath, "-x", "c++", "-Wno-pragma-once-outside-header", "-std=c++14", "-fsyntax-only" }; vector clangArgs; clangArgs.reserve(flags.size() + m_clangOptions.size() + m_sourceFiles.size()); diff --git a/generator/codefactory.h b/generator/codefactory.h index bc085ef..67f5654 100644 --- a/generator/codefactory.h +++ b/generator/codefactory.h @@ -29,8 +29,8 @@ class CodeFactory { friend class Visitor; public: - CodeFactory( - const char *applicationPath, const std::vector &sourceFiles, const std::vector &clangOptions, std::ostream &os); + CodeFactory(std::string_view applicationPath, const std::vector &sourceFiles, const std::vector &clangOptions, + std::ostream &os); ~CodeFactory(); const std::vector> &generators() const; @@ -50,9 +50,9 @@ private: bool generate() const; std::vector makeClangArgs() const; - const char *const m_applicationPath; + std::string_view m_applicationPath; const std::vector &m_sourceFiles; - const std::vector &m_clangOptions; + const std::vector &m_clangOptions; std::ostream &m_os; std::vector> m_generators; std::unique_ptr m_toolInvocation; diff --git a/generator/main.cpp b/generator/main.cpp index b4d0fa1..d10909f 100644 --- a/generator/main.cpp +++ b/generator/main.cpp @@ -69,14 +69,16 @@ int main(int argc, char *argv[]) } // compose options passed to the clang tool invocation - vector clangOptions; + auto clangOptions = std::vector(); if (clangOptionsArg.isPresent()) { // add additional options specified via CLI argument for (const auto *const value : clangOptionsArg.values(0)) { // split options by ";" - not nice but this eases using CMake generator expressions - const auto splittedValues(splitString>(value, ";", EmptyPartsTreat::Omit)); + const auto splittedValues = splitStringSimple>(value, ";"); for (const auto &splittedValue : splittedValues) { - clangOptions.emplace_back(move(splittedValue)); + if (!splittedValue.empty()) { + clangOptions.emplace_back(splittedValue); + } } } } @@ -88,7 +90,7 @@ int main(int argc, char *argv[]) } // instantiate the code factory and add generators to it - CodeFactory factory(parser.executable(), inputFileArg.values(0), clangOptions, *os); + auto factory = CodeFactory(parser.executable(), inputFileArg.values(0), clangOptions, *os); factory.setErrorResilient(errorResilientArg.isPresent()); // add specified generators if the --generator argument is present; otherwise add default generators if (generatorsArg.isPresent()) { diff --git a/generator/tests/jsongenerator.cpp b/generator/tests/jsongenerator.cpp index 3bf98a6..9b8b0f9 100644 --- a/generator/tests/jsongenerator.cpp +++ b/generator/tests/jsongenerator.cpp @@ -64,13 +64,14 @@ JsonGeneratorTests::JsonGeneratorTests() */ void JsonGeneratorTests::testGeneratorItself() { - const string inputFilePath(testFilePath("some_structs.h")); - const vector inputFiles{ inputFilePath.data() }; - const vector clangOptions{ "-resource-dir", REFLECTION_GENERATOR_CLANG_RESOURCE_DIR, "-std=c++17", "-I", CPP_UTILITIES_INCLUDE_DIRS, + const auto inputFilePath = testFilePath("some_structs.h"); + const auto inputFiles = vector{ inputFilePath.data() }; + const auto clangOptions + = vector{ "-resource-dir", REFLECTION_GENERATOR_CLANG_RESOURCE_DIR, "-std=c++17", "-I", CPP_UTILITIES_INCLUDE_DIRS, #ifdef RAPIDJSON_INCLUDE_DIRS - "-I", RAPIDJSON_INCLUDE_DIRS + "-I", RAPIDJSON_INCLUDE_DIRS #endif - }; + }; stringstream buffer; JsonSerializationCodeGenerator::Options jsonOptions;