Example #1
0
  Exp transDec(Absyn.TypeDec d) {
    // 1st pass - handles the type headers
    // Using a local hashtable, check if there are two types
    // with the same name in the same (consecutive) batch
    // of mutually recursive types. See test38.tig!
    Hashtable hash = new Hashtable();
    for (Absyn.TypeDec type = d; type != null; type = type.next) {
      if (hash.put(type.name, type.name) != null) error(type.pos, "type redeclared");
      type.entry = new Types.NAME(type.name);
      env.tenv.put(type.name, type.entry);
    }

    // 2nd pass - handles the type bodies
    for (Absyn.TypeDec type = d; type != null; type = type.next) {
      Types.NAME name = (Types.NAME) type.entry;
      name.bind(transTy(type.ty));
    }

    // check for illegal cycle in type declarations
    for (Absyn.TypeDec type = d; type != null; type = type.next) {
      Types.NAME name = (Types.NAME) type.entry;
      if (name.isLoop()) error(type.pos, "illegal type cycle");
    }
    return translate.TypeDec();
  }