示例#1
0
 public IGenericParameterUniqueIdentifier GetIdentifier(IIntermediateGenericParameter member)
 {
     if (member.Position > -1)
     {
         return(TypeSystemIdentifiers.GetGenericParameterIdentifier(member.Position, member.Name, member is IGenericTypeParameter));
     }
     else
     {
         return(TypeSystemIdentifiers.GetGenericParameterIdentifier(member.Name, member is IGenericTypeParameter));
     }
 }
示例#2
0
 public GenericParameterDictionary(SymbolType parent, string[] tParamNames)
     : this(parent)
 {
     if (tParamNames != null)
     {
         this.tParamNames = new IGenericParameterUniqueIdentifier[tParamNames.Length];
         for (int i = 0; i < tParamNames.Length; i++)
         {
             this.tParamNames[i] = TypeSystemIdentifiers.GetGenericParameterIdentifier(i, true);
         }
         this.elements = new GenericParameterMember[tParamNames.Length];
     }
 }
示例#3
0
 protected override IGenericParameterUniqueIdentifier OnGetUniqueIdentifier()
 {
     if (this.uniqueIdentifier == null)
     {
         if (this.Position > -1)
         {
             this.uniqueIdentifier = TypeSystemIdentifiers.GetGenericParameterIdentifier(this.Position, this.Name, true);
         }
         else
         {
             this.uniqueIdentifier = TypeSystemIdentifiers.GetGenericParameterIdentifier(this.Name, true);
         }
     }
     return(this.uniqueIdentifier);
 }
        public TIntermediateGenericParameter[] AddRange(params GenericParameterData[] genericParameterData)
        {
            if (this.Locked)
            {
                throw new InvalidOperationException(Resources.ObjectStateThrowMessage);
            }
            if (genericParameterData == null)
            {
                throw new ArgumentNullException("genericParameterData");
            }
            TIntermediateGenericParameter[]     result      = new TIntermediateGenericParameter[genericParameterData.Length];
            IGenericParameterUniqueIdentifier[] currentKeys = new IGenericParameterUniqueIdentifier[result.Length];

            //Parallel.For(0, genericParameterData.Length, i =>
            for (int i = 0; i < genericParameterData.Length; i++)
            {
                var currentName     = genericParameterData[i].Name;
                var current         = this.GetNew(currentName);
                var currentUniqueId = TypeSystemIdentifiers.GetGenericParameterIdentifier(i + this.Count, currentName, Parent is IType);
                if (this.ContainsKey(currentUniqueId) ||
                    currentKeys.Contains(currentUniqueId))
                {
                    throw new ArgumentException("genericParameterData");
                }
                currentKeys[i] = currentUniqueId;
                result[i]      = current;
            }//**/);
            this._AddRange((from i in 0.RangeTo(genericParameterData.Length)
                            select new KeyValuePair <IGenericParameterUniqueIdentifier, TGenericParameter>(currentKeys[i], result[i])));
            //Parallel.For(0, genericParameterData.Length, i=>
            for (int i = 0; i < genericParameterData.Length; i++)
            {
                var currentParameterData = genericParameterData[i];
                var current = result[i];
                foreach (var constraint in currentParameterData.Constraints)
                {
                    current.Constraints.Add(TransposeType(constraint, current));
                }
                foreach (var ctorSig in currentParameterData.Constructors.Signatures)
                {
                    current.Constructors.Add(TransposeTypedNames(ctorSig.Parameters.ToSeries(), current));
                }
                foreach (var eventGroup in TransposeTypedNames(currentParameterData.Events, current))
                {
                    current.Events.Add(eventGroup);
                }
                foreach (var indexerSig in currentParameterData.Indexers.Signatures)
                {
                    current.Indexers.Add(TransposeTypedName(new TypedName(indexerSig.Name, indexerSig.ReturnType), current), TransposeTypedNames(indexerSig.Parameters.ToSeries(), current));
                }
                //result.Properties.Add
                current.SpecialConstraint = currentParameterData.SpecialConstraint;
                foreach (var method in currentParameterData.Methods.Signatures)
                {
                    current.Methods.Add(TransposeTypedName(new TypedName(method.Name, method.ReturnType), current), TransposeTypedNames(method.Parameters.ToSeries(), current));
                }
            }//*/);

            //Parallel.For(0, genericParameterData.Length, i =>
            //for (int i = 0; i < genericParameterData.Length; i++)
            //{
            //    var currentParameterData = genericParameterData[i];
            //    var current = result[i];
            //    foreach (var constraint in currentParameterData.Constraints)
            //        if (constraint.ContainsSymbols())
            //            current.Constraints.Add(constraint.SimpleSymbolDisambiguation(current));
            //        else
            //            current.Constraints.Add(constraint);
            //    foreach (var ctor in current.Constructors.Values)
            //        foreach (var param in ctor.Parameters.Values)
            //            if (param.ParameterType.ContainsSymbols())
            //                param.ParameterType = param.ParameterType.SimpleSymbolDisambiguation(current);
            //    foreach (var method in current.Methods.Values)
            //    {
            //        foreach (var param in method.Parameters.Values)
            //            if (param.ParameterType.ContainsSymbols())
            //                param.ParameterType = param.ParameterType.SimpleSymbolDisambiguation(current);
            //        if (method.ReturnType.ContainsSymbols())
            //            method.ReturnType = method.ReturnType.SimpleSymbolDisambiguation(current);
            //    }
            //    foreach (var property in current.Properties.Values)
            //        if (property.PropertyType.ContainsSymbols())
            //            property.PropertyType = property.PropertyType.SimpleSymbolDisambiguation(current);

            //    foreach (var indexer in current.Indexers.Values)
            //    {
            //        if (indexer.PropertyType.ContainsSymbols())
            //            indexer.PropertyType = indexer.PropertyType.SimpleSymbolDisambiguation(current);
            //        foreach (var param in indexer.Parameters.Values)
            //            if (param.ParameterType.ContainsSymbols())
            //                param.ParameterType = param.ParameterType.SimpleSymbolDisambiguation(current);
            //    }
            //}//);
            return(result);
        }
        public TIntermediateGenericParameter Add(GenericParameterData genericParameterData)
        {
            if (this.Locked)
            {
                throw new InvalidOperationException(Resources.ObjectStateThrowMessage);
            }
            if (string.IsNullOrEmpty(genericParameterData.Name))
            {
                throw new ArgumentException("genericParameterData");
            }
            int index          = this.Count;
            var defaultParamId = TypeSystemIdentifiers.GetGenericParameterIdentifier(index, this.Parent is IType);
            var result         = this.GetNew(genericParameterData.Name);

            if (this.ContainsKey(defaultParamId))
            {
                throw new ArgumentException("genericParameterData");
            }
            foreach (var ctorSig in genericParameterData.Constructors.Signatures)
            {
                result.Constructors.Add(TransposeTypedNames(ctorSig.Parameters.ToSeries(), result));
            }
            var disambiguatedEvents = TransposeTypedNames(genericParameterData.Events, result);

            foreach (var eventGroup in disambiguatedEvents)
            {
                result.Events.Add(eventGroup);
            }
            IControlledTypeCollection typeParameters       = null;
            IControlledTypeCollection methodTypeParameters = null;

            foreach (var constraint in genericParameterData.Constraints)
            {
                if (constraint.ContainsSymbols())
                {
                    if (constraint.ContainsGenericParameters())
                    {
                        result.Constraints.Add(Disambiguate(constraint).SimpleSymbolDisambiguation(result));
                    }
                    else
                    {
                        result.Constraints.Add(constraint.SimpleSymbolDisambiguation(result));
                    }
                }
                else if (constraint.ContainsGenericParameters())
                {
                    result.Constraints.Add(Disambiguate(constraint));
                }
                else
                {
                    result.Constraints.Add(constraint);
                }
            }
            result.SpecialConstraint = genericParameterData.SpecialConstraint;
            //foreach (var propertyGroup in genericParameterData.Properties)
            //result.Properties.Add
            foreach (var method in genericParameterData.Methods.Signatures)
            {
                result.Methods.Add(new TypedName(method.Name, method.ReturnType), method.Parameters.ToSeries());
            }
            this._Add(defaultParamId, result);
            this.Keys[index] = result.UniqueIdentifier;
            return(result);
        }
示例#6
0
 protected override IGenericParameterUniqueIdentifier OnGetUniqueIdentifier()
 {
     return(TypeSystemIdentifiers.GetGenericParameterIdentifier((int)this.Position, false));
 }
示例#7
0
 protected override IGenericParameterUniqueIdentifier GetIdentifierFrom(int index, ICliMetadataGenericParameterTableRow metadata)
 {
     return(TypeSystemIdentifiers.GetGenericParameterIdentifier(index, false));
 }
示例#8
0
        public void BuildVisitor()
        {
            var nameWithoutTail      = string.Join("", this.NameParts.Take(this.NameParts.Length - 1)).LowerFirstCharacter();
            var namePartsWithoutTail = this.NameParts.Take(this.NameParts.Length - 1).Select(k => k.ToLower()).ToArray();
            var lastItem             = namePartsWithoutTail.Last();

            if (lastItem == "code")
#pragma warning disable 642
            {
                ;//Do nothing, keep it the same.
            }
#pragma warning restore 642
            else if (lastItem.EndsWith("y"))
            {
                namePartsWithoutTail[namePartsWithoutTail.Length - 1] = lastItem.Substring(0, lastItem.Length - 1) + "ies";
            }
            else if (!lastItem.EndsWith("s"))
            {
                namePartsWithoutTail[namePartsWithoutTail.Length - 1] = lastItem + "s";
            }

            IGenericTypeParameter <IGeneralGenericTypeUniqueIdentifier, IInterfaceType> tResult;
            IGenericTypeParameter <IGeneralGenericTypeUniqueIdentifier, IInterfaceType> tContext;
            this.VisitorInterface.TypeParameters.TryGetValue(TypeSystemIdentifiers.GetGenericParameterIdentifier("TResult"), out tResult);
            this.VisitorInterface.TypeParameters.TryGetValue(TypeSystemIdentifiers.GetGenericParameterIdentifier("TContext"), out tContext);
            this.VisitorInterface.SummaryText = string.Format("Represents a basic visitor for {2}{0}{1}.", tResult != null ? " which yields a result of @t:TResult;" : string.Empty, tContext != null ? string.Format("{0} has a @t:TContext; relevant to the visit", tResult != null ? " and also" : " which") : string.Empty, string.Join(" ", namePartsWithoutTail));
            if (tResult != null)
            {
                ((IIntermediateGenericTypeParameter <IGeneralGenericTypeUniqueIdentifier, IInterfaceType, IIntermediateInterfaceType>)(tResult)).SummaryText = string.Format("Denotes the type of result the members of the @s:{0}; should yield.", this.VisitorInterface.MakeGenericClosure(this.VisitorInterface.GenericParameters).BuildTypeName(true, typeParameterDisplayMode: TypeParameterDisplayMode.CommentStandard));
            }
            if (tContext != null)
            {
                ((IIntermediateGenericTypeParameter <IGeneralGenericTypeUniqueIdentifier, IInterfaceType, IIntermediateInterfaceType>)(tContext)).SummaryText = string.Format("Denotes the type of context the members of the @s:{0}; should receive along with the types that accept the visitor.", this.VisitorInterface.MakeGenericClosure(this.VisitorInterface.GenericParameters).BuildTypeName(true, typeParameterDisplayMode: TypeParameterDisplayMode.CommentStandard));
            }
            IType resultType   = tResult ?? this._assembly.IdentityManager.ObtainTypeReference(RuntimeCoreType.VoidType);
            var   methodLookup = new Dictionary <IType, IIntermediateInterfaceMethodMember>();
            /* Skipped types are for the notion of inheritance-based visitors which are derived from multiple other visitors, we skip the types associated to those inherited visitors to avoid repeating their signatures. */
            foreach (var type in this.RelevantTypes.Except(this.SkippedTypes).OrderBy(k => k.FullName))
            {
                var gpData = new List <GenericParameterData>();
                if (type.IsGenericConstruct)
                {
                    var genericType = (IGenericType)type;
                    if (genericType.IsGenericDefinition)
                    {
                        foreach (IGenericTypeParameter typeParam in genericType.TypeParameters.Values)
                        {
                            gpData.Add(new GenericParameterData(typeParam.Name, typeParam.Constraints.Select(k => k.TurnTypeParametersIntoSymbols()) /*.Select(constraint=>constraint.IsGenericConstruct ? ((IGenericType)(constraint)).MakeGenericClosure(((IGenericType)(constraint)).GenericParameters) : constraint.IsGenericTypeParameter ? constraint.Name.GetSymbolType() : constraint)*/.ToArray())
                            {
                                SpecialConstraint = typeParam.SpecialConstraint
                            });
                        }
                    }
                }
                TypedNameSeries paramData = new TypedNameSeries();
                paramData.Add(type.WithName(nameWithoutTail));

                if (tContext != null)
                {
                    paramData.Add(tContext.WithName("context"));
                }
                var method = this.VisitorInterface.Methods.Add(resultType.WithName("Visit"), paramData, gpData.ToArray());
                methodLookup.Add(type, method);
                if (tContext != null)
                {
                    var contextParam = method.Parameters["context"];
                    contextParam.SummaryText = "The @t:TContext; relevant to the visit.";
                }
                var inputParam = method.Parameters[nameWithoutTail];
                if (tResult != null)
                {
                    method.SummaryText = string.Format("Returns a @t:{1}; after it visits the @p:{0}; provided{2}.", inputParam.Name, tResult.Name, tContext == null ? string.Empty : " with the given @p:context;");
                    method.ReturnsText = @"Returns the value of @t:TResult; relative to the implementation of the visitor.";
                }
                else
                {
                    method.SummaryText = string.Format("Visits the @p:{0}; provided{1}.", inputParam.Name, tContext == null ? string.Empty : " with the given @p:context;");
                }
                var    commentType = ((IGenericType)(type));
                string ofText      = string.Empty;
                if (commentType.IsGenericConstruct && !commentType.IsGenericDefinition && this._detail.TypeParameterVariations != null && this._detail.TypeParameterVariations.Length > 0)
                {
                    ofText      = string.Format(" of @s:{0};", commentType.GenericParameters.First().BuildTypeName());
                    commentType = (IGenericType)commentType.ElementType;
                }
                if (commentType.IsGenericConstruct && commentType.IsGenericDefinition)
                {
                    commentType = commentType.MakeGenericClosure(commentType.GenericParameters);
                }
                inputParam.SummaryText = string.Format("The @s:{0};{1} relevant to the visit.", commentType.BuildTypeName(true, typeParameterDisplayMode: TypeParameterDisplayMode.CommentStandard), ofText);
            }
            this.TypeToMethodLookup = methodLookup;
        }