global::EnvDTE.vsCMTypeRef GetStructTypeKind(KnownTypeCode knownTypeCode) { switch (knownTypeCode) { case KnownTypeCode.Boolean: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefBool; case KnownTypeCode.Char: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefChar; case KnownTypeCode.SByte: case KnownTypeCode.Byte: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefByte; case KnownTypeCode.Int16: case KnownTypeCode.UInt16: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefShort; case KnownTypeCode.Int32: case KnownTypeCode.UInt32: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefInt; case KnownTypeCode.Int64: case KnownTypeCode.UInt64: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefLong; case KnownTypeCode.Single: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefFloat; case KnownTypeCode.Double: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefDouble; case KnownTypeCode.Decimal: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefDecimal; case KnownTypeCode.Void: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefVoid; case KnownTypeCode.IntPtr: case KnownTypeCode.UIntPtr: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefPointer; default: return global::EnvDTE.vsCMTypeRef.vsCMTypeRefOther; } }
public IType FindType(KnownTypeCode typeCode) { IType type = LazyInit.VolatileRead(ref knownTypes[(int)typeCode]); if (type != null) { return type; } return LazyInit.GetOrSet(ref knownTypes[(int)typeCode], SearchType(typeCode)); }
public IType FindType(KnownTypeCode typeCode) { IType type = knownTypes[(int)typeCode]; if (type != null) { LazyInit.ReadBarrier(); return type; } return LazyInit.GetOrSet(ref knownTypes[(int)typeCode], SearchType(typeCode)); }
IType SearchType(KnownTypeCode typeCode) { KnownTypeReference typeRef = KnownTypeReference.Get(typeCode); if (typeRef == null) return SpecialType.UnknownType; foreach (IAssembly asm in compilation.Assemblies) { var typeDef = asm.GetTypeDefinition(typeRef.Namespace, typeRef.Name, typeRef.TypeParameterCount); if (typeDef != null) return typeDef; } return new UnknownType(typeRef.Namespace, typeRef.Name, typeRef.TypeParameterCount); }
/// <summary> /// Finds IList<T> or IEnumerable<T> base type. /// </summary> /// <param name="fullNamePrefix">Type code to search for (IList<T> or IEnumerable<T>)</param></param> /// <param name="implementation">Found implementation.</param> /// <param name="itemType">The only generic argument of <paramref name="implementation"/></param> /// <returns>True if found, false otherwise.</returns> private static bool ResolveKnownBaseType(this IType type, KnownTypeCode knownTypeCode, out ParameterizedType implementation, out IType itemType) { if (type == null) throw new ArgumentNullException("type"); implementation = null; itemType = null; ParameterizedType impl = type.GetAllBaseTypes().OfType<ParameterizedType>(). Where(t => t.IsKnownType(knownTypeCode) && t.TypeParameterCount == 1) .FirstOrDefault(); if (impl != null) { implementation = impl; itemType = impl.GetTypeArgument(0); return true; } return false; }
public static unsafe void SetValue(this ICorDebugGenericValue corGenVal, KnownTypeCode type, object value) { if (value == null) throw new ArgumentNullException("value"); byte[] val = new byte[(int)corGenVal.GetSize()]; fixed(byte* pValue = val) { switch(type) { case KnownTypeCode.Boolean: *((System.Boolean*)pValue) = (System.Boolean)value; break; case KnownTypeCode.Char: *((System.Char*) pValue) = (System.Char) value; break; case KnownTypeCode.SByte: *((System.SByte*) pValue) = (System.SByte) value; break; case KnownTypeCode.Byte: *((System.Byte*) pValue) = (System.Byte) value; break; case KnownTypeCode.Int16: *((System.Int16*) pValue) = (System.Int16) value; break; case KnownTypeCode.UInt16: *((System.UInt16*) pValue) = (System.UInt16) value; break; case KnownTypeCode.Int32: *((System.Int32*) pValue) = (System.Int32) value; break; case KnownTypeCode.UInt32: *((System.UInt32*) pValue) = (System.UInt32) value; break; case KnownTypeCode.Int64: *((System.Int64*) pValue) = (System.Int64) value; break; case KnownTypeCode.UInt64: *((System.UInt64*) pValue) = (System.UInt64) value; break; case KnownTypeCode.Single: *((System.Single*) pValue) = (System.Single) value; break; case KnownTypeCode.Double: *((System.Double*) pValue) = (System.Double) value; break; case KnownTypeCode.IntPtr: *((System.IntPtr*) pValue) = (System.IntPtr) value; break; case KnownTypeCode.UIntPtr: *((System.UIntPtr*)pValue) = (System.UIntPtr)value; break; default: throw new NotSupportedException(); } corGenVal.SetValue(new IntPtr(pValue)); } }
private static bool IsIntegerTypeCode(KnownTypeCode code) { switch (code) { case KnownTypeCode.Char: case KnownTypeCode.SByte: case KnownTypeCode.Byte: case KnownTypeCode.Int16: case KnownTypeCode.UInt16: case KnownTypeCode.Int32: case KnownTypeCode.UInt32: case KnownTypeCode.Int64: case KnownTypeCode.UInt64: { return true; } } return false; }
/// <summary> /// Gets whether the type is the specified known type. /// For generic known types, this returns true any parameterization of the type (and also for the definition itself). /// </summary> public static bool IsKnownType(this IType type, KnownTypeCode knownType) { var def = type.GetDefinition(); return def != null && def.KnownTypeCode == knownType; }
/// <summary> /// Gets whether the type is the specified known type. /// For generic known types, this returns true for any parameterization of the type (and also for the definition itself). /// </summary> public static bool IsKnownType(this IType type, KnownTypeCode knownType) { var def = type.GetDefinition(); return(def != null && def.KnownTypeCode == knownType); }
/// <summary> /// Gets the known type reference for the specified type code. /// Returns null for KnownTypeCode.None. /// </summary> public static KnownTypeReference Get(KnownTypeCode typeCode) { return knownTypeReferences[(int)typeCode]; }
/// <summary> /// Gets the C# primitive type name from the known type code. /// Returns null if there is no primitive name for the specified type. /// </summary> public static string GetCSharpNameByTypeCode(KnownTypeCode knownTypeCode) { switch (knownTypeCode) { case KnownTypeCode.Object: return "object"; case KnownTypeCode.Boolean: return "bool"; case KnownTypeCode.Char: return "char"; case KnownTypeCode.SByte: return "sbyte"; case KnownTypeCode.Byte: return "byte"; case KnownTypeCode.Int16: return "short"; case KnownTypeCode.UInt16: return "ushort"; case KnownTypeCode.Int32: return "int"; case KnownTypeCode.UInt32: return "uint"; case KnownTypeCode.Int64: return "long"; case KnownTypeCode.UInt64: return "ulong"; case KnownTypeCode.Single: return "float"; case KnownTypeCode.Double: return "double"; case KnownTypeCode.Decimal: return "decimal"; case KnownTypeCode.String: return "string"; case KnownTypeCode.Void: return "void"; default: return null; } }
public static bool IsKnownType(this TopLevelTypeName typeName, KnownTypeCode knownType) { return(typeName == KnownTypeReference.Get(knownType).TypeName); }
object ReadElemValue(KnownTypeCode typeCode) { switch (typeCode) { case KnownTypeCode.Boolean: return ReadByte() != 0; case KnownTypeCode.Char: return (char)ReadUInt16(); case KnownTypeCode.SByte: return ReadSByte(); case KnownTypeCode.Byte: return ReadByte(); case KnownTypeCode.Int16: return ReadInt16(); case KnownTypeCode.UInt16: return ReadUInt16(); case KnownTypeCode.Int32: return ReadInt32(); case KnownTypeCode.UInt32: return ReadUInt32(); case KnownTypeCode.Int64: return ReadInt64(); case KnownTypeCode.UInt64: return ReadUInt64(); case KnownTypeCode.Single: return ReadSingle(); case KnownTypeCode.Double: return ReadDouble(); case KnownTypeCode.String: return ReadSerString(); default: throw new NotSupportedException(); } }
public static unsafe object GetValue(this ICorDebugGenericValue corGenVal, KnownTypeCode type) { object retValue; byte[] value = new byte[(int)corGenVal.GetSize()]; fixed(byte* pValue = value) { corGenVal.GetValue(new IntPtr(pValue)); switch (type) { case KnownTypeCode.Boolean: retValue = *((System.Boolean*)pValue); break; case KnownTypeCode.Char: retValue = *((System.Char*) pValue); break; case KnownTypeCode.SByte: retValue = *((System.SByte*) pValue); break; case KnownTypeCode.Byte: retValue = *((System.Byte*) pValue); break; case KnownTypeCode.Int16: retValue = *((System.Int16*) pValue); break; case KnownTypeCode.UInt16: retValue = *((System.UInt16*) pValue); break; case KnownTypeCode.Int32: retValue = *((System.Int32*) pValue); break; case KnownTypeCode.UInt32: retValue = *((System.UInt32*) pValue); break; case KnownTypeCode.Int64: retValue = *((System.Int64*) pValue); break; case KnownTypeCode.UInt64: retValue = *((System.UInt64*) pValue); break; case KnownTypeCode.Single: retValue = *((System.Single*) pValue); break; case KnownTypeCode.Double: retValue = *((System.Double*) pValue); break; case KnownTypeCode.IntPtr: retValue = *((System.IntPtr*) pValue); break; case KnownTypeCode.UIntPtr: retValue = *((System.UIntPtr*)pValue); break; default: throw new NotSupportedException(); } } return retValue; }
public IType FindType(KnownTypeCode typeCode) { return knownTypeCache.FindType(typeCode); }
/// <summary> /// Construct a builtin attribute with a single positional argument of known type. /// </summary> public void Add(KnownAttribute type, KnownTypeCode argType, object argValue) { Add(type, ImmutableArray.Create(new CustomAttributeTypedArgument <IType>(module.Compilation.FindType(argType), argValue))); }
public void AddNamedArg(string name, KnownTypeCode type, object value) { AddNamedArg(name, compilation.FindType(type), value); }
private void HandleType(ResolveResult resolveOperator, string variable, string op_name, KnownTypeCode typeCode) { if (this.AssignmentExpression.Operator == AssignmentOperatorType.Assign) { if (variable != null) { this.Write(variable); } else { new ExpressionListBlock(this.Emitter, new Expression[] { this.AssignmentExpression.Right }, null, null, 0).Emit(); } return; } var orr = resolveOperator as OperatorResolveResult; var method = orr != null ? orr.UserDefinedOperatorMethod : null; var assigmentType = Helpers.TypeOfAssignment(this.AssignmentExpression.Operator); if (orr != null && method == null) { var name = Helpers.GetBinaryOperatorMethodName(assigmentType); var type = NullableType.IsNullable(orr.Type) ? NullableType.GetUnderlyingType(orr.Type) : orr.Type; method = type.GetMethods(m => m.Name == name, GetMemberOptions.IgnoreInheritedMembers).FirstOrDefault(); } if (method != null) { var inline = this.Emitter.GetInline(method); if (orr.IsLiftedOperator) { this.Write(JS.Types.SYSTEM_NULLABLE + "."); string action = JS.Funcs.Math.LIFT2; this.Write(action); this.WriteOpenParentheses(); this.WriteScript(op_name); this.WriteComma(); if (variable != null) { new ExpressionListBlock(this.Emitter, new Expression[] { this.AssignmentExpression.Left }, null, null, 0).Emit(); } else { new ExpressionListBlock(this.Emitter, new Expression[] { this.AssignmentExpression.Left, this.AssignmentExpression.Right }, null, null, 0).Emit(); } this.AddOveflowFlag(typeCode, op_name); this.WriteCloseParentheses(); } else if (!string.IsNullOrWhiteSpace(inline)) { new InlineArgumentsBlock(this.Emitter, new ArgumentsInfo(this.Emitter, this.AssignmentExpression, orr, method), inline).Emit(); } else if (!this.Emitter.Validator.IsExternalType(method.DeclaringTypeDefinition)) { this.Write(BridgeTypes.ToJsName(method.DeclaringType, this.Emitter)); this.WriteDot(); this.Write(OverloadsCollection.Create(this.Emitter, method).GetOverloadName()); this.WriteOpenParentheses(); if (variable != null) { new ExpressionListBlock(this.Emitter, new Expression[] { this.AssignmentExpression.Left }, null, null, 0).Emit(); this.Write(", " + variable); } else { new ExpressionListBlock(this.Emitter, new Expression[] { this.AssignmentExpression.Left, this.AssignmentExpression.Right }, null, null, 0).Emit(); } this.WriteCloseParentheses(); } } else { if (orr.IsLiftedOperator) { this.Write(JS.Types.SYSTEM_NULLABLE + "."); string action = JS.Funcs.Math.LIFT2; this.Write(action); this.WriteOpenParentheses(); this.WriteScript(op_name); this.WriteComma(); if (variable != null) { new ExpressionListBlock(this.Emitter, new Expression[] { this.AssignmentExpression.Left }, null, null, 0).Emit(); } else { new ExpressionListBlock(this.Emitter, new Expression[] { this.AssignmentExpression.Left, this.AssignmentExpression.Right }, null, null, 0).Emit(); } this.AddOveflowFlag(typeCode, op_name); this.WriteCloseParentheses(); } else { this.AssignmentExpression.Left.AcceptVisitor(this.Emitter); this.WriteDot(); this.Write(op_name); this.WriteOpenParentheses(); this.AssignmentExpression.Right.AcceptVisitor(this.Emitter); this.AddOveflowFlag(typeCode, op_name); this.WriteCloseParentheses(); } } }
private KnownTypeReference(KnownTypeCode knownTypeCode, TypeKind typeKind, string namespaceName, string name, int typeParameterCount = 0, KnownTypeCode baseType = KnownTypeCode.Object) { if (typeKind == TypeKind.Struct && baseType == KnownTypeCode.Object) { baseType = KnownTypeCode.ValueType; } this.knownTypeCode = knownTypeCode; this.namespaceName = namespaceName; this.name = name; this.typeParameterCount = typeParameterCount; this.typeKind = typeKind; this.baseType = baseType; }
/// <summary> /// Gets the known type reference for the specified type code. /// Returns null for KnownTypeCode.None. /// </summary> public static KnownTypeReference Get(KnownTypeCode typeCode) { return(knownTypeReferences[(int)typeCode]); }
public IType FindType(KnownTypeCode typeCode) { switch(typeCode){ case KnownTypeCode.Void: return FindType(BVEPrimitiveTypeCode.None); case KnownTypeCode.Int32: return FindType(BVEPrimitiveTypeCode.Integer); case KnownTypeCode.Double: return FindType(BVEPrimitiveTypeCode.Float); case KnownTypeCode.String: return FindType(BVEPrimitiveTypeCode.Name); default: return new UnknownType("global", typeCode.ToString(), 0); } }
public IType FindType(KnownTypeCode typeCode) { return null; }
public static bool IsKnownType(this EntityHandle handle, MetadataReader reader, KnownTypeCode knownType) { return(GetFullTypeName(handle, reader) == KnownTypeReference.Get(knownType).TypeName); }
LiteralExpression CreateDefaultValue(KnownTypeCode type) { LiteralExpression result = null; var loc = CurrentLocation; var type_name = type.ToString().ToLower(); switch(type){ case KnownTypeCode.Int: case KnownTypeCode.UInt: case KnownTypeCode.Byte: result = Expression.MakeConstant(type_name, 0, loc); break; case KnownTypeCode.Bool: result = Expression.MakeConstant(type_name, false, loc); break; case KnownTypeCode.Float: result = Expression.MakeConstant(type_name, 0.0, loc); break; case KnownTypeCode.String: result = Expression.MakeConstant(type_name, "", loc); break; case KnownTypeCode.Char: result = Expression.MakeConstant(type_name, '\0', loc); break; default: SemanticError("Error ES0030: Unknown object type"); break; } return result; }
protected AstType ConvertType(KnownTypeCode knownTypeCode) { IType type = refactoringContext.Compilation.FindType(knownTypeCode); if (type != null) return ConvertType(type); // Backup solution return new SimpleType(KnownTypeReference.GetCSharpNameByTypeCode(knownTypeCode)); }
public IType FindType(KnownTypeCode typeCode) { return(knownTypeCache.FindType(typeCode)); }
private KnownTypeReference(KnownTypeCode knownTypeCode, string namespaceName, string name, int typeParameterCount = 0, KnownTypeCode baseType = KnownTypeCode.Object) { this.knownTypeCode = knownTypeCode; this.namespaceName = namespaceName; this.name = name; this.typeParameterCount = typeParameterCount; this.baseType = baseType; }
public void AddFixedArg(KnownTypeCode type, object value) { AddFixedArg(compilation.FindType(type), value); }
/// <summary> /// Gets whether this type definition is derived from a given known type. /// </summary> public static bool IsDerivedFrom(this ITypeDefinition type, KnownTypeCode baseType) { if (type == null) throw new ArgumentNullException("type"); if (baseType == KnownTypeCode.None) return false; return IsDerivedFrom(type, type.Compilation.FindType(baseType).GetDefinition()); }
private static bool IsFloatingPointTypeCode(KnownTypeCode code) { return code == KnownTypeCode.Single || code == KnownTypeCode.Double; }
CSharpOperators.BinaryOperatorMethod PointerArithmeticOperator(IType resultType, KnownTypeCode inputType1, IType inputType2) { return PointerArithmeticOperator(resultType, compilation.FindType(inputType1), inputType2); }
public static unsafe void SetValue(this ICorDebugGenericValue corGenVal, KnownTypeCode type, object value) { if (value == null) throw new ArgumentNullException("value"); }