Skip to content

Commit

Permalink
Encode correctly all constants into a payload
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-safar committed Sep 15, 2010
1 parent 7de7347 commit 55bd1d4
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 121 deletions.
5 changes: 2 additions & 3 deletions mcs/mcs/argument.cs
Expand Up @@ -238,8 +238,7 @@ public ArrayInitializer CreateDynamicBinderArguments (ResolveContext rc)
const string info_flags_enum = "CSharpArgumentInfoFlags";
Expression info_flags = new IntLiteral (0, loc);

var constant = a.Expr as Constant;
if (constant != null && constant.IsLiteral) {
if (a.Expr is Constant) {
info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "Constant", loc), loc);
} else if (a.ArgType == Argument.AType.Ref) {
Expand All @@ -255,7 +254,7 @@ public ArrayInitializer CreateDynamicBinderArguments (ResolveContext rc)

var arg_type = a.Expr.Type;

if (arg_type != InternalType.Dynamic) {
if (arg_type != InternalType.Dynamic && arg_type != InternalType.Null) {
MethodGroupExpr mg = a.Expr as MethodGroupExpr;
if (mg != null) {
rc.Report.Error (1976, a.Expr.Location,
Expand Down
75 changes: 36 additions & 39 deletions mcs/tests/dtest-003.cs
Expand Up @@ -260,7 +260,7 @@ void BinaryAdd_3 (dynamic d, DynamicObjectMock mock)
Assert (binder.Operation, ExpressionType.Add, "Operation");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType, null)
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
}, "ArgumentInfo");
Assert (arg, Enum.A, "arg");
Expand Down Expand Up @@ -738,7 +738,7 @@ void Convert_3 (dynamic d, DynamicObjectMock mock)
{
mock.ConvertOperation = (binder) => {
Assert (binder.Explicit, true, "Explicit");
// Assert (binder.IsChecked, true, "IsChecked");
// Assert (binder.IsChecked, true, "IsChecked");
Assert (binder.Type, typeof (byte), "Type");
return (byte) 2;
};
Expand Down Expand Up @@ -767,15 +767,14 @@ void Convert_5 (dynamic d, DynamicObjectMock mock)
};

foreach (int v in d) {
// Console.WriteLine (v);
// Console.WriteLine (v);
}
}

void GetIndex_1 (dynamic d, DynamicObjectMock mock)
{
mock.GetIndexOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (1, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null) },
Expand All @@ -791,7 +790,6 @@ void GetIndex_2 (dynamic d, DynamicObjectMock mock)
{
mock.GetIndexOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (2, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null),
Expand All @@ -809,7 +807,6 @@ void GetIndex_3 (dynamic d, DynamicObjectMock mock)
{
mock.GetIndexOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (1, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null) },
Expand All @@ -826,7 +823,6 @@ void GetMember_1 (dynamic d, DynamicObjectMock mock)
mock.GetMemberOperation = (binder) => {
Assert (binder.Name, "Foo", "Name");
Assert (binder.IgnoreCase, false, "IgnoreCase");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null) },
"ArgumentInfo");
Expand All @@ -839,11 +835,10 @@ void Invoke_1 (dynamic d, DynamicObjectMock mock)
{
mock.InvokeOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (2, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null)
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant, null)
}, "ArgumentInfo");
Assert ((IList<object>) args, new object[] { "foo", null }, "args");
Expand All @@ -856,7 +851,6 @@ void Invoke_2 (dynamic d, DynamicObjectMock mock)
{
mock.InvokeOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (0, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null) },
"ArgumentInfo");
Expand All @@ -866,7 +860,7 @@ void Invoke_2 (dynamic d, DynamicObjectMock mock)

d ();
}

void Invoke_3 (dynamic d, DynamicObjectMock mock)
{
try {
Expand All @@ -880,11 +874,10 @@ void Invoke_4 (dynamic d, DynamicObjectMock mock)
{
mock.InvokeOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (2, new string[] { "name" }), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.NamedArgument | CSharpArgumentInfoFlags.UseCompileTimeType, "name")
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.NamedArgument | CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, "name")
}, "ArgumentInfo");
Assert ((IList<object>) args, new object[] { typeof (bool), -1 }, "args");
Expand All @@ -896,25 +889,38 @@ void Invoke_4 (dynamic d, DynamicObjectMock mock)
void Invoke_5 (dynamic d, DynamicObjectMock mock)
{
mock.InvokeOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (2, new string[] { "name" }), "CallInfo");
Assert (binder.CallInfo, new CallInfo (1, new string[0]), "CallInfo");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.NamedArgument | CSharpArgumentInfoFlags.UseCompileTimeType, "name")
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
}, "ArgumentInfo");
Assert ((IList<object>) args, new object[] { typeof (bool), -1 }, "args");
Assert ((IList<object>) args, new object[] { "a" }, "args");
};

Action<object> a = (i) => { };
Action<dynamic> a = (i) => { i ("a"); };
a (d);
}

void Invoke_6 (dynamic d, DynamicObjectMock mock)
{
mock.InvokeOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (1, new string[0]), "CallInfo");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
}, "ArgumentInfo");
Assert ((IList<object>) args, new object[] { 3 }, "args");
};

d (1 + 2);
}

void InvokeMember_1 (dynamic d, DynamicObjectMock mock)
{
mock.InvokeMemberOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (1, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null)},
Expand All @@ -934,7 +940,6 @@ void InvokeMember_2 (dynamic d, DynamicObjectMock mock)
{
mock.InvokeMemberOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (1, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null)},
Expand All @@ -954,15 +959,14 @@ void InvokeMember_3 (dynamic d, DynamicObjectMock mock)
{
mock.InvokeMemberOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (1, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.IsRef | CSharpArgumentInfoFlags.UseCompileTimeType, null) },
"ArgumentInfo");
// Assert (binder.Flags, CSharpCallFlags.None, "Flags");
// Assert (binder.Flags, CSharpCallFlags.None, "Flags");
Assert (binder.IgnoreCase, false, "IgnoreCase");
// Assert (binder.TypeArguments, new Type[0], "TypeArguments");
// Assert (binder.TypeArguments, new Type[0], "TypeArguments");
Assert ((IList<object>) args, new object[] { 9 }, "args");
};
Expand All @@ -975,7 +979,6 @@ void InvokeMember_4 (dynamic d, DynamicObjectMock mock)
{
mock.InvokeMemberOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (1, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.IsOut | CSharpArgumentInfoFlags.UseCompileTimeType, null) },
Expand All @@ -1001,15 +1004,14 @@ void InvokeMember_6 (dynamic d, DynamicObjectMock mock)
{
InvokeMemberOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (2, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant, null),
}, "ArgumentInfo");
// Assert (binder.Flags, CSharpCallFlags.SimpleNameCall, "Flags");
// Assert (binder.Flags, CSharpCallFlags.SimpleNameCall, "Flags");
Assert (binder.IgnoreCase, false, "IgnoreCase");
// Assert (binder.TypeArguments, Type.EmptyTypes, "TypeArguments");
// Assert (binder.TypeArguments, Type.EmptyTypes, "TypeArguments");
Assert ((IList<object>) args, new object[] { d, null }, "args");
};
Expand All @@ -1021,7 +1023,6 @@ void InvokeMember_7 (dynamic d, DynamicObjectMock mock)
{
mock.InvokeMemberOperation = (binder, args) => {
Assert (binder.CallInfo, new CallInfo (0, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null)
}, "ArgumentInfo");
Expand All @@ -1039,7 +1040,6 @@ void SetIndex_1 (dynamic d, DynamicObjectMock mock)
{
mock.SetIndexOperation = (binder, args, value) => {
Assert (binder.CallInfo, new CallInfo (1, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null),
Expand All @@ -1057,12 +1057,11 @@ void SetIndex_2 (dynamic d, DynamicObjectMock mock)
{
mock.SetIndexOperation = (binder, args, value) => {
Assert (binder.CallInfo, new CallInfo (2, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType, null)
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null)
}, "ArgumentInfo");
Assert ((IList<object>) args, new object[] { 2, 3 }, "args");
Expand All @@ -1077,7 +1076,6 @@ void SetIndex_3 (dynamic d, DynamicObjectMock mock)
{
mock.SetIndexOperation = (binder, args, value) => {
Assert (binder.CallInfo, new CallInfo (1, new string[0]), "CallInfo");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
Expand All @@ -1098,10 +1096,9 @@ void SetMember_1 (dynamic d, DynamicObjectMock mock)
mock.SetMemberOperation = (binder, value) => {
Assert (binder.Name, "Foo", "Name");
Assert (binder.IgnoreCase, false, "IgnoreCase");
// Assert (binder.CallingContext, typeof (Tester), "CallingContext");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType, null) // Not a literal because we got the type
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
}, "ArgumentInfo");
Assert (value, d_const, "value");
Expand Down Expand Up @@ -1237,7 +1234,7 @@ void UnaryIsFalse_1 (dynamic d, DynamicObjectMock mock)
Assert (binder.Operation, ExpressionType.Equal, "Operation");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null) },
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant, null) },
"ArgumentInfo");
Assert (arg, null, "arg");
Expand All @@ -1261,7 +1258,7 @@ void UnaryIsFalse_2 (dynamic d, DynamicObjectMock mock)
Assert (binder.Operation, ExpressionType.NotEqual, "Operation");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null) },
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant, null) },
"ArgumentInfo");
Assert (arg, null, "arg");
Expand All @@ -1285,7 +1282,7 @@ void UnaryIsFalse_3 (dynamic d, DynamicObjectMock mock)
Assert (binder.Operation, ExpressionType.And, "Operation");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null) },
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant, null) },
"ArgumentInfo");
Assert (arg, null, "arg");
Expand Down Expand Up @@ -1323,7 +1320,7 @@ void UnaryIsTrue_2 (dynamic d, DynamicObjectMock mock)
Assert (binder.Operation, ExpressionType.Or, "Operation");
AssertArgument (binder, new[] {
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null) },
CSharpArgumentInfo.Create (CSharpArgumentInfoFlags.Constant, null) },
"ArgumentInfo");
Assert (arg, null, "arg");
Expand Down

0 comments on commit 55bd1d4

Please sign in to comment.