private HLLocation ProcessBoundExpression(IBoundExpression pExpression) { if (pExpression.Definition is ILocalDefinition) { ILocalDefinition definition = pExpression.Definition as ILocalDefinition; HLLocation location = HLLocalLocation.Create(HLDomain.GetLocal(definition)); if (pExpression.Type.ResolvedType.TypeCode == PrimitiveTypeCode.Reference) { location = location.AddressOf(); } return(location); } else if (pExpression.Definition is IParameterDefinition) { return(HLParameterLocation.Create(HLDomain.GetParameter(pExpression.Definition as IParameterDefinition))); } else if (pExpression.Definition is IFieldDefinition || pExpression.Definition is IFieldReference) { IFieldDefinition definition = pExpression.Definition is IFieldDefinition ? (IFieldDefinition)pExpression.Definition : ((IFieldReference)pExpression.Definition).ResolvedField; HLType typeFieldContainer = HLDomain.GetOrCreateType(definition.Container); HLField field = HLDomain.GetField(definition); if (field.IsStatic) { return(HLStaticFieldLocation.Create(field)); } HLLocation instance = ProcessExpression(pExpression.Instance); return(HLFieldLocation.Create(instance, field)); } throw new NotSupportedException(); }
private HLLocation ProcessCreateDelegateInstanceExpression(ICreateDelegateInstance pExpression) { HLLocation locationInstance = null; if (pExpression.Instance != null) { locationInstance = ProcessExpression(pExpression.Instance); } HLMethod methodCalled = HLDomain.GetOrCreateMethod(pExpression.MethodToCallViaDelegate); HLLocation locationDelegate = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); mCurrentBlock.EmitNewDelegate(locationDelegate.Type, locationDelegate.AddressOf(), locationInstance, methodCalled, pExpression.IsVirtualDelegate); return(locationDelegate); }
private HLLocation ProcessCreateObjectInstanceExpression(ICreateObjectInstance pExpression) { HLMethod methodCalled = HLDomain.GetOrCreateMethod(pExpression.MethodToCall); HLLocation locationThis = HLTemporaryLocation.Create(CreateTemporary(methodCalled.Container)); List <HLLocation> locationsParameters = new List <HLLocation>(); if (methodCalled.Container == HLDomain.SystemString) { locationsParameters.Add(locationThis.AddressOf()); } else { mCurrentBlock.EmitNewObject(methodCalled.Container, locationThis.AddressOf()); locationsParameters.Add(locationThis); } foreach (IExpression argument in pExpression.Arguments) { locationsParameters.Add(ProcessExpression(argument)); } mCurrentBlock.EmitCall(methodCalled, false, null, locationsParameters); return(locationThis); }
private HLLocation ProcessCreateArrayExpression(ICreateArray pExpression) { if (pExpression.Rank != 1 || pExpression.Sizes.Count() != 1 || pExpression.LowerBounds.Count() > 0) { throw new NotSupportedException(); } HLType typeElement = HLDomain.GetOrCreateType(pExpression.ElementType); HLLocation locationInstance = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); HLLocation locationSize = ProcessExpression(pExpression.Sizes.First()); mCurrentBlock.EmitNewArray(locationInstance.AddressOf(), locationSize, locationInstance.Type, typeElement); IExpression[] initializers = pExpression.Initializers.ToArray(); for (int indexInitializer = 0; indexInitializer < initializers.Length; ++indexInitializer) { HLLocation locationInitializer = ProcessExpression(initializers[indexInitializer]); HLLocation locationArrayElement = HLArrayElementLocation.Create(locationInstance, HLInt32LiteralLocation.Create(indexInitializer), typeElement); mCurrentBlock.EmitAssignment(locationArrayElement, locationInitializer); } return(locationInstance); }