scale.clef
Class Node

java.lang.Object
  extended by scale.common.Root
      extended by scale.clef.Node
All Implemented Interfaces:
AnnotationInterface, DisplayNode
Direct Known Subclasses:
AltCase, Bound, Declaration, Expression, Raise, Statement, Type

public abstract class Node
extends Root

The base class for the Clef representation.

$Id: Node.java,v 1.83 2007-03-21 13:31:49 burrill Exp $

Copyright 2007 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.


Constructor Summary
Node()
          Constructor for a Clef node object.
 
Method Summary
 Node getChild(int i)
          Return the specified AST child of this node.
 Type getCoreType()
          Return the actual Type associated with this Node.
 Declaration getDecl()
          Return any Declaration associated with this Node.
 int getSourceLineNumber()
          Return the source line number associated with this node or -1 if not known.
 Type getType()
          Return the Type associated with this Node.
 int numChildren()
          Return the number of AST children of this node.
static void setAnnotationLevel(int level)
          Set the depth to which a node displays it's annotations.
static void setReportLevel(int level)
          Set the depth to which a node displays it's children.
 void setSourceLineNumber(int lineNumber)
          Set the source line number associated with this node or -1 if not known.
 java.lang.String toString()
           
 java.lang.String toString(java.lang.String del1, java.lang.String del2)
          The toString() method with begin and end delimiters specified.
 java.lang.String toStringChildren()
          Convert children of this node to a string representation.
 java.lang.String toStringSpecial()
          This method allows sub-classes to provide class specific stuff to the string.
abstract  void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.common.Root
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayColorHint, getDisplayLabel, getDisplayName, getDisplayShapeHint, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, hashCode, removeAnnotation, removeAnnotations, toStringAnnotations, toStringClass, trace, trace, trace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

public Node()
Constructor for a Clef node object.

Method Detail

visit

public abstract void visit(Predicate p)
Process a node by calling its associated routine. See the "visitor" design pattern in Design Patterns: Elements of Reusable Object-Oriented Software by E. Gamma, et al, Addison Wesley, ISBN 0-201-63361-2.

Each class has a visit(Predicate p) method. For example, in class ABC:

   public void visit(Predicate p)
   {
     p.visitABC(this);
   }
 
and the class that implements Predicate has a method
   public void visitABC(Node n)
   {
     ABC a = (ABC) n;
     ...
   }
 
Thus, the class that implements Predicate can call
   n.visit(this);
 
where n is a Node sub-class without determining which specific sub-class n is. The visit pattern basically avoids implementing a large switch statement or defining different methods in each class for some purpose.

See Also:
Predicate

getType

public Type getType()
Return the Type associated with this Node.


getCoreType

public Type getCoreType()
Return the actual Type associated with this Node. Note - getType() should always be used when the Type is not examined or when the attributes are needed.

See Also:
getType(), RefType

getDecl

public Declaration getDecl()
Return any Declaration associated with this Node.


numChildren

public int numChildren()
Return the number of AST children of this node.


getChild

public Node getChild(int i)
Return the specified AST child of this node.


toStringChildren

public java.lang.String toStringChildren()
Convert children of this node to a string representation.


setReportLevel

public static void setReportLevel(int level)
Set the depth to which a node displays it's children.


setAnnotationLevel

public static void setAnnotationLevel(int level)
Set the depth to which a node displays it's annotations.


toString

public java.lang.String toString()
Overrides:
toString in class Root

toString

public final java.lang.String toString(java.lang.String del1,
                                       java.lang.String del2)
The toString() method with begin and end delimiters specified.


toStringSpecial

public java.lang.String toStringSpecial()
This method allows sub-classes to provide class specific stuff to the string.

Overrides:
toStringSpecial in class Root

getSourceLineNumber

public int getSourceLineNumber()
Return the source line number associated with this node or -1 if not known.


setSourceLineNumber

public void setSourceLineNumber(int lineNumber)
Set the source line number associated with this node or -1 if not known.