Convert to Scope ids

This commit is contained in:
caheckman 2020-09-30 11:29:50 -04:00
parent 97b04cac7e
commit 7c0b21f0dc
17 changed files with 394 additions and 327 deletions

View file

@ -615,22 +615,33 @@ public class HighFunction extends PcodeSyntaxTree {
}
}
/**
* The decompiler treats some namespaces as equivalent to the "global" namespace.
* Return true if the given namespace is treated as equivalent.
* @param namespace is the namespace
* @return true if equivalent
*/
static final public boolean collapseToGlobal(Namespace namespace) {
if (namespace instanceof Library) {
return true;
}
return false;
}
/**
* Append an XML <parent> tag to the buffer describing the formal path elements
* from the root (global) namespace up to the given namespace
* @param buf is the buffer to write to
* @param namespace is the namespace being described
* @param includeId is true if the XML tag should include namespace ids
*/
static public void createNamespaceTag(StringBuilder buf, Namespace namespace,
boolean includeId) {
static public void createNamespaceTag(StringBuilder buf, Namespace namespace) {
buf.append("<parent>\n");
if (namespace != null) {
ArrayList<Namespace> arr = new ArrayList<Namespace>();
Namespace curspc = namespace;
while (curspc != null) {
arr.add(0, curspc);
if (curspc instanceof Library) {
if (collapseToGlobal(curspc)) {
break; // Treat library namespace as root
}
curspc = curspc.getParentNamespace();
@ -639,9 +650,7 @@ public class HighFunction extends PcodeSyntaxTree {
for (int i = 1; i < arr.size(); ++i) {
Namespace curScope = arr.get(i);
buf.append("<val");
if (includeId) {
SpecXmlUtils.encodeUnsignedIntegerAttribute(buf, "id", curScope.getID());
}
SpecXmlUtils.encodeUnsignedIntegerAttribute(buf, "id", curScope.getID());
buf.append('>');
SpecXmlUtils.xmlEscape(buf, curScope.getName());
buf.append("</val>\n");

View file

@ -338,7 +338,13 @@ public class LocalSymbolMap {
resBuf.append("<scope");
SpecXmlUtils.xmlEscapeAttribute(resBuf, "name", func.getFunction().getName());
resBuf.append(">\n");
HighFunction.createNamespaceTag(resBuf, namespace, false);
resBuf.append("<parent");
long parentid = Namespace.GLOBAL_NAMESPACE_ID;
if (!HighFunction.collapseToGlobal(namespace)) {
parentid = namespace.getID();
}
SpecXmlUtils.encodeUnsignedIntegerAttribute(resBuf, "id", parentid);
resBuf.append("/>\n");
resBuf.append("<rangelist/>\n"); // Empty address range
resBuf.append("<symbollist>\n");
Iterator<HighSymbol> iter = symbolMap.values().iterator();