Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

Commit 1ed796b

Browse files
committed
Merge pull request #873 from iskiselev/DecimalLiterals
Create decimal literals through decimal constructor.
2 parents 0a33194 + 5fdc4fc commit 1ed796b

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

JSIL/AST/JSLiteralTypes.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,20 @@ select em
244244
}
245245
}
246246

247+
public class JSDecimalLiteral : JSLiteralBase<Decimal>
248+
{
249+
public JSDecimalLiteral(decimal value)
250+
: base(value)
251+
{
252+
}
253+
254+
public override TypeReference GetActualType(TypeSystem typeSystem)
255+
{
256+
return new TypeReference(typeSystem.Double.Namespace, "Decimal", typeSystem.Double.Module,
257+
typeSystem.Double.Scope, true);
258+
}
259+
}
260+
247261
public class JSNumberLiteral : JSLiteralBase<double> {
248262
public readonly Type OriginalType;
249263

@@ -260,8 +274,6 @@ public override TypeReference GetActualType (TypeSystem typeSystem) {
260274
return typeSystem.Single;
261275
case "System.Double":
262276
return typeSystem.Double;
263-
case "System.Decimal":
264-
return new TypeReference(typeSystem.Double.Namespace, "Decimal", typeSystem.Double.Module, typeSystem.Double.Scope, true);
265277
default:
266278
throw new NotImplementedException(String.Format(
267279
"Unsupported number literal type: {0}",

JSIL/AST/JSNodeTypes.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ public static JSNumberLiteral New (double value) {
494494
return new JSNumberLiteral(value, typeof(double));
495495
}
496496

497-
public static JSNumberLiteral New (decimal value) {
498-
return new JSNumberLiteral((double)value, typeof(decimal));
497+
public static JSDecimalLiteral New (decimal value) {
498+
return new JSDecimalLiteral(value);
499499
}
500500

501501
public static JSDefaultValueLiteral DefaultValue (TypeReference type) {

JSIL/JavascriptAstEmitter.cs

+5
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,11 @@ public void VisitNode (JSNumberLiteral number) {
992992
}
993993
}
994994

995+
public void VisitNode(JSDecimalLiteral number)
996+
{
997+
VisitNode(new JSNewExpression(number.GetActualType(TypeSystem), null, null, JSLiteral.New((double) number.Value)));
998+
}
999+
9951000
public void VisitNode (JSBooleanLiteral b) {
9961001
Output.Value(b.Value);
9971002
}

0 commit comments

Comments
 (0)