Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chochos committed Jan 7, 2013
1 parent 6ff039f commit 4b6bcd4
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions src/main/java/com/redhat/ceylon/compiler/js/GenerateJsVisitor.java
Expand Up @@ -1371,7 +1371,17 @@ public void visit(FloatLiteral that) {

@Override
public void visit(NaturalLiteral that) {
out("(", that.getText(), ")");
char prefix = that.getText().charAt(0);
if (prefix == '$' || prefix == '#') {
int radix= prefix == '$' ? 2 : 16;
try {
out("(", new java.math.BigInteger(that.getText().substring(1), radix).toString(), ")");
} catch (NumberFormatException ex) {
that.addError("Invalid numeric literal " + that.getText());
}
} else {
out("(", that.getText(), ")");
}
}

@Override
Expand Down Expand Up @@ -1697,34 +1707,6 @@ public void visit(QualifiedTypeExpression that) {

@Override
public void visit(InvocationExpression that) {
if (that.getPrimary() instanceof BaseMemberExpression && that.getPositionalArgumentList() != null) {
//This is just for hex() and bin() literals
List<PositionalArgument> args = that.getPositionalArgumentList().getPositionalArguments();
if (args.size() == 1 && args.get(0).getExpression() != null) {
Term term = args.get(0).getExpression().getTerm();
if (term instanceof QuotedLiteral) {
Declaration decl = ((BaseMemberExpression)that.getPrimary()).getDeclaration();
if (decl instanceof Method) {
String name = decl.getQualifiedNameString();
int radix=0;
if ("ceylon.language::hex".equals(name)) {
radix = 16;
} else if ("ceylon.language::bin".equals(name)) {
radix = 2;
}
if (radix > 0) {
String lit = term.getText().substring(1, term.getText().length()-1);
try {
out("(", new java.math.BigInteger(lit, radix).toString(), ")");
} catch (NumberFormatException ex) {
that.addError("Invalid numeric literal " + lit);
}
return;
}
}
}
}
}
if (that.getNamedArgumentList()!=null) {
NamedArgumentList argList = that.getNamedArgumentList();
out("(");
Expand Down

0 comments on commit 4b6bcd4

Please sign in to comment.