mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-23 01:50:15 +08:00
GP-3183 Fixed CParser.parse(String) method with not data type archive.
Fixed return data type of method when parsing a structure.
This commit is contained in:
@@ -307,6 +307,8 @@ public class CParser {
|
||||
private DataType addDef(Map<String, DataType> table, String name, DataType dt) {
|
||||
// System.out.println("** addDef " + name + " = " + (dt != null ? dt.getName() : " - no type -") );
|
||||
|
||||
lastDataType = dt;
|
||||
|
||||
DataType existingDT = table.get(name);
|
||||
if (existingDT != null && dt.isEquivalent(existingDT)) {
|
||||
return existingDT;
|
||||
@@ -426,7 +428,7 @@ public class CParser {
|
||||
|
||||
hasNoComponents = (dtComp.getNumDefinedComponents() == 0 ? true : false);
|
||||
|
||||
hasSameSourceArchive = dt.getSourceArchive().equals(dtMgr.getLocalSourceArchive());
|
||||
hasSameSourceArchive = Objects.equals(dt.getSourceArchive(), dtMgr.getLocalSourceArchive());
|
||||
}
|
||||
|
||||
// make sure comp is a Composite, if existing dt is empty, in same category and archive
|
||||
|
||||
@@ -51,6 +51,21 @@ public class CParserTest extends AbstractGenericTest {
|
||||
DataType dt = parser.getDataTypeManager().getDataType("/int32_t");
|
||||
assertTrue(dt != null);
|
||||
assertTrue(dt instanceof TypeDef);
|
||||
|
||||
dt = parser.parse("struct mystruct {" +
|
||||
" int field1;" +
|
||||
" char field2;" +
|
||||
" };");
|
||||
|
||||
assertTrue(dt != null);
|
||||
assertTrue(dt instanceof Structure);
|
||||
Structure sdt = (Structure) dt;
|
||||
DataTypeComponent comp = sdt.getComponent(0);
|
||||
assertEquals("field1", comp.getFieldName());
|
||||
assertEquals(comp.getDataType().getName(),"int");
|
||||
comp = sdt.getComponent(1);
|
||||
assertEquals("field2", comp.getFieldName());
|
||||
assertEquals(comp.getDataType().getName(),"char");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user