public override void Visit(IGenericTypeParameter genericTypeParameter) { if (Process(genericTypeParameter)) { visitor.Visit(genericTypeParameter); } base.Visit(genericTypeParameter); }
/// <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); }
internal InheritedTypeParameter( ushort index, ITypeDefinition inheritingType, IGenericTypeParameter parentParameter ) { _index = index; _inheritingType = inheritingType; _parentParameter = parentParameter; }
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); }
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); }
public virtual void onMetadataElement(IGenericTypeParameter genericTypeParameter) { }
protected override bool Equals(IGenericTypeParameter <TTypeIdentifier, TType> other) { return(object.ReferenceEquals(other, this)); }
public override void Visit(IGenericTypeParameter genericTypeParameter) { if(Process(genericTypeParameter)){visitor.Visit(genericTypeParameter);} base.Visit(genericTypeParameter); }
/// <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); }
internal InheritedTypeParameter(ushort index, ITypeDefinition inheritingType, IGenericTypeParameter parentParameter) { this.index = index; this.inheritingType = inheritingType; this.parentParameter = parentParameter; }
public bool Equals(IGenericTypeParameter other) => Name.Equals(other.Name);
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!?!"); }
/// <summary> /// Rewrites the given generic type parameter reference. /// </summary> public virtual IGenericTypeParameter Rewrite(IGenericTypeParameter genericTypeParameter) { return genericTypeParameter; }
protected override bool Equals(IGenericTypeParameter <IGeneralGenericTypeUniqueIdentifier, ISymbolType> other) { return(ReferenceEquals(other, this)); }
public override void Visit(IGenericTypeParameter genericTypeParameter) { allElements.Add(new InvokInfo(Traverser, "IGenericTypeParameter", genericTypeParameter)); }
public override void TraverseChildren(IGenericTypeParameter genericTypeParameter) { MethodEnter(genericTypeParameter); base.TraverseChildren(genericTypeParameter); MethodExit(); }
public override void TraverseChildren(IGenericTypeParameter genericTypeParameter) { sourceEmitterOutput.Write(genericTypeParameter.Name.Value); }
public void Visit(IGenericTypeParameter genericTypeParameter) { throw new NotImplementedException(); }
//^ 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) { }
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); }
/// <summary> /// Performs some computation with the given generic parameter. /// </summary> public void Visit(IGenericTypeParameter genericTypeParameter) { this.Visit((IGenericParameter)genericTypeParameter); }
/// <summary> /// Traverses the children of the generic type parameter. /// </summary> public virtual void TraverseChildren(IGenericTypeParameter genericTypeParameter) { Contract.Requires(genericTypeParameter != null); this.TraverseChildren((IGenericParameter)genericTypeParameter); }
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); }
public void Visit(IGenericTypeParameter genericTypeParameter) { this.traverser.Traverse(genericTypeParameter); }
public virtual void Visit(IGenericTypeParameter genericTypeParameter) { }
/// <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); { }
/// <summary> /// Traverses the children of the generic type parameter. /// </summary> public virtual void TraverseChildren(IGenericTypeParameter genericTypeParameter) { this.TraverseChildren((IGenericParameter)genericTypeParameter); }