CrispOSS / jabsc

ABS Compiler for Java
Apache License 2.0
1 stars 1 forks source link

Adding an argument to a JavaWriter beginType method based on the JavaWriter after a recursive visit #8

Closed vlad-serbanescu closed 9 years ago

vlad-serbanescu commented 9 years ago
public Prog visit(ClassImplements p, JavaWriter w) {
    try {
      w.beginType(p.uident_, "class", DEFAULT_MODIFIERS, "TODO:visit Qtype");

    for (QType impl : p.listqtype_) {
        impl.accept(this, w);
      }
     w.emitEmptyLine();

      for (ClassBody cb : p.listclassbody_1) {
        cb.accept(this, w);
      }
      for (ClassBody cb : p.listclassbody_2) {
        cb.accept(this, w);
      }
      w.endType();
      return prog;
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

We have to insert as the argument what w emits after visiting p.

nobeh commented 9 years ago

Let's work by example. Can we two examples of small ABS code showing one ClassDecl and one ClassImplements? Because these are two that we actually begin a new Java class for.

vlad-serbanescu commented 9 years ago

module PrimeCWI; import * from ABS.FLI;

interface IPrime { Unit divide (Int n); }

interface IRead { Int read(); }

[Foreign] class Read implements IRead { Int read() { return 10000; // stub } }

class Sieve(Int bound) { Int n = 0; IPrime two; { two = new Prime(2); n = 3; } Unit run() { while (n < bound) { two!divide(n) ; n = n + 1; } } }

class Prime (Int p) implements IPrime { IPrime next; Unit divide (Int n) { if ( (n % p) != 0) { if (next != null) { next!divide (n); } else { next = new Prime(n); } } } }

{ IRead r = new local Read(); Int bound = r.read(); new Sieve(bound); }

This has both types of Class Declarations. Al classes in ABS have to implement at least one interface to have some behaviour other than run(). If a class doesn't implement an interface it only has the run() method. Such a class must extend abs.api.Actor all others implement interfaces that implicitly extend abs.api.Actor

vlad-serbanescu commented 9 years ago

We can create a concatenation of getQTypeName(QType qtype) calls on p.listqtype_ instead of visiting all nodes of Qtype. I assume that is what that method is for in the Visitor.java class right ?

vlad-serbanescu commented 9 years ago

Closed on with this auxiliary method "protected String toString(ListQType qtypes, String delimiter)" implemented

nobeh commented 9 years ago

Plus, we started to use StringWriter for nesting generation of elements inside a higher element.