Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / Microsoft / Scripting / Compiler / CompilerScope.Storage.cs / 1305376 / CompilerScope.Storage.cs
/* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Microsoft Public License. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Microsoft Public License, please send an email to * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Microsoft Public License. * * You must not remove this notice, or any other, from this software. * * * ***************************************************************************/ using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; namespace System.Linq.Expressions.Compiler { internal sealed partial class CompilerScope { private abstract class Storage { internal readonly LambdaCompiler Compiler; internal readonly ParameterExpression Variable; internal Storage(LambdaCompiler compiler, ParameterExpression variable) { Compiler = compiler; Variable = variable; } internal abstract void EmitLoad(); internal abstract void EmitAddress(); internal abstract void EmitStore(); internal virtual void EmitStore(Storage value) { value.EmitLoad(); EmitStore(); } internal virtual void FreeLocal() { } } private sealed class LocalStorage : Storage { private readonly LocalBuilder _local; internal LocalStorage(LambdaCompiler compiler, ParameterExpression variable) : base(compiler, variable) { // ByRef variables are supported. This is used internally by // the compiler when emitting an inlined lambda invoke, to // handle ByRef parameters. BlockExpression prevents this // from being exposed to user created trees. _local = compiler.GetNamedLocal(variable.IsByRef ? variable.Type.MakeByRefType() : variable.Type, variable); } internal override void EmitLoad() { Compiler.IL.Emit(OpCodes.Ldloc, _local); } internal override void EmitStore() { Compiler.IL.Emit(OpCodes.Stloc, _local); } internal override void EmitAddress() { Compiler.IL.Emit(OpCodes.Ldloca, _local); } } private sealed class ArgumentStorage : Storage { private readonly int _argument; internal ArgumentStorage(LambdaCompiler compiler, ParameterExpression p) : base(compiler, p) { _argument = compiler.GetLambdaArgument(compiler.Parameters.IndexOf(p)); } internal override void EmitLoad() { Compiler.IL.EmitLoadArg(_argument); } internal override void EmitStore() { Compiler.IL.EmitStoreArg(_argument); } internal override void EmitAddress() { Compiler.IL.EmitLoadArgAddress(_argument); } } private sealed class ElementBoxStorage : Storage { private readonly int _index; private readonly Storage _array; private readonly Type _boxType; private readonly FieldInfo _boxValueField; internal ElementBoxStorage(Storage array, int index, ParameterExpression variable) : base(array.Compiler, variable) { _array = array; _index = index; _boxType = typeof(StrongBox<>).MakeGenericType(variable.Type); _boxValueField = _boxType.GetField("Value"); } internal override void EmitLoad() { EmitLoadBox(); Compiler.IL.Emit(OpCodes.Ldfld, _boxValueField); } internal override void EmitStore() { LocalBuilder value = Compiler.GetLocal(Variable.Type); Compiler.IL.Emit(OpCodes.Stloc, value); EmitLoadBox(); Compiler.IL.Emit(OpCodes.Ldloc, value); Compiler.FreeLocal(value); Compiler.IL.Emit(OpCodes.Stfld, _boxValueField); } internal override void EmitStore(Storage value) { EmitLoadBox(); value.EmitLoad(); Compiler.IL.Emit(OpCodes.Stfld, _boxValueField); } internal override void EmitAddress() { EmitLoadBox(); Compiler.IL.Emit(OpCodes.Ldflda, _boxValueField); } internal void EmitLoadBox() { _array.EmitLoad(); Compiler.IL.EmitInt(_index); Compiler.IL.Emit(OpCodes.Ldelem_Ref); Compiler.IL.Emit(OpCodes.Castclass, _boxType); } } private sealed class LocalBoxStorage : Storage { private readonly LocalBuilder _boxLocal; private readonly Type _boxType; private readonly FieldInfo _boxValueField; internal LocalBoxStorage(LambdaCompiler compiler, ParameterExpression variable) : base(compiler, variable) { _boxType = typeof(StrongBox<>).MakeGenericType(variable.Type); _boxValueField = _boxType.GetField("Value"); _boxLocal = compiler.GetNamedLocal(_boxType, variable); } internal override void EmitLoad() { Compiler.IL.Emit(OpCodes.Ldloc, _boxLocal); Compiler.IL.Emit(OpCodes.Ldfld, _boxValueField); } internal override void EmitAddress() { Compiler.IL.Emit(OpCodes.Ldloc, _boxLocal); Compiler.IL.Emit(OpCodes.Ldflda, _boxValueField); } internal override void EmitStore() { LocalBuilder value = Compiler.GetLocal(Variable.Type); Compiler.IL.Emit(OpCodes.Stloc, value); Compiler.IL.Emit(OpCodes.Ldloc, _boxLocal); Compiler.IL.Emit(OpCodes.Ldloc, value); Compiler.FreeLocal(value); Compiler.IL.Emit(OpCodes.Stfld, _boxValueField); } internal override void EmitStore(Storage value) { Compiler.IL.Emit(OpCodes.Ldloc, _boxLocal); value.EmitLoad(); Compiler.IL.Emit(OpCodes.Stfld, _boxValueField); } internal void EmitStoreBox() { Compiler.IL.Emit(OpCodes.Stloc, _boxLocal); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Microsoft Public License. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Microsoft Public License, please send an email to * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Microsoft Public License. * * You must not remove this notice, or any other, from this software. * * * ***************************************************************************/ using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; namespace System.Linq.Expressions.Compiler { internal sealed partial class CompilerScope { private abstract class Storage { internal readonly LambdaCompiler Compiler; internal readonly ParameterExpression Variable; internal Storage(LambdaCompiler compiler, ParameterExpression variable) { Compiler = compiler; Variable = variable; } internal abstract void EmitLoad(); internal abstract void EmitAddress(); internal abstract void EmitStore(); internal virtual void EmitStore(Storage value) { value.EmitLoad(); EmitStore(); } internal virtual void FreeLocal() { } } private sealed class LocalStorage : Storage { private readonly LocalBuilder _local; internal LocalStorage(LambdaCompiler compiler, ParameterExpression variable) : base(compiler, variable) { // ByRef variables are supported. This is used internally by // the compiler when emitting an inlined lambda invoke, to // handle ByRef parameters. BlockExpression prevents this // from being exposed to user created trees. _local = compiler.GetNamedLocal(variable.IsByRef ? variable.Type.MakeByRefType() : variable.Type, variable); } internal override void EmitLoad() { Compiler.IL.Emit(OpCodes.Ldloc, _local); } internal override void EmitStore() { Compiler.IL.Emit(OpCodes.Stloc, _local); } internal override void EmitAddress() { Compiler.IL.Emit(OpCodes.Ldloca, _local); } } private sealed class ArgumentStorage : Storage { private readonly int _argument; internal ArgumentStorage(LambdaCompiler compiler, ParameterExpression p) : base(compiler, p) { _argument = compiler.GetLambdaArgument(compiler.Parameters.IndexOf(p)); } internal override void EmitLoad() { Compiler.IL.EmitLoadArg(_argument); } internal override void EmitStore() { Compiler.IL.EmitStoreArg(_argument); } internal override void EmitAddress() { Compiler.IL.EmitLoadArgAddress(_argument); } } private sealed class ElementBoxStorage : Storage { private readonly int _index; private readonly Storage _array; private readonly Type _boxType; private readonly FieldInfo _boxValueField; internal ElementBoxStorage(Storage array, int index, ParameterExpression variable) : base(array.Compiler, variable) { _array = array; _index = index; _boxType = typeof(StrongBox<>).MakeGenericType(variable.Type); _boxValueField = _boxType.GetField("Value"); } internal override void EmitLoad() { EmitLoadBox(); Compiler.IL.Emit(OpCodes.Ldfld, _boxValueField); } internal override void EmitStore() { LocalBuilder value = Compiler.GetLocal(Variable.Type); Compiler.IL.Emit(OpCodes.Stloc, value); EmitLoadBox(); Compiler.IL.Emit(OpCodes.Ldloc, value); Compiler.FreeLocal(value); Compiler.IL.Emit(OpCodes.Stfld, _boxValueField); } internal override void EmitStore(Storage value) { EmitLoadBox(); value.EmitLoad(); Compiler.IL.Emit(OpCodes.Stfld, _boxValueField); } internal override void EmitAddress() { EmitLoadBox(); Compiler.IL.Emit(OpCodes.Ldflda, _boxValueField); } internal void EmitLoadBox() { _array.EmitLoad(); Compiler.IL.EmitInt(_index); Compiler.IL.Emit(OpCodes.Ldelem_Ref); Compiler.IL.Emit(OpCodes.Castclass, _boxType); } } private sealed class LocalBoxStorage : Storage { private readonly LocalBuilder _boxLocal; private readonly Type _boxType; private readonly FieldInfo _boxValueField; internal LocalBoxStorage(LambdaCompiler compiler, ParameterExpression variable) : base(compiler, variable) { _boxType = typeof(StrongBox<>).MakeGenericType(variable.Type); _boxValueField = _boxType.GetField("Value"); _boxLocal = compiler.GetNamedLocal(_boxType, variable); } internal override void EmitLoad() { Compiler.IL.Emit(OpCodes.Ldloc, _boxLocal); Compiler.IL.Emit(OpCodes.Ldfld, _boxValueField); } internal override void EmitAddress() { Compiler.IL.Emit(OpCodes.Ldloc, _boxLocal); Compiler.IL.Emit(OpCodes.Ldflda, _boxValueField); } internal override void EmitStore() { LocalBuilder value = Compiler.GetLocal(Variable.Type); Compiler.IL.Emit(OpCodes.Stloc, value); Compiler.IL.Emit(OpCodes.Ldloc, _boxLocal); Compiler.IL.Emit(OpCodes.Ldloc, value); Compiler.FreeLocal(value); Compiler.IL.Emit(OpCodes.Stfld, _boxValueField); } internal override void EmitStore(Storage value) { Compiler.IL.Emit(OpCodes.Ldloc, _boxLocal); value.EmitLoad(); Compiler.IL.Emit(OpCodes.Stfld, _boxValueField); } internal void EmitStoreBox() { Compiler.IL.Emit(OpCodes.Stloc, _boxLocal); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WebPartMovingEventArgs.cs
- SqlRecordBuffer.cs
- CheckoutException.cs
- Bits.cs
- OutputCacheSection.cs
- MembershipValidatePasswordEventArgs.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- WCFBuildProvider.cs
- ParenExpr.cs
- CategoryNameCollection.cs
- TransformGroup.cs
- CustomCategoryAttribute.cs
- NetworkAddressChange.cs
- DesignerContextDescriptor.cs
- XmlEntity.cs
- UnmanagedBitmapWrapper.cs
- Splitter.cs
- StringUtil.cs
- SiteMapProvider.cs
- Select.cs
- SequenceQuery.cs
- KeyValueInternalCollection.cs
- TableRowGroup.cs
- SetterBaseCollection.cs
- MetadataFile.cs
- Sql8ExpressionRewriter.cs
- ListView.cs
- Int32Collection.cs
- ControlBindingsCollection.cs
- OutputScopeManager.cs
- RegexCharClass.cs
- InfoCardProofToken.cs
- NullableDecimalMinMaxAggregationOperator.cs
- Frame.cs
- OleDbEnumerator.cs
- InputLanguage.cs
- UniqueSet.cs
- ErrorHandler.cs
- IdlingCommunicationPool.cs
- ListViewUpdateEventArgs.cs
- ApplicationSecurityManager.cs
- ExpressionBuilder.cs
- ValidationResult.cs
- WebPartZone.cs
- PreProcessInputEventArgs.cs
- SystemWebExtensionsSectionGroup.cs
- FatalException.cs
- ToolStripScrollButton.cs
- WSTrust.cs
- AutomationPeer.cs
- ScriptResourceAttribute.cs
- QuotedPrintableStream.cs
- figurelength.cs
- ExitEventArgs.cs
- TdsParserSessionPool.cs
- ExeContext.cs
- X509CertificateEndpointIdentity.cs
- PolyBezierSegmentFigureLogic.cs
- OperationExecutionFault.cs
- Margins.cs
- RoleManagerSection.cs
- ExternalCalls.cs
- PixelFormat.cs
- QuaternionAnimation.cs
- ChangeDirector.cs
- ConsoleTraceListener.cs
- SQLSingleStorage.cs
- WebPartTransformerCollection.cs
- BasicHttpSecurityMode.cs
- InfoCardClaimCollection.cs
- PartialToken.cs
- AmbientLight.cs
- PageCatalogPart.cs
- TypeDependencyAttribute.cs
- VisualBasic.cs
- PropertyChangedEventArgs.cs
- Memoizer.cs
- ConsumerConnectionPoint.cs
- File.cs
- Baml2006ReaderContext.cs
- Guid.cs
- PathFigureCollection.cs
- EntityContainer.cs
- PopOutPanel.cs
- ExtenderProviderService.cs
- Grid.cs
- NameTable.cs
- Ipv6Element.cs
- ExpressionNode.cs
- NavigationEventArgs.cs
- ReferentialConstraint.cs
- MetadataArtifactLoaderCompositeFile.cs
- DetailsViewRowCollection.cs
- DataObject.cs
- HttpApplication.cs
- TokenizerHelper.cs
- MergeLocalizationDirectives.cs
- baseaxisquery.cs
- StrokeFIndices.cs
- InkCanvasFeedbackAdorner.cs