// Internal for unit tests only. internal MergedDeclaration CalculateMergedRoot(LanguageCompilation compilation) { var oldRoot = _cache.MergedRoot.Value; if (_latestLazyRootDeclaration == null) { return(oldRoot); } else if (oldRoot == null) { return(MergedDeclaration.Create(_latestLazyRootDeclaration.Value)); } else { var oldRootDeclarations = oldRoot.Declarations; var builder = ArrayBuilder <SingleDeclaration> .GetInstance(oldRootDeclarations.Length + 1); builder.AddRange(oldRootDeclarations); builder.Add(_latestLazyRootDeclaration.Value); // Sort the root namespace declarations to match the order of SyntaxTrees. if (compilation != null) { builder.Sort(new RootNamespaceLocationComparer(compilation)); } return(MergedDeclaration.Create(builder.ToImmutableAndFree())); } }
private Binder(Binder next, BinderFlags flags) { Debug.Assert(next != null); _next = next; this.Flags = flags; _compilation = next._compilation; }
private Imports( LanguageCompilation compilation, ImmutableDictionary <string, AliasAndUsingDirective> usingAliases, ImmutableArray <NamespaceOrTypeAndUsingDirective> usings, ImmutableArray <AliasAndExternAliasDirective> externs, DiagnosticBag diagnostics) { Debug.Assert(usingAliases != null); Debug.Assert(!usings.IsDefault); Debug.Assert(!externs.IsDefault); _compilation = compilation; this.UsingAliases = usingAliases; this.Usings = usings; _diagnostics = diagnostics; this.ExternAliases = externs; if (_compilation != null) { _state = SymbolCompletionState.Create(_compilation.Language); } else { _state = null; } }
/// <summary> /// Create a duplicate of this compilation with different symbol instances. /// </summary> protected override LanguageCompilation CreateNew( string assemblyName, LanguageCompilationOptions options, IEnumerable <MetadataReference> references, LanguageCompilation previousSubmission, Type submissionReturnType, Type hostObjectType, bool isSubmission, ReferenceManager referenceManager, bool reuseReferenceManager, SyntaxAndDeclarationManager syntaxAndDeclarations, AsyncQueue <CompilationEvent> eventQueue = null) { return(new MetaCompilation( assemblyName, (MetaCompilationOptions)options, references, (MetaCompilation)previousSubmission, submissionReturnType, hostObjectType, isSubmission, referenceManager, reuseReferenceManager, syntaxAndDeclarations, eventQueue)); }
internal LanguageScriptCompilationInfo(LanguageCompilation previousCompilationOpt, Type returnType, Type globalsType) : base(returnType, globalsType) { Debug.Assert(previousCompilationOpt == null || previousCompilationOpt.HostObjectType == globalsType); PreviousScriptCompilation = previousCompilationOpt; }
/// <summary> /// Construct context /// </summary> public RegionAnalysisContext(LanguageCompilation compilation, Symbol member, BoundNode boundNode, BoundNode firstInRegion, BoundNode lastInRegion) { this.Compilation = compilation; this.Member = member; this.BoundNode = boundNode; this.FirstInRegion = firstInRegion; this.LastInRegion = lastInRegion; this.Failed = boundNode == null || firstInRegion == null || lastInRegion == null || firstInRegion.Syntax.SpanStart > lastInRegion.Syntax.Span.End; if (!this.Failed && ReferenceEquals(firstInRegion, lastInRegion)) { throw new NotImplementedException("TODO:MetaDslx"); /*switch (firstInRegion.Kind) * { * case BoundKind.NamespaceExpression: * case BoundKind.TypeExpression: * * // Some bound nodes are still considered to be invalid for flow analysis * this.Failed = true; * break; * }*/ } }
/// <summary> /// Check all generic constraints on the given type and any containing types /// (such as A<T> in A<T>.B<U>). This includes checking constraints /// on generic types within the type (such as B<T> in A<B<T>[]>). /// </summary> public virtual void CheckAllConstraints( LanguageCompilation compilation, ConversionsBase conversions, Location location, DiagnosticBag diagnostics) { // TODO:MetaDslx }
public static Imports FromCustomDebugInfo( LanguageCompilation compilation, ImmutableDictionary <string, AliasAndUsingDirective> usingAliases, ImmutableArray <NamespaceOrTypeAndUsingDirective> usings, ImmutableArray <AliasAndExternAliasDirective> externs) { return(new Imports(compilation, usingAliases, usings, externs, diagnostics: null)); }
public Binder(Binder next, Conversions conversions = null) { Debug.Assert(next != null); _next = next; this.Flags = next.Flags; _compilation = next._compilation; _lazyConversions = conversions; }
private static void MarkImportDirective(LanguageCompilation compilation, LanguageSyntaxNode directive, bool callerIsSemanticModel) { Debug.Assert(compilation != null); // If any directives are used, then there must be a compilation. if (directive != null && !callerIsSemanticModel) { compilation.MarkImportDirectiveAsUsed(directive); } }
/// <summary> /// Create a metadata reference to a compilation. /// </summary> /// <param name="compilation">The compilation to reference.</param> /// <param name="aliases">Extern aliases for this reference.</param> /// <param name="embedInteropTypes">Should interop types be embedded in the created assembly?</param> public LanguageCompilationReference( LanguageCompilation compilation, ImmutableArray <string> aliases = default(ImmutableArray <string>), bool embedInteropTypes = false) : base(GetProperties(compilation, aliases, embedInteropTypes)) { this.Compilation = compilation; }
internal virtual void AddDeclarationDiagnostics(DiagnosticBag diagnostics) { if (!diagnostics.IsEmptyWithoutResolution) { LanguageCompilation compilation = this.DeclaringCompilation; Debug.Assert(compilation != null); compilation.DeclarationDiagnostics.AddRange(diagnostics); } }
// The merged-tree-reuse story goes like this. We have a "forest" of old declarations, and // possibly a lone tree of new declarations. We construct a merged declaration by merging // together everything in the forest. This we can re-use from edit to edit, provided that // nothing is added to or removed from the forest. We construct a merged declaration from // the lone tree if there is one. (The lone tree might have nodes inside it that need // merging, if there are two halves of one partial class.) Once we have two merged trees, we // construct the full merged tree by merging them both together. So, diagrammatically, we // have: // // MergedRoot // / \ // old merged root new merged root // / | | | \ \ // old singles forest new single tree public MergedDeclaration GetMergedRoot(LanguageCompilation compilation) { Debug.Assert(compilation.Declarations == this); if (_mergedRoot == null) { Interlocked.CompareExchange(ref _mergedRoot, CalculateMergedRoot(compilation), null); } return(_mergedRoot); }
protected BinderFactory(LanguageCompilation compilation, SyntaxTree syntaxTree) { _compilation = compilation; _syntaxTree = syntaxTree; _binderFactoryVisitorPool = new ObjectPool <BinderFactoryVisitor>(() => Language.CompilationFactory.CreateBinderFactoryVisitor(this), 64); _buckStopsHereBinder = new BuckStopsHereBinder(compilation); }
public BoundTree(LanguageCompilation compilation, LanguageSyntaxTree syntaxTree, Binder rootBinder, DiagnosticBag diagnostics) { _compilation = compilation; _syntaxTree = syntaxTree; _rootBinder = rootBinder; _diagnostics = diagnostics; _boundNodeFactoryVisitorPool = new ObjectPool <BoundNodeFactoryVisitor>(() => Language.CompilationFactory.CreateBoundNodeFactoryVisitor(this), 64); _isBindableNodeVisitorPool = new ObjectPool <IsBindableNodeVisitor>(() => Language.CompilationFactory.CreateIsBindableNodeVisitor(this), 64); }
public LexicalSortKey GetLexicalSortKey(LanguageCompilation compilation) { LexicalSortKey sortKey = new LexicalSortKey(Declarations[0].NameLocation, compilation); for (var i = 1; i < Declarations.Length; i++) { sortKey = LexicalSortKey.First(sortKey, new LexicalSortKey(Declarations[i].NameLocation, compilation)); } return(sortKey); }
internal CachingBinderFactory(LanguageCompilation compilation, SyntaxTree syntaxTree) : base(compilation, syntaxTree) { // 50 is more or less a guess, but it seems to work fine for scenarios that I tried. // we need something big enough to keep binders for most classes and some methods // in a typical syntax tree. // On the other side, note that the whole factory is weakly referenced and therefore short lived, // making this cache big is not very useful. // I noticed that while compiling Roslyn C# compiler most caches never see // more than 50 items added before getting collected. _binderCache = new ConcurrentCache <BinderCacheKey, Binder>(50); }
internal SyntaxTreeSemanticModel(LanguageCompilation compilation, LanguageSyntaxTree syntaxTree, bool ignoreAccessibility = false) { _compilation = compilation; _ignoresAccessibility = ignoreAccessibility; if (!this.Compilation.SyntaxTrees.Contains(syntaxTree)) { throw new ArgumentOutOfRangeException(nameof(syntaxTree), CSharpResources.TreeNotPartOfCompilation); } _boundTree = new BoundTree(compilation, syntaxTree, compilation.GetBinder(syntaxTree.GetRootNode()), _ignoredDiagnostics); _binderFactory = compilation.GetBinderFactory(SyntaxTree); }
public bool CheckAllConstraints( LanguageCompilation compilation, ConversionsBase conversions) { var diagnostics = DiagnosticBag.GetInstance(); // Nullability checks can only add warnings here so skip them for this check as we are only // concerned with errors. CheckAllConstraints(compilation, conversions, NoLocation.Singleton, diagnostics); bool ok = !diagnostics.HasAnyErrors(); diagnostics.Free(); return(ok); }
internal NamespaceSymbol GetConstituentForCompilation(LanguageCompilation compilation) { //return namespacesToMerge.FirstOrDefault(n => n.IsFromSource); //Replace above code with that below to eliminate allocation of array enumerator. foreach (var n in _namespacesToMerge) { if (n.IsFromCompilation(compilation)) { return(n); } } return(null); }
/// <summary> /// Is a member with declared accessibility "declaredAccessibility" accessible from within /// "within", which must be a named type or an assembly. /// </summary> private static bool IsMemberAccessible( NamedTypeSymbol containingType, // the symbol's containing type Accessibility declaredAccessibility, Symbol within, TypeSymbol throughTypeOpt, out bool failedThroughTypeCheck, LanguageCompilation compilation, ref HashSet <DiagnosticInfo> useSiteDiagnostics, ConsList <TypeSymbol> basesBeingResolved = null) { Debug.Assert(within is NamedTypeSymbol || within is AssemblySymbol); Debug.Assert((object)containingType != null); failedThroughTypeCheck = false; if (containingType.IsTupleType) { containingType = containingType.TupleUnderlyingType; } // easy case - members of containing type are accessible. if ((object)containingType == (object)within) { return(true); } // A nested symbol is only accessible to us if its container is accessible as well. if (!IsNamedTypeAccessible(containingType, within, ref useSiteDiagnostics, basesBeingResolved)) { return(false); } // public in accessible type is accessible if (declaredAccessibility == Accessibility.Public) { return(true); } return(IsNonPublicMemberAccessible( containingType, declaredAccessibility, within, throughTypeOpt, out failedThroughTypeCheck, compilation, ref useSiteDiagnostics, basesBeingResolved)); }
private static ImmutableArray <AliasAndExternAliasDirective> BuildExternAliases( ImmutableArray <ExternAliasDirective> directiveList, InContainerBinder binder, DiagnosticBag diagnostics) { LanguageCompilation compilation = binder.Compilation; SyntaxFacts syntaxFacts = compilation.Language.SyntaxFacts; var builder = ArrayBuilder <AliasAndExternAliasDirective> .GetInstance(); foreach (ExternAliasDirective aliasSyntax in directiveList) { compilation.RecordImport(aliasSyntax); // Extern aliases not allowed in interactive submissions: if (compilation.IsSubmission) { diagnostics.Add(InternalErrorCode.ERR_ExternAliasNotAllowed, aliasSyntax.Location); continue; } string aliasName = syntaxFacts.ExtractName(aliasSyntax.AliasName); // some n^2 action, but n should be very small. foreach (var existingAlias in builder) { if (existingAlias.Alias.Name == aliasName) { diagnostics.Add(InternalErrorCode.ERR_DuplicateAlias, existingAlias.Alias.Locations[0], existingAlias.Alias.Name); break; } } /* TODO:MetaDslx? * if (aliasSyntax.Identifier.ContextualKind() == SyntaxKind.GlobalKeyword) * { * diagnostics.Add(InternalErrorCode.ERR_GlobalExternAlias, aliasSyntax.Identifier.GetLocation()); * } */ builder.Add(new AliasAndExternAliasDirective(AliasSymbol.CreateExternAlias(aliasName, aliasSyntax, binder), aliasSyntax)); } return(builder.ToImmutableAndFree()); }
internal AliasSymbol ToNewSubmission(LanguageCompilation compilation) { Debug.Assert(_binder.Compilation.IsSubmission); // We can pass basesBeingResolved: null because base type cycles can't cross // submission boundaries - there's no way to depend on a subsequent submission. var previousTarget = GetAliasTarget(basesBeingResolved: null); if (previousTarget.Kind != LanguageSymbolKind.Namespace) { return(this); } var expandedGlobalNamespace = compilation.GlobalNamespace; var expandedNamespace = (NamespaceOrTypeSymbol)Imports.ExpandPreviousSubmissionNamespace((NamespaceSymbol)previousTarget, expandedGlobalNamespace); var binder = new InContainerBinder(expandedGlobalNamespace, new BuckStopsHereBinder(compilation)); return(new AliasSymbol(binder, expandedNamespace, _aliasName, _locations)); }
private LanguageCompilationReference(LanguageCompilation compilation, MetadataReferenceProperties properties) : base(properties) { this.Compilation = compilation; }
private readonly LookupResultKind _resultKind; // why the guessSymbols were wrong. internal ExtendedErrorTypeSymbol(LanguageCompilation compilation, string name, string metadataName, DiagnosticInfo errorInfo, bool unreported = false, bool variableUsedBeforeDeclaration = false) : this(compilation.Assembly.GlobalNamespace, name, metadataName, errorInfo, unreported, variableUsedBeforeDeclaration) { }
public BuckStopsHereBinder(LanguageCompilation compilation) : base(compilation) { }
// TODO (https://github.com/dotnet/roslyn/issues/5517): skip namespace expansion if references haven't changed. internal static Imports ExpandPreviousSubmissionImports(Imports previousSubmissionImports, LanguageCompilation newSubmission) { if (previousSubmissionImports == Empty) { return(Empty); } Debug.Assert(previousSubmissionImports != null); Debug.Assert(previousSubmissionImports._compilation.IsSubmission); Debug.Assert(newSubmission.IsSubmission); var expandedGlobalNamespace = newSubmission.GlobalNamespace; var expandedAliases = ImmutableDictionary <string, AliasAndUsingDirective> .Empty; if (!previousSubmissionImports.UsingAliases.IsEmpty) { var expandedAliasesBuilder = ImmutableDictionary.CreateBuilder <string, AliasAndUsingDirective>(); foreach (var pair in previousSubmissionImports.UsingAliases) { var name = pair.Key; var directive = pair.Value; expandedAliasesBuilder.Add(name, new AliasAndUsingDirective(directive.Alias.ToNewSubmission(newSubmission), directive.UsingDirective)); } expandedAliases = expandedAliasesBuilder.ToImmutable(); } var expandedUsings = ImmutableArray <NamespaceOrTypeAndUsingDirective> .Empty; if (!previousSubmissionImports.Usings.IsEmpty) { var expandedUsingsBuilder = ArrayBuilder <NamespaceOrTypeAndUsingDirective> .GetInstance(previousSubmissionImports.Usings.Length); foreach (var previousUsing in previousSubmissionImports.Usings) { var previousTarget = previousUsing.NamespaceOrType; if (previousTarget.IsType) { expandedUsingsBuilder.Add(previousUsing); } else { var expandedNamespace = ExpandPreviousSubmissionNamespace((NamespaceSymbol)previousTarget, expandedGlobalNamespace); expandedUsingsBuilder.Add(new NamespaceOrTypeAndUsingDirective(expandedNamespace, previousUsing.UsingDirective)); } } expandedUsings = expandedUsingsBuilder.ToImmutableAndFree(); } return(new Imports( newSubmission, expandedAliases, expandedUsings, previousSubmissionImports.ExternAliases, diagnostics: null)); }
public static Imports FromGlobalUsings(LanguageCompilation compilation) { var usings = compilation.Options.Usings; if (usings.Length == 0 && compilation.PreviousSubmission == null) { return(Empty); } var diagnostics = new DiagnosticBag(); var usingsBinder = new InContainerBinder(compilation.GlobalNamespace, new BuckStopsHereBinder(compilation)); var boundUsings = ArrayBuilder <NamespaceOrTypeAndUsingDirective> .GetInstance(); var uniqueUsings = PooledHashSet <NamespaceOrTypeSymbol> .GetInstance(); var syntaxFacts = compilation.Language.SyntaxFacts; foreach (string @using in usings) { if ([email protected]()) { continue; } var qualifiedName = syntaxFacts.ExtractQualifiedName(@using); var imported = usingsBinder.BindNamespaceOrTypeSymbol(qualifiedName, diagnostics); if (uniqueUsings.Add(imported)) { boundUsings.Add(new NamespaceOrTypeAndUsingDirective(imported, null)); } } if (diagnostics.IsEmptyWithoutResolution) { diagnostics = null; } var previousSubmissionImports = compilation.PreviousSubmission?.GlobalImports; if (previousSubmissionImports != null) { // Currently, only usings are supported. Debug.Assert(previousSubmissionImports.UsingAliases.IsEmpty); Debug.Assert(previousSubmissionImports.ExternAliases.IsEmpty); var expandedImports = ExpandPreviousSubmissionImports(previousSubmissionImports, compilation); foreach (var previousUsing in expandedImports.Usings) { if (uniqueUsings.Add(previousUsing.NamespaceOrType)) { boundUsings.Add(previousUsing); } } } uniqueUsings.Free(); if (boundUsings.Count == 0) { boundUsings.Free(); return(Empty); } return(new Imports(compilation, ImmutableDictionary <string, AliasAndUsingDirective> .Empty, boundUsings.ToImmutableAndFree(), ImmutableArray <AliasAndExternAliasDirective> .Empty, diagnostics)); }
internal AnonymousTypeManager(LanguageCompilation compilation) { Debug.Assert(compilation != null); this.Compilation = compilation; }
/// <summary> /// Create a NamespaceExtent that represents a given Compilation. /// </summary> internal NamespaceExtent(LanguageCompilation compilation) { _kind = NamespaceKind.Compilation; _symbolOrCompilation = compilation; }