write binding code
This commit is contained in:
parent
ef5d1760a3
commit
68bffefe5a
3
CodeGen/BMapBindings/.gitignore
vendored
3
CodeGen/BMapBindings/.gitignore
vendored
|
@ -2,6 +2,9 @@
|
|||
*.interp
|
||||
*.tokens
|
||||
|
||||
ExpFctsLexer*.java
|
||||
ExpFctsParser*.java
|
||||
|
||||
# ===== Python =====
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
|
16
CodeGen/BMapBindings/ExpFctDecl.java
Normal file
16
CodeGen/BMapBindings/ExpFctDecl.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
import java.util.Vector;
|
||||
|
||||
public class ExpFctDecl {
|
||||
|
||||
public String mFctName;
|
||||
public VariableType mFctRetType;
|
||||
public Vector<ExpFctParamDecl> mFctParams;
|
||||
|
||||
public ExpFctDecl(String fct_name, VariableType ret_type) {
|
||||
mFctName = fct_name;
|
||||
mFctRetType = ret_type;
|
||||
mFctParams = new Vector<ExpFctParamDecl>();
|
||||
}
|
||||
|
||||
}
|
||||
|
12
CodeGen/BMapBindings/ExpFctParamDecl.java
Normal file
12
CodeGen/BMapBindings/ExpFctParamDecl.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
public class ExpFctParamDecl {
|
||||
|
||||
public VariableType mVarType;
|
||||
public String mVarName;
|
||||
|
||||
public ExpFctParamDecl(VariableType vtype, String vname) {
|
||||
mVarType = vtype;
|
||||
mVarName = vname;
|
||||
}
|
||||
|
||||
}
|
6
CodeGen/BMapBindings/ExpFctsWalker.java
Normal file
6
CodeGen/BMapBindings/ExpFctsWalker.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.tree.*;
|
||||
|
||||
public class ExpFctsWalker extends ExpFctsParserBaseListener {
|
||||
|
||||
}
|
11
CodeGen/BMapBindings/MainRunner.java
Normal file
11
CodeGen/BMapBindings/MainRunner.java
Normal file
|
@ -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!");
|
||||
}
|
||||
}
|
|
@ -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
|
||||
```
|
||||
|
||||
|
|
57
CodeGen/BMapBindings/VariableType.java
Normal file
57
CodeGen/BMapBindings/VariableType.java
Normal file
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user