コード例 #1
0
 public override void Visit(IGenericTypeParameter genericTypeParameter)
 {
     if (Process(genericTypeParameter))
     {
         visitor.Visit(genericTypeParameter);
     }
     base.Visit(genericTypeParameter);
 }
コード例 #2
0
 /// <summary>
 /// Gets specific type for the given generic type parameter, resolving bounds as well
 /// </summary>
 public static bool GetSpecificType(this IPythonClassType cls, IGenericTypeParameter param, out IPythonType specificType)
 {
     cls.GenericParameters.TryGetValue(param, out specificType);
     // If type has not been found, check if the type parameter has an upper bound and use that
     if (specificType is IGenericTypeParameter gtp && gtp.Bound != null)
     {
         specificType = gtp.Bound;
     }
     return(specificType != null);
 }
コード例 #3
0
 internal InheritedTypeParameter(
     ushort index,
     ITypeDefinition inheritingType,
     IGenericTypeParameter parentParameter
     )
 {
     _index           = index;
     _inheritingType  = inheritingType;
     _parentParameter = parentParameter;
 }
コード例 #4
0
 public bool TryGetValue(IGenericParameterUniqueIdentifier key, out IGenericTypeParameter <IGeneralGenericTypeUniqueIdentifier, ISymbolType> value)
 {
     for (int i = 0; i < this.Count; i++)
     {
         if (this.tParamNames[i].Equals(key))
         {
             this.CheckItemAt(i);
             value = this.elements[i];
             return(true);
         }
     }
     value = null;
     return(false);
 }
コード例 #5
0
 public int IndexOf(IGenericTypeParameter <IGeneralGenericTypeUniqueIdentifier, ISymbolType> decl)
 {
     for (int i = 0; i < this.Count; i++)
     {
         if (this.elements[i] != null)
         {
             if (decl == this.elements[i])
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
コード例 #6
0
 public virtual void onMetadataElement(IGenericTypeParameter genericTypeParameter)
 {
 }
コード例 #7
0
 protected override bool Equals(IGenericTypeParameter <TTypeIdentifier, TType> other)
 {
     return(object.ReferenceEquals(other, this));
 }
コード例 #8
0
 public override void Visit(IGenericTypeParameter genericTypeParameter)
 {
     if(Process(genericTypeParameter)){visitor.Visit(genericTypeParameter);}
     base.Visit(genericTypeParameter);
 }
コード例 #9
0
 public virtual void onMetadataElement(IGenericTypeParameter genericTypeParameter) { }
コード例 #10
0
ファイル: Visitors.cs プロジェクト: rasiths/visual-profiler
 /// <summary>
 /// Traverses the generic type parameter.
 /// </summary>
 public void Traverse(IGenericTypeParameter genericTypeParameter)
 {
     Contract.Requires(genericTypeParameter != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(genericTypeParameter);
       if (this.stopTraversal) return;
       this.TraverseChildren(genericTypeParameter);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(genericTypeParameter);
 }
コード例 #11
0
 internal InheritedTypeParameter(ushort index, ITypeDefinition inheritingType, IGenericTypeParameter parentParameter)
 {
     this.index = index;
     this.inheritingType = inheritingType;
     this.parentParameter = parentParameter;
 }
コード例 #12
0
 public bool Equals(IGenericTypeParameter other) => Name.Equals(other.Name);
コード例 #13
0
        internal static string TypeDefinition(IUnit currentUnit, ITypeDefinition typeDefinition)
        {
            if (typeDefinition == Dummy.Type)
            {
                return("###DummyType###");
            }
            PrimitiveTypeCode ptc = typeDefinition.TypeCode;

            switch (ptc)
            {
            case PrimitiveTypeCode.Boolean:
                return("bool");

            case PrimitiveTypeCode.Char:
                return("char");

            case PrimitiveTypeCode.Int8:
                return("int8");

            case PrimitiveTypeCode.Float32:
                return("float32");

            case PrimitiveTypeCode.Float64:
                return("float64");

            case PrimitiveTypeCode.Int16:
                return("int16");

            case PrimitiveTypeCode.Int32:
                return("int32");

            case PrimitiveTypeCode.Int64:
                return("int64");

            case PrimitiveTypeCode.IntPtr:
                return("native int");

            case PrimitiveTypeCode.UInt8:
                return("unsigned int8");

            case PrimitiveTypeCode.UInt16:
                return("unsigned int16");

            case PrimitiveTypeCode.UInt32:
                return("unsigned int32");

            case PrimitiveTypeCode.UInt64:
                return("unsigned int64");

            case PrimitiveTypeCode.UIntPtr:
                return("native unsigned int");

            case PrimitiveTypeCode.Void:
                return("void");
            }
            INamespaceTypeDefinition namespaceType = typeDefinition as INamespaceTypeDefinition;

            if (namespaceType != null)
            {
                bool          wasRoot;
                StringBuilder sb = new StringBuilder(Helper.ModuleQualifiedUnitNamespace(currentUnit, (IUnitNamespace)namespaceType.ContainingNamespace, out wasRoot));
                if (!wasRoot)
                {
                    sb.Append(".");
                }
                sb.Append(namespaceType.Name.Value);
                if (namespaceType.GenericParameterCount != 0)
                {
                    sb.Append("`");
                    sb.Append(namespaceType.GenericParameterCount);
                }
                return(sb.ToString());
            }
            INestedTypeDefinition nestedTypeDefinition = typeDefinition as INestedTypeDefinition;

            if (nestedTypeDefinition != null)
            {
                StringBuilder sb = new StringBuilder(Helper.TypeDefinition(currentUnit, nestedTypeDefinition.ContainingTypeDefinition));
                sb.Append("/");
                sb.Append(nestedTypeDefinition.Name.Value);
                if (nestedTypeDefinition.GenericParameterCount != 0)
                {
                    sb.Append("`");
                    sb.Append(nestedTypeDefinition.GenericParameterCount);
                }
                return(sb.ToString());
            }
            IGenericTypeInstanceReference genericTypeInstance = typeDefinition as IGenericTypeInstanceReference;

            if (genericTypeInstance != null)
            {
                StringBuilder sb = new StringBuilder(Helper.TypeDefinition(currentUnit, genericTypeInstance.GenericType.ResolvedType));
                sb.Append("<");
                bool isNotFirst = false;
                foreach (ITypeReference typeReference in genericTypeInstance.GenericArguments)
                {
                    if (isNotFirst)
                    {
                        sb.Append(",");
                    }
                    isNotFirst = true;
                    sb.Append(Helper.TypeDefinition(currentUnit, typeReference.ResolvedType));
                }
                sb.Append(">");
                return(sb.ToString());
            }
            IPointerTypeReference pointerType = typeDefinition as IPointerTypeReference;

            if (pointerType != null)
            {
                StringBuilder sb = new StringBuilder(Helper.TypeDefinition(currentUnit, pointerType.TargetType.ResolvedType));
                sb.Append("*");
                return(sb.ToString());
            }
            IArrayTypeReference arrayType = typeDefinition as IArrayTypeReference;

            if (arrayType != null)
            {
                StringBuilder sb = new StringBuilder(Helper.TypeDefinition(currentUnit, arrayType.ElementType.ResolvedType));
                sb.Append("[");
                if (!arrayType.IsVector)
                {
                    if (arrayType.Rank == 1)
                    {
                        sb.Append("*");
                    }
                    else
                    {
                        for (int i = 1; i < arrayType.Rank; ++i)
                        {
                            sb.Append(",");
                        }
                    }
                }
                sb.Append("]");
                return(sb.ToString());
            }
            IGenericTypeParameter genericTypeParameter = typeDefinition as IGenericTypeParameter;

            if (genericTypeParameter != null)
            {
                return("!" + genericTypeParameter.Index);
            }
            IGenericMethodParameter genericMethodParameter = typeDefinition as IGenericMethodParameter;

            if (genericMethodParameter != null)
            {
                return("!!" + genericMethodParameter.Index);
            }
            return("!?!ErrorType!?!");
        }
コード例 #14
0
 /// <summary>
 /// Rewrites the given generic type parameter reference.
 /// </summary>
 public virtual IGenericTypeParameter Rewrite(IGenericTypeParameter genericTypeParameter)
 {
     return genericTypeParameter;
 }
コード例 #15
0
 protected override bool Equals(IGenericTypeParameter <IGeneralGenericTypeUniqueIdentifier, ISymbolType> other)
 {
     return(ReferenceEquals(other, this));
 }
コード例 #16
0
 public override void Visit(IGenericTypeParameter genericTypeParameter)
 {
     allElements.Add(new InvokInfo(Traverser, "IGenericTypeParameter", genericTypeParameter));
 }
コード例 #17
0
        public override void TraverseChildren(IGenericTypeParameter genericTypeParameter)
{ MethodEnter(genericTypeParameter);
            base.TraverseChildren(genericTypeParameter);
     MethodExit();   }
コード例 #18
0
 public override void TraverseChildren(IGenericTypeParameter genericTypeParameter)
 {
     sourceEmitterOutput.Write(genericTypeParameter.Name.Value);
 }
コード例 #19
0
ファイル: Visitors.cs プロジェクト: Refresh06/visualmutator
 public void Visit(IGenericTypeParameter genericTypeParameter)
 {
     throw new NotImplementedException();
 }
コード例 #20
0
ファイル: Visitors.cs プロジェクト: rasiths/visual-profiler
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Performs some computation with the given generic parameter.
 /// </summary>
 /// <param name="genericTypeParameter"></param>
 public virtual void Visit(IGenericTypeParameter genericTypeParameter)
 {
 }
コード例 #21
0
        private IMember CreateSpecificReturnFromTypeVar(IPythonClassType selfClassType, IArgumentSet args, IGenericTypeParameter returnType)
        {
            if (selfClassType.GetSpecificType(returnType.Name, out var specificType))
            {
                return(specificType.CreateInstance(args));
            }

            // Find first base class type in which function was declared
            var baseType = selfClassType.Mro
                           .OfType <IPythonClassType>()
                           .Skip(1)
                           .FirstOrDefault(b => b.GetMember(ClassMember.Name) != null && b.GenericParameters.ContainsKey(returnType.Name));

            // Try and infer return value from base class
            if (baseType != null && baseType.GetSpecificType(returnType.Name, out specificType))
            {
                return(specificType.CreateInstance(args));
            }

            // Try getting type from passed in arguments
            if (args?.Arguments.FirstOrDefault(a => returnType.Equals(a.Type))?.Value is IMember typeFromArgs)
            {
                return(typeFromArgs);
            }

            // Try getting the type from the type parameter bound
            if (!returnType.Bound.IsUnknown())
            {
                return(returnType.Bound.CreateInstance(args));
            }

            // Try returning the constraint
            // TODO: improve this, the heuristic is pretty basic and tailored to simple func(_T) -> _T
            var name       = StaticReturnValue.GetPythonType()?.Name;
            var typeDefVar = DeclaringModule.Analysis.GlobalScope.Variables[name];

            if (typeDefVar?.Value is IGenericTypeParameter gtp2)
            {
                // See if the instance (self) type satisfies one of the constraints.
                return(selfClassType.Mro.Any(b => gtp2.Constraints.Any(c => c.Equals(b)))
                    ? selfClassType
                    : gtp2.Constraints.FirstOrDefault());
            }

            return(null);
        }
コード例 #22
0
ファイル: Validator.cs プロジェクト: rasiths/visual-profiler
 /// <summary>
 /// Performs some computation with the given generic parameter.
 /// </summary>
 public void Visit(IGenericTypeParameter genericTypeParameter)
 {
     this.Visit((IGenericParameter)genericTypeParameter);
 }
コード例 #23
0
ファイル: Visitors.cs プロジェクト: rasiths/visual-profiler
 /// <summary>
 /// Traverses the children of the generic type parameter.
 /// </summary>
 public virtual void TraverseChildren(IGenericTypeParameter genericTypeParameter)
 {
     Contract.Requires(genericTypeParameter != null);
       this.TraverseChildren((IGenericParameter)genericTypeParameter);
 }
コード例 #24
0
            protected internal override void _Add(IGenericParameterUniqueIdentifier key, IGenericTypeParameter <TTypeIdentifier, TType> value)
            {
                var oldIdentifier = this.Parent.UniqueIdentifier;

                _Parent.ItemAdded(value);
                base._Add(key, value);
                this._Parent.CardinalityChanged(oldIdentifier);
            }
コード例 #25
0
ファイル: Visitors.cs プロジェクト: rasiths/visual-profiler
 public void Visit(IGenericTypeParameter genericTypeParameter)
 {
     this.traverser.Traverse(genericTypeParameter);
 }
コード例 #26
0
 public override void TraverseChildren(IGenericTypeParameter genericTypeParameter) {
   sourceEmitterOutput.Write(genericTypeParameter.Name.Value);
 }
コード例 #27
0
 public virtual void Visit(IGenericTypeParameter genericTypeParameter)
 {
 }
コード例 #28
0
ファイル: Visitors.cs プロジェクト: modulexcite/IL2JS
 /// <summary>
 /// Performs some computation with the given generic parameter.
 /// </summary>
 /// <param name="genericTypeParameter"></param>
 public virtual void Visit(IGenericTypeParameter genericTypeParameter)
   //^ ensures this.path.Count == old(this.path.Count);
 {
 }
コード例 #29
0
 public override void TraverseChildren(IGenericTypeParameter genericTypeParameter)
 {
     MethodEnter(genericTypeParameter);
     base.TraverseChildren(genericTypeParameter);
     MethodExit();
 }
コード例 #30
0
 /// <summary>
 /// Traverses the children of the generic type parameter.
 /// </summary>
 public virtual void TraverseChildren(IGenericTypeParameter genericTypeParameter)
 {
     this.TraverseChildren((IGenericParameter)genericTypeParameter);
 }