private int GetSeverityAtWhichWarningsBecomeErrors(Cci.ErrorNode/*!*/ error, SpecSharpCompilerOptions/*!*/ options) { int severity = error.Severity; if (severity == 0 || options.TreatWarningsAsErrors) return severity; int errorCode = error.Code; Cci.Int32List severeWarnings = options.SpecificWarningsToTreatAsErrors; for (int i = 0, n = severeWarnings == null ? 0 : severeWarnings.Count; i < n; i++) { if (severeWarnings[i] == errorCode) return severity; } return 0; }
private int GetLevelAtWhichWarningsAreSuppressed(Cci.ErrorNode/*!*/ error, SpecSharpCompilerOptions/*!*/ options) { int severity = error.Severity; int errorCode = error.Code; Cci.Int32List suppressedWarnings = options.SuppressedWarnings; for (int i = 0, n = suppressedWarnings == null ? 0 : suppressedWarnings.Count; i < n; i++) { if (suppressedWarnings[i] == errorCode) return severity; } return options.WarningLevel + 1; }
/// <summary> /// Returns a path to the given document that is relative to the current directory. Returns an absolute path if the path /// to the given document does not share a common prefix with the current directory. /// </summary> private string GetRelativePath(Cci.Document document) { if (document == null) return ""; string relativePath = document.Name; if (relativePath != null) relativePath = relativePath.Trim(); if (relativePath == null || relativePath.Length == 0) return null; string fullPath = Path.GetFullPath(relativePath); //^ assume fullPath != null; string currentDir = Directory.GetCurrentDirectory(); //^ assume currentDir != null && currentDir.Length > 0; //TODO: get the length of the longest common prefix //if this is shorter than currentDir, compute the number of directories to go up //and append ..\ sequences to relative path. //TODO: put this logic in the compiler and just reuse it here. if (fullPath.Length <= currentDir.Length) return fullPath; //TODO: make relative if fullPath and currentDir share a common prefix System.Globalization.CultureInfo invariantCulture = System.Globalization.CultureInfo.InvariantCulture; //^ assume invariantCulture != null; System.Globalization.CompareInfo compInfo = invariantCulture.CompareInfo; //^ assume compInfo != null; if (compInfo.IsPrefix(fullPath, currentDir, System.Globalization.CompareOptions.IgnoreCase)) return fullPath.Substring(currentDir.Length + 1); return relativePath; }
private String GetFullPath(Cci.Document document) { if (document != null && document.Name != null) { string relativePath = document.Name.Trim(); if (relativePath.Length > 0) { string fullPath = Path.GetFullPath(relativePath); if (fullPath != null) { return fullPath; } } } return ""; }
private void LogErrorsAndWarnings(Cci.ErrorNodeList/*!*/ errors, SpecSharpCompilerOptions/*!*/ options) { int errorCount = 0; int warningCount = 0; int prevSev = 0; int n = errors.Count; if (n > 100) n = 100; for (int i = 0; i < n; i++) { Cci.ErrorNode error = errors[i]; if (error != null) { int suppressedWarningSeverity = this.GetLevelAtWhichWarningsAreSuppressed(error, options); int errorSeverity = (options.TreatWarningsAsErrors ? suppressedWarningSeverity - 1 : this.GetSeverityAtWhichWarningsBecomeErrors(error, options)); int severity = error.Severity; if (severity < 0) severity = prevSev; else prevSev = severity; bool isWarning = severity > errorSeverity; bool isSpecSharpSpecific = error.Code >= 2500 && error.Code < 3000; if (!isWarning || severity < suppressedWarningSeverity) { LogTaskError("CS", error.Code, null, this.GetRelativePath(error.SourceContext.Document), this.GetFullPath(error.SourceContext.Document), error.SourceContext.StartLine, error.SourceContext.StartColumn, error.SourceContext.EndLine, error.SourceContext.EndColumn, error.GetMessage(CultureInfo.CurrentCulture), isWarning, isSpecSharpSpecific ); } if (isWarning) warningCount++; else errorCount++; } } LogMessage("Compile complete -- " + errorCount.ToString() + " errors, " + warningCount.ToString() + " warnings\n" ); }
public ArrayIndexable(Cci.BlockList blocks) { this.members = new CfgBlock[blocks.Count]; for (int i=0; i<blocks.Count; i++) { this.members[i] = (CfgBlock)blocks[i]; } }
public ArrayIndexable(Cci.StatementList stmts) { this.members = new Cci.Statement[stmts.Count]; for (int i=0; i<stmts.Count; i++) { this.members[i] = stmts[i]; } }