2023-08-20 16:10:22 +08:00
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
|
|
|
|
import org.antlr.v4.runtime.*;
|
|
|
|
import org.antlr.v4.runtime.tree.*;
|
|
|
|
|
|
|
|
public class MainRunner {
|
|
|
|
|
|
|
|
private static EnumsHelper.EnumCollection_t getEnumsCollection(String infile) throws Exception {
|
|
|
|
CommonHelper.InputFilePair pair = CommonHelper.openInputFile(infile);
|
|
|
|
CKGeneralLexer lexer = new CKGeneralLexer(pair.mAntlrStream);
|
|
|
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
|
|
|
CKEnumsParser parser = new CKEnumsParser(tokens);
|
|
|
|
|
|
|
|
ParseTree tree = parser.prog();
|
|
|
|
ParseTreeWalker walker = new ParseTreeWalker();
|
|
|
|
EnumsWalker worker = new EnumsWalker(tokens);
|
|
|
|
walker.walk(worker, tree);
|
|
|
|
|
|
|
|
pair.mUnderlyingStream.close();
|
|
|
|
return worker.getEnums();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static EnumsHelper.Enum_t organiseDefines(String infile, String assignedEnumName) throws Exception {
|
|
|
|
CommonHelper.InputFilePair pair = CommonHelper.openInputFile(infile);
|
|
|
|
CKGeneralLexer lexer = new CKGeneralLexer(pair.mAntlrStream);
|
|
|
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
|
|
|
CKDefinesParser parser = new CKDefinesParser(tokens);
|
|
|
|
|
|
|
|
ParseTree tree = parser.prog();
|
|
|
|
ParseTreeWalker walker = new ParseTreeWalker();
|
|
|
|
DefinesWalker worker = new DefinesWalker(tokens);
|
|
|
|
walker.walk(worker, tree);
|
|
|
|
|
|
|
|
pair.mUnderlyingStream.close();
|
|
|
|
|
|
|
|
EnumsHelper.Enum_t result = worker.getEnum();
|
|
|
|
result.mEnumName = assignedEnumName;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-08-26 20:34:51 +08:00
|
|
|
private static EnumsHelper.Enum_t organiseClassid(String infile) throws Exception {
|
2023-08-20 16:10:22 +08:00
|
|
|
CommonHelper.InputFilePair pair = CommonHelper.openInputFile(infile);
|
|
|
|
CKGeneralLexer lexer = new CKGeneralLexer(pair.mAntlrStream);
|
|
|
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
|
|
|
CKDefinesParser parser = new CKDefinesParser(tokens);
|
|
|
|
|
|
|
|
ParseTree tree = parser.prog();
|
|
|
|
ParseTreeWalker walker = new ParseTreeWalker();
|
|
|
|
ClassidWalker worker = new ClassidWalker(tokens);
|
|
|
|
walker.walk(worker, tree);
|
|
|
|
|
|
|
|
pair.mUnderlyingStream.close();
|
|
|
|
|
|
|
|
EnumsHelper.Enum_t result = worker.getEnum();
|
2023-08-26 20:34:51 +08:00
|
|
|
result.mEnumName = "CK_CLASSID";
|
2023-08-20 16:10:22 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
OutputStreamWriter fs = null;
|
2023-08-20 21:38:16 +08:00
|
|
|
|
2023-08-26 20:34:51 +08:00
|
|
|
// =========== CKERROR ===========
|
2023-08-20 21:38:16 +08:00
|
|
|
EnumsHelper.Enum_t ckerror = organiseDefines("src/CKError.txt", "CKERROR");
|
2023-08-26 20:34:51 +08:00
|
|
|
fs = CommonHelper.openOutputFile("dest/CKError.hpp");
|
|
|
|
GeneralWriter.writeEnum(fs, ckerror);
|
2023-08-20 16:10:22 +08:00
|
|
|
fs.close();
|
2023-08-26 20:34:51 +08:00
|
|
|
fs = CommonHelper.openOutputFile("dest/CKError.AccVal.hpp");
|
|
|
|
ErrorsWriter.writeAccVals(fs, ckerror);
|
2023-08-20 16:10:22 +08:00
|
|
|
fs.close();
|
2023-08-26 20:34:51 +08:00
|
|
|
|
|
|
|
// =========== CK_CLASSID ===========
|
|
|
|
EnumsHelper.Enum_t classid = organiseClassid("src/CK_CLASSID.txt");
|
|
|
|
fs = CommonHelper.openOutputFile("dest/CK_CLASSID.hpp");
|
|
|
|
GeneralWriter.writeEnum(fs, classid);
|
2023-08-20 16:10:22 +08:00
|
|
|
fs.close();
|
2023-08-26 20:34:51 +08:00
|
|
|
fs = CommonHelper.openOutputFile("dest/CK_CLASSID.AccVal.hpp");
|
|
|
|
ClassidWriter.writeAccVals(fs, classid);
|
2023-08-20 21:38:16 +08:00
|
|
|
fs.close();
|
|
|
|
|
2023-08-26 20:34:51 +08:00
|
|
|
// =========== Define2 ===========
|
|
|
|
// Define2 do not need values.
|
|
|
|
EnumsHelper.EnumCollection_t def2 = getEnumsCollection("src/Defines2.txt");
|
|
|
|
fs = CommonHelper.openOutputFile("dest/CK_CLASSID.hpp");
|
|
|
|
GeneralWriter.writeEnums(fs, def2);
|
|
|
|
fs.close();
|
|
|
|
|
|
|
|
// =========== Combined enums ===========
|
|
|
|
EnumsHelper.EnumCollection_t ck2Enums = getEnumsCollection("src/CKEnums.txt"),
|
|
|
|
vxEnums = getEnumsCollection("src/VxEnums.txt");
|
2023-08-20 21:38:16 +08:00
|
|
|
fs = CommonHelper.openOutputFile("dest/CKEnums.hpp");
|
|
|
|
GeneralWriter.writeEnums(fs, ck2Enums);
|
|
|
|
fs.close();
|
2023-08-26 20:34:51 +08:00
|
|
|
fs = CommonHelper.openOutputFile("dest/CKEnums.AccVal.hpp");
|
|
|
|
GeneralWriter.writeAccVals(fs, ck2Enums, CommonHelper.CKParts.CK2);
|
|
|
|
fs.close();
|
2023-08-20 21:38:16 +08:00
|
|
|
fs = CommonHelper.openOutputFile("dest/VxEnums.hpp");
|
|
|
|
GeneralWriter.writeEnums(fs, vxEnums);
|
|
|
|
fs.close();
|
2023-08-26 20:34:51 +08:00
|
|
|
fs = CommonHelper.openOutputFile("dest/VxEnums.AccVal.hpp");
|
|
|
|
GeneralWriter.writeAccVals(fs, vxEnums, CommonHelper.CKParts.VxMath);
|
|
|
|
fs.close();
|
|
|
|
|
|
|
|
// =========== Single enums ===========
|
|
|
|
EnumsHelper.Enum_t single;
|
|
|
|
|
|
|
|
single = organiseDefines("src/CK_STATECHUNK_CHUNKVERSION.txt", "CK_STATECHUNK_CHUNKVERSION");
|
|
|
|
fs = CommonHelper.openOutputFile("dest/CK_STATECHUNK_CHUNKVERSION.hpp");
|
|
|
|
GeneralWriter.writeEnum(fs, single);
|
|
|
|
fs.close();
|
|
|
|
fs = CommonHelper.openOutputFile("dest/CK_STATECHUNK_CHUNKVERSION.AccVal.hpp");
|
|
|
|
GeneralWriter.writeAccVal(fs, single, CommonHelper.CKParts.CK2);
|
|
|
|
fs.close();
|
|
|
|
|
|
|
|
single = organiseDefines("src/CK_STATECHUNK_DATAVERSION.txt", "CK_STATECHUNK_DATAVERSION");
|
|
|
|
fs = CommonHelper.openOutputFile("dest/CK_STATECHUNK_DATAVERSION.hpp");
|
|
|
|
GeneralWriter.writeEnum(fs, single);
|
|
|
|
fs.close();
|
|
|
|
fs = CommonHelper.openOutputFile("dest/CK_STATECHUNK_DATAVERSION.AccVal.hpp");
|
|
|
|
GeneralWriter.writeAccVal(fs, single, CommonHelper.CKParts.CK2);
|
2023-08-20 16:10:22 +08:00
|
|
|
fs.close();
|
2023-08-22 15:30:26 +08:00
|
|
|
|
2023-08-20 16:10:22 +08:00
|
|
|
// print message.
|
|
|
|
System.out.println("DONE!");
|
|
|
|
}
|
|
|
|
}
|