protected override SuppressionsInfo readSuppressions(SuppressionStorage storage, string projectBasePath = null, string projectName = null) { SuppressionsInfo suppressionsInfo = new SuppressionsInfo(); String suppressionsFilePath = suppressionsFilePathByStorage(storage, projectBasePath, projectName); suppressionsInfo.LoadFromFile(suppressionsFilePath); return(suppressionsInfo); }
public override void suppressProblem(Problem p, SuppressionScope scope) { if (p == null) { return; } String simpleFileName = p.FileName; String suppressionLine = null; switch (scope) { case SuppressionScope.suppressAllMessagesThisFileGlobally: case SuppressionScope.suppressAllMessagesThisFileSolutionWide: case SuppressionScope.suppressAllMessagesThisFileProjectWide: suppressionLine = "*:" + simpleFileName; break; case SuppressionScope.suppressThisTypeOfMessageFileWide: suppressionLine = p.MessageId + ":" + simpleFileName; break; case SuppressionScope.suppressThisTypeOfMessagesGlobally: case SuppressionScope.suppressThisTypeOfMessageProjectWide: case SuppressionScope.suppressThisTypeOfMessagesSolutionWide: suppressionLine = p.MessageId; break; case SuppressionScope.suppressThisMessage: case SuppressionScope.suppressThisMessageSolutionWide: case SuppressionScope.suppressThisMessageGlobally: suppressionLine = p.MessageId + ":" + simpleFileName + ":" + p.Line; break; default: throw new InvalidOperationException("Unsupported value: " + scope.ToString()); } String suppressionsFilePath = suppressionsFilePathByScope(scope, p.BaseProjectPath, p.ProjectName); Debug.Assert(suppressionsFilePath != null); SuppressionsInfo suppressionsInfo = new SuppressionsInfo(); suppressionsInfo.LoadFromFile(suppressionsFilePath); suppressionsInfo.AddSuppressionLine(suppressionLine); suppressionsInfo.SaveToFile(suppressionsFilePath); }
private static void CreateDefaultGlobalSuppressions() { String globalsuppressionsFilePath = ICodeAnalyzer.suppressionsFilePathByStorage(ICodeAnalyzer.SuppressionStorage.Global); if (!System.IO.File.Exists(globalsuppressionsFilePath)) { SuppressionsInfo suppressionsInfo = new SuppressionsInfo(); suppressionsInfo.SkippedIncludesMask.Add(".*Microsoft Visual Studio.*"); suppressionsInfo.SkippedIncludesMask.Add(".*Microsoft SDKs.*"); suppressionsInfo.SkippedIncludesMask.Add(".*Windows Kits.*"); suppressionsInfo.SkippedIncludesMask.Add(".*boost.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\ActiveQt.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\Qt$"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtCore.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtDeclarative.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtGui.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtMultimedia.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtNetwork.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtOpenGL.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtOpenVG.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtScript.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtScriptTools.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtSql.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtSvg.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtTest.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtWebKit.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtXml.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtXmlPatterns.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtConcurrent.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtMultimediaWidgets.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtOpenGLExtensions.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtQml.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtQuick.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtSensors.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtWebKitWidgets.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtWidgets.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtZlib.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\include\\QtV8.*"); suppressionsInfo.SkippedIncludesMask.Add(@".*\\mkspecs\\win32-.*"); suppressionsInfo.SkippedFilesMask.Add("^moc_.*\\.cpp$"); suppressionsInfo.SkippedFilesMask.Add("^qrc_.*\\.cpp$"); suppressionsInfo.SkippedFilesMask.Add("^ui_.*\\.h$"); suppressionsInfo.SaveToFile(globalsuppressionsFilePath); } }
public override void analyze(List <SourceFile> filesToAnalyze, OutputWindowPane outputWindow, bool is64bitConfiguration, bool isDebugConfiguration, bool analysisOnSavedFile) { if (filesToAnalyze.Count == 0) { return; } Debug.Assert(_numCores > 0); String cppheckargs = Properties.Settings.Default.DefaultArguments; if (Properties.Settings.Default.SeveritiesString.Length != 0) { cppheckargs += " --enable=" + Properties.Settings.Default.SeveritiesString; } HashSet <string> suppressions = new HashSet <string>(Properties.Settings.Default.SuppressionsString.Split(',')); suppressions.Add("unmatchedSuppression"); HashSet <string> skippedFilesMask = new HashSet <string>(); HashSet <string> skippedIncludeMask = new HashSet <string>(); SuppressionsInfo unitedSuppressionsInfo = readSuppressions(ICodeAnalyzer.SuppressionStorage.Global); unitedSuppressionsInfo.UnionWith(readSuppressions(ICodeAnalyzer.SuppressionStorage.Solution)); // Creating the list of all different project locations (no duplicates) HashSet <string> projectPaths = new HashSet <string>(); // enforce uniqueness on the list of project paths foreach (var file in filesToAnalyze) { projectPaths.Add(file.BaseProjectPath); } Debug.Assert(projectPaths.Count == 1); _projectBasePath = projectPaths.First(); _projectName = filesToAnalyze[0].ProjectName; // Creating the list of all different suppressions (no duplicates) foreach (var path in projectPaths) { unitedSuppressionsInfo.UnionWith(readSuppressions(SuppressionStorage.Project, path, filesToAnalyze[0].ProjectName)); } cppheckargs += (" --relative-paths=\"" + filesToAnalyze[0].BaseProjectPath + "\""); cppheckargs += (" -j " + _numCores.ToString()); if (Properties.Settings.Default.InconclusiveChecksEnabled) { cppheckargs += " --inconclusive "; } suppressions.UnionWith(unitedSuppressionsInfo.SuppressionLines); foreach (string suppression in suppressions) { if (!String.IsNullOrWhiteSpace(suppression)) { cppheckargs += (" --suppress=" + suppression); } } // We only add include paths once, and then specify a set of files to check HashSet <string> includePaths = new HashSet <string>(); foreach (var file in filesToAnalyze) { if (!matchMasksList(file.FilePath, unitedSuppressionsInfo.SkippedFilesMask)) { includePaths.UnionWith(file.IncludePaths); } } includePaths.Add(filesToAnalyze[0].BaseProjectPath); // Fix for #60 foreach (string path in includePaths) { if (!matchMasksList(path, unitedSuppressionsInfo.SkippedIncludesMask)) { String includeArgument = " -I\"" + path + "\""; cppheckargs = cppheckargs + " " + includeArgument; } } foreach (SourceFile file in filesToAnalyze) { if (!matchMasksList(file.FileName, unitedSuppressionsInfo.SkippedFilesMask)) { cppheckargs += " \"" + file.FilePath + "\""; } } if ((analysisOnSavedFile && Properties.Settings.Default.FileOnlyCheckCurrentConfig) || (!analysisOnSavedFile && Properties.Settings.Default.ProjectOnlyCheckCurrentConfig)) // Only checking current macros configuration (for speed) { cppheckargs = cppheckargs.Replace("--force", ""); // Creating the list of all different macros (no duplicates) HashSet <string> macros = new HashSet <string>(); macros.Add("__cplusplus=199711L"); // At least in VS2012, this is still 199711L // Assuming all files passed here are from the same project / same toolset, which should be true, so peeking the first file for global settings switch (filesToAnalyze[0].vcCompilerVersion) { case SourceFile.VCCompilerVersion.vc2003: macros.Add("_MSC_VER=1310"); break; case SourceFile.VCCompilerVersion.vc2005: macros.Add("_MSC_VER=1400"); break; case SourceFile.VCCompilerVersion.vc2008: macros.Add("_MSC_VER=1500"); break; case SourceFile.VCCompilerVersion.vc2010: macros.Add("_MSC_VER=1600"); break; case SourceFile.VCCompilerVersion.vc2012: macros.Add("_MSC_VER=1700"); break; case SourceFile.VCCompilerVersion.vc2013: macros.Add("_MSC_VER=1800"); break; case SourceFile.VCCompilerVersion.vcFuture: macros.Add("_MSC_VER=1900"); break; } foreach (var file in filesToAnalyze) { macros.UnionWith(file.Macros); } macros.Add("WIN32"); macros.Add("_WIN32"); if (is64bitConfiguration) { macros.Add("_M_X64"); macros.Add("_WIN64"); } else { macros.Add("_M_IX86"); } if (isDebugConfiguration) { macros.Add("_DEBUG"); } foreach (string macro in macros) { if (!String.IsNullOrEmpty(macro) && !macro.Contains(" ") /* macros with spaces are invalid in VS */) { String macroArgument = " -D" + macro; cppheckargs += macroArgument; } } HashSet <string> macrosToUndefine = new HashSet <string>(); foreach (var file in filesToAnalyze) { macrosToUndefine.UnionWith(file.MacrosToUndefine); } foreach (string macro in macrosToUndefine) { if (!String.IsNullOrEmpty(macro) && !macro.Contains(" ") /* macros with spaces are invalid in VS */) { String macroUndefArgument = " -U" + macro; cppheckargs += macroUndefArgument; } } } else if (!cppheckargs.Contains("--force")) { cppheckargs += " --force"; } string analyzerPath = Properties.Settings.Default.CPPcheckPath; while (!File.Exists(analyzerPath)) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "cppcheck executable|cppcheck.exe"; if (dialog.ShowDialog() != DialogResult.OK) { return; } analyzerPath = dialog.FileName; } Properties.Settings.Default.CPPcheckPath = analyzerPath; Properties.Settings.Default.Save(); run(analyzerPath, cppheckargs, outputWindow); }
public void UnionWith(SuppressionsInfo suppressionsInfo) { SuppressionLines.UnionWith(suppressionsInfo.SuppressionLines); SkippedFilesMask.UnionWith(suppressionsInfo.SkippedFilesMask); SkippedIncludesMask.UnionWith(suppressionsInfo.SkippedIncludesMask); }
private string getCPPCheckArgs(ConfiguredFiles configuredFiles, bool analysisOnSavedFile, bool multipleProjects, string tempFileName) { Debug.Assert(_numCores > 0); String cppheckargs = Properties.Settings.Default.DefaultArguments; if (Properties.Settings.Default.SeveritiesString.Length != 0) { cppheckargs += " --enable=" + Properties.Settings.Default.SeveritiesString; } HashSet <string> suppressions = new HashSet <string>(Properties.Settings.Default.SuppressionsString.Split(',')); suppressions.Add("unmatchedSuppression"); HashSet <string> skippedFilesMask = new HashSet <string>(); HashSet <string> skippedIncludeMask = new HashSet <string>(); SuppressionsInfo unitedSuppressionsInfo = readSuppressions(ICodeAnalyzer.SuppressionStorage.Global); unitedSuppressionsInfo.UnionWith(readSuppressions(ICodeAnalyzer.SuppressionStorage.Solution)); var filesToAnalyze = configuredFiles.Files; // Creating the list of all different project locations (no duplicates) HashSet <string> projectPaths = new HashSet <string>(); // enforce uniqueness on the list of project paths foreach (var file in filesToAnalyze) { projectPaths.Add(file.BaseProjectPath); } Debug.Assert(projectPaths.Count == 1); _projectBasePath = projectPaths.First(); _projectName = filesToAnalyze[0].ProjectName; // Creating the list of all different suppressions (no duplicates) foreach (var path in projectPaths) { unitedSuppressionsInfo.UnionWith(readSuppressions(SuppressionStorage.Project, path, filesToAnalyze[0].ProjectName)); } if (!multipleProjects) { cppheckargs += (" --relative-paths=\"" + filesToAnalyze[0].BaseProjectPath + "\""); } cppheckargs += (" -j " + _numCores.ToString()); if (Properties.Settings.Default.InconclusiveChecksEnabled) { cppheckargs += " --inconclusive "; } suppressions.UnionWith(unitedSuppressionsInfo.SuppressionLines); foreach (string suppression in suppressions) { if (!String.IsNullOrWhiteSpace(suppression)) { cppheckargs += (" --suppress=" + suppression); } } if (!(analysisOnSavedFile && Properties.Settings.Default.IgnoreIncludePaths)) { // We only add include paths once, and then specify a set of files to check HashSet <string> includePaths = new HashSet <string>(); foreach (var file in filesToAnalyze) { if (!matchMasksList(file.FilePath, unitedSuppressionsInfo.SkippedFilesMask)) { includePaths.UnionWith(file.IncludePaths); } } includePaths.Add(filesToAnalyze[0].BaseProjectPath); // Fix for #60 foreach (string path in includePaths) { if (!matchMasksList(path, unitedSuppressionsInfo.SkippedIncludesMask)) { String includeArgument = " -I\"" + path + "\""; cppheckargs = cppheckargs + " " + includeArgument; } } } using (StreamWriter tempFile = new StreamWriter(tempFileName)) { foreach (SourceFile file in filesToAnalyze) { if (!matchMasksList(file.FileName, unitedSuppressionsInfo.SkippedFilesMask)) { tempFile.WriteLine(file.FilePath); } } } cppheckargs += " --file-list=\"" + tempFileName + "\""; if ((analysisOnSavedFile && Properties.Settings.Default.FileOnlyCheckCurrentConfig) || (!analysisOnSavedFile && Properties.Settings.Default.ProjectOnlyCheckCurrentConfig)) // Only checking current macros configuration (for speed) { cppheckargs = cppheckargs.Replace("--force", ""); // Creating the list of all different macros (no duplicates) HashSet <string> macros = new HashSet <string>(); macros.Add("__cplusplus=199711L"); // At least in VS2012, this is still 199711L // Assuming all files passed here are from the same project / same toolset, which should be true, so peeking the first file for global settings switch (filesToAnalyze[0].vcCompilerVersion) { case SourceFile.VCCompilerVersion.vc2003: macros.Add("_MSC_VER=1310"); break; case SourceFile.VCCompilerVersion.vc2005: macros.Add("_MSC_VER=1400"); break; case SourceFile.VCCompilerVersion.vc2008: macros.Add("_MSC_VER=1500"); break; case SourceFile.VCCompilerVersion.vc2010: macros.Add("_MSC_VER=1600"); break; case SourceFile.VCCompilerVersion.vc2012: macros.Add("_MSC_VER=1700"); break; case SourceFile.VCCompilerVersion.vc2013: macros.Add("_MSC_VER=1800"); break; case SourceFile.VCCompilerVersion.vcFuture: macros.Add("_MSC_VER=1900"); break; } foreach (var file in filesToAnalyze) { macros.UnionWith(file.Macros); } macros.Add("WIN32"); macros.Add("_WIN32"); if (configuredFiles.is64bitConfiguration()) { macros.Add("_M_X64"); macros.Add("_WIN64"); } else { macros.Add("_M_IX86"); } if (configuredFiles.isDebugConfiguration()) { macros.Add("_DEBUG"); } foreach (string macro in macros) { if (!String.IsNullOrEmpty(macro) && !macro.Contains(" ") /* macros with spaces are invalid in VS */) { String macroArgument = " -D" + macro; cppheckargs += macroArgument; } } HashSet <string> macrosToUndefine = new HashSet <string>(); foreach (var file in filesToAnalyze) { macrosToUndefine.UnionWith(file.MacrosToUndefine); } foreach (string macro in macrosToUndefine) { if (!String.IsNullOrEmpty(macro) && !macro.Contains(" ") /* macros with spaces are invalid in VS */) { String macroUndefArgument = " -U" + macro; cppheckargs += macroUndefArgument; } } } else if (!cppheckargs.Contains("--force")) { cppheckargs += " --force"; } return(cppheckargs); }
protected override SuppressionsInfo readSuppressions(SuppressionStorage storage, string projectBasePath = null, string projectName = null) { SuppressionsInfo suppressionsInfo = new SuppressionsInfo(); String suppressionsFilePath = suppressionsFilePathByStorage(storage, projectBasePath, projectName); suppressionsInfo.LoadFromFile(suppressionsFilePath); return suppressionsInfo; }
public override void suppressProblem(Problem p, SuppressionScope scope) { if (p == null) return; String simpleFileName = p.FileName; String suppressionLine = null; switch (scope) { case SuppressionScope.suppressAllMessagesThisFileGlobally: case SuppressionScope.suppressAllMessagesThisFileSolutionWide: case SuppressionScope.suppressAllMessagesThisFileProjectWide: suppressionLine = "*:" + simpleFileName; break; case SuppressionScope.suppressThisTypeOfMessageFileWide: suppressionLine = p.MessageId + ":" + simpleFileName; break; case SuppressionScope.suppressThisTypeOfMessagesGlobally: case SuppressionScope.suppressThisTypeOfMessageProjectWide: case SuppressionScope.suppressThisTypeOfMessagesSolutionWide: suppressionLine = p.MessageId; break; case SuppressionScope.suppressThisMessage: case SuppressionScope.suppressThisMessageSolutionWide: case SuppressionScope.suppressThisMessageGlobally: suppressionLine = p.MessageId + ":" + simpleFileName + ":" + p.Line; break; default: throw new InvalidOperationException("Unsupported value: " + scope.ToString()); } String suppressionsFilePath = suppressionsFilePathByScope(scope, p.BaseProjectPath, p.ProjectName); Debug.Assert(suppressionsFilePath != null); SuppressionsInfo suppressionsInfo = new SuppressionsInfo(); suppressionsInfo.LoadFromFile(suppressionsFilePath); suppressionsInfo.AddSuppressionLine(suppressionLine); suppressionsInfo.SaveToFile(suppressionsFilePath); }