Skip to content

Commit

Permalink
Create decimal literals through decimal constructor (sq#871).
Browse files Browse the repository at this point in the history
  • Loading branch information
iskiselev committed Oct 16, 2015
1 parent 46ac870 commit 5fdc4fc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 14 additions & 2 deletions JSIL/AST/JSLiteralTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ select em
}
}

public class JSDecimalLiteral : JSLiteralBase<Decimal>
{
public JSDecimalLiteral(decimal value)
: base(value)
{
}

public override TypeReference GetActualType(TypeSystem typeSystem)
{
return new TypeReference(typeSystem.Double.Namespace, "Decimal", typeSystem.Double.Module,
typeSystem.Double.Scope, true);
}
}

public class JSNumberLiteral : JSLiteralBase<double> {
public readonly Type OriginalType;

Expand All @@ -260,8 +274,6 @@ public override TypeReference GetActualType (TypeSystem typeSystem) {
return typeSystem.Single;
case "System.Double":
return typeSystem.Double;
case "System.Decimal":
return new TypeReference(typeSystem.Double.Namespace, "Decimal", typeSystem.Double.Module, typeSystem.Double.Scope, true);
default:
throw new NotImplementedException(String.Format(
"Unsupported number literal type: {0}",
Expand Down
4 changes: 2 additions & 2 deletions JSIL/AST/JSNodeTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ public static JSNumberLiteral New (double value) {
return new JSNumberLiteral(value, typeof(double));
}

public static JSNumberLiteral New (decimal value) {
return new JSNumberLiteral((double)value, typeof(decimal));
public static JSDecimalLiteral New (decimal value) {
return new JSDecimalLiteral(value);
}

public static JSDefaultValueLiteral DefaultValue (TypeReference type) {
Expand Down
5 changes: 5 additions & 0 deletions JSIL/JavascriptAstEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,11 @@ public void VisitNode (JSNumberLiteral number) {
}
}

public void VisitNode(JSDecimalLiteral number)
{
VisitNode(new JSNewExpression(number.GetActualType(TypeSystem), null, null, JSLiteral.New((double) number.Value)));
}

public void VisitNode (JSBooleanLiteral b) {
Output.Value(b.Value);
}
Expand Down

0 comments on commit 5fdc4fc

Please sign in to comment.