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; package decaf.symbol;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import decaf.Driver; import decaf.Driver;
import decaf.Location; import decaf.Location;
...@@ -172,15 +173,32 @@ public class Class extends Symbol { ...@@ -172,15 +173,32 @@ public class Class extends Symbol {
if (sym.isVariable()) { if (sym.isVariable()) {
sym.setOrder(numVar++); sym.setOrder(numVar++);
size += OffsetCounter.WORD_SIZE; size += OffsetCounter.WORD_SIZE;
} else if (!((Function) sym).isStatik()) { } else if (sym.isFunctionTable()){
for (Function func : ((FunctionTable) sym).getFunctions()) {
if (!func.isStatik()) {
if (ps == null) { if (ps == null) {
sym.setOrder(numNonStaticFunc++); func.setOrder(numNonStaticFunc++);
} else { } else {
Symbol s = ps.lookupVisible(sym.name); Symbol s = ps.lookupVisible(func.name);
if (s == null) { if (s == null) {
sym.setOrder(numNonStaticFunc++); func.setOrder(numNonStaticFunc++);
} else if (!s.isFunctionTable()) {
func.setOrder(s.getOrder());
} else { } else {
sym.setOrder(s.getOrder()); 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; ...@@ -12,6 +12,7 @@ import decaf.machdesc.Intrinsic;
import decaf.scope.ClassScope; import decaf.scope.ClassScope;
import decaf.symbol.Class; import decaf.symbol.Class;
import decaf.symbol.Function; import decaf.symbol.Function;
import decaf.symbol.FunctionTable;
import decaf.symbol.Symbol; import decaf.symbol.Symbol;
import decaf.symbol.Variable; import decaf.symbol.Variable;
import decaf.tac.Functy; import decaf.tac.Functy;
...@@ -90,7 +91,7 @@ public class Translater { ...@@ -90,7 +91,7 @@ public class Translater {
} else { } else {
functy.label = Label.createLabel("_" functy.label = Label.createLabel("_"
+ ((ClassScope) func.getScope()).getOwner().getName() + "." + ((ClassScope) func.getScope()).getOwner().getName() + "."
+ func.getName(), true); + func.toSignature(), true);
} }
functy.sym = func; functy.sym = func;
func.setFuncty(functy); func.setFuncty(functy);
...@@ -143,13 +144,17 @@ public class Translater { ...@@ -143,13 +144,17 @@ public class Translater {
Iterator<Symbol> iter = cs.iterator(); Iterator<Symbol> iter = cs.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Symbol sym = iter.next(); Symbol s = iter.next();
if (sym.isFunction() && !((Function) sym).isStatik()) { if (s.isFunctionTable()) {
Function func = (Function) sym; List<Function> functions = ((FunctionTable) s).getFunctions();
for (Function func : functions) {
if (!func.isStatik()) {
vt.entries[func.getOrder()] = func.getFuncty().label; vt.entries[func.getOrder()] = func.getFuncty().label;
} }
} }
} }
}
}
public void append(Tac tac) { public void append(Tac tac) {
if (currentFuncty.head == null) { if (currentFuncty.head == null) {
......
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