@Test public void testCreateCallbackCWrapperPrimitiveParameters() { assertEquals( "void f_inner(char, short, int, long long, float, double);\n" + "void f(char p0, short p1, int p2, long long p3, float p4, double p5) {\n" + " f_inner(p0, p1, p2, p3, p4, p5);\n" + "}\n", CallbackMethodCompiler.createCallbackCWrapper( new FunctionType(VOID, I8, I16, I32, I64, FLOAT, DOUBLE), "f", "f_inner")); }
protected static String createCallbackCWrapper(FunctionType functionType, String name, String innerName) { Map<String, String> structs = new TreeMap<String, String>(Collections.reverseOrder()); StringBuilder hiSignature = new StringBuilder(); hiSignature .append(getHiType(functionType.getReturnType())) .append(' ') .append(innerName) .append('('); StringBuilder loSignature = new StringBuilder(); String loReturnType = getLoType(functionType.getReturnType(), name, 0, structs); loSignature .append(loReturnType) .append(' ') .append(name) .append('('); StringBuilder body = new StringBuilder(" {\n"); StringBuilder args = new StringBuilder(); for (int i = 0; i < functionType.getParameterTypes().length; i++) { String arg = "p" + i; if (i > 0) { hiSignature.append(", "); loSignature.append(", "); args.append(", "); } String hiParamType = getHiType(functionType.getParameterTypes()[i]); hiSignature.append(hiParamType); String loParamType = getLoType(functionType.getParameterTypes()[i], name, i + 1, structs); loSignature.append(loParamType).append(' ').append(arg); if (functionType.getParameterTypes()[i] instanceof StructureType) { args.append("(void*) &").append(arg); } else { args.append(arg); } } if (functionType.getParameterTypes().length == 0) { hiSignature.append("void"); loSignature.append("void"); } hiSignature.append(')'); loSignature.append(')'); StringBuilder header = new StringBuilder(); for (Entry<String, String> struct : structs.entrySet()) { header.append("struct " + struct.getKey() + " " + struct.getValue() + ";\n"); } header.append(hiSignature + ";\n"); if (functionType.getReturnType() instanceof StructureType) { body.append(" return *((" + loReturnType + "*) " + innerName + "(" + args + "));\n"); } else if (functionType.getReturnType() != Type.VOID) { body.append(" return " + innerName + "(" + args + ");\n"); } else { body.append(" " + innerName + "(" + args + ");\n"); } body.append("}\n"); return header.toString() + loSignature.toString() + body.toString(); }
CallbackMethodCompiler extends BroMethodCompiler { protected static String createCallbackCWrapper(FunctionType functionType, String name, String innerName) { Map<String, String> structs = new TreeMap<String, String>(Collections.reverseOrder()); StringBuilder hiSignature = new StringBuilder(); hiSignature .append(getHiType(functionType.getReturnType())) .append(' ') .append(innerName) .append('('); StringBuilder loSignature = new StringBuilder(); String loReturnType = getLoType(functionType.getReturnType(), name, 0, structs); loSignature .append(loReturnType) .append(' ') .append(name) .append('('); StringBuilder body = new StringBuilder(" {\n"); StringBuilder args = new StringBuilder(); for (int i = 0; i < functionType.getParameterTypes().length; i++) { String arg = "p" + i; if (i > 0) { hiSignature.append(", "); loSignature.append(", "); args.append(", "); } String hiParamType = getHiType(functionType.getParameterTypes()[i]); hiSignature.append(hiParamType); String loParamType = getLoType(functionType.getParameterTypes()[i], name, i + 1, structs); loSignature.append(loParamType).append(' ').append(arg); if (functionType.getParameterTypes()[i] instanceof StructureType) { args.append("(void*) &").append(arg); } else { args.append(arg); } } if (functionType.getParameterTypes().length == 0) { hiSignature.append("void"); loSignature.append("void"); } hiSignature.append(')'); loSignature.append(')'); StringBuilder header = new StringBuilder(); for (Entry<String, String> struct : structs.entrySet()) { header.append("struct " + struct.getKey() + " " + struct.getValue() + ";\n"); } header.append(hiSignature + ";\n"); if (functionType.getReturnType() instanceof StructureType) { body.append(" return *((" + loReturnType + "*) " + innerName + "(" + args + "));\n"); } else if (functionType.getReturnType() != Type.VOID) { body.append(" return " + innerName + "(" + args + ");\n"); } else { body.append(" " + innerName + "(" + args + ");\n"); } body.append("}\n"); return header.toString() + loSignature.toString() + body.toString(); } }
CallbackMethodCompiler extends BroMethodCompiler { protected static String createCallbackCWrapper(FunctionType functionType, String name, String innerName) { Map<String, String> structs = new TreeMap<String, String>(Collections.reverseOrder()); StringBuilder hiSignature = new StringBuilder(); hiSignature .append(getHiType(functionType.getReturnType())) .append(' ') .append(innerName) .append('('); StringBuilder loSignature = new StringBuilder(); String loReturnType = getLoType(functionType.getReturnType(), name, 0, structs); loSignature .append(loReturnType) .append(' ') .append(name) .append('('); StringBuilder body = new StringBuilder(" {\n"); StringBuilder args = new StringBuilder(); for (int i = 0; i < functionType.getParameterTypes().length; i++) { String arg = "p" + i; if (i > 0) { hiSignature.append(", "); loSignature.append(", "); args.append(", "); } String hiParamType = getHiType(functionType.getParameterTypes()[i]); hiSignature.append(hiParamType); String loParamType = getLoType(functionType.getParameterTypes()[i], name, i + 1, structs); loSignature.append(loParamType).append(' ').append(arg); if (functionType.getParameterTypes()[i] instanceof StructureType) { args.append("(void*) &").append(arg); } else { args.append(arg); } } if (functionType.getParameterTypes().length == 0) { hiSignature.append("void"); loSignature.append("void"); } hiSignature.append(')'); loSignature.append(')'); StringBuilder header = new StringBuilder(); for (Entry<String, String> struct : structs.entrySet()) { header.append("struct " + struct.getKey() + " " + struct.getValue() + ";\n"); } header.append(hiSignature + ";\n"); if (functionType.getReturnType() instanceof StructureType) { body.append(" return *((" + loReturnType + "*) " + innerName + "(" + args + "));\n"); } else if (functionType.getReturnType() != Type.VOID) { body.append(" return " + innerName + "(" + args + ");\n"); } else { body.append(" " + innerName + "(" + args + ");\n"); } body.append("}\n"); return header.toString() + loSignature.toString() + body.toString(); } CallbackMethodCompiler(Config config); }
CallbackMethodCompiler extends BroMethodCompiler { protected static String createCallbackCWrapper(FunctionType functionType, String name, String innerName) { Map<String, String> structs = new TreeMap<String, String>(Collections.reverseOrder()); StringBuilder hiSignature = new StringBuilder(); hiSignature .append(getHiType(functionType.getReturnType())) .append(' ') .append(innerName) .append('('); StringBuilder loSignature = new StringBuilder(); String loReturnType = getLoType(functionType.getReturnType(), name, 0, structs); loSignature .append(loReturnType) .append(' ') .append(name) .append('('); StringBuilder body = new StringBuilder(" {\n"); StringBuilder args = new StringBuilder(); for (int i = 0; i < functionType.getParameterTypes().length; i++) { String arg = "p" + i; if (i > 0) { hiSignature.append(", "); loSignature.append(", "); args.append(", "); } String hiParamType = getHiType(functionType.getParameterTypes()[i]); hiSignature.append(hiParamType); String loParamType = getLoType(functionType.getParameterTypes()[i], name, i + 1, structs); loSignature.append(loParamType).append(' ').append(arg); if (functionType.getParameterTypes()[i] instanceof StructureType) { args.append("(void*) &").append(arg); } else { args.append(arg); } } if (functionType.getParameterTypes().length == 0) { hiSignature.append("void"); loSignature.append("void"); } hiSignature.append(')'); loSignature.append(')'); StringBuilder header = new StringBuilder(); for (Entry<String, String> struct : structs.entrySet()) { header.append("struct " + struct.getKey() + " " + struct.getValue() + ";\n"); } header.append(hiSignature + ";\n"); if (functionType.getReturnType() instanceof StructureType) { body.append(" return *((" + loReturnType + "*) " + innerName + "(" + args + "));\n"); } else if (functionType.getReturnType() != Type.VOID) { body.append(" return " + innerName + "(" + args + ");\n"); } else { body.append(" " + innerName + "(" + args + ");\n"); } body.append("}\n"); return header.toString() + loSignature.toString() + body.toString(); } CallbackMethodCompiler(Config config);  }
CallbackMethodCompiler extends BroMethodCompiler { protected static String createCallbackCWrapper(FunctionType functionType, String name, String innerName) { Map<String, String> structs = new TreeMap<String, String>(Collections.reverseOrder()); StringBuilder hiSignature = new StringBuilder(); hiSignature .append(getHiType(functionType.getReturnType())) .append(' ') .append(innerName) .append('('); StringBuilder loSignature = new StringBuilder(); String loReturnType = getLoType(functionType.getReturnType(), name, 0, structs); loSignature .append(loReturnType) .append(' ') .append(name) .append('('); StringBuilder body = new StringBuilder(" {\n"); StringBuilder args = new StringBuilder(); for (int i = 0; i < functionType.getParameterTypes().length; i++) { String arg = "p" + i; if (i > 0) { hiSignature.append(", "); loSignature.append(", "); args.append(", "); } String hiParamType = getHiType(functionType.getParameterTypes()[i]); hiSignature.append(hiParamType); String loParamType = getLoType(functionType.getParameterTypes()[i], name, i + 1, structs); loSignature.append(loParamType).append(' ').append(arg); if (functionType.getParameterTypes()[i] instanceof StructureType) { args.append("(void*) &").append(arg); } else { args.append(arg); } } if (functionType.getParameterTypes().length == 0) { hiSignature.append("void"); loSignature.append("void"); } hiSignature.append(')'); loSignature.append(')'); StringBuilder header = new StringBuilder(); for (Entry<String, String> struct : structs.entrySet()) { header.append("struct " + struct.getKey() + " " + struct.getValue() + ";\n"); } header.append(hiSignature + ";\n"); if (functionType.getReturnType() instanceof StructureType) { body.append(" return *((" + loReturnType + "*) " + innerName + "(" + args + "));\n"); } else if (functionType.getReturnType() != Type.VOID) { body.append(" return " + innerName + "(" + args + ");\n"); } else { body.append(" " + innerName + "(" + args + ");\n"); } body.append("}\n"); return header.toString() + loSignature.toString() + body.toString(); } CallbackMethodCompiler(Config config);   }