/// <summary>
        /// Adds a synthesized method to the class.
        /// </summary>
        public void AddMethod(Cci.ITypeDefinition container, MethodSymbol method)
        {
            Contract.ThrowIfNull(method);
            Debug.Assert(method.IsImplicitlyDeclared);

            AddMember(container, method);
        }
        /// <summary>
        /// Gets or initializes static constructor symbol.
        /// </summary>
        public MethodSymbol /*!*/ EnsureStaticCtor(Cci.ITypeDefinition container)
        {
            Contract.ThrowIfNull(container);

            //if (container is NamedTypeSymbol)
            //{
            //    var cctors = ((NamedTypeSymbol)container).StaticConstructors;
            //    if (!cctors.IsDefaultOrEmpty)
            //    {
            //        return cctors[0];
            //    }
            //}

            //
            var members = EnsureList(container);

            lock (members)
            {
                //
                var cctor = members.OfType <SynthesizedCctorSymbol>().FirstOrDefault();
                if (cctor == null)
                {
                    cctor = new SynthesizedCctorSymbol(container, DeclaringCompilation.SourceModule);
                    members.Add(cctor);
                }
                return(cctor);
            }

            //
        }
        /// <summary>
        /// Adds a type member to the class.
        /// </summary>
        /// <param name="container">Containing type.</param>
        /// <param name="nestedType">Type to be added as nested type.</param>
        public void AddNestedType(Cci.ITypeDefinition container, NamedTypeSymbol nestedType)
        {
            Contract.ThrowIfNull(nestedType);
            Debug.Assert(nestedType.IsImplicitlyDeclared);
            Debug.Assert((container as ISymbol)?.ContainingType == null); // can't nest in nested type

            AddMember(container, nestedType);
        }
Exemple #4
0
 public SynthesizedMethodSymbol(Cci.ITypeDefinition containingType, ModuleSymbol module, string name, bool isstatic, bool isvirtual, TypeSymbol returnType, Accessibility accessibility = Accessibility.Private, bool isfinal = true, bool isabstract = false)
 {
     _type          = containingType ?? throw new ArgumentNullException(nameof(containingType));
     _module        = module ?? throw new ArgumentNullException(nameof(module));
     _name          = name;
     _static        = isstatic;
     _virtual       = isvirtual && !isstatic;
     _abstract      = isvirtual && isabstract && !isfinal;
     _return        = returnType;
     _accessibility = accessibility;
     _final         = isfinal && isvirtual && !isstatic;
 }
        /// <summary>
        /// Gets synthezised members contained in <paramref name="container"/>.
        /// </summary>
        /// <remarks>
        /// This method is not thread-safe, it is expected to be called after all
        /// the synthesized members were added to <paramref name="container"/>.
        /// </remarks>
        /// <typeparam name="T">Type of members to enumerate.</typeparam>
        /// <param name="container">Containing type.</param>
        /// <returns>Enumeration of synthesized type members.</returns>
        public IEnumerable <T> GetMembers <T>(Cci.ITypeDefinition container) where T : ISymbol
        {
            List <Symbol> list;

            if (_membersByType.TryGetValue(container, out list) && list.Count != 0)
            {
                return(list.OfType <T>());
            }
            else
            {
                return(SpecializedCollections.EmptyEnumerable <T>());
            }
        }
        void AddMember(Cci.ITypeDefinition type, Symbol member)
        {
            var members = EnsureList(type);

            lock (members)
            {
                if (members.IndexOf(member) < 0)
                {
                    members.Add(member);
                }
                else
                {
                    Debug.Fail("Member added twice!");
                }
            }
        }
Exemple #7
0
 public VtblGap(Cci.ITypeDefinition containingType, string name)
 {
     this.ContainingType = containingType;
     this.name           = name;
 }
Exemple #8
0
 public VtblGap(Cci.ITypeDefinition containingType, string name)
 {
     this.ContainingType = containingType;
     this.name = name;
 }
 List <Symbol> EnsureList(Cci.ITypeDefinition type)
 {
     return(_membersByType.GetOrAdd(type, (_) => new List <Symbol>()));
 }
 /// <summary>
 /// Adds a synthesized symbol to the class.
 /// </summary>
 public void AddField(Cci.ITypeDefinition container, FieldSymbol field)
 {
     AddMember(container, field);
 }
        /// <summary>
        /// Adds a synthesized property to the class.
        /// </summary>
        public void AddProperty(Cci.ITypeDefinition container, PropertySymbol property)
        {
            Contract.ThrowIfNull(property);

            AddMember(container, property);
        }
Exemple #12
0
 public SynthesizedCctorSymbol(Cci.ITypeDefinition container, ModuleSymbol module)
     : base(container, module, WellKnownMemberNames.StaticConstructorName, true, false, module.DeclaringCompilation.CoreTypes.Void)
 {
     SetParameters(ImmutableArray <ParameterSymbol> .Empty);
 }