Changeset View
Changeset View
Standalone View
Standalone View
src/Clazy.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Line(s) | 133 | { | |||
---|---|---|---|---|---|
164 | } | 164 | } | ||
165 | 165 | | |||
166 | return true; | 166 | return true; | ||
167 | } | 167 | } | ||
168 | 168 | | |||
169 | void ClazyASTConsumer::HandleTranslationUnit(ASTContext &ctx) | 169 | void ClazyASTConsumer::HandleTranslationUnit(ASTContext &ctx) | ||
170 | { | 170 | { | ||
171 | // FIXME: EndSourceFile() is called automatically, but not BeginsSourceFile() | 171 | // FIXME: EndSourceFile() is called automatically, but not BeginsSourceFile() | ||
172 | if (m_context->exporter) | ||||
172 | m_context->exporter->BeginSourceFile(clang::LangOptions()); | 173 | m_context->exporter->BeginSourceFile(clang::LangOptions()); | ||
173 | 174 | | |||
174 | if ((m_context->options & ClazyContext::ClazyOption_OnlyQt) && !m_context->isQt()) | 175 | if ((m_context->options & ClazyContext::ClazyOption_OnlyQt) && !m_context->isQt()) | ||
175 | return; | 176 | return; | ||
176 | 177 | | |||
177 | // Run our RecursiveAstVisitor based checks: | 178 | // Run our RecursiveAstVisitor based checks: | ||
178 | TraverseDecl(ctx.getTranslationUnitDecl()); | 179 | TraverseDecl(ctx.getTranslationUnitDecl()); | ||
179 | 180 | | |||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
228 | { | 229 | { | ||
229 | // NOTE: This method needs to be kept reentrant (but not necessarily thread-safe) | 230 | // NOTE: This method needs to be kept reentrant (but not necessarily thread-safe) | ||
230 | // Might be called from multiple threads via libclang, each thread operates on a different instance though | 231 | // Might be called from multiple threads via libclang, each thread operates on a different instance though | ||
231 | 232 | | |||
232 | std::vector<std::string> args = args_; | 233 | std::vector<std::string> args = args_; | ||
233 | 234 | | |||
234 | const string headerFilter = getEnvVariable("CLAZY_HEADER_FILTER"); | 235 | const string headerFilter = getEnvVariable("CLAZY_HEADER_FILTER"); | ||
235 | const string ignoreDirs = getEnvVariable("CLAZY_IGNORE_DIRS"); | 236 | const string ignoreDirs = getEnvVariable("CLAZY_IGNORE_DIRS"); | ||
237 | std::string exportFixes; | ||||
236 | 238 | | |||
237 | if (parseArgument("help", args)) { | 239 | if (parseArgument("help", args)) { | ||
238 | m_context = new ClazyContext(ci, headerFilter, ignoreDirs, ClazyContext::ClazyOption_None); | 240 | m_context = new ClazyContext(ci, headerFilter, ignoreDirs, exportFixes, ClazyContext::ClazyOption_None); | ||
239 | PrintHelp(llvm::errs()); | 241 | PrintHelp(llvm::errs()); | ||
240 | return true; | 242 | return true; | ||
241 | } | 243 | } | ||
242 | 244 | | |||
243 | if (parseArgument("no-inplace-fixits", args)) { | 245 | if (parseArgument("no-inplace-fixits", args)) { | ||
244 | // Unit-tests don't use inplace fixits | 246 | // Unit-tests don't use inplace fixits | ||
245 | m_options |= ClazyContext::ClazyOption_NoFixitsInplace; | 247 | m_options |= ClazyContext::ClazyOption_NoFixitsInplace; | ||
246 | } | 248 | } | ||
Show All 16 Lines | 264 | if (parseArgument("qt-developer", args)) | |||
263 | m_options |= ClazyContext::ClazyOption_QtDeveloper; | 265 | m_options |= ClazyContext::ClazyOption_QtDeveloper; | ||
264 | 266 | | |||
265 | if (parseArgument("visit-implicit-code", args)) | 267 | if (parseArgument("visit-implicit-code", args)) | ||
266 | m_options |= ClazyContext::ClazyOption_VisitImplicitCode; | 268 | m_options |= ClazyContext::ClazyOption_VisitImplicitCode; | ||
267 | 269 | | |||
268 | if (parseArgument("ignore-included-files", args)) | 270 | if (parseArgument("ignore-included-files", args)) | ||
269 | m_options |= ClazyContext::ClazyOption_IgnoreIncludedFiles; | 271 | m_options |= ClazyContext::ClazyOption_IgnoreIncludedFiles; | ||
270 | 272 | | |||
271 | m_context = new ClazyContext(ci, headerFilter, ignoreDirs, m_options); | 273 | if (parseArgument("export-fixes", args)) | ||
274 | exportFixes = args.at(0); | ||||
275 | | ||||
276 | m_context = new ClazyContext(ci, headerFilter, ignoreDirs, exportFixes, m_options); | ||||
272 | 277 | | |||
273 | // This argument is for debugging purposes | 278 | // This argument is for debugging purposes | ||
274 | const bool dbgPrintRequestedChecks = parseArgument("print-requested-checks", args); | 279 | const bool dbgPrintRequestedChecks = parseArgument("print-requested-checks", args); | ||
275 | 280 | | |||
276 | { | 281 | { | ||
277 | std::lock_guard<std::mutex> lock(CheckManager::lock()); | 282 | std::lock_guard<std::mutex> lock(CheckManager::lock()); | ||
278 | m_checks = m_checkManager->requestedChecks(m_context, args); | 283 | m_checks = m_checkManager->requestedChecks(m_context, args); | ||
279 | } | 284 | } | ||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | 324 | { | |||
368 | ros << "or pass as compiler arguments, for example:\n"; | 373 | ros << "or pass as compiler arguments, for example:\n"; | ||
369 | ros << " -Xclang -plugin-arg-clazy -Xclang reserve-candidates,qstring-allocations\n"; | 374 | ros << " -Xclang -plugin-arg-clazy -Xclang reserve-candidates,qstring-allocations\n"; | ||
370 | ros << "\n"; | 375 | ros << "\n"; | ||
371 | ros << "To enable FixIts for a check, also set the env variable CLAZY_FIXIT, for example:\n"; | 376 | ros << "To enable FixIts for a check, also set the env variable CLAZY_FIXIT, for example:\n"; | ||
372 | ros << " export CLAZY_FIXIT=\"fix-qlatin1string-allocations\"\n\n"; | 377 | ros << " export CLAZY_FIXIT=\"fix-qlatin1string-allocations\"\n\n"; | ||
373 | ros << "FixIts are experimental and rewrite your code therefore only one FixIt is allowed per build.\nSpecifying a list of different FixIts is not supported.\nBackup your code before running them.\n"; | 378 | ros << "FixIts are experimental and rewrite your code therefore only one FixIt is allowed per build.\nSpecifying a list of different FixIts is not supported.\nBackup your code before running them.\n"; | ||
374 | } | 379 | } | ||
375 | 380 | | |||
376 | ClazyStandaloneASTAction::ClazyStandaloneASTAction(const string &checkList, const string &headerFilter, const string &ignoreDirs, | 381 | ClazyStandaloneASTAction::ClazyStandaloneASTAction(const string &checkList, const string &headerFilter, const string &ignoreDirs, const string &exportFixes, | ||
377 | ClazyContext::ClazyOptions options) | 382 | ClazyContext::ClazyOptions options) | ||
378 | : clang::ASTFrontendAction() | 383 | : clang::ASTFrontendAction() | ||
379 | , m_checkList(checkList.empty() ? "level1" : checkList) | 384 | , m_checkList(checkList.empty() ? "level1" : checkList) | ||
380 | , m_headerFilter(headerFilter.empty() ? getEnvVariable("CLAZY_HEADER_FILTER") : headerFilter) | 385 | , m_headerFilter(headerFilter.empty() ? getEnvVariable("CLAZY_HEADER_FILTER") : headerFilter) | ||
381 | , m_ignoreDirs(ignoreDirs.empty() ? getEnvVariable("CLAZY_IGNORE_DIRS") : ignoreDirs) | 386 | , m_ignoreDirs(ignoreDirs.empty() ? getEnvVariable("CLAZY_IGNORE_DIRS") : ignoreDirs) | ||
387 | , m_exportFixes(exportFixes) | ||||
382 | , m_options(options) | 388 | , m_options(options) | ||
383 | { | 389 | { | ||
384 | } | 390 | } | ||
385 | 391 | | |||
386 | unique_ptr<ASTConsumer> ClazyStandaloneASTAction::CreateASTConsumer(CompilerInstance &ci, llvm::StringRef) | 392 | unique_ptr<ASTConsumer> ClazyStandaloneASTAction::CreateASTConsumer(CompilerInstance &ci, llvm::StringRef) | ||
387 | { | 393 | { | ||
388 | auto context = new ClazyContext(ci, m_headerFilter, m_ignoreDirs, m_options); | 394 | auto context = new ClazyContext(ci, m_headerFilter, m_ignoreDirs, m_exportFixes, m_options); | ||
389 | auto astConsumer = new ClazyASTConsumer(context); | 395 | auto astConsumer = new ClazyASTConsumer(context); | ||
390 | 396 | | |||
391 | auto cm = CheckManager::instance(); | 397 | auto cm = CheckManager::instance(); | ||
392 | 398 | | |||
393 | vector<string> checks; checks.push_back(m_checkList); | 399 | vector<string> checks; checks.push_back(m_checkList); | ||
394 | const RegisteredCheck::List requestedChecks = cm->requestedChecks(context, checks); | 400 | const RegisteredCheck::List requestedChecks = cm->requestedChecks(context, checks); | ||
395 | 401 | | |||
396 | if (requestedChecks.size() == 0) { | 402 | if (requestedChecks.size() == 0) { | ||
Show All 16 Lines |