refactor (5/?)

This commit is contained in:
2023-08-26 20:34:51 +08:00
parent 47bf6ab6c6
commit 8a1f71e855
16 changed files with 582 additions and 378 deletions

View File

@ -5,12 +5,8 @@ import java.util.stream.Collectors;
* The nameof values writer for CK_CLASSID.
*/
public class ClassidWriter {
public static void writeNameofClassid(OutputStreamWriter writer, EnumsHelper.Enum_t classids) throws Exception {
public static void writeAccVals(OutputStreamWriter writer, EnumsHelper.Enum_t classids) throws Exception {
IndentHelper indent = new IndentHelper(writer);
indent.puts("struct CkClassidReflection { std::vector<const char*> mHierarchy; };");
indent.puts(
"using CkClassidReflectionArray = std::vector<std::pair<LibCmo::CK2::CK_CLASSID, CkClassidReflection>>;");
indent.puts("");
indent.puts("const CkClassidReflectionArray CK_CLASSID {");
indent.inc();

View File

@ -4,13 +4,9 @@ import java.io.OutputStreamWriter;
* The nameof values writer for CKERROR
*/
public class ErrorsWriter {
public static void writeNameofError(OutputStreamWriter writer, EnumsHelper.Enum_t errors) throws Exception {
public static void writeAccVals(OutputStreamWriter writer, EnumsHelper.Enum_t errors) throws Exception {
IndentHelper indent = new IndentHelper(writer);
indent.puts("struct CkErrorReflection { const char* mName; const char* mDescription; };");
indent.puts("using CkErrorReflectionArray = std::vector<std::pair<LibCmo::CK2::CKERROR, CkErrorReflection>>;");
indent.puts("");
indent.puts("const CkErrorReflectionArray CKERROR {");
indent.inc();
for (EnumsHelper.EnumEntry_t entry : errors.mEntries) {

View File

@ -4,6 +4,7 @@ import java.io.OutputStreamWriter;
* Generic Enum Writer. Including Data Type Defination and Nameof Values.
*/
public class GeneralWriter {
public static void writeEnums(OutputStreamWriter writer, EnumsHelper.EnumCollection_t prog) throws Exception {
IndentHelper indent = new IndentHelper(writer);
for (EnumsHelper.Enum_t enum_t : prog.mEnums) {
@ -31,18 +32,29 @@ public class GeneralWriter {
// write enum tail
indent.dec();
indent.puts("};");
indent.printf("LIBCMO_BITFLAG_OPERATORS(%s);", enum_t.mEnumName);
}
}
public static void writeNameofValues(OutputStreamWriter writer, EnumsHelper.EnumCollection_t prog,
public static void writeEnum(OutputStreamWriter writer, EnumsHelper.Enum_t _enum) throws Exception {
EnumsHelper.EnumCollection_t col = new EnumsHelper.EnumCollection_t();
col.mEnums.add(_enum);
writeEnums(writer, col);
}
public static void writeAccVals(OutputStreamWriter writer, EnumsHelper.EnumCollection_t prog,
CommonHelper.CKParts parts) throws Exception {
IndentHelper indent = new IndentHelper(writer);
// write decls
for (EnumsHelper.Enum_t enum_t : prog.mEnums) {
indent.printf("extern const GeneralReflectionArray<LibCmo::%s::%s> %s;", CommonHelper.getCKPartsNamespace(parts),
enum_t.mEnumName, enum_t.mEnumName);
}
indent.puts("struct GeneralReflection { const char* mName; };");
indent.puts("template<typename _Ty>;");
indent.puts("using GeneralReflectionArray = std::vector<std::pair<TEnum, GeneralReflection>>;");
indent.puts("");
indent.puts("");
indent.puts("");
// write implements
for (EnumsHelper.Enum_t enum_t : prog.mEnums) {
// write enum desc header
indent.printf("const GeneralReflectionArray<LibCmo::%s::%s> %s {", CommonHelper.getCKPartsNamespace(parts),
@ -60,4 +72,12 @@ public class GeneralWriter {
indent.puts("};");
}
}
public static void writeAccVal(OutputStreamWriter writer, EnumsHelper.Enum_t _enum, CommonHelper.CKParts parts)
throws Exception {
EnumsHelper.EnumCollection_t col = new EnumsHelper.EnumCollection_t();
col.mEnums.add(_enum);
writeAccVals(writer, col, parts);
}
}

View File

@ -38,7 +38,7 @@ public class MainRunner {
return result;
}
private static EnumsHelper.Enum_t organiseClassid(String infile, String assignedEnumName) throws Exception {
private static EnumsHelper.Enum_t organiseClassid(String infile) throws Exception {
CommonHelper.InputFilePair pair = CommonHelper.openInputFile(infile);
CKGeneralLexer lexer = new CKGeneralLexer(pair.mAntlrStream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
@ -52,61 +52,71 @@ public class MainRunner {
pair.mUnderlyingStream.close();
EnumsHelper.Enum_t result = worker.getEnum();
result.mEnumName = assignedEnumName;
result.mEnumName = "CK_CLASSID";
return result;
}
public static void main(String[] args) throws Exception {
OutputStreamWriter fs = null;
// =========== Read Data ===========
// read enum series first.
// these file are originally is enum in Virtools SDK
EnumsHelper.EnumCollection_t ck2Enums = getEnumsCollection("src/CKEnums.txt"),
vxEnums = getEnumsCollection("src/VxEnums.txt"),
def2 = getEnumsCollection("src/Defines2.txt");
// read and reorganize #define type enum
// read CKERROR standalone. because we need treat it specialized.
// =========== CKERROR ===========
EnumsHelper.Enum_t ckerror = organiseDefines("src/CKError.txt", "CKERROR");
// read CK_CLASSID standalone in another way.
EnumsHelper.Enum_t classid = organiseClassid("src/Classid.txt", "CK_CLASSID");
// these enum can be directly merge into previous read enum collection
// because we do not need process it independently.
ck2Enums.mEnums.add(organiseDefines("src/CK_STATECHUNK_CHUNKVERSION.txt", "CK_STATECHUNK_CHUNKVERSION"));
ck2Enums.mEnums.add(organiseDefines("src/CK_STATECHUNK_DATAVERSION.txt", "CK_STATECHUNK_DATAVERSION"));
// =========== Write Nameof Values ===========
// write general accessible values
fs = CommonHelper.openOutputFile("dest/CKEnums.NameofValue.hpp");
GeneralWriter.writeNameofValues(fs, ck2Enums, CommonHelper.CKParts.CK2);
fs = CommonHelper.openOutputFile("dest/CKError.hpp");
GeneralWriter.writeEnum(fs, ckerror);
fs.close();
fs = CommonHelper.openOutputFile("dest/VxEnums.NameofValue.hpp");
GeneralWriter.writeNameofValues(fs, vxEnums, CommonHelper.CKParts.VxMath);
fs.close();
// write CKERROR
fs = CommonHelper.openOutputFile("dest/CKError.NameofValue.hpp");
ErrorsWriter.writeNameofError(fs, ckerror);
fs.close();
// write CK_CLASSID
fs = CommonHelper.openOutputFile("dest/CKClassid.NameofValue.hpp");
ClassidWriter.writeNameofClassid(fs, classid);
fs = CommonHelper.openOutputFile("dest/CKError.AccVal.hpp");
ErrorsWriter.writeAccVals(fs, ckerror);
fs.close();
// write data type defines
// CKERROR and CK_CLASSID should be grouped into ck2Enums
ck2Enums.mEnums.add(ckerror);
ck2Enums.mEnums.add(classid);
// =========== CK_CLASSID ===========
EnumsHelper.Enum_t classid = organiseClassid("src/CK_CLASSID.txt");
fs = CommonHelper.openOutputFile("dest/CK_CLASSID.hpp");
GeneralWriter.writeEnum(fs, classid);
fs.close();
fs = CommonHelper.openOutputFile("dest/CK_CLASSID.AccVal.hpp");
ClassidWriter.writeAccVals(fs, classid);
fs.close();
// =========== 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");
fs = CommonHelper.openOutputFile("dest/CKEnums.hpp");
GeneralWriter.writeEnums(fs, ck2Enums);
fs.close();
fs = CommonHelper.openOutputFile("dest/CKEnums.AccVal.hpp");
GeneralWriter.writeAccVals(fs, ck2Enums, CommonHelper.CKParts.CK2);
fs.close();
fs = CommonHelper.openOutputFile("dest/VxEnums.hpp");
GeneralWriter.writeEnums(fs, vxEnums);
fs.close();
// Defines2.h need independentlt write
fs = CommonHelper.openOutputFile("dest/Def2.hpp");
GeneralWriter.writeEnums(fs, def2);
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);
fs.close();
// print message.

View File

@ -54,6 +54,45 @@ typedef enum CK_LOAD_FLAGS {
// or because the loaded object already exist in the current level
// and the user choose to keep the existing one.
};
/*************************************************
{filename:CK_LOADMODE}
Summary: Specify the way an object just loaded should be handled when it already exists in the level.
{secret}
See also:
*************************************************/
typedef enum CK_LOADMODE
{
CKLOAD_INVALID=-1,// Use the existing object instead of loading
CKLOAD_OK=0, // Ignore ( Name unicity is broken )
CKLOAD_REPLACE=1, // Replace the existing object (Not yet implemented)
CKLOAD_RENAME=2, // Rename the loaded object
CKLOAD_USECURRENT=3,// Use the existing object instead of loading
} CK_LOADMODE;
/*************************************************
{filename:CK_OBJECTCREATION_OPTIONS}
Summary: Specify the way an object is created through CKCreateObject.
Remarks:
+ These flag controls the way an object is created, the most important of these flags
being CK_OBJECTCREATION_DYNAMIC which, if set in CKCreateObject, make the newly created object
dynamic.
See also: CKContext::CreateObject,Dynamic Objects
*************************************************/
enum CK_OBJECTCREATION_OPTIONS
{
CK_OBJECTCREATION_NONAMECHECK = 0, // Do not test for name unicity (may be overriden in special case)
CK_OBJECTCREATION_REPLACE = 1, // Replace the current object by the object being loaded
CK_OBJECTCREATION_RENAME = 2, // Rename the created object to ensure its uniqueness
CK_OBJECTCREATION_USECURRENT = 3, // Do not create a new object, use the one with the same name instead
CK_OBJECTCREATION_ASK = 4, // If a duplicate name if found, opens a dialog box to ask the useror use automatic load mode if any.
CK_OBJECTCREATION_FLAGSMASK = 0x0000000F, // Mask for previous values
CK_OBJECTCREATION_DYNAMIC = 0x00000010, // The object must be created dynamic
CK_OBJECTCREATION_ACTIVATE = 0x00000020, // The object will be copied/created active
CK_OBJECTCREATION_NONAMECOPY = 0x00000040 // The object will take control of the string given to it directly, without copying it
};
/*************************************************
{filename:CK_PLUGIN_TYPE}