Skip to content

Commit b1d6064

Browse files
authored
Merge pull request #19 from JiajunW/nativerpc
Support 64bit pointer
2 parents 65fd6c5 + 171f0d0 commit b1d6064

File tree

4 files changed

+56
-40
lines changed

4 files changed

+56
-40
lines changed

src/testtools.messages.runtime/RuntimeMarshaler.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ public bool UseSpaceChecking
560560
/// <param name="symbol">The symbol to be resolved</param>
561561
/// <param name="value">The value corresponding to the symbol</param>
562562
/// <returns>Returns true if the symbol is defined and has a value</returns>
563-
public bool TryResolveSymbol(string symbol, out int value)
563+
public bool TryResolveSymbol(string symbol, out long value)
564564
{
565565
if (symbolStore != null)
566566
{
@@ -574,15 +574,14 @@ public bool TryResolveSymbol(string symbol, out int value)
574574
}
575575
else if (valueObj is IntPtr)
576576
{
577-
value = ((IntPtr)valueObj).ToInt32();
577+
value = ((IntPtr)valueObj).ToInt64();
578578
return true;
579579
}
580580
else
581581
{
582582
try
583583
{
584-
long temp = Convert.ToInt64(valueObj);
585-
value = (int)temp;
584+
value = Convert.ToInt64(valueObj);
586585

587586
return true;
588587
}
@@ -1004,7 +1003,16 @@ public void WriteInt64(long value)
10041003
public void WriteIntPtr(IntPtr value)
10051004
{
10061005
if (tracing)
1007-
Trace("writing @0x{0:x4}", value);
1006+
{
1007+
if (IntPtr.Size == sizeof(Int32))
1008+
{
1009+
Trace("writing @0x{0:x8}", value);
1010+
}
1011+
else if (IntPtr.Size == sizeof(Int64))
1012+
{
1013+
Trace("writing @0x{0:x16}", value);
1014+
}
1015+
}
10081016
region.WriteIntPtr(value);
10091017
}
10101018

@@ -1104,7 +1112,16 @@ public IntPtr ReadIntPtr()
11041112
{
11051113
IntPtr r = region.ReadIntPtr();
11061114
if (tracing)
1107-
Trace("reading @0x{0:x4}", r);
1115+
{
1116+
if (IntPtr.Size == sizeof(Int32))
1117+
{
1118+
Trace("reading @0x{0:x8}", r);
1119+
}
1120+
else if (IntPtr.Size == sizeof(Int64))
1121+
{
1122+
Trace("reading @0x{0:x16}", r);
1123+
}
1124+
}
11081125
return r;
11091126
}
11101127

@@ -1591,7 +1608,7 @@ public int Evaluate(string expression)
15911608
IList<object> result = evaluator.Evaluate();
15921609
if (result.Count != 1 || result[0] == null)
15931610
TestAssertFail("expected exactly one expression in attribute '{0}'", expression);
1594-
return (int)result[0];
1611+
return Convert.ToInt32(result[0]);
15951612
}
15961613

15971614
/// <summary>
@@ -1609,7 +1626,7 @@ public int Evaluate(string expression)
16091626
IList<int?> intResult = new List<int?>();
16101627
foreach (object s in result)
16111628
{
1612-
intResult.Add(s as int?);
1629+
intResult.Add((int?)(s as long?));
16131630
}
16141631
return intResult;
16151632
}
@@ -1637,7 +1654,7 @@ public void ReportError(string message)
16371654
IList<int?> intResult = new List<int?>();
16381655
foreach (object s in result)
16391656
{
1640-
intResult.Add(s as int?);
1657+
intResult.Add((int?)(s as long?));
16411658
}
16421659
return intResult;
16431660
}

src/testtools.messages.runtime/messagecommon/ExpressionParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ protected ExpressionNode Literal()
460460
}
461461
else if (currentToken.Type == TokenType.String)
462462
{
463-
int x;
463+
long x;
464464

465465
if (!context.TryResolveSymbol(currentToken.Text, out x))
466466
{

src/testtools.messages.runtime/messagecommon/ExpressionVisitor.cs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -116,65 +116,65 @@ public void Visit(BinaryExpression expression)
116116
expression.RightExpression.Accept(this);
117117
object right = result;
118118

119-
if (left is int && right is int)
119+
if (left is long && right is long)
120120
{
121121
switch (expression.Type)
122122
{
123123
case BinaryExpressionType.Plus:
124-
result = Convert.ToInt32(left) + Convert.ToInt32(right);
124+
result = Convert.ToInt64(left) + Convert.ToInt64(right);
125125
break;
126126
case BinaryExpressionType.Minus:
127-
result = Convert.ToInt32(left) - Convert.ToInt32(right);
127+
result = Convert.ToInt64(left) - Convert.ToInt64(right);
128128
break;
129129
case BinaryExpressionType.Multiply:
130-
result = Convert.ToInt32(left) * Convert.ToInt32(right);
130+
result = Convert.ToInt64(left) * Convert.ToInt64(right);
131131
break;
132132
case BinaryExpressionType.Div:
133-
result = Convert.ToInt32(left) / Convert.ToInt32(right);
133+
result = Convert.ToInt64(left) / Convert.ToInt64(right);
134134
break;
135135
case BinaryExpressionType.Mod:
136-
result = Convert.ToInt32(left) % Convert.ToInt32(right);
136+
result = Convert.ToInt64(left) % Convert.ToInt64(right);
137137
break;
138138
case BinaryExpressionType.ShiftLeft:
139-
result = Convert.ToInt32(left) << Convert.ToInt32(right);
139+
result = Convert.ToInt64(left) << Convert.ToInt32(right);
140140
break;
141141
case BinaryExpressionType.ShiftRight:
142-
result = Convert.ToInt32(left) >> Convert.ToInt32(right);
142+
result = Convert.ToInt64(left) >> Convert.ToInt32(right);
143143
break;
144144
case BinaryExpressionType.GreaterOrEqual:
145-
result = (Convert.ToInt32(left) >= Convert.ToInt32(right)) ? 1 : 0;
145+
result = (Convert.ToInt64(left) >= Convert.ToInt64(right)) ? 1 : 0;
146146
break;
147147
case BinaryExpressionType.LesserOrEqual:
148-
result = (Convert.ToInt32(left) <= Convert.ToInt32(right)) ? 1 : 0;
148+
result = (Convert.ToInt64(left) <= Convert.ToInt64(right)) ? 1 : 0;
149149
break;
150150
case BinaryExpressionType.Greater:
151-
result = (Convert.ToInt32(left) > Convert.ToInt32(right)) ? 1 : 0;
151+
result = (Convert.ToInt64(left) > Convert.ToInt64(right)) ? 1 : 0;
152152
break;
153153
case BinaryExpressionType.Lesser:
154-
result = (Convert.ToInt32(left) < Convert.ToInt32(right)) ? 1 : 0;
154+
result = (Convert.ToInt64(left) < Convert.ToInt64(right)) ? 1 : 0;
155155
break;
156156
case BinaryExpressionType.Equal:
157-
result = (Convert.ToInt32(left) == Convert.ToInt32(right)) ? 1 : 0;
157+
result = (Convert.ToInt64(left) == Convert.ToInt64(right)) ? 1 : 0;
158158
break;
159159
case BinaryExpressionType.NotEqual:
160-
result = (Convert.ToInt32(left) != Convert.ToInt32(right)) ? 1 : 0;
160+
result = (Convert.ToInt64(left) != Convert.ToInt64(right)) ? 1 : 0;
161161
break;
162162
case BinaryExpressionType.BitXor:
163-
result = Convert.ToInt32(left) ^ Convert.ToInt32(right);
163+
result = Convert.ToInt64(left) ^ Convert.ToInt64(right);
164164
break;
165165
case BinaryExpressionType.BitAnd:
166-
result = Convert.ToInt32(left) & Convert.ToInt32(right);
166+
result = Convert.ToInt64(left) & Convert.ToInt64(right);
167167
break;
168168
case BinaryExpressionType.BitOr:
169-
result = Convert.ToInt32(left) | Convert.ToInt32(right);
169+
result = Convert.ToInt64(left) | Convert.ToInt64(right);
170170
break;
171171
case BinaryExpressionType.And:
172172
bool andResult = Convert.ToBoolean(left) && Convert.ToBoolean(right);
173-
result = Convert.ToInt32(andResult);
173+
result = Convert.ToInt64(andResult);
174174
break;
175175
case BinaryExpressionType.Or:
176176
bool orResult = Convert.ToBoolean(left) || Convert.ToBoolean(right);
177-
result = Convert.ToInt32(orResult);
177+
result = Convert.ToInt64(orResult);
178178
break;
179179
default:
180180
throw new ExpressionEvaluatorException(
@@ -205,10 +205,10 @@ public void Visit(ValueExpression expression)
205205
switch (expression.Type)
206206
{
207207
case ValueExpressionType.Integer:
208-
result = int.Parse(expression.Text);
208+
result = long.Parse(expression.Text);
209209
break;
210210
case ValueExpressionType.Variable:
211-
int value;
211+
long value;
212212
int dereferencedValue;
213213
int pointerValue;
214214
if (context.TryResolveSymbol(expression.Text, out value))
@@ -258,7 +258,7 @@ public void Visit(FunctionExpression expression)
258258
if (expression.FunctionName == "sizeof")
259259
{
260260
string customTypeName;
261-
int symbolValue;
261+
long symbolValue;
262262
if (param is string)
263263
{
264264
if ((context.TryResolveCustomType((string)param, out customTypeName)
@@ -301,8 +301,8 @@ public void Visit(FunctionExpression expression)
301301

302302
result = DatatypeInfoProvider.GetRpcDatatypeLength(typeName);
303303
}
304-
if (result is int
305-
&& (int)result <= 0)
304+
if (result is long
305+
&& (long)result <= 0)
306306
{
307307
throw new ExpressionEvaluatorException(
308308
String.Format("cannot get the datatype length for the datatype '{0}'", param));
@@ -323,9 +323,9 @@ public void Visit(UnaryExpression expression)
323323
}
324324

325325
expression.Expression.Accept(this);
326-
if (result is int)
326+
if (result is long)
327327
{
328-
int param = (int)result;
328+
long param = (long)result;
329329
switch (expression.Type)
330330
{
331331
case UnaryExpressionType.Not:
@@ -356,7 +356,6 @@ public void Visit(UnaryExpression expression)
356356
else
357357
{
358358
IntPtr p = new IntPtr(param);
359-
// only supports 32bit pointer here. To support 64bit, too much work to do
360359
result = System.Runtime.InteropServices.Marshal.ReadInt32(p);
361360
}
362361
break;
@@ -385,9 +384,9 @@ public void Visit(ConditionalExpression expression)
385384
expression.FirstExpression.Accept(this);
386385
object first = result;
387386

388-
if (first is int)
387+
if (first is long)
389388
{
390-
if (Convert.ToBoolean((int)first))
389+
if (Convert.ToBoolean((long)first))
391390
{
392391
expression.SecondExpression.Accept(this);
393392
}

src/testtools.messages.runtime/messagecommon/IEvaluationContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface IEvaluationContext
1818
/// <param name="symbol">The symbol to be resolved</param>
1919
/// <param name="value">The value</param>
2020
/// <returns>Returns true if it resolves the symbol successfully.</returns>
21-
bool TryResolveSymbol(string symbol, out int value);
21+
bool TryResolveSymbol(string symbol, out long value);
2222

2323
/// <summary>
2424
/// Tries to resolve a custom type.

0 commit comments

Comments
 (0)