summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar qadeer <qadeer@microsoft.com>2011-06-10 09:11:04 -0700
committerGravatar qadeer <qadeer@microsoft.com>2011-06-10 09:11:04 -0700
commita7f87b4c259d61dd14008328fb7861d5c5a7223e (patch)
treedd4dd916a10315b8f6b7dea7a06e6668c166e1fa
parente8f2d0713f40066bc153cc351e50a400fcb9248b (diff)
parent784a683b04ac390c1660a714e82720a172c5af1b (diff)
Merge
-rw-r--r--BCT/BytecodeTranslator/ExpressionTraverser.cs30
-rw-r--r--BCT/BytecodeTranslator/MetadataTraverser.cs34
-rw-r--r--BCT/BytecodeTranslator/Sink.cs4
3 files changed, 39 insertions, 29 deletions
diff --git a/BCT/BytecodeTranslator/ExpressionTraverser.cs b/BCT/BytecodeTranslator/ExpressionTraverser.cs
index 69841178..000071d9 100644
--- a/BCT/BytecodeTranslator/ExpressionTraverser.cs
+++ b/BCT/BytecodeTranslator/ExpressionTraverser.cs
@@ -338,14 +338,18 @@ namespace BytecodeTranslator
}
break;
case PrimitiveTypeCode.Char: // chars are represented as ints
- case PrimitiveTypeCode.Int16:
- case PrimitiveTypeCode.Int32:
- case PrimitiveTypeCode.Int64:
case PrimitiveTypeCode.Int8:
- var lit = Bpl.Expr.Literal((int)constant.Value);
+ case PrimitiveTypeCode.Int16:
+ var lit = Bpl.Expr.Literal((short)constant.Value);
lit.Type = Bpl.Type.Int;
TranslatedExpressions.Push(lit);
break;
+ case PrimitiveTypeCode.Int32:
+ case PrimitiveTypeCode.Int64:
+ var lit2 = Bpl.Expr.Literal((int)constant.Value);
+ lit2.Type = Bpl.Type.Int;
+ TranslatedExpressions.Push(lit2);
+ break;
case PrimitiveTypeCode.UInt16:
case PrimitiveTypeCode.UInt32:
case PrimitiveTypeCode.UInt64:
@@ -486,11 +490,6 @@ namespace BytecodeTranslator
// So this code is the same as Visit(ICreateObjectInstance)
// TODO: factor the code into a single method?
- var addrOf = methodCall.ThisArgument as IAddressOf;
- var ae = addrOf.Expression as IAddressableExpression;
- var local = ae.Definition as ILocalDefinition;
- var s = this.sink.CreateFreshLocal(local.Type);
-
// First generate an Alloc() call
this.StmtTraverser.StmtBuilder.Add(new Bpl.CallCmd(methodCallToken, this.sink.AllocationMethodName, new Bpl.ExprSeq(), new Bpl.IdentifierExprSeq(thisExpr)));
@@ -502,7 +501,7 @@ namespace BytecodeTranslator
new Bpl.AssumeCmd(methodCallToken,
Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Eq,
this.sink.Heap.DynamicType(thisExpr),
- this.sink.FindOrCreateType(resolvedMethod.ContainingTypeDefinition)
+ this.sink.FindOrCreateType(methodCall.MethodToCall.ResolvedMethod.ContainingTypeDefinition)
)
)
);
@@ -531,8 +530,8 @@ namespace BytecodeTranslator
inexpr[0] = Bpl.Expr.Ident(local);
}
- System.Diagnostics.Debug.Assert(outvars.Count == 0);
- outvars.Add(Bpl.Expr.Ident(local));
+ System.Diagnostics.Debug.Assert(outvars.Count == 1);
+ outvars.Insert(0, Bpl.Expr.Ident(local));
string methodName = isEventAdd ? this.sink.DelegateAddName : this.sink.DelegateRemoveName;
call = new Bpl.CallCmd(methodCallToken, methodName, inexpr, outvars);
this.StmtTraverser.StmtBuilder.Add(call);
@@ -652,7 +651,7 @@ namespace BytecodeTranslator
}
TranslatedExpressions.Push(unboxed);
}
- outvars.Add(Bpl.Expr.Ident(procInfo.ExcVariable));
+ outvars.Add(Bpl.Expr.Ident(this.sink.ExcVariable));
}
return procInfo.Decl;
@@ -780,6 +779,11 @@ namespace BytecodeTranslator
TranslateAssignment(tok, be.Definition, be.Instance, source);
return;
}
+ var ao = popValue as IAddressOf;
+ if (ao != null) {
+ TranslateAssignment(tok, ao.Expression.Definition, ao.Expression.Instance, source);
+ return;
+ }
}
var be2 = addressDereference.Address as IBoundExpression;
if (be2 != null) {
diff --git a/BCT/BytecodeTranslator/MetadataTraverser.cs b/BCT/BytecodeTranslator/MetadataTraverser.cs
index f133e85c..32700349 100644
--- a/BCT/BytecodeTranslator/MetadataTraverser.cs
+++ b/BCT/BytecodeTranslator/MetadataTraverser.cs
@@ -324,20 +324,26 @@ namespace BytecodeTranslator {
var mdc = c as IMetadataConstant;
if (mdc != null) {
object o;
- switch (mdc.Type.TypeCode) {
- case PrimitiveTypeCode.Boolean:
- o = (bool)mdc.Value ? Bpl.Expr.True : Bpl.Expr.False;
- break;
- case PrimitiveTypeCode.Int32:
- var lit = Bpl.Expr.Literal((int)mdc.Value);
- lit.Type = Bpl.Type.Int;
- o = lit;
- break;
- case PrimitiveTypeCode.String:
- o = mdc.Value;
- break;
- default:
- throw new InvalidCastException("Invalid metadata constant type");
+ if (mdc.Type.IsEnum) {
+ var lit = Bpl.Expr.Literal((int) mdc.Value);
+ lit.Type = Bpl.Type.Int;
+ o = lit;
+ } else {
+ switch (mdc.Type.TypeCode) {
+ case PrimitiveTypeCode.Boolean:
+ o = (bool) mdc.Value ? Bpl.Expr.True : Bpl.Expr.False;
+ break;
+ case PrimitiveTypeCode.Int32:
+ var lit = Bpl.Expr.Literal((int) mdc.Value);
+ lit.Type = Bpl.Type.Int;
+ o = lit;
+ break;
+ case PrimitiveTypeCode.String:
+ o = mdc.Value;
+ break;
+ default:
+ throw new InvalidCastException("Invalid metadata constant type");
+ }
}
args[argIndex++] = o;
}
diff --git a/BCT/BytecodeTranslator/Sink.cs b/BCT/BytecodeTranslator/Sink.cs
index 951c791a..2bf5db9d 100644
--- a/BCT/BytecodeTranslator/Sink.cs
+++ b/BCT/BytecodeTranslator/Sink.cs
@@ -817,7 +817,7 @@ namespace BytecodeTranslator {
IGenericMethodParameter gmp = type as IGenericMethodParameter;
if (gmp != null) {
ProcedureInfo info = FindOrCreateProcedure(methodBeingTranslated);
- return Bpl.Expr.Ident(info.TypeParameter(gmp.Index));
+ return Bpl.Expr.Ident(info.MethodParameter(gmp.Index));
}
ITypeReference uninstantiatedGenericType = GetUninstantiatedGenericType(type);
@@ -915,7 +915,7 @@ namespace BytecodeTranslator {
/// The values in this table are the procedures
/// defined in the program created by the heap in the Sink's ctor.
/// </summary>
- private Dictionary<string, ProcedureInfo> initiallyDeclaredProcedures = new Dictionary<string, ProcedureInfo>();
+ public Dictionary<string, ProcedureInfo> initiallyDeclaredProcedures = new Dictionary<string, ProcedureInfo>();
public void BeginMethod(ITypeReference containingType) {
this.localVarMap = new Dictionary<ILocalDefinition, Bpl.LocalVariable>();