internal static string GetIntrinsicNameForArgs(IPointerType dst, IPointerType src, ITypeRef len) { Debug.Assert(dst != null && dst.ElementType.IsInteger && dst.ElementType.IntegerBitWidth > 0, "Invalid dst"); Debug.Assert(src != null && src.ElementType.IsInteger && src.ElementType.IntegerBitWidth > 0, "Invalid src"); Debug.Assert(len.IsInteger && len.IntegerBitWidth > 0, "Invalid len"); return($"llvm.memcpy.p{dst.AddressSpace}i{dst.ElementType.IntegerBitWidth}.p{src.AddressSpace}i{src.ElementType.IntegerBitWidth}.i{len.IntegerBitWidth}"); }
public Type?LookupType(IType type) { return(type switch { IPointerType pointerType => LookupType(pointerType.DestinationType)?.PointerType(), IPrimitiveType primitiveType => Context.LookupPrimitiveType(primitiveType.Primitive), StructType structType => Context.LookupStructType(structType.Name), _ => throw new InvalidOperationException("unhandled IType") });
public int GetSize(IType type) { return(type switch { IPrimitiveType primitiveType => GetSize(primitiveType), IPointerType pointerType => IntPtr.Size, StructType structType => GetSize(structType), _ => throw new NotSupportedException() });
public int CompareTo(object obj) { IPointerType pointerType = obj as IPointerType; if (pointerType == null) { return(-1); } return(this.ElementType.CompareTo(pointerType.ElementType)); }
protected override string ConvertPointerType(IPointerType Type) { if (Type.PointerKind.Equals(PointerKind.ReferencePointer)) { return "ref " + Convert(Type.ElementType); } else { return base.ConvertPointerType(Type); } }
public ISymbol CreateReferenceInstance(IPointerType type, ISymbol parent) { IValueSymbol symbol = (IValueSymbol)this.inner.CreateReferenceInstance(type, ((DynamicSymbol)parent).InnerSymbol); ISymbol symbol2 = null; if (symbol != null) { symbol2 = this.create(symbol); } return(symbol2); }
public ISymbol CreateReferenceInstance(IPointerType type, ISymbol parent) { if (type == null) { throw new ArgumentNullException("type"); } if (parent == null) { throw new ArgumentNullException("parent"); } return(this.OnCreateReference(type, parent)); }
public override bool Equals(object obj) { if (this == obj) { return(true); } IPointerType pointerType = obj as IPointerType; if (pointerType == null) { return(false); } return(this.ElementType.Equals(pointerType.ElementType)); }
/// <summary> /// Determines whether two types are equivalent (Cecil/Reflector) /// </summary> /// <param name="typeref">Cecil type reference</param> /// <param name="type">Reflector type reference</param> /// <returns>true if equivalent</returns> private static bool TypeMatches(TypeReference typeref, IType type) { if (type is ITypeReference) { var ityperef = (ITypeReference)type; if (typeref.Namespace == ityperef.Namespace && IsSameName(typeref.Name, ityperef.Name)) { if (typeref.DeclaringType != null && (ityperef.Owner) is ITypeReference) { return(TypeMatches(typeref.DeclaringType, ((ITypeReference)ityperef.Owner))); } else { return(true); } } return(false); } else if (type is IGenericParameter) { IGenericParameter igenprm = (IGenericParameter)type; return(typeref.Name.StartsWith(igenprm.Name)); } else if (type is IGenericArgument) { IGenericArgument igenarg = (IGenericArgument)type; return(TypeMatches(typeref, igenarg.Owner.GenericArguments[igenarg.Position])); } else if ((type is IArrayType) && (typeref is ArrayType)) { IArrayType iarrtyp = (IArrayType)type; return(TypeMatches(((ArrayType)typeref).ElementType, iarrtyp.ElementType)); } else if ((type is IReferenceType) && (typeref is ByReferenceType)) { IReferenceType iref = (IReferenceType)type; return(TypeMatches(((ByReferenceType)typeref).ElementType, iref.ElementType)); } else if ((type is IPointerType) && (typeref is PointerType)) { IPointerType ipt = (IPointerType)type; return(TypeMatches(((PointerType)typeref).ElementType, ipt.ElementType)); } return(false); }
// constructor internal Types(Context context) { this.context = context; this.Int = context.Int64Type; this.Double = context.DoubleType; this.Bool = context.BoolType; this.Pauli = context.GetIntType(2); this.Range = context.CreateStructType(TypeNames.Range, false, context.Int64Type, context.Int64Type, context.Int64Type); this.Result = context.CreateStructType(TypeNames.Result).CreatePointerType(); this.Qubit = context.CreateStructType(TypeNames.Qubit).CreatePointerType(); this.String = context.CreateStructType(TypeNames.String).CreatePointerType(); this.BigInt = context.CreateStructType(TypeNames.BigInt).CreatePointerType(); this.Tuple = context.CreateStructType(TypeNames.Tuple).CreatePointerType(); this.Array = context.CreateStructType(TypeNames.Array).CreatePointerType(); this.Callable = context.CreateStructType(TypeNames.Callable).CreatePointerType(); this.FunctionSignature = context.GetFunctionType(context.VoidType, this.Tuple, this.Tuple, this.Tuple); this.CallableTable = this.FunctionSignature.CreatePointerType().CreateArrayType(4); this.CaptureCountFunction = context.GetFunctionType(context.VoidType, this.Tuple, context.Int32Type); this.CallableMemoryManagementTable = this.CaptureCountFunction.CreatePointerType().CreateArrayType(2); }
public string WriteName(LanguageWriter w) { if (tref != null) { string name = tref.Name.Replace(".", "::").Replace("+", "::"); string special; if (tref.Namespace == "System" && specialTypeNames.TryGetValue(name, out special)) { name = special; } name = NameMangling.UnDecorateName(name); w.WriteReference(name, this.FullName, tref); ITypeCollection genericArguments = tref.GenericArguments; if (genericArguments.Count > 0) { w.Write("<"); bool first = true; foreach (IType type1 in genericArguments) { if (first) { first = false; } else { w.Write(", "); } new TypeRef(type1).WriteNameWithRef(w); } w.Write(">"); } return(name); } IArrayType type2 = type as IArrayType; if (type2 != null) { w.WriteKeyword("array"); w.Write("<"); new TypeRef(type2.ElementType).WriteNameWithRef(w); if (type2.Dimensions.Count > 1) { w.Write(", "); w.WriteAsLiteral(type2.Dimensions.Count); } w.Write(">"); } IPointerType type4 = type as IPointerType; if (type4 != null) { new TypeRef(type4.ElementType).WriteNameWithRef(w); w.Write("*"); } IReferenceType type3 = type as IReferenceType; if (type3 != null) { new TypeRef(type3.ElementType).WriteNameWithRef(w); w.Write("%"); } IOptionalModifier modifier2 = type as IOptionalModifier; if (modifier2 != null) { WriteModify(w, new TypeRef(modifier2.Modifier), new TypeRef(modifier2.ElementType), false); } IRequiredModifier modifier = type as IRequiredModifier; if (modifier != null) { WriteModify(w, new TypeRef(modifier.Modifier), new TypeRef(modifier.ElementType), true); } IFunctionPointer fptr = type as IFunctionPointer; if (fptr != null) { w.Write("("); new TypeRef(fptr.ReturnType.Type).WriteNameWithRef(w); w.Write(" (*)("); bool first = true; foreach (IParameterDeclaration declaration in fptr.Parameters) { if (first) { first = false; } else { w.Write(", "); } new TypeRef(declaration.ParameterType).WriteNameWithRef(w); } w.Write("))"); } IGenericParameter parameter = type as IGenericParameter; if (parameter != null) { w.WriteReference(parameter.Name, "/* γΈγ§γγͺγγ―γγ©γ‘γΌγΏ */ " + parameter.Name, null); } IGenericArgument argument = type as IGenericArgument; if (argument != null) { new TypeRef(argument.Resolve()).WriteNameWithRef(w); } if (type is IValueTypeConstraint) { w.WriteKeyword("value class"); } else if (type is IDefaultConstructorConstraint) { w.Write("<DefaultConstructorConstraint>"); } return("<δΈζγͺε>"); }
public int CompareTo(object obj) { IPointerType ptype = obj as IPointerType; return(ptype == null?-1:this.elem.CompareTo(ptype.ElementType)); }
protected override ISymbol OnCreateReference(IPointerType type, ISymbol parent) { if (type == null) { throw new ArgumentNullException("type"); } if (parent == null) { throw new ArgumentNullException("parent"); } int fieldOffset = 0; ISymbol symbol2 = null; DataType referencedType = (DataType)type.ReferencedType; bool flag = (referencedType.Flags & AdsDataTypeFlags.AnySizeArray) == AdsDataTypeFlags.AnySizeArray; bool flag2 = (((Symbol)parent).MemberFlags & AdsDataTypeFlags.AnySizeArray) == AdsDataTypeFlags.AnySizeArray; if ((referencedType == null) || ((referencedType.Size == 0) && !flag2)) { return(null); } string instanceName = parent.InstanceName; bool isBitType = type.ReferencedType.IsBitType; if (((DataType)parent.DataType).ResolveType(DataTypeResolveStrategy.AliasReference).IsPointer) { instanceName = instanceName + "^"; } if (referencedType.Category == DataTypeCategory.Struct) { StructType type3 = (StructType)referencedType; symbol2 = !type3.HasRpcMethods ? new StructInstance(parent, type3, instanceName, fieldOffset) : new RpcStructInstance(parent, type3, instanceName, fieldOffset); } else if (referencedType.Category == DataTypeCategory.Array) { symbol2 = !flag2 ? new ArrayInstance(parent, (ArrayType)referencedType, instanceName, fieldOffset) : new AnySizeArrayInstance(parent, (ArrayType)referencedType, instanceName, fieldOffset); } else if (referencedType.Category == DataTypeCategory.Reference) { symbol2 = new ReferenceInstance(parent, (ReferenceType)referencedType, instanceName, fieldOffset); } else if (referencedType.Category == DataTypeCategory.Pointer) { symbol2 = new PointerInstance(parent, (PointerType)referencedType, instanceName, fieldOffset); } else if (referencedType.Category == DataTypeCategory.Alias) { AliasType type4 = (AliasType)referencedType; DataType type5 = (DataType)type4.ResolveType(DataTypeResolveStrategy.Alias); symbol2 = new AliasInstance(parent, type4, instanceName, fieldOffset); } else if (referencedType.Category == DataTypeCategory.Union) { symbol2 = new UnionInstance(parent, (UnionType)referencedType, instanceName, fieldOffset); } else if (referencedType.Category == DataTypeCategory.String) { symbol2 = new StringInstance(parent, (IStringType)referencedType, instanceName, fieldOffset); } else { if (referencedType.Category == DataTypeCategory.Union) { Module.Trace.TraceError("Unions not supported yet!"); } symbol2 = new Symbol(parent, referencedType, instanceName, fieldOffset, ((ISymbolFactoryServicesProvider)parent).FactoryServices); } return(symbol2); }
protected override IPointerInstance OnCreatePointerInstance(ISymbolInfo entry, IPointerType pointerType, ISymbol parent) => new PointerInstance((AdsSymbolEntry)entry, (PointerType)pointerType, parent, base.services);
public virtual IType TransformPointerType(IPointerType value) { value.ElementType = this.TransformType(value.ElementType); return value; }
public override void VisitPointerType(IPointerType type) { WriteUnsupported(type.ToString()); }
private void AppendPointerType([NotNull] IPointerType pointerType, NamespaceDisplays expectedNamespaceDisplay) { AppendType(pointerType.ElementType, expectedNamespaceDisplay); AppendText("*", VsHighlightingAttributeIds.Operator); }
public virtual void VisitPointerType(IPointerType value) { VisitType(value.ElementType); }
private string GetName(bool fullname) { if (tref != null) { string name = tref.Name.Replace(".", "::").Replace("+", "::"); if (!fullname) { string special; if (tref.Namespace == "System" && specialTypeNames.TryGetValue(name, out special)) { name = special; } } ITypeCollection genericArguments = tref.GenericArguments; if (genericArguments.Count > 0) { System.Text.StringBuilder build = new System.Text.StringBuilder(name); build.Append('<'); bool first = true; foreach (IType type1 in genericArguments) { if (first) { first = false; } else { build.Append(", "); } build.Append(new TypeRef(type1).GetNameWithRef(fullname)); } build.Append('>'); name = build.ToString(); } return(fullname?RawNamespace + name:name); } IArrayType type2 = type as IArrayType; if (type2 != null) { string name = type2.Dimensions.Count <= 1?"":", " + type2.Dimensions.Count.ToString(); return("array<" + new TypeRef(type2.ElementType).GetNameWithRef(fullname) + name + ">"); } IPointerType type4 = type as IPointerType; if (type4 != null) { return(new TypeRef(type4.ElementType).GetNameWithRef(fullname) + "*"); } IReferenceType type3 = type as IReferenceType; if (type3 != null) { return(new TypeRef(type3.ElementType).GetNameWithRef(fullname) + "%"); } IOptionalModifier modifier2 = type as IOptionalModifier; if (modifier2 != null) { return(Modify(new TypeRef(modifier2.Modifier), new TypeRef(modifier2.ElementType), fullname, false)); } IRequiredModifier modifier = type as IRequiredModifier; if (modifier != null) { return(Modify(new TypeRef(modifier.Modifier), new TypeRef(modifier.ElementType), fullname, true)); } IGenericParameter parameter = type as IGenericParameter; if (parameter != null) { return(parameter.Name); } IGenericArgument argument = type as IGenericArgument; if (argument != null) { return(new TypeRef(argument.Resolve()).GetNameWithRef(fullname)); } IFunctionPointer fptr = type as IFunctionPointer; if (fptr != null) { System.Text.StringBuilder build = new System.Text.StringBuilder(); build.Append("("); build.Append(new TypeRef(fptr.ReturnType.Type).GetNameWithRef(fullname)); build.Append(" (*)("); bool first = true; foreach (IParameterDeclaration declaration in fptr.Parameters) { if (first) { first = false; } else { build.Append(", "); } build.Append(new TypeRef(declaration.ParameterType).GetNameWithRef(fullname)); } build.Append("))"); return(build.ToString()); } if (type is IValueTypeConstraint) { return("value class"); } else if (type is IDefaultConstructorConstraint) { return("<DefaultConstructorConstraint>"); } return("<δΈζγͺε>"); }
protected abstract ISymbol OnCreateReference(IPointerType type, ISymbol parent);
protected abstract IPointerInstance OnCreatePointerInstance(ISymbolInfo entry, IPointerType structType, ISymbol parent);
/// <summary> /// Use the generic argument providers to specialize a type /// </summary> /// <param name="type">The type to resolve</param> /// <param name="declaringType">The declaring type as a generic argument provider</param> /// <param name="method">The method as a generic argument provider</param> /// <returns></returns> public static IType GetType(IType type, IGenericArgumentProvider declaringType, IGenericArgumentProvider method) { ITypeReference itr = type as ITypeReference; if (itr != null) { if (itr.GenericType == null) { // The parameter is directly a non-generic type reference return(itr); } else { // The parameter is a reference to a generic type. Build an array of types of the // generic arguments by recursion IType[] ita = new IType[itr.GenericArguments.Count]; for (int i = 0; i < ita.Length; i++) { ita[i] = GetType(itr.GenericArguments[i], declaringType, method); } // Build the specialization (the 'instance') of the generic type ITypeReference itr2 = new XTypeInstanceReference(); itr2.GenericType = itr.GenericType; itr2.GenericArguments.AddRange(ita); ((ISettableTypeDeclaration)itr2).Declaration = itr.Resolve(); return(itr2); } } // Check to see if the parameter is an array IArrayType iat = type as IArrayType; if (iat != null) { // The parameter is an array type. Build an array type and recurse to get its element type IArrayType iat2 = new XArrayType(); iat2.ElementType = GetType(iat.ElementType, declaringType, method); iat2.DotNetType = iat.DotNetType; return(iat2); } // Check to see if the parameter is a pointer IPointerType ipt = type as IPointerType; if (ipt != null) { // The parameter is a pointer type. Build a pointer type and recurse to set its element type IPointerType ipt2 = new XPointerType(); ipt2.ElementType = GetType(ipt.ElementType, declaringType, method); return(ipt2); } // Check to see if the parameter is a reference IReferenceType irt = type as IReferenceType; if (irt != null) { // The parameter is a reference type. Build a reference type and recurse // to set its element type IReferenceType irt2 = new XReferenceType(); irt2.ElementType = GetType(irt.ElementType, declaringType, method); return(irt2); } // Check to see if the parameter has an optional modifier IOptionalModifier iom = type as IOptionalModifier; if (iom != null) { // The parameter has an optional modifier. Build an optional modifier type and recurse // to set its element type IOptionalModifier iom2 = new XOptionalModifier(); iom2.Modifier = (ITypeReference)GetType(iom.Modifier, declaringType, method); iom2.ElementType = GetType(iom.ElementType, declaringType, method); return(iom2); } // Check to see if the parameter has an required modifier IRequiredModifier irm = type as IRequiredModifier; if (irm != null) { // The parameter has a required modifier. Build a required modifier type and recurse // to set its element type IRequiredModifier irm2 = new XRequiredModifier(); irm2.Modifier = (ITypeReference)GetType(irm.Modifier, declaringType, method); irm2.ElementType = GetType(irm.ElementType, declaringType, method); return(irm2); } // Deal with generic parameters IGenericParameter igp = type as IGenericParameter; IMethodReference imr; if (igp != null) { itr = igp.Owner as ITypeReference; imr = igp.Owner as IMethodReference; ; if (itr == null && imr == null) { throw new NotSupportedException("A generic parameter must be owned by a method or type"); } if (itr == null) { if (method != null) { // Get the parameter type from the method instance return(method.GenericArguments[igp.Position]); } else { return(igp); } } else { if (declaringType != null) { // Get the parameter type from the declaring type return(declaringType.GenericArguments[igp.Position]); } else { return(igp); } } } // The only thing left is that the parameter is a generic argument IGenericArgument iga = type as IGenericArgument; if (iga == null) { throw new NotSupportedException("Unable to get the parameters type"); } IType it = iga.Resolve(); if (it == null || !(it is IGenericArgument) || (it is IGenericParameter)) { itr = iga.Owner as ITypeReference; imr = iga.Owner as IMethodReference; if (itr == null && imr == null) { throw new NotSupportedException(); } if (itr == null) { if (method != null) { IGenericArgument iga2 = new XGenericArgument(); iga2.Owner = method; iga2.Position = iga.Position; return(iga2); } else { return(iga); } } else { IGenericArgument iga2 = new XGenericArgument(); iga2.Owner = declaringType; iga2.Position = iga.Position; return(iga2); } } // Recurse return(GetType(it, declaringType, method)); }
private string GetTypeText(IType value) { ITypeReference typeReference = value as ITypeReference; if (typeReference != null) { string specialName = this.GetTypeSpecialNameText(typeReference); if ((specialName != null) && (specialName.Length > 0)) { return(specialName); } string typeReferenceText = this.GetTypeReferenceText(typeReference); return(typeReferenceText); } IPointerType pointerType = value as IPointerType; if (pointerType != null) { return(this.GetTypeText(pointerType.ElementType) + "*"); } IReferenceType referenceType = value as IReferenceType; if (referenceType != null) { return(this.GetTypeText(referenceType.ElementType) + "&"); } IArrayType arrayType = value as IArrayType; if (arrayType != null) { using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture)) { writer.Write(this.GetTypeText(arrayType.ElementType)); writer.Write("["); IArrayDimensionCollection dimensions = arrayType.Dimensions; for (int i = 0; i < dimensions.Count; i++) { if (i != 0) { writer.Write(","); } int lowerBound = dimensions[i].LowerBound; int upperBound = dimensions[i].UpperBound; if (lowerBound != -1) { writer.Write(lowerBound.ToString(CultureInfo.InvariantCulture)); } if ((lowerBound != -1) || (upperBound != -1)) { writer.Write(":"); } if (upperBound != -1) { writer.Write(upperBound.ToString(CultureInfo.InvariantCulture)); } } writer.Write("]"); return(writer.ToString()); } } IOptionalModifier optionalModifier = value as IOptionalModifier; if (optionalModifier != null) { return("{optional:" + this.GetTypeText(optionalModifier.Modifier) + "}" + this.GetTypeText(optionalModifier.ElementType)); } IRequiredModifier requiredModifier = value as IRequiredModifier; if (requiredModifier != null) { return("{required:" + this.GetTypeText(requiredModifier.Modifier) + "}" + this.GetTypeText(requiredModifier.ElementType)); } IFunctionPointer functionPointer = value as IFunctionPointer; if (functionPointer != null) { using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture)) { writer.Write("*"); writer.Write("("); for (int i = 0; i < functionPointer.Parameters.Count; i++) { if (i != 0) { writer.Write(","); } writer.Write(this.GetTypeText(functionPointer.Parameters[i].ParameterType)); } writer.Write(")"); writer.Write(":"); writer.Write(this.GetTypeText(functionPointer.ReturnType.Type)); return(writer.ToString()); } } IGenericParameter genericParameter = value as IGenericParameter; if (genericParameter != null) { return(genericParameter.Name); } IGenericArgument genericArgument = value as IGenericArgument; if (genericArgument != null) { ITypeReference genericType = genericArgument.Owner as ITypeReference; if (genericType != null) { return("<!" + genericArgument.Position.ToString(CultureInfo.InvariantCulture) + ">"); } IMethodReference genericMethod = genericArgument.Owner as IMethodReference; if (genericMethod != null) { return("<!!" + genericArgument.Position.ToString(CultureInfo.InvariantCulture) + ">"); } } throw new NotSupportedException("Invalid type in code identifier."); }
internal PointerInstance(AdsSymbolEntry entry, IPointerType type, ISymbol parent, ISymbolFactoryServices factoryServices) : base(entry, type, parent, factoryServices) { base.category = DataTypeCategory.Pointer; }
private void AppendPointerType([NotNull] IPointerType pointerType, QualifierDisplays expectedQualifierDisplay, Context context) { AppendTypeWithoutModule(pointerType.ElementType, expectedQualifierDisplay, context); AppendText("*", _highlighterIdProvider.Operator); }
internal static Tuple cil_pointer_type(IPointerType t, IType pointee) => new Tuple("cil_pointer_type", t, pointee);
public virtual void VisitPointerType(IPointerType value) { this.VisitType(value.ElementType); }
private static ITypeName GetName(this IPointerType type, IDictionary <DeclaredElementInstance, IName> seenElements) { return(type.ElementType.GetName(seenElements)); }
public override void VisitPointerType(IPointerType pointerType) { }
private StaticPointerTypeWrapper MakePointerType(IPointerType pointerTypeHandle) { return MakeType(pointerTypeHandle.ElementType).MakePointerType(); }
private void AppendPointerType([NotNull] IPointerType pointerType, QualifierDisplays expectedQualifierDisplay, Context context) { AppendTypeWithoutModule(pointerType.ElementType, expectedQualifierDisplay, context); AppendText("*", VsHighlightingAttributeIds.Operator); }