Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/expression/DSLExpressionResolver.java @ 20169:65d29fa81397
DSL: add support for hex, oct and binary integer literals.
author | Chris Seaton <chris.seaton@oracle.com> |
---|---|
date | Sun, 05 Apr 2015 19:51:46 +0100 |
parents | ef292a5bb79d |
children | 953c813b8e7a |
comparison
equal
deleted
inserted
replaced
20168:f0f725496f2a | 20169:65d29fa81397 |
---|---|
224 } | 224 } |
225 | 225 |
226 public void visitIntLiteral(IntLiteral binary) { | 226 public void visitIntLiteral(IntLiteral binary) { |
227 try { | 227 try { |
228 binary.setResolvedType(context.getType(int.class)); | 228 binary.setResolvedType(context.getType(int.class)); |
229 binary.setResolvedValueInt(Integer.parseInt(binary.getLiteral())); | 229 |
230 final int base; | |
231 final String literal; | |
232 | |
233 if (binary.getLiteral().startsWith("0x")) { | |
234 base = 16; | |
235 literal = binary.getLiteral().substring(2); | |
236 } else if (binary.getLiteral().startsWith("0b")) { | |
237 base = 2; | |
238 literal = binary.getLiteral().substring(2); | |
239 } else if (binary.getLiteral().startsWith("0")) { | |
240 base = 8; | |
241 literal = binary.getLiteral(); | |
242 } else { | |
243 base = 10; | |
244 literal = binary.getLiteral(); | |
245 } | |
246 | |
247 binary.setResolvedValueInt(Integer.parseInt(literal, base)); | |
230 } catch (NumberFormatException e) { | 248 } catch (NumberFormatException e) { |
231 throw new InvalidExpressionException(String.format("Type mismatch: cannot convert from String '%s' to int", binary.getLiteral())); | 249 throw new InvalidExpressionException(String.format("Type mismatch: cannot convert from String '%s' to int", binary.getLiteral())); |
232 } | 250 } |
233 } | 251 } |
234 | 252 |