/** * Returns <code>true</code> if the given type node is a complex type or * either an array or pointer of complex type. * * @param type a type node. * @return <code>true</code> if the given type node is a complex type or * either an array or pointer of complex type. */ public static boolean isComplexType(final Type type) { if (type instanceof ComplexType) { return true; } else if ((type instanceof ArrayOf) || (type instanceof PointerOf)) { return isComplexType(getContainedType((TypeContainer) type)); } else { return false; } }
/** * Returns the equivalent in C of the given return type. * * @param type the type * @return the equivalent in C of the given return type. */ public static String buildType(Type type) { final StringBuffer result = new StringBuffer(); int nbPointer = 0; // A return type is an [ArrayOf](PointerOf)*(PrimitiveType|ComplexType) while (type instanceof ArrayOf) { nbPointer++; type = getContainedType((ArrayOf) type); } while (type instanceof PointerOf) { nbPointer++; type = getContainedType((PointerOf) type); } result.append(buildComplexOrPrimitiveType(type)); for (int i = 0; i < nbPointer; i++) result.append('*'); return result.toString(); }
/** * Returns the complex type node contained by the given type. More precisely, * if the given <code>type</code> is a {@link ComplexType} this method * simply return it; if the given <code>type</code> is an {@link ArrayOf} of * a {@link PointerOf}, returns the complex type it contains; else, throws an * {@link IllegalArgumentException} * * @param type a {@link ComplexType} or a container of {@link ComplexType} * @return the complex type node contained by the given type. * @throws IllegalArgumentException if * <code>{@link #isComplexType(Type)}(type)</code> is * <code>false</code>. */ public static ComplexType getComplexType(final Type type) { if (type instanceof ComplexType) { return (ComplexType) type; } else if ((type instanceof ArrayOf) || (type instanceof PointerOf)) { return getComplexType(getContainedType((TypeContainer) type)); } else { throw new IllegalArgumentException( "The given type is not a complex type."); } }
private Field newField(Token name, String qualifier, Type type, String value) { Field field = (Field)newNode("field", name); field.setName(name.image); field.setValue(value); field.setQualifier(qualifier); Util.setContainedType((TypeContainer)field, type); return field; }
public static boolean isPointerToArray(final Type type) { if (type instanceof PointerOf && getContainedType((PointerOf) type) instanceof ComplexType) { final IDLDefinition pointedDefinition = ((ComplexType) getContainedType((PointerOf) type)) .getIDLDefinition(); return pointedDefinition instanceof RecordDefinition && (getArrayCType(type) != null); } else { return false; } }
switch (getPrimitiveType((PrimitiveType) type)) { case VOID : case BYTE :
case BOOLEAN : cw.append(sizeofName).append(" += sizeof(").append( buildPrimitiveType(varType)).append(");").endl(); break; case STRING :
private static String buildSizeableArray(Type type, final ParseArrayMode What) { final StringBuffer result = new StringBuffer(); String arraySpec = ""; while (type instanceof ArrayOf) { final String size = ((ArrayOf) type).getSize(); if (size != null) { arraySpec = "[" + size + "]" + arraySpec; } else { arraySpec = "[]" + arraySpec; } type = getContainedType((ArrayOf) type); } if (What == ParseArrayMode.TYPE) result.append(buildComplexOrPrimitiveType(type)); if (What == ParseArrayMode.SIZEOF) result.append(arraySpec); return result.toString(); }
final public Parameter FormalParameter() throws ParseException { Token t; Type type; Parameter fp; String qualifier; qualifier = ParameterQualifier(); type = ParameterType(); t = jj_consume_token(IDENTIFIER); fp = (Parameter)newNode("parameter", t); fp.setName(t.image); fp.setQualifier(qualifier); Util.setContainedType((TypeContainer)fp, type); {if (true) return fp;} throw new Error("Missing return statement in function"); }
public static String getArrayCType(final Type type) { if (type instanceof PointerOf && getContainedType((PointerOf) type) instanceof ComplexType) { final IDLDefinition pointedDefinition = ((ComplexType) getContainedType((PointerOf) type)) .getIDLDefinition(); final String name = ((RecordDefinition) pointedDefinition).getName(); if (BYTE_ARRAY_TYPE.equals(name)) return "minus_bare_generic_api_ByteArray"; else if (SHORT_ARRAY_TYPE.equals(name)) return "minus_bare_generic_api_ShortArray"; else if (USHORT_ARRAY_TYPE.equals(name)) return "minus_bare_generic_api_UShortArray"; else if (INT_ARRAY_TYPE.equals(name)) return "minus_bare_generic_api_IntArray"; else if (UINT_ARRAY_TYPE.equals(name)) return "minus_bare_generic_api_UIntArray"; else if (STRING_ARRAY_TYPE.equals(name)) return "minus_bare_generic_api_StringArray"; } return null; }
/** * Generates the declaration code required to the serialization of the * variable whose name is <code>varName</code> and its type is * <code>varType</code>. The returned object will be passed as * <code>context</code> parameter to the call of the * {@link #writeSerialization(Type, String, String, CodeWriter, Object, boolean) writeSerialization} * method for the same variable. * * @param varType the type of the variable to serialize. * @param varName the name of the variable to serialize. * @param cw the {@link CodeWriter} into which the generated code is appended. * @param validator the name validator. Can be used to validate a local * variable name. * @return an object that will be passed as <code>context</code> parameter * to the call of the * {@link #writeSerialization(Type, String, String, CodeWriter, Object, boolean) writeSerialization} * method for the same variable. */ public static Object writeSerializationDeclaration(final Type varType, final String varName, final CodeWriter cw, final VarNameValidator validator) { if (varType instanceof PrimitiveType) { return writeSerializationDeclaration( getPrimitiveType((PrimitiveType) varType), varName, cw, validator); } if (isPointerToArray(varType)) { return null; } throw new IllegalArgumentException("Invalid varType"); }
private static String buildSizeableArray(Type type, final ParseArrayMode What) { final StringBuffer result = new StringBuffer(); String arraySpec = ""; while (type instanceof ArrayOf) { final String size = ((ArrayOf) type).getSize(); if (size != null) { arraySpec = "[" + size + "]" + arraySpec; } else { arraySpec = "[]" + arraySpec; } type = getContainedType((ArrayOf) type); } if (What == ParseArrayMode.TYPE) result.append(buildComplexOrPrimitiveType(type)); if (What == ParseArrayMode.SIZEOF) result.append(arraySpec); return result.toString(); }
final public Parameter FormalParameter() throws ParseException { Token t; Type type; Parameter fp; String qualifier; qualifier = ParameterQualifier(); type = ParameterType(); t = jj_consume_token(IDENTIFIER); fp = (Parameter)newNode("parameter", t); fp.setName(t.image); fp.setQualifier(qualifier); Util.setContainedType((TypeContainer)fp, type); {if (true) return fp;} throw new Error("Missing return statement in function"); }
/** * Generates the declaration code required to the deserialization of the * variable whoes name is <code>varName</code> and its type is * <code>varType</code>. The returned object will be passed as * <code>context</code> parameter to the call of the * {@link #writeSerialization(Type, String, String, CodeWriter, Object, boolean) writeSerialization} * method for the same variable. * * @param varType the type of the variable to serialize. * @param varName the name of the variable to serialize. * @param cw the {@link CodeWriter} into which the generated code is appended. * @param validator the name validator. Can be used to validate a local * variable name. * @return an object that will be passed as <code>context</code> parameter * to the call of the * {@link #writeSerialization(Type, String, String, CodeWriter, Object, boolean) writeSerialization} * method for the same variable. */ public static Object writeDeserializationDeclaration(final Type varType, final String varName, final CodeWriter cw, final VarNameValidator validator) { if (varType instanceof PrimitiveType) { return writeDeserializationDeclaration( getPrimitiveType((PrimitiveType) varType), varName, cw, validator); } if (isPointerToArray(varType)) { return null; } throw new IllegalArgumentException("Invalid varType"); }
private static String buildSizeableArray(Type type, final ParseArrayMode What) { final StringBuffer result = new StringBuffer(); String arraySpec = ""; while (type instanceof ArrayOf) { final String size = ((ArrayOf) type).getSize(); if (size != null) { arraySpec = "[" + size + "]" + arraySpec; } else { arraySpec = "[]" + arraySpec; } type = getContainedType((ArrayOf) type); } if (What == ParseArrayMode.TYPE) result.append(buildComplexOrPrimitiveType(type)); if (What == ParseArrayMode.SIZEOF) result.append(arraySpec); return result.toString(); }
final public Field RecordFieldDefinition() throws ParseException { Token t; Field field; Type type; String qualifier = ""; qualifier = RecordFieldQualifier(); type = RecordFieldType(); t = jj_consume_token(IDENTIFIER); SemiList(); field = (Field)newNode("field", t); field.setName(t.image); field.setValue(null); field.setQualifier(qualifier); Util.setContainedType((TypeContainer)field, type); {if (true) return field;} throw new Error("Missing return statement in function"); }
private static String buildSizeableArray(Type type, final ParseArrayMode What) { final StringBuffer result = new StringBuffer(); String arraySpec = ""; while (type instanceof ArrayOf) { final String size = ((ArrayOf) type).getSize(); if (size != null) { arraySpec = "[" + size + "]" + arraySpec; } else { arraySpec = "[]" + arraySpec; } type = getContainedType((ArrayOf) type); } if (What == ParseArrayMode.TYPE) result.append(buildComplexOrPrimitiveType(type)); if (What == ParseArrayMode.SIZEOF) result.append(arraySpec); return result.toString(); }
final public Field UnionFieldDefinition() throws ParseException { Token t; Field field; Type type; String qualifier = ""; qualifier = UnionFieldQualifier(); type = RecordFieldType(); t = jj_consume_token(IDENTIFIER); SemiList(); field = (Field)newNode("field", t); field.setName(t.image); field.setValue(null); field.setQualifier(qualifier); Util.setContainedType((TypeContainer)field, type); {if (true) return field;} throw new Error("Missing return statement in function"); }
final public Method MethodDefinition() throws ParseException { Token t; Type type; Method method; type = ReturnType(); t = jj_consume_token(IDENTIFIER); method = (Method)newNode("method", t); method.setName(t.image); method.setHasVarParams("false"); Util.setContainedType((TypeContainer)method, type); FormalParameters((ParameterContainer)method); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case THROWS: jj_consume_token(THROWS); NameList(); break; default: jj_la1[16] = jj_gen; ; } SemiList(); {if (true) return method;} throw new Error("Missing return statement in function"); }
final public void MethodDefinition(MethodContainer container) throws ParseException { Token t; Type type; Method method; type = ReturnType(); t = jj_consume_token(IDENTIFIER); method = (Method)newNode("method", t); method.setName(t.image); method.setHasVarParams("false"); Util.setContainedType((TypeContainer)method, type); FormalParameters((ParameterContainer)method); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case THROWS: jj_consume_token(THROWS); NameList(); break; default: jj_la1[19] = jj_gen; ; } SemiList(); container.addMethod(method); }