public ForEachEnumeratorInfo Build(BinderFlags location) { Debug.Assert( (object)CollectionType != null, $"'{nameof(CollectionType)}' cannot be null" ); Debug.Assert( (object)ElementType != null, $"'{nameof(ElementType)}' cannot be null" ); Debug.Assert( GetEnumeratorInfo != null, $"'{nameof(GetEnumeratorInfo)}' cannot be null" ); Debug.Assert(MoveNextInfo != null); Debug.Assert(CurrentPropertyGetter != null); return(new ForEachEnumeratorInfo( CollectionType, ElementTypeWithAnnotations, GetEnumeratorInfo, CurrentPropertyGetter, MoveNextInfo, IsAsync, NeedsDisposal, DisposeAwaitableInfo, PatternDisposeInfo, CollectionConversion, CurrentConversion, EnumeratorConversion, location )); }
internal CSharpCompilationOptions WithTopLevelBinderFlags(BinderFlags flags) { return((flags == TopLevelBinderFlags) ? this : new CSharpCompilationOptions(this) { TopLevelBinderFlags = flags }); }
internal Binder(Binder next) { Debug.Assert(next != null); _next = next; this.Flags = next.Flags; this.Compilation = next.Compilation; }
internal BinderWithContainingMemberOrLambda(Binder next, BinderFlags flags, Symbol containingMemberOrLambda) : base(next, flags) { Debug.Assert(containingMemberOrLambda != null); _containingMemberOrLambda = containingMemberOrLambda; }
private ForEachEnumeratorInfo( TypeSymbol collectionType, TypeSymbolWithAnnotations elementType, MethodSymbol getEnumeratorMethod, MethodSymbol currentPropertyGetter, MethodSymbol moveNextMethod, bool needsDisposeMethod, Conversion collectionConversion, Conversion currentConversion, Conversion enumeratorConversion, BinderFlags location) { Debug.Assert((object)collectionType != null, "Field 'collectionType' cannot be null"); Debug.Assert(!elementType.IsNull, "Field 'elementType' cannot be null"); Debug.Assert((object)getEnumeratorMethod != null, "Field 'getEnumeratorMethod' cannot be null"); Debug.Assert((object)currentPropertyGetter != null, "Field 'currentPropertyGetter' cannot be null"); Debug.Assert((object)moveNextMethod != null, "Field 'moveNextMethod' cannot be null"); this.CollectionType = collectionType; this.ElementType = elementType; this.GetEnumeratorMethod = getEnumeratorMethod; this.CurrentPropertyGetter = currentPropertyGetter; this.MoveNextMethod = moveNextMethod; this.NeedsDisposeMethod = needsDisposeMethod; this.CollectionConversion = collectionConversion; this.CurrentConversion = currentConversion; this.EnumeratorConversion = enumeratorConversion; this.Location = location; }
internal BinderWithContainingMemberOrLambda(Binder next, BinderFlags flags, Symbol containingMemberOrLambda) : base(next, flags) { Debug.Assert(containingMemberOrLambda != null); _containingMemberOrLambda = containingMemberOrLambda; }
protected MetaCompilation Compile(string filePath, bool assertEmptyDiagnostics = true, bool compileMetaModelCore = false) { MetaDescriptor.Initialize(); string text = File.ReadAllText(filePath); var st = MetaSyntaxTree.ParseText(text); BinderFlags binderFlags = BinderFlags.IgnoreAccessibility; if (compileMetaModelCore) { BinderFlags binderFlags2 = BinderFlags.IgnoreMetaLibraryDuplicatedTypes; binderFlags = binderFlags.UnionWith(binderFlags2); } MetaCompilationOptions options = new MetaCompilationOptions(MetaLanguage.Instance, OutputKind.NetModule, deterministic: true, concurrentBuild: false, topLevelBinderFlags: binderFlags); var compilation = MetaCompilation. Create("MetaModelCompilation"). AddSyntaxTrees(st). AddReferences( ModelReference.CreateFromModel(MetaInstance.MModel) ). WithOptions(options); compilation.ForceComplete(); if (assertEmptyDiagnostics) { AssertEmptyDiagnostics(compilation); } return(compilation); }
internal Binder(Binder next) { Debug.Assert(next != null); _next = next; this.Flags = next.Flags; this.Compilation = next.Compilation; }
private ForEachEnumeratorInfo( TypeSymbol collectionType, TypeSymbol elementType, MethodSymbol getEnumeratorMethod, MethodSymbol currentPropertyGetter, MethodSymbol moveNextMethod, bool needsDisposeMethod, Conversion collectionConversion, Conversion currentConversion, Conversion enumeratorConversion, BinderFlags location) { Debug.Assert((object)collectionType != null, "Field 'collectionType' cannot be null"); Debug.Assert((object)elementType != null, "Field 'elementType' cannot be null"); Debug.Assert((object)getEnumeratorMethod != null, "Field 'getEnumeratorMethod' cannot be null"); Debug.Assert((object)currentPropertyGetter != null, "Field 'currentPropertyGetter' cannot be null"); Debug.Assert((object)moveNextMethod != null, "Field 'moveNextMethod' cannot be null"); this.CollectionType = collectionType; this.ElementType = elementType; this.GetEnumeratorMethod = getEnumeratorMethod; this.CurrentPropertyGetter = currentPropertyGetter; this.MoveNextMethod = moveNextMethod; this.NeedsDisposeMethod = needsDisposeMethod; this.CollectionConversion = collectionConversion; this.CurrentConversion = currentConversion; this.EnumeratorConversion = enumeratorConversion; this.Location = location; }
internal LazyObsoleteDiagnosticInfo(object symbol, Symbol containingSymbol, BinderFlags binderFlags) { Debug.Assert(symbol is Symbol || symbol is TypeWithAnnotations); _symbolOrSymbolWithAnnotations = symbol; _containingSymbol = containingSymbol; _binderFlags = binderFlags; }
public ForEachEnumeratorInfo Build(BinderFlags location) { Debug.Assert((object)CollectionType != null, "'CollectionType' cannot be null"); Debug.Assert((object)ElementType != null, "'ElementType' cannot be null"); Debug.Assert((object)GetEnumeratorMethod != null, "'GetEnumeratorMethod' cannot be null"); Debug.Assert(MoveNextMethod != null); Debug.Assert(CurrentPropertyGetter != null); Debug.Assert(Binder != null); return(new ForEachEnumeratorInfo( CollectionType, ElementTypeWithAnnotations, GetEnumeratorMethod, CurrentPropertyGetter, MoveNextMethod, IsAsync, NeedsDisposal, DisposeAwaitableInfo, DisposeMethod, CollectionConversion, CurrentConversion, EnumeratorConversion, location, Binder)); }
internal LocalScopeBinder(Binder next, BinderFlags flags) : base(next, flags) { var parentDepth = next.LocalScopeDepth; if (parentDepth != Binder.TopLevelScope) { _localScopeDepth = parentDepth + 1; } else { //NOTE: TopLevel is special. //For our purpose parameters and top level locals are on that level. var parentScope = next; while (parentScope != null) { if (parentScope is InMethodBinder || parentScope is WithLambdaParametersBinder) { _localScopeDepth = Binder.TopLevelScope; break; } if (parentScope is LocalScopeBinder) { _localScopeDepth = Binder.TopLevelScope + 1; break; } parentScope = parentScope.Next; Debug.Assert(parentScope != null); } } }
private ForEachEnumeratorInfo( TypeSymbol collectionType, TypeWithAnnotations elementType, MethodArgumentInfo getEnumeratorInfo, MethodSymbol currentPropertyGetter, MethodArgumentInfo moveNextInfo, bool isAsync, bool needsDisposal, BoundAwaitableInfo?disposeAwaitableInfo, MethodArgumentInfo?patternDisposeInfo, BoundValuePlaceholder?currentPlaceholder, BoundExpression?currentConversion, BinderFlags location) { Debug.Assert((object)collectionType != null, $"Field '{nameof(collectionType)}' cannot be null"); Debug.Assert(elementType.HasType, $"Field '{nameof(elementType)}' cannot be null"); Debug.Assert((object)getEnumeratorInfo != null, $"Field '{nameof(getEnumeratorInfo)}' cannot be null"); Debug.Assert((object)currentPropertyGetter != null, $"Field '{nameof(currentPropertyGetter)}' cannot be null"); Debug.Assert((object)moveNextInfo != null, $"Field '{nameof(moveNextInfo)}' cannot be null"); Debug.Assert(patternDisposeInfo == null || needsDisposal); this.CollectionType = collectionType; this.ElementTypeWithAnnotations = elementType; this.GetEnumeratorInfo = getEnumeratorInfo; this.CurrentPropertyGetter = currentPropertyGetter; this.MoveNextInfo = moveNextInfo; this.IsAsync = isAsync; this.NeedsDisposal = needsDisposal; this.DisposeAwaitableInfo = disposeAwaitableInfo; this.PatternDisposeInfo = patternDisposeInfo; this.CurrentPlaceholder = currentPlaceholder; this.CurrentConversion = currentConversion; this.Location = location; }
/// <summary> /// Used to create a root binder. /// </summary> internal Binder(CSharpCompilation compilation) { RoslynDebug.Assert(compilation != null); RoslynDebug.Assert(this is BuckStopsHereBinder); this.Flags = compilation.Options.TopLevelBinderFlags; this.Compilation = compilation; }
internal ExecutableCodeBinder(CSharpSyntaxNode root, Symbol memberSymbol, Binder next, BinderFlags additionalFlags) : base(next, (next.Flags | additionalFlags) & ~BinderFlags.AllClearedAtExecutableCodeBoundary) { this.memberSymbol = memberSymbol; this.root = root; this.owner = memberSymbol as MethodSymbol; }
private ForEachEnumeratorInfo( TypeSymbol collectionType, TypeWithAnnotations elementType, MethodSymbol getEnumeratorMethod, MethodSymbol currentPropertyGetter, MethodSymbol moveNextMethod, bool isAsync, bool needsDisposal, BoundAwaitableInfo disposeAwaitableInfo, MethodSymbol disposeMethod, Conversion collectionConversion, Conversion currentConversion, Conversion enumeratorConversion, BinderFlags location) { Debug.Assert((object)collectionType != null, "Field 'collectionType' cannot be null"); Debug.Assert(elementType.HasType, "Field 'elementType' cannot be null"); Debug.Assert((object)getEnumeratorMethod != null, "Field 'getEnumeratorMethod' cannot be null"); Debug.Assert((object)currentPropertyGetter != null, "Field 'currentPropertyGetter' cannot be null"); Debug.Assert((object)moveNextMethod != null, "Field 'moveNextMethod' cannot be null"); this.CollectionType = collectionType; this.ElementTypeWithAnnotations = elementType; this.GetEnumeratorMethod = getEnumeratorMethod; this.CurrentPropertyGetter = currentPropertyGetter; this.MoveNextMethod = moveNextMethod; this.IsAsync = isAsync; this.NeedsDisposal = needsDisposal; this.DisposeAwaitableInfo = disposeAwaitableInfo; this.DisposeMethod = disposeMethod; this.CollectionConversion = collectionConversion; this.CurrentConversion = currentConversion; this.EnumeratorConversion = enumeratorConversion; this.Location = location; }
private ForEachEnumeratorInfo(TypeSymbol iterableType, TypeSymbolWithAnnotations elementType, TypeSymbol iteratorType, MethodSymbol iterateBegin, MethodSymbol iterateHasCurrent, MethodSymbol iterateCurrent, MethodSymbol iterateNext, MethodSymbol iterateEnd, bool needsDisposal, AwaitableInfo disposeAwaitableInfo, BinderFlags location) { Debug.Assert((object)iterableType != null, "Field 'collectionType' cannot be null"); Debug.Assert(!elementType.IsNull, "Field 'elementType' cannot be null"); Debug.Assert((object)iteratorType != null, "Field 'stateType' cannot be null"); Debug.Assert((object)iterateBegin != null, "Field 'iterateBegin' cannot be null"); Debug.Assert((object)iterateNext != null, "Field 'iterateItem' cannot be null"); Debug.Assert((object)iterateHasCurrent != null, "Field 'iterateNext' cannot be null"); Debug.Assert((object)iterateEnd != null, "Field 'iterateEnd' cannot be null"); this.IterableType = iterableType; this.ElementType = elementType; this.IteratorType = iteratorType; this.IterateBegin = iterateBegin; this.IterateHasCurrent = iterateHasCurrent; this.IterateCurrent = iterateCurrent; this.IterateNext = iterateNext; this.IterateEnd = iterateEnd; this.NeedsDisposal = needsDisposal; this.DisposeAwaitableInfo = disposeAwaitableInfo; this.Location = location; }
public void Compile() { if (_compilation == null) { ImmutableModel coreModel = MetaInstance.MModel; string text = File.ReadAllText(_inputFilePath); var tree = MetaSyntaxTree.ParseText(text, path: _inputFilePath); BinderFlags binderFlags = BinderFlags.IgnoreAccessibility; if (_compileMetaModelCore) { BinderFlags binderFlags2 = BinderFlags.IgnoreMetaLibraryDuplicatedTypes; binderFlags = binderFlags.UnionWith(binderFlags2); } MetaCompilationOptions options = new MetaCompilationOptions(MetaLanguage.Instance, OutputKind.NetModule, deterministic: true, concurrentBuild: true, topLevelBinderFlags: binderFlags); //MetaCompilationOptions options = new MetaCompilationOptions(MetaLanguage.Instance, OutputKind.NetModule, deterministic: true, concurrentBuild: false); var compilation = MetaCompilation. Create("MetaModelCompilation"). AddSyntaxTrees(tree). AddReferences( ModelReference.CreateFromModel(coreModel) ). WithOptions(options); Interlocked.CompareExchange(ref _compilation, compilation, null); } _compilation.ForceComplete(); }
internal LazyObsoleteDiagnosticInfo(Symbol symbol, Symbol containingSymbol, BinderFlags binderFlags) : base(CSharp.MessageProvider.Instance, (int)ErrorCode.Unknown) { this.symbol = symbol; this.containingSymbol = containingSymbol; this.binderFlags = binderFlags; this.lazyActualObsoleteDiagnostic = null; }
internal Binder(Binder next, Conversions conversions = null) { Debug.Assert(next != null); _next = next; this.Flags = next.Flags; this.Compilation = next.Compilation; _lazyConversions = conversions; }
internal LazyObsoleteDiagnosticInfo(Symbol symbol, Symbol containingSymbol, BinderFlags binderFlags) : base(CSharp.MessageProvider.Instance, (int)ErrorCode.Unknown) { this.symbol = symbol; this.containingSymbol = containingSymbol; this.binderFlags = binderFlags; this.lazyActualObsoleteDiagnostic = null; }
/// <remarks> /// It seems to be common to do both of these things at once, so provide a way to do so /// without adding two links to the binder chain. /// </remarks> internal Binder WithAdditionalFlagsAndContainingMemberOrLambda( BinderFlags flags, Symbol containing ) { Debug.Assert((object)containing != null); return(new BinderWithContainingMemberOrLambda(this, this.Flags | flags, containing)); }
protected Binder(Binder next, BinderFlags flags) { Debug.Assert(next != null); // Mutually exclusive. Debug.Assert(!flags.Includes(BinderFlags.UncheckedRegion | BinderFlags.CheckedRegion)); this.next = next; this.Flags = flags; this.Compilation = next.Compilation; }
internal LazyObsoleteDiagnosticInfo(Symbol symbol, Symbol containingSymbol, BinderFlags binderFlags) : base(CSharp.MessageProvider.Instance, (int)CSharp.ErrorCode.Unknown) { Debug.Assert(symbol is Symbol); _symbol = symbol; _containingSymbol = containingSymbol; _binderFlags = binderFlags; _lazyActualObsoleteDiagnostic = null; }
internal ExecutableCodeBinder(CSharpSyntaxNode root, Symbol memberSymbol, Binder next, BinderFlags additionalFlags) : base(next, (next.Flags | additionalFlags) & ~BinderFlags.AllClearedAtExecutableCodeBoundary) { Debug.Assert((object)memberSymbol == null || (memberSymbol.Kind != SymbolKind.Local && memberSymbol.Kind != SymbolKind.RangeVariable && memberSymbol.Kind != SymbolKind.Parameter)); _memberSymbol = memberSymbol; _root = root; }
internal LazyObsoleteDiagnosticInfo(object symbol, Symbol containingSymbol, BinderFlags binderFlags) : base(CSharp.MessageProvider.Instance, (int)ErrorCode.Unknown) { Debug.Assert(symbol is Symbol || symbol is TypeWithAnnotations); _symbolOrSymbolWithAnnotations = symbol; _containingSymbol = containingSymbol; _binderFlags = binderFlags; _lazyActualObsoleteDiagnostic = null; }
internal Binder WithCheckedOrUncheckedRegion(bool @checked) { Debug.Assert(!this.Flags.Includes(BinderFlags.UncheckedRegion | BinderFlags.CheckedRegion)); BinderFlags added = @checked ? BinderFlags.CheckedRegion : BinderFlags.UncheckedRegion; BinderFlags removed = @checked ? BinderFlags.UncheckedRegion : BinderFlags.CheckedRegion; return(this.Flags.Includes(added) ? this : new Binder(this, (this.Flags & ~removed) | added)); }
public LanguageCompilationOptions WithTopLevelBinderFlags(BinderFlags flags) { if (flags == TopLevelBinderFlags) { return(this); } var clone = this.Clone(); clone.TopLevelBinderFlags = flags; return(clone); }
protected Binder(Binder next, BinderFlags flags) { Debug.Assert(next != null); // Mutually exclusive. Debug.Assert(!flags.Includes(BinderFlags.UncheckedRegion | BinderFlags.CheckedRegion)); // Implied. Debug.Assert(!flags.Includes(BinderFlags.InNestedFinallyBlock) || flags.Includes(BinderFlags.InFinallyBlock | BinderFlags.InCatchBlock)); _next = next; this.Flags = flags; this.Compilation = next.Compilation; }
private ExpressionLambdaRewriter(TypeCompilationState compilationState, TypeMap typeMap, BinderFlags binderFlags, CSharpSyntaxNode node, DiagnosticBag diagnostics) { _bound = new SyntheticBoundNodeFactory(null, compilationState.Type, node, compilationState, diagnostics); _binderFlags = binderFlags; _int32Type = _bound.SpecialType(SpecialType.System_Int32); _objectType = _bound.SpecialType(SpecialType.System_Object); _nullableType = _bound.SpecialType(SpecialType.System_Nullable_T); _IEnumerableType = _bound.SpecialType(SpecialType.System_Collections_Generic_IEnumerable_T); _typeMap = typeMap; }
protected Binder(Binder next, BinderFlags flags) { Debug.Assert(next != null); // Mutually exclusive. Debug.Assert(!flags.Includes(BinderFlags.UncheckedRegion | BinderFlags.CheckedRegion)); // Implied. Debug.Assert(!flags.Includes(BinderFlags.InNestedFinallyBlock) || flags.Includes(BinderFlags.InFinallyBlock | BinderFlags.InCatchBlock)); _next = next; this.Flags = flags; this.Compilation = next.Compilation; }
public ForEachEnumeratorInfo Build(BinderFlags location) { return(new ForEachEnumeratorInfo( CollectionType, ElementType, GetEnumeratorMethod, CurrentPropertyGetter, MoveNextMethod, NeedsDisposeMethod, CollectionConversion, CurrentConversion, EnumeratorConversion, location)); }
public ForEachEnumeratorInfo Build(BinderFlags location) { return new ForEachEnumeratorInfo( CollectionType, ElementType, GetEnumeratorMethod, CurrentPropertyGetter, MoveNextMethod, NeedsDisposeMethod, CollectionConversion, CurrentConversion, EnumeratorConversion, location); }
protected override ICompilation CreateCompilation(string filePath, string sourceText, CancellationToken cancellationToken) { var metaModelReference = ModelReference.CreateFromModel(MetaInstance.MModel); var tree = MetaSyntaxTree.ParseText(sourceText, path: filePath, cancellationToken: cancellationToken); BinderFlags binderFlags = BinderFlags.IgnoreAccessibility; BinderFlags binderFlags2 = BinderFlags.IgnoreMetaLibraryDuplicatedTypes; binderFlags = binderFlags.UnionWith(binderFlags2); MetaCompilationOptions options = new MetaCompilationOptions(MetaLanguage.Instance, OutputKind.NetModule, deterministic: true, concurrentBuild: true, topLevelBinderFlags: binderFlags); var compilation = MetaCompilation.Create("Tagger").AddReferences(metaModelReference).AddSyntaxTrees(tree).WithOptions(options); return(compilation); }
private bool Test(int index) { bool result = false; string inputFileName = string.Format(@"..\..\InputFiles\soal\Xsd{0:00}.soal", index); string expectedFileName = string.Format(@"..\..\ExpectedFiles\xsd\Xsd{0:00}.Hello.xsd", index); string outputFileName = string.Format(@"..\..\OutputFiles\xsd\Xsd{0:00}.Hello.xsd", index); string outputDirectory = string.Format(@"..\..\OutputFiles"); string inputSoal = null; using (StreamReader reader = new StreamReader(inputFileName)) { inputSoal = reader.ReadToEnd(); } SoalSyntaxTree syntaxTree = SoalSyntaxTree.ParseText(inputSoal); ModelReference soalReference = ModelReference.CreateFromModel(SoalInstance.Model); BinderFlags binderFlags = BinderFlags.IgnoreAccessibility; SoalCompilationOptions options = new SoalCompilationOptions(SoalLanguage.Instance, OutputKind.NetModule, topLevelBinderFlags: binderFlags); SoalCompilation compilation = SoalCompilation.Create("SoalTest").AddReferences(soalReference).AddSyntaxTrees(syntaxTree).WithOptions(options); compilation.ForceComplete(); ImmutableModel model = compilation.Model; Assert.IsFalse(compilation.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error)); DiagnosticBag generatorDiagnostics = new DiagnosticBag(); SoalGenerator generator = new SoalGenerator(model, compilation.BuildModelObjectToSymbolMap(), outputDirectory, generatorDiagnostics, inputFileName); generator.SeparateXsdWsdl = true; generator.SingleFileWsdl = false; generator.Generate(); Assert.IsFalse(generatorDiagnostics.AsEnumerable().Any(d => d.Severity == DiagnosticSeverity.Error)); string expectedXsd = null; using (StreamReader reader = new StreamReader(expectedFileName)) { expectedXsd = reader.ReadToEnd(); } string outputXsd = null; using (StreamReader reader = new StreamReader(outputFileName)) { outputXsd = reader.ReadToEnd(); } Assert.AreEqual(expectedXsd, outputXsd); return(result); }
/// <summary> /// Create a diagnostic for the given symbol. This could be an error or a warning based on /// the ObsoleteAttribute's arguments. /// </summary> internal static DiagnosticInfo CreateObsoleteDiagnostic(Symbol symbol, BinderFlags location) { var data = symbol.ObsoleteAttributeData; Debug.Assert(data != null); if (data == null) { return(null); } // At this point, we are going to issue diagnostics and therefore the data shouldn't be // uninitialized. Debug.Assert(!data.IsUninitialized); // The native compiler suppresses Obsolete diagnostics in these locations. if (location.Includes(BinderFlags.SuppressObsoleteChecks)) { return(null); } if (data.Kind == ObsoleteAttributeKind.Experimental) { Debug.Assert(data.Message == null); Debug.Assert(!data.IsError); // Provide an explicit format for fully-qualified type names. return(new CSDiagnosticInfo(ErrorCode.WRN_Experimental, new FormattedSymbol(symbol, SymbolDisplayFormat.CSharpErrorMessageFormat))); } // Issue a specialized diagnostic for add methods of collection initializers bool isColInit = location.Includes(BinderFlags.CollectionInitializerAddMethod); if (data.Message == null) { // It seems like we should be able to assert that data.IsError is false, but we can't because dev11 had // a bug in this area (i.e. always produce a warning when there's no message) and we have to match it. // Debug.Assert(!data.IsError); return(new CSDiagnosticInfo(isColInit ? ErrorCode.WRN_DeprecatedCollectionInitAdd : ErrorCode.WRN_DeprecatedSymbol, symbol)); } else { ErrorCode errorCode = data.IsError ? (isColInit ? ErrorCode.ERR_DeprecatedCollectionInitAddStr : ErrorCode.ERR_DeprecatedSymbolStr) : (isColInit ? ErrorCode.WRN_DeprecatedCollectionInitAddStr : ErrorCode.WRN_DeprecatedSymbolStr); return(new CSDiagnosticInfo(errorCode, symbol, data.Message)); } }
internal CSharpCompilationOptions( OutputKind outputKind, bool reportSuppressedDiagnostics, string?moduleName, string?mainTypeName, string?scriptClassName, IEnumerable <string>?usings, OptimizationLevel optimizationLevel, bool checkOverflow, bool allowUnsafe, string?cryptoKeyContainer, string?cryptoKeyFile, ImmutableArray <byte> cryptoPublicKey, bool?delaySign, Platform platform, ReportDiagnostic generalDiagnosticOption, int warningLevel, IEnumerable <KeyValuePair <string, ReportDiagnostic> >?specificDiagnosticOptions, bool concurrentBuild, bool deterministic, DateTime currentLocalTime, bool debugPlusMode, XmlReferenceResolver?xmlReferenceResolver, SourceReferenceResolver?sourceReferenceResolver, MetadataReferenceResolver?metadataReferenceResolver, AssemblyIdentityComparer?assemblyIdentityComparer, StrongNameProvider?strongNameProvider, MetadataImportOptions metadataImportOptions, bool referencesSupersedeLowerVersions, bool publicSign, BinderFlags topLevelBinderFlags, NullableContextOptions nullableContextOptions, decimal warningVersion = 0m) : base(outputKind, reportSuppressedDiagnostics, moduleName, mainTypeName, scriptClassName, cryptoKeyContainer, cryptoKeyFile, cryptoPublicKey, delaySign, publicSign, optimizationLevel, checkOverflow, platform, generalDiagnosticOption, warningLevel, specificDiagnosticOptions.ToImmutableDictionaryOrEmpty(), concurrentBuild, deterministic, currentLocalTime, debugPlusMode, xmlReferenceResolver, sourceReferenceResolver, metadataReferenceResolver, assemblyIdentityComparer, strongNameProvider, metadataImportOptions, referencesSupersedeLowerVersions) { this.Usings = usings.AsImmutableOrEmpty(); this.AllowUnsafe = allowUnsafe; this.TopLevelBinderFlags = topLevelBinderFlags; this.NullableContextOptions = nullableContextOptions; this.WarningVersion = warningVersion; }
// Defaults correspond to the compiler's defaults or indicate that the user did not specify when that is significant. // That's significant when one option depends on another's setting. SubsystemVersion depends on Platform and Target. public LanguageCompilationOptions( Language language, OutputKind outputKind, bool reportSuppressedDiagnostics = false, string moduleName = null, string mainTypeName = null, string scriptClassName = null, IEnumerable <string> usings = null, OptimizationLevel optimizationLevel = OptimizationLevel.Debug, bool checkOverflow = false, bool allowUnsafe = false, string cryptoKeyContainer = null, string cryptoKeyFile = null, ImmutableArray <byte> cryptoPublicKey = default(ImmutableArray <byte>), bool?delaySign = null, Platform platform = Platform.AnyCpu, ReportDiagnostic generalDiagnosticOption = ReportDiagnostic.Default, int warningLevel = 4, IEnumerable <KeyValuePair <string, ReportDiagnostic> > specificDiagnosticOptions = null, bool concurrentBuild = true, bool deterministic = false, DateTime currentLocalTime = default(DateTime), bool debugPlusMode = false, XmlReferenceResolver xmlReferenceResolver = null, SourceReferenceResolver sourceReferenceResolver = null, MetadataReferenceResolver metadataReferenceResolver = null, AssemblyIdentityComparer assemblyIdentityComparer = null, StrongNameProvider strongNameProvider = null, bool publicSign = false, MetadataImportOptions metadataImportOptions = MetadataImportOptions.Public, bool referencesSupersedeLowerVersions = false, BinderFlags topLevelBinderFlags = null) : base(outputKind, reportSuppressedDiagnostics, moduleName, mainTypeName, scriptClassName, cryptoKeyContainer, cryptoKeyFile, cryptoPublicKey, delaySign, publicSign, optimizationLevel, checkOverflow, platform, generalDiagnosticOption, warningLevel, specificDiagnosticOptions.ToImmutableDictionaryOrEmpty(), concurrentBuild, deterministic, currentLocalTime, debugPlusMode, xmlReferenceResolver, sourceReferenceResolver, metadataReferenceResolver, assemblyIdentityComparer, strongNameProvider, metadataImportOptions, referencesSupersedeLowerVersions) { _language = language; this.Usings = usings.AsImmutableOrEmpty(); this.AllowUnsafe = allowUnsafe; this.TopLevelBinderFlags = topLevelBinderFlags ?? BinderFlags.None; }
/// <summary> /// Create a diagnostic for the given symbol. This could be an error or a warning based on /// the ObsoleteAttribute's arguments. /// </summary> internal static DiagnosticInfo CreateObsoleteDiagnostic(Symbol symbol, BinderFlags location) { var data = symbol.ObsoleteAttributeData; if (data == null) { // ObsoleteAttribute had errors. return null; } // At this point, we are going to issue diagnostics and therefore the data shouldn't be // uninitialized. Debug.Assert(!data.IsUninitialized); // The native compiler suppresses Obsolete diagnostics in these locations. if (location.Includes(BinderFlags.SuppressObsoleteChecks)) { return null; } // Issue a specialized diagnostic for add methods of collection initializers bool isColInit = location.Includes(BinderFlags.CollectionInitializerAddMethod); if (data.Message == null) { // It seems like we should be able to assert that data.IsError is false, but we can't because dev11 had // a bug in this area (i.e. always produce a warning when there's no message) and we have to match it. // Debug.Assert(!data.IsError); return new CSDiagnosticInfo(isColInit ? ErrorCode.WRN_DeprecatedCollectionInitAdd : ErrorCode.WRN_DeprecatedSymbol, symbol); } else { ErrorCode errorCode = data.IsError ? (isColInit ? ErrorCode.ERR_DeprecatedCollectionInitAddStr : ErrorCode.ERR_DeprecatedSymbolStr) : (isColInit ? ErrorCode.WRN_DeprecatedCollectionInitAddStr : ErrorCode.WRN_DeprecatedSymbolStr); return new CSDiagnosticInfo(errorCode, symbol, data.Message); } }
public static bool Includes(this BinderFlags self, BinderFlags other) { return (self & other) == other; }
public BlockBinder(MethodSymbol owner, Binder enclosing, SyntaxList<StatementSyntax> statements, BinderFlags additionalFlags) : base(owner, enclosing, enclosing.Flags | additionalFlags) { this.statements = statements; }
/// <remarks> /// It seems to be common to do both of these things at once, so provide a way to do so /// without adding two links to the binder chain. /// </remarks> internal Binder WithAdditionalFlagsAndContainingMemberOrLambda(BinderFlags flags, Symbol containing) { Debug.Assert((object)containing != null); return new BinderWithContainingMemberOrLambda(this, this.Flags | flags, containing); }
internal Binder WithAdditionalFlags(BinderFlags flags) { return this.Flags.Includes(flags) ? this : new Binder(this, this.Flags | flags); }
internal Binder WithFlags(BinderFlags flags) { return this.Flags == flags ? this : new Binder(this, flags); }
internal BinderWithContainingMemberOrLambda(Binder next, BinderFlags flags, Symbol containingMemberOrLambda) : base(next, flags) { this.containingMemberOrLambda = containingMemberOrLambda; }
public BlockBinder(Binder enclosing, BlockSyntax block, BinderFlags additionalFlags) : base(enclosing, enclosing.Flags | additionalFlags) { Debug.Assert(block != null); _block = block; }
public BlockBinder(Binder enclosing, SyntaxList<StatementSyntax> statements, BinderFlags additionalFlags) : base(enclosing, enclosing.Flags | additionalFlags) { _statements = statements; }
public BoundExpression StaticCall(BinderFlags flags, TypeSymbol receiver, string name, ImmutableArray<TypeSymbol> typeArgs, params BoundExpression[] args) { return MakeInvocationExpression(flags, this.Syntax, this.Type(receiver), name, args.ToImmutableArray(), this.Diagnostics, typeArgs); }
internal BoundExpression MakeInvocationExpression( BinderFlags flags, CSharpSyntaxNode node, BoundExpression receiver, string methodName, ImmutableArray<BoundExpression> args, DiagnosticBag diagnostics, ImmutableArray<TypeSymbol> typeArgs = default(ImmutableArray<TypeSymbol>), bool allowUnexpandedForm = true) { if (_binder == null || _binder.Flags != flags) { _binder = new SyntheticBinderImpl(this).WithFlags(flags); } return _binder.MakeInvocationExpression( node, receiver, methodName, args, diagnostics, typeArgs: typeArgs, allowFieldsAndProperties: false, allowUnexpandedForm: allowUnexpandedForm); }
/// <returns> /// True if the symbol is definitely obsolete. /// False if the symbol is definitely not obsolete. /// Unknown if the symbol may be obsolete. /// /// NOTE: The return value reflects obsolete-ness, not whether or not the diagnostic was reported. /// </returns> private static ThreeState ReportDiagnosticsIfObsoleteInternal(DiagnosticBag diagnostics, Symbol symbol, SyntaxNodeOrToken node, Symbol containingMember, BinderFlags location) { Debug.Assert(diagnostics != null); if (symbol.ObsoleteState == ThreeState.False) { return ThreeState.False; } var data = symbol.ObsoleteAttributeData; if (data == null) { // Obsolete attribute has errors. return ThreeState.False; } // If we haven't cracked attributes on the symbol at all or we haven't // cracked attribute arguments enough to be able to report diagnostics for // ObsoleteAttribute, store the symbol so that we can report diagnostics at a // later stage. if (symbol.ObsoleteState == ThreeState.Unknown) { diagnostics.Add(new LazyObsoleteDiagnosticInfo(symbol, containingMember, location), node.GetLocation()); return ThreeState.Unknown; } // After this point, always return True. var inObsoleteContext = ObsoleteAttributeHelpers.GetObsoleteContextState(containingMember); // If we are in a context that is already obsolete, there is no point reporting // more obsolete diagnostics. if (inObsoleteContext == ThreeState.True) { return ThreeState.True; } // If the context is unknown, then store the symbol so that we can do this check at a // later stage else if (inObsoleteContext == ThreeState.Unknown) { diagnostics.Add(new LazyObsoleteDiagnosticInfo(symbol, containingMember, location), node.GetLocation()); return ThreeState.True; } // We have all the information we need to report diagnostics right now. So do it. var diagInfo = ObsoleteAttributeHelpers.CreateObsoleteDiagnostic(symbol, location); if (diagInfo != null) { diagnostics.Add(diagInfo, node.GetLocation()); return ThreeState.True; } return ThreeState.True; }
internal static void ReportDiagnosticsIfObsolete( DiagnosticBag diagnostics, Symbol symbol, SyntaxNodeOrToken node, bool hasBaseReceiver, Symbol containingMember, NamedTypeSymbol containingType, BinderFlags location) { Debug.Assert((object)symbol != null); Debug.Assert(symbol.Kind == SymbolKind.NamedType || symbol.Kind == SymbolKind.Field || symbol.Kind == SymbolKind.Method || symbol.Kind == SymbolKind.Event || symbol.Kind == SymbolKind.Property); // Dev11 also reports on the unconstructed method. It would be nice to report on // the constructed method, but then we wouldn't be able to walk the override chain. if (symbol.Kind == SymbolKind.Method) { symbol = ((MethodSymbol)symbol).ConstructedFrom; } // There are two reasons to walk up to the least-overridden member: // 1) That's the method to which we will actually emit a call. // 2) We don't know what virtual dispatch will do at runtime so an // overriding member is basically a shot in the dark. Better to // just be consistent and always use the least-overridden member. Symbol leastOverriddenSymbol = symbol.GetLeastOverriddenMember(containingType); bool checkOverridingSymbol = hasBaseReceiver && !ReferenceEquals(symbol, leastOverriddenSymbol); if (checkOverridingSymbol) { // If we have a base receiver, we must be done with declaration binding, so it should // be safe to decode diagnostics. We want to do this since reporting for the overriding // member is conditional on reporting for the overridden member (i.e. we need a definite // answer so we don't double-report). You might think that double reporting just results // in cascading diagnostics, but it's possible that the second diagnostic is an error // while the first is merely a warning. leastOverriddenSymbol.GetAttributes(); } ThreeState reportedOnOverridden = ReportDiagnosticsIfObsoleteInternal(diagnostics, leastOverriddenSymbol, node, containingMember, location); // CONSIDER: In place of hasBaseReceiver, dev11 also accepts cases where symbol.ContainingType is a "simple type" (e.g. int) // or a special by-ref type (e.g. ArgumentHandle). These cases are probably more important for other checks performed by // ExpressionBinder::PostBindMethod, but they do appear to ObsoleteAttribute as well. We're skipping them because they // don't make much sense for ObsoleteAttribute (e.g. this would seem to address the case where int.ToString has been made // obsolete but object.ToString has not). // If the overridden member was not definitely obsolete and this is a (non-virtual) base member // access, then check the overriding symbol as well. if (reportedOnOverridden != ThreeState.True && checkOverridingSymbol) { Debug.Assert(reportedOnOverridden != ThreeState.Unknown, "We forced attribute binding above."); ReportDiagnosticsIfObsoleteInternal(diagnostics, symbol, node, containingMember, location); } }
/// <summary> /// Used to create a root binder. /// </summary> internal Binder(CSharpCompilation compilation) { Debug.Assert(compilation != null); this.Flags = compilation.Options.TopLevelBinderFlags; this.Compilation = compilation; }