public InterField(FieldReference fldRef, List <InterGenericArgument> genericArgs, IResolver resolver, Action <InterField> onMapped) { genericArgs = genericArgs ?? InterGenericArgument.EmptyGenericArgsList; this.declType = resolver.Resolve(fldRef.DeclaringType, genericArgs); this.fldType = resolver.Resolve(fldRef.FieldType, genericArgs.Union(this.declType.GenericArguments).ToList()); this.name = fldRef.Name; FieldDefinition fldDef = fldRef.Resolve(); CustomAttribute mappedAttr = fldDef.CustomAttributes.Where(C => C.AttributeType.FullName == ClassNames.FieldMapAttribute).FirstOrDefault(); if (mappedAttr != null) { TypeReference mappedToType = mappedAttr.ConstructorArguments[0].Value as TypeReference; if (mappedToType != null) { string mappedToName = null; if (mappedAttr.ConstructorArguments.Count > 1) { mappedToName = mappedAttr.ConstructorArguments[1].Value as string; } mappedToName = mappedToName ?? this.name; TypeDefinition mappedToTypeDef = mappedToType.Resolve(); if (mappedToTypeDef != null) { FieldReference newFldRef = mappedToTypeDef.Fields.Where(F => F.Name == mappedToName).FirstOrDefault(); if (newFldRef != null) { onMapped(resolver.Resolve(newFldRef, genericArgs)); return; } } } } this.IsPublic = fldDef.IsPublic || fldDef.IsAssembly; this.IsProtected = fldDef.IsFamily || fldDef.IsFamilyAndAssembly || fldDef.IsFamilyOrAssembly; this.IsPrivate = fldDef.IsPrivate; this.IsStatic = fldDef.IsStatic; this.IsReadonly = fldDef.IsInitOnly; this.IsLiteral = fldDef.IsLiteral; this.IsThreadLocal = fldDef.CustomAttributes.Where(C => C.AttributeType.FullName == ClassNames.ThreadStaticAttribute).Count() > 0; if (fldRef.FieldType is RequiredModifierType) { RequiredModifierType modreq = (RequiredModifierType)fldRef.FieldType; if (modreq.ModifierType.FullName == ClassNames.IsVolatileModReq) { this.IsVolatile = true; } } this.constant = fldDef.Constant; this.initialValue = fldDef.InitialValue; }
public Ref <Types> RequiredModifier(Ref <Types> elementType, ClassName className) { var elementRefType = RefToValue(elementType); var modifierType = ClassNameToTypeReference(className); var type = new RequiredModifierType(modifierType, elementRefType); return(ValueToRef(type)); }
public static Expression GetDefaultValueExpression(this TypeReference typeReference, TypeSystem typeSystem) { if (typeReference.IsPrimitive) { string typeName = typeReference.FullName; switch (typeName) { case "System.Boolean": { return(new LiteralExpression(false, typeSystem, null)); } case "System.Char": { return(new LiteralExpression((char)0, typeSystem, null)); } case "System.IntPtr": { return(new DefaultObjectExpression(typeReference, null)); } default: { return(new LiteralExpression(Activator.CreateInstance(Type.GetType(typeName)), typeSystem, null)); } } } if (typeReference.IsGenericParameter) { return(new DefaultObjectExpression(typeReference, null)); } if (typeReference.IsArray) { //return GetLiteralExpression(typeReference.GetElementType(), typeSystem); return(new LiteralExpression(null, typeSystem, null)); } if (typeReference.IsValueType) { var typeDefinition = typeReference.Resolve(); if (typeDefinition != null && typeDefinition.IsEnum) { return(new LiteralExpression(0, typeSystem, null)); } else { return(new ObjectCreationExpression(typeReference.GetEmptyConstructorReference(), typeReference, null, null)); } } if (typeReference.IsRequiredModifier) { RequiredModifierType typeReferenceAsReqMod = typeReference as RequiredModifierType; return(typeReferenceAsReqMod.ElementType.GetDefaultValueExpression(typeSystem)); } return(new LiteralExpression(null, typeSystem, null)); }
void addRequiredModifierType(RequiredModifierType rmt) { if (rmt == null) { return; } addTypeSpecification(rmt); pushMember(rmt.ModifierType); }
void doRequiredModifierType(RequiredModifierType requiredModifierType) { if (requiredModifierTypes.ContainsKey(requiredModifierType)) { return; } requiredModifierTypes[requiredModifierType] = true; addRequiredModifierType(requiredModifierType); }
public TypeReference Visit(RequiredModifierType current, IGenericContext gcontext) { var result = new RequiredModifierType(Get(current.ModifierType, gcontext), Get(current.ElementType, gcontext)); if (current.HasGenericParameters) { CopyAndUpdate(result, current, gcontext); } return(result); }
public static bool IsVolatile(this FieldDefinition fieldDefinition) { RequiredModifierType modifierType = fieldDefinition.FieldType as RequiredModifierType; if (modifierType != null && modifierType.ModifierType.FullName == "System.Runtime.CompilerServices.IsVolatile") { return(true); } return(false); }
protected override StringBuilder AppendRequiredModifierType( StringBuilder buf, RequiredModifierType type, DynamicParserContext context) { if (type.ModifierType.FullName == "System.Runtime.InteropServices.InAttribute" && type.ElementType is ByReferenceType refType) { buf.Append("ref readonly "); return(_AppendTypeName(buf, refType.ElementType, context)); } return(base.AppendRequiredModifierType(buf, type, context)); }
public static RequiredModifierType ChangeRequiredModifierType(this RequiredModifierType type, TypeReference elementType) { if (elementType != type.ElementType) { var result = new RequiredModifierType(type.ModifierType, elementType); if (type.HasGenericParameters) { SetGenericParameters(result, type.GenericParameters); } return(result); } return(type); }
public static Modifiers ConvertModifiers(FieldDefinition fieldDef) { Modifiers modifiers = Modifiers.None; if (fieldDef.IsPrivate) { modifiers |= Modifiers.Private; } else if (fieldDef.IsAssembly || fieldDef.IsFamilyAndAssembly) { modifiers |= Modifiers.Internal; } else if (fieldDef.IsFamily) { modifiers |= Modifiers.Protected; } else if (fieldDef.IsFamilyOrAssembly) { modifiers |= Modifiers.Protected | Modifiers.Internal; } else if (fieldDef.IsPublic) { modifiers |= Modifiers.Public; } if (fieldDef.IsLiteral) { modifiers |= Modifiers.Const; } else { if (fieldDef.IsStatic) { modifiers |= Modifiers.Static; } if (fieldDef.IsInitOnly) { modifiers |= Modifiers.Readonly; } } RequiredModifierType modreq = fieldDef.FieldType as RequiredModifierType; if (modreq != null && modreq.ModifierType.FullName == typeof(IsVolatile).FullName) { modifiers |= Modifiers.Volatile; } return(modifiers); }
internal FieldGroupWithMonoCecil(ITypeWithMonoCecil declaringType, FieldDefinition field) { this.declaringType = declaringType; this.field = field; AssemblyWithMonoCecil assembly = declaringType.Assembly; attributes = new Lazy <Attributes>(() => new Attributes(assembly, field)); RequiredModifierType modifierType = field.FieldType as RequiredModifierType; fieldType = TypeReferenceWithMonoCecilFactory.CreateReference( assembly, modifierType == null ? field.FieldType : modifierType.ElementType, field); }
private static TypeReference ResolveIfNeeded(IGenericInstance genericInstanceMethod, IGenericInstance declaringGenericInstanceType, TypeReference parameterType) { ByReferenceType byReferenceType = parameterType as ByReferenceType; if (byReferenceType != null) { return(ResolveIfNeeded(genericInstanceMethod, declaringGenericInstanceType, byReferenceType)); } ArrayType arrayType = parameterType as ArrayType; if (arrayType != null) { return(ResolveIfNeeded(genericInstanceMethod, declaringGenericInstanceType, arrayType)); } GenericInstanceType type3 = parameterType as GenericInstanceType; if (type3 != null) { return(ResolveIfNeeded(genericInstanceMethod, declaringGenericInstanceType, type3)); } GenericParameter genericParameterElement = parameterType as GenericParameter; if (genericParameterElement != null) { return(ResolveIfNeeded(genericInstanceMethod, declaringGenericInstanceType, genericParameterElement)); } RequiredModifierType typeReference = parameterType as RequiredModifierType; if ((typeReference != null) && typeReference.ContainsGenericParameters()) { return(ResolveIfNeeded(genericInstanceMethod, declaringGenericInstanceType, typeReference.ElementType)); } if (parameterType.ContainsGenericParameters()) { throw new Exception("Unexpected generic parameter."); } return(parameterType); }
public void BuildField(RuntimicSystemModel semanticModel, BoundTypeDefinitionWithFields_I typeWithFields, FieldDefinition field, FieldInfo fieldInfo) { var fieldType = field.FieldType; // DotNet type is the elmeent type, not the elmenet type + modifier. if (field.FieldType.IsRequiredModifier) { RequiredModifierType modifierType = (RequiredModifierType)field.FieldType; fieldType = modifierType.ElementType; } Execution.Types.Ensuring.EnsureToType(semanticModel, fieldType, fieldInfo.FieldType, out BoundTypeDefinitionMask_I semanticFieldType); var convertedField = new BoundField() { FieldType = semanticFieldType, FieldDefinition = field, UnderlyingField = fieldInfo, Name = field.Name, }; typeWithFields.Fields.ByName.Add(convertedField.Name, convertedField); }
public FieldReference GetFieldReference(TypeDefinition type) { var fieldReference = FindField(type); var modifierType = new RequiredModifierType(volatileTypeFinder.VolatileReference, typeSystem.Boolean); if (fieldReference.IsStatic) { throw new WeavingException($"Field '{fieldReference.FullName}' can not be static."); } var fieldType = fieldReference.FieldType; if (fieldType.Name == "Boolean") { fieldReference.FieldType = modifierType; volatileFieldFixer.Fields.Add(fieldReference); return(fieldReference); } if (fieldReference.FieldType.Name != modifierType.Name) { throw new WeavingException("Incorrect type"); } return(fieldReference); }
protected void VisitTypeReference(TypeReference typeReference, Context context) { GenericParameter genericParameter = typeReference as GenericParameter; if (genericParameter != null) { this.Visit(genericParameter, context); } else { ArrayType arrayType = typeReference as ArrayType; if (arrayType != null) { this.Visit(arrayType, context); } else { PointerType pointerType = typeReference as PointerType; if (pointerType != null) { this.Visit(pointerType, context); } else { ByReferenceType byReferenceType = typeReference as ByReferenceType; if (byReferenceType != null) { this.Visit(byReferenceType, context); } else { FunctionPointerType functionPointerType = typeReference as FunctionPointerType; if (functionPointerType != null) { this.Visit(functionPointerType, context); } else { PinnedType pinnedType = typeReference as PinnedType; if (pinnedType != null) { this.Visit(pinnedType, context); } else { SentinelType sentinelType = typeReference as SentinelType; if (sentinelType != null) { this.Visit(sentinelType, context); } else { GenericInstanceType genericInstanceType = typeReference as GenericInstanceType; if (genericInstanceType != null) { this.Visit(genericInstanceType, context); } else { RequiredModifierType requiredModifierType = typeReference as RequiredModifierType; if (requiredModifierType != null) { this.Visit(requiredModifierType, context); } else { this.Visit(typeReference, context); } } } } } } } } } }
protected virtual void Visit(RequiredModifierType requiredModifierType, Context context) { this.VisitTypeReference(requiredModifierType.ElementType, context.ElementType(requiredModifierType)); }
public CodeTypeReference Visit(RequiredModifierType type, object data) { throw new System.NotImplementedException(); }
public static bool IsEqual(Reflector.CodeModel.IType t, TypeReference tr) { if (t is Reflector.CodeModel.ITypeReference) { return(IsEqual((Reflector.CodeModel.ITypeReference)t, tr)); } else if ((t is Reflector.CodeModel.IArrayType) && (tr is ArrayType)) { Reflector.CodeModel.IArrayType t2 = (Reflector.CodeModel.IArrayType)t; ArrayType tr2 = (ArrayType)tr; if ( !(t2.Dimensions.Count == 0 && tr2.Dimensions.Count == 1) && // one dimension (t2.Dimensions.Count != tr2.Dimensions.Count) // two or more dimension ) { return(false); } return(IsEqual(t2.ElementType, tr2.ElementType)); } else if ((t is Reflector.CodeModel.IReferenceType) && (tr is ByReferenceType)) { return(IsEqual(((Reflector.CodeModel.IReferenceType)t).ElementType, ((ByReferenceType)tr).ElementType)); } else if ((t is Reflector.CodeModel.IPointerType) && (tr is PointerType)) { return(IsEqual(((Reflector.CodeModel.IPointerType)t).ElementType, ((PointerType)tr).ElementType)); } else if ((t is Reflector.CodeModel.IOptionalModifier) && (tr is OptionalModifierType)) { Reflector.CodeModel.IOptionalModifier t2 = (Reflector.CodeModel.IOptionalModifier)t; OptionalModifierType tr2 = (OptionalModifierType)tr; return(IsEqual(t2.Modifier, tr2.ModifierType) && IsEqual(t2.ElementType, tr2.ElementType)); } else if ((t is Reflector.CodeModel.IFunctionPointer) && (tr is FunctionPointerType)) { Reflector.CodeModel.IFunctionPointer t2 = (Reflector.CodeModel.IFunctionPointer)t; FunctionPointerType tr2 = (FunctionPointerType)tr; if (t2.Parameters.Count == tr2.Parameters.Count && IsEqual(t2.ReturnType.Type, tr2.ReturnType)) { for (int i = 0; i < t2.Parameters.Count; i++) { if (!IsEqual(t2.Parameters[i].ParameterType, tr2.Parameters[i].ParameterType)) { return(false); } } return(true); } return(false); } else if ((t is Reflector.CodeModel.IRequiredModifier) && (tr is RequiredModifierType)) { Reflector.CodeModel.IRequiredModifier t2 = (Reflector.CodeModel.IRequiredModifier)t; RequiredModifierType tr2 = (RequiredModifierType)tr; return(IsEqual(t2.Modifier, tr2.ModifierType) && IsEqual(t2.ElementType, tr2.ElementType)); } else { string trName = InsUtils.GetOldMemberName(tr); //when tr is GenericParameter, it may be !0 or something, no clue what it is, no luck ... if ("!0" == trName && t.ToString() == "T") { return(true); } return(t.ToString().Equals(trName)); } }
public static TypeReference StackTypeFor(TypeReference type) { PinnedType type2 = type as PinnedType; if (type2 != null) { type = type2.ElementType; } ByReferenceType type3 = type as ByReferenceType; if (type3 != null) { return(type3); } RequiredModifierType type4 = type as RequiredModifierType; if (type4 != null) { return(StackTypeFor(type4.ElementType)); } if ((type.IsSameType(TypeProvider.NativeIntTypeReference) || type.IsSameType(TypeProvider.NativeUIntTypeReference)) || type.IsPointer) { return(TypeProvider.NativeIntTypeReference); } if (!type.IsValueType()) { return(TypeProvider.ObjectTypeReference); } MetadataType metadataType = type.MetadataType; if (type.IsValueType() && type.IsEnum()) { metadataType = type.GetUnderlyingEnumType().MetadataType; } switch (metadataType) { case MetadataType.Boolean: case MetadataType.Char: case MetadataType.SByte: case MetadataType.Byte: case MetadataType.Int16: case MetadataType.UInt16: case MetadataType.Int32: case MetadataType.UInt32: return(TypeProvider.Int32TypeReference); case MetadataType.Int64: case MetadataType.UInt64: return(TypeProvider.Int64TypeReference); case MetadataType.Single: return(TypeProvider.SingleTypeReference); case MetadataType.Double: return(TypeProvider.DoubleTypeReference); case MetadataType.IntPtr: case MetadataType.UIntPtr: return(TypeProvider.NativeIntTypeReference); } throw new ArgumentException($"Cannot get stack type for {type.Name}"); }
/// <summary> /// Gets a TypeRef from a TypeReference. /// </summary> /// <param name="type">The TypeReference.</param> /// <returns>The TypeRef.</returns> public static TypeRef GetTypeRefFromType(TypeReference type) { switch (type.MetadataType) { case MetadataType.UInt64: case MetadataType.Int64: return(Int64); case MetadataType.UInt32: case MetadataType.Int32: return(Int32); case MetadataType.UInt16: case MetadataType.Int16: return(Int16); case MetadataType.Byte: case MetadataType.SByte: return(Int8); case MetadataType.Char: return(Int8); case MetadataType.String: return(String); case MetadataType.Boolean: return(Boolean); case MetadataType.Void: return(Void); case MetadataType.Single: return(Float); case MetadataType.Double: return(Double); case MetadataType.IntPtr: case MetadataType.UIntPtr: return(NativeIntType); case MetadataType.Array: ArrayType array = (ArrayType)type; return(LLVM.PointerType(GetTypeRefFromType(array.ElementType), 0)); case MetadataType.Pointer: PointerType ptr = (PointerType)type; return(LLVM.PointerType(GetTypeRefFromType(ptr.ElementType), 0)); case MetadataType.ByReference: ByReferenceType byRef = (ByReferenceType)type; return(LLVM.PointerType(GetTypeRefFromType(byRef.ElementType), 0)); case MetadataType.Pinned: PinnedType pinned = (PinnedType)type; return(GetTypeRefFromType(pinned.ElementType)); case MetadataType.Class: return(LLVM.PointerType(mLookup.GetTypeRef(type), 0)); case MetadataType.ValueType: return(mLookup.GetTypeRef(type)); case MetadataType.GenericInstance: case MetadataType.Var: case MetadataType.Object: return(VoidPtr); case MetadataType.RequiredModifier: RequiredModifierType requiredModifier = (RequiredModifierType)type; return(GetTypeRefFromType(requiredModifier.ElementType)); case MetadataType.OptionalModifier: OptionalModifierType optionalModifier = (OptionalModifierType)type; return(GetTypeRefFromType(optionalModifier.ElementType)); default: throw new InvalidOperationException("Invalid meta data type to get type from: " + type.MetadataType); } }
public NetTypeReference Visit(RequiredModifierType type, ResolveData data) { throw new NotImplementedException("RequiredModifierType to NetTypeReference"); }
private static TypeReference ImportType(TypeReference typeRef, ModuleDefinition mod, MethodReference context, Dictionary <MetadataToken, IMemberDefinition> mems) { TypeReference ret = typeRef; if (typeRef is TypeSpecification) { if (typeRef is ArrayType) { ArrayType _spec = typeRef as ArrayType; ret = new ArrayType(ImportType(_spec.ElementType, mod, context, mems)); (ret as ArrayType).Dimensions.Clear(); foreach (var i in _spec.Dimensions) { (ret as ArrayType).Dimensions.Add(i); } } else if (typeRef is GenericInstanceType) { GenericInstanceType _spec = typeRef as GenericInstanceType; ret = new GenericInstanceType(ImportType(_spec.ElementType, mod, context, mems)); foreach (var i in _spec.GenericArguments) { (ret as GenericInstanceType).GenericArguments.Add(ImportType(i, mod, context, mems)); } } else if (typeRef is OptionalModifierType) { ret = new OptionalModifierType( ImportType((typeRef as OptionalModifierType).ModifierType, mod, context, mems), ImportType((typeRef as TypeSpecification).ElementType, mod, context, mems)); } else if (typeRef is RequiredModifierType) { ret = new RequiredModifierType( ImportType((typeRef as RequiredModifierType).ModifierType, mod, context, mems), ImportType((typeRef as TypeSpecification).ElementType, mod, context, mems)); } else if (typeRef is ByReferenceType) { ret = new ByReferenceType(ImportType((typeRef as TypeSpecification).ElementType, mod, context, mems)); } else if (typeRef is PointerType) { ret = new PointerType(ImportType((typeRef as TypeSpecification).ElementType, mod, context, mems)); } else if (typeRef is PinnedType) { ret = new PinnedType(ImportType((typeRef as TypeSpecification).ElementType, mod, context, mems)); } else if (typeRef is SentinelType) { ret = new SentinelType(ImportType((typeRef as TypeSpecification).ElementType, mod, context, mems)); } else { throw new NotSupportedException(); } } else if (typeRef is GenericParameter) { if (context == null || (typeRef as GenericParameter).Owner is TypeReference || (typeRef as GenericParameter).Position >= context.GenericParameters.Count) { return(typeRef); } return(context.GenericParameters[(typeRef as GenericParameter).Position]); } else { if (mems != null && mems.ContainsKey(typeRef.MetadataToken)) { ret = mems[typeRef.MetadataToken] as TypeReference; } else if (!(ret is TypeDefinition) && typeRef.Scope.Name != "Confuser.Core.Injections.dll") { ret = mod.Import(ret); } } return(ret); }
public TypeReference Resolve(TypeReference typeReference, bool includeTypeDefinitions) { if (!this.IsDummy()) { if ((this._typeDefinitionContext != null) && this._typeDefinitionContext.GenericArguments.Contains(typeReference)) { return(typeReference); } if ((this._methodDefinitionContext != null) && this._methodDefinitionContext.GenericArguments.Contains(typeReference)) { return(typeReference); } GenericParameter item = typeReference as GenericParameter; if (item != null) { if ((this._typeDefinitionContext != null) && this._typeDefinitionContext.GenericArguments.Contains(item)) { return(item); } if ((this._methodDefinitionContext != null) && this._methodDefinitionContext.GenericArguments.Contains(item)) { return(item); } return(this.ResolveGenericParameter(item)); } ArrayType type = typeReference as ArrayType; if (type != null) { return(new ArrayType(this.Resolve(type.ElementType), type.Rank)); } PointerType type2 = typeReference as PointerType; if (type2 != null) { return(new PointerType(this.Resolve(type2.ElementType))); } ByReferenceType type3 = typeReference as ByReferenceType; if (type3 != null) { return(new ByReferenceType(this.Resolve(type3.ElementType))); } PinnedType type4 = typeReference as PinnedType; if (type4 != null) { return(new PinnedType(this.Resolve(type4.ElementType))); } GenericInstanceType type5 = typeReference as GenericInstanceType; if (type5 != null) { GenericInstanceType type6 = new GenericInstanceType(type5.ElementType); foreach (TypeReference reference2 in type5.GenericArguments) { type6.GenericArguments.Add(this.Resolve(reference2)); } return(type6); } RequiredModifierType type7 = typeReference as RequiredModifierType; if (type7 != null) { return(this.Resolve(type7.ElementType, includeTypeDefinitions)); } if (includeTypeDefinitions) { TypeDefinition definition = typeReference as TypeDefinition; if ((definition != null) && definition.HasGenericParameters) { GenericInstanceType type8 = new GenericInstanceType(definition); foreach (GenericParameter parameter2 in definition.GenericParameters) { type8.GenericArguments.Add(this.Resolve(parameter2)); } return(type8); } } if (typeReference is TypeSpecification) { throw new NotSupportedException($"The type {typeReference.FullName} cannot be resolved correctly."); } } return(typeReference); }
public TypeReference Resolve(TypeReference typeReference) { GenericParameter genericParameter = typeReference as GenericParameter; if (genericParameter != null) { return(this.Resolve(this.ResolveGenericParameter(genericParameter))); } ArrayType arrayType = typeReference as ArrayType; if (arrayType != null) { return(new ArrayType(this.Resolve(arrayType.ElementType), arrayType.Rank)); } PointerType pointerType = typeReference as PointerType; if (pointerType != null) { return(new PointerType(this.Resolve(pointerType.ElementType))); } ByReferenceType byReferenceType = typeReference as ByReferenceType; if (byReferenceType != null) { return(new ByReferenceType(this.Resolve(byReferenceType.ElementType))); } GenericInstanceType genericInstanceType = typeReference as GenericInstanceType; if (genericInstanceType != null) { GenericInstanceType genericInstanceType2 = new GenericInstanceType(this.Resolve(genericInstanceType.ElementType)); foreach (TypeReference current in genericInstanceType.GenericArguments) { genericInstanceType2.GenericArguments.Add(this.Resolve(current)); } return(genericInstanceType2); } PinnedType pinnedType = typeReference as PinnedType; if (pinnedType != null) { return(new PinnedType(this.Resolve(pinnedType.ElementType))); } RequiredModifierType requiredModifierType = typeReference as RequiredModifierType; if (requiredModifierType != null) { return(this.Resolve(requiredModifierType.ElementType)); } OptionalModifierType optionalModifierType = typeReference as OptionalModifierType; if (optionalModifierType != null) { return(new OptionalModifierType(this.Resolve(optionalModifierType.ModifierType), this.Resolve(optionalModifierType.ElementType))); } SentinelType sentinelType = typeReference as SentinelType; if (sentinelType != null) { return(new SentinelType(this.Resolve(sentinelType.ElementType))); } FunctionPointerType functionPointerType = typeReference as FunctionPointerType; if (functionPointerType != null) { throw new NotSupportedException("Function pointer types are not supported by the SerializationWeaver"); } if (typeReference is TypeSpecification) { throw new NotSupportedException(); } return(typeReference); }
protected void TypeIdentifier(RequiredModifierType modreq, TypeReferenceContext context, bool includeParens) { Identifier(modreq.ElementType as dynamic, context, includeParens); }
protected override StringBuilder AppendRequiredModifierType(StringBuilder buf, RequiredModifierType type, DynamicParserContext context) { _AppendTypeName(buf, type.ElementType, context); buf.Append(" modreq("); _AppendTypeName(buf, type.ModifierType, context); buf.Append(')'); return(buf); }
static bool Match(TypeReference type, TypeReference target) { if (!(target is TypeSpecification)) { return(type.Name == target.Name && type.Namespace == target.Namespace); } if (type.MetadataType != target.MetadataType) { return(false); } TypeSpecification typeSpecA = type as TypeSpecification; TypeSpecification typeSpecB = target as TypeSpecification; switch (type.MetadataType) { case MetadataType.Array: { ArrayType arrA = type as ArrayType, arrB = target as ArrayType; if (arrA.Dimensions.Count != arrB.Dimensions.Count) { return(false); } for (int i = 0; i < arrA.Dimensions.Count; i++) { if (arrA.Dimensions[i].LowerBound != arrB.Dimensions[i].LowerBound || arrA.Dimensions[i].UpperBound != arrB.Dimensions[i].UpperBound) { return(false); } } return(Match(typeSpecA.ElementType, typeSpecB.ElementType)); } case MetadataType.RequiredModifier: { RequiredModifierType modA = type as RequiredModifierType, modB = target as RequiredModifierType; return(Match(modA.ModifierType, modB.ModifierType) && Match(typeSpecA.ElementType, typeSpecB.ElementType)); } case MetadataType.OptionalModifier: { OptionalModifierType modA = type as OptionalModifierType, modB = target as OptionalModifierType; return(Match(modA.ModifierType, modB.ModifierType) && Match(typeSpecA.ElementType, typeSpecB.ElementType)); } case MetadataType.ByReference: case MetadataType.Pinned: case MetadataType.Pointer: return(Match(typeSpecA.ElementType, typeSpecB.ElementType)); case MetadataType.GenericInstance: GenericInstanceType instA = type as GenericInstanceType, instB = target as GenericInstanceType; if (instA.GenericArguments.Count != instB.GenericArguments.Count) { return(false); } for (int i = 0; i < instA.GenericArguments.Count; i++) { if (!Match(instA.GenericArguments[i], instB.GenericArguments[i])) { return(false); } } return(Match(typeSpecA.ElementType, typeSpecB.ElementType)); case MetadataType.FunctionPointer: //not support throw new NotSupportedException(); } return(false); }
private static string GetFriendlyFullRequiredModifierTypeName(this RequiredModifierType self, ILanguage language, bool includeNamespace = true) { return(self.GetFriendlyFullTypeSpecificationName(language, includeNamespace) + self.Suffix); }
private static string GetFriendlyFullRequiredModifierTypeName(this RequiredModifierType self, ILanguage language) { return(String.Concat(self.GetFriendlyFullTypeSpecificationName(language), self.get_Suffix())); }
private void GetXmlDocParameterPathRecursive( TypeReference tpType, bool ExplicitMode, StringBuilder CurrPath) { if (tpType == null) { return; } if (tpType.GenericParameters.Count > 0) { CurrPath.Append( tpType.Namespace + ((CanAppendSpecialExplicitChar() && ExplicitMode) ? "#" : ".") + StripGenericName(tpType.Name)); // list parameters or types bool firstAppend = true; CurrPath.Append("{"); foreach (GenericParameter TempType in tpType.GenericParameters) { if (!firstAppend) { CurrPath.Append(","); } CurrPath.Append(GetXmlDocParameterPath(TempType, ExplicitMode)); firstAppend = false; } CurrPath.Append("}"); } else if (tpType is GenericInstanceType) { GenericInstanceType thisGenericType = tpType as GenericInstanceType; // if nested, scan enclosing type if (tpType.DeclaringType != null) { CurrPath.Append(GetXmlDocParameterPath(tpType.DeclaringType, ExplicitMode)); } // determine namespace string strNamespace = string.Empty; if ((tpType.Namespace != null && tpType.Namespace.Length > 0) || tpType.DeclaringType != null) { strNamespace = tpType.Namespace + ((CanAppendSpecialExplicitChar() && ExplicitMode) ? "#" : "."); } CurrPath.Append(strNamespace + StripGenericName(thisGenericType.Name)); // list parameters or types bool firstAppend = true; CurrPath.Append("{"); foreach (TypeReference tempTypeRef in thisGenericType.GenericArguments) { if (!firstAppend) { CurrPath.Append(","); } CurrPath.Append(GetXmlDocParameterPath(tempTypeRef, ExplicitMode)); firstAppend = false; } CurrPath.Append("}"); } else if (tpType is GenericParameter) { GenericParameter thisGenParam = tpType as GenericParameter; if (ExplicitMode) { // in explicit mode we print parameter name CurrPath.Append(thisGenParam.Name); } else { // in non-explicit mode we print parameter order int paramOrder = 0; // find for (int i = 0; i < thisGenParam.Owner.GenericParameters.Count; i++) { if (thisGenParam.Owner.GenericParameters[i].Name == tpType.Name) { paramOrder = i; break; } } if (thisGenParam.Owner is MethodReference) { CurrPath.Append("``" + paramOrder); } else { CurrPath.Append("`" + paramOrder); } } } else if (tpType is PointerType) { // parameter is pointer type CurrPath.Append(GetXmlDocParameterPath((tpType as PointerType).ElementType, ExplicitMode)); CurrPath.Append("*"); } else if (tpType is ArrayType) { ArrayType thisArrayType = tpType as ArrayType; if (thisArrayType.ElementType != null) { CurrPath.Append(GetXmlDocParameterPath(thisArrayType.ElementType, ExplicitMode)); } int iRank = thisArrayType.Rank; if (iRank == 1) { CurrPath.Append("[]"); } else { bool firstAppend = true; CurrPath.Append("["); for (int i = 0; i < (ExplicitMode ? iRank - 1 : iRank); i++) { // in explicit mode for .NET3.5/VS2008, // there is no separator char "," used for multi-dimensional array, // so there are three cases when comma shall be added: // firstAppend = false; ExplicitMode = false; CanAppendSpecialExplicitChar() = true; // firstAppend = false; ExplicitMode = false; CanAppendSpecialExplicitChar() = false; // firstAppend = false; ExplicitMode = true; CanAppendSpecialExplicitChar() = false; // below this is stored in decent manner if (!firstAppend && (!ExplicitMode || !CanAppendSpecialExplicitChar())) { CurrPath.Append(","); } CurrPath.Append(((CanAppendSpecialExplicitChar() && ExplicitMode) ? "@" : "0:")); if (thisArrayType.Dimensions[i].UpperBound > 0) { CurrPath.Append(thisArrayType.Dimensions[i].UpperBound.ToString()); } firstAppend = false; } CurrPath.Append("]"); } } else if (tpType is ByReferenceType) { // parameter is passed by reference CurrPath.Append(GetXmlDocParameterPath((tpType as ByReferenceType).ElementType, false)); CurrPath.Append("@"); } else if (tpType is OptionalModifierType) { // parameter has optional modifier OptionalModifierType thisModOpt = tpType as OptionalModifierType; CurrPath.Append(GetXmlDocParameterPath(thisModOpt.ElementType, ExplicitMode)); CurrPath.Append("!"); CurrPath.Append(GetXmlDocParameterPath(thisModOpt.ModifierType, ExplicitMode)); } else if (tpType is RequiredModifierType) { // parameter has required modifier RequiredModifierType thisModReq = tpType as RequiredModifierType; CurrPath.Append(GetXmlDocParameterPath(thisModReq.ElementType, ExplicitMode)); CurrPath.Append("|"); CurrPath.Append(GetXmlDocParameterPath(thisModReq.ModifierType, ExplicitMode)); } else if (tpType is FunctionPointerType) { // type is function pointer FunctionPointerType thisFuncPtr = tpType as FunctionPointerType; string tempString = string.Empty; // return type CurrPath.Append("=FUNC:"); CurrPath.Append(GetXmlDocParameterPath(thisFuncPtr.ReturnType, ExplicitMode)); // method's parameters if (thisFuncPtr.Parameters.Count > 0) { bool firstAppend = true; CurrPath.Append("("); foreach (ParameterDefinition tempParam in thisFuncPtr.Parameters) { if (!firstAppend) { CurrPath.Append(","); } CurrPath.Append(GetXmlDocParameterPath(tempParam.ParameterType, ExplicitMode)); firstAppend = false; } CurrPath.Append(")"); } else { CurrPath.Append("(System.Void)"); } } else if (tpType is PinnedType) { // type is pinned type CurrPath.Append(GetXmlDocParameterPath((tpType as PinnedType).ElementType, ExplicitMode)); CurrPath.Append("^"); } else if (tpType is TypeReference) { // if nested, scan enclosing type if (tpType.DeclaringType != null) { CurrPath.Append(GetXmlDocParameterPath(tpType.DeclaringType, ExplicitMode)); } // determine namespace string strNamespace = string.Empty; if ((tpType.Namespace != null && tpType.Namespace.Length > 0) || tpType.DeclaringType != null) { strNamespace = tpType.Namespace + ((CanAppendSpecialExplicitChar() && ExplicitMode) ? "#" : "."); } // concrete type CurrPath.Append( strNamespace + ((CanAppendSpecialExplicitChar() && ExplicitMode) ? tpType.Name.Replace(".", "#") : tpType.Name)); } }