scale.clef.decl
Class Declaration

java.lang.Object
  |
  +--scale.common.Root
        |
        +--scale.clef.Node
              |
              +--scale.clef.decl.Declaration
All Implemented Interfaces:
AnnotationInterface, DisplayNode, java.io.Serializable
Direct Known Subclasses:
ExceptionDecl, FileDecl, LabelDecl, RoutineDecl, TypeDecl, TypeName, ValueDecl

public abstract class Declaration
extends Node

This is the base class for declarations such as variable, routines, etc.

$Id: Declaration.java,v 1.66 2002/01/03 21:42:42 burrill Exp $

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

See Also:
Serialized Form

Field Summary
static java.lang.String[] accessibilities
          The names of the accessibilities.
static byte cAuto
          Marks a data value as being locally allocated (i.e., on the stack).
static byte cExtern
          Indicates that an entity is defined external to this file scope.
static byte cFile
          Indicates that the entity is visible only within its file scope.
static byte cGlobal
          Indicates that an entity is defined in, and has global visibility outside, this file scope.
static byte cLocal
          Indicates that an entity is visible only within its current scope.
static byte cMemory
          Indicates that an entity is assigned to permanently allocated space.
static byte cPrivate
          Specifies that the method is accessible only within its namespace.
static byte cProtected
          Specifies than an identifier is accessible only within its namespace.
static byte cPublic
          Specifies that the method is accessible outside of its namespace.
static byte cRegister
          Recommends that a value be assigned to a register.
static java.lang.String[] residencies
          The names of the different residencies.
static java.lang.String[] visibilitys
          The names of the different visibilitys.
 
Fields inherited from interface scale.common.DisplayNode
ANNO, CLEF, DD, DEFUSE, DOM, EXPR, MAYUSE, TYPE
 
Constructor Summary
protected Declaration(java.lang.String n)
          Create a declaration with the specified name and no type.
protected Declaration(java.lang.String name, Type type)
          Create a declaration with the specified name and type.
 
Method Summary
 int accessibility()
          Return the declaration accessibility.
 boolean addressTaken()
          Return true if the address of this Declaration has been taken.
 java.lang.String DDname()
           
protected  void finalize()
          Keep the count of instances up-to-date.
 java.lang.Object getConstantValue()
          Return the constant value of the expression.
 Type getCoreType()
          Return the type of the Declaration without attributes.
 Declaration getDecl()
          Retun any Declaration associated with this Node.
 java.lang.String getDisplayColorHint()
          Return a String specifying the color to use for coloring this node in a graphical display.
 java.lang.String getDisplayShapeHint()
          Return a String specifying a shape to use when drawing this node in a graphical display.
 java.lang.String getDisplayText()
          Return a String suitable for labeling this node in a graphical display.
 java.lang.String getName()
          Return the name of the Declaration.
 Node getParent()
          Return my parent in the Clef tree if any
 SymtabScope getScope()
          Return the symbol table scope in which the declaration was declared.
 Node getScopeNode()
          Return the node which represents the clef scope node.
 int getTag()
          Return the tag associated with this variable.
 Type getType()
          Return the type of the Declaration.
 int hashCode()
          Use the name of the routine instead of the address of the instance so things are more predictable.
 boolean inMemory()
          Return true if this declaration is to be allocated to memory.
 boolean isFtnResultVar()
          Return true if the declaration is declared as the result variable of a function.
 boolean isGlobal()
          Return true if this declaration is globally visible.
 boolean isPure()
          Return true if this declaration has a PureFunctionAnnotation of level PUREGV.
 boolean isReferenced()
          Return true if the declaration is referenced somewhere in the Clef AST.
 boolean isTemporary()
          Return true if the declaration is a temporary variable.
 boolean isVariable()
          Return true if the declaration is a variable.
 boolean isVirtual()
          Return true if the declaration is a virtual variable.
static int number()
          Return the current number of instances of this class.
 int residency()
          Return the declaration residency.
 void setAccessibility(int accessibility)
          Specify the accessibility of the declaration.
 void setAddressTaken()
          Record that the address is used.
protected  void setChildParent(Vector v)
           
 void setName(java.lang.String name)
          Change the display name of the declaration.
 void setParent(Node s)
          Specify the parent node of this node.
 void setReferenced()
          Specify that the Declaration is referenced somewhere in the Clef AST.
 void setResidency(int residency)
          Specify the residency of the declaration.
 void setScope(SymtabScope scope)
          Specify the symbol table scope in which the declaration was declared.
 void setTag(int tag)
          Set the tag for this variable.
 void setType(Type type)
          Specify the type of this declaration.
 void setVisibility(int visibility)
          Specify the visibility of the declaration.
 java.lang.String toStringSpecial()
          Return any special information of a node that is not a child or annotation.
 int visibility()
          Return the declaration visibility.
 void visit(Predicate p)
          The visit() method is used to implement a visit 'pattern'.
 
Methods inherited from class scale.clef.Node
createChildren, getChildren, setAnnotationLevel, setReportLevel, toString, toString, toStringChildren
 
Methods inherited from class scale.common.Root
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayName, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, removeAnnotation, removeAnnotations, toStringAnnotations, toStringClass
 
Methods inherited from class java.lang.Object
clone, equals, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

cLocal

public static final byte cLocal
Indicates that an entity is visible only within its current scope. This is the default visibility.

cFile

public static final byte cFile
Indicates that the entity is visible only within its file scope. This attribute is intended to represent one meaning of the C/C++ static construct. Admittedly, this attribute should be redundant with cLocal when at the file scope level. However, this captures the notion of C/C++'s static construct; whereas, cLocal should never be used.

cGlobal

public static final byte cGlobal
Indicates that an entity is defined in, and has global visibility outside, this file scope.

cExtern

public static final byte cExtern
Indicates that an entity is defined external to this file scope. This attribute implements the common case of the C extern construct.

visibilitys

public static final java.lang.String[] visibilitys
The names of the different visibilitys.

cPublic

public static final byte cPublic
Specifies that the method is accessible outside of its namespace. This value is the default.

cProtected

public static final byte cProtected
Specifies than an identifier is accessible only within its namespace. This attribute may only be used for class members, in which case it denotes the semantics of C++'s protected construct.

cPrivate

public static final byte cPrivate
Specifies that the method is accessible only within its namespace.

accessibilities

public static final java.lang.String[] accessibilities
The names of the accessibilities.

cAuto

public static final byte cAuto
Marks a data value as being locally allocated (i.e., on the stack). Local allocation is the default form of allocation and so seldom (if ever) needs to be explicitly specified. This attribute represents C/C++'s auto construct.

cRegister

public static final byte cRegister
Recommends that a value be assigned to a register. If the value cannot be assigned to a register, it should be allocated on the stack.

cMemory

public static final byte cMemory
Indicates that an entity is assigned to permanently allocated space.

residencies

public static final java.lang.String[] residencies
The names of the different residencies.
Constructor Detail

Declaration

protected Declaration(java.lang.String n)
Create a declaration with the specified name and no type.

Declaration

protected Declaration(java.lang.String name,
                      Type type)
Create a declaration with the specified name and type.
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Keep the count of instances up-to-date.
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - [needs description]

number

public static int number()
Return the current number of instances of this class.

hashCode

public int hashCode()
Use the name of the routine instead of the address of the instance so things are more predictable.
Overrides:
hashCode in class Root

setScope

public final void setScope(SymtabScope scope)
Specify the symbol table scope in which the declaration was declared.

getScope

public final SymtabScope getScope()
Return the symbol table scope in which the declaration was declared.

setAccessibility

public void setAccessibility(int accessibility)
Specify the accessibility of the declaration.
Parameters:
accessibility - is the accessibility of the declaration
See Also:
cPublic, cProtected, cPrivate

accessibility

public int accessibility()
Return the declaration accessibility.
See Also:
cPublic, cProtected, cPrivate

setVisibility

public void setVisibility(int visibility)
Specify the visibility of the declaration.
Parameters:
visibility - is the visibility of the declaration
See Also:
cLocal, cFile, cGlobal, cExtern

visibility

public int visibility()
Return the declaration visibility.
See Also:
cLocal, cFile, cGlobal, cExtern

setResidency

public void setResidency(int residency)
Specify the residency of the declaration.
Parameters:
residency - is the residency of the declaration
See Also:
cAuto, cRegister, cMemory

residency

public int residency()
Return the declaration residency.
See Also:
cAuto, cRegister, cMemory

setAddressTaken

public void setAddressTaken()
Record that the address is used.

addressTaken

public boolean addressTaken()
Return true if the address of this Declaration has been taken.

setTag

public final void setTag(int tag)
Set the tag for this variable. The tag can be used by various algorithms.

getTag

public final int getTag()
Return the tag associated with this variable. The tag can be used by various algorithms.

getParent

public final Node getParent()
Return my parent in the Clef tree if any
Overrides:
getParent in class Node
Following copied from class: scale.clef.Node
Returns:
my parent in the Clef tree if any

getDecl

public Declaration getDecl()
Description copied from class: Node
Retun any Declaration associated with this Node.
Overrides:
getDecl in class Node

setParent

public final void setParent(Node s)
Specify the parent node of this node.
Overrides:
setParent in class Node
Parameters:
p - my parent in the Clef tree

setChildParent

protected void setChildParent(Vector v)

toStringSpecial

public java.lang.String toStringSpecial()
Description copied from class: Root
Return any special information of a node that is not a child or annotation. This method is meant to be overridden by nodes that need to provide special output.
Overrides:
toStringSpecial in class Node

getDisplayText

public java.lang.String getDisplayText()
Return a String suitable for labeling this node in a graphical display. This method should be over-ridden as it simplay returns the class name.
Overrides:
getDisplayText in class Root

getDisplayColorHint

public java.lang.String getDisplayColorHint()
Return a String specifying the color to use for coloring this node in a graphical display. This method should be over-ridden as it simplay returns the color red.
Overrides:
getDisplayColorHint in class Root

getDisplayShapeHint

public java.lang.String getDisplayShapeHint()
Return a String specifying a shape to use when drawing this node in a graphical display. This method should be over-ridden as it simplay returns the shape "box".
Overrides:
getDisplayShapeHint in class Root

visit

public void visit(Predicate p)
Description copied from class: Node
The visit() method is used to implement a visit 'pattern'.
Overrides:
visit in class Node

getName

public final java.lang.String getName()
Return the name of the Declaration.

getType

public final Type getType()
Return the type of the Declaration. Use this method to obtain the complete type.
Overrides:
getType in class Node

getCoreType

public final Type getCoreType()
Return the type of the Declaration without attributes. Use this method for comparing base types.
Overrides:
getCoreType in class Node
Following copied from class: scale.clef.Node
See Also:
Node.getType(), RefType

getScopeNode

public Node getScopeNode()
Return the node which represents the clef scope node. For most nodes, the parent points to the Clef node which represents the scope. For example, the parent node for class members is the class node.
Returns:
the clef node which represents the scope for the node.

setName

public final void setName(java.lang.String name)
Change the display name of the declaration.
Parameters:
name - is the new name for the declaration

setType

public final void setType(Type type)
Specify the type of this declaration.

getConstantValue

public java.lang.Object getConstantValue()
Return the constant value of the expression.
See Also:
Lattice

isReferenced

public boolean isReferenced()
Return true if the declaration is referenced somewhere in the Clef AST. Must declarations are considered to be referenced whether or not they actually are. However, variables and routines without bodies may not be referenced and the over-ridden version of this method may return false.
See Also:
VariableDecl, RoutineDecl

setReferenced

public void setReferenced()
Specify that the Declaration is referenced somewhere in the Clef AST. This method must be over-ridden for a declataion that may or may not be referenced.
See Also:
VariableDecl, RoutineDecl

isGlobal

public boolean isGlobal()
Return true if this declaration is globally visible.

inMemory

public boolean inMemory()
Return true if this declaration is to be allocated to memory.

isTemporary

public boolean isTemporary()
Return true if the declaration is a temporary variable.

isFtnResultVar

public boolean isFtnResultVar()
Return true if the declaration is declared as the result variable of a function.

isVariable

public boolean isVariable()
Return true if the declaration is a variable.

isVirtual

public boolean isVirtual()
Return true if the declaration is a virtual variable.

DDname

public java.lang.String DDname()

isPure

public boolean isPure()
Return true if this declaration has a PureFunctionAnnotation of level PUREGV.