@Test public void testCreateCallbackCWrapperSmallStructByValReturn() { assertEquals( "typedef struct {int m0;} f_0000;\n" + "void* f_inner(void);\n" + "f_0000 f(void) {\n" + " return *((f_0000*) f_inner());\n" + "}\n", CallbackMethodCompiler.createCallbackCWrapper( new FunctionType(new StructureType(I32)), "f", "f_inner")); }
protected static String createCallbackCWrapper(FunctionType functionType, String name, String innerName) { Map<String, String> typedefs = 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, typedefs); 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, typedefs); 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 (String typedef : typedefs.values()) { header.append(typedef + "\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> typedefs = 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, typedefs); 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, typedefs); 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 (String typedef : typedefs.values()) { header.append(typedef + "\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> typedefs = 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, typedefs); 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, typedefs); 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 (String typedef : typedefs.values()) { header.append(typedef + "\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> typedefs = 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, typedefs); 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, typedefs); 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 (String typedef : typedefs.values()) { header.append(typedef + "\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> typedefs = 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, typedefs); 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, typedefs); 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 (String typedef : typedefs.values()) { header.append(typedef + "\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);   }