2023-11-02 12:40:50 +08:00
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
2023-11-02 10:53:16 +08:00
|
|
|
public class ExpFctsWalker extends ExpFctsParserBaseListener {
|
2023-11-02 12:40:50 +08:00
|
|
|
|
|
|
|
|
public ExpFctsWalker() {
|
2026-01-28 12:00:40 +08:00
|
|
|
mFctCollection = null;
|
2023-11-02 12:40:50 +08:00
|
|
|
mCurrentFct = null;
|
|
|
|
|
mCurrentParam = null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 12:00:40 +08:00
|
|
|
public ExpFctsHelper.ExpFctCollection getResult() {
|
|
|
|
|
return mFctCollection;
|
2023-11-02 12:40:50 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-28 12:00:40 +08:00
|
|
|
private ExpFctsHelper.ExpFctCollection mFctCollection;
|
|
|
|
|
private ExpFctsHelper.ExpFct mCurrentFct;
|
|
|
|
|
private ExpFctsHelper.ExpFctParam mCurrentParam;
|
2023-11-02 12:40:50 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void enterProgram(ExpFctsParser.ProgramContext ctx) {
|
2026-01-28 12:00:40 +08:00
|
|
|
mFctCollection = new ExpFctsHelper.ExpFctCollection();
|
2023-11-02 12:40:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void enterFctDecl(ExpFctsParser.FctDeclContext ctx) {
|
2026-01-28 12:00:40 +08:00
|
|
|
mCurrentFct = new ExpFctsHelper.ExpFct();
|
2023-11-02 12:40:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exitFctDecl(ExpFctsParser.FctDeclContext ctx) {
|
2023-11-02 22:02:39 +08:00
|
|
|
// set name
|
2023-11-02 12:40:50 +08:00
|
|
|
mCurrentFct.mFctName = ctx.EXPFCTS_IDENTIFIER().getText();
|
2023-11-02 22:02:39 +08:00
|
|
|
// check return type
|
|
|
|
|
if (!mCurrentFct.mFctRetType.isValid() || mCurrentFct.mFctRetType.isPointer()
|
|
|
|
|
|| !mCurrentFct.mFctRetType.getBaseType().equals("bool"))
|
|
|
|
|
throw new IllegalArgumentException("invalid interface function return type. must be bool.");
|
|
|
|
|
|
|
|
|
|
// add into list
|
2026-01-28 12:00:40 +08:00
|
|
|
mFctCollection.mFcts.add(mCurrentFct);
|
2023-11-02 12:40:50 +08:00
|
|
|
mCurrentFct = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exitFctArgFileDecl(ExpFctsParser.FctArgFileDeclContext ctx) {
|
2026-01-28 12:00:40 +08:00
|
|
|
ExpFctsHelper.ExpFctParam param = new ExpFctsHelper.ExpFctParam();
|
|
|
|
|
param.mVarName = ctx.EXPFCTS_IDENTIFIER().getText();
|
|
|
|
|
param.mVarDesc = "The pointer to corresponding BMFile.";
|
|
|
|
|
param.mIsInput = true;
|
|
|
|
|
param.mVarType.fromCType("BMap::BMFile*");
|
|
|
|
|
mCurrentFct.mFctParams.add(param);
|
2023-11-02 12:40:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exitFctArgMeshTransDecl(ExpFctsParser.FctArgMeshTransDeclContext ctx) {
|
2026-01-28 12:00:40 +08:00
|
|
|
ExpFctsHelper.ExpFctParam param = new ExpFctsHelper.ExpFctParam();
|
|
|
|
|
param.mVarName = ctx.EXPFCTS_IDENTIFIER().getText();
|
|
|
|
|
param.mVarDesc = "The pointer to corresponding BMMeshTransition.";
|
|
|
|
|
param.mIsInput = true;
|
|
|
|
|
param.mVarType.fromCType("BMap::BMMeshTransition*");
|
|
|
|
|
mCurrentFct.mFctParams.add(param);
|
2023-11-02 12:40:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exitFctArgObjDecl(ExpFctsParser.FctArgObjDeclContext ctx) {
|
2026-01-28 12:00:40 +08:00
|
|
|
ExpFctsHelper.ExpFctParam firstParam = new ExpFctsHelper.ExpFctParam();
|
|
|
|
|
firstParam.mVarName = ctx.EXPFCTS_IDENTIFIER(0).getText();
|
|
|
|
|
firstParam.mVarDesc = "The pointer to corresponding BMFile.";
|
|
|
|
|
firstParam.mIsInput = true;
|
|
|
|
|
firstParam.mVarType.fromCType("BMap::BMFile*");
|
|
|
|
|
mCurrentFct.mFctParams.add(firstParam);
|
|
|
|
|
|
|
|
|
|
ExpFctsHelper.ExpFctParam secondParam = new ExpFctsHelper.ExpFctParam();
|
|
|
|
|
secondParam.mVarName = ctx.EXPFCTS_IDENTIFIER(1).getText();
|
|
|
|
|
secondParam.mVarDesc = "The CKID of object you accessing.";
|
|
|
|
|
secondParam.mIsInput = true;
|
|
|
|
|
secondParam.mVarType.fromCType("LibCmo::CK2::CK_ID");
|
|
|
|
|
mCurrentFct.mFctParams.add(secondParam);
|
2023-11-02 12:40:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void enterFctArgParamIn(ExpFctsParser.FctArgParamInContext ctx) {
|
2026-01-28 12:00:40 +08:00
|
|
|
mCurrentParam = new ExpFctsHelper.ExpFctParam();
|
2023-11-02 12:40:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exitFctArgParamIn(ExpFctsParser.FctArgParamInContext ctx) {
|
|
|
|
|
mCurrentParam.mVarName = ctx.EXPFCTS_IDENTIFIER().getText();
|
|
|
|
|
mCurrentParam.mIsInput = true;
|
2023-11-02 22:02:39 +08:00
|
|
|
|
2023-11-02 12:40:50 +08:00
|
|
|
mCurrentFct.mFctParams.add(mCurrentParam);
|
|
|
|
|
mCurrentParam = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void enterFctArgParamOut(ExpFctsParser.FctArgParamOutContext ctx) {
|
2026-01-28 12:00:40 +08:00
|
|
|
mCurrentParam = new ExpFctsHelper.ExpFctParam();
|
2023-11-02 12:40:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exitFctArgParamOut(ExpFctsParser.FctArgParamOutContext ctx) {
|
|
|
|
|
mCurrentParam.mVarName = ctx.EXPFCTS_IDENTIFIER().getText();
|
|
|
|
|
mCurrentParam.mIsInput = false;
|
|
|
|
|
// set to its pointer type
|
2023-11-02 22:02:39 +08:00
|
|
|
// mCurrentParam.mVarType = mCurrentParam.mVarType.getPointerOfThis();
|
|
|
|
|
|
2023-11-02 12:40:50 +08:00
|
|
|
mCurrentFct.mFctParams.add(mCurrentParam);
|
|
|
|
|
mCurrentParam = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exitVarType(ExpFctsParser.VarTypeContext ctx) {
|
|
|
|
|
// get namespace parts and join them
|
|
|
|
|
String ctype = ctx.EXPFCTS_IDENTIFIER().stream().map(value -> value.getText())
|
|
|
|
|
.collect(Collectors.joining("::"));
|
|
|
|
|
// add star if necessary
|
|
|
|
|
if (ctx.EXPFCTS_STAR() != null) {
|
|
|
|
|
ctype += String.join("", Collections.nCopies(ctx.EXPFCTS_STAR().size(), "*"));
|
|
|
|
|
}
|
2023-11-02 22:02:39 +08:00
|
|
|
|
2023-11-02 12:40:50 +08:00
|
|
|
if (!mCurrentFct.mFctRetType.isValid()) {
|
|
|
|
|
// fill function ret type first
|
|
|
|
|
mCurrentFct.mFctRetType.fromCType(ctype);
|
|
|
|
|
} else {
|
|
|
|
|
// otherwise, fill param data
|
|
|
|
|
mCurrentParam.mVarType.fromCType(ctype);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-02 10:53:16 +08:00
|
|
|
}
|