diff --git a/CodeGen/BMapBindings/JsonWriter.java b/CodeGen/BMapBindings/JsonWriter.java new file mode 100644 index 0000000..13c6a99 --- /dev/null +++ b/CodeGen/BMapBindings/JsonWriter.java @@ -0,0 +1,60 @@ +import java.io.OutputStreamWriter; +import java.util.Vector; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class JsonWriter { + + private static JsonObject writeVariableType(VariableType vt) { + JsonObject data = new JsonObject(); + + JsonArray hierarchy = new JsonArray(); + for (String item : vt.getBaseTypeHierarchy()) { + hierarchy.add(item); + } + data.add("hierarchy", hierarchy); + data.addProperty("pointer_level", vt.getPointerLevel()); + + return data; + } + + private static JsonObject writeExpFctParamDecl(ExpFctParamDecl paramdecl) { + JsonObject data = new JsonObject(); + data.addProperty("name", paramdecl.mVarName); + data.addProperty("is_input", paramdecl.mIsInput); + data.addProperty("desc", paramdecl.mVarDesc); + data.add("type", writeVariableType(paramdecl.mVarType)); + + return data; + } + + private static JsonObject writeExpFctDecl(ExpFctDecl fctdecl) { + JsonObject data = new JsonObject(); + data.addProperty("name", fctdecl.mFctName); + data.add("return", writeVariableType(fctdecl.mFctRetType)); + + JsonArray paramlist = new JsonArray(); + for (ExpFctParamDecl paramdecl : fctdecl.mFctParams) { + paramlist.add(writeExpFctParamDecl(paramdecl)); + } + data.add("params", paramlist); + + return data; + } + + public static void writeJson(Vector data) throws Exception { + OutputStreamWriter writer = CommonHelper.openWriter("dest/BMExports.json"); + //Gson gson_instance = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); + Gson gson_instance = new GsonBuilder().disableHtmlEscaping().create(); + + JsonArray fcts = new JsonArray(); + for (ExpFctDecl fctdecl : data) { + fcts.add(writeExpFctDecl(fctdecl)); + } + + writer.write(gson_instance.toJson(fcts)); + writer.close(); + } +} diff --git a/CodeGen/BMapBindings/MainRunner.java b/CodeGen/BMapBindings/MainRunner.java index 077f661..e27dfc9 100644 --- a/CodeGen/BMapBindings/MainRunner.java +++ b/CodeGen/BMapBindings/MainRunner.java @@ -26,6 +26,7 @@ public class MainRunner { Vector result = worker.getResult(); PythonWriter.writePythonCode(result); CSharpWriter.writeCSharpCode(result); + JsonWriter.writeJson(result); // print message. System.out.println("DONE!"); diff --git a/CodeGen/BMapBindings/VariableType.java b/CodeGen/BMapBindings/VariableType.java index 803b95c..4a50787 100644 --- a/CodeGen/BMapBindings/VariableType.java +++ b/CodeGen/BMapBindings/VariableType.java @@ -67,6 +67,10 @@ public class VariableType { public int getPointerLevel() { return mPointerLevel; } + + public Vector getBaseTypeHierarchy() { + return (Vector) mBaseType.clone(); + } public boolean isValid() { return mBaseType.size() != 0;