Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,82 +0,0 @@
//
// ConditionalExpression.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
#if !FULL_AOT_RUNTIME
using System.Reflection.Emit;
#endif
namespace System.Linq.Expressions {
public sealed class ConditionalExpression : Expression {
Expression test;
Expression if_true;
Expression if_false;
public Expression Test {
get { return test; }
}
public Expression IfTrue {
get { return if_true; }
}
public Expression IfFalse {
get { return if_false; }
}
internal ConditionalExpression (Expression test, Expression if_true, Expression if_false)
: base (ExpressionType.Conditional, if_true.Type)
{
this.test = test;
this.if_true = if_true;
this.if_false = if_false;
}
#if !FULL_AOT_RUNTIME
internal override void Emit (EmitContext ec)
{
var ig = ec.ig;
var false_target = ig.DefineLabel ();
var end_target = ig.DefineLabel ();
test.Emit (ec);
ig.Emit (OpCodes.Brfalse, false_target);
if_true.Emit (ec);
ig.Emit (OpCodes.Br, end_target);
ig.MarkLabel (false_target);
if_false.Emit (ec);
ig.MarkLabel (end_target);
}
#endif
}
}

View File

@@ -1,204 +0,0 @@
//
// ConstantExpression.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
// Miguel de Icaza (miguel@novell.com)
//
// Some code is based on the Mono C# compiler:
// Marek Safar (marek.safar@seznam.cz)
// Martin Baulig (martin@ximian.com)
//
// (C) 2001-2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
#if !FULL_AOT_RUNTIME
using System.Reflection.Emit;
#endif
namespace System.Linq.Expressions {
public sealed class ConstantExpression : Expression {
object value;
public object Value {
get { return value; }
}
internal ConstantExpression (object value, Type type)
: base (ExpressionType.Constant, type)
{
this.value = value;
}
internal static bool IsNull (Expression e)
{
var c = e as ConstantExpression;
return c != null && c.value == null;
}
#if !FULL_AOT_RUNTIME
internal override void Emit (EmitContext ec)
{
if (Type.IsNullable ()) {
EmitNullableConstant (ec, Type, value);
return;
}
EmitConstant (ec, Type, value);
}
void EmitNullableConstant (EmitContext ec, Type type, object value)
{
if (value == null) {
var local = ec.ig.DeclareLocal (type);
ec.EmitNullableInitialize (local);
} else {
EmitConstant (ec, type.GetFirstGenericArgument (), value);
ec.EmitNullableNew (type);
}
}
void EmitConstant (EmitContext ec, Type type, object value)
{
var ig = ec.ig;
switch (Type.GetTypeCode (type)){
case TypeCode.Byte:
ig.Emit (OpCodes.Ldc_I4, (int) ((byte)value));
return;
case TypeCode.SByte:
ig.Emit (OpCodes.Ldc_I4, (int) ((sbyte)value));
return;
case TypeCode.Int16:
ig.Emit (OpCodes.Ldc_I4, (int) ((short)value));
return;
case TypeCode.UInt16:
ig.Emit (OpCodes.Ldc_I4, (int) ((ushort)value));
return;
case TypeCode.Int32:
ig.Emit (OpCodes.Ldc_I4, (int) value);
return;
case TypeCode.UInt32:
ig.Emit (OpCodes.Ldc_I4, unchecked ((int) ((uint)Value)));
return;
case TypeCode.Int64:
ig.Emit (OpCodes.Ldc_I8, (long) value);
return;
case TypeCode.UInt64:
ig.Emit (OpCodes.Ldc_I8, unchecked ((long) ((ulong)value)));
return;
case TypeCode.Boolean:
if ((bool) Value)
ig.Emit (OpCodes.Ldc_I4_1);
else
ec.ig.Emit (OpCodes.Ldc_I4_0);
return;
case TypeCode.Char:
ig.Emit (OpCodes.Ldc_I4, (int) ((char) value));
return;
case TypeCode.Single:
ig.Emit (OpCodes.Ldc_R4, (float) value);
return;
case TypeCode.Double:
ig.Emit (OpCodes.Ldc_R8, (double) value);
return;
case TypeCode.Decimal: {
Decimal v = (decimal) value;
int [] words = Decimal.GetBits (v);
int power = (words [3] >> 16) & 0xff;
Type ti = typeof (int);
if (power == 0 && v <= int.MaxValue && v >= int.MinValue) {
ig.Emit (OpCodes.Ldc_I4, (int) v);
ig.Emit (OpCodes.Newobj, typeof (Decimal).GetConstructor (new Type [1] { ti }));
return;
}
ig.Emit (OpCodes.Ldc_I4, words [0]);
ig.Emit (OpCodes.Ldc_I4, words [1]);
ig.Emit (OpCodes.Ldc_I4, words [2]);
// sign
ig.Emit (OpCodes.Ldc_I4, words [3] >> 31);
// power
ig.Emit (OpCodes.Ldc_I4, power);
ig.Emit (OpCodes.Newobj, typeof (Decimal).GetConstructor (new Type [5] { ti, ti, ti, typeof(bool), typeof(byte) }));
return;
}
case TypeCode.DateTime: {
var date = (DateTime) value;
var local = ig.DeclareLocal (typeof (DateTime));
ig.Emit (OpCodes.Ldloca, local);
ig.Emit (OpCodes.Ldc_I8, date.Ticks);
ig.Emit (OpCodes.Ldc_I4, (int) date.Kind);
ig.Emit (OpCodes.Call, typeof (DateTime).GetConstructor (new [] { typeof (long), typeof (DateTimeKind) }));
ig.Emit (OpCodes.Ldloc, local);
return;
}
case TypeCode.DBNull:
ig.Emit (OpCodes.Ldsfld, typeof (DBNull).GetField ("Value", BindingFlags.Public | BindingFlags.Static));
return;
case TypeCode.String:
EmitIfNotNull (ec, c => c.ig.Emit (OpCodes.Ldstr, (string) value));
return;
case TypeCode.Object:
EmitIfNotNull (ec, c => c.EmitReadGlobal (value));
return;
}
throw new NotImplementedException (String.Format ("No support for constants of type {0} yet", Type));
}
void EmitIfNotNull (EmitContext ec, Action<EmitContext> emit)
{
if (value == null) {
ec.ig.Emit (OpCodes.Ldnull);
return;
}
emit (ec);
}
#endif
}
}

View File

@@ -26,7 +26,6 @@
//
//
#if NET_4_5
namespace System.Linq.Expressions
{
@@ -35,4 +34,3 @@ namespace System.Linq.Expressions
}
}
#endif

View File

@@ -1,78 +0,0 @@
//
// ElementInit.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.ObjectModel;
using System.Reflection;
#if !FULL_AOT_RUNTIME
using System.Reflection.Emit;
#endif
namespace System.Linq.Expressions {
public sealed class ElementInit {
MethodInfo add_method;
ReadOnlyCollection<Expression> arguments;
public MethodInfo AddMethod {
get { return add_method; }
}
public ReadOnlyCollection<Expression> Arguments {
get { return arguments; }
}
internal ElementInit (MethodInfo add_method, ReadOnlyCollection<Expression> arguments)
{
this.add_method = add_method;
this.arguments = arguments;
}
public override string ToString ()
{
return ExpressionPrinter.ToString (this);
}
#if !FULL_AOT_RUNTIME
void EmitPopIfNeeded (EmitContext ec)
{
if (add_method.ReturnType == typeof (void))
return;
ec.ig.Emit (OpCodes.Pop);
}
internal void Emit (EmitContext ec, LocalBuilder local)
{
ec.EmitCall (local, arguments, add_method);
EmitPopIfNeeded (ec);
}
#endif
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,398 +0,0 @@
//
// ExpressionPrinter.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace System.Linq.Expressions {
class ExpressionPrinter : ExpressionVisitor {
StringBuilder builder;
const string ListSeparator = ", ";
ExpressionPrinter (StringBuilder builder)
{
this.builder = builder;
}
ExpressionPrinter () : this (new StringBuilder ())
{
}
public static string ToString (Expression expression)
{
var printer = new ExpressionPrinter ();
printer.Visit (expression);
return printer.builder.ToString ();
}
public static string ToString (ElementInit init)
{
var printer = new ExpressionPrinter ();
printer.VisitElementInitializer (init);
return printer.builder.ToString ();
}
public static string ToString (MemberBinding binding)
{
var printer = new ExpressionPrinter ();
printer.VisitBinding (binding);
return printer.builder.ToString ();
}
void Print (string str)
{
builder.Append (str);
}
void Print (object obj)
{
builder.Append (obj);
}
void Print (string str, params object [] objs)
{
builder.AppendFormat (str, objs);
}
protected override void VisitElementInitializer (ElementInit initializer)
{
Print (initializer.AddMethod);
Print ("(");
VisitExpressionList (initializer.Arguments);
Print (")");
}
protected override void VisitUnary (UnaryExpression unary)
{
switch (unary.NodeType) {
case ExpressionType.ArrayLength:
case ExpressionType.Convert:
case ExpressionType.ConvertChecked:
case ExpressionType.Not:
Print ("{0}(", unary.NodeType);
Visit (unary.Operand);
Print (")");
return;
case ExpressionType.Negate:
Print ("-");
Visit (unary.Operand);
return;
case ExpressionType.Quote:
Visit (unary.Operand);
return;
case ExpressionType.TypeAs:
Print ("(");
Visit (unary.Operand);
Print (" As {0})", unary.Type.Name);
return;
case ExpressionType.UnaryPlus:
Print ("+");
Visit (unary.Operand);
return;
}
throw new NotImplementedException ();
}
static string OperatorToString (BinaryExpression binary)
{
switch (binary.NodeType) {
case ExpressionType.Add:
case ExpressionType.AddChecked:
return "+";
case ExpressionType.AndAlso:
return "&&";
case ExpressionType.Coalesce:
return "??";
case ExpressionType.Divide:
return "/";
case ExpressionType.Equal:
return "=";
case ExpressionType.ExclusiveOr:
return "^";
case ExpressionType.GreaterThan:
return ">";
case ExpressionType.GreaterThanOrEqual:
return ">=";
case ExpressionType.LeftShift:
return "<<";
case ExpressionType.LessThan:
return "<";
case ExpressionType.LessThanOrEqual:
return "<=";
case ExpressionType.Modulo:
return "%";
case ExpressionType.Multiply:
case ExpressionType.MultiplyChecked:
return "*";
case ExpressionType.NotEqual:
return "!=";
case ExpressionType.OrElse:
return "||";
case ExpressionType.Power:
return "^";
case ExpressionType.RightShift:
return ">>";
case ExpressionType.Subtract:
case ExpressionType.SubtractChecked:
return "-";
case ExpressionType.And:
return IsBoolean (binary) ? "And" : "&";
case ExpressionType.Or:
return IsBoolean (binary) ? "Or" : "|";
default:
return null;
}
}
static bool IsBoolean (Expression expression)
{
return expression.Type == typeof (bool) || expression.Type == typeof (bool?);
}
void PrintArrayIndex (BinaryExpression index)
{
Visit (index.Left);
Print ("[");
Visit (index.Right);
Print ("]");
}
protected override void VisitBinary (BinaryExpression binary)
{
switch (binary.NodeType) {
case ExpressionType.ArrayIndex:
PrintArrayIndex (binary);
return;
default:
Print ("(");
Visit (binary.Left);
Print (" {0} ", OperatorToString (binary));
Visit (binary.Right);
Print (")");
return;
}
}
protected override void VisitTypeIs (TypeBinaryExpression type)
{
switch (type.NodeType) {
case ExpressionType.TypeIs:
Print ("(");
Visit (type.Expression);
Print (" Is {0})", type.TypeOperand.Name);
return;
}
throw new NotImplementedException ();
}
protected override void VisitConstant (ConstantExpression constant)
{
var value = constant.Value;
if (value == null) {
Print ("null");
} else if (value is string) {
Print ("\"");
Print (value);
Print ("\"");
} else if (!HasStringRepresentation (value)) {
Print ("value(");
Print (value);
Print (")");
} else
Print (value);
}
static bool HasStringRepresentation (object obj)
{
return obj.ToString () != obj.GetType ().ToString ();
}
protected override void VisitConditional (ConditionalExpression conditional)
{
Print ("IIF(");
Visit (conditional.Test);
Print (ListSeparator);
Visit (conditional.IfTrue);
Print (ListSeparator);
Visit (conditional.IfFalse);
Print (")");
}
protected override void VisitParameter (ParameterExpression parameter)
{
Print (parameter.Name ?? "<param>");
}
protected override void VisitMemberAccess (MemberExpression access)
{
if (access.Expression == null)
Print (access.Member.DeclaringType.Name);
else
Visit (access.Expression);
Print (".{0}", access.Member.Name);
}
protected override void VisitMethodCall (MethodCallExpression call)
{
if (call.Object != null) {
Visit (call.Object);
Print (".");
}
Print (call.Method.Name);
Print ("(");
VisitExpressionList (call.Arguments);
Print (")");
}
protected override void VisitMemberAssignment (MemberAssignment assignment)
{
Print ("{0} = ", assignment.Member.Name);
Visit (assignment.Expression);
}
protected override void VisitMemberMemberBinding (MemberMemberBinding binding)
{
Print (binding.Member.Name);
Print (" = {");
// VisitBindingList (binding.Bindings);
VisitList (binding.Bindings, VisitBinding);
Print ("}");
}
protected override void VisitMemberListBinding (MemberListBinding binding)
{
Print (binding.Member.Name);
Print (" = {");
// replace when the patch to the visitor is in
// VisitElementInitializerList (binding.Initializers);
VisitList (binding.Initializers, VisitElementInitializer);
Print ("}");
}
protected override void VisitList<T> (ReadOnlyCollection<T> list, Action<T> visitor)
{
for (int i = 0; i < list.Count; i++) {
if (i > 0)
Print (ListSeparator);
visitor (list [i]);
}
}
protected override void VisitLambda (LambdaExpression lambda)
{
if (lambda.Parameters.Count != 1) {
Print ("(");
// replace when the patch to the visitor is in
// VisitExpressionList (lambda.Parameters);
VisitList (lambda.Parameters, Visit);
Print (")");
} else
Visit (lambda.Parameters [0]);
Print (" => ");
Visit (lambda.Body);
}
protected override void VisitNew (NewExpression nex)
{
Print ("new {0}(", nex.Type.Name);
if (nex.Members != null && nex.Members.Count > 0) {
for (int i = 0; i < nex.Members.Count; i++) {
if (i > 0)
Print (ListSeparator);
Print ("{0} = ", nex.Members [i].Name);
Visit (nex.Arguments [i]);
}
} else
VisitExpressionList (nex.Arguments);
Print (")");
}
protected override void VisitMemberInit (MemberInitExpression init)
{
Visit (init.NewExpression);
Print (" {");
// VisitBindingList (init.Bindings)
VisitList (init.Bindings, VisitBinding);
Print ("}");
}
protected override void VisitListInit (ListInitExpression init)
{
Visit (init.NewExpression);
Print (" {");
// VisitElementInitializerList
VisitList (init.Initializers, VisitElementInitializer);
Print ("}");
}
protected override void VisitNewArray (NewArrayExpression newArray)
{
Print ("new ");
switch (newArray.NodeType) {
case ExpressionType.NewArrayBounds:
Print (newArray.Type);
Print ("(");
VisitExpressionList (newArray.Expressions);
Print (")");
return;
case ExpressionType.NewArrayInit:
Print ("[] {");
VisitExpressionList (newArray.Expressions);
Print ("}");
return;
}
throw new NotSupportedException ();
}
protected override void VisitInvocation (InvocationExpression invocation)
{
Print ("Invoke(");
Visit (invocation.Expression);
if (invocation.Arguments.Count != 0) {
Print (ListSeparator);
VisitExpressionList (invocation.Arguments);
}
Print (")");
}
}
}

View File

@@ -1,79 +0,0 @@
//
// Expression.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Linq.Expressions {
public enum ExpressionType {
Add,
AddChecked,
And,
AndAlso,
ArrayLength,
ArrayIndex,
Call,
Coalesce,
Conditional,
Constant,
Convert,
ConvertChecked,
Divide,
Equal,
ExclusiveOr,
GreaterThan,
GreaterThanOrEqual,
Invoke,
Lambda,
LeftShift,
LessThan,
LessThanOrEqual,
ListInit,
MemberAccess,
MemberInit,
Modulo,
Multiply,
MultiplyChecked,
Negate,
UnaryPlus,
NegateChecked,
New,
NewArrayInit,
NewArrayBounds,
Not,
NotEqual,
Or,
OrElse,
Parameter,
Power,
Quote,
RightShift,
Subtract,
SubtractChecked,
TypeAs,
TypeIs,
}
}

View File

@@ -1,260 +0,0 @@
//
// ExpressionVisitor.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !NET_4_0
using System;
using System.Collections.ObjectModel;
namespace System.Linq.Expressions {
abstract class ExpressionVisitor {
protected virtual void Visit (Expression expression)
{
if (expression == null)
return;
switch (expression.NodeType) {
case ExpressionType.Negate:
case ExpressionType.NegateChecked:
case ExpressionType.Not:
case ExpressionType.Convert:
case ExpressionType.ConvertChecked:
case ExpressionType.ArrayLength:
case ExpressionType.Quote:
case ExpressionType.TypeAs:
case ExpressionType.UnaryPlus:
VisitUnary ((UnaryExpression) expression);
break;
case ExpressionType.Add:
case ExpressionType.AddChecked:
case ExpressionType.Subtract:
case ExpressionType.SubtractChecked:
case ExpressionType.Multiply:
case ExpressionType.MultiplyChecked:
case ExpressionType.Divide:
case ExpressionType.Modulo:
case ExpressionType.Power:
case ExpressionType.And:
case ExpressionType.AndAlso:
case ExpressionType.Or:
case ExpressionType.OrElse:
case ExpressionType.LessThan:
case ExpressionType.LessThanOrEqual:
case ExpressionType.GreaterThan:
case ExpressionType.GreaterThanOrEqual:
case ExpressionType.Equal:
case ExpressionType.NotEqual:
case ExpressionType.Coalesce:
case ExpressionType.ArrayIndex:
case ExpressionType.RightShift:
case ExpressionType.LeftShift:
case ExpressionType.ExclusiveOr:
VisitBinary ((BinaryExpression) expression);
break;
case ExpressionType.TypeIs:
VisitTypeIs ((TypeBinaryExpression) expression);
break;
case ExpressionType.Conditional:
VisitConditional ((ConditionalExpression) expression);
break;
case ExpressionType.Constant:
VisitConstant ((ConstantExpression) expression);
break;
case ExpressionType.Parameter:
VisitParameter ((ParameterExpression) expression);
break;
case ExpressionType.MemberAccess:
VisitMemberAccess ((MemberExpression) expression);
break;
case ExpressionType.Call:
VisitMethodCall ((MethodCallExpression) expression);
break;
case ExpressionType.Lambda:
VisitLambda ((LambdaExpression) expression);
break;
case ExpressionType.New:
VisitNew ((NewExpression) expression);
break;
case ExpressionType.NewArrayInit:
case ExpressionType.NewArrayBounds:
VisitNewArray ((NewArrayExpression) expression);
break;
case ExpressionType.Invoke:
VisitInvocation ((InvocationExpression) expression);
break;
case ExpressionType.MemberInit:
VisitMemberInit ((MemberInitExpression) expression);
break;
case ExpressionType.ListInit:
VisitListInit ((ListInitExpression) expression);
break;
default:
throw new ArgumentException (string.Format ("Unhandled expression type: '{0}'", expression.NodeType));
}
}
protected virtual void VisitBinding (MemberBinding binding)
{
switch (binding.BindingType) {
case MemberBindingType.Assignment:
VisitMemberAssignment ((MemberAssignment) binding);
break;
case MemberBindingType.MemberBinding:
VisitMemberMemberBinding ((MemberMemberBinding) binding);
break;
case MemberBindingType.ListBinding:
VisitMemberListBinding ((MemberListBinding) binding);
break;
default:
throw new ArgumentException (string.Format ("Unhandled binding type '{0}'", binding.BindingType));
}
}
protected virtual void VisitElementInitializer (ElementInit initializer)
{
VisitExpressionList (initializer.Arguments);
}
protected virtual void VisitUnary (UnaryExpression unary)
{
Visit (unary.Operand);
}
protected virtual void VisitBinary (BinaryExpression binary)
{
Visit (binary.Left);
Visit (binary.Right);
Visit (binary.Conversion);
}
protected virtual void VisitTypeIs (TypeBinaryExpression type)
{
Visit (type.Expression);
}
protected virtual void VisitConstant (ConstantExpression constant)
{
}
protected virtual void VisitConditional (ConditionalExpression conditional)
{
Visit (conditional.Test);
Visit (conditional.IfTrue);
Visit (conditional.IfFalse);
}
protected virtual void VisitParameter (ParameterExpression parameter)
{
}
protected virtual void VisitMemberAccess (MemberExpression member)
{
Visit (member.Expression);
}
protected virtual void VisitMethodCall (MethodCallExpression methodCall)
{
Visit (methodCall.Object);
VisitExpressionList (methodCall.Arguments);
}
protected virtual void VisitList<T> (ReadOnlyCollection<T> list, Action<T> visitor)
{
foreach (T element in list) {
visitor (element);
}
}
protected virtual void VisitExpressionList (ReadOnlyCollection<Expression> list)
{
VisitList (list, Visit);
}
protected virtual void VisitMemberAssignment (MemberAssignment assignment)
{
Visit (assignment.Expression);
}
protected virtual void VisitMemberMemberBinding (MemberMemberBinding binding)
{
VisitBindingList (binding.Bindings);
}
protected virtual void VisitMemberListBinding (MemberListBinding binding)
{
VisitElementInitializerList (binding.Initializers);
}
protected virtual void VisitBindingList (ReadOnlyCollection<MemberBinding> list)
{
VisitList (list, VisitBinding);
}
protected virtual void VisitElementInitializerList (ReadOnlyCollection<ElementInit> list)
{
VisitList (list, VisitElementInitializer);
}
protected virtual void VisitLambda (LambdaExpression lambda)
{
Visit (lambda.Body);
}
protected virtual void VisitNew (NewExpression nex)
{
VisitExpressionList (nex.Arguments);
}
protected virtual void VisitMemberInit (MemberInitExpression init)
{
VisitNew (init.NewExpression);
VisitBindingList (init.Bindings);
}
protected virtual void VisitListInit (ListInitExpression init)
{
VisitNew (init.NewExpression);
VisitElementInitializerList (init.Initializers);
}
protected virtual void VisitNewArray (NewArrayExpression newArray)
{
VisitExpressionList (newArray.Expressions);
}
protected virtual void VisitInvocation (InvocationExpression invocation)
{
VisitExpressionList (invocation.Arguments);
Visit (invocation.Expression);
}
}
}
#endif

View File

@@ -1,47 +0,0 @@
//
// Expression_T.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace System.Linq.Expressions {
public sealed class Expression<TDelegate> : LambdaExpression {
internal Expression (Expression body, ReadOnlyCollection<ParameterExpression> parameters)
: base (typeof (TDelegate), body, parameters)
{
}
public new TDelegate Compile ()
{
return (TDelegate) (object) base.Compile ();
}
}
}

View File

@@ -1,63 +0,0 @@
//
// InvocationExpression.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace System.Linq.Expressions {
public sealed class InvocationExpression : Expression {
Expression expression;
ReadOnlyCollection<Expression> arguments;
public Expression Expression {
get { return expression; }
}
public ReadOnlyCollection<Expression> Arguments {
get { return arguments; }
}
internal InvocationExpression (Expression expression, Type type, ReadOnlyCollection<Expression> arguments)
: base (ExpressionType.Invoke, type)
{
this.expression = expression;
this.arguments = arguments;
}
#if !FULL_AOT_RUNTIME
internal override void Emit (EmitContext ec)
{
ec.EmitCall (expression, arguments, expression.Type.GetInvokeMethod ());
}
#endif
}
}

View File

@@ -1,104 +0,0 @@
//
// LambdaExpression.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
// Miguel de Icaza (miguel@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Reflection;
#if !FULL_AOT_RUNTIME
using System.Reflection.Emit;
#endif
namespace System.Linq.Expressions {
public class LambdaExpression : Expression {
Expression body;
ReadOnlyCollection<ParameterExpression> parameters;
public Expression Body {
get { return body; }
}
public ReadOnlyCollection<ParameterExpression> Parameters {
get { return parameters; }
}
internal LambdaExpression (Type delegateType, Expression body, ReadOnlyCollection<ParameterExpression> parameters)
: base (ExpressionType.Lambda, delegateType)
{
this.body = body;
this.parameters = parameters;
}
#if !FULL_AOT_RUNTIME
void EmitPopIfNeeded (EmitContext ec)
{
if (GetReturnType () == typeof (void) && body.Type != typeof (void))
ec.ig.Emit (OpCodes.Pop);
}
internal override void Emit (EmitContext ec)
{
ec.EmitCreateDelegate (this);
}
internal void EmitBody (EmitContext ec)
{
body.Emit (ec);
EmitPopIfNeeded (ec);
ec.ig.Emit (OpCodes.Ret);
}
#endif
internal Type GetReturnType ()
{
return this.Type.GetInvokeMethod ().ReturnType;
}
public Delegate Compile ()
{
#if FULL_AOT_RUNTIME
return new System.Linq.jvm.Runner (this).CreateDelegate ();
#else
var context = new CompilationContext ();
context.AddCompilationUnit (this);
return context.CreateDelegate ();
#endif
}
#if FULL_AOT_RUNTIME
internal Delegate Compile (System.Linq.jvm.ExpressionInterpreter interpreter)
{
return new System.Linq.jvm.Runner (this, interpreter).CreateDelegate ();
}
#endif
}
}

View File

@@ -1,65 +0,0 @@
//
// ListInitExpression.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace System.Linq.Expressions {
public sealed class ListInitExpression : Expression {
NewExpression new_expression;
ReadOnlyCollection<ElementInit> initializers;
public NewExpression NewExpression {
get { return new_expression; }
}
public ReadOnlyCollection<ElementInit> Initializers {
get { return initializers; }
}
internal ListInitExpression (NewExpression new_expression, ReadOnlyCollection<ElementInit> initializers)
: base (ExpressionType.ListInit, new_expression.Type)
{
this.new_expression = new_expression;
this.initializers = initializers;
}
#if !FULL_AOT_RUNTIME
internal override void Emit (EmitContext ec)
{
var local = ec.EmitStored (new_expression);
ec.EmitCollection (initializers, local);
ec.EmitLoad (local);
}
#endif
}
}

View File

@@ -1,79 +0,0 @@
//
// MemberAssignement.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
#if !FULL_AOT_RUNTIME
using System.Reflection.Emit;
#endif
using System.Text;
namespace System.Linq.Expressions {
public sealed class MemberAssignment : MemberBinding {
Expression expression;
public Expression Expression {
get { return expression; }
}
internal MemberAssignment (MemberInfo member, Expression expression)
: base (MemberBindingType.Assignment, member)
{
this.expression = expression;
}
#if !FULL_AOT_RUNTIME
internal override void Emit (EmitContext ec, LocalBuilder local)
{
this.Member.OnFieldOrProperty (
field => EmitFieldAssignment (ec, field, local),
prop => EmitPropertyAssignment (ec, prop, local));
}
void EmitFieldAssignment (EmitContext ec, FieldInfo field, LocalBuilder local)
{
ec.EmitLoadSubject (local);
expression.Emit (ec);
ec.ig.Emit (OpCodes.Stfld, field);
}
void EmitPropertyAssignment (EmitContext ec, PropertyInfo property, LocalBuilder local)
{
var setter = property.GetSetMethod (true);
if (setter == null)
throw new InvalidOperationException ();
ec.EmitLoadSubject (local);
expression.Emit (ec);
ec.EmitCall (setter);
}
#endif
}
}

View File

@@ -1,94 +0,0 @@
//
// MemberBinding.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
#if !FULL_AOT_RUNTIME
using System.Reflection.Emit;
#endif
namespace System.Linq.Expressions {
public abstract class MemberBinding {
MemberBindingType binding_type;
MemberInfo member;
public MemberBindingType BindingType {
get { return binding_type; }
}
public MemberInfo Member {
get { return member; }
}
protected MemberBinding (MemberBindingType binding_type, MemberInfo member)
{
this.binding_type = binding_type;
this.member = member;
}
public override string ToString ()
{
return ExpressionPrinter.ToString (this);
}
#if !FULL_AOT_RUNTIME
internal abstract void Emit (EmitContext ec, LocalBuilder local);
internal LocalBuilder EmitLoadMember (EmitContext ec, LocalBuilder local)
{
ec.EmitLoadSubject (local);
return member.OnFieldOrProperty<LocalBuilder> (
field => EmitLoadField (ec, field),
prop => EmitLoadProperty (ec, prop));
}
LocalBuilder EmitLoadProperty (EmitContext ec, PropertyInfo property)
{
var getter = property.GetGetMethod (true);
if (getter == null)
throw new NotSupportedException ();
var store = ec.ig.DeclareLocal (property.PropertyType);
ec.EmitCall (getter);
ec.ig.Emit (OpCodes.Stloc, store);
return store;
}
LocalBuilder EmitLoadField (EmitContext ec, FieldInfo field)
{
var store = ec.ig.DeclareLocal (field.FieldType);
ec.ig.Emit (OpCodes.Ldfld, field);
ec.ig.Emit (OpCodes.Stloc, store);
return store;
}
#endif
}
}

View File

@@ -1,36 +0,0 @@
//
// MemberBindingType.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Linq.Expressions {
public enum MemberBindingType {
Assignment,
MemberBinding,
ListBinding
}
}

View File

@@ -1,84 +0,0 @@
//
// MemberExpression.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
#if !FULL_AOT_RUNTIME
using System.Reflection.Emit;
#endif
namespace System.Linq.Expressions {
public sealed class MemberExpression : Expression {
Expression expression;
MemberInfo member;
public Expression Expression {
get { return expression; }
}
public MemberInfo Member {
get { return member; }
}
internal MemberExpression (Expression expression, MemberInfo member, Type type)
: base (ExpressionType.MemberAccess, type)
{
this.expression = expression;
this.member = member;
}
#if !FULL_AOT_RUNTIME
internal override void Emit (EmitContext ec)
{
member.OnFieldOrProperty (
field => EmitFieldAccess (ec, field),
prop => EmitPropertyAccess (ec, prop));
}
void EmitPropertyAccess (EmitContext ec, PropertyInfo property)
{
var getter = property.GetGetMethod (true);
if (!getter.IsStatic)
ec.EmitLoadSubject (expression);
ec.EmitCall (getter);
}
void EmitFieldAccess (EmitContext ec, FieldInfo field)
{
if (!field.IsStatic) {
ec.EmitLoadSubject (expression);
ec.ig.Emit (OpCodes.Ldfld, field);
} else
ec.ig.Emit (OpCodes.Ldsfld, field);
}
#endif
}
}

View File

@@ -1,64 +0,0 @@
//
// MemberInitExpression.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// (C) 2008 Novell, Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.ObjectModel;
using System.Reflection;
namespace System.Linq.Expressions {
public sealed class MemberInitExpression : Expression {
NewExpression new_expression;
ReadOnlyCollection<MemberBinding> bindings;
public NewExpression NewExpression {
get { return new_expression; }
}
public ReadOnlyCollection<MemberBinding> Bindings {
get { return bindings; }
}
internal MemberInitExpression (NewExpression new_expression, ReadOnlyCollection<MemberBinding> bindings)
: base (ExpressionType.MemberInit, new_expression.Type)
{
this.new_expression = new_expression;
this.bindings = bindings;
}
#if !FULL_AOT_RUNTIME
internal override void Emit (EmitContext ec)
{
var local = ec.EmitStored (new_expression);
ec.EmitCollection (bindings, local);
ec.EmitLoad (local);
}
#endif
}
}

Some files were not shown because too many files have changed in this diff Show More