fix: finish enums migration
This commit is contained in:
@@ -1,168 +0,0 @@
|
|||||||
import java.io.OutputStreamWriter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write enum declarations and accessible value into CSharp format.
|
|
||||||
*/
|
|
||||||
public class CSharpWriter {
|
|
||||||
|
|
||||||
// =========== C# Enum Declaration Writer ===========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get corredponding C# underlying type of given enum.
|
|
||||||
* <p>
|
|
||||||
* This is C# specific function.
|
|
||||||
*
|
|
||||||
* @param canUnsigned The parameter stored in Enum_t that indicate whether this
|
|
||||||
* enum can use unsigned int as its underlying type.
|
|
||||||
* @return The string form of its underlying type.
|
|
||||||
*/
|
|
||||||
private static String getEnumUnderlyingType(boolean canUnsigned) {
|
|
||||||
return canUnsigned ? "uint" : "int";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal real enum declaration writer.
|
|
||||||
*
|
|
||||||
* @param writer {@linkplain java.io.OutputStreamWriter} instance for writing.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private static void internalWriteEnums(OutputStreamWriter writer, EnumsHelper.BEnumCollection prog)
|
|
||||||
throws Exception {
|
|
||||||
IndentHelper indent = new IndentHelper(writer, CommonHelper.LangType.CSharp);
|
|
||||||
for (EnumsHelper.BEnum benum : prog.mEnums) {
|
|
||||||
// write enum comment
|
|
||||||
indent.briefComment(benum.mEnumComment);
|
|
||||||
|
|
||||||
// write enum start
|
|
||||||
// write flasg attribute if it is
|
|
||||||
if (benum.mUseFlags) {
|
|
||||||
indent.puts("[Flags]");
|
|
||||||
}
|
|
||||||
indent.printf("public enum %s : %s {", benum.mEnumName, getEnumUnderlyingType(benum.mCanUnsigned));
|
|
||||||
indent.inc();
|
|
||||||
|
|
||||||
// write enum entries
|
|
||||||
for (EnumsHelper.BEnumEntry enumEntry : benum.mEntries) {
|
|
||||||
// write entry self
|
|
||||||
if (enumEntry.mEntryValue == null) {
|
|
||||||
indent.printf("%s,", enumEntry.mEntryName);
|
|
||||||
} else {
|
|
||||||
indent.printf("%s = %s,", enumEntry.mEntryName, enumEntry.mEntryValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write entry comment after member
|
|
||||||
indent.afterMemberComment(enumEntry.mEntryComment);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write enum tail
|
|
||||||
indent.dec();
|
|
||||||
indent.puts("}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write an enum declaration collection into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum declaration collection writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for
|
|
||||||
* writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeEnums(String filename, EnumsHelper.BEnumCollection prog) throws Exception {
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteEnums(fs, prog);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write a single enum declaration into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum declaration collection writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param _enum {@linkplain EnumsHelper.BEnum} instance for writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeEnum(String filename, EnumsHelper.BEnum _enum) throws Exception {
|
|
||||||
// create collection from single enum
|
|
||||||
EnumsHelper.BEnumCollection col = new EnumsHelper.BEnumCollection();
|
|
||||||
col.mEnums.add(_enum);
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteEnums(fs, col);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========== C# Enum Accessible Value Writer ===========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal real enum accessible value writer.
|
|
||||||
*
|
|
||||||
* @param writer {@linkplain java.io.OutputStreamWriter} instance for writing.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private static void internalWriteAccVals(OutputStreamWriter writer, EnumsHelper.BEnumCollection prog)
|
|
||||||
throws Exception {
|
|
||||||
IndentHelper indent = new IndentHelper(writer, CommonHelper.LangType.CSharp);
|
|
||||||
// write enum collections
|
|
||||||
for (EnumsHelper.BEnum benum : prog.mEnums) {
|
|
||||||
// write enum desc header
|
|
||||||
indent.printf(
|
|
||||||
"public static readonly System.Collections.Generic.Dictionary<%s, string> %s = new System.Collections.Generic.Dictionary<%s, string>() {",
|
|
||||||
benum.mEnumName, benum.mEnumName, benum.mEnumName);
|
|
||||||
indent.inc();
|
|
||||||
|
|
||||||
// write enum desc entries
|
|
||||||
for (EnumsHelper.BEnumEntry enumEntry : benum.mEntries) {
|
|
||||||
indent.printf("{ %s.%s, \"%s\" },", benum.mEnumName, enumEntry.mEntryName, enumEntry.mEntryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write enum tail
|
|
||||||
indent.dec();
|
|
||||||
indent.puts("};");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write an enum accessible value collection into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum accessible value collection
|
|
||||||
* writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for
|
|
||||||
* writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeAccVals(String filename, EnumsHelper.BEnumCollection prog) throws Exception {
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteAccVals(fs, prog);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write a single enum accessible value into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum accessible value collection
|
|
||||||
* writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param _enum {@linkplain EnumsHelper.BEnum} instance for writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeAccVal(String filename, EnumsHelper.BEnum _enum) throws Exception {
|
|
||||||
// create a collection with single enum.
|
|
||||||
EnumsHelper.BEnumCollection col = new EnumsHelper.BEnumCollection();
|
|
||||||
col.mEnums.add(_enum);
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteAccVals(fs, col);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@@ -48,11 +47,35 @@ public class CommonHelper {
|
|||||||
|
|
||||||
switch (comment.getType()) {
|
switch (comment.getType()) {
|
||||||
case CKGeneralLexer.CKGENERAL_LINE_COMMENT: {
|
case CKGeneralLexer.CKGENERAL_LINE_COMMENT: {
|
||||||
return removeStars(comment.getText().substring(2));
|
// For line comment, we start to remove "//" prefix first
|
||||||
|
String slashRemoved = comment.getText().substring(2);
|
||||||
|
// Then remove successive starts
|
||||||
|
String starsRemoved = removeSeperator(slashRemoved);
|
||||||
|
// Do a strip for it.
|
||||||
|
String stripped = starsRemoved.strip();
|
||||||
|
// Then remove EOL to avoid unexpected line break.
|
||||||
|
String eolRemoved = removeEol(stripped);
|
||||||
|
// Okey
|
||||||
|
return eolRemoved;
|
||||||
}
|
}
|
||||||
case CKGeneralLexer.CKGENERAL_BLOCK_COMMENT: {
|
case CKGeneralLexer.CKGENERAL_BLOCK_COMMENT: {
|
||||||
String cache = comment.getText();
|
// For block comment, we first cut "/*" head and "*/" tail.
|
||||||
return removeStars(cache.substring(2, cache.length() - 4));
|
String blockComment = comment.getText();
|
||||||
|
String slashRemoved = blockComment.substring(2, blockComment.length() - 4);
|
||||||
|
|
||||||
|
// Then we break it at line breaker and process each line one by one.
|
||||||
|
String beautyComment = slashRemoved.lines().map((String line) -> {
|
||||||
|
// Remove successive starts
|
||||||
|
String starsRemoved = removeSeperator(line);
|
||||||
|
// Do a strip for it.
|
||||||
|
String stripped = starsRemoved.strip();
|
||||||
|
// Then remove EOL to avoid unexpected line break.
|
||||||
|
String eolRemoved = removeEol(stripped);
|
||||||
|
// Line process is okey now
|
||||||
|
return eolRemoved;
|
||||||
|
}).collect(Collectors.joining("\n")); // Then re-join with fresh line breaker
|
||||||
|
// Then return
|
||||||
|
return beautyComment;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return comment.getText();
|
return comment.getText();
|
||||||
@@ -73,9 +96,8 @@ public class CommonHelper {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
return tokens.stream().map(value -> {
|
return tokens.stream().map(value -> {
|
||||||
String text = cutComment(value).strip();
|
return cutComment(value);
|
||||||
return text + " ";
|
}).collect(Collectors.joining("\n"));
|
||||||
}).collect(Collectors.joining(""));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========== Number Operations ===========
|
// =========== Number Operations ===========
|
||||||
@@ -100,39 +122,6 @@ public class CommonHelper {
|
|||||||
return numstr.startsWith("0x") || numstr.startsWith("0X");
|
return numstr.startsWith("0x") || numstr.startsWith("0X");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert accepted string into Python cupported format.
|
|
||||||
*
|
|
||||||
* It actually just remove trail "UL".
|
|
||||||
*
|
|
||||||
* @param numstr The captured number.
|
|
||||||
* @return The Python style number string.
|
|
||||||
*/
|
|
||||||
public static String convertToPythonNumber(String numstr) {
|
|
||||||
return numstr.replaceFirst("[ulUL]+$", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========== Parts ===========
|
|
||||||
|
|
||||||
enum CKParts {
|
|
||||||
CK2, VxMath
|
|
||||||
}
|
|
||||||
|
|
||||||
enum LangType {
|
|
||||||
Cpp, Python, CSharp
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getCKPartsNamespace(CKParts parts) {
|
|
||||||
switch (parts) {
|
|
||||||
case CK2:
|
|
||||||
return "CK2";
|
|
||||||
case VxMath:
|
|
||||||
return "VxMath";
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Unexpected value: " + parts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========== File Operations ===========
|
// =========== File Operations ===========
|
||||||
|
|
||||||
private static Path getRootDirectoryPath() throws Exception {
|
private static Path getRootDirectoryPath() throws Exception {
|
||||||
@@ -182,80 +171,25 @@ public class CommonHelper {
|
|||||||
|
|
||||||
// =========== String Process ===========
|
// =========== String Process ===========
|
||||||
|
|
||||||
/**
|
|
||||||
* Escape String
|
|
||||||
*
|
|
||||||
* Escape all characters which are invalid in string quote.
|
|
||||||
*
|
|
||||||
* @param strl The string need to be escaped.
|
|
||||||
* @return The escaped string.
|
|
||||||
* @see removeEol
|
|
||||||
*/
|
|
||||||
public static String escapeString(String strl) {
|
|
||||||
return strl.replace("\\", "\\\\").replace("\t", "\\t").replace("\b", "\\b").replace("\n", "\\n")
|
|
||||||
.replace("\r", "\\r").replace("\f", "\\f").replace("\"", "\\\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all EOL (End of Line) characters.
|
* Remove all EOL (End of Line) characters.
|
||||||
*
|
*
|
||||||
* @param strl The string need to be processed.
|
* @param strl The string need to be processed.
|
||||||
* @return The string eliminated all EOL.
|
* @return The string eliminated all EOL.
|
||||||
* @see escapeString
|
|
||||||
*/
|
*/
|
||||||
public static String removeEol(String strl) {
|
public static String removeEol(String strl) {
|
||||||
return strl.replace("\n", "").replace("\r", "");
|
return strl.replace("\n", "").replace("\r", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove redundent star '*' (at least 5 continuous star chars)
|
* Remove seperator bar consisted by '*' or '-' (at least 5 successive chars)
|
||||||
*
|
*
|
||||||
* @param cmt The string provided.
|
* @param cmt The string provided.
|
||||||
* @return The string processed.
|
* @return The string processed.
|
||||||
*/
|
*/
|
||||||
public static String removeStars(String cmt) {
|
public static String removeSeperator(String cmt) {
|
||||||
// only remove at least 5 continuous star chars.
|
// only remove at least 5 continuous star chars.
|
||||||
return cmt.replaceAll("\\*{5,}", "");
|
return cmt.replaceAll("[\\*\\-]{5,}", "");
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get indent char by style
|
|
||||||
*
|
|
||||||
* @param use_tab Whether indent use Tab, not Space.
|
|
||||||
* @return The indent chars
|
|
||||||
*/
|
|
||||||
public static String getIndentString(boolean use_tab) {
|
|
||||||
if (use_tab)
|
|
||||||
return "\t";
|
|
||||||
else
|
|
||||||
return " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Re-indent a block of string
|
|
||||||
*
|
|
||||||
* This function will first split block string by line. Then remove all indent
|
|
||||||
* (strip Tab and Space). At last, re-indent and join each line
|
|
||||||
*
|
|
||||||
* @param block_str The string provided.
|
|
||||||
* @param use_tab Use Tab, not Space as indent chars.
|
|
||||||
* @param indent_level The level of indent, started by 0.
|
|
||||||
* @return The re-indent string
|
|
||||||
*/
|
|
||||||
public static String reindentBlockString(String block_str, boolean use_tab, int indent_level) {
|
|
||||||
// pre-create indent string
|
|
||||||
String indentChars = getIndentString(use_tab);
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 0; i < indent_level; ++i) {
|
|
||||||
sb.append(indentChars);
|
|
||||||
}
|
|
||||||
String indents = sb.toString();
|
|
||||||
|
|
||||||
// split line
|
|
||||||
return block_str.lines().map((String line) -> {
|
|
||||||
// strip space and tab, then re-indent it.
|
|
||||||
return indents + line.trim();
|
|
||||||
}).collect(Collectors.joining(System.lineSeparator())); // then join with new line breaker and return.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,273 +0,0 @@
|
|||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write enum declarations and accessible value into C++ format.
|
|
||||||
*/
|
|
||||||
public class CppWriter {
|
|
||||||
|
|
||||||
// =========== C++ Enum Declaration Writer ===========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get corredponding C++ underlying type of given enum.
|
|
||||||
* <p>
|
|
||||||
* This is C++ specific function.
|
|
||||||
*
|
|
||||||
* @param canUnsigned The parameter stored in Enum_t that indicate whether this
|
|
||||||
* enum can use unsigned int as its underlying type.
|
|
||||||
* @return The string form of its underlying type.
|
|
||||||
*/
|
|
||||||
private static String getEnumUnderlyingType(boolean canUnsigned) {
|
|
||||||
return canUnsigned ? "CKDWORD" : "CKINT";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal real enum declarations writer.
|
|
||||||
*
|
|
||||||
* @param writer {@linkplain java.io.OutputStreamWriter} instance for writing.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private static void internalWriteEnums(OutputStreamWriter writer, EnumsHelper.BEnumCollection prog)
|
|
||||||
throws Exception {
|
|
||||||
IndentHelper indent = new IndentHelper(writer, CommonHelper.LangType.Cpp);
|
|
||||||
for (EnumsHelper.BEnum benum : prog.mEnums) {
|
|
||||||
// write enum comment
|
|
||||||
indent.briefComment(benum.mEnumComment);
|
|
||||||
|
|
||||||
// write enum start
|
|
||||||
indent.printf("enum class %s : %s {", benum.mEnumName, getEnumUnderlyingType(benum.mCanUnsigned));
|
|
||||||
indent.inc();
|
|
||||||
|
|
||||||
// write enum entries
|
|
||||||
for (EnumsHelper.BEnumEntry enumEntry : benum.mEntries) {
|
|
||||||
// write entry self
|
|
||||||
if (enumEntry.mEntryValue == null) {
|
|
||||||
indent.printf("%s,", enumEntry.mEntryName);
|
|
||||||
} else {
|
|
||||||
indent.printf("%s = %s,", enumEntry.mEntryName, enumEntry.mEntryValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write entry comment after member
|
|
||||||
indent.afterMemberComment(enumEntry.mEntryComment);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write enum tail
|
|
||||||
indent.dec();
|
|
||||||
indent.puts("};");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write an enum collection into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum collection writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for
|
|
||||||
* writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeEnums(String filename, EnumsHelper.BEnumCollection prog) throws Exception {
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteEnums(fs, prog);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write a single enum into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum collection writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param _enum {@linkplain EnumsHelper.BEnum} instance for writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeEnum(String filename, EnumsHelper.BEnum _enum) throws Exception {
|
|
||||||
// create an collection from single enum declaration
|
|
||||||
// for suit the argument requirement of real writer.
|
|
||||||
EnumsHelper.BEnumCollection col = new EnumsHelper.BEnumCollection();
|
|
||||||
col.mEnums.add(_enum);
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteEnums(fs, col);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========== C++ Enum Accessible Value Writer ===========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal real enum collection accessible value writer.
|
|
||||||
*
|
|
||||||
* @param writer {@linkplain java.io.OutputStreamWriter} instance for writing.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for writing.
|
|
||||||
* @param parts The part of these enum declarations. It will indicate the
|
|
||||||
* namespace where find given enum collection.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private static void internalWriteAccVals(OutputStreamWriter writer, EnumsHelper.BEnumCollection prog,
|
|
||||||
CommonHelper.CKParts parts) throws Exception {
|
|
||||||
IndentHelper indent = new IndentHelper(writer, CommonHelper.LangType.Cpp);
|
|
||||||
|
|
||||||
// write type defination (just to let user know what the type is)
|
|
||||||
indent.puts("// struct GeneralReflection { const char8_t* mName; };");
|
|
||||||
indent.puts("// template<typename _Ty, std::enable_if_t<std::is_enum_v<_Ty>, int> = 0>");
|
|
||||||
indent.puts("// using GeneralReflectionArray = std::vector<std::pair<_Ty, GeneralReflection>>;");
|
|
||||||
|
|
||||||
indent.puts("");
|
|
||||||
indent.puts("");
|
|
||||||
indent.puts("");
|
|
||||||
|
|
||||||
// write declarations
|
|
||||||
for (EnumsHelper.BEnum benum : prog.mEnums) {
|
|
||||||
indent.printf("extern const GeneralReflectionArray<LibCmo::%s::%s> %s;",
|
|
||||||
CommonHelper.getCKPartsNamespace(parts), benum.mEnumName, benum.mEnumName);
|
|
||||||
}
|
|
||||||
|
|
||||||
indent.puts("");
|
|
||||||
indent.puts("");
|
|
||||||
indent.puts("");
|
|
||||||
|
|
||||||
// write implements
|
|
||||||
for (EnumsHelper.BEnum benum : prog.mEnums) {
|
|
||||||
// write enum desc header
|
|
||||||
indent.printf("const GeneralReflectionArray<LibCmo::%s::%s> %s {", CommonHelper.getCKPartsNamespace(parts),
|
|
||||||
benum.mEnumName, benum.mEnumName);
|
|
||||||
indent.inc();
|
|
||||||
|
|
||||||
// write enum desc entries
|
|
||||||
for (EnumsHelper.BEnumEntry enumEntry : benum.mEntries) {
|
|
||||||
indent.printf("{ LibCmo::%s::%s::%s, { u8\"%s\" } },", CommonHelper.getCKPartsNamespace(parts),
|
|
||||||
benum.mEnumName, enumEntry.mEntryName, enumEntry.mEntryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write enum tail
|
|
||||||
indent.dec();
|
|
||||||
indent.puts("};");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write an enum collection accessible value into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum collection accessible value
|
|
||||||
* writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for
|
|
||||||
* writing.
|
|
||||||
* @param parts The part of these enum declarations.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeAccVals(String filename, EnumsHelper.BEnumCollection prog, CommonHelper.CKParts parts)
|
|
||||||
throws Exception {
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteAccVals(fs, prog, parts);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write a single enum accessible value into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum collection accessible value
|
|
||||||
* writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param _enum {@linkplain EnumsHelper.BEnum} instance for writing.
|
|
||||||
* @param parts The part of these enum declarations.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeAccVal(String filename, EnumsHelper.BEnum _enum, CommonHelper.CKParts parts)
|
|
||||||
throws Exception {
|
|
||||||
// create a enum collection to fulfill the requirement of internal writer.
|
|
||||||
EnumsHelper.BEnumCollection col = new EnumsHelper.BEnumCollection();
|
|
||||||
col.mEnums.add(_enum);
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteAccVals(fs, col, parts);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========== Specialized C++ Enum Accessible Value Writer ===========
|
|
||||||
// Only accessible value part of CERROR and CK_CLASSID need to be specialized.
|
|
||||||
// The enum self do not need special treat. Just write them normally.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specialized CKERROR accessible value writer.
|
|
||||||
* <p>
|
|
||||||
* The declaration of CKERROR do not need special treat. It is okey to use
|
|
||||||
* common writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param errors The {@linkplain EnumsHelper.BEnum} instance storing CKERROR.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeCkErrorAccVal(String filename, EnumsHelper.BEnum errors) throws Exception {
|
|
||||||
OutputStreamWriter writer = CommonHelper.openOutputFile(filename);
|
|
||||||
IndentHelper indent = new IndentHelper(writer, CommonHelper.LangType.Cpp);
|
|
||||||
|
|
||||||
// write type defination (just to let user know what the type is)
|
|
||||||
indent.puts("// struct CkErrorReflection { const char8_t* mName; const char8_t* mDescription; };");
|
|
||||||
indent.puts("// using CkErrorReflectionArray = std::vector<std::pair<LibCmo::CK2::CKERROR, CkErrorReflection>>;");
|
|
||||||
|
|
||||||
indent.puts("");
|
|
||||||
indent.puts("");
|
|
||||||
indent.puts("");
|
|
||||||
|
|
||||||
// write implementation
|
|
||||||
indent.puts("const CkErrorReflectionArray CKERROR {");
|
|
||||||
indent.inc();
|
|
||||||
for (EnumsHelper.BEnumEntry entry : errors.mEntries) {
|
|
||||||
String comment = CommonHelper.escapeString(entry.mEntryComment);
|
|
||||||
if (comment == null)
|
|
||||||
comment = "";
|
|
||||||
|
|
||||||
indent.printf("{ LibCmo::CK2::CKERROR::%s, { u8\"%s\", u8\"%s\" } },", entry.mEntryName, entry.mEntryName,
|
|
||||||
comment);
|
|
||||||
}
|
|
||||||
indent.dec();
|
|
||||||
indent.puts("};");
|
|
||||||
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specialized CK_CLASSID accessible value writer.
|
|
||||||
* <p>
|
|
||||||
* The declaration of CK_CLASSID do not need special treat. It is okey to use
|
|
||||||
* common writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param classids The {@linkplain EnumsHelper.BEnum} instance storing
|
|
||||||
* CK_CLASSID.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeCkClassidAccVal(String filename, EnumsHelper.BEnum classids) throws Exception {
|
|
||||||
OutputStreamWriter writer = CommonHelper.openOutputFile(filename);
|
|
||||||
IndentHelper indent = new IndentHelper(writer, CommonHelper.LangType.Cpp);
|
|
||||||
|
|
||||||
// write type defination (just to let user know what the type is)
|
|
||||||
indent.puts("// struct CkClassidReflection { std::vector<const char8_t*> mHierarchy; };");
|
|
||||||
indent.puts("// using CkClassidReflectionArray = std::vector<std::pair<LibCmo::CK2::CK_CLASSID, CkClassidReflection>>;");
|
|
||||||
|
|
||||||
indent.puts("");
|
|
||||||
indent.puts("");
|
|
||||||
indent.puts("");
|
|
||||||
|
|
||||||
indent.puts("const CkClassidReflectionArray CK_CLASSID {");
|
|
||||||
indent.inc();
|
|
||||||
for (EnumsHelper.BEnumEntry entry : classids.mEntries) {
|
|
||||||
EnumsHelper.BHierarchyEnumEntry specialized = (EnumsHelper.BHierarchyEnumEntry) entry;
|
|
||||||
|
|
||||||
String hierarchy = specialized.mHierarchy.stream().map(value -> value.mEntryName)
|
|
||||||
.collect(Collectors.joining("\", u8\""));
|
|
||||||
indent.printf("{ LibCmo::CK2::CK_CLASSID::%s, { { u8\"%s\" } } },", entry.mEntryName, hierarchy);
|
|
||||||
}
|
|
||||||
indent.dec();
|
|
||||||
indent.puts("};");
|
|
||||||
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
import java.io.OutputStreamWriter;
|
|
||||||
|
|
||||||
public class IndentHelper {
|
|
||||||
public IndentHelper(OutputStreamWriter writer, CommonHelper.LangType lang_type) {
|
|
||||||
mIndent = 0;
|
|
||||||
mLangType = lang_type;
|
|
||||||
mWriter = writer;
|
|
||||||
|
|
||||||
// set indent chars
|
|
||||||
switch (mLangType) {
|
|
||||||
case Cpp:
|
|
||||||
case CSharp:
|
|
||||||
mIndentChars = CommonHelper.getIndentString(true);
|
|
||||||
break;
|
|
||||||
case Python:
|
|
||||||
mIndentChars = CommonHelper.getIndentString(false);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
mIndentChars = "";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int mIndent;
|
|
||||||
private CommonHelper.LangType mLangType;
|
|
||||||
private String mIndentChars;
|
|
||||||
private OutputStreamWriter mWriter;
|
|
||||||
|
|
||||||
private void rawIndent() throws Exception {
|
|
||||||
for (int i = 0; i < mIndent; ++i) {
|
|
||||||
mWriter.write(mIndentChars);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void inc() {
|
|
||||||
++mIndent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dec() {
|
|
||||||
--mIndent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void indent() throws Exception {
|
|
||||||
mWriter.write(System.lineSeparator());
|
|
||||||
rawIndent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void puts(String data) throws Exception {
|
|
||||||
indent();
|
|
||||||
mWriter.write(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void printf(String fmt, Object... args) throws Exception {
|
|
||||||
indent();
|
|
||||||
mWriter.write(String.format(fmt, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write standard Doxygen document comment.
|
|
||||||
* <p>
|
|
||||||
* Usually be called before writing content.
|
|
||||||
*
|
|
||||||
* @param comment
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public void briefComment(String comment) throws Exception {
|
|
||||||
if (comment == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (mLangType) {
|
|
||||||
case Cpp:
|
|
||||||
case CSharp:
|
|
||||||
puts("/**");
|
|
||||||
|
|
||||||
mWriter.write(System.lineSeparator());
|
|
||||||
mWriter.write(CommonHelper.reindentBlockString(comment, true, mIndent));
|
|
||||||
|
|
||||||
puts(" */");
|
|
||||||
break;
|
|
||||||
case Python:
|
|
||||||
puts("\"\"\"!");
|
|
||||||
|
|
||||||
mWriter.write(System.lineSeparator());
|
|
||||||
mWriter.write(CommonHelper.reindentBlockString(comment, false, mIndent));
|
|
||||||
|
|
||||||
puts("\"\"\"");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write suffix style Doxygen document comment.
|
|
||||||
* <p>
|
|
||||||
* Usually be called after writing content.
|
|
||||||
*
|
|
||||||
* @param comment
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public void afterMemberComment(String comment) throws Exception {
|
|
||||||
if (comment == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
mWriter.write(mIndentChars);
|
|
||||||
switch (mLangType) {
|
|
||||||
case Cpp:
|
|
||||||
case CSharp:
|
|
||||||
mWriter.write(String.format("/**< %s */", CommonHelper.removeEol(comment)));
|
|
||||||
break;
|
|
||||||
case Python:
|
|
||||||
mWriter.write(String.format("##< %s", CommonHelper.removeEol(comment)));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,7 @@ public class JsonWriter {
|
|||||||
// Export hierarchy if possible
|
// Export hierarchy if possible
|
||||||
if (enumEntry instanceof EnumsHelper.BHierarchyEnumEntry hierarchyEnumEntry) {
|
if (enumEntry instanceof EnumsHelper.BHierarchyEnumEntry hierarchyEnumEntry) {
|
||||||
// We only export name in hierarchy.
|
// We only export name in hierarchy.
|
||||||
// Otherwise we may cause recursive calling.
|
// Otherwise, we may cause recursive calling.
|
||||||
JsonArray entries = new JsonArray();
|
JsonArray entries = new JsonArray();
|
||||||
for (EnumsHelper.BHierarchyEnumEntry subEntry : hierarchyEnumEntry.mHierarchy) {
|
for (EnumsHelper.BHierarchyEnumEntry subEntry : hierarchyEnumEntry.mHierarchy) {
|
||||||
entries.add(subEntry.mEntryName);
|
entries.add(subEntry.mEntryName);
|
||||||
@@ -54,7 +54,7 @@ public class JsonWriter {
|
|||||||
private static void writeJson(String filename, EnumsHelper.BEnumCollection enumCollection) throws Exception {
|
private static void writeJson(String filename, EnumsHelper.BEnumCollection enumCollection) throws Exception {
|
||||||
OutputStreamWriter writer = CommonHelper.openOutputFile(filename);
|
OutputStreamWriter writer = CommonHelper.openOutputFile(filename);
|
||||||
//Gson gsonInstance = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
//Gson gsonInstance = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||||
Gson gsonInstance = new GsonBuilder().disableHtmlEscaping().create();
|
Gson gsonInstance = new GsonBuilder().serializeNulls().disableHtmlEscaping().create();
|
||||||
writer.write(gsonInstance.toJson(writeBEnumCollection(enumCollection)));
|
writer.write(gsonInstance.toJson(writeBEnumCollection(enumCollection)));
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ public class MainRunner {
|
|||||||
* <p>
|
* <p>
|
||||||
* This function will assume that given file only contain C++ "#define" syntax.
|
* This function will assume that given file only contain C++ "#define" syntax.
|
||||||
* After reading it, it will re-organize it as an enum and return. This only is
|
* After reading it, it will re-organize it as an enum and return. This only is
|
||||||
* used by CKERROR now. But it suit for more scenarios if there are something
|
* used by CKERROR now. But it is suit for more scenarios if there are something
|
||||||
* like CKERROR in future.
|
* like CKERROR in the future.
|
||||||
*
|
*
|
||||||
* @param filename The file name relative to input directory for reading.
|
* @param filename The file name relative to input directory for reading.
|
||||||
* @param assignedEnumName The desired name of organized enum instance.
|
* @param assignedEnumName The desired name of organized enum instance.
|
||||||
@@ -106,30 +106,14 @@ public class MainRunner {
|
|||||||
// =========== CKERROR ===========
|
// =========== CKERROR ===========
|
||||||
EnumsHelper.BEnum ckerror = organiseDefines("CKERROR.txt", "CKERROR");
|
EnumsHelper.BEnum ckerror = organiseDefines("CKERROR.txt", "CKERROR");
|
||||||
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CKERROR.json"), ckerror);
|
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CKERROR.json"), ckerror);
|
||||||
// CppWriter.writeEnum("CKERROR.hpp", ckerror);
|
|
||||||
// PythonWriter.writeEnum("CKERROR.py", ckerror);
|
|
||||||
// CSharpWriter.writeEnum("CKERROR.cs", ckerror);
|
|
||||||
// CppWriter.writeCkErrorAccVal("CKERROR.AccVal.hpp", ckerror);
|
|
||||||
// PythonWriter.writeAccVal("CKERROR.AccVal.py", ckerror);
|
|
||||||
// CSharpWriter.writeAccVal("CKERROR.AccVal.cs", ckerror);
|
|
||||||
|
|
||||||
// =========== CK_CLASSID ===========
|
// =========== CK_CLASSID ===========
|
||||||
EnumsHelper.BEnum classid = organiseClassid("CK_CLASSID.txt");
|
EnumsHelper.BEnum classid = organiseClassid("CK_CLASSID.txt");
|
||||||
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CK_CLASSID.json"), classid);
|
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CK_CLASSID.json"), classid);
|
||||||
// CppWriter.writeEnum("CK_CLASSID.hpp", classid);
|
|
||||||
// PythonWriter.writeEnum("CK_CLASSID.py", classid);
|
|
||||||
// CSharpWriter.writeEnum("CK_CLASSID.cs", classid);
|
|
||||||
// CppWriter.writeCkClassidAccVal("CK_CLASSID.AccVal.hpp", classid);
|
|
||||||
// PythonWriter.writeAccVal("CK_CLASSID.AccVal.py", classid);
|
|
||||||
|
|
||||||
// =========== Define2 ===========
|
// =========== Define2 ===========
|
||||||
// Define2 do not need annotation output.
|
|
||||||
// Because they are CKStateChunk used value which are not exposed to outside.
|
|
||||||
EnumsHelper.BEnumCollection def2 = getEnumsCollection("Defines2.txt");
|
EnumsHelper.BEnumCollection def2 = getEnumsCollection("Defines2.txt");
|
||||||
JsonWriter.writeEnums(CommonHelper.getOutputFilePath("Defines2.json"), def2);
|
JsonWriter.writeEnums(CommonHelper.getOutputFilePath("Defines2.json"), def2);
|
||||||
// CppWriter.writeEnums("Defines2.hpp", def2);
|
|
||||||
// PythonWriter.writeEnums("Defines2.py", def2);
|
|
||||||
// CSharpWriter.writeEnums("Defines2.cs", def2);
|
|
||||||
|
|
||||||
// =========== Combined enums ===========
|
// =========== Combined enums ===========
|
||||||
EnumsHelper.BEnumCollection ck2Enums = getEnumsCollection("CKEnums.txt"),
|
EnumsHelper.BEnumCollection ck2Enums = getEnumsCollection("CKEnums.txt"),
|
||||||
@@ -137,58 +121,20 @@ public class MainRunner {
|
|||||||
JsonWriter.writeEnums(CommonHelper.getOutputFilePath("CKEnums.json"), ck2Enums);
|
JsonWriter.writeEnums(CommonHelper.getOutputFilePath("CKEnums.json"), ck2Enums);
|
||||||
JsonWriter.writeEnums(CommonHelper.getOutputFilePath("VxEnums.json"), vxEnums);
|
JsonWriter.writeEnums(CommonHelper.getOutputFilePath("VxEnums.json"), vxEnums);
|
||||||
|
|
||||||
// CppWriter.writeEnums("CKEnums.hpp", ck2Enums);
|
|
||||||
// PythonWriter.writeEnums("CKEnums.py", ck2Enums);
|
|
||||||
// CSharpWriter.writeEnums("CKEnums.cs", ck2Enums);
|
|
||||||
// CppWriter.writeAccVals("CKEnums.AccVal.hpp", ck2Enums, CommonHelper.CKParts.CK2);
|
|
||||||
// PythonWriter.writeAccVals("CKEnums.AccVal.py", ck2Enums);
|
|
||||||
// CSharpWriter.writeAccVals("CKEnums.AccVal.cs", ck2Enums);
|
|
||||||
|
|
||||||
// CppWriter.writeEnums("VxEnums.hpp", vxEnums);
|
|
||||||
// PythonWriter.writeEnums("VxEnums.py", vxEnums);
|
|
||||||
// CSharpWriter.writeEnums("VxEnums.cs", vxEnums);
|
|
||||||
// CppWriter.writeAccVals("VxEnums.AccVal.hpp", vxEnums, CommonHelper.CKParts.VxMath);
|
|
||||||
// PythonWriter.writeAccVals("VxEnums.AccVal.py", vxEnums);
|
|
||||||
// CSharpWriter.writeAccVals("VxEnums.AccVal.cs", vxEnums);
|
|
||||||
|
|
||||||
// =========== Single enums ===========
|
// =========== Single enums ===========
|
||||||
EnumsHelper.BEnum single;
|
EnumsHelper.BEnum single;
|
||||||
|
|
||||||
single = organiseDefines("CK_STATECHUNK_CHUNKVERSION.txt", "CK_STATECHUNK_CHUNKVERSION");
|
single = organiseDefines("CK_STATECHUNK_CHUNKVERSION.txt", "CK_STATECHUNK_CHUNKVERSION");
|
||||||
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CK_STATECHUNK_CHUNKVERSION.json"), single);
|
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CK_STATECHUNK_CHUNKVERSION.json"), single);
|
||||||
// CppWriter.writeEnum("CK_STATECHUNK_CHUNKVERSION.hpp", single);
|
|
||||||
// PythonWriter.writeEnum("CK_STATECHUNK_CHUNKVERSION.py", single);
|
|
||||||
// CSharpWriter.writeEnum("CK_STATECHUNK_CHUNKVERSION.cs", single);
|
|
||||||
// CppWriter.writeAccVal("CK_STATECHUNK_CHUNKVERSION.AccVal.hpp", single, CommonHelper.CKParts.CK2);
|
|
||||||
// PythonWriter.writeAccVal("CK_STATECHUNK_CHUNKVERSION.AccVal.py", single);
|
|
||||||
// CSharpWriter.writeAccVal("CK_STATECHUNK_CHUNKVERSION.AccVal.cs", single);
|
|
||||||
|
|
||||||
single = organiseDefines("CK_STATECHUNK_DATAVERSION.txt", "CK_STATECHUNK_DATAVERSION");
|
single = organiseDefines("CK_STATECHUNK_DATAVERSION.txt", "CK_STATECHUNK_DATAVERSION");
|
||||||
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CK_STATECHUNK_DATAVERSION.json"), single);
|
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CK_STATECHUNK_DATAVERSION.json"), single);
|
||||||
// CppWriter.writeEnum("CK_STATECHUNK_DATAVERSION.hpp", single);
|
|
||||||
// PythonWriter.writeEnum("CK_STATECHUNK_DATAVERSION.py", single);
|
|
||||||
// CSharpWriter.writeEnum("CK_STATECHUNK_DATAVERSION.cs", single);
|
|
||||||
// CppWriter.writeAccVal("CK_STATECHUNK_DATAVERSION.AccVal.hpp", single, CommonHelper.CKParts.CK2);
|
|
||||||
// PythonWriter.writeAccVal("CK_STATECHUNK_DATAVERSION.AccVal.py", single);
|
|
||||||
// CSharpWriter.writeAccVal("CK_STATECHUNK_DATAVERSION.AccVal.cs", single);
|
|
||||||
|
|
||||||
single = organiseDefines("CK_BITMAPDATA_FLAGS.txt", "CK_BITMAPDATA_FLAGS");
|
single = organiseDefines("CK_BITMAPDATA_FLAGS.txt", "CK_BITMAPDATA_FLAGS");
|
||||||
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CK_BITMAPDATA_FLAGS.json"), single);
|
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CK_BITMAPDATA_FLAGS.json"), single);
|
||||||
// CppWriter.writeEnum("CK_BITMAPDATA_FLAGS.hpp", single);
|
|
||||||
// PythonWriter.writeEnum("CK_BITMAPDATA_FLAGS.py", single);
|
|
||||||
// CSharpWriter.writeEnum("CK_BITMAPDATA_FLAGS.cs", single);
|
|
||||||
// CppWriter.writeAccVal("CK_BITMAPDATA_FLAGS.AccVal.hpp", single, CommonHelper.CKParts.CK2);
|
|
||||||
// PythonWriter.writeAccVal("CK_BITMAPDATA_FLAGS.AccVal.py", single);
|
|
||||||
// CSharpWriter.writeAccVal("CK_BITMAPDATA_FLAGS.AccVal.cs", single);
|
|
||||||
|
|
||||||
single = organiseDefines("CK_CAMERA_PROJECTION.txt", "CK_CAMERA_PROJECTION");
|
single = organiseDefines("CK_CAMERA_PROJECTION.txt", "CK_CAMERA_PROJECTION");
|
||||||
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CK_CAMERA_PROJECTION.json"), single);
|
JsonWriter.writeEnum(CommonHelper.getOutputFilePath("CK_CAMERA_PROJECTION.json"), single);
|
||||||
// CppWriter.writeEnum("CK_CAMERA_PROJECTION.hpp", single);
|
|
||||||
// PythonWriter.writeEnum("CK_CAMERA_PROJECTION.py", single);
|
|
||||||
// CSharpWriter.writeEnum("CK_CAMERA_PROJECTION.cs", single);
|
|
||||||
// CppWriter.writeAccVal("CK_CAMERA_PROJECTION.AccVal.hpp", single, CommonHelper.CKParts.CK2);
|
|
||||||
// PythonWriter.writeAccVal("CK_CAMERA_PROJECTION.AccVal.py", single);
|
|
||||||
// CSharpWriter.writeAccVal("CK_CAMERA_PROJECTION.AccVal.cs", single);
|
|
||||||
|
|
||||||
// print message.
|
// print message.
|
||||||
System.out.println("Done");
|
System.out.println("Done");
|
||||||
|
|||||||
@@ -1,185 +0,0 @@
|
|||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write enum declarations and accessible value into Python format.
|
|
||||||
*/
|
|
||||||
public class PythonWriter {
|
|
||||||
|
|
||||||
// =========== Python Enum Declaration Writer ===========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal real enum declaration writer.
|
|
||||||
*
|
|
||||||
* @param writer {@linkplain java.io.OutputStreamWriter} instance for writing.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private static void internalWriteEnums(OutputStreamWriter writer, EnumsHelper.BEnumCollection prog)
|
|
||||||
throws Exception {
|
|
||||||
IndentHelper indent = new IndentHelper(writer, CommonHelper.LangType.Python);
|
|
||||||
for (EnumsHelper.BEnum benum : prog.mEnums) {
|
|
||||||
// write enum start
|
|
||||||
indent.printf("class %s(enum.IntEnum):", benum.mEnumName);
|
|
||||||
indent.inc();
|
|
||||||
|
|
||||||
// write enum comment
|
|
||||||
indent.briefComment(benum.mEnumComment);
|
|
||||||
|
|
||||||
// write enum entries
|
|
||||||
for (EnumsHelper.BEnumEntry enumEntry : benum.mEntries) {
|
|
||||||
// write entry self
|
|
||||||
if (enumEntry.mEntryValue == null) {
|
|
||||||
indent.printf("%s = auto()", enumEntry.mEntryName);
|
|
||||||
} else {
|
|
||||||
indent.printf("%s = %s", enumEntry.mEntryName,
|
|
||||||
CommonHelper.convertToPythonNumber(enumEntry.mEntryValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
// write entry comment after member
|
|
||||||
indent.afterMemberComment(enumEntry.mEntryComment);
|
|
||||||
}
|
|
||||||
|
|
||||||
// enum tail
|
|
||||||
indent.dec();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write an enum declaration collection into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum declaration collection writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for
|
|
||||||
* writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeEnums(String filename, EnumsHelper.BEnumCollection prog) throws Exception {
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteEnums(fs, prog);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write a single enum declaration into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum declaration collection writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param _enum {@linkplain EnumsHelper.BEnum} instance for writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeEnum(String filename, EnumsHelper.BEnum _enum) throws Exception {
|
|
||||||
// create collection from single enum
|
|
||||||
EnumsHelper.BEnumCollection col = new EnumsHelper.BEnumCollection();
|
|
||||||
col.mEnums.add(_enum);
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteEnums(fs, col);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========== Python Enum Accessible Value Writer ===========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try generate human readable name from enum entry name.
|
|
||||||
* <p>
|
|
||||||
* This function is only served for Python code generation.
|
|
||||||
* <p>
|
|
||||||
* As you noticed, almost entries of CK enums are fully capital and splitted by
|
|
||||||
* underline. This is really not good for human reading, especially those who
|
|
||||||
* are not programmer. So this function will try give these programmer-oriented
|
|
||||||
* entry name a human readable name as its display name. However, this extract
|
|
||||||
* method is not perfect. It simply do some split and replacement so the
|
|
||||||
* generated content may still not good for reader.
|
|
||||||
*
|
|
||||||
* @param entry_name The name of enum entry
|
|
||||||
* @return A human readable entry name. No guaranteen that return value is must
|
|
||||||
* human readable.
|
|
||||||
*/
|
|
||||||
private static String extractHumanReadableEntryName(String entry_name) {
|
|
||||||
// remove first part (any content before underline '_')
|
|
||||||
entry_name = entry_name.replaceFirst("^[a-zA-Z0-9]+_", "");
|
|
||||||
|
|
||||||
// lower all chars except first char
|
|
||||||
if (entry_name.length() < 1)
|
|
||||||
return entry_name;
|
|
||||||
else
|
|
||||||
return entry_name.substring(0, 1) + entry_name.substring(1).toLowerCase(Locale.ROOT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal real enum accessible value writer.
|
|
||||||
*
|
|
||||||
* @param writer {@linkplain java.io.OutputStreamWriter} instance for writing.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private static void internalWriteAccVals(OutputStreamWriter writer, EnumsHelper.BEnumCollection prog)
|
|
||||||
throws Exception {
|
|
||||||
IndentHelper indent = new IndentHelper(writer, CommonHelper.LangType.Python);
|
|
||||||
|
|
||||||
// write implements
|
|
||||||
for (EnumsHelper.BEnum benum : prog.mEnums) {
|
|
||||||
// write enum desc header
|
|
||||||
indent.printf("g_Annotation_%s: dict[int, EnumAnnotation] = {", benum.mEnumName);
|
|
||||||
indent.inc();
|
|
||||||
|
|
||||||
// write enum desc entries
|
|
||||||
for (EnumsHelper.BEnumEntry enumEntry : benum.mEntries) {
|
|
||||||
String comment = "";
|
|
||||||
if (enumEntry.mEntryComment != null) {
|
|
||||||
comment = CommonHelper.escapeString(enumEntry.mEntryComment);
|
|
||||||
}
|
|
||||||
|
|
||||||
indent.printf("%s.%s.value: EnumAnnotation(\"%s\", \"%s\"),", benum.mEnumName, enumEntry.mEntryName,
|
|
||||||
extractHumanReadableEntryName(enumEntry.mEntryName), comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write enum tail
|
|
||||||
indent.dec();
|
|
||||||
indent.puts("}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write an enum accessible value collection into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum accessible value collection
|
|
||||||
* writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param prog {@linkplain EnumsHelper.BEnumCollection} instance for
|
|
||||||
* writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeAccVals(String filename, EnumsHelper.BEnumCollection prog) throws Exception {
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteAccVals(fs, prog);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write a single enum accessible value into given file.
|
|
||||||
* <p>
|
|
||||||
* Actually this is a wrapper of internal enum accessible value collection
|
|
||||||
* writer.
|
|
||||||
*
|
|
||||||
* @param filename The name of written file.
|
|
||||||
* @param _enum {@linkplain EnumsHelper.BEnum} instance for writing.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static void writeAccVal(String filename, EnumsHelper.BEnum _enum) throws Exception {
|
|
||||||
// create a collection with single enum.
|
|
||||||
EnumsHelper.BEnumCollection col = new EnumsHelper.BEnumCollection();
|
|
||||||
col.mEnums.add(_enum);
|
|
||||||
// open file and write
|
|
||||||
OutputStreamWriter fs = CommonHelper.openOutputFile(filename);
|
|
||||||
internalWriteAccVals(fs, col);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,99 @@
|
|||||||
import jinja2
|
import jinja2
|
||||||
|
import jinja2.filters
|
||||||
|
import re
|
||||||
import typing
|
import typing
|
||||||
from json_loader import BEnumCollection, BEnum
|
from json_loader import BEnumCollection, BEnum
|
||||||
from utils import CKParts
|
from utils import CKParts
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
class RenderUtils:
|
class RenderUtils:
|
||||||
pass
|
"""Possible used functions for jinja when rendering templates"""
|
||||||
|
|
||||||
|
TRANTABLE_ESCAPE_STRING: typing.ClassVar[dict[int, str]] = str.maketrans({
|
||||||
|
"\\": "\\\\",
|
||||||
|
"\t": "\\t",
|
||||||
|
"\b": "\\b",
|
||||||
|
"\n": "\\n",
|
||||||
|
"\r": "\\r",
|
||||||
|
"\f": "\\f",
|
||||||
|
"\"": "\\\"",
|
||||||
|
})
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def escape_string(strl: str) -> str:
|
||||||
|
"""
|
||||||
|
Escape string
|
||||||
|
|
||||||
|
Escape all characters which are invalid in string quote.
|
||||||
|
|
||||||
|
:param strl: The string need to be escaped.
|
||||||
|
:return: The escaped string.
|
||||||
|
"""
|
||||||
|
return strl.translate(RenderUtils.TRANTABLE_ESCAPE_STRING)
|
||||||
|
|
||||||
|
TRANTABLE_REMOVE_EOL: typing.ClassVar[dict[int, str]] = str.maketrans({
|
||||||
|
"\n": "",
|
||||||
|
"\r": "",
|
||||||
|
})
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def remove_eol(strl: str) -> str:
|
||||||
|
"""
|
||||||
|
Remove EOL of given string.
|
||||||
|
|
||||||
|
When rendering code, adding line comment is a common case.
|
||||||
|
However, comment may have EOL.
|
||||||
|
So when adding this to line comment, we need to remove all EOL.
|
||||||
|
"""
|
||||||
|
return strl.translate(RenderUtils.TRANTABLE_REMOVE_EOL)
|
||||||
|
|
||||||
|
REGEX_PY_TO_LITERAL_NUMBER: typing.ClassVar[re.Pattern] = re.compile("[ulUL]+$")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def convert_to_python_number(numstr: str) -> str:
|
||||||
|
"""
|
||||||
|
Convert accepted string into Python cupported format.
|
||||||
|
|
||||||
|
It actually just remove trail "UL".
|
||||||
|
|
||||||
|
This function is only served for Python code generation.
|
||||||
|
|
||||||
|
:param numstr: The captured number.
|
||||||
|
:return: The Python style number string.
|
||||||
|
"""
|
||||||
|
return RenderUtils.REGEX_PY_TO_LITERAL_NUMBER.sub("", numstr, 1)
|
||||||
|
|
||||||
|
REGEX_PY_EXT_HUMANRDABLE_ENTRY_NAME: typing.ClassVar[re.Pattern] = re.compile("^[a-zA-Z0-9]+_")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def extract_human_readable_entry_name(entry_name: str) -> str:
|
||||||
|
"""
|
||||||
|
Try generate human readable name from enum entry name.
|
||||||
|
|
||||||
|
This function is only served for Python code generation.
|
||||||
|
|
||||||
|
As you noticed, almost entries of CK enums are fully capital and splitted by
|
||||||
|
underline. This is really not good for human reading, especially those who
|
||||||
|
are not programmer. So this function will try give these programmer-oriented
|
||||||
|
entry name a human readable name as its display name. However, this extract
|
||||||
|
method is not perfect. It simply do some split and replacement so the
|
||||||
|
generated content may still not good for reader.
|
||||||
|
|
||||||
|
:param entry_name: The name of enum entry
|
||||||
|
:return: A human readable entry name. No guaranteen that return value is must human readable.
|
||||||
|
"""
|
||||||
|
# remove first part (any content before underline '_')
|
||||||
|
entry_name = RenderUtils.REGEX_PY_EXT_HUMANRDABLE_ENTRY_NAME.sub("", entry_name, 1)
|
||||||
|
|
||||||
|
# lower all chars except first char
|
||||||
|
if len(entry_name) < 1:
|
||||||
|
return entry_name
|
||||||
|
else:
|
||||||
|
return entry_name[0:1] + entry_name[1:].lower()
|
||||||
|
|
||||||
class TemplateRender:
|
class TemplateRender:
|
||||||
|
"""Render templates to code files"""
|
||||||
|
|
||||||
__loader: jinja2.BaseLoader
|
__loader: jinja2.BaseLoader
|
||||||
__environment: jinja2.Environment
|
__environment: jinja2.Environment
|
||||||
|
|
||||||
@@ -15,6 +101,12 @@ class TemplateRender:
|
|||||||
self.__loader = jinja2.FileSystemLoader(utils.get_template_directory())
|
self.__loader = jinja2.FileSystemLoader(utils.get_template_directory())
|
||||||
self.__environment = jinja2.Environment(loader=self.__loader)
|
self.__environment = jinja2.Environment(loader=self.__loader)
|
||||||
|
|
||||||
|
# prepare filters
|
||||||
|
self.__environment.filters['some_or_blank'] = lambda s: "" if s is None else s
|
||||||
|
self.__environment.filters['escape_string'] = lambda s: RenderUtils.escape_string(s)
|
||||||
|
self.__environment.filters['block_comment'] = lambda s, fmt: jinja2.filters.do_indent(s, fmt, True, True)
|
||||||
|
self.__environment.filters['line_comment'] = lambda s: RenderUtils.remove_eol(s)
|
||||||
|
|
||||||
def __render(self, template_name: str, dest_filename: str, payload: BEnumCollection, extra: dict[str, typing.Any] = {}) -> None:
|
def __render(self, template_name: str, dest_filename: str, payload: BEnumCollection, extra: dict[str, typing.Any] = {}) -> None:
|
||||||
# prepare template argument
|
# prepare template argument
|
||||||
template_argument: dict[str, typing.Any] = {
|
template_argument: dict[str, typing.Any] = {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{%- set benum = first(payload.iter_enums()) %}
|
{%- set benum = payload.iter_enums() | first %}
|
||||||
const CkErrorReflectionArray CKERROR {
|
const CkErrorReflectionArray CKERROR {
|
||||||
{%- for entry in benum.iter_entries() %}
|
{%- for entry in benum.iter_entries() %}
|
||||||
{ LibCmo::CK2::CKERROR::{{ entry.get_entry_name() }}, { u8"{{ entry.get_entry_name() }}", u8"{{- entry.get_entry_comment() }}" } },
|
{ LibCmo::CK2::CKERROR::{{ entry.get_entry_name() }}, { u8"{{ entry.get_entry_name() }}", u8"{{- entry.get_entry_comment() | some_or_blank | escape_string }}" } },
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{%- set benum = first(payload.iter_enums()) %}
|
{%- set benum = payload.iter_enums() | first %}
|
||||||
const CkClassidReflectionArray CK_CLASSID {
|
const CkClassidReflectionArray CK_CLASSID {
|
||||||
{%- for entry in benum.iter_entries() %}
|
{%- for entry in benum.iter_entries() %}
|
||||||
{ LibCmo::CK2::CK_CLASSID::{{ entry.get_entry_name() }}, { { {% for item in entry.iter_hierarchy(benum) %} u8"{{ item.get_enum_name() }}" {%- if not loop.last -%}, {%- endif %} {%- endfor %} } } },
|
{ LibCmo::CK2::CK_CLASSID::{{ entry.get_entry_name() }}, { { {%- for item in entry.iter_hierarchy(benum) %} u8"{{ item.get_entry_name() }}" {%- if not loop.last -%}, {%- endif %} {%- endfor %} } } },
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
{%- for benum in payload.iter_enums() %}
|
{%- for benum in payload.iter_enums() %}
|
||||||
{%- if benum.get_enum_comment() is not none %}
|
{%- if benum.get_enum_comment() is not none %}
|
||||||
/**
|
{{ benum.get_enum_comment() | block_comment('/// ') }}
|
||||||
{{ benum.get_enum_comment() }}
|
|
||||||
*/
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{% if benum.get_use_flags() %}[Flags]{%- endif %}
|
{% if benum.get_use_flags() %}[Flags]{%- endif %}
|
||||||
public enum {{ benum.get_enum_name() }} : {% if benum.get_can_unsigned() -%} uint {%- else -%} int {%- endif %} {
|
public enum {{ benum.get_enum_name() }} : {% if benum.get_can_unsigned() -%} uint {%- else -%} int {%- endif %} {
|
||||||
{%- for entry in benum.iter_entries() %}
|
{%- for entry in benum.iter_entries() %}
|
||||||
{{ entry.get_entry_name() }} {%- if entry.get_entry_value() is not none %} = {{ entry.get_entry_value() }} {%- endif %}, {%- if entry.get_entry_comment() is not none %} /**< {{ entry.get_entry_comment() }} */ {%- endif %}
|
{{ entry.get_entry_name() }} {%- if entry.get_entry_value() is not none %} = {{ entry.get_entry_value() }} {%- endif %}, {%- if entry.get_entry_comment() is not none %} /// {{ entry.get_entry_comment() | line_comment }} {%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
};
|
};
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
{%- for benum in payload.iter_enums() %}
|
using System.Collections.Generic;
|
||||||
public static readonly System.Collections.Generic.Dictionary<{{ benum.get_enum_name() }}, string> {{ benum.get_enum_name() }} = new System.Collections.Generic.Dictionary<{{ benum.get_enum_name() }}, string>() {
|
|
||||||
|
{% for benum in payload.iter_enums() %}
|
||||||
|
public static readonly Dictionary<{{ benum.get_enum_name() }}, string> {{ benum.get_enum_name() }} = new Dictionary<{{ benum.get_enum_name() }}, string>() {
|
||||||
{%- for entry in benum.iter_entries() %}
|
{%- for entry in benum.iter_entries() %}
|
||||||
{ {{ benum.get_enum_name() }}.{{ entry.get_entry_name() }}, "{{ entry.get_entry_name() }}" },
|
{ {{ benum.get_enum_name() }}.{{ entry.get_entry_name() }}, "{{ entry.get_entry_name() }}" },
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class EnumDocstring():
|
||||||
|
display_name: str
|
||||||
|
"""The name of this enum entry."""
|
||||||
|
description: str
|
||||||
|
"""The description of this enum entry."""
|
||||||
|
|
||||||
|
{% for benum in payload.iter_enums() %}
|
||||||
|
DOCSTRING_{{ benum.get_enum_name() }}: dict[{{ benum.get_enum_name() }}, EnumDocstring] = {
|
||||||
|
{%- for entry in benum.iter_entries() %}
|
||||||
|
{{ benum.get_enum_name() }}.{{ entry.get_entry_name() }}: EnumDocstring("{{ utils.extract_human_readable_entry_name(entry.get_entry_name()) }}", "{{ entry.get_entry_comment() | some_or_blank | escape_string }}"),
|
||||||
|
{%- endfor %}
|
||||||
|
}
|
||||||
|
{%- endfor %}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{%- for benum in payload.iter_enums() %}
|
{%- for benum in payload.iter_enums() %}
|
||||||
{%- if benum.get_enum_comment() is not none %}
|
{%- if benum.get_enum_comment() is not none %}
|
||||||
/**
|
/**
|
||||||
{{ benum.get_enum_comment() }}
|
{{ benum.get_enum_comment() | block_comment(' * ') }}
|
||||||
*/
|
*/
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
enum class {{ benum.get_enum_name() }} : {% if benum.get_can_unsigned() -%} CKDWORD {%- else -%} CKINT {%- endif %} {
|
enum class {{ benum.get_enum_name() }} : {% if benum.get_can_unsigned() -%} CKDWORD {%- else -%} CKINT {%- endif %} {
|
||||||
{%- for entry in benum.iter_entries() %}
|
{%- for entry in benum.iter_entries() %}
|
||||||
{{ entry.get_entry_name() }} {%- if entry.get_entry_value() is not none %} = {{ entry.get_entry_value() }} {%- endif %}, {%- if entry.get_entry_comment() is not none %} /**< {{ entry.get_entry_comment() }} */ {%- endif %}
|
{{ entry.get_entry_name() }} {%- if entry.get_entry_value() is not none %} = {{ entry.get_entry_value() }} {%- endif %}, {%- if entry.get_entry_comment() is not none %} /**< {{ entry.get_entry_comment() | line_comment }} */ {%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
};
|
};
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import enum
|
import enum
|
||||||
|
|
||||||
{% for benum in payload.iter_enums() %}
|
{% for benum in payload.iter_enums() %}
|
||||||
{%- if benum.get_enum_comment() is not none %}
|
|
||||||
/**
|
|
||||||
{{ benum.get_enum_comment() }}
|
|
||||||
*/
|
|
||||||
{%- endif %}
|
|
||||||
class {{ benum.get_enum_name() }}(enum.IntEnum):
|
class {{ benum.get_enum_name() }}(enum.IntEnum):
|
||||||
|
{%- if benum.get_enum_comment() is not none %}
|
||||||
|
"""
|
||||||
|
{{ benum.get_enum_comment() | block_comment('') }}
|
||||||
|
"""
|
||||||
|
{%- endif %}
|
||||||
{%- for entry in benum.iter_entries() %}
|
{%- for entry in benum.iter_entries() %}
|
||||||
{{ entry.get_entry_name() }} = {% if entry.get_entry_value() is none -%} auto() {%- else -%} {{ entry.get_entry_value() }} {%- endif %} {%- if entry.get_entry_comment() is not none %}
|
{{ entry.get_entry_name() }} = {% if entry.get_entry_value() is none -%} auto() {%- else -%} {{ utils.convert_to_python_number(entry.get_entry_value()) }} {%- endif %} {%- if entry.get_entry_comment() is not none %}
|
||||||
"""{{ entry.get_entry_comment() }}""" {%- endif %}
|
"""{{ entry.get_entry_comment() | line_comment }}""" {%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user