return new Constant(tpe, form, value, orig);
public void visitConstant(Constant e) { expressionPre(e); String txt = e.getOriginalTextualRepresentation(); if (txt != null) { append(txt); } else { Object value = e.getValue(); if (e.getIntForm() == IntForm.Hex) { append("0x", Long.toHexString(value instanceof Long ? ((Long) value).longValue() : ((Integer) value).longValue()).toUpperCase()); } else if (e.getIntForm() == IntForm.Octal) { append(Long.toOctalString(value instanceof Long ? ((Long) value).longValue() : ((Integer) value).longValue()).toUpperCase()); } else if (e.getType() == null) { append(""); } else { switch (e.getType()) { case Null: append("null"); case IntegerString: int intVal = ((Integer) value).intValue(); append('\'', Constant.intStr(intVal), '\''); break; case LongString: append( '\'', Constant.intStr((int) (longVal & 0xffffffffL)), Constant.intStr((int) ((longVal >>> 32) & 0xffffffffL)), '\''); break;
if (lastRefValue instanceof Expression.Constant) { try { lastAdditiveValue = ((Expression.Constant) lastRefValue).asInteger(); lastRefValue = null; } catch (Exception ex) {
String s = String.valueOf(Constant.parseString((an!=null?an.getText():null)).getValue()); if (retval.asmName == null) retval.asmName = s;
if ( state.backtracking==0 ) { constant = Constant.parseDecimal(((s!=null?s.getText():null) == null ? "" : (s!=null?s.getText():null)) + (DECIMAL_NUMBER53!=null?DECIMAL_NUMBER53.getText():null)); } if ( state.backtracking==0 ) { constant = Constant.parseHex((HEXADECIMAL_NUMBER54!=null?HEXADECIMAL_NUMBER54.getText():null), "-".equals((s!=null?s.getText():null))); } if ( state.backtracking==0 ) { constant = Constant.parseOctal((OCTAL_NUMBER55!=null?OCTAL_NUMBER55.getText():null), "-".equals((s!=null?s.getText():null))); } if ( state.backtracking==0 ) { constant = Constant.parseCharOrStringInteger((CHARACTER56!=null?CHARACTER56.getText():null)); } if ( state.backtracking==0 ) { constant = Constant.parseFloat(((s2!=null?s2.getText():null) == null ? "" : (s2!=null?s2.getText():null)) + (FLOAT_NUMBER57!=null?FLOAT_NUMBER57.getText():null)); } if ( state.backtracking==0 ) { constant = Constant.parseString((STRING58!=null?STRING58.getText():null)); }
declarator.setName(String.valueOf(Constant.parseString((fieldName!=null?fieldName.getText():null)).getValue()));
if (lastRefValue instanceof Expression.Constant) { try { lastAdditiveValue = ((Expression.Constant) lastRefValue).asInteger(); lastRefValue = null; } catch (Exception ex) {
if (defineValue instanceof Expression.Constant) { Expression.Constant constant = (Expression.Constant) defineValue; return typed(findDefine(name), convertToJavaType(constant.getType()));
public Constant asJava() { Type type = getType(); String txt = originalTextualRepresentation; switch (type) { case LongString: case Short: txt = trimTrailingTypeInfo(txt); break; case UInt: if (intForm != IntForm.Hex && (getValue() instanceof Long) && ((Long)getValue()) > Integer.MAX_VALUE) { txt = null; break; txt = trimTrailingTypeInfo(txt); break; return new Constant(type, getValue(), txt);
case Char: case String: expr = methodCall(ident("v8", "String", "New"), new Expression.Constant(valueType, value + "", null)); break; case Null:
if (defineValue instanceof Expression.Constant) { Expression.Constant constant = (Expression.Constant) defineValue; return typed(findDefine(name), convertToJavaType(constant.getType()));
case Char: case String: expr = methodCall(ident("v8", "String", "New"), new Expression.Constant(valueType, value + "", null)); break; case Null:
return new Constant(Type.IntegerString, IntForm.String, (int)result, orig); else return new Constant(Type.LongString, IntForm.String, result, orig); String parsed = parseNakedString(string); if (parsed.length() != 1) { throw new IllegalArgumentException("Expected char, go string of length " + parsed.length() + ": '" + parsed + "'"); return new Constant(Type.Char, parsed.charAt(0), orig);
return; Object value = getValue(); switch (type) { case Int:
@Override public void visitConstant(Constant c) { if (c.getValue() instanceof String) { //Struct s = c.findParentOfType(Struct.class); Class charClass; String ptrMethodName; if (c.getType() == Constant.Type.LongString) { charClass = Short.class; ptrMethodName = "pointerToWideCString"; } else { charClass = Byte.class; ptrMethodName = "pointerToCString"; } String fieldName = "strConstant" + (++nConstants); VariablesDeclaration staticConstField = new VariablesDeclaration(typeRef(ident(ptrClass(), expr(typeRef(charClass)))), new DirectDeclarator(fieldName, staticPtrMethod(ptrMethodName, c.clone()))); staticConstField.addModifiers(ModifierType.Static, ModifierType.Private, ModifierType.Final); //s.addDeclaration(staticConstField); extraDeclarationsOut.add(staticConstField); c.replaceBy(varRef(fieldName)); return; } super.visitConstant(c); } //
@Override public void visitConstant(Constant c) { if (c.getValue() instanceof String) { //Struct s = c.findParentOfType(Struct.class); Class charClass; String ptrMethodName; if (c.getType() == Constant.Type.LongString) { charClass = Short.class; ptrMethodName = "pointerToWideCString"; } else { charClass = Byte.class; ptrMethodName = "pointerToCString"; } String fieldName = "strConstant" + (++nConstants); VariablesDeclaration staticConstField = new VariablesDeclaration(typeRef(ident(ptrClass(), expr(typeRef(charClass)))), new DirectDeclarator(fieldName, staticPtrMethod(ptrMethodName, c.clone()))); staticConstField.addModifiers(ModifierType.Static, ModifierType.Private, ModifierType.Final); //s.addDeclaration(staticConstField); extraDeclarationsOut.add(staticConstField); c.replaceBy(varRef(fieldName)); return; } super.visitConstant(c); } //
public static Constant parseStringInteger(final String orig) { String string = orig; int len = string.length(); if (len <= 2 || string.charAt(0) != '\'' || string.charAt(len - 1) != '\'' || ((len -= 2) != 4 && len != 8)) throw new IllegalArgumentException("Expecting 'xxxx' or 'xxxxxxxx', got " + string); string = string.substring(1, len - 1); long result = 0; for (int i = len; i-- != 0;) { result = result << 8 | (int)string.charAt(i); } if (len == 4) return new Constant(Type.Int, IntForm.String, (int)result, orig); else return new Constant(Type.Long, IntForm.String, result, orig); }
public static Constant parseFloat(final String orig) { String string = orig; string = string.trim().toLowerCase(); if (string.length() > 0) { int lm1 = string.length() - 1; char c = string.charAt(lm1); if (Character.isLetter(c)) { String beg = string.substring(0, lm1); if (c == 'f') return new Constant(Type.Float, Float.parseFloat(beg), orig); } } return new Constant(Type.Double, Double.parseDouble(string), orig); } static final String[] trailingTypeInfos = new String[] { "ll", "li", "l", "s", "u" };