Eliminate unused refined attributes

Issue #281 new
Jesper Öqvist created an issue

With JastAdd 2.2.2, an attribute that is refined but not used by the refined version is still emitted in the generated Java code. This can add a lot of unnecessary generated code.

For example, in ExtendJ's Java 8 module, the TypeDecl.typeProblems() attribute is refined. The original version is not used, so we get a large unused method declaration in the generated code:

  private Collection<Problem> refined_TypeHierarchyCheck_TypeDecl_typeProblems()
{
    Collection<Problem> problems = new LinkedList<Problem>();
    // 8.4.6.4 & 9.4.1
    for (Iterator iter1 = localMethodsIterator(); iter1.hasNext(); ) {
      MethodDecl m = (MethodDecl) iter1.next();
      ASTNode target = m.hostType() == this ? (ASTNode) m : (ASTNode) this;

      for (MethodDecl decl : ancestorMethods(m.signature())) {
        if (m.overrides(decl)) {
          // 8.4.6.1
...

If the original attribute code is just ignored in this case, it would save space in the generated Java code. It might even slightly improve the runtime performance of the generated code.

A disadvantage of not generating unused refined code is that errors in the unused code might go unnoticed.

Comments (0)

  1. Log in to comment