diff options
author | qadeer <qadeer@microsoft.com> | 2011-07-27 10:56:44 -0700 |
---|---|---|
committer | qadeer <qadeer@microsoft.com> | 2011-07-27 10:56:44 -0700 |
commit | 9a0058c715d945d29fc8ce1229f27283f02583c7 (patch) | |
tree | 96ca65f7416272a3fa6d5201090443a0f2534ab3 /BCT | |
parent | 9f5c8a04f53263df20b29711cbe3d35d21919268 (diff) |
fixed bug in constant translation
Diffstat (limited to 'BCT')
-rw-r--r-- | BCT/BytecodeTranslator/ExpressionTraverser.cs | 69 |
1 files changed, 40 insertions, 29 deletions
diff --git a/BCT/BytecodeTranslator/ExpressionTraverser.cs b/BCT/BytecodeTranslator/ExpressionTraverser.cs index 0f7ee250..34f55fd9 100644 --- a/BCT/BytecodeTranslator/ExpressionTraverser.cs +++ b/BCT/BytecodeTranslator/ExpressionTraverser.cs @@ -319,6 +319,12 @@ namespace BytecodeTranslator TranslatedExpressions.Push(Bpl.Expr.Ident(c));
return;
}
+ if (constant.Type.IsEnum) {
+ var lit = Bpl.Expr.Literal((int)constant.Value);
+ lit.Type = Bpl.Type.Int;
+ TranslatedExpressions.Push(lit);
+ return;
+ }
switch (constant.Type.TypeCode) {
case PrimitiveTypeCode.Boolean:
// Decompiler might not have converted the constant back to a boolean? Not sure why,
@@ -331,46 +337,51 @@ namespace BytecodeTranslator break;
case PrimitiveTypeCode.Char: // chars are represented as ints
case PrimitiveTypeCode.Int8:
- 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:
+ case PrimitiveTypeCode.Int16: {
+ var lit = Bpl.Expr.Literal((short)constant.Value);
+ lit.Type = Bpl.Type.Int;
+ TranslatedExpressions.Push(lit);
+ break;
+ }
+ case PrimitiveTypeCode.Int32: {
+ var lit = Bpl.Expr.Literal((int)constant.Value);
+ lit.Type = Bpl.Type.Int;
+ TranslatedExpressions.Push(lit);
+ break;
+ }
+ case PrimitiveTypeCode.Int64: {
+ var lit = Bpl.Expr.Literal(Microsoft.Basetypes.BigNum.FromLong((long)constant.Value));
+ lit.Type = Bpl.Type.Int;
+ TranslatedExpressions.Push(lit);
+ break;
+ }
case PrimitiveTypeCode.UInt8:
- lit = Bpl.Expr.Literal((int)(uint)constant.Value);
- lit.Type = Bpl.Type.Int;
- TranslatedExpressions.Push(lit);
- break;
+ case PrimitiveTypeCode.UInt16:
+ case PrimitiveTypeCode.UInt32: {
+ var lit = Bpl.Expr.Literal((int)(uint)constant.Value);
+ lit.Type = Bpl.Type.Int;
+ TranslatedExpressions.Push(lit);
+ break;
+ }
+ case PrimitiveTypeCode.UInt64: {
+ var lit = Bpl.Expr.Literal(Microsoft.Basetypes.BigNum.FromULong((ulong)constant.Value));
+ lit.Type = Bpl.Type.Int;
+ TranslatedExpressions.Push(lit);
+ break;
+ }
case PrimitiveTypeCode.Float32: {
var c = this.sink.FindOrCreateConstant((float)(constant.Value));
TranslatedExpressions.Push(Bpl.Expr.Ident(c));
- return;
+ break;
}
case PrimitiveTypeCode.Float64: {
var c = this.sink.FindOrCreateConstant((double)(constant.Value));
TranslatedExpressions.Push(Bpl.Expr.Ident(c));
- return;
- }
- case PrimitiveTypeCode.NotPrimitive:
- if (constant.Type.IsEnum) {
- lit = Bpl.Expr.Literal((int)constant.Value);
- lit.Type = Bpl.Type.Int;
- TranslatedExpressions.Push(lit);
- return;
+ break;
}
+ default:
throw new NotImplementedException(String.Format("Can't translate compile-time constant of type '{0}'",
TypeHelper.GetTypeName(constant.Type)));
- default:
- throw new NotImplementedException();
}
return;
}
|