internal DiagnosticWithInfo(DiagnosticInfo info, Location location) { Debug.Assert(info != null); Debug.Assert(location != null); _info = info; _location = location; }
protected GreenNode(ushort kind, DiagnosticInfo[] diagnostics) { _kind = kind; if (diagnostics?.Length > 0) { this.flags |= NodeFlags.ContainsDiagnostics; s_diagnosticsTable.Add(this, diagnostics); } }
private DiagnosticInfo(DiagnosticInfo original, DiagnosticSeverity overridenSeverity) { _messageProvider = original.MessageProvider; _errorCode = original._errorCode; _defaultSeverity = original.DefaultSeverity; _arguments = original._arguments; _effectiveSeverity = overridenSeverity; }
public static ImmutableArray<TypeWithModifiers> CreateTypeArguments(ImmutableArray<TypeParameterSymbol> typeParameters, int n, DiagnosticInfo errorInfo) { var result = ArrayBuilder<TypeWithModifiers>.GetInstance(); for (int i = 0; i < n; i++) { string name = (i < typeParameters.Length) ? typeParameters[i].Name : string.Empty; result.Add(new TypeWithModifiers(new UnboundArgumentErrorTypeSymbol(name, errorInfo))); } return result.ToImmutableAndFree(); }
protected GreenNode(ushort kind, DiagnosticInfo[] diagnostics, SyntaxAnnotation[] annotations) : this(kind, diagnostics) { if (annotations?.Length > 0) { foreach (var annotation in annotations) { if (annotation == null) throw new ArgumentException(paramName: nameof(annotations), message: "" /*CSharpResources.ElementsCannotBeNull*/); } this.flags |= NodeFlags.ContainsAnnotations; s_annotationsTable.Add(this, annotations); } }
private bool TryDeleteFile(string filePath, TextWriter consoleOutput) { try { if (File.Exists(filePath)) { FileDelete(filePath); } return true; } catch (Exception e) { // Treat all possible exceptions uniformly, so we report // "Could not write to output file"/"can't open '***' for writing" // for all as in the native CS/VB compiler. if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_OutputWriteFailed, filePath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return false; } }
/// <summary> /// Produces the filtering action for the diagnostic based on the options passed in. /// </summary> /// <returns> /// A new <see cref="DiagnosticInfo"/> with new effective severity based on the options or null if the /// diagnostic has been suppressed. /// </returns> public abstract ReportDiagnostic GetDiagnosticReport(DiagnosticInfo diagnosticInfo, CompilationOptions options);
/// <summary> /// csc.exe and vbc.exe entry point. /// </summary> public virtual int Run(TextWriter consoleOutput, CancellationToken cancellationToken = default(CancellationToken)) { var saveUICulture = CultureInfo.CurrentUICulture; ErrorLogger errorLogger = null; try { // Messages from exceptions can be used as arguments for errors and they are often localized. // Ensure they are localized to the right language. var culture = this.Culture; if (culture != null) { PortableShim.Misc.SetCurrentUICulture(culture); } if (Arguments.ErrorLogPath != null) { errorLogger = GetErrorLogger(consoleOutput, cancellationToken); if (errorLogger == null) { return Failed; } } return RunCore(consoleOutput, errorLogger, cancellationToken); } catch (OperationCanceledException) { var errorCode = MessageProvider.ERR_CompileCancelled; if (errorCode > 0) { var diag = new DiagnosticInfo(MessageProvider, errorCode); ReportErrors(new[] { diag }, consoleOutput, errorLogger); } return Failed; } finally { PortableShim.Misc.SetCurrentUICulture(saveUICulture); errorLogger?.Dispose(); } }
internal static DiagnosticInfo ToFileReadDiagnostics(CommonMessageProvider messageProvider, Exception e, string filePath) { DiagnosticInfo diagnosticInfo; if (e is FileNotFoundException || e.GetType().Name == "DirectoryNotFoundException") { diagnosticInfo = new DiagnosticInfo(messageProvider, messageProvider.ERR_FileNotFound, filePath); } else if (e is InvalidDataException) { diagnosticInfo = new DiagnosticInfo(messageProvider, messageProvider.ERR_BinaryFile, filePath); } else { diagnosticInfo = new DiagnosticInfo(messageProvider, messageProvider.ERR_NoSourceFile, filePath, e.Message); } return diagnosticInfo; }
internal static Diagnostic Create(DiagnosticInfo info) { return(new DiagnosticWithInfo(info, Location.None)); }
protected DiagnosticWithInfo(SerializationInfo info, StreamingContext context) { this.info = (DiagnosticInfo)info.GetValue("info", typeof(DiagnosticInfo)); this.location = (Location)info.GetValue("location", typeof(Location)); }
private DiagnosticInfo ToFileReadDiagnostics(Exception e, CommandLineSourceFile file) { DiagnosticInfo diagnosticInfo; if (e is FileNotFoundException || e.GetType().Name == "DirectoryNotFoundException") { diagnosticInfo = new DiagnosticInfo(MessageProvider, MessageProvider.ERR_FileNotFound, file.Path); } else if (e is InvalidDataException) { diagnosticInfo = new DiagnosticInfo(MessageProvider, MessageProvider.ERR_BinaryFile, file.Path); } else { diagnosticInfo = new DiagnosticInfo(MessageProvider, MessageProvider.ERR_NoSourceFile, file.Path, e.Message); } return diagnosticInfo; }
internal abstract GreenNode SetDiagnostics(DiagnosticInfo[] diagnostics);
// Only the compiler creates instances. internal DiagnosticInfoWithOverridenSeverity(DiagnosticInfo original, DiagnosticSeverity overriddenSeverity) : base(original.messageProvider, original.isWarningAsError, original.errorCode, original.Arguments) { this.overriddenSeverity = overriddenSeverity; }
private ImmutableArray<TypeParameterSymbol> LoadTypeParameters(ref DiagnosticInfo diagnosticInfo) { try { var moduleSymbol = _containingType.ContainingPEModule; var gpHandles = moduleSymbol.Module.GetGenericParametersForMethodOrThrow(_handle); if (gpHandles.Count == 0) { return ImmutableArray<TypeParameterSymbol>.Empty; } else { var ownedParams = ImmutableArray.CreateBuilder<TypeParameterSymbol>(gpHandles.Count); for (int i = 0; i < gpHandles.Count; i++) { ownedParams.Add(new PETypeParameterSymbol(moduleSymbol, this, (ushort)i, gpHandles[i])); } return ownedParams.ToImmutable(); } } catch (BadImageFormatException) { //diagnosticInfo = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this); // TODO: ErrorCode return ImmutableArray<TypeParameterSymbol>.Empty; } }
private ImmutableArray<TypeParameterSymbol> EnsureTypeParametersAreLoaded(ref DiagnosticInfo diagnosticInfo) { var typeParams = _lazyTypeParameters; if (!typeParams.IsDefault) { return typeParams; } return InterlockedOperations.Initialize(ref _lazyTypeParameters, LoadTypeParameters(ref diagnosticInfo)); }
/// <summary> /// Create a simple language specific diagnostic with no location for given info. /// </summary> public abstract Diagnostic CreateDiagnostic(DiagnosticInfo info);
internal void ResolveAnalyzersFromArguments( string language, List <DiagnosticInfo> diagnostics, CommonMessageProvider messageProvider, IAnalyzerAssemblyLoader analyzerLoader, bool skipAnalyzers, out ImmutableArray <DiagnosticAnalyzer> analyzers, out ImmutableArray <ISourceGenerator> generators) { var analyzerBuilder = ImmutableArray.CreateBuilder <DiagnosticAnalyzer>(); var generatorBuilder = ImmutableArray.CreateBuilder <ISourceGenerator>(); EventHandler <AnalyzerLoadFailureEventArgs> errorHandler = (o, e) => { var analyzerReference = o as AnalyzerFileReference; RoslynDebug.Assert(analyzerReference is object); DiagnosticInfo?diagnostic; switch (e.ErrorCode) { case AnalyzerLoadFailureEventArgs.FailureErrorCode.UnableToLoadAnalyzer: diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_UnableToLoadAnalyzer, analyzerReference.FullPath, e.Message); break; case AnalyzerLoadFailureEventArgs.FailureErrorCode.UnableToCreateAnalyzer: diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_AnalyzerCannotBeCreated, e.TypeName ?? "", analyzerReference.FullPath, e.Message); break; case AnalyzerLoadFailureEventArgs.FailureErrorCode.NoAnalyzers: diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_NoAnalyzerInAssembly, analyzerReference.FullPath); break; case AnalyzerLoadFailureEventArgs.FailureErrorCode.None: default: return; } // Filter this diagnostic based on the compilation options so that /nowarn and /warnaserror etc. take effect. diagnostic = messageProvider.FilterDiagnosticInfo(diagnostic, this.CompilationOptions); if (diagnostic != null) { diagnostics.Add(diagnostic); } }; var resolvedReferences = ArrayBuilder <AnalyzerFileReference> .GetInstance(); foreach (var reference in AnalyzerReferences) { var resolvedReference = ResolveAnalyzerReference(reference, analyzerLoader); if (resolvedReference != null) { resolvedReferences.Add(resolvedReference); // register the reference to the analyzer loader: analyzerLoader.AddDependencyLocation(resolvedReference.FullPath); } else { diagnostics.Add(new DiagnosticInfo(messageProvider, messageProvider.ERR_MetadataFileNotFound, reference.FilePath)); } } // All analyzer references are registered now, we can start loading them: foreach (var resolvedReference in resolvedReferences) { resolvedReference.AnalyzerLoadFailed += errorHandler; if (!skipAnalyzers) { resolvedReference.AddAnalyzers(analyzerBuilder, language); } resolvedReference.AddGenerators(generatorBuilder, language); resolvedReference.AnalyzerLoadFailed -= errorHandler; } resolvedReferences.Free(); generators = generatorBuilder.ToImmutable(); analyzers = analyzerBuilder.ToImmutable(); }
private bool TryMoveFile(string sourcePath, string destinationPath, TextWriter consoleOutput) { try { FileMove(sourcePath, destinationPath); return true; } catch (Exception e) { // There can be various exceptions caught here including: // - DirectoryNotFoundException when a given path is not found // - IOException when a device like a:\ is not ready // - UnauthorizedAccessException when a given path is not accessible // - NotSupportedException when a given path is in an invalid format // // Treat them uniformly, so we report "Cannot open 'filename' for writing" for all as in the native VB compiler. if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_CantOpenFileWrite, destinationPath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return false; } }
public override Diagnostic CreateDiagnostic(DiagnosticInfo info) { throw new NotImplementedException(); }
internal ImmutableArray<DiagnosticAnalyzer> ResolveAnalyzersFromArguments(string language, List<DiagnosticInfo> diagnostics, CommonMessageProvider messageProvider, TouchedFileLogger touchedFiles, Func<string, Assembly> getAssembly) { var builder = ImmutableArray.CreateBuilder<DiagnosticAnalyzer>(); EventHandler<AnalyzerLoadFailureEventArgs> errorHandler = (o, e) => { var analyzerReference = o as AnalyzerFileReference; DiagnosticInfo diagnostic = null; switch (e.ErrorCode) { case AnalyzerLoadFailureEventArgs.FailureErrorCode.UnableToLoadAnalyzer: diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_UnableToLoadAnalyzer, analyzerReference.FullPath, e.Exception.Message); break; case AnalyzerLoadFailureEventArgs.FailureErrorCode.UnableToCreateAnalyzer: diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_AnalyzerCannotBeCreated, e.TypeName, analyzerReference.FullPath, e.Exception.Message); break; case AnalyzerLoadFailureEventArgs.FailureErrorCode.NoAnalyzers: diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_NoAnalyzerInAssembly, analyzerReference.FullPath); break; case AnalyzerLoadFailureEventArgs.FailureErrorCode.None: default: return; } // Filter this diagnostic based on the compilation options so that /nowarn and /warnaserror etc. take effect. diagnostic = messageProvider.FilterDiagnosticInfo(diagnostic, this.CompilationOptions); if (diagnostic != null) { diagnostics.Add(diagnostic); } }; foreach (var reference in AnalyzerReferences) { var resolvedReference = ResolveAnalyzerReference(reference, getAssembly); if (resolvedReference != null) { resolvedReference.AnalyzerLoadFailed += errorHandler; resolvedReference.AddAnalyzers(builder, language); resolvedReference.AnalyzerLoadFailed -= errorHandler; } else { diagnostics.Add(new DiagnosticInfo(messageProvider, messageProvider.ERR_MetadataFileNotFound, reference.FilePath)); } } return builder.ToImmutable(); }
// Only the compiler creates instances. internal DiagnosticInfoWithOverridenSeverity(DiagnosticInfo original, DiagnosticSeverity overriddenSeverity) : base (original.messageProvider, original.isWarningAsError, original.errorCode, original.Arguments) { this.overriddenSeverity = overriddenSeverity; }
protected virtual void PrintError(DiagnosticInfo diagnostic, TextWriter consoleOutput) { consoleOutput.WriteLine(diagnostic.ToString(Culture)); }
public override ReportDiagnostic GetDiagnosticReport(DiagnosticInfo diagnosticInfo, CompilationOptions options) { throw new NotImplementedException(); }
private FileStream CreateTempFile(TextWriter consoleOutput, out string fileName) { // now catching in response to watson bucket 148019219 try { fileName = GetTempFileName(); var result = FileOpen(fileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None); if (OnCreateTempFile != null) { OnCreateTempFile(fileName, result); } return result; } catch (IOException ex) { if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_FailedToCreateTempFile, ex.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } } fileName = null; return null; }
internal ImmutableArray<DiagnosticAnalyzer> ResolveAnalyzersFromArguments( string language, List<DiagnosticInfo> diagnostics, CommonMessageProvider messageProvider, IAnalyzerAssemblyLoader analyzerLoader) { var analyzerBuilder = ImmutableArray.CreateBuilder<DiagnosticAnalyzer>(); EventHandler<AnalyzerLoadFailureEventArgs> errorHandler = (o, e) => { var analyzerReference = o as AnalyzerFileReference; DiagnosticInfo diagnostic; switch (e.ErrorCode) { case AnalyzerLoadFailureEventArgs.FailureErrorCode.UnableToLoadAnalyzer: diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_UnableToLoadAnalyzer, analyzerReference.FullPath, e.Message); break; case AnalyzerLoadFailureEventArgs.FailureErrorCode.UnableToCreateAnalyzer: diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_AnalyzerCannotBeCreated, e.TypeName, analyzerReference.FullPath, e.Message); break; case AnalyzerLoadFailureEventArgs.FailureErrorCode.NoAnalyzers: diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_NoAnalyzerInAssembly, analyzerReference.FullPath); break; case AnalyzerLoadFailureEventArgs.FailureErrorCode.None: default: return; } // Filter this diagnostic based on the compilation options so that /nowarn and /warnaserror etc. take effect. diagnostic = messageProvider.FilterDiagnosticInfo(diagnostic, this.CompilationOptions); if (diagnostic != null) { diagnostics.Add(diagnostic); } }; var resolvedReferences = ArrayBuilder<AnalyzerFileReference>.GetInstance(); foreach (var reference in AnalyzerReferences) { var resolvedReference = ResolveAnalyzerReference(reference, analyzerLoader); if (resolvedReference != null) { resolvedReferences.Add(resolvedReference); // register the reference to the analyzer loader: analyzerLoader.AddDependencyLocation(resolvedReference.FullPath); } else { diagnostics.Add(new DiagnosticInfo(messageProvider, messageProvider.ERR_MetadataFileNotFound, reference.FilePath)); } } // All analyzer references are registered now, we can start loading them: foreach (var resolvedReference in resolvedReferences) { resolvedReference.AnalyzerLoadFailed += errorHandler; resolvedReference.AddAnalyzers(analyzerBuilder, language); resolvedReference.AnalyzerLoadFailed -= errorHandler; } resolvedReferences.Free(); return analyzerBuilder.ToImmutable(); }
private UnboundArgumentErrorTypeSymbol(string name, DiagnosticInfo errorInfo) { _name = name; _errorInfo = errorInfo; }
/// <summary> /// Filter a <see cref="DiagnosticInfo"/> based on the compilation options so that /nowarn and /warnaserror etc. take effect.options /// </summary> /// <returns>A <see cref="DiagnosticInfo"/> with effective severity based on option or null if suppressed.</returns> public DiagnosticInfo FilterDiagnosticInfo(DiagnosticInfo diagnosticInfo, CompilationOptions options) { var report = this.GetDiagnosticReport(diagnosticInfo, options); switch (report) { case ReportDiagnostic.Error: return diagnosticInfo.GetInstanceWithSeverity(DiagnosticSeverity.Error); case ReportDiagnostic.Warn: return diagnosticInfo.GetInstanceWithSeverity(DiagnosticSeverity.Warning); case ReportDiagnostic.Info: return diagnosticInfo.GetInstanceWithSeverity(DiagnosticSeverity.Info); case ReportDiagnostic.Hidden: return diagnosticInfo.GetInstanceWithSeverity(DiagnosticSeverity.Hidden); case ReportDiagnostic.Suppress: return null; default: return diagnosticInfo; } }
private string CreateTempFile(TextWriter consoleOutput) { string result = null; // now catching in response to watson bucket 148019219 try { result = PathGetTempFileName(); } catch (IOException ex) { if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_FailedToCreateTempFile, ex.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } } return result; }
private FileStream OpenFile(string filePath, TextWriter consoleOutput, FileMode mode = FileMode.Open, FileAccess access = FileAccess.ReadWrite, FileShare share = FileShare.None) { try { return FileOpen(filePath, mode, access, share); } catch (Exception e) { if (consoleOutput != null) { // TODO: distinct error message? DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_OutputWriteFailed, filePath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return null; } }
private Stream OpenFile(string filePath, TextWriter consoleOutput, object mode = null, object access = null, object share = null) { mode = mode ?? PortableShim.FileMode.Open; access = access ?? PortableShim.FileAccess.ReadWrite; share = share ?? PortableShim.FileShare.None; try { return FileOpen(filePath, mode, access, share); } catch (Exception e) { if (consoleOutput != null) { // TODO: distinct error message? DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_OutputWriteFailed, filePath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return null; } }