/*
 * Copyright 2016, Hridesh Rajan, Robert Dyer, Neha Bhide
 *                 Iowa State University of Science and Technology
 *                 and Bowling Green State University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package boa.compiler.transforms;

import boa.compiler.ast.Program;
import boa.compiler.visitors.AbstractVisitorNoArg;

/**
 * Converts use of current(T) inherited attributes in visitors into stack variables.
 * 
 * General algorithm:
 * 
 * 1) Find all instances of "current(T)" in the AST
 * 2) Collect set of all unique types T found in #1
 * 3) For each type T in the set from #2:
 *    a) Add a variable 's_T' of type 'stack of T' at the top-most scope of the AST
 *    b) Where-ever we encounter 'current(T)', replace with code for 's_T.peek()'
 *    c) Add/Update the before clause for T
 *       i)  If the visitor has a 'before T' clause, add 's_t.push(node)' as the first statement
 *       ii) Otherwise, add a 'before T' clause with a 's_t.push(node)'
 *    d) Add/Update the after clause for T
 *       i)  If the visitor has a 'after T' clause, add 's_t.pop()' as the first statement
 *       ii) Otherwise, add a 'after T' clause with a 's_t.pop()'
 * 
 * @author rdyer
 * @author nbhide
 */
public class InheritedAttributeTransformer extends AbstractVisitorNoArg {
	/** {@inheritDoc} */
	@Override
	public void visit(final Program n) {
		// TODO
	}
}

@@ -947,18 +947,17 @@
 bles.%0A *
- 
 %0A
+
  * Gener
@@ -976,15 +976,79 @@
 :%0A *
- 
 %0A * 1)
+ Find each instance of VisitorExpression, then for each:%0A *    a)
  Fin
@@ -1090,16 +1090,23 @@
 the 
-AST%0A * 2
+visitor%0A *    b
 ) Co
@@ -1150,15 +1150,18 @@
  in 
-#
 1
+a
 %0A * 
-3
+   c
 ) Fo
@@ -1194,18 +1194,18 @@
 rom 
-#2
+1b
 :%0A *    
 a) A
@@ -1200,18 +1200,23 @@
 :%0A *    
-a)
+   i)  
  Add a v
@@ -1227,16 +1227,18 @@
 ble 's_T
+_#
 ' of typ
@@ -1291,18 +1291,23 @@
 T%0A *    
-b)
+   ii) 
  Where-e
@@ -1363,16 +1363,18 @@
 for 's_T
+_#
 .peek()'
@@ -1380,17 +1380,22 @@
 '%0A *    
+ 
-c
+  iii
 ) Add/Up
@@ -1414,32 +1414,47 @@
 ore clause for T
+ in the visitor
 %0A *       i)  If
@@ -1439,35 +1439,39 @@
 isitor%0A *       
-i) 
+     a)
  If the visitor 
@@ -1499,24 +1499,26 @@
 se, add 's_t
+_#
 .push(node)'
@@ -1542,34 +1542,38 @@
 tement%0A *       
+     
-ii
+b
 ) Otherwise, add
@@ -1604,16 +1604,18 @@
 h a 's_t
+_#
 .push(no
@@ -1629,10 +1629,15 @@
     
-d)
+   iv) 
  Add
@@ -1666,16 +1666,31 @@
 se for T
+ in the visitor
 %0A *     
@@ -1691,19 +1691,23 @@
 *       
-i) 
+     a)
  If the 
@@ -1742,24 +1742,26 @@
 se, add 's_t
+_#
 .pop()' as t
@@ -1788,18 +1788,22 @@
 *       
-ii
+     b
 ) Otherw
@@ -1841,16 +1841,18 @@
 h a 's_t
+_#
 .pop()'%0A
@@ -1853,17 +1853,16 @@
 op()'%0A *
- 
 %0A * @aut

update algorithm