com.veromodo.tempo.filters.rules
Class CounterRule

java.lang.Object
  extended by com.veromodo.tempo.filters.rules.CounterRule
All Implemented Interfaces:
SemanticRule
Direct Known Subclasses:
IdCounter

public class CounterRule
extends java.lang.Object
implements SemanticRule

Defines a SemanticRule requireing counting of nodes. for example "an expression only has one quantifier".

Semantics of Rule: Rule(n,x,S,F,P) : class(n)== X && S(n) => P(|F(n)|) Where
- |z| denotes the size of z
- n is a node
- x is a class
- S is a semantic rule to determine when The counting should start (the root of the subtree where it applies)
- F is a semantic rule to filter the nodes in the subtree where the counting occurs.
- P is a predicate on integers that tests the value of the counter.

Note how F is going to be applied on all the nodes reachable from the root n satisfying the guard (class(n)==x && S(n))


Constructor Summary
CounterRule(java.lang.Class c, BasicRule startPred, BasicRule filterPred, IntegerPredicate numPred)
          Constructor.
 
Method Summary
 boolean eval(ASTNode n)
          evaluates the ASTNode n.
 java.lang.Class getNodeClass()
          provides the class of the root node which the semantic Rule is defined for.
 boolean IgnoreSubtree()
          boolean value if the subtree should be ignored.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CounterRule

public CounterRule(java.lang.Class c,
                   BasicRule startPred,
                   BasicRule filterPred,
                   IntegerPredicate numPred)
Constructor. Creates a counting rule.

Parameters:
c - ASTNode type which the counting should start on
startPred - identifies the criteria to start a count
filterPred - identifies the criteria count a node
numPred - evaulates if the count is satifactory
Method Detail

getNodeClass

public java.lang.Class getNodeClass()
Description copied from interface: SemanticRule
provides the class of the root node which the semantic Rule is defined for. This is used to filter when a check is executed, so that it is not performed on every node.

Specified by:
getNodeClass in interface SemanticRule
Returns:
the class which counting starts on.

IgnoreSubtree

public boolean IgnoreSubtree()
Description copied from interface: SemanticRule
boolean value if the subtree should be ignored. This is used to to deside if the subtree should have the current set of rules applied to it.

Specified by:
IgnoreSubtree in interface SemanticRule
Returns:
true if the subtree should be ignored

eval

public boolean eval(ASTNode n)
evaluates the ASTNode n. Returns true if the ASTNode matches the counting critera, false otherwise. Reports errors if necessary.

Specified by:
eval in interface SemanticRule
Parameters:
n - an ASTNode to be checked.
Returns:
true if the ASTNode counting matches.