From 68bffefe5a8b63e88a995b694e52c4ed6e9f2edc Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 2 Nov 2023 10:53:16 +0800 Subject: [PATCH] write binding code --- CodeGen/BMapBindings/.gitignore | 3 ++ CodeGen/BMapBindings/ExpFctDecl.java | 16 +++++++ CodeGen/BMapBindings/ExpFctParamDecl.java | 12 +++++ CodeGen/BMapBindings/ExpFctsWalker.java | 6 +++ CodeGen/BMapBindings/MainRunner.java | 11 +++++ CodeGen/BMapBindings/README.md | 11 +++++ CodeGen/BMapBindings/VariableType.java | 57 +++++++++++++++++++++++ README.md | 4 -- 8 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 CodeGen/BMapBindings/ExpFctDecl.java create mode 100644 CodeGen/BMapBindings/ExpFctParamDecl.java create mode 100644 CodeGen/BMapBindings/ExpFctsWalker.java create mode 100644 CodeGen/BMapBindings/MainRunner.java create mode 100644 CodeGen/BMapBindings/VariableType.java diff --git a/CodeGen/BMapBindings/.gitignore b/CodeGen/BMapBindings/.gitignore index 6d8923b..ac9dc64 100644 --- a/CodeGen/BMapBindings/.gitignore +++ b/CodeGen/BMapBindings/.gitignore @@ -2,6 +2,9 @@ *.interp *.tokens +ExpFctsLexer*.java +ExpFctsParser*.java + # ===== Python ===== # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/CodeGen/BMapBindings/ExpFctDecl.java b/CodeGen/BMapBindings/ExpFctDecl.java new file mode 100644 index 0000000..abb4f90 --- /dev/null +++ b/CodeGen/BMapBindings/ExpFctDecl.java @@ -0,0 +1,16 @@ +import java.util.Vector; + +public class ExpFctDecl { + + public String mFctName; + public VariableType mFctRetType; + public Vector mFctParams; + + public ExpFctDecl(String fct_name, VariableType ret_type) { + mFctName = fct_name; + mFctRetType = ret_type; + mFctParams = new Vector(); + } + +} + diff --git a/CodeGen/BMapBindings/ExpFctParamDecl.java b/CodeGen/BMapBindings/ExpFctParamDecl.java new file mode 100644 index 0000000..c941b69 --- /dev/null +++ b/CodeGen/BMapBindings/ExpFctParamDecl.java @@ -0,0 +1,12 @@ + +public class ExpFctParamDecl { + + public VariableType mVarType; + public String mVarName; + + public ExpFctParamDecl(VariableType vtype, String vname) { + mVarType = vtype; + mVarName = vname; + } + +} diff --git a/CodeGen/BMapBindings/ExpFctsWalker.java b/CodeGen/BMapBindings/ExpFctsWalker.java new file mode 100644 index 0000000..487ef2d --- /dev/null +++ b/CodeGen/BMapBindings/ExpFctsWalker.java @@ -0,0 +1,6 @@ +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.tree.*; + +public class ExpFctsWalker extends ExpFctsParserBaseListener { + +} diff --git a/CodeGen/BMapBindings/MainRunner.java b/CodeGen/BMapBindings/MainRunner.java new file mode 100644 index 0000000..c989517 --- /dev/null +++ b/CodeGen/BMapBindings/MainRunner.java @@ -0,0 +1,11 @@ +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.tree.*; + +public class MainRunner { + + public static void main(String[] args) throws Exception { + + // print message. + System.out.println("DONE!"); + } +} diff --git a/CodeGen/BMapBindings/README.md b/CodeGen/BMapBindings/README.md index 37cf3e3..41189f2 100644 --- a/CodeGen/BMapBindings/README.md +++ b/CodeGen/BMapBindings/README.md @@ -4,3 +4,14 @@ A helper program to generate BMap binding in Python and CSharp This program is consisted by 2 parts, first is Python part which extract BMap interface function declarations from source file, thus following Antlr step can focus on syntax analyze. Next part is Antlr part. It analyse extracted function declarations and output corresponding Python binding and CSharp binding. + +``` +python ExtractBMapFctDecl.py + +antlr4 ExpFctsLexer.g4 +antlr4 ExpFctsParser.g4 + +javac *.java +java MainRunner +``` + diff --git a/CodeGen/BMapBindings/VariableType.java b/CodeGen/BMapBindings/VariableType.java new file mode 100644 index 0000000..d26aff9 --- /dev/null +++ b/CodeGen/BMapBindings/VariableType.java @@ -0,0 +1,57 @@ +import java.util.Collections; + +public class VariableType { + /** + * The base type of this variable which remove all ending stars. + */ + private String mBaseType; + /** + * The pointer level of this type. It is equal with the count of stars. + */ + private int mPointerLevel; + + public VariableType(String ctype) { + fromCType(ctype); + } + + private VariableType(String base_type, int pointer_level) { + mBaseType = base_type; + mPointerLevel = pointer_level; + } + + public void fromCType(String ctype) { + if (ctype.isEmpty()) + throw new IllegalArgumentException("empty string can not be parsed."); + + int len = ctype.length(); + int star_pos = ctype.indexOf('*'); + if (star_pos == -1) { + // no star + mBaseType = ctype; + mPointerLevel = 0; + } else { + // has star + if (star_pos == 0) + throw new IllegalArgumentException("base type not found."); + mBaseType = ctype.substring(0, star_pos); + mPointerLevel = len - star_pos; + } + } + + public String toCType() { + return mBaseType + String.join("", Collections.nCopies(mPointerLevel, "*")); + } + + public String getBaseType() { + return mBaseType; + } + + public boolean isPointer() { + return mPointerLevel != 0; + } + + public VariableType getPointerOfThis() { + return new VariableType(mBaseType, mPointerLevel); + } + +} diff --git a/README.md b/README.md index 544cc1a..149231c 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,6 @@ There are 3 lists which indicate our accept guideline. These features will be accepted as soon as possible. * The bug fix of any existing code. -* Class layout, `Load()` functions of following `CKObject` based classes. - - None -* Class layout, and `LoadData()` functions of following `CKBaseManager` based classes. - - `CKAttributeManager` ### Not Urgent Features