Exemplo n.º 1
0
 internal static SymbolInfo Create(ImmutableArray <Symbol> symbols, LookupResultKind resultKind, bool isDynamic)
 {
     if (isDynamic)
     {
         if (symbols.Length == 1)
         {
             return(new SymbolInfo(symbols[0], CandidateReason.LateBound));
         }
         else
         {
             return(new SymbolInfo(StaticCast <ISymbol> .From(symbols), CandidateReason.LateBound));
         }
     }
     else if (resultKind == LookupResultKind.Viable)
     {
         if (symbols.Length > 0)
         {
             Debug.Assert(symbols.Length == 1);
             return(new SymbolInfo(symbols[0]));
         }
         else
         {
             return(SymbolInfo.None);
         }
     }
     else
     {
         return(new SymbolInfo(StaticCast <ISymbol> .From(symbols), (symbols.Length > 0) ? resultKind.ToCandidateReason() : CandidateReason.None));
     }
 }
Exemplo n.º 2
0
 public override bool Visit(StaticCast node)
 {
     Visit((LvalueExpression)node);
     TraversePrint(node.casttype);
     TraversePrint(node.expr);
     return(true);
 }
Exemplo n.º 3
0
        public sealed override ImmutableArray <NamedTypeSymbol> GetTypeMembers(string name)
        {
            EnsureAllMembersLoaded();

            ImmutableArray <PENamedTypeSymbol> t;

#if XSHARP
            // When we have siblings then collect all types from all siblings
            if (!siblings.IsEmpty)
            {
                var builder = ArrayBuilder <NamedTypeSymbol> .GetInstance();

                foreach (var ns in siblings)
                {
                    if (ns.lazyTypes.TryGetValue(name, out t))
                    {
                        builder.AddRange(t);
                    }
                }
                return(builder.ToImmutableAndFree());
            }
#endif
            return(lazyTypes.TryGetValue(name, out t)
                ? StaticCast <NamedTypeSymbol> .From(t)
                : ImmutableArray <NamedTypeSymbol> .Empty);
        }
Exemplo n.º 4
0
        public sealed override ImmutableArray <Symbol> GetMembers(string name)
        {
            EnsureAllMembersLoaded();

            PENestedNamespaceSymbol            ns = null;
            ImmutableArray <PENamedTypeSymbol> t;

            if (lazyNamespaces.TryGetValue(name, out ns))
            {
                if (lazyTypes.TryGetValue(name, out t))
                {
                    // TODO - Eliminate the copy by storing all members and type members instead of non-type and type members?
                    return(StaticCast <Symbol> .From(t).Add(ns));
                }
                else
                {
                    return(ImmutableArray.Create <Symbol>(ns));
                }
            }
            else if (lazyTypes.TryGetValue(name, out t))
            {
                return(StaticCast <Symbol> .From(t));
            }

            return(ImmutableArray <Symbol> .Empty);
        }
Exemplo n.º 5
0
        public sealed override ImmutableArray <NamedTypeSymbol> GetTypeMembers(string name)
        {
            EnsureAllMembersLoaded();

            ImmutableArray <PENamedTypeSymbol> t;

            return(lazyTypes.TryGetValue(name, out t)
                ? StaticCast <NamedTypeSymbol> .From(t)
                : ImmutableArray <NamedTypeSymbol> .Empty);
        }
Exemplo n.º 6
0
        private ImmutableArray <NamedTypeSymbol> GetMemberTypesPrivate()
        {
            //assume that EnsureAllMembersLoaded() has initialize lazyTypes
            if (_lazyFlattenedTypes.IsDefault)
            {
                var flattened = lazyTypes.Flatten();
                ImmutableInterlocked.InterlockedExchange(ref _lazyFlattenedTypes, flattened);
            }

            return(StaticCast <NamedTypeSymbol> .From(_lazyFlattenedTypes));
        }
Exemplo n.º 7
0
        public sealed override ImmutableArray <Symbol> GetMembers(string name)
        {
            EnsureAllMembersLoaded();

            ImmutableArray <NamedTypeSymbol> t;

            if (_types.TryGetValue(name, out t))
            {
                return(StaticCast <Symbol> .From(t));
            }

            return(ImmutableArray <Symbol> .Empty);
        }
Exemplo n.º 8
0
        public sealed override ImmutableArray <Symbol> GetMembers(string name)
        {
            EnsureAllMembersLoaded();

            PENestedNamespaceSymbol            ns = null;
            ImmutableArray <PENamedTypeSymbol> t;

#if XSHARP
            // When we have siblings then collect all members from all siblings
            if (!siblings.IsEmpty)
            {
                var builder = ArrayBuilder <Symbol> .GetInstance();

                foreach (var sib in siblings)
                {
                    sib.EnsureAllMembersLoaded();
                    if (sib.lazyNamespaces.TryGetValue(name, out ns))
                    {
                        builder.AddRange(ns);
                    }
                    if (sib.lazyTypes.TryGetValue(name, out t))
                    {
                        builder.AddRange(t);
                    }
                }
                return(builder.ToImmutableAndFree());
            }
#endif

            if (lazyNamespaces.TryGetValue(name, out ns))
            {
                if (lazyTypes.TryGetValue(name, out t))
                {
                    // TODO - Eliminate the copy by storing all members and type members instead of non-type and type members?
                    return(StaticCast <Symbol> .From(t).Add(ns));
                }
                else
                {
                    return(ImmutableArray.Create <Symbol>(ns));
                }
            }
            else if (lazyTypes.TryGetValue(name, out t))
            {
                return(StaticCast <Symbol> .From(t));
            }

            return(ImmutableArray <Symbol> .Empty);
        }
Exemplo n.º 9
0
        public sealed override ImmutableArray <Symbol> GetMembers(string name)
        {
            if (_unbound)
            {
                return(StaticCast <Symbol> .From(GetTypeMembers(name)));
            }

            ImmutableArray <Symbol> result;
            var cache = _lazyMembersByNameCache;

            if (cache != null && cache.TryGetValue(name, out result))
            {
                return(result);
            }

            return(GetMembersWorker(name));
        }
Exemplo n.º 10
0
        private static void AddNestedTypesToDictionary(Dictionary <string, ImmutableArray <Symbol> > membersByName, Dictionary <string, ImmutableArray <NamedTypeSymbol> > typesByName)
        {
            foreach (var pair in typesByName)
            {
                string name = pair.Key;
                ImmutableArray <NamedTypeSymbol> types          = pair.Value;
                ImmutableArray <Symbol>          typesAsSymbols = StaticCast <Symbol> .From(types);

                ImmutableArray <Symbol> membersForName;
                if (membersByName.TryGetValue(name, out membersForName))
                {
                    membersByName[name] = membersForName.Concat(typesAsSymbols);
                }
                else
                {
                    membersByName.Add(name, typesAsSymbols);
                }
            }
        }
Exemplo n.º 11
0
            /// <summary>
            /// Given a SynthesizedSealedPropertyAccessor (an accessor with a reference to the accessor it overrides),
            /// construct a BoundBlock body.
            /// </summary>
            internal override void GenerateMethodBody(
                TypeCompilationState compilationState,
                BindingDiagnosticBag diagnostics
                )
            {
                SyntheticBoundNodeFactory F = new SyntheticBoundNodeFactory(
                    this,
                    this.GetNonNullSyntaxNode(),
                    compilationState,
                    diagnostics
                    );

                F.CurrentFunction = this.OriginalDefinition;

                try
                {
                    MethodSymbol methodBeingWrapped = this.BaseMethod;

                    if (this.Arity > 0)
                    {
                        Debug.Assert(this.Arity == methodBeingWrapped.Arity);
                        methodBeingWrapped = methodBeingWrapped.ConstructedFrom.Construct(
                            StaticCast <TypeSymbol> .From(this.TypeParameters)
                            );
                    }

                    BoundBlock body = MethodBodySynthesizer.ConstructSingleInvocationMethodBody(
                        F,
                        methodBeingWrapped,
                        useBaseReference: true
                        );
                    if (body.Kind != BoundKind.Block)
                    {
                        body = F.Block(body);
                    }
                    F.CompilationState.AddMethodWrapper(methodBeingWrapped, this, body);
                }
                catch (SyntheticBoundNodeFactory.MissingPredefinedMember ex)
                {
                    diagnostics.Add(ex.Diagnostic);
                }
            }
Exemplo n.º 12
0
            public Dictionary <String, ImmutableArray <NamespaceOrTypeSymbol> > CreateMap()
            {
                var result = new Dictionary <String, ImmutableArray <NamespaceOrTypeSymbol> >(_dictionary.Count, StringOrdinalComparer.Instance);

                foreach (var kvp in _dictionary)
                {
                    object value = kvp.Value;
                    ImmutableArray <NamespaceOrTypeSymbol> members;

                    var builder = value as ArrayBuilder <NamespaceOrTypeSymbol>;
                    if (builder != null)
                    {
                        Debug.Assert(builder.Count > 1);
                        bool hasNamespaces = false;
                        for (int i = 0; (i < builder.Count) && !hasNamespaces; i++)
                        {
                            hasNamespaces |= (builder[i].Kind == SymbolKind.Namespace);
                        }

                        members = hasNamespaces
                            ? builder.ToImmutable()
                            : StaticCast <NamespaceOrTypeSymbol> .From(builder.ToDowncastedImmutable <NamedTypeSymbol>());

                        builder.Free();
                    }
                    else
                    {
                        NamespaceOrTypeSymbol symbol = (NamespaceOrTypeSymbol)value;

                        #region PackageTemplate - SourceNamespaceSymbol - SymbolKind.Template
                        members = (symbol.Kind == SymbolKind.Namespace || symbol.Kind == SymbolKind.Template)
                            ? ImmutableArray.Create <NamespaceOrTypeSymbol>(symbol)
                            : StaticCast <NamespaceOrTypeSymbol> .From(ImmutableArray.Create <NamedTypeSymbol>((NamedTypeSymbol)symbol));

                        #endregion
                    }

                    result.Add(kvp.Key, members);
                }

                return(result);
            }
Exemplo n.º 13
0
            public Dictionary <String, ImmutableArray <NamespaceOrTypeSymbol> > CreateMap()
            {
                var result = new Dictionary <String, ImmutableArray <NamespaceOrTypeSymbol> >(this.dictionary.Count);

                foreach (var kvp in this.dictionary)
                {
                    object value = kvp.Value;
                    ImmutableArray <NamespaceOrTypeSymbol> members;

                    var builder = value as ArrayBuilder <NamespaceOrTypeSymbol>;
                    if (builder != null)
                    {
                        Debug.Assert(builder.Count > 1);
                        bool hasNamespaces = false;
                        for (int i = 0; (i < builder.Count) && !hasNamespaces; i++)
                        {
                            hasNamespaces |= (builder[i].Kind == SymbolKind.Namespace);
                        }

                        members = hasNamespaces
                            ? builder.ToImmutable()
                            : StaticCast <NamespaceOrTypeSymbol> .From(builder.ToDowncastedImmutable <NamedTypeSymbol>());

                        builder.Free();
                    }
                    else
                    {
                        NamespaceOrTypeSymbol symbol = (NamespaceOrTypeSymbol)value;
                        members = symbol.Kind == SymbolKind.Namespace
                            ? ImmutableArray.Create <NamespaceOrTypeSymbol>(symbol)
                            : StaticCast <NamespaceOrTypeSymbol> .From(ImmutableArray.Create <NamedTypeSymbol>((NamedTypeSymbol)symbol));
                    }

                    result.Add(kvp.Key, members);
                }

                return(result);
            }
Exemplo n.º 14
0
        /// <summary>
        /// If we have a WinRT type event, we need to encapsulate the adder call
        /// (which returns an EventRegistrationToken) with a call to
        /// WindowsRuntimeMarshal.AddEventHandler or RemoveEventHandler, but these
        /// require us to create a new Func representing the adder and another
        /// Action representing the Remover.
        ///
        /// The rewritten call looks something like:
        ///
        /// WindowsRuntimeMarshal.AddEventHandler&lt;EventHandler&gt;
        ///     (new Func&lt;EventHandler, EventRegistrationToken&gt;(@object.add),
        ///      new Action&lt;EventRegistrationToken&gt;(@object.remove), handler);
        ///
        /// Where @object is a compiler-generated local temp if needed.
        /// </summary>
        /// <remarks>
        /// TODO: use or delete isDynamic.
        /// </remarks>
        private BoundExpression RewriteWindowsRuntimeEventAssignmentOperator(SyntaxNode syntax, EventSymbol eventSymbol, EventAssignmentKind kind, bool isDynamic, BoundExpression rewrittenReceiverOpt, BoundExpression rewrittenArgument)
        {
            BoundAssignmentOperator tempAssignment = null;
            BoundLocal boundTemp = null;

            if (!eventSymbol.IsStatic && CanChangeValueBetweenReads(rewrittenReceiverOpt))
            {
                boundTemp = _factory.StoreToTemp(rewrittenReceiverOpt, out tempAssignment);
            }

            NamedTypeSymbol tokenType   = _factory.WellKnownType(WellKnownType.System_Runtime_InteropServices_WindowsRuntime_EventRegistrationToken);
            NamedTypeSymbol marshalType = _factory.WellKnownType(WellKnownType.System_Runtime_InteropServices_WindowsRuntime_WindowsRuntimeMarshal);

            NamedTypeSymbol actionType = _factory.WellKnownType(WellKnownType.System_Action_T).Construct(tokenType);

            TypeSymbol eventType = eventSymbol.Type;

            BoundExpression delegateCreationArgument = boundTemp ?? rewrittenReceiverOpt ?? _factory.Type(eventType);

            BoundDelegateCreationExpression removeDelegate = new BoundDelegateCreationExpression(
                syntax: syntax,
                argument: delegateCreationArgument,
                methodOpt: eventSymbol.RemoveMethod,
                isExtensionMethod: false,
                type: actionType);

            BoundExpression clearCall = null;

            if (kind == EventAssignmentKind.Assignment)
            {
                MethodSymbol clearMethod;
                if (TryGetWellKnownTypeMember(syntax, WellKnownMember.System_Runtime_InteropServices_WindowsRuntime_WindowsRuntimeMarshal__RemoveAllEventHandlers, out clearMethod))
                {
                    clearCall = MakeCall(
                        syntax: syntax,
                        rewrittenReceiver: null,
                        method: clearMethod,
                        rewrittenArguments: ImmutableArray.Create <BoundExpression>(removeDelegate),
                        type: clearMethod.ReturnType);
                }
                else
                {
                    clearCall = new BoundBadExpression(syntax, LookupResultKind.NotInvocable, ImmutableArray <Symbol> .Empty, ImmutableArray.Create <BoundNode>(removeDelegate), ErrorTypeSymbol.UnknownResultType);
                }
            }

            ImmutableArray <BoundExpression> marshalArguments;
            WellKnownMember helper;

            if (kind == EventAssignmentKind.Subtraction)
            {
                helper           = WellKnownMember.System_Runtime_InteropServices_WindowsRuntime_WindowsRuntimeMarshal__RemoveEventHandler_T;
                marshalArguments = ImmutableArray.Create <BoundExpression>(removeDelegate, rewrittenArgument);
            }
            else
            {
                NamedTypeSymbol func2Type = _factory.WellKnownType(WellKnownType.System_Func_T2).Construct(eventType, tokenType);

                BoundDelegateCreationExpression addDelegate = new BoundDelegateCreationExpression(
                    syntax: syntax,
                    argument: delegateCreationArgument,
                    methodOpt: eventSymbol.AddMethod,
                    isExtensionMethod: false,
                    type: func2Type);

                helper           = WellKnownMember.System_Runtime_InteropServices_WindowsRuntime_WindowsRuntimeMarshal__AddEventHandler_T;
                marshalArguments = ImmutableArray.Create <BoundExpression>(addDelegate, removeDelegate, rewrittenArgument);
            }

            BoundExpression marshalCall;

            MethodSymbol marshalMethod;

            if (TryGetWellKnownTypeMember(syntax, helper, out marshalMethod))
            {
                marshalMethod = marshalMethod.Construct(eventType);

                marshalCall = MakeCall(
                    syntax: syntax,
                    rewrittenReceiver: null,
                    method: marshalMethod,
                    rewrittenArguments: marshalArguments,
                    type: marshalMethod.ReturnType);
            }
            else
            {
                marshalCall = new BoundBadExpression(syntax, LookupResultKind.NotInvocable, ImmutableArray <Symbol> .Empty, StaticCast <BoundNode> .From(marshalArguments), ErrorTypeSymbol.UnknownResultType);
            }

            // In this case, we don't need a sequence.
            if (boundTemp == null && clearCall == null)
            {
                return(marshalCall);
            }

            ImmutableArray <LocalSymbol> tempSymbols = boundTemp == null
                ? ImmutableArray <LocalSymbol> .Empty
                : ImmutableArray.Create <LocalSymbol>(boundTemp.LocalSymbol);

            ArrayBuilder <BoundExpression> sideEffects = ArrayBuilder <BoundExpression> .GetInstance(2); //max size

            if (clearCall != null)
            {
                sideEffects.Add(clearCall);
            }
            if (tempAssignment != null)
            {
                sideEffects.Add(tempAssignment);
            }
            Debug.Assert(sideEffects.Any(), "Otherwise, we shouldn't be building a sequence");

            return(new BoundSequence(syntax, tempSymbols, sideEffects.ToImmutableAndFree(), marshalCall, marshalCall.Type));
        }
Exemplo n.º 15
0
 ImmutableArray <Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(EmitContext context)
 {
     CheckDefinitionInvariant();
     return(StaticCast <Cci.IParameterTypeInformation> .From(this.Parameters));
 }
Exemplo n.º 16
0
 protected override ImmutableArray <SingleNamespaceOrTypeDeclaration> GetNamespaceOrTypeDeclarationChildren()
 {
     return(StaticCast <SingleNamespaceOrTypeDeclaration> .From(_children));
 }
Exemplo n.º 17
0
 ImmutableArray <AttributeData> ISymbol.GetAttributes()
 {
     return(StaticCast <AttributeData> .From(UnderlyingSymbol.GetAttributes()));
 }
Exemplo n.º 18
0
 protected override ImmutableArray <Declaration> GetDeclarationChildren()
 {
     return(StaticCast <Declaration> .From(this.GetNamespaceOrTypeDeclarationChildren()));
 }
Exemplo n.º 19
0
 public ImmutableArray <Cci.IParameterTypeInformation> GetParameters(EmitContext context)
 {
     return(StaticCast <Cci.IParameterTypeInformation> .From(_parameters));
 }
Exemplo n.º 20
0
 // Only when the caller passes allowAlpha=true do we tolerate substituted (alpha-renamed) type parameters as keys
 internal TypeMap(ImmutableArray <TypeParameterSymbol> from, ImmutableArray <TypeParameterSymbol> to, bool allowAlpha = false)
     : this(from, StaticCast <TypeSymbol> .From(to), allowAlpha)
 {
     // mapping contents are read-only hereafter
 }
Exemplo n.º 21
0
 public virtual T Visit(StaticCast node)
 {
     Visit((LvalueExpression)node);
     traverse(node.casttype);
     return(traverse(node.expr));
 }