示例#1
0
  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();
  }
示例#2
0
 private static void assertNonCyclicClassHierarchy(ClassDef c, List<ClassDef> hierarchy) {
   if (hierarchy.contains(c)) {
     ClassDef start = hierarchy.get(0);
     throw new CompileError(
         start.getSource(),
         "Class "
             + start.getName()
             + " has a cyclic class hierarchy: "
             + hierarchy.stream().map(ClassDef::getName).collect(Collectors.joining(" < ")));
   }
   OptTypeExpr ext = c.getExtendedClass();
   if (ext instanceof TypeExpr) {
     TypeExpr extT = (TypeExpr) ext;
     if (extT.attrTypeDef() instanceof ClassDef) {
       ClassDef extC = (ClassDef) extT.attrTypeDef();
       hierarchy.add(c);
       assertNonCyclicClassHierarchy(extC, hierarchy);
     }
   }
 }