- Iterator<TokenTupleSet> rulesItr = rules.iterator();
- while(rulesItr.hasNext()) {
- TokenTupleSet rule = rulesItr.next();
-
- TokenTupleSet ttsEmpty = new TokenTupleSet().makeCanonical();
- ReachabilitySet rewrittenRule = new ReachabilitySet(ttsEmpty).makeCanonical();
-
- Iterator<TokenTuple> ruleItr = rule.iterator();
- while(ruleItr.hasNext()) {
- TokenTuple ttCallee = ruleItr.next();
-
- // compute the possibilities for rewriting this callee token
- ReachabilitySet ttCalleeRewrites = null;
-
- if( ttCallee.equals( p_i ) ) {
- // replace the arity-one token of the current parameter with the reachability
- // information from the caller node
- ttCalleeRewrites = hrn.getAlpha();
-
- } else if( paramToken2paramIndex.containsKey( ttCallee ) ||
- paramTokenStar2paramIndex.containsKey( ttCallee ) ) {
- // this token is another callee parameter, or any ARITY_MANY callee parameter,
- // so rewrite it with the D rules for that parameter
- Integer paramIndex_j;
- if( paramToken2paramIndex.containsKey( ttCallee ) ) {
- paramIndex_j = paramToken2paramIndex.get( ttCallee );
- } else {
- paramIndex_j = paramTokenStar2paramIndex.get( ttCallee );
- }
-
- ttCalleeRewrites = paramIndex2rewriteD.get( paramIndex_j );
- assert ttCalleeRewrites != null;
-
- } else {
- // otherwise there's no need for a rewrite, just pass this one on
- TokenTupleSet ttsCaller = new TokenTupleSet(ttCallee).makeCanonical();
- ttCalleeRewrites = new ReachabilitySet(ttsCaller).makeCanonical();
- }
-
- // branch every version of the working rewritten rule with
- // the possibilities for rewriting the current callee token
- ReachabilitySet rewrittenRuleWithTTCallee = new ReachabilitySet().makeCanonical();
-
- Iterator<TokenTupleSet> rewrittenRuleItr = rewrittenRule.iterator();
- while( rewrittenRuleItr.hasNext() ) {
- TokenTupleSet ttsRewritten = rewrittenRuleItr.next();
-
- Iterator<TokenTupleSet> ttCalleeRewritesItr = ttCalleeRewrites.iterator();
- while( ttCalleeRewritesItr.hasNext() ) {
- TokenTupleSet ttsBranch = ttCalleeRewritesItr.next();
-
- rewrittenRuleWithTTCallee =
- rewrittenRuleWithTTCallee.union( ttsRewritten.unionUpArity( ttsBranch ) );
- }
- }
-
- // now the rewritten rule's possibilities have been extended by
- // rewriting the current callee token, remember result
- rewrittenRule = rewrittenRuleWithTTCallee;
- }
-
- // the rule has been entirely rewritten into the caller context
- // now, so add it to the new reachability information
- callerReachability =
- callerReachability.union( rewrittenRule );