add json output for convenience about more lang bindings for bmap.

This commit is contained in:
yyc12345 2023-11-07 15:55:07 +08:00
parent 824497f638
commit aa8ec72df7
3 changed files with 65 additions and 0 deletions

View File

@ -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<ExpFctDecl> 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();
}
}

View File

@ -26,6 +26,7 @@ public class MainRunner {
Vector<ExpFctDecl> result = worker.getResult(); Vector<ExpFctDecl> result = worker.getResult();
PythonWriter.writePythonCode(result); PythonWriter.writePythonCode(result);
CSharpWriter.writeCSharpCode(result); CSharpWriter.writeCSharpCode(result);
JsonWriter.writeJson(result);
// print message. // print message.
System.out.println("DONE!"); System.out.println("DONE!");

View File

@ -67,6 +67,10 @@ public class VariableType {
public int getPointerLevel() { public int getPointerLevel() {
return mPointerLevel; return mPointerLevel;
} }
public Vector<String> getBaseTypeHierarchy() {
return (Vector<String>) mBaseType.clone();
}
public boolean isValid() { public boolean isValid() {
return mBaseType.size() != 0; return mBaseType.size() != 0;