public override Func <IExtractContext, string[]> Apply( IFieldInformation field, DecodeContext decodeContext) { var siValue = decodeContext.PopStack(); var siReference = decodeContext.PopStack(); if (siReference.TargetType.IsByReference) { var dereferencedType = siReference.TargetType.ElementType; if (field.DeclaringType.IsAssignableFrom(dereferencedType) == false) { throw new InvalidProgramSequenceException( "Invalid managed reference: Location={0}, StackType={1}, Name={2}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName, field.FriendlyName); } } else if (siReference.TargetType.IsValueType == false) { if (field.DeclaringType.IsAssignableFrom(siReference.TargetType) == false) { throw new InvalidProgramSequenceException( "Invalid object reference: Location={0}, StackType={1}, Name={2}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName, field.FriendlyName); } } else { throw new InvalidProgramSequenceException( "Invalid type at stack: Location={0}, StackType={1}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName); } var codeInformation = decodeContext.CurrentCode; return(extractContext => { var rightExpression = extractContext.GetRightExpression( field.FieldType, siValue); if (rightExpression == null) { throw new InvalidProgramSequenceException( "Invalid store operation: Location={0}, StackType={1}, FieldType={2}", codeInformation.RawLocation, siValue.TargetType.FriendlyName, field.FieldType.FriendlyName); } return new[] { string.Format( "{0}->{1} = {2}", extractContext.GetSymbolName(siReference), field.Name, rightExpression) }; }); }
public static Func <IExtractContext, string[]> ApplyStatic( IFieldInformation field, DecodeContext decodeContext, bool requestPointer) { Debug.Assert(field.IsStatic); var targetType = field.FieldType; var symbol = decodeContext.PushStack( requestPointer ? targetType.MakeByReference() : targetType); // Special case: This method is the type initializer and target field inside it type. if (decodeContext.Method.IsConstructor && decodeContext.Method.IsStatic && decodeContext.Method.DeclaringType.Equals(field.DeclaringType)) { if (field.FieldType.IsReferenceType || (field.FieldType.IsValueType && field.FieldType.IsRequiredTraverse)) { return(extractContext => new[] { string.Format( "{0} = {1}{2}_STATIC_FIELDS__.{3}", extractContext.GetSymbolName(symbol), requestPointer ? "&" : string.Empty, field.DeclaringType.MangledUniqueName, field.MangledName) }); } else { return(extractContext => new[] { string.Format( "{0} = {1}{2}", extractContext.GetSymbolName(symbol), requestPointer ? "&" : string.Empty, field.MangledUniqueName) }); } } else if (field.NativeValue != null) { return(extractContext => new[] { string.Format( "{0} = {1}{2}", extractContext.GetSymbolName(symbol), requestPointer ? "&" : string.Empty, field.MangledUniqueName) }); } else { return(extractContext => new[] { string.Format( "{0} = {1}{2}_REF__", extractContext.GetSymbolName(symbol), requestPointer ? string.Empty : "*", extractContext.GetRightExpression(targetType, field.FieldType, field.MangledUniqueName)) }); } }
public override Func <IExtractContext, string[]> Apply( IFieldInformation field, DecodeContext decodeContext) { Debug.Assert(field.IsStatic); decodeContext.PrepareContext.RegisterStaticField(field); var targetType = field.FieldType; var symbol = decodeContext.PushStack(targetType); return(extractContext => new [] { string.Format( "{0} = {1}", extractContext.GetSymbolName(symbol), extractContext.GetRightExpression(targetType, field.FieldType, field.MangledName)) }); }
public override ExpressionEmitter Prepare( IFieldInformation field, DecodeContext decodeContext) { Debug.Assert(field.IsStatic); var targetType = field.FieldType; var symbol = decodeContext.PopStack(); // Special case: This method is the type initializer and target field inside it type. if (decodeContext.Method.IsConstructor && decodeContext.Method.IsStatic && decodeContext.Method.DeclaringType.Equals(field.DeclaringType)) { if (field.FieldType.IsReferenceType || (field.FieldType.IsValueType && field.FieldType.IsRequiredTraverse)) { return((extractContext, _) => new[] { string.Format( "{0}_STATIC_FIELDS__.{1} = {2}", field.DeclaringType.MangledUniqueName, field.MangledName, extractContext.GetRightExpression(targetType, symbol)) }); } else { return((extractContext, _) => new[] { string.Format( "{0} = {1}", field.MangledUniqueName, extractContext.GetRightExpression(targetType, symbol)) }); } } else if (field.NativeValue != null) { return((extractContext, _) => new[] { string.Format( "{0} = {1}", field.MangledUniqueName, extractContext.GetRightExpression(targetType, symbol)) }); } else { return((extractContext, _) => new[] { string.Format( "*{0}_REF__ = {1}", field.MangledUniqueName, extractContext.GetRightExpression(targetType, symbol)) }); } }
public override Func <IExtractContext, string[]> Apply( IFieldInformation field, DecodeContext decodeContext) { return(LdfldConverterUtilities.ApplyStatic(field, decodeContext, true)); }
public static Func <IExtractContext, string[]> Apply( IFieldInformation field, DecodeContext decodeContext, bool requestPointer) { var siReference = decodeContext.PopStack(); var oper = "->"; if (siReference.TargetType.IsByReference) { var dereferencedType = siReference.TargetType.ElementType; if (field.DeclaringType.IsAssignableFrom(dereferencedType) == false) { throw new InvalidProgramSequenceException( "Invalid managed reference: Location={0}, StackType={1}, Name={2}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName, field.FriendlyName); } } else if (!siReference.TargetType.IsValueType) { Debug.Assert(siReference.TargetType.IsClass || siReference.TargetType.IsInterface); if (field.DeclaringType.IsAssignableFrom(siReference.TargetType) == false) { throw new InvalidProgramSequenceException( "Invalid object reference: Location={0}, StackType={1}, Name={2}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName, field.FriendlyName); } } else if (!siReference.TargetType.IsPrimitive) { Debug.Assert(siReference.TargetType.IsValueType); if (field.DeclaringType.IsAssignableFrom(siReference.TargetType) == false) { throw new InvalidProgramSequenceException( "Invalid managed reference: Location={0}, StackType={1}, Name={2}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName, field.FriendlyName); } oper = "."; } else { throw new InvalidProgramSequenceException( "Invalid type at stack: Location={0}, StackType={1}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName); } var codeInformation = decodeContext.CurrentCode; // Register referenced field type (at the file scope). decodeContext.PrepareContext.RegisterType(field.FieldType, decodeContext.Method); if (requestPointer) { var result = decodeContext.PushStack(field.FieldType.MakeByReference()); return(extractContext => { return new[] { string.Format( "{0} = &{1}", extractContext.GetSymbolName(result), extractContext.GetSymbolName(siReference) + oper + field.MangledName) }; }); } else { var result = decodeContext.PushStack(field.FieldType); return(extractContext => { return new[] { string.Format( "{0} = {1}", extractContext.GetSymbolName(result), extractContext.GetSymbolName(siReference) + oper + field.MangledName) }; }); } }
public override ExpressionEmitter Prepare( IFieldInformation field, DecodeContext decodeContext) { return(StfldConverterUtilities.Prepare(field, decodeContext)); }
public static ExpressionEmitter Prepare( IFieldInformation field, DecodeContext decodeContext) { var siValue = decodeContext.PopStack(); var siReference = decodeContext.PopStack(); if (siReference.TargetType.IsByReference) { var dereferencedType = siReference.TargetType.ElementType; if (field.DeclaringType.IsAssignableFrom(dereferencedType) == false) { throw new InvalidProgramSequenceException( "Invalid managed reference: Location={0}, StackType={1}, Name={2}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName, field.FriendlyName); } } else if (siReference.TargetType.IsValueType == false) { if (field.DeclaringType.IsAssignableFrom(siReference.TargetType) == false) { throw new InvalidProgramSequenceException( "Invalid object reference: Location={0}, StackType={1}, Name={2}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName, field.FriendlyName); } } else { throw new InvalidProgramSequenceException( "Invalid type at stack: Location={0}, StackType={1}", decodeContext.CurrentCode.RawLocation, siReference.TargetType.FriendlyName); } var codeInformation = decodeContext.CurrentCode; // Register referenced field type (at the file scope). decodeContext.PrepareContext.RegisterType(field.FieldType, decodeContext.Method); return((extractContext, _) => { var rightExpression = extractContext.GetRightExpression( field.FieldType, siValue); if (rightExpression == null) { throw new InvalidProgramSequenceException( "Invalid store operation: Location={0}, StackType={1}, FieldType={2}", codeInformation.RawLocation, siValue.TargetType.FriendlyName, field.FieldType.FriendlyName); } return new[] { string.Format( "{0}->{1} = {2}", extractContext.GetSymbolName(siReference), field.MangledName, rightExpression) }; }); }
public override ExpressionEmitter Prepare( IFieldInformation field, DecodeContext decodeContext) { return(LdfldConverterUtilities.ApplyStatic(field, decodeContext, true)); }