@Override protected void checkRemoteInterface( final RemoteInterfaceDefinition definition, final Map<Object, Object> context) throws ADLException { for (final Method m : ((MethodContainer) definition).getMethods()) { final Type returnType = Util.getContainedType((m)); /* The method must return void */ final boolean isVoidMethod = (returnType instanceof PrimitiveType) && getPrimitiveType((PrimitiveType) returnType) == PrimitiveTypeEnum.VOID; if (!isVoidMethod) throw new ADLException(EXBErrors.IDL_INVALID_TYPE, "Each method in MP stubs and skeletons must return void"); ; /* Each parameter must be serializable and must not be in or in/out */ for (final Parameter p : ((ParameterContainer) m).getParameters()) { final Type paramType = Util.getContainedType((p)); if (!isSerializable(paramType)) throw new ADLException(EXBErrors.IDL_INVALID_TYPE, "The type of the parameter '" + p.getName() + "' is not serializable", paramType); if (Util.isOutParameter(p) || Util.isInOutParameter(p)) throw new ADLException(EXBErrors.IDL_INVALID_TYPE, "The parameter '" + p.getName() + "' must be IN", paramType); } } } }
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; }
/** * 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."); } }
/** * 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; } }
public void visitMethod(final Method method) throws Exception { final Type returnType = Util.getContainedType((method)); final Parameter[] parameters = ((ParameterContainer) method) .getParameters(); final boolean isVoidMethod = (returnType instanceof PrimitiveType) && getPrimitiveType((PrimitiveType) returnType) == PrimitiveTypeEnum.VOID; final Map<Parameter, Object> paramContext = new HashMap<Parameter, Object>(); final Object resultContext = null; .getContainedType(p), p.getName(), cw, localVars); paramContext.put(p, ctx); writeDeserialization(Util.getContainedType(p), p.getName(), data, cw, paramContext.get(p), true);
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 :
final Type type = getContainedType(p); if (!isPointerToArray(type)) { boolean pointer = false; pointer |= ((type instanceof PrimitiveType) && (getPrimitiveType((PrimitiveType) type) == PrimitiveTypeEnum.STRING)); pointer |= (type instanceof PointerOf); pointer |= (type instanceof ArrayOf); final Type type = getContainedType(p);
/** * 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(); }
/** * 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"); }
Type type; for (final Parameter p : ((ParameterContainer) method).getParameters()) { type = getContainedType(p); if (!isPointerToArray(type)) { boolean pointer = false; pointer |= ((type instanceof PrimitiveType) && (getPrimitiveType((PrimitiveType) type) == PrimitiveTypeEnum.STRING)); pointer |= (type instanceof PointerOf); pointer |= (type instanceof ArrayOf);
final Type returnType = Util.getContainedType((method)); final Parameter[] parameters = ((ParameterContainer) method) .getParameters(); final boolean isVoidMethod = (returnType instanceof PrimitiveType) && getPrimitiveType((PrimitiveType) returnType) == PrimitiveTypeEnum.VOID; final Map<Parameter, Object> paramContext = new HashMap<Parameter, Object>(); final Map<Parameter, Object> outParamContext = new HashMap<Parameter, Object>(); if (Util.isOutParameter(p) || Util.isInOutParameter(p)) hasOutParam = true; if (Util.isOutParameter(p) || Util.isInOutParameter(p)) { final String qualifier = p.getQualifier(); p.setQualifier(Parameter.IN); .getContainedType(p), p.getName(), cw, localVars); paramContext.put(p, ctx); if (Util.isOutParameter(p) || Util.isInOutParameter(p)) { final Object ctx = writeSerializationDeclaration(Util .getContainedType(p), p.getName(), cw, localVars); outParamContext.put(p, ctx); if (Util.isOutParameter(p)) continue; cw.append("// Deserialize \"" + p.getName() + "\"").endl(); writeDeserialization(Util.getContainedType(p), p.getName(), data, cw, paramContext.get(p), false); cw.append("CALL(REQUIRED.itf, ").append(method.getName());
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; }
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"); }
public void visitMethod(final Method method) throws Exception { final Type returnType = Util.getContainedType((method)); final boolean isVoidMethod = (returnType instanceof PrimitiveType) && getPrimitiveType((PrimitiveType) returnType) == PrimitiveTypeEnum.VOID;
final Type returnType = Util.getContainedType((method)); final Parameter[] parameters = ((ParameterContainer) method) .getParameters(); final boolean isVoidMethod = (returnType instanceof PrimitiveType) && getPrimitiveType((PrimitiveType) returnType) == PrimitiveTypeEnum.VOID; final Map<Parameter, Object> paramContext = new HashMap<Parameter, Object>(); Object resultContext = null; if (Util.isOutParameter(p) || Util.isInOutParameter(p)) hasOutParam = true; if (Util.isOutParameter(p)) continue; final Object ctx = writeSerializationDeclaration(Util .getContainedType(p), p.getName(), cw, localVars); paramContext.put(p, ctx); if (Util.isOutParameter(p)) continue; String paramName = p.getName(); if (Util.isInOutParameter(p)) paramName = "(*" + paramName + ")"; writeSizeOf(Util.getContainedType(p), paramName, msgSize, cw, paramContext.get(p)); if (Util.isOutParameter(p)) continue; cw.append("// Serialize \"" + p.getName() + "\"").endl(); if (Util.isInOutParameter(p)) writeSerialization(Util.getContainedType(p), "(*" + p.getName() + ")", data, cw, paramContext.get(p), false); else writeSerialization(Util.getContainedType(p), p.getName(), data, cw,
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"); }
final Type type = getContainedType(p); && (getPrimitiveType((PrimitiveType) type) == PrimitiveTypeEnum.STRING)) {