private void readArrayField(Field field, ArrayType array) { String elTypeJavaName = TypeNameEmitter.getTypeName(array); if (elTypeJavaName.startsWith("ObjectArray")) { try { ArrayEmitter ae = new ArrayEmitter(field, array, this); Template tpl = global.getTemplateConfig().getTemplate("java/ArrayRead.ftl"); tpl.process(ae, writer); } catch (TemplateException exc) { throw new DataScriptException(exc); } catch (IOException exc) { throw new DataScriptException(exc); } } else { Expression length = array.getLengthExpression(); TypeInterface elType = array.getElementType(); if (elType instanceof EnumType) { EnumType enumType = (EnumType) elType; readEnumField(field, enumType); } else { buffer.append(AccessorNameEmitter.getSetterName(field)); buffer.append("(new "); buffer.append(elTypeJavaName); buffer.append("(__in, (int)("); buffer.append(getLengthExpression(length)); buffer.append(")"); if (elType instanceof BitFieldType) { BitFieldType bitField = (BitFieldType) elType; Expression numBits = bitField.getLengthExpression(); buffer.append(", "); buffer.append(getLengthExpression(numBits)); } } buffer.append("));"); } }
public String getVisitor(TypeInterface type, String nodeName, String fieldName) { type = TypeReference.resolveType(type); Expression length = null; StringBuilder buffer = new StringBuilder(); if (type instanceof IntegerType) { buffer.append("visit"); IntegerType itype = (IntegerType) type; switch (itype.getType()) { case DataScriptParserTokenTypes.INT8: buffer.append("Int8"); break; case DataScriptParserTokenTypes.UINT8: buffer.append("UInt8"); break; case DataScriptParserTokenTypes.INT16: buffer.append("Int16"); break; case DataScriptParserTokenTypes.UINT16: buffer.append("UInt16"); break; case DataScriptParserTokenTypes.INT32: buffer.append("Int32"); break; case DataScriptParserTokenTypes.UINT32: buffer.append("UInt32"); break; case DataScriptParserTokenTypes.INT64: buffer.append("Int64"); break; case DataScriptParserTokenTypes.UINT64: buffer.append("UInt64"); break; case DataScriptParserTokenTypes.BIT: BitFieldType bftype = (BitFieldType) itype; length = bftype.getLengthExpression(); buffer.append("BitField"); break; } buffer.append("("); buffer.append(nodeName); if (length != null) { buffer.append(", "); buffer.append(exprEmitter.emit(length, "node")); } buffer.append(", \""); buffer.append(fieldName); buffer.append("\")"); } else if (type instanceof StringType) { buffer.append("visitString(" + nodeName + ", \"" + fieldName + "\")"); } else if (type instanceof ArrayType) { buffer.append("visitArray(" + nodeName + ", \"" + fieldName + "\")"); } else { buffer.append(nodeName); buffer.append(".accept(this, \""); buffer.append(fieldName); buffer.append("\")"); } return buffer.toString(); }
public boolean getIsSimple() { boolean result = false; if (type instanceof StdIntegerType) { result = (((StdIntegerType) type).getType() != datascript.antlr.DataScriptParserTokenTypes.UINT64); } else if (type instanceof BitFieldType) { BitFieldType bitField = (BitFieldType) type; result = 0 < bitField.getLength() && bitField.getLength() < 64; } return result; }
public long getMinVal() { if (type instanceof SignedBitFieldType) { BitFieldType bitField = (BitFieldType) type; return -(1 << bitField.getLength() - 1); } if (type instanceof BitFieldType) { return 0; } if (type instanceof StdIntegerType) { StdIntegerType integerType = (StdIntegerType) type; return integerType.getLowerBound().longValue(); } throw new RuntimeException("type of field '" + param.getName() + "' is not a simple type"); }
protected String getTypeName(BitFieldType t) { int length = t.getLength(); if (length < 64) return "INT"; else return "BLOB"; }