This commit is contained in:
Guus Waals 2025-05-29 20:36:01 +08:00
parent e7417745fd
commit b0b4683f7d
2 changed files with 355 additions and 362 deletions

File diff suppressed because it is too large Load Diff

View File

@ -231,7 +231,9 @@ public class DataTypeWriter {
code.append(annotator.getPrefix(composite, component));
String fieldName = component.getFieldName();
if (fieldName == null || fieldName.length() == 0) {
String originalName = fieldName;
boolean needsFixing = fieldName != null && fieldName.contains("?");
if (fieldName == null || fieldName.length() == 0 || needsFixing) {
fieldName = component.getDefaultFieldName();
}
@ -250,8 +252,12 @@ public class DataTypeWriter {
code.append(annotator.getSuffix(composite, component));
String comment = component.getComment();
if (comment != null && comment.length() > 0) {
code.append(" ").append(comment(comment));
String commentText = comment != null && comment.length() > 0 ? comment : "";
if (needsFixing) {
commentText += (commentText.length() > 0 ? " " : "") + "(fix name \"" + originalName + "\")";
}
if (commentText.length() > 0) {
code.append(" ").append(comment(commentText));
}
code.append(EOL);
}
@ -297,8 +303,6 @@ public class DataTypeWriter {
String dataTypeName = dataType.getDisplayName();
if (!isIntegral(typedefName, dataTypeName)) {
DataType baseType = typeDef.getBaseDataType();
// Add dependency only if it's not a pointer
if (!isPointerType(dataType)) {
DataType depType = getImmediateDependencyType(dataType);
@ -314,24 +318,17 @@ public class DataTypeWriter {
private void writeBuiltInBlock(BuiltInDataType dt, StringBuilder code, Set<String> dependencies) {
String declaration = dt.getCTypeDeclaration(this.dataOrganization);
if (declaration != null && !dt.getDisplayName().equals("bool")) {
if (declaration != null) {
code.append(declaration);
}
}
private boolean isPointerType(DataType dt) {
return dt instanceof Pointer;
}
private boolean isBuiltInType(DataType dt) {
return dt instanceof BuiltInDataType ||
dt.getDisplayName().equals("void") ||
dt.getDisplayName().equals("char") ||
dt.getDisplayName().equals("int") ||
dt.getDisplayName().equals("short") ||
dt.getDisplayName().equals("long") ||
dt.getDisplayName().equals("float") ||
dt.getDisplayName().equals("double");
return dt instanceof BuiltInDataType;
}
private DataType getImmediateDependencyType(DataType dt) {
@ -348,23 +345,6 @@ public class DataTypeWriter {
return dt;
}
private DataType getBaseDataType(DataType dt) {
while (dt != null) {
if (dt instanceof Array) {
dt = ((Array) dt).getDataType();
} else if (dt instanceof Pointer) {
dt = ((Pointer) dt).getDataType();
} else if (dt instanceof BitFieldDataType) {
dt = ((BitFieldDataType) dt).getBaseDataType();
} else if (dt instanceof TypeDef) {
dt = ((TypeDef) dt).getBaseDataType();
} else {
break;
}
}
return dt;
}
private String getTypeDeclaration(String name, DataType dataType, int instanceLength) {
if (name == null) {
name = "";
@ -399,7 +379,15 @@ public class DataTypeWriter {
}
String prefix = getDataTypePrefix(dataType);
String componentString = prefix + dataType.getDisplayName();
String dataTypeString;
if (dataType instanceof AbstractIntegerDataType) {
dataTypeString = ((AbstractIntegerDataType)dataType).getCDeclaration();
} else {
dataTypeString = dataType.getDisplayName();
}
String componentString = prefix + dataTypeString;
if (name.length() != 0) {
componentString = componentString + " " + name;
}
@ -408,7 +396,12 @@ public class DataTypeWriter {
}
private String getDataTypePrefix(DataType dataType) {
dataType = getBaseDataType(dataType);
// Don't add struct/union prefix for typedefs - they already have their own name
if (dataType instanceof TypeDef) {
return "";
}
// Only add struct/union prefix for direct struct/union references (not typedefs)
if (dataType instanceof Structure) {
return "struct ";
} else if (dataType instanceof Union) {