Commit c544bc37 by Tianqi Yang

feat(overload): handle overloaded functions while tranlating

Modify symbol.Class.resolveFieldOrder: - handle overloaded functions while calculating the offset of each member of a class Modfiy translate.Translater.fillVTableEntries: - handle overloaded functions while building VTable Modify translate.Translater.createFuncty: - replace the function names with function signatures
parent d5dd7e00
package decaf.symbol;
import java.util.Iterator;
import java.util.List;
import decaf.Driver;
import decaf.Location;
......@@ -172,15 +173,32 @@ public class Class extends Symbol {
if (sym.isVariable()) {
sym.setOrder(numVar++);
size += OffsetCounter.WORD_SIZE;
} else if (!((Function) sym).isStatik()) {
if (ps == null) {
sym.setOrder(numNonStaticFunc++);
} else {
Symbol s = ps.lookupVisible(sym.name);
if (s == null) {
sym.setOrder(numNonStaticFunc++);
} else {
sym.setOrder(s.getOrder());
} else if (sym.isFunctionTable()){
for (Function func : ((FunctionTable) sym).getFunctions()) {
if (!func.isStatik()) {
if (ps == null) {
func.setOrder(numNonStaticFunc++);
} else {
Symbol s = ps.lookupVisible(func.name);
if (s == null) {
func.setOrder(numNonStaticFunc++);
} else if (!s.isFunctionTable()) {
func.setOrder(s.getOrder());
} else {
List<Function> functions = ((FunctionTable) s).getFunctions();
boolean found = false;
for (Function f : functions) {
if (!f.isStatik() && func.conflictArgList(f)) {
func.setOrder(f.getOrder());
found = true;
break;
}
}
if (!found) {
func.setOrder(numNonStaticFunc++);
}
}
}
}
}
}
......
......@@ -12,6 +12,7 @@ import decaf.machdesc.Intrinsic;
import decaf.scope.ClassScope;
import decaf.symbol.Class;
import decaf.symbol.Function;
import decaf.symbol.FunctionTable;
import decaf.symbol.Symbol;
import decaf.symbol.Variable;
import decaf.tac.Functy;
......@@ -90,7 +91,7 @@ public class Translater {
} else {
functy.label = Label.createLabel("_"
+ ((ClassScope) func.getScope()).getOwner().getName() + "."
+ func.getName(), true);
+ func.toSignature(), true);
}
functy.sym = func;
func.setFuncty(functy);
......@@ -143,10 +144,14 @@ public class Translater {
Iterator<Symbol> iter = cs.iterator();
while (iter.hasNext()) {
Symbol sym = iter.next();
if (sym.isFunction() && !((Function) sym).isStatik()) {
Function func = (Function) sym;
vt.entries[func.getOrder()] = func.getFuncty().label;
Symbol s = iter.next();
if (s.isFunctionTable()) {
List<Function> functions = ((FunctionTable) s).getFunctions();
for (Function func : functions) {
if (!func.isStatik()) {
vt.entries[func.getOrder()] = func.getFuncty().label;
}
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment