Exemple #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);
            }
        }
        public IndexerExpression(Expression objectReference, IndexerSymbol indexer)
            : base(ExpressionType.Indexer, indexer.AssociatedType, SymbolFilter.Public | SymbolFilter.InstanceMembers) {
            _indexer = indexer;
            _objectReference = objectReference;

            _indices = new Collection<Expression>();
        }
Exemple #3
0
 private void DumpIndexer(IndexerSymbol indexerSymbol)
 {
     _writer.Write("ReadOnly: ");
     _writer.WriteLine(indexerSymbol.IsReadOnly);
     _writer.Write("Abstract: ");
     _writer.WriteLine(indexerSymbol.IsAbstract);
 }
Exemple #4
0
        public IndexerExpression(Expression objectReference, IndexerSymbol indexer)
            : base(ExpressionType.Indexer, indexer.AssociatedType, SymbolFilter.Public | SymbolFilter.InstanceMembers)
        {
            _indexer         = indexer;
            _objectReference = objectReference;

            _indices = new Collection <Expression>();
        }
Exemple #5
0
 public static void GenerateScript(ScriptGenerator generator, IndexerSymbol symbol, bool getter) {
     SymbolImplementation accessorImpl;
     if (getter) {
         accessorImpl = symbol.GetterImplementation;
     }
     else {
         accessorImpl = symbol.SetterImplementation;
     }
     GenerateImplementationScript(generator, symbol, accessorImpl);
 }
        public override void AddMember(MemberSymbol memberSymbol) {
            Debug.Assert(memberSymbol != null);

            if (memberSymbol.Type == SymbolType.Indexer) {
                Debug.Assert(_indexer == null);
                _indexer = (IndexerSymbol)memberSymbol;
            }
            else {
                base.AddMember(memberSymbol);
            }
        }
Exemple #7
0
        public override void AddMember(MemberSymbol memberSymbol)
        {
            Debug.Assert(memberSymbol != null);

            if (memberSymbol.Type == SymbolType.Indexer)
            {
                Debug.Assert(_indexer == null);
                _indexer = (IndexerSymbol)memberSymbol;
            }
            else
            {
                base.AddMember(memberSymbol);
            }
        }
Exemple #8
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);
        }
Exemple #9
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.SetArray();

            return(specificArrayTypeSymbol);
        }
Exemple #10
0
        private ParameterSymbol BuildParameter(ParameterNode parameterNode, IndexerSymbol indexerSymbol) {
            TypeSymbol parameterType = indexerSymbol.SymbolSet.ResolveType(parameterNode.Type, _symbolTable, indexerSymbol);
            Debug.Assert(parameterType != null);

            if (parameterType != null) {
                return new ParameterSymbol(parameterNode.Name, indexerSymbol, parameterType, ParameterMode.In);
            }

            return null;
        }
        public SymbolImplementation BuildIndexerSetter(IndexerSymbol indexerSymbol)
        {
            AccessorNode setterNode = ((IndexerDeclarationNode)indexerSymbol.ParseContext).SetAccessor;
            BlockStatementNode accessorBody = setterNode.Implementation;

            return BuildImplementation((ISymbolTable)indexerSymbol.Parent,
                                       indexerSymbol, accessorBody, /* addAllParameters */ true);
        }
        private void ImportProperties(TypeSymbol typeSymbol)
        {
            TypeDefinition type = (TypeDefinition)typeSymbol.MetadataReference;

            foreach (PropertyDefinition property in type.Properties) {
                if (property.IsSpecialName) {
                    continue;
                }
                if (property.GetMethod == null) {
                    continue;
                }
                if (property.GetMethod.IsPrivate || property.GetMethod.IsAssembly || property.GetMethod.IsFamilyAndAssembly) {
                    continue;
                }

                string propertyName = property.Name;
                bool preserveCase = MetadataHelpers.ShouldPreserveCase(property);
                bool intrinsicProperty = MetadataHelpers.ShouldTreatAsIntrinsicProperty(property);

                TypeSymbol propertyType = ResolveType(property.PropertyType);
                if (propertyType == null) {
                    continue;
                }

                PropertySymbol propertySymbol = null;
                if (property.Parameters.Count != 0) {
                    IndexerSymbol indexerSymbol = new IndexerSymbol(typeSymbol, propertyType);
                    ImportMemberDetails(indexerSymbol, property.GetMethod, property);

                    if (intrinsicProperty) {
                        indexerSymbol.SetIntrinsic();
                    }

                    propertySymbol = indexerSymbol;
                    propertySymbol.SetNameCasing(preserveCase);
                }
                else {
                    if (intrinsicProperty) {
                        // Properties marked with this attribute are to be thought of as
                        // fields. If they are read-only, the C# compiler will enforce that,
                        // so we don't have to worry about making them read-write via a field
                        // instead of a property

                        FieldSymbol fieldSymbol = new FieldSymbol(propertyName, typeSymbol, propertyType);
                        ImportMemberDetails(fieldSymbol, property.GetMethod, property);

                        string alias = MetadataHelpers.GetScriptAlias(property);
                        if (String.IsNullOrEmpty(alias) == false) {
                            fieldSymbol.SetAlias(alias);
                        }

                        typeSymbol.AddMember(fieldSymbol);
                    }
                    else {
                        propertySymbol = new PropertySymbol(propertyName, typeSymbol, propertyType);
                        ImportMemberDetails(propertySymbol, property.GetMethod, property);
                    }
                }

                if (propertySymbol != null) {
                    SymbolImplementationFlags implFlags = SymbolImplementationFlags.Regular;
                    if (property.SetMethod == null) {
                        implFlags |= SymbolImplementationFlags.ReadOnly;
                    }
                    if (property.GetMethod.IsAbstract) {
                        implFlags |= SymbolImplementationFlags.Abstract;
                    }
                    propertySymbol.SetImplementationState(implFlags);

                    typeSymbol.AddMember(propertySymbol);
                }
            }
        }
Exemple #13
0
        private IndexerSymbol BuildIndexer(IndexerDeclarationNode indexerNode, TypeSymbol typeSymbol) {
            TypeSymbol indexerType = typeSymbol.SymbolSet.ResolveType(indexerNode.Type, _symbolTable, typeSymbol);
            Debug.Assert(indexerType != null);

            if (indexerType != null) {
                IndexerSymbol indexer = new IndexerSymbol(typeSymbol, indexerType);
                BuildMemberDetails(indexer, typeSymbol, indexerNode, indexerNode.Attributes);

                if (AttributeNode.FindAttribute(indexerNode.Attributes, "IntrinsicProperty") != null) {
                    indexer.SetIntrinsic();
                }

                SymbolImplementationFlags implFlags = SymbolImplementationFlags.Regular;
                if (indexerNode.SetAccessor == null) {
                    implFlags |= SymbolImplementationFlags.ReadOnly;
                }
                if ((indexerNode.Modifiers & Modifiers.Abstract) != 0) {
                    implFlags |= SymbolImplementationFlags.Abstract;
                }
                else if ((indexerNode.Modifiers & Modifiers.Override) != 0) {
                    implFlags |= SymbolImplementationFlags.Override;
                }

                indexer.SetImplementationState(implFlags);

                Debug.Assert(indexerNode.Parameters.Count != 0);
                foreach (ParameterNode parameterNode in indexerNode.Parameters) {
                    ParameterSymbol paramSymbol = BuildParameter(parameterNode, indexer);
                    if (paramSymbol != null) {
                        paramSymbol.SetParseContext(parameterNode);
                        indexer.AddParameter(paramSymbol);
                    }
                }

                indexer.AddParameter(new ParameterSymbol("value", indexer, indexerType, ParameterMode.In));

                return indexer;
            }

            return null;
        }
        private void ImportPseudoMembers(PseudoClassMembers memberSet, ClassSymbol classSymbol)
        {
            // Import pseudo members that go on the class but aren't defined in mscorlib.dll
            // These are meant to be used by internal compiler-generated transformations etc.
            // and aren't meant to be referenced directly in C# code.

            if (memberSet == PseudoClassMembers.Script) {
                TypeSymbol boolType = (TypeSymbol)((ISymbolTable)_symbols.SystemNamespace).FindSymbol("Boolean", null, SymbolFilter.Types);
                Debug.Assert(boolType != null);

                TypeSymbol intType = (TypeSymbol)((ISymbolTable)_symbols.SystemNamespace).FindSymbol("Int32", null, SymbolFilter.Types);
                Debug.Assert(intType != null);

                TypeSymbol floatType = (TypeSymbol)((ISymbolTable)_symbols.SystemNamespace).FindSymbol("Single", null, SymbolFilter.Types);
                Debug.Assert(floatType != null);

                TypeSymbol stringType = (TypeSymbol)((ISymbolTable)_symbols.SystemNamespace).FindSymbol("String", null, SymbolFilter.Types);
                Debug.Assert(stringType != null);

                // Define the Escape, Unescape, encodeURI, decodeURI, encodeURIComponent, decodeURIComponent methods
                MethodSymbol escapeMethod = new MethodSymbol("Escape", classSymbol, stringType, MemberVisibility.Public | MemberVisibility.Static);
                classSymbol.AddMember(escapeMethod);

                MethodSymbol unescapeMethod = new MethodSymbol("Unescape", classSymbol, stringType, MemberVisibility.Public | MemberVisibility.Static);
                classSymbol.AddMember(unescapeMethod);

                MethodSymbol encodeURIMethod = new MethodSymbol("EncodeUri", classSymbol, stringType, MemberVisibility.Public | MemberVisibility.Static);
                encodeURIMethod.SetTransformedName("encodeURI");
                classSymbol.AddMember(encodeURIMethod);

                MethodSymbol decodeURIMethod = new MethodSymbol("DecodeUri", classSymbol, stringType, MemberVisibility.Public | MemberVisibility.Static);
                decodeURIMethod.SetTransformedName("decodeURI");
                classSymbol.AddMember(decodeURIMethod);

                MethodSymbol encodeURIComponentMethod = new MethodSymbol("EncodeUriComponent", classSymbol, stringType, MemberVisibility.Public | MemberVisibility.Static);
                encodeURIComponentMethod.SetTransformedName("encodeURIComponent");
                classSymbol.AddMember(encodeURIComponentMethod);

                MethodSymbol decodeURIComponentMethod = new MethodSymbol("DecodeUriComponent", classSymbol, stringType, MemberVisibility.Public | MemberVisibility.Static);
                decodeURIComponentMethod.SetTransformedName("decodeURIComponent");
                classSymbol.AddMember(decodeURIComponentMethod);

                return;
            }

            if (memberSet == PseudoClassMembers.Arguments) {
                TypeSymbol objectType = (TypeSymbol)((ISymbolTable)_symbols.SystemNamespace).FindSymbol("Object", null, SymbolFilter.Types);
                Debug.Assert(objectType != null);

                IndexerSymbol indexer = new IndexerSymbol(classSymbol, objectType, MemberVisibility.Public | MemberVisibility.Static);
                indexer.SetIntrinsic();
                classSymbol.AddMember(indexer);

                return;
            }

            if (memberSet == PseudoClassMembers.Type) {
                // Define the Type.GetInstanceType static method which provides the functionality of
                // Object.GetType instance method. We don't extend Object.prototype in script to add
                // GetType, since we want to keep Object's protoype clean of any extensions.
                //
                // We create this symbol here, so that later the ExpressionBuilder can transform
                // calls to Object.GetType to this.
                TypeSymbol objectType = (TypeSymbol)((ISymbolTable)_symbols.SystemNamespace).FindSymbol("Object", null, SymbolFilter.Types);
                Debug.Assert(objectType != null);

                TypeSymbol typeType = (TypeSymbol)((ISymbolTable)_symbols.SystemNamespace).FindSymbol("Type", null, SymbolFilter.Types);
                Debug.Assert(objectType != null);

                MethodSymbol getTypeMethod = new MethodSymbol("GetInstanceType", classSymbol, typeType, MemberVisibility.Public | MemberVisibility.Static);
                getTypeMethod.AddParameter(new ParameterSymbol("instance", getTypeMethod, objectType, ParameterMode.In));
                classSymbol.AddMember(getTypeMethod);

                return;
            }

            if (memberSet == PseudoClassMembers.Dictionary) {
                TypeSymbol intType = (TypeSymbol)((ISymbolTable)_symbols.SystemNamespace).FindSymbol("Int32", null, SymbolFilter.Types);
                Debug.Assert(intType != null);

                TypeSymbol boolType = (TypeSymbol)((ISymbolTable)_symbols.SystemNamespace).FindSymbol("Boolean", null, SymbolFilter.Types);
                Debug.Assert(boolType != null);

                TypeSymbol voidType = (TypeSymbol)((ISymbolTable)_symbols.SystemNamespace).FindSymbol("Void", null, SymbolFilter.Types);
                Debug.Assert(boolType != null);

                TypeSymbol stringType = (TypeSymbol)((ISymbolTable)_symbols.SystemNamespace).FindSymbol("String", null, SymbolFilter.Types);
                Debug.Assert(boolType != null);

                // Define Dictionary.Keys
                MethodSymbol getKeysMethod = new MethodSymbol("GetKeys", classSymbol, _symbols.CreateArrayTypeSymbol(stringType), MemberVisibility.Public | MemberVisibility.Static);
                getKeysMethod.SetTransformedName("keys");
                classSymbol.AddMember(getKeysMethod);

                // Define Dictionary.GetCount
                MethodSymbol countMethod = new MethodSymbol("GetKeyCount", classSymbol, intType, MemberVisibility.Public | MemberVisibility.Static);
                classSymbol.AddMember(countMethod);

                // Define Dictionary.ClearKeys
                MethodSymbol clearMethod = new MethodSymbol("ClearKeys", classSymbol, voidType, MemberVisibility.Public | MemberVisibility.Static);
                classSymbol.AddMember(clearMethod);

                // Define Dictionary.DeleteKey
                MethodSymbol deleteMethod = new MethodSymbol("DeleteKey", classSymbol, voidType, MemberVisibility.Public | MemberVisibility.Static);
                classSymbol.AddMember(deleteMethod);

                // Define Dictionary.KeyExists
                MethodSymbol existsMethod = new MethodSymbol("KeyExists", classSymbol, boolType, MemberVisibility.Public | MemberVisibility.Static);
                classSymbol.AddMember(existsMethod);

                return;
            }

            if (memberSet == PseudoClassMembers.String) {
                // In script, String.replace replaces only the first occurrence of a string
                // whereas in C# all occurrences are replaced.
                // Replace becomes replaceAll (a method we add) in generated script
                // ReplaceFirst becomes replace in generated script.
                // ReplaceRegex also becomes replace in generated script. (We added ReplaceRegex so
                //   it could be mapped to the native replace method, rather than out replaceAll
                //   extension)

                MethodSymbol replaceFirstMethod = (MethodSymbol)classSymbol.GetMember("ReplaceFirst");
                Debug.Assert(replaceFirstMethod != null);
                replaceFirstMethod.SetTransformedName("replace");

                MethodSymbol replaceMethod = (MethodSymbol)classSymbol.GetMember("Replace");
                Debug.Assert(replaceMethod != null);
                replaceMethod.SetTransformedName("replaceAll");

                MethodSymbol replaceRegexMethod = (MethodSymbol)classSymbol.GetMember("ReplaceRegex");
                Debug.Assert(replaceRegexMethod != null);
                replaceRegexMethod.SetTransformedName("replace");
            }
        }
Exemple #15
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);
            }
        }
        private static void GenerateIndexerComment(ScriptTextWriter writer, IndexerSymbol indexerSymbol) {
            GenerateSummaryComment(writer, indexerSymbol);

            if (indexerSymbol.Parameters != null) {
                foreach (ParameterSymbol parameterSymbol in indexerSymbol.Parameters) {
                    GenerateParameterComment(writer, parameterSymbol);
                }
            }

            GenerateReturnsComment(writer, indexerSymbol.AssociatedType);
        }
Exemple #17
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.SetArray();

            return specificArrayTypeSymbol;
        }
Exemple #18
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);
                }
            }
        }
Exemple #19
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);
            }
            else 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);
            }
            else if (templateMember.Type == SymbolType.Field)
            {
                FieldSymbol templateField = (FieldSymbol)templateMember;
                FieldSymbol instanceField = new FieldSymbol(templateField.Name, parentType, instanceAssociatedType);

                if (templateField.IsTransformed)
                {
                    instanceField.SetTransformedName(templateField.GeneratedName);
                }
                instanceField.SetNameCasing(templateField.IsCasePreserved);
                instanceField.SetVisibility(templateField.Visibility);

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

                if (templateMethod.IsAliased)
                {
                    instanceMethod.SetAlias(templateMethod.Alias);
                }
                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);
        }
 private void DumpIndexer(IndexerSymbol indexerSymbol)
 {
     _writer.Write("ReadOnly: ");
     _writer.WriteLine(indexerSymbol.IsReadOnly);
     _writer.Write("Abstract: ");
     _writer.WriteLine(indexerSymbol.IsAbstract);
 }
Exemple #21
0
        private void BuildCode(IndexerSymbol indexerSymbol)
        {
            if (indexerSymbol.IsAbstract) {
                return;
            }

            ImplementationBuilder implBuilder = new ImplementationBuilder(_options, _errorHandler);

            indexerSymbol.AddImplementation(implBuilder.BuildIndexerGetter(indexerSymbol), /* getter */ true);
            _implementations.Add(indexerSymbol.GetterImplementation);

            if (indexerSymbol.IsReadOnly == false) {
                indexerSymbol.AddImplementation(implBuilder.BuildPropertySetter(indexerSymbol), /* getter */ false);
                _implementations.Add(indexerSymbol.SetterImplementation);
            }

            if (indexerSymbol.AnonymousMethods != null) {
                foreach (AnonymousMethodSymbol anonymousMethod in indexerSymbol.AnonymousMethods) {
                    Debug.Assert(anonymousMethod.Implementation != null);

                    _implementations.Add(anonymousMethod.Implementation);
                }
            }
        }
Exemple #22
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;
            }
            else 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;
            }
            else if (templateMember.Type == SymbolType.Field) {
                FieldSymbol templateField = (FieldSymbol)templateMember;
                FieldSymbol instanceField = new FieldSymbol(templateField.Name, parentType, instanceAssociatedType);

                if (templateField.IsTransformed) {
                    instanceField.SetTransformedName(templateField.GeneratedName);
                }
                instanceField.SetNameCasing(templateField.IsCasePreserved);
                instanceField.SetVisibility(templateField.Visibility);

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

                if (templateMethod.IsAliased) {
                    instanceMethod.SetAlias(templateMethod.Alias);
                }
                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;
        }