Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[henshin-dev] Ascending tree traversal with parameters and multiple rules

Hello,

I recently worked on a set of Henshin rules (packaged as a
transformation unit) which should traverse a number of objects
structured as a tree (more specifically, an abstract syntax tree (AST)
of a Java program) and the questions arises, whether there is any
possibility to let Henshin obtain one transformation unit "output"
parameter from a set of containing rules equally?

More specifically, I came along this problem:

My input value is a node of the AST and the goal of the transformation
unit is, that I receive a specific parent node through a parameter,
after no rule could be applied any more. I already have a transformation
unit doing this, working on classes and their respective parents, which
ascends the class inheritance tree step by step---starting with a given
class X' and returning her parent-class X. The rules are structures as
follows:

searchBaseClass (counted unit, count = -1):
  getExtendedClass (rule):
    class (parameter)
    extendedClass (parameter)
  
  class (parameter)

The unit parameter "class" is set by the surrounding transformation
unit, sets the rule parameter "class" to its own value and will be
re-set according to the rule parameter "extendedClass" after every
successful application of the rule so that the "class" parameter of the
unit eventually contains the uppermost class of the inheritance tree.

Now, I wanted to model a similar action, but instead of working on
classes, the rules have to work on program statements
(System.out.println("Hello, World")) and their containers
(If-Conditions, Switch-Case, Loops) eventually resulting in receiving
the class method the statement is contained in. The structure so far is:

searchContainingClassMethod (counted unit, count = -1):
  getContainer (independent unit):
    getContainerStatementInStatementContainer (rule):
      contained (parameter)
      container (parameter)

    getContainerStatementInCondition (rule):
      contained (parameter)
      container (parameter)
    ...

    contained (parameter)
    container (parameter)

  statement (parameter)

The unit parameter "statement" is set by the surrounding transformation
unit, sets the inner unit parameter "contained" to its own value and
will be re-set according to the inner unit parameter "container" after
every successful application of the inner transformation unit so that
"statement" eventually contains the class method containing the initial
method call.

The problem I experienced was, that because I have multiple rules (as
the structure of the AST contains a lot of "special cases" for certain
syntactical features) working on the "container" and "contained"
parameters, I can't map every "container" output parameter of every rule
to the "container" parameter of the surrounding transformation unit but
only one---resulting in an infinite application of one rule (because the
previous container will only be re-set by one single rule).

Greets,
Johannes



Back to the top