Beispiel #1
0
        public override void AddMember(MemberSymbol memberSymbol)
        {
            if (primaryPartialClass != null)
            {
                primaryPartialClass.AddMember(memberSymbol);

                return;
            }

            Debug.Assert(memberSymbol != null);

            if (memberSymbol.Type == SymbolType.Constructor)
            {
                if ((memberSymbol.Visibility & MemberVisibility.Static) == 0)
                {
                    Debug.Assert(constructor == null);
                    constructor = (ConstructorSymbol)memberSymbol;
                }
                else
                {
                    Debug.Assert(staticConstructor == null);
                    staticConstructor = (ConstructorSymbol)memberSymbol;
                }
            }
            else if (memberSymbol.Type == SymbolType.Indexer)
            {
                Debug.Assert(IsApplicationType == false || indexer == null);
                indexer = (IndexerSymbol)memberSymbol;
            }
            else
            {
                base.AddMember(memberSymbol);
            }
        }
Beispiel #2
0
        public IndexerSymbol GetIndexer()
        {
            if (primaryPartialClass != null)
            {
                return(primaryPartialClass.GetIndexer());
            }

            ClassSymbol   classSymbol = this;
            IndexerSymbol indexer     = classSymbol.Indexer;

            while (indexer == null)
            {
                classSymbol = (ClassSymbol)classSymbol.GetBaseType();

                if (classSymbol == null)
                {
                    break;
                }

                indexer = classSymbol.Indexer;
            }

            return(indexer);
        }
Beispiel #3
0
        private TypeSymbol CreateArrayTypeCore(TypeSymbol itemTypeSymbol)
        {
            TypeSymbol arrayTypeSymbol =
                (TypeSymbol)((ISymbolTable)SystemNamespace).FindSymbol("Array", null, SymbolFilter.Types);

            Debug.Assert(arrayTypeSymbol != null);

            TypeSymbol specificArrayTypeSymbol = new ClassSymbol("Array", SystemNamespace);

            foreach (MemberSymbol memberSymbol in arrayTypeSymbol.Members)
            {
                specificArrayTypeSymbol.AddMember(memberSymbol);
            }

            IndexerSymbol indexerSymbol = new IndexerSymbol(specificArrayTypeSymbol, itemTypeSymbol,
                                                            MemberVisibility.Public);

            indexerSymbol.SetScriptIndexer();
            specificArrayTypeSymbol.AddMember(indexerSymbol);
            specificArrayTypeSymbol.SetIgnoreNamespace();
            specificArrayTypeSymbol.SetNativeArray();

            return(specificArrayTypeSymbol);
        }
Beispiel #4
0
        private void CreateGenericTypeMembers(TypeSymbol templateType, TypeSymbol instanceType,
                                              IList <TypeSymbol> typeArguments)
        {
            foreach (MemberSymbol memberSymbol in templateType.Members)
            {
                if (memberSymbol.AssociatedType.Type == SymbolType.GenericParameter &&
                    ((GenericParameterSymbol)memberSymbol.AssociatedType).IsTypeParameter)
                {
                    MemberSymbol instanceMemberSymbol = CreateGenericMember(memberSymbol, typeArguments);
                    instanceType.AddMember(instanceMemberSymbol);
                }
                else if (memberSymbol.AssociatedType.IsGeneric &&
                         memberSymbol.AssociatedType.GenericArguments == null &&
                         memberSymbol.AssociatedType.GenericParameters.Count == typeArguments.Count)
                {
                    TypeSymbol genericType = CreateGenericTypeSymbol(memberSymbol.AssociatedType, typeArguments);

                    if (genericType == null)
                    {
                        genericType = instanceType;
                    }

                    List <TypeSymbol> memberTypeArgs = new List <TypeSymbol> {
                        genericType
                    };

                    MemberSymbol instanceMemberSymbol = CreateGenericMember(memberSymbol, memberTypeArgs);
                    instanceType.AddMember(instanceMemberSymbol);
                }
                else
                {
                    instanceType.AddMember(memberSymbol);
                }
            }

            IndexerSymbol indexer = null;

            if (templateType.Type == SymbolType.Class)
            {
                indexer = ((ClassSymbol)templateType).Indexer;
            }
            else if (templateType.Type == SymbolType.Interface)
            {
                indexer = ((InterfaceSymbol)templateType).Indexer;
            }

            if (indexer != null)
            {
                if (indexer.AssociatedType.Type == SymbolType.GenericParameter)
                {
                    MemberSymbol instanceIndexer = CreateGenericMember(indexer, typeArguments);
                    instanceType.AddMember(instanceIndexer);
                }
                else if (indexer.AssociatedType.IsGeneric &&
                         indexer.AssociatedType.GenericArguments == null &&
                         indexer.AssociatedType.GenericParameters.Count == typeArguments.Count)
                {
                    TypeSymbol genericType = CreateGenericTypeSymbol(indexer.AssociatedType, typeArguments);

                    if (genericType == null)
                    {
                        genericType = instanceType;
                    }

                    List <TypeSymbol> memberTypeArgs = new List <TypeSymbol> {
                        genericType
                    };

                    MemberSymbol instanceMemberSymbol = CreateGenericMember(indexer, memberTypeArgs);
                    instanceType.AddMember(instanceMemberSymbol);
                }
                else
                {
                    instanceType.AddMember(indexer);
                }
            }
        }
Beispiel #5
0
        private MemberSymbol CreateGenericMember(MemberSymbol templateMember, IList <TypeSymbol> typeArguments)
        {
            TypeSymbol parentType = (TypeSymbol)templateMember.Parent;
            TypeSymbol instanceAssociatedType;

            if (templateMember.AssociatedType.Type == SymbolType.GenericParameter)
            {
                GenericParameterSymbol genericParameter = (GenericParameterSymbol)templateMember.AssociatedType;
                instanceAssociatedType = typeArguments[genericParameter.Index];
            }
            else
            {
                instanceAssociatedType = typeArguments[0];
            }

            if (templateMember.Type == SymbolType.Indexer)
            {
                IndexerSymbol templateIndexer = (IndexerSymbol)templateMember;
                IndexerSymbol instanceIndexer = new IndexerSymbol(parentType, instanceAssociatedType);

                if (templateIndexer.UseScriptIndexer)
                {
                    instanceIndexer.SetScriptIndexer();
                }

                instanceIndexer.SetVisibility(templateIndexer.Visibility);

                return(instanceIndexer);
            }

            if (templateMember.Type == SymbolType.Property)
            {
                PropertySymbol templateProperty = (PropertySymbol)templateMember;
                PropertySymbol instanceProperty =
                    new PropertySymbol(templateProperty.Name, parentType, instanceAssociatedType);

                if (templateProperty.IsTransformed)
                {
                    instanceProperty.SetTransformedName(templateProperty.GeneratedName);
                }

                instanceProperty.SetNameCasing(templateProperty.IsCasePreserved);
                instanceProperty.SetVisibility(templateProperty.Visibility);

                return(instanceProperty);
            }

            if (templateMember.Type == SymbolType.Field)
            {
                FieldSymbol templateField = (FieldSymbol)templateMember;
                FieldSymbol instanceField = new FieldSymbol(templateField.Name, parentType, instanceAssociatedType);

                if (templateField.IsTransformed)
                {
                    instanceField.SetTransformName(templateField.GeneratedName);
                }

                instanceField.SetNameCasing(templateField.IsCasePreserved);
                instanceField.SetVisibility(templateField.Visibility);

                return(instanceField);
            }

            if (templateMember.Type == SymbolType.Method)
            {
                MethodSymbol templateMethod = (MethodSymbol)templateMember;
                MethodSymbol instanceMethod = new MethodSymbol(templateMethod.Name, parentType, instanceAssociatedType);

                if (templateMethod.IsAliased)
                {
                    instanceMethod.SetTransformedName(templateMethod.TransformName);
                }
                else if (templateMethod.IsTransformed)
                {
                    instanceMethod.SetTransformedName(templateMethod.GeneratedName);
                }

                if (templateMethod.SkipGeneration)
                {
                    instanceMethod.SetSkipGeneration();
                }

                if (templateMethod.InterfaceMember != null)
                {
                    instanceMethod.SetInterfaceMember(templateMethod.InterfaceMember);
                }

                instanceMethod.SetNameCasing(templateMethod.IsCasePreserved);
                instanceMethod.SetVisibility(templateMethod.Visibility);

                return(instanceMethod);
            }

            Debug.Fail("Unexpected generic member '" + templateMember.Name + " on type '" +
                       ((TypeSymbol)templateMember.Parent).FullName + "'.");

            return(null);
        }