internal ModuleReference(PEModuleBuilder moduleBeingBuilt, ModuleSymbol underlyingModule)
        {
            Debug.Assert(moduleBeingBuilt != null);
            Debug.Assert((object)underlyingModule != null);

            this.moduleBeingBuilt = moduleBeingBuilt;
            this.underlyingModule = underlyingModule;
        }
        internal SynthesizedGlobalMethodSymbol(ModuleSymbol containingModule, PrivateImplementationDetails privateImplType, TypeSymbol returnType, string name)
        {
            Debug.Assert((object)containingModule != null);
            Debug.Assert(privateImplType != null);
            Debug.Assert((object)returnType != null);
            Debug.Assert(name != null);

            _containingModule = containingModule;
            _privateImplType = privateImplType;
            _returnType = returnType;
            _name = name;
        }
 internal NamespaceSymbol Get_System_NamespaceSymbol(ModuleSymbol m)
 {
     var assembly = m.ContainingSymbol;
     SourceAssemblySymbol sourceAssembly = assembly as SourceAssemblySymbol;
     if (sourceAssembly != null)
     {
         return sourceAssembly.DeclaringCompilation.GlobalNamespace.GetMember<NamespaceSymbol>("System");
     }
     else
     {
         var peAssembly = (PEAssemblySymbol)assembly;
         return peAssembly.CorLibrary.GlobalNamespace.GetMember<NamespaceSymbol>("System");
     }
 }
        internal PEAssemblySymbol(PEAssembly assembly, DocumentationProvider documentationProvider, bool isLinked, MetadataImportOptions importOptions)
        {
            Debug.Assert(assembly != null);
            Debug.Assert(documentationProvider != null);
            _assembly = assembly;
            _documentationProvider = documentationProvider;

            var modules = new ModuleSymbol[assembly.Modules.Length];

            for (int i = 0; i < assembly.Modules.Length; i++)
            {
                modules[i] = new PEModuleSymbol(this, assembly.Modules[i], importOptions, i);
            }

            _modules = modules.AsImmutableOrNull();
            _isLinked = isLinked;
        }
Пример #5
0
 protected override IModuleReference TranslateModule(ModuleSymbol symbol, DiagnosticBag diagnostics)
 {
     var moduleSymbol = symbol as PEModuleSymbol;
     if ((object)moduleSymbol != null)
     {
         var module = moduleSymbol.Module;
         // Expose the individual runtime Windows.*.winmd modules as assemblies.
         // (The modules were wrapped in a placeholder Windows.winmd assembly
         // in MetadataUtilities.MakeAssemblyReferences.)
         if (MetadataUtilities.IsWindowsComponent(module.MetadataReader, module.Name) &&
             MetadataUtilities.IsWindowsAssemblyName(moduleSymbol.ContainingAssembly.Name))
         {
             var identity = module.ReadAssemblyIdentityOrThrow();
             return new Microsoft.CodeAnalysis.ExpressionEvaluator.AssemblyReference(identity);
         }
     }
     return base.TranslateModule(symbol, diagnostics);
 }
Пример #6
0
        // NOTE: assumes there's an event E in a type C.
        private static void ValidateEvent(ModuleSymbol module, bool isFromSource, bool isStatic, bool isFieldLike)
        {
            var @class = module.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
            var @event = @class.GetMember<EventSymbol>("E");

            Assert.Equal(SymbolKind.Event, @event.Kind);
            Assert.Equal(Accessibility.Public, @event.DeclaredAccessibility);
            Assert.Equal(isStatic, @event.IsStatic);
            Assert.False(@event.MustCallMethodsDirectly);

            var addMethod = @event.AddMethod;
            Assert.Equal(MethodKind.EventAdd, addMethod.MethodKind);
            Assert.Equal("void C.E.add", addMethod.ToTestDisplayString());
            addMethod.CheckAccessorShape(@event);

            var removeMethod = @event.RemoveMethod;
            Assert.Equal(MethodKind.EventRemove, removeMethod.MethodKind);
            Assert.Equal("void C.E.remove", removeMethod.ToTestDisplayString());
            removeMethod.CheckAccessorShape(@event);

            // Whether or not the event was field-like in source, it will look custom when loaded from metadata.
            if (isFieldLike && isFromSource)
            {
                Assert.True(@event.HasAssociatedField);
                var associatedField = @event.AssociatedField;
                Assert.Equal(SymbolKind.Field, associatedField.Kind);
                Assert.Equal(Accessibility.Private, associatedField.DeclaredAccessibility);
                Assert.Equal(isStatic, associatedField.IsStatic);
                Assert.Equal(@event.Type, associatedField.Type);
            }
            else
            {
                Assert.False(@event.HasAssociatedField);
                Assert.Null(@event.AssociatedField);
            }
        }
 private TopLevel(ModuleSymbol module, ref MetadataTypeName fullName, bool mangleName)
     : this(module, fullName.NamespaceName,
            mangleName ? fullName.UnmangledTypeName : fullName.TypeName,
            mangleName ? fullName.InferredArity : fullName.ForcedArity,
            mangleName)
 {
 }
Пример #8
0
        private void TestTypeAccessibilityHelper(ModuleSymbol module0)
        {
            var system = (from n in module0.GlobalNamespace.GetMembers()
                          where n.Kind == SymbolKind.Namespace && n.Name.Equals("System")
                          select n).Cast <NamespaceSymbol>().Single();

            var obj = (from t in system.GetTypeMembers()
                       where t.Name.Equals("Object")
                       select t).Single();

            Assert.Equal(Accessibility.Public, obj.DeclaredAccessibility);

            var frameworkAssembly = (from t in module0.GlobalNamespace.GetTypeMembers()
                                     where t.Name.Equals("FXAssembly")
                                     select t).Single();

            Assert.Equal(Accessibility.Internal, frameworkAssembly.DeclaredAccessibility);

            var @enum = (from t in system.GetTypeMembers()
                         where t.Name.Equals("Enum")
                         select t).Single();

            var console = (from t in system.GetTypeMembers()
                           where t.Name.Equals("Console")
                           select t).Single();

            var controlKeyState = (from t in console.GetTypeMembers()
                                   where t.Name.Equals("ControlKeyState")
                                   select t).Single();

            Assert.Equal(Accessibility.Internal, controlKeyState.DeclaredAccessibility);

            var activationContext = (from t in system.GetTypeMembers()
                                     where t.Name.Equals("ActivationContext")
                                     select t).Single();

            var contextForm = (from t in activationContext.GetTypeMembers()
                               where t.Name.Equals("ContextForm")
                               select t).Single();

            Assert.Equal(Accessibility.Public, contextForm.DeclaredAccessibility);

            var runtime = (from t in system.GetMembers()
                           where t.Kind == SymbolKind.Namespace && t.Name.Equals("Runtime")
                           select t).Cast <NamespaceSymbol>().Single();

            var remoting = (from t in runtime.GetMembers()
                            where t.Kind == SymbolKind.Namespace && t.Name.Equals("Remoting")
                            select t).Cast <NamespaceSymbol>().Single();

            var messaging = (from t in remoting.GetMembers()
                             where t.Kind == SymbolKind.Namespace && t.Name.Equals("Messaging")
                             select t).Cast <NamespaceSymbol>().Single();

            var messageSmuggler = (from t in messaging.GetTypeMembers()
                                   where t.Name.Equals("MessageSmuggler")
                                   select t).Single();

            var serializedArg = (from t in messageSmuggler.GetTypeMembers()
                                 where t.Name.Equals("SerializedArg")
                                 select t).Single();

            Assert.Equal(Accessibility.Protected, serializedArg.DeclaredAccessibility);

            var security = (from t in system.GetMembers()
                            where t.Kind == SymbolKind.Namespace && t.Name.Equals("Security")
                            select t).Cast <NamespaceSymbol>().Single();

            var accessControl = (from t in security.GetMembers()
                                 where t.Kind == SymbolKind.Namespace && t.Name.Equals("AccessControl")
                                 select t).Cast <NamespaceSymbol>().Single();

            var nativeObjectSecurity = (from t in accessControl.GetTypeMembers()
                                        where t.Name.Equals("NativeObjectSecurity")
                                        select t).Single();

            var exceptionFromErrorCode = (from t in nativeObjectSecurity.GetTypeMembers()
                                          where t.Name.Equals("ExceptionFromErrorCode")
                                          select t).Single();

            Assert.Equal(Accessibility.ProtectedOrInternal, exceptionFromErrorCode.DeclaredAccessibility);

            Assert.Same(module0, module0.GlobalNamespace.Locations.Single().MetadataModuleInternal);
            Assert.Same(module0, system.Locations.Single().MetadataModuleInternal);
            Assert.Same(module0, runtime.Locations.Single().MetadataModuleInternal);
            Assert.Same(module0, obj.Locations.Single().MetadataModuleInternal);
        }
Пример #9
0
        private void TestAttributeOnPartialMethodHelper(ModuleSymbol m, MethodSymbol fooMethod)
        {
            var a1Class = m.GlobalNamespace.GetTypeMember("A1");
            var a2Class = m.GlobalNamespace.GetTypeMember("A2");
            var b1Class = m.GlobalNamespace.GetTypeMember("B1");
            var b2Class = m.GlobalNamespace.GetTypeMember("B2");
            var c1Class = m.GlobalNamespace.GetTypeMember("C1");
            var c2Class = m.GlobalNamespace.GetTypeMember("C2");
            var d1Class = m.GlobalNamespace.GetTypeMember("D1");
            var d2Class = m.GlobalNamespace.GetTypeMember("D2");
            var e1Class = m.GlobalNamespace.GetTypeMember("E1");
            var e2Class = m.GlobalNamespace.GetTypeMember("E2");

            Assert.Equal(1, fooMethod.GetAttributes(a1Class).Count());
            Assert.Equal(1, fooMethod.GetAttributes(a2Class).Count());

            Assert.Equal(1, fooMethod.GetReturnTypeAttributes().Where(a => a.AttributeClass == b1Class).Count());
            Assert.Equal(1, fooMethod.GetReturnTypeAttributes().Where(a => a.AttributeClass == b2Class).Count());

            var typeParam1 = fooMethod.TypeParameters[0];
            Assert.Equal(1, typeParam1.GetAttributes(c1Class).Count());
            Assert.Equal(1, typeParam1.GetAttributes(c2Class).Count());

            var typeParam2 = fooMethod.TypeParameters[1];
            Assert.Equal(1, typeParam2.GetAttributes(d1Class).Count());
            Assert.Equal(1, typeParam2.GetAttributes(d2Class).Count());

            var param = fooMethod.Parameters[0];
            Assert.Equal(1, param.GetAttributes(e1Class).Count());
            Assert.Equal(1, param.GetAttributes(e2Class).Count());
        }
        private void CheckAnonymousTypes(ModuleSymbol module)
        {
            var ns = module.GlobalNamespace;
            Assert.NotNull(ns);

            CheckAnonymousType(ns.GetMember<NamedTypeSymbol>("<>f__AnonymousType0"), "<>f__AnonymousType0", "<>f__AnonymousType0`2");
            CheckAnonymousType(ns.GetMember<NamedTypeSymbol>("<>f__AnonymousType1"), "<>f__AnonymousType1", "<>f__AnonymousType1");
        }
 private void CommonMetadataValidatorForCondAttrType(ModuleSymbol module)
 {
     CommonValidatorForCondAttrType(module, isFromSource: false);
 }
Пример #12
0
 internal static XElement DumpTypeInfo(ModuleSymbol moduleSymbol)
 {
     return(LoadChildNamespace(moduleSymbol.GlobalNamespace));
 }
Пример #13
0
        /// <summary>
        /// The variable's or method's base type will be resolved (if auto type, the intializer's type will be taken).
        /// A class' base class will be searched.
        /// etc..
        /// </summary>
        public static AbstractType HandleNodeMatch(
            INode m,
            ResolverContextStack ctxt,
            AbstractType resultBase = null,
            object typeBase         = null)
        {
            stackNum_HandleNodeMatch++;

            /*
             * Pushing a new scope is only required if current scope cannot be found in the handled node's hierarchy.
             */
            bool popAfterwards = !ctxt.NodeIsInCurrentScopeHierarchy(m);

            if (popAfterwards)
            {
                ctxt.PushNewScope(m is IBlockNode ? (IBlockNode)m : m.Parent as IBlockNode);
            }



            //HACK: Really dirty stack overflow prevention via manually counting call depth
            var canResolveBaseGenerally = stackNum_HandleNodeMatch < 6;



            var DoResolveBaseType = canResolveBaseGenerally &&
                                    !ctxt.Options.HasFlag(ResolutionOptions.DontResolveBaseClasses) &&
                                    (m.Type == null || m.Type.ToString(false) != m.Name);

            AbstractType ret = null;

            // To support resolving type parameters to concrete types if the context allows this, introduce all deduced parameters to the current context
            if (canResolveBaseGenerally && resultBase is DSymbol)
            {
                ctxt.CurrentContext.IntroduceTemplateParameterTypes((DSymbol)resultBase);
            }

            // Only import symbol aliases are allowed to search in the parse cache
            if (m is ImportSymbolAlias)
            {
                var isa = (ImportSymbolAlias)m;

                if (isa.IsModuleAlias ? isa.Type != null : isa.Type.InnerDeclaration != null)
                {
                    var mods = new List <DModule>();
                    var td   = isa.IsModuleAlias ? isa.Type : isa.Type.InnerDeclaration;
                    foreach (var mod in ctxt.ParseCache.LookupModuleName(td.ToString()))
                    {
                        mods.Add(mod as DModule);
                    }

                    if (mods.Count == 0)
                    {
                        ctxt.LogError(new NothingFoundError(isa.Type));
                    }
                    else if (mods.Count > 1)
                    {
                        var m__ = new List <ISemantic>();

                        foreach (var mod in mods)
                        {
                            m__.Add(new ModuleSymbol(mod, isa.Type));
                        }

                        ctxt.LogError(new AmbiguityError(isa.Type, m__));
                    }

                    var bt = mods.Count != 0 ? (AbstractType) new ModuleSymbol(mods[0], td) : null;

                    //TODO: Is this correct behaviour?
                    if (!isa.IsModuleAlias)
                    {
                        var furtherId = ResolveFurtherTypeIdentifier(isa.Type.ToString(false), new[] { bt }, ctxt, isa.Type);

                        ctxt.CheckForSingleResult(furtherId, isa.Type);

                        if (furtherId != null && furtherId.Length != 0)
                        {
                            bt = furtherId[0];
                        }
                        else
                        {
                            bt = null;
                        }
                    }

                    ret = new AliasedType(isa, bt, isa.Type);
                }
            }
            else if (m is DVariable)
            {
                var          v  = (DVariable)m;
                AbstractType bt = null;

                if (DoResolveBaseType)
                {
                    var bts = TypeDeclarationResolver.Resolve(v.Type, ctxt);

                    if (bts != null && bts.Length != 0 && ctxt.CheckForSingleResult(bts, v.Type))
                    {
                        bt = bts[0];
                    }

                    // For auto variables, use the initializer to get its type
                    else if (v.Initializer != null)
                    {
                        bt = ExpressionSemantics.Evaluation.EvaluateType(v.Initializer, ctxt);
                    }

                    // Check if inside an foreach statement header
                    if (bt == null && ctxt.ScopedStatement != null)
                    {
                        bt = GetForeachIteratorType(v, ctxt);
                    }
                }

                // Note: Also works for aliases! In this case, we simply try to resolve the aliased type, otherwise the variable's base type
                ret = v.IsAlias ?
                      (DSymbol) new AliasedType(v, bt, typeBase as ISyntaxRegion) :
                      new MemberSymbol(v, bt, typeBase as ISyntaxRegion);
            }
            else if (m is DMethod)
            {
                ret = new MemberSymbol((DNode)m,
                                       DoResolveBaseType ? GetMethodReturnType((DMethod)m, ctxt) : null
                                       , typeBase as ISyntaxRegion);
            }
            else if (m is DClassLike)
            {
                UserDefinedType udt = null;
                var             dc  = (DClassLike)m;

                var invisibleTypeParams = new Dictionary <string, TemplateParameterSymbol>();

                /*
                 * Add 'superior' template parameters to the current symbol because the parameters
                 * might be re-used in the nested class.
                 */
                var tStk = new Stack <ResolverContext>();
                do
                {
                    var curCtxt = ctxt.Pop();
                    tStk.Push(curCtxt);
                    foreach (var kv in curCtxt.DeducedTemplateParameters)
                    {
                        if (!dc.ContainsTemplateParameter(kv.Key) &&
                            !invisibleTypeParams.ContainsKey(kv.Key))
                        {
                            invisibleTypeParams.Add(kv.Key, kv.Value);
                        }
                    }
                } while (ctxt.PrevContextIsInSameHierarchy);

                while (tStk.Count != 0)
                {
                    ctxt.Push(tStk.Pop());
                }

                switch (dc.ClassType)
                {
                case DTokens.Struct:
                    ret = new StructType(dc, typeBase as ISyntaxRegion, invisibleTypeParams);
                    break;

                case DTokens.Union:
                    ret = new UnionType(dc, typeBase as ISyntaxRegion, invisibleTypeParams);
                    break;

                case DTokens.Class:
                    udt = new ClassType(dc, typeBase as ISyntaxRegion, null, null, invisibleTypeParams);
                    break;

                case DTokens.Interface:
                    udt = new InterfaceType(dc, typeBase as ISyntaxRegion, null, invisibleTypeParams);
                    break;

                case DTokens.Template:
                    ret = new TemplateType(dc, typeBase as ISyntaxRegion, invisibleTypeParams);
                    break;

                default:
                    ctxt.LogError(new ResolutionError(m, "Unknown type (" + DTokens.GetTokenString(dc.ClassType) + ")"));
                    break;
                }

                if (dc.ClassType == DTokens.Class || dc.ClassType == DTokens.Interface)
                {
                    if (canResolveBaseGenerally &&
                        !ctxt.Options.HasFlag(ResolutionOptions.DontResolveBaseClasses))
                    {
                        ret = DResolver.ResolveBaseClasses(udt, ctxt);
                    }
                    else
                    {
                        ret = udt;
                    }
                }
            }
            else if (m is IAbstractSyntaxTree)
            {
                var mod = (IAbstractSyntaxTree)m;
                if (typeBase != null && typeBase.ToString() != mod.ModuleName)
                {
                    var pack = ctxt.ParseCache.LookupPackage(typeBase.ToString()).First();
                    if (pack != null)
                    {
                        ret = new PackageSymbol(pack, typeBase as ISyntaxRegion);
                    }
                }
                else
                {
                    ret = new ModuleSymbol(m as DModule, typeBase as ISyntaxRegion);
                }
            }
            else if (m is DEnum)
            {
                ret = new EnumType((DEnum)m, typeBase as ISyntaxRegion);
            }
            else if (m is TemplateParameterNode)
            {
                //ResolveResult[] templateParameterType = null;

                //TODO: Resolve the specialization type
                //var templateParameterType = TemplateInstanceHandler.ResolveTypeSpecialization(tmp, ctxt);
                ret = new TemplateParameterSymbol((TemplateParameterNode)m, null, typeBase as ISyntaxRegion);
            }

            if (canResolveBaseGenerally && resultBase is DSymbol)
            {
                ctxt.CurrentContext.RemoveParamTypesFromPreferredLocals((DSymbol)resultBase);
            }

            if (popAfterwards)
            {
                ctxt.Pop();
            }

            stackNum_HandleNodeMatch--;
            return(ret);
        }
Пример #14
0
        internal NamespaceSymbol Get_System_Diagnostics_NamespaceSymbol(ModuleSymbol m)
        {
            NamespaceSymbol sysNS = Get_System_NamespaceSymbol(m);

            return(sysNS.GetMember <NamespaceSymbol>("Diagnostics"));
        }
Пример #15
0
        internal NamespaceSymbol Get_System_Security_NamespaceSymbol(ModuleSymbol m)
        {
            NamespaceSymbol sysNS = Get_System_NamespaceSymbol(m);

            return(sysNS.GetMember <NamespaceSymbol>("Security"));
        }
Пример #16
0
        internal NamespaceSymbol Get_System_Runtime_CompilerServices_NamespaceSymbol(ModuleSymbol m)
        {
            NamespaceSymbol sysNS = Get_System_NamespaceSymbol(m);

            return(Get_System_Runtime_CompilerServices_NamespaceSymbol(sysNS));
        }
Пример #17
0
        internal NamespaceSymbol Get_System_Runtime_InteropServices_WindowsRuntime_NamespaceSymbol(ModuleSymbol m)
        {
            NamespaceSymbol interopNS = Get_System_Runtime_InteropServices_NamespaceSymbol(m);

            return(interopNS.GetMember <NamespaceSymbol>("WindowsRuntime"));
        }
Пример #18
0
 public ulong VisitModuleSymbol(ModuleSymbol t)
 {
     return(1001953);
 }
 internal NamespaceSymbol Get_System_Runtime_CompilerServices_NamespaceSymbol(ModuleSymbol m)
 {
     NamespaceSymbol sysNS = Get_System_NamespaceSymbol(m);
     return Get_System_Runtime_CompilerServices_NamespaceSymbol(sysNS);
 }
Пример #20
0
 public override void VisitModule(ModuleSymbol module)
 {
     Visit(module.GlobalNamespace);
 }
 internal NamespaceSymbol Get_System_Security_NamespaceSymbol(ModuleSymbol m)
 {
     NamespaceSymbol sysNS = Get_System_NamespaceSymbol(m);
     return sysNS.GetMember<NamespaceSymbol>("Security");
 }
Пример #22
0
 internal static NamedTypeSymbol GetCorLibType(this ModuleSymbol module, SpecialType typeId)
 {
     return(module.ContainingAssembly.GetSpecialType(typeId));
 }
Пример #23
0
        private void TestTypeAccessibilityHelper(ModuleSymbol module0)
        {
            var system = (from n in module0.GlobalNamespace.GetMembers()
                          where n.Kind == SymbolKind.Namespace && n.Name.Equals("System")
                          select n).Cast<NamespaceSymbol>().Single();

            var obj = (from t in system.GetTypeMembers()
                       where t.Name.Equals("Object")
                       select t).Single();

            Assert.Equal(Accessibility.Public, obj.DeclaredAccessibility);

            var frameworkAssembly = (from t in module0.GlobalNamespace.GetTypeMembers()
                                     where t.Name.Equals("FXAssembly")
                                     select t).Single();

            Assert.Equal(Accessibility.Internal, frameworkAssembly.DeclaredAccessibility);

            var @enum = (from t in system.GetTypeMembers()
                         where t.Name.Equals("Enum")
                         select t).Single();

            var console = (from t in system.GetTypeMembers()
                           where t.Name.Equals("Console")
                           select t).Single();

            var controlKeyState = (from t in console.GetTypeMembers()
                                   where t.Name.Equals("ControlKeyState")
                                   select t).Single();

            Assert.Equal(Accessibility.Internal, controlKeyState.DeclaredAccessibility);

            var activationContext = (from t in system.GetTypeMembers()
                                     where t.Name.Equals("ActivationContext")
                                     select t).Single();

            var contextForm = (from t in activationContext.GetTypeMembers()
                               where t.Name.Equals("ContextForm")
                               select t).Single();

            Assert.Equal(Accessibility.Public, contextForm.DeclaredAccessibility);

            var runtime = (from t in system.GetMembers()
                           where t.Kind == SymbolKind.Namespace && t.Name.Equals("Runtime")
                           select t).Cast<NamespaceSymbol>().Single();

            var remoting = (from t in runtime.GetMembers()
                            where t.Kind == SymbolKind.Namespace && t.Name.Equals("Remoting")
                            select t).Cast<NamespaceSymbol>().Single();

            var messaging = (from t in remoting.GetMembers()
                             where t.Kind == SymbolKind.Namespace && t.Name.Equals("Messaging")
                             select t).Cast<NamespaceSymbol>().Single();

            var messageSmuggler = (from t in messaging.GetTypeMembers()
                                   where t.Name.Equals("MessageSmuggler")
                                   select t).Single();

            var serializedArg = (from t in messageSmuggler.GetTypeMembers()
                                 where t.Name.Equals("SerializedArg")
                                 select t).Single();

            Assert.Equal(Accessibility.Protected, serializedArg.DeclaredAccessibility);

            var security = (from t in system.GetMembers()
                            where t.Kind == SymbolKind.Namespace && t.Name.Equals("Security")
                            select t).Cast<NamespaceSymbol>().Single();

            var accessControl = (from t in security.GetMembers()
                                 where t.Kind == SymbolKind.Namespace && t.Name.Equals("AccessControl")
                                 select t).Cast<NamespaceSymbol>().Single();

            var nativeObjectSecurity = (from t in accessControl.GetTypeMembers()
                                        where t.Name.Equals("NativeObjectSecurity")
                                        select t).Single();

            var exceptionFromErrorCode = (from t in nativeObjectSecurity.GetTypeMembers()
                                          where t.Name.Equals("ExceptionFromErrorCode")
                                          select t).Single();

            Assert.Equal(Accessibility.ProtectedOrInternal, exceptionFromErrorCode.DeclaredAccessibility);

            Assert.Same(module0, module0.GlobalNamespace.Locations.Single().MetadataModule);
            Assert.Same(module0, system.Locations.Single().MetadataModule);
            Assert.Same(module0, runtime.Locations.Single().MetadataModule);
            Assert.Same(module0, obj.Locations.Single().MetadataModule);
        }
Пример #24
0
 internal static AssemblySymbol CorLibrary(this ModuleSymbol module)
 {
     return(module.ContainingAssembly.CorLibrary);
 }
        private static void AssertLifetimeAnnotationAttributes(ModuleSymbol module, string expected)
        {
            var actual = LifetimeAnnotationAttributesVisitor.GetString((PEModuleSymbol)module);

            AssertEx.AssertEqualToleratingWhitespaceDifferences(expected, actual);
        }
 private static void AssertNoNullablePublicOnlyAttribute(ModuleSymbol module)
 {
     AssertAttributes(module.GetAttributes());
 }
Пример #27
0
        private void TestGetMembersOfName(ModuleSymbol module0)
        {
            var sys = module0.GlobalNamespace.GetMembers("SYSTEM");

            Assert.Equal(0, sys.Length);

            sys = module0.GlobalNamespace.GetMembers("System");
            Assert.Equal(1, sys.Length);

            var system = sys[0] as NamespaceSymbol;

            Assert.NotNull(system);

            Assert.Equal(9, system.GetMembers("Action").Length);
            Assert.Equal(0, system.GetMembers("ActionThatDoesntExist").Length);

            Assert.Equal(9, system.GetTypeMembers("Action").Length);
            Assert.Equal(0, system.GetTypeMembers("ActionThatDoesntExist").Length);

            Assert.Equal(0, system.GetTypeMembers("Action", 20).Length);
            var actionOf0 = system.GetTypeMembers("Action", 0).Single();
            var actionOf4 = system.GetTypeMembers("Action", 4).Single();

            Assert.Equal("Action", actionOf0.Name);
            Assert.Equal("Action", actionOf4.Name);
            Assert.Equal(0, actionOf0.Arity);
            Assert.Equal(4, actionOf4.Arity);

            Assert.Equal(0, system.GetTypeMembers("ActionThatDoesntExist", 1).Length);

            var collectionsArray = ((NamespaceSymbol)sys[0]).GetMembers("CollectionS");

            Assert.Equal(0, collectionsArray.Length);

            collectionsArray = ((NamespaceSymbol)sys[0]).GetMembers("Collections");
            Assert.Equal(1, collectionsArray.Length);

            var collections = collectionsArray[0] as NamespaceSymbol;

            Assert.NotNull(collections);

            Assert.Equal(0, collections.GetAttributes().Length);

            var enumerable = collections.GetMembers("IEnumerable");

            Assert.Equal(1, enumerable.Length);
            Assert.Equal(
                "System.Collections.IEnumerable",
                ((NamedTypeSymbol)enumerable[0]).ToTestDisplayString()
                );

            var generic = collections.GetMembers("Generic");

            Assert.Equal(1, generic.Length);
            Assert.NotNull((generic[0] as NamespaceSymbol));

            var dictionaryArray = ((NamespaceSymbol)generic[0]).GetMembers("Dictionary");

            Assert.Equal(1, dictionaryArray.Length);

            var dictionary = (NamedTypeSymbol)dictionaryArray[0];

            Assert.Equal(2, dictionary.Arity);
            Assert.Same(dictionary.ConstructedFrom, dictionary);
            Assert.Equal("Dictionary", dictionary.Name);

            Assert.Equal(0, collections.GetAttributes(dictionary).Count());

            Assert.Equal(0, dictionary.GetTypeMembers("ValueCollectionThatDoesntExist").Length);
            Assert.Equal(0, dictionary.GetTypeMembers("ValueCollectioN").Length);

            var valueCollection = dictionary.GetTypeMembers("ValueCollection");

            Assert.Equal(1, valueCollection.Length);
            Assert.Equal("ValueCollection", ((NamedTypeSymbol)valueCollection[0]).Name);
            Assert.Equal(0, ((NamedTypeSymbol)valueCollection[0]).Arity);

            Assert.Equal(0, dictionary.GetTypeMembers("ValueCollectionThatDoesntExist", 1).Length);
            Assert.Equal(
                valueCollection[0],
                dictionary.GetTypeMembers("ValueCollection", 0).Single()
                );
            Assert.Equal(0, dictionary.GetTypeMembers("ValueCollection", 1).Length);
        }
 private static void AssertNullablePublicOnlyAttribute(ModuleSymbol module)
 {
     AssertAttributes(module.GetAttributes(), "System.Runtime.CompilerServices.NullablePublicOnlyAttribute");
 }
 public virtual void VisitModule(ModuleSymbol symbol)
 {
     DefaultVisit(symbol);
 }
Пример #30
0
 private void CommonSourceValidatorForCondAttrType(ModuleSymbol module)
 {
     CommonValidatorForCondAttrType(module, isFromSource: true);
 }
Пример #31
0
 private TopLevel(ModuleSymbol module, ref MetadataTypeName fullName, int typeId)
     : this(module, ref fullName, fullName.ForcedArity == -1 || fullName.ForcedArity == fullName.InferredArity)
 {
     Debug.Assert(typeId == -1 || typeId == (int)SpecialType.None || Arity == 0 || MangleName);
     _lazyTypeId = typeId;
 }
Пример #32
0
 private void CommonMetadataValidatorForCondAttrType(ModuleSymbol module)
 {
     CommonValidatorForCondAttrType(module, isFromSource: false);
 }
Пример #33
0
 public TopLevelWithCustomErrorInfo(ModuleSymbol module, ref MetadataTypeName emittedName, DiagnosticInfo errorInfo, WellKnownType typeId)
     : base(module, ref emittedName, typeId)
 {
     Debug.Assert(errorInfo != null);
     _errorInfo = errorInfo;
 }
Пример #34
0
        private void CommonValidatorForCondAttrType(ModuleSymbol module, bool isFromSource)
        {
            var attributesArrayBuilder = new List <ImmutableArray <CSharpAttributeData> >();

            var classZ = module.GlobalNamespace.GetTypeMember("Z");

            attributesArrayBuilder.Add(classZ.GetAttributes());
            attributesArrayBuilder.Add(classZ.TypeParameters[0].GetAttributes());

            var methodM = classZ.GetMember <MethodSymbol>("m");

            attributesArrayBuilder.Add(methodM.GetAttributes());
            attributesArrayBuilder.Add(methodM.GetReturnTypeAttributes());
            var param1 = methodM.Parameters[0];

            attributesArrayBuilder.Add(param1.GetAttributes());

            var fieldF = classZ.GetMember <FieldSymbol>("f");

            attributesArrayBuilder.Add(fieldF.GetAttributes());

            var propP1 = classZ.GetMember <PropertySymbol>("p1");

            attributesArrayBuilder.Add(propP1.GetAttributes());
            var propGetMethod = propP1.GetMethod;

            attributesArrayBuilder.Add(propGetMethod.GetAttributes());
            attributesArrayBuilder.Add(propGetMethod.GetReturnTypeAttributes());
            var propSetMethod = propP1.SetMethod;

            attributesArrayBuilder.Add(propSetMethod.GetAttributes());
            attributesArrayBuilder.Add(propSetMethod.Parameters[0].GetAttributes());

            var propP2 = classZ.GetMember <PropertySymbol>("p2");

            attributesArrayBuilder.Add(propP2.GetAttributes());
            propGetMethod = propP2.GetMethod;
            attributesArrayBuilder.Add(propGetMethod.GetAttributes());
            attributesArrayBuilder.Add(propGetMethod.GetReturnTypeAttributes());

            var propP3 = classZ.GetMember <PropertySymbol>("p3");

            attributesArrayBuilder.Add(propP3.GetAttributes());
            propGetMethod = propP3.GetMethod;
            attributesArrayBuilder.Add(propGetMethod.GetAttributes());
            attributesArrayBuilder.Add(propGetMethod.GetReturnTypeAttributes());
            propSetMethod = propP3.SetMethod;
            attributesArrayBuilder.Add(propSetMethod.GetAttributes());
            attributesArrayBuilder.Add(propSetMethod.Parameters[0].GetAttributes());

            var eventE = classZ.GetMember <EventSymbol>("e");

            attributesArrayBuilder.Add(eventE.GetAttributes());
            attributesArrayBuilder.Add(eventE.AddMethod.GetAttributes());
            attributesArrayBuilder.Add(eventE.RemoveMethod.GetAttributes());
            if (isFromSource)
            {
                attributesArrayBuilder.Add(eventE.AssociatedField.GetAttributes());
            }

            var enumE = module.GlobalNamespace.GetTypeMember("E");

            attributesArrayBuilder.Add(enumE.GetAttributes());

            var fieldA = enumE.GetMember <FieldSymbol>("A");

            attributesArrayBuilder.Add(fieldA.GetAttributes());

            var structS = module.GlobalNamespace.GetTypeMember("S");

            attributesArrayBuilder.Add(structS.GetAttributes());

            foreach (var attributes in attributesArrayBuilder)
            {
                // PreservedAppliedAttribute and OmittedAppliedAttribute have applied conditional attributes, such that
                // (a) PreservedAppliedAttribute is conditionally applied to symbols
                // (b) OmittedAppliedAttribute is conditionally NOT applied to symbols

                // PreservedInheritedAttribute and OmittedInheritedAttribute have inherited conditional attributes, such that
                // (a) PreservedInheritedAttribute is conditionally applied to symbols
                // (b) OmittedInheritedAttribute is conditionally NOT applied to symbols

                // PreservedMultipleAttribute and OmittedMultipleAttribute have multiple applied/inherited conditional attributes, such that
                // (a) PreservedMultipleAttribute is conditionally applied to symbols
                // (b) OmittedMultipleAttribute is conditionally NOT applied to symbols

                var actualAttributeNames = attributes.
                                           Where(a => a.AttributeClass.Name != "CompilerGeneratedAttribute").
                                           Select(a => a.AttributeClass.Name);

                if (isFromSource)
                {
                    // All attributes should be present for source symbols
                    AssertEx.SetEqual(
                        new[]
                        { "PreservedAppliedAttribute",
                          "OmittedAppliedAttribute",
                          "PreservedInheritedAttribute",
                          "OmittedInheritedAttribute",
                          "PreservedMultipleAttribute",
                          "OmittedMultipleAttribute", },
                        actualAttributeNames);
                }
                else
                {
                    // Only PreservedAppliedAttribute, PreservedInheritedAttribute, PreservedMultipleAttribute should be emitted in metadata
                    AssertEx.SetEqual(
                        new[]
                    {
                        "PreservedAppliedAttribute",
                        "PreservedInheritedAttribute",
                        "PreservedMultipleAttribute",
                    },
                        actualAttributeNames);
                }
            }
        }
 internal NamespaceSymbol Get_System_Runtime_InteropServices_WindowsRuntime_NamespaceSymbol(ModuleSymbol m)
 {
     NamespaceSymbol interopNS = Get_System_Runtime_InteropServices_NamespaceSymbol(m);
     return interopNS.GetMember<NamespaceSymbol>("WindowsRuntime");
 }
Пример #36
0
        private void EmitModule(ModuleSymbol moduleSymbol)
        {
            writer.WriteStartObject();

            if (moduleSymbol.DeclaringModule.IfCondition is IfConditionSyntax ifCondition)
            {
                this.emitter.EmitProperty("condition", ifCondition.ConditionExpression);
            }

            this.emitter.EmitProperty("type", NestedDeploymentResourceType);
            this.emitter.EmitProperty("apiVersion", NestedDeploymentResourceApiVersion);

            // emit all properties apart from 'params'. In practice, this currrently only allows 'name', but we may choose to allow other top-level resource properties in future.
            // params requires special handling (see below).
            this.emitter.EmitObjectProperties((ObjectSyntax)moduleSymbol.DeclaringModule.Body, ModulePropertiesToOmit);


            var scopeData = context.ModuleScopeData[moduleSymbol];

            ScopeHelper.EmitModuleScopeProperties(scopeData, emitter);

            if (scopeData.RequestedScope != ResourceScopeType.ResourceGroupScope)
            {
                // if we're deploying to a scope other than resource group, we need to supply a location
                if (this.context.SemanticModel.TargetScope == ResourceScopeType.ResourceGroupScope)
                {
                    // the deployment() object at resource group scope does not contain a property named 'location', so we have to use resourceGroup().location
                    this.emitter.EmitProperty("location", new FunctionExpression(
                                                  "resourceGroup",
                                                  new LanguageExpression[] { },
                                                  new LanguageExpression[] { new JTokenExpression("location") }));
                }
                else
                {
                    // at all other scopes we can just use deployment().location
                    this.emitter.EmitProperty("location", new FunctionExpression(
                                                  "deployment",
                                                  new LanguageExpression[] { },
                                                  new LanguageExpression[] { new JTokenExpression("location") }));
                }
            }

            writer.WritePropertyName("properties");
            {
                writer.WriteStartObject();

                writer.WritePropertyName("expressionEvaluationOptions");
                {
                    writer.WriteStartObject();
                    this.emitter.EmitProperty("scope", "inner");
                    writer.WriteEndObject();
                }

                this.emitter.EmitProperty("mode", "Incremental");

                EmitModuleParameters(moduleSymbol);

                writer.WritePropertyName("template");
                {
                    var moduleSemanticModel = GetModuleSemanticModel(moduleSymbol);
                    var moduleWriter        = new TemplateWriter(writer, moduleSemanticModel);
                    moduleWriter.Write();
                }

                writer.WriteEndObject();
            }

            this.EmitDependsOn(moduleSymbol);

            writer.WriteEndObject();
        }
 internal NamespaceSymbol Get_System_Diagnostics_NamespaceSymbol(ModuleSymbol m)
 {
     NamespaceSymbol sysNS = Get_System_NamespaceSymbol(m);
     return sysNS.GetMember<NamespaceSymbol>("Diagnostics");
 }
Пример #38
0
            public override Symbol VisitModule(ModuleSymbol module)
            {
                Debug.Assert((object)module.ContainingSymbol == (object)this.sourceAssembly);

                return(this.otherAssembly.Modules[module.Ordinal]);
            }
 private static NamedTypeSymbol GetLifetimeAnnotationType(ModuleSymbol module)
 {
     return(module.GlobalNamespace.GetMember <NamedTypeSymbol>("System.Runtime.CompilerServices.LifetimeAnnotationAttribute"));
 }
Пример #40
0
        private void EmitModule(JsonTextWriter jsonWriter, ModuleSymbol moduleSymbol, ExpressionEmitter emitter)
        {
            jsonWriter.WriteStartObject();

            var body = moduleSymbol.DeclaringModule.Value;

            switch (body)
            {
            case IfConditionSyntax ifCondition:
                body = ifCondition.Body;
                emitter.EmitProperty("condition", ifCondition.ConditionExpression);
                break;

            case ForSyntax @for:
                if (@for.Body is IfConditionSyntax loopFilter)
                {
                    body = loopFilter.Body;
                    emitter.EmitProperty("condition", loopFilter.ConditionExpression);
                }
                else
                {
                    body = @for.Body;
                }

                var batchSize = GetBatchSize(moduleSymbol.DeclaringModule);
                emitter.EmitProperty("copy", () => emitter.EmitCopyObject(moduleSymbol.Name, @for, input: null, batchSize: batchSize));
                break;
            }

            emitter.EmitProperty("type", NestedDeploymentResourceType);
            emitter.EmitProperty("apiVersion", NestedDeploymentResourceApiVersion);

            // emit all properties apart from 'params'. In practice, this currrently only allows 'name', but we may choose to allow other top-level resource properties in future.
            // params requires special handling (see below).
            emitter.EmitObjectProperties((ObjectSyntax)body, ModulePropertiesToOmit);

            var scopeData = context.ModuleScopeData[moduleSymbol];

            ScopeHelper.EmitModuleScopeProperties(context.SemanticModel.TargetScope, scopeData, emitter, body);

            if (scopeData.RequestedScope != ResourceScope.ResourceGroup)
            {
                // if we're deploying to a scope other than resource group, we need to supply a location
                if (this.context.SemanticModel.TargetScope == ResourceScope.ResourceGroup)
                {
                    // the deployment() object at resource group scope does not contain a property named 'location', so we have to use resourceGroup().location
                    emitter.EmitProperty("location", new FunctionExpression(
                                             "resourceGroup",
                                             Array.Empty <LanguageExpression>(),
                                             new LanguageExpression[] { new JTokenExpression("location") }));
                }
                else
                {
                    // at all other scopes we can just use deployment().location
                    emitter.EmitProperty("location", new FunctionExpression(
                                             "deployment",
                                             Array.Empty <LanguageExpression>(),
                                             new LanguageExpression[] { new JTokenExpression("location") }));
                }
            }

            jsonWriter.WritePropertyName("properties");
            {
                jsonWriter.WriteStartObject();

                jsonWriter.WritePropertyName("expressionEvaluationOptions");
                {
                    jsonWriter.WriteStartObject();
                    emitter.EmitProperty("scope", "inner");
                    jsonWriter.WriteEndObject();
                }

                emitter.EmitProperty("mode", "Incremental");

                EmitModuleParameters(jsonWriter, moduleSymbol, emitter);

                var moduleSemanticModel = GetModuleSemanticModel(moduleSymbol);

                // If it is a template spec module, emit templateLink instead of template contents.
                jsonWriter.WritePropertyName(moduleSemanticModel is TemplateSpecSemanticModel ? "templateLink" : "template");
                {
                    TemplateWriterFactory.CreateTemplateWriter(moduleSemanticModel, this.settings).Write(jsonWriter);
                }

                jsonWriter.WriteEndObject();
            }

            this.EmitDependsOn(jsonWriter, moduleSymbol, emitter, body);

            // Since we don't want to be mutating the body of the original ObjectSyntax, we create an placeholder body in place
            // and emit its properties to merge decorator properties.
            foreach (var(property, val) in AddDecoratorsToBody(
                         moduleSymbol.DeclaringModule,
                         SyntaxFactory.CreateObject(Enumerable.Empty <ObjectPropertySyntax>()),
                         moduleSymbol.Type).ToNamedPropertyValueDictionary())
            {
                emitter.EmitProperty(property, val);
            }

            jsonWriter.WriteEndObject();
        }
        internal Microsoft.Cci.IModuleReference Translate(ModuleSymbol module)
        {
            if (ReferenceEquals(sourceModule, module))
            {
                return this;
            }

            object reference;

            if (SymbolsMap.TryGetValue(module, out reference))
            {
                return (Microsoft.Cci.IModuleReference)reference;
            }

            Microsoft.Cci.IModuleReference moduleRef;
            AssemblySymbol container = module.ContainingAssembly;

            if (container != null && ReferenceEquals(container.Modules[0], module))
            {
                moduleRef = new AssemblyReference(container);
                SymbolsMap.Add(container, moduleRef);
            }
            else
            {
                moduleRef = new ModuleReference(this, module);
            }

            SymbolsMap.Add(module, moduleRef);

            return moduleRef;
        }
Пример #42
0
 public virtual TResult VisitModule(ModuleSymbol symbol)
 {
     return(DefaultVisit(symbol));
 }
 private void CommonSourceValidatorForCondAttrType(ModuleSymbol module)
 {
     CommonValidatorForCondAttrType(module, isFromSource: true);
 }
Пример #44
0
 internal static XElement DumpTypeInfo(ModuleSymbol moduleSymbol)
 {
     return LoadChildNamespace(moduleSymbol.GlobalNamespace);
 }
        private void CommonValidatorForCondAttrType(ModuleSymbol module, bool isFromSource)
        {
            var attributesArrayBuilder = ArrayBuilder<ImmutableArray<CSharpAttributeData>>.GetInstance();
            
            var classZ = module.GlobalNamespace.GetTypeMember("Z");
            attributesArrayBuilder.Add(classZ.GetAttributes());
            attributesArrayBuilder.Add(classZ.TypeParameters[0].GetAttributes());
            
            var methodM = classZ.GetMember<MethodSymbol>("m");
            attributesArrayBuilder.Add(methodM.GetAttributes());
            attributesArrayBuilder.Add(methodM.GetReturnTypeAttributes());
            var param1 = methodM.Parameters[0];
            attributesArrayBuilder.Add(param1.GetAttributes());

            var fieldF = classZ.GetMember<FieldSymbol>("f");
            attributesArrayBuilder.Add(fieldF.GetAttributes());
            
            var propP1 = classZ.GetMember<PropertySymbol>("p1");
            attributesArrayBuilder.Add(propP1.GetAttributes());
            var propGetMethod = propP1.GetMethod;
            attributesArrayBuilder.Add(propGetMethod.GetAttributes());
            attributesArrayBuilder.Add(propGetMethod.GetReturnTypeAttributes());
            var propSetMethod = propP1.SetMethod;
            attributesArrayBuilder.Add(propSetMethod.GetAttributes());
            attributesArrayBuilder.Add(propSetMethod.Parameters[0].GetAttributes());
            
            var propP2 = classZ.GetMember<PropertySymbol>("p2");
            attributesArrayBuilder.Add(propP2.GetAttributes());
            propGetMethod = propP2.GetMethod;
            attributesArrayBuilder.Add(propGetMethod.GetAttributes());
            attributesArrayBuilder.Add(propGetMethod.GetReturnTypeAttributes());
            
            var propP3 = classZ.GetMember<PropertySymbol>("p3");
            attributesArrayBuilder.Add(propP3.GetAttributes());
            propGetMethod = propP3.GetMethod;
            attributesArrayBuilder.Add(propGetMethod.GetAttributes());
            attributesArrayBuilder.Add(propGetMethod.GetReturnTypeAttributes());
            propSetMethod = propP3.SetMethod;
            attributesArrayBuilder.Add(propSetMethod.GetAttributes());
            attributesArrayBuilder.Add(propSetMethod.Parameters[0].GetAttributes());
            
            var eventE = classZ.GetMember<EventSymbol>("e");
            attributesArrayBuilder.Add(eventE.GetAttributes());
            attributesArrayBuilder.Add(eventE.AddMethod.GetAttributes());
            attributesArrayBuilder.Add(eventE.RemoveMethod.GetAttributes());
            if (isFromSource)
            {
                attributesArrayBuilder.Add(eventE.AssociatedField.GetAttributes());
            }

            var enumE = module.GlobalNamespace.GetTypeMember("E");
            attributesArrayBuilder.Add(enumE.GetAttributes());

            var fieldA = enumE.GetMember<FieldSymbol>("A");
            attributesArrayBuilder.Add(fieldA.GetAttributes());

            var structS = module.GlobalNamespace.GetTypeMember("S");
            attributesArrayBuilder.Add(structS.GetAttributes());

            foreach (var attributes in attributesArrayBuilder)
            {
                // PreservedAppliedAttribute and OmittedAppliedAttribute have applied conditional attributes, such that
                // (a) PreservedAppliedAttribute is conditionally applied to symbols
                // (b) OmittedAppliedAttribute is conditionally NOT applied to symbols

                // PreservedInheritedAttribute and OmittedInheritedAttribute have inherited conditional attributes, such that
                // (a) PreservedInheritedAttribute is conditionally applied to symbols
                // (b) OmittedInheritedAttribute is conditionally NOT applied to symbols

                // PreservedMultipleAttribute and OmittedMultipleAttribute have multiple applied/inherited conditional attributes, such that
                // (a) PreservedMultipleAttribute is conditionally applied to symbols
                // (b) OmittedMultipleAttribute is conditionally NOT applied to symbols

                var actualAttributeNames = attributes.
                    Where(a => a.AttributeClass.Name != "CompilerGeneratedAttribute").
                    Select(a => a.AttributeClass.Name);

                if (isFromSource)
                {
                    // All attributes should be present for source symbols
                    AssertEx.SetEqual(
                        new[] 
                        {   "PreservedAppliedAttribute",
                            "OmittedAppliedAttribute", 
                            "PreservedInheritedAttribute",
                            "OmittedInheritedAttribute",
                            "PreservedMultipleAttribute",
                            "OmittedMultipleAttribute",
                        },
                        actualAttributeNames);
                }
                else
                {
                    // Only PreservedAppliedAttribute, PreservedInheritedAttribute, PreservedMultipleAttribute should be emitted in metadata
                    AssertEx.SetEqual(
                        new[] 
                        {
                            "PreservedAppliedAttribute", 
                            "PreservedInheritedAttribute",
                            "PreservedMultipleAttribute",
                        },
                        actualAttributeNames);
                }
            }

            attributesArrayBuilder.Free();
        }
Пример #46
0
        // NOTE: assumes there's a destructor.
        private static void ValidateDestructor(ModuleSymbol module, string typeName)
        {
            var @class = module.GlobalNamespace.GetMember<NamedTypeSymbol>(typeName);
            var destructor = @class.GetMember<MethodSymbol>(WellKnownMemberNames.DestructorName);

            Assert.Equal(MethodKind.Destructor, destructor.MethodKind);

            Assert.True(destructor.IsMetadataVirtual());
            Assert.False(destructor.IsVirtual);
            Assert.False(destructor.IsOverride);
            Assert.False(destructor.IsSealed);
            Assert.False(destructor.IsStatic);
            Assert.False(destructor.IsAbstract);
            Assert.Null(destructor.OverriddenMethod);

            Assert.Equal(SpecialType.System_Void, destructor.ReturnType.SpecialType);
            Assert.Equal(0, destructor.Parameters.Length);
            Assert.Equal(0, destructor.TypeParameters.Length);

            Assert.Equal(Accessibility.Protected, destructor.DeclaredAccessibility);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="underlyingAssembly">
        /// The underlying AssemblySymbol, cannot be an instance of RetargetingAssemblySymbol.
        /// </param>
        /// <param name="isLinked">
        /// Assembly is /l-ed by compilation that is using it as a reference.
        /// </param>
        public RetargetingAssemblySymbol(SourceAssemblySymbol underlyingAssembly, bool isLinked)
        {
            Debug.Assert((object)underlyingAssembly != null);

            _underlyingAssembly = underlyingAssembly;

            ModuleSymbol[] modules = new ModuleSymbol[underlyingAssembly.Modules.Length];

            modules[0] = new RetargetingModuleSymbol(this, (SourceModuleSymbol)underlyingAssembly.Modules[0]);

            for (int i = 1; i < underlyingAssembly.Modules.Length; i++)
            {
                PEModuleSymbol under = (PEModuleSymbol)underlyingAssembly.Modules[i];
                modules[i] = new PEModuleSymbol(this, under.Module, under.ImportOptions, i);
            }

            _modules = modules.AsImmutableOrNull();
            _isLinked = isLinked;
        }
Пример #48
0
        private void TypeAndNamespaceDifferByCase(ModuleSymbol module0)
        {
            var someName = module0.GlobalNamespace.GetMembers("SomenamE");
            Assert.Equal(someName.Length, 0);

            someName = module0.GlobalNamespace.GetMembers("somEnamE");
            Assert.Equal(someName.Length, 1);
            Assert.NotNull((someName[0] as NamedTypeSymbol));

            someName = module0.GlobalNamespace.GetMembers("SomeName");
            Assert.Equal(someName.Length, 1);
            Assert.NotNull((someName[0] as NamespaceSymbol));

            var someName1_1 = module0.GlobalNamespace.GetTypeMembers("somEnamE1").OrderBy((t) => t.Name).ToArray();
            var someName1_2 = module0.GlobalNamespace.GetTypeMembers("SomeName1").OrderBy((t) => t.Name).ToArray();

            Assert.Equal(1, someName1_1.Length);
            Assert.Equal("somEnamE1", someName1_1[0].Name);
            Assert.Equal(1, someName1_2.Length);
            Assert.Equal("SomeName1", someName1_2[0].Name);
            Assert.NotEqual(someName1_1[0], someName1_2[0]);

            var someName2_1 = module0.GlobalNamespace.GetMembers("somEnamE2").OfType<NamespaceSymbol>().OrderBy((t) => t.Name).ToArray();
            var someName2_2 = module0.GlobalNamespace.GetMembers("SomeName2").OfType<NamespaceSymbol>().OrderBy((t) => t.Name).ToArray();
            Assert.Equal(1, someName2_1.Length);
            Assert.Equal("somEnamE2", someName2_1[0].Name);
            Assert.Equal(1, someName2_2.Length);
            Assert.Equal("SomeName2", someName2_2[0].Name);
            Assert.NotEqual(someName2_1[0], someName2_2[0]);

            var otherName_1 = someName2_1[0].GetTypeMembers("OtherName");
            var otherName_2 = someName2_2[0].GetTypeMembers("OtherName");

            Assert.Equal(1, otherName_1.Length);
            Assert.Equal(1, otherName_2.Length);
            Assert.NotEqual(otherName_1[0], otherName_2[0]);

            var nestingClass = module0.GlobalNamespace.GetTypeMembers("NestingClass").Single();
            var someName3_1 = nestingClass.GetTypeMembers("SomeName3").OrderBy((t) => t.Name).ToArray();
            var someName3_2 = nestingClass.GetTypeMembers("somEnamE3").OrderBy((t) => t.Name).ToArray();

            Assert.Equal(1, someName3_1.Length);
            Assert.Equal(1, someName3_2.Length);
            Assert.Equal("somEnamE3", someName3_2[0].Name);
            Assert.Equal("SomeName3", someName3_1[0].Name);
        }
Пример #49
0
        public static string[] GetFieldNamesAndTypes(this ModuleSymbol module, string qualifiedTypeName)
        {
            var type = (NamedTypeSymbol)module.GlobalNamespace.GetMember(qualifiedTypeName);

            return(type.GetMembers().OfType <FieldSymbol>().Select(f => f.Name + ": " + f.TypeWithAnnotations).ToArray());
        }
Пример #50
0
        private void TypeAndNamespaceDifferByCase(ModuleSymbol module0)
        {
            var someName = module0.GlobalNamespace.GetMembers("SomenamE");

            Assert.Equal(0, someName.Length);

            someName = module0.GlobalNamespace.GetMembers("somEnamE");
            Assert.Equal(1, someName.Length);
            Assert.NotNull((someName[0] as NamedTypeSymbol));

            someName = module0.GlobalNamespace.GetMembers("SomeName");
            Assert.Equal(1, someName.Length);
            Assert.NotNull((someName[0] as NamespaceSymbol));

            var someName1_1 = module0.GlobalNamespace
                              .GetTypeMembers("somEnamE1")
                              .OrderBy((t) => t.Name)
                              .ToArray();
            var someName1_2 = module0.GlobalNamespace
                              .GetTypeMembers("SomeName1")
                              .OrderBy((t) => t.Name)
                              .ToArray();

            Assert.Equal(1, someName1_1.Length);
            Assert.Equal("somEnamE1", someName1_1[0].Name);
            Assert.Equal(1, someName1_2.Length);
            Assert.Equal("SomeName1", someName1_2[0].Name);
            Assert.NotEqual(someName1_1[0], someName1_2[0]);

            var someName2_1 = module0.GlobalNamespace
                              .GetMembers("somEnamE2")
                              .OfType <NamespaceSymbol>()
                              .OrderBy((t) => t.Name)
                              .ToArray();
            var someName2_2 = module0.GlobalNamespace
                              .GetMembers("SomeName2")
                              .OfType <NamespaceSymbol>()
                              .OrderBy((t) => t.Name)
                              .ToArray();

            Assert.Equal(1, someName2_1.Length);
            Assert.Equal("somEnamE2", someName2_1[0].Name);
            Assert.Equal(1, someName2_2.Length);
            Assert.Equal("SomeName2", someName2_2[0].Name);
            Assert.NotEqual(someName2_1[0], someName2_2[0]);

            var otherName_1 = someName2_1[0].GetTypeMembers("OtherName");
            var otherName_2 = someName2_2[0].GetTypeMembers("OtherName");

            Assert.Equal(1, otherName_1.Length);
            Assert.Equal(1, otherName_2.Length);
            Assert.NotEqual(otherName_1[0], otherName_2[0]);

            var nestingClass = module0.GlobalNamespace.GetTypeMembers("NestingClass").Single();
            var someName3_1  = nestingClass
                               .GetTypeMembers("SomeName3")
                               .OrderBy((t) => t.Name)
                               .ToArray();
            var someName3_2 = nestingClass
                              .GetTypeMembers("somEnamE3")
                              .OrderBy((t) => t.Name)
                              .ToArray();

            Assert.Equal(1, someName3_1.Length);
            Assert.Equal(1, someName3_2.Length);
            Assert.Equal("somEnamE3", someName3_2[0].Name);
            Assert.Equal("SomeName3", someName3_1[0].Name);
        }
 public NoPiaIllegalGenericInstantiationSymbol(ModuleSymbol exposingModule, NamedTypeSymbol underlyingSymbol)
 {
     _exposingModule = exposingModule;
     _underlyingSymbol = underlyingSymbol;
 }
Пример #52
0
 public virtual void VisitModule(ModuleSymbol symbol)
 {
     DefaultVisit(symbol);
 }
Пример #53
0
 /// <summary>
 /// Called when visiting a <see cref="ModuleSymbol" />; Override this method with specific
 /// implementation; Calling default <see cref="DefaultVisit" /> if it's not overridden
 /// </summary>
 /// <param name="symbol">The visited symbol</param>
 /// <param name="argument">Additional argument</param>
 /// <returns></returns>
 public virtual TResult VisitModule(ModuleSymbol symbol, TArgument argument)
 {
     return(DefaultVisit(symbol, argument));
 }
Пример #54
0
        private LanguageExpression GetModuleNameExpression(ModuleSymbol moduleSymbol)
        {
            SyntaxBase nameValueSyntax = GetModuleNameSyntax(moduleSymbol);

            return(ConvertExpression(nameValueSyntax));
        }
Пример #55
0
        private void TestGetMembersOfName(ModuleSymbol module0)
        {
            var sys = module0.GlobalNamespace.GetMembers("SYSTEM");
            Assert.Equal(sys.Length, 0);

            sys = module0.GlobalNamespace.GetMembers("System");
            Assert.Equal(sys.Length, 1);

            var system = sys[0] as NamespaceSymbol;
            Assert.NotNull(system);

            Assert.Equal(system.GetMembers("Action").Length, 9);
            Assert.Equal(system.GetMembers("ActionThatDoesntExist").Length, 0);

            Assert.Equal(system.GetTypeMembers("Action").Length, 9);
            Assert.Equal(system.GetTypeMembers("ActionThatDoesntExist").Length, 0);

            Assert.Equal(system.GetTypeMembers("Action", 20).Length, 0);
            var actionOf0 = system.GetTypeMembers("Action", 0).Single();
            var actionOf4 = system.GetTypeMembers("Action", 4).Single();
            Assert.Equal("Action", actionOf0.Name);
            Assert.Equal("Action", actionOf4.Name);
            Assert.Equal(actionOf0.Arity, 0);
            Assert.Equal(actionOf4.Arity, 4);

            Assert.Equal(system.GetTypeMembers("ActionThatDoesntExist", 1).Length, 0);

            var collectionsArray = ((NamespaceSymbol)sys[0]).GetMembers("CollectionS");
            Assert.Equal(collectionsArray.Length, 0);

            collectionsArray = ((NamespaceSymbol)sys[0]).GetMembers("Collections");
            Assert.Equal(collectionsArray.Length, 1);

            var collections = collectionsArray[0] as NamespaceSymbol;
            Assert.NotNull(collections);

            Assert.Equal(0, collections.GetAttributes().Length);

            var enumerable = collections.GetMembers("IEnumerable");
            Assert.Equal(enumerable.Length, 1);
            Assert.Equal("System.Collections.IEnumerable", ((NamedTypeSymbol)enumerable[0]).ToTestDisplayString());

            var generic = collections.GetMembers("Generic");
            Assert.Equal(generic.Length, 1);
            Assert.NotNull((generic[0] as NamespaceSymbol));

            var dictionaryArray = ((NamespaceSymbol)generic[0]).GetMembers("Dictionary");
            Assert.Equal(dictionaryArray.Length, 1);

            var dictionary = (NamedTypeSymbol)dictionaryArray[0];
            Assert.Equal(dictionary.Arity, 2);
            Assert.Same(dictionary.ConstructedFrom, dictionary);
            Assert.Equal("Dictionary", dictionary.Name);

            Assert.Equal(0, collections.GetAttributes(dictionary).Count());

            Assert.Equal(dictionary.GetTypeMembers("ValueCollectionThatDoesntExist").Length, 0);
            Assert.Equal(dictionary.GetTypeMembers("ValueCollectioN").Length, 0);

            var valueCollection = dictionary.GetTypeMembers("ValueCollection");
            Assert.Equal(valueCollection.Length, 1);
            Assert.Equal("ValueCollection", ((NamedTypeSymbol)valueCollection[0]).Name);
            Assert.Equal(((NamedTypeSymbol)valueCollection[0]).Arity, 0);

            Assert.Equal(dictionary.GetTypeMembers("ValueCollectionThatDoesntExist", 1).Length, 0);
            Assert.Equal(valueCollection[0], dictionary.GetTypeMembers("ValueCollection", 0).Single());
            Assert.Equal(dictionary.GetTypeMembers("ValueCollection", 1).Length, 0);
        }
Пример #56
0
 public static SyntaxBase GetModuleNameSyntax(ModuleSymbol moduleSymbol)
 {
     // this condition should have already been validated by the type checker
     return(moduleSymbol.TryGetBodyPropertyValue(LanguageConstants.ModuleNamePropertyName) ?? throw new ArgumentException($"Expected module syntax body to contain property 'name'"));
 }
Пример #57
0
        // NOTE: assumes there's a single indexer (type = int) in a type C.
        private static void ValidateIndexer(ModuleSymbol module, string getterDisplayString, string setterDisplayString)
        {
            var @class = module.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
            var indexer = @class.Indexers.Single();

            Assert.Equal(SymbolKind.Property, indexer.Kind);
            Assert.True(indexer.IsIndexer);
            Assert.False(indexer.MustCallMethodsDirectly);
            Assert.Equal(Accessibility.Public, indexer.DeclaredAccessibility);
            Assert.False(indexer.IsStatic);

            var getMethod = indexer.GetMethod;
            if (getterDisplayString == null)
            {
                Assert.Null(getMethod);
            }
            else
            {
                Assert.Equal(MethodKind.PropertyGet, getMethod.MethodKind);
                Assert.Equal(getterDisplayString, getMethod.ToTestDisplayString());
                getMethod.CheckAccessorShape(indexer);
            }

            var setMethod = indexer.SetMethod;
            if (setterDisplayString == null)
            {
                Assert.Null(setMethod);
            }
            else
            {
                Assert.Equal(MethodKind.PropertySet, setMethod.MethodKind);
                Assert.Equal(setterDisplayString, setMethod.ToTestDisplayString());
                setMethod.CheckAccessorShape(indexer);
            }
        }
Пример #58
0
 public TopLevel(ModuleSymbol module, ref MetadataTypeName fullName, WellKnownType wellKnownType)
     : this(module, ref fullName, (int)wellKnownType)
 {
 }
Пример #59
0
 /// <summary>
 /// </summary>
 /// <param name="moduleDef">
 /// </param>
 internal MetadataModuleAdapter(ModuleSymbol moduleDef)
 {
     Debug.Assert(moduleDef != null);
     this.moduleDef = moduleDef;
 }
Пример #60
0
 /// <summary>
 /// </summary>
 /// <param name="moduleDef">
 /// </param>
 internal MetadataModuleAdapter(ModuleSymbol moduleDef)
 {
     this.moduleDef = moduleDef;
 }