private void AnalyzeCurrentFile() { ts.TraceInformation("AnalyzeCurrentFile"); try { VCFile vcFile = DTE2Utils.GetVcCppFile(_applicationObject.ActiveDocument); if (vcFile == null) { return; } VCConfiguration vcConfiguration = DTE2Utils.GetVcConfigurationForDocument(_applicationObject.ActiveDocument, vcFile.project); if (vcConfiguration == null) { return; } ClangAnalyzer.AnalyzeFile(_applicationObject.Solution, vcFile, vcConfiguration); } catch (Exception exception) { ts.TraceData(TraceEventType.Error, 1, "AnalyzeFile exception: " + exception.Message); MessageBox.Show(exception.Message, _addInName + " System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private String GetProcessArgument(VCFile vcFile, VCConfiguration vcConfiguration) { VCFileConfiguration vcFileConfiguration = DTE2Utils.GetVcFileConfiguration(vcFile, vcConfiguration); if (vcFileConfiguration == null) { ts.TraceData(TraceEventType.Error, 1, "GetProcessArgument cannot get VcFileConfiguration "); return(""); } StringBuilder stringBuilder = new StringBuilder(); //stringBuilder.Append(" -Xclang -analyzer-display-progress "); stringBuilder.Append(" --analyze "); //stringBuilder.Append(" -o " + GetReportFile() + " "); if (!vcFile.Name.EndsWith(".c")) { stringBuilder.Append(" -x c++ "); } stringBuilder.Append(DTE2Utils.GetIncludesForProject(vcConfiguration)); stringBuilder.Append(DTE2Utils.GetDefinesForProject(vcConfiguration)); stringBuilder.Append(DTE2Utils.GetIncludesForFile(vcFileConfiguration)); stringBuilder.Append(DTE2Utils.GetDefinesForFile(vcFileConfiguration)); stringBuilder.Append(GetArgumentMicrosoftCompilerSpecific()); stringBuilder.Append(" -pedantic "); stringBuilder.Append(" -ferror-limit=0 "); stringBuilder.Append("\"" + vcFile.FullPath + "\""); return(stringBuilder.ToString()); }
private void DoAnalyzeProject(VCProject vcProject) { ts.TraceInformation("DoAnalyzeProject " + vcProject.Name); ts.TraceInformation("DoAnalyzeProject #files " + _report.SolutionCurrent.ProjectCurrent.Files.Count); OutputPaneWriteln("Analyzing project " + vcProject.Name + " " + _report.SolutionCurrent.ProjectCurrent.Files.Count + " files to analyze"); OnStartProject(); ts.TraceInformation("DoAnalyzeProject " + vcProject.Name + " getting vc conf"); _vcConfiguration = DTE2Utils.GetVcConfiguratioForVcProject(vcProject); if (_vcConfiguration == null) { ts.TraceInformation("DoAnalyzeProject cannot get c++ project configuration" + vcProject.Name); OnStopProject(true); return; } ts.TraceInformation("DoAnalyzeProject " + vcProject.Name + " create file queue"); _vcProject = vcProject; _vcFileQueue = DTE2Utils.CreateFileQueue(vcProject); ts.TraceInformation("DoAnalyzeProject " + vcProject.Name + " file queue created"); if (_vcFileQueue.Count == 0) { ts.TraceInformation("DoAnalyzeProject no c++ file in project " + vcProject.Name); OnStopProject(false); return; } AnalyseNextFile(); }
public static bool HasVcStartupProject(Solution solution) { VCProject vcProject = DTE2Utils.GetVcProjectStartup(solution); if (vcProject == null) { //ts.TraceInformation("HasVcStartupProject: cannot get startup vc project from solution"); return(false); } else { return(true); } }
private void UpdateRecord(string line) { Match match = RegExFileLineColumnMessage.Match(line); string file; string lineNumber; string columnNumber; string type; string message; ts.TraceData(TraceEventType.Verbose, 1, "UpdateRecord match count " + match.Groups.Count); if (match.Groups.Count == 6) { file = match.Groups[1].Value; // we simply ignore errors and warnings from system includes if (DTE2Utils.IsSystemInclude(file)) { return; } lineNumber = match.Groups[2].Value; columnNumber = match.Groups[3].Value; type = match.Groups[4].Value; message = match.Groups[5].Value; Reporting.Violation violation = _report.CreateViolation(); violation.FilePath = file; violation.LineNumber = lineNumber; violation.ColumnNumber = columnNumber; if (type == "warning") { violation.Severity = Reporting.Violation.ESeverity.WARNING; } else { violation.Severity = Reporting.Violation.ESeverity.ERROR; } violation.Message = message; violation.FullMessage = line; if (_report.AddViolation(violation)) { DelegateViolation(violation); } else { ts.TraceData(TraceEventType.Verbose, 1, "UpdateRecord already added"); } } }
public void AnalyzeSolution(Solution solution) { try { _solution = solution; ts.TraceInformation("AnalyzeSolution " + solution.FullName); OnStartAnalyze(); OnStartSolution(); OutputPaneWriteln("Analyzing solution " + solution.FullName); Projects projects = solution.Projects; if ((projects == null) || (projects.Count == 0)) { ts.TraceInformation("No projects in solution"); OnStopAnalyze(true); return; } ts.TraceInformation("AnalyzeSolution #projects " + projects.Count); _vcProjectQueue = DTE2Utils.CreateVCProjectQueue(solution); _report = Reporting.ReportFactory.CreateReportFromVsSolution(solution, _vcProjectQueue); OutputPaneWriteln("Analyzing solution " + solution.FullName + ", " + _report.SolutionCurrent.NumberOfProject + " projects" + ", " + _report.SolutionCurrent.NumberOfFiles + " files"); ts.TraceInformation("AnalyzeSolution " + _vcProjectQueue.Count + " c++ projects " + " in " + _report.SolutionCurrent.NumberOfFiles + " files"); if (_vcProjectQueue.Count == 0) { ts.TraceInformation("AnalyzeSolution no c++ project found " + solution.Projects.Count); OnStopAnalyze(true); } _analyzeType = AnalyzeType.SOLUTION; AnalyseNextProject(); } catch (Exception exception) { ts.TraceData(TraceEventType.Error, 1, "AnalyzeSolution exception: " + exception.Message); OnStopSolution(true); } }
static public Queue <VCFile> CreateFileQueue(VCProject vcProject) { ts.TraceInformation("CreateFileQueue"); Queue <VCFile> fileQueue = new Queue <VCFile>(); var vcFileCollection = (IVCCollection)vcProject.Files; if (vcFileCollection == null) { ts.TraceData(TraceEventType.Verbose, 1, "CreateFileList cannot get vc file collection"); return(null); } ts.TraceInformation("CreateFileQueue #vcFileCollection " + vcFileCollection.Count); foreach (VCFile vcFile in vcFileCollection) { try { VCFileConfiguration vcFileConfiguration = DTE2Utils.GetVcFileConfiguration( vcFile, DTE2Utils.GetVcConfiguratioForVcProject(vcProject)); if (vcFileConfiguration != null) { if ((vcFileConfiguration.ExcludedFromBuild == false) && (vcFile.FileType == eFileType.eFileTypeCppCode)) { ts.TraceData(TraceEventType.Verbose, 1, "CreateFileList add " + vcFile.FullPath); fileQueue.Enqueue(vcFile); } else { ts.TraceData(TraceEventType.Verbose, 1, "CreateFileList exclude " + vcFile.FullPath); } } } catch (Exception exception) { ts.TraceData(TraceEventType.Verbose, 1, "CreateFileList exception " + exception.Message); } } ts.TraceInformation("CreateFileList project " + vcProject.Name + " #files " + fileQueue.Count); return(fileQueue); }
private void AnalyzeProjectStartup() { ts.TraceInformation("AnalyzeProjectStartup"); try { Solution solution = _applicationObject.Solution; VCProject vcProject = DTE2Utils.GetVcProjectStartup(solution); if (vcProject == null) { ts.TraceInformation("AnalyzeProjectStartup cannot get startup vc project from solution"); return; } ClangAnalyzer.AnalyzeProject(solution, vcProject); } catch (Exception exception) { ts.TraceData(TraceEventType.Error, 1, "AnalyzeProjectStartup exception: " + exception.Message); MessageBox.Show(exception.Message, _addInName + " System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary>Implements the QueryStatus method of the IDTCommandTarget interface. This is called when the command's availability is updated</summary> /// <param term='commandName'>The name of the command to determine state for.</param> /// <param term='neededText'>Text that is needed for the command.</param> /// <param term='status'>The state of the command in the user interface.</param> /// <param term='commandText'>Text requested by the neededText parameter.</param> /// <seealso class='Exec' /> public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText) { ts.TraceData(TraceEventType.Verbose, 1, "QueryStatus " + commandName); if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone) { if (commandName.StartsWith(CommandPrefix)) { status = vsCommandStatus.vsCommandStatusSupported; if (commandName.EndsWith(COMMAND_ANALYSE_CURRENT_FILE_NAME)) { ts.TraceData(TraceEventType.Verbose, 1, "QueryStatus " + COMMAND_ANALYSE_CURRENT_FILE_NAME + " " + _analyzing); if (ClangAnalyzer.State == ClangAnalyzer.AnalyzeState.RUNNING) { status |= vsCommandStatus.vsCommandStatusInvisible; } else if (DTE2Utils.HasVcCppFileActive(_applicationObject.ActiveDocument)) { status |= vsCommandStatus.vsCommandStatusEnabled; } } if (commandName.EndsWith(COMMAND_ANALYSE_PROJECT_NAME)) { ts.TraceData(TraceEventType.Verbose, 1, "QueryStatus " + COMMAND_ANALYSE_PROJECT_NAME + " " + _analyzing); if (ClangAnalyzer.State == ClangAnalyzer.AnalyzeState.RUNNING) { status |= vsCommandStatus.vsCommandStatusInvisible; } else if (DTE2Utils.IsVcProjectSelected(_applicationObject)) { status |= vsCommandStatus.vsCommandStatusEnabled; } } if (commandName.EndsWith(COMMAND_ANALYSE_PROJECT_STARTUP_NAME)) { ts.TraceData(TraceEventType.Verbose, 1, "QueryStatus " + COMMAND_ANALYSE_PROJECT_STARTUP_NAME + " " + _analyzing); if (ClangAnalyzer.State == ClangAnalyzer.AnalyzeState.RUNNING) { status |= vsCommandStatus.vsCommandStatusInvisible; } else if (DTE2Utils.HasVcStartupProject(_applicationObject.Solution)) { status |= vsCommandStatus.vsCommandStatusEnabled; } } if (commandName.EndsWith(COMMAND_ANALYSE_SOLUTION_NAME)) { ts.TraceData(TraceEventType.Verbose, 1, "QueryStatus " + COMMAND_ANALYSE_SOLUTION_NAME + " " + _analyzing); if (ClangAnalyzer.State == ClangAnalyzer.AnalyzeState.RUNNING) { status |= vsCommandStatus.vsCommandStatusInvisible; } else if (DTE2Utils.HasVcProjectsInSolution(_applicationObject.Solution)) { status |= vsCommandStatus.vsCommandStatusEnabled; } } if (commandName.EndsWith(COMMAND_STOP_NAME)) { ts.TraceData(TraceEventType.Verbose, 1, "QueryStatus " + COMMAND_STOP_NAME); if (ClangAnalyzer.State == ClangAnalyzer.AnalyzeState.RUNNING) { status |= vsCommandStatus.vsCommandStatusEnabled; } else { status |= vsCommandStatus.vsCommandStatusInvisible; } } if (commandName.EndsWith(COMMAND_SETTINGS_NAME)) { ts.TraceData(TraceEventType.Verbose, 1, "QueryStatus " + COMMAND_SETTINGS_NAME + " "); status |= vsCommandStatus.vsCommandStatusEnabled; } if (commandName.EndsWith(COMMAND_OPENLOG_NAME)) { ts.TraceData(TraceEventType.Verbose, 1, "QueryStatus " + COMMAND_OPENLOG_NAME + " On"); status |= vsCommandStatus.vsCommandStatusEnabled; } if (commandName.EndsWith(COMMAND_ABOUT_NAME)) { ts.TraceData(TraceEventType.Verbose, 1, "QueryStatus " + COMMAND_ABOUT_NAME + " On"); status |= vsCommandStatus.vsCommandStatusEnabled; } } } }