-/* This file is part of NIT ( http://www.nitlanguage.org ).
- *
- * Copyright 2008 Jean Privat <jean@pryen.org>
- * Based on algorithms developped for ( http://www.sablecc.org/ ).
- *
- * 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.
- */
+$ // This file is part of NIT ( http://www.nitlanguage.org ).
+$ //
+$ // Copyright 2008 Jean Privat <jean@pryen.org>
+$ // Based on algorithms developped for ( http://www.sablecc.org/ ).
+$ //
+$ // 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.
$ template make_abs_nodes()
# Root of the AST hierarchy
# Thus, call "v.visit(e)" for each node e starting from the last child
fun visit_all_reverse(v: Visitor) is abstract
- # Give a human readable location of the node.
- fun locate: String
- do
- if location == null then
- return "????"
- end
- return location.to_s
- end
-
# Debug method: output a message prefixed with the location.
fun printl(str: String)
do
- print("{locate}: {str}\n")
+ if location == null then
+ print("???: {str}\n")
+ else
+ print("{location}: {str}\n")
+ end
end
end
# Abstract standard visitor
class Visitor
+ # What the visitor do when a node is visited
+ # Concrete visitors should redefine this method.
+ protected fun visit(e: nullable PNode) is abstract
+
# Ask the visitor to visit a given node.
# Usually automatically called by visit_all* methods.
- # Concrete visitors should redefine this method.
- fun visit(e: nullable PNode) is abstract
+ # This methos should not be redefined
+ fun enter_visit(e: nullable PNode)
+ do
+ var old = _current_node
+ _current_node = e
+ visit(e)
+ _current_node = old
+ end
+
+ # The current visited node
+ readable var _current_node: nullable PNode = null
end
$ end template