private void translateInterfaceFuncDef( InterfaceDef interfaceDef, List<ClassDef> instances, FuncDef funcDef) { AstElement trace = funcDef; ImFunction f = translator.getDynamicDispatchFuncFor(funcDef); Map<ClassDef, FuncDef> instances2 = translator.getClassesWithImplementation(instances, funcDef); if (instances2.size() > 0) { int maxTypeId = translator.getMaxTypeId(instances); f.getBody() .addAll( translator.createDispatch(instances2, funcDef, f, maxTypeId, new TypeIdGetterImpl())); } if (!funcDef.attrHasEmptyBody()) { // TODO add default implementation f.getBody().addAll(translator.translateStatements(f, funcDef.getBody())); } else { // create dynamic message when not matched: String msg = "ERROR: invalid type for interface dispatch when calling " + interfaceDef.getName() + "." + funcDef.getName(); f.getBody() .add( JassIm.ImFunctionCall( trace, translator.getDebugPrintFunc(), ImExprs(ImStringVal(msg)))); if (!(funcDef.attrTyp() instanceof WurstTypeVoid)) { // add return statement ImType type = f.getReturnType(); ImExpr def = translator.getDefaultValueForJassType(type); f.getBody().add(JassIm.ImReturn(trace, def)); } } }
public void translate() { translator.getImProg().getClasses().add(imClass); // set super-classes for (TypeExpr ext : interfaceDef.getExtendsList()) { if (ext.attrTypeDef() instanceof StructureDef) { StructureDef sup = (StructureDef) ext.attrTypeDef(); imClass.getSuperClasses().add(translator.getClassFor(sup)); } } // create dispatch methods for (FuncDef f : interfaceDef.getMethods()) { translateInterfaceFuncDef(f); } // add destroy method addDestroyMethod(); }
public void translate() { // TODO implement @castable // get classes implementing this interface List<ClassDef> instances = Lists.newArrayList(translator.getInterfaceInstances(interfaceDef)); // sort instances by typeid Collections.sort(instances, new TypeIdComparator(translator)); // create dispatch methods for (FuncDef f : interfaceDef.getMethods()) { translateInterfaceFuncDef(interfaceDef, instances, f); } }