bool ClazyASTAction::ParseArgs()

in src/Clazy.cpp [216:290]


bool ClazyASTAction::ParseArgs(const CompilerInstance &ci, const std::vector<std::string> &args_)
{
    // NOTE: This method needs to be kept reentrant (but not necessarily thread-safe)
    // Might be called from multiple threads via libclang, each thread operates on a different instance though

    std::vector<std::string> args = args_;

    const std::string headerFilter = getEnvVariable("CLAZY_HEADER_FILTER");
    const std::string ignoreDirs = getEnvVariable("CLAZY_IGNORE_DIRS");
    std::string exportFixesFilename;

    if (parseArgument("help", args)) {
        m_context = new ClazyContext(ci, headerFilter, ignoreDirs, exportFixesFilename, {}, ClazyContext::ClazyOption_None);
        PrintHelp(llvm::errs());
        return true;
    }

    if (parseArgument("export-fixes", args) || getenv("CLAZY_EXPORT_FIXES")) {
        m_options |= ClazyContext::ClazyOption_ExportFixes;
    }

    if (parseArgument("only-qt", args)) {
        m_options |= ClazyContext::ClazyOption_OnlyQt;
    }

    if (parseArgument("qt-developer", args)) {
        m_options |= ClazyContext::ClazyOption_QtDeveloper;
    }

    if (parseArgument("visit-implicit-code", args)) {
        m_options |= ClazyContext::ClazyOption_VisitImplicitCode;
    }

    if (parseArgument("ignore-included-files", args)) {
        m_options |= ClazyContext::ClazyOption_IgnoreIncludedFiles;
    }

    if (parseArgument("export-fixes", args)) {
        exportFixesFilename = args.at(0);
    }

    m_context = new ClazyContext(ci, headerFilter, ignoreDirs, exportFixesFilename, {}, m_options);

    // This argument is for debugging purposes
    const bool dbgPrintRequestedChecks = parseArgument("print-requested-checks", args);

    {
        std::lock_guard<std::mutex> lock(CheckManager::lock());
        m_checks = m_checkManager->requestedChecks(args);
    }

    if (args.size() > 1) {
        // Too many arguments.
        llvm::errs() << "Too many arguments: ";
        for (const std::string &a : args) {
            llvm::errs() << a << ' ';
        }
        llvm::errs() << "\n";

        PrintHelp(llvm::errs());
        return false;
    }
    if (args.size() == 1 && m_checks.empty()) {
        // Checks were specified but couldn't be found
        llvm::errs() << "Could not find checks in comma separated string " + args[0] + "\n";
        PrintHelp(llvm::errs());
        return false;
    }

    if (dbgPrintRequestedChecks) {
        printRequestedChecks();
    }

    return true;
}