scale.clef.decl
Class Declaration

java.lang.Object
  extended by scale.common.Root
      extended by scale.clef.Node
          extended by scale.clef.decl.Declaration
All Implemented Interfaces:
java.lang.Comparable, AnnotationInterface, DisplayNode
Direct Known Subclasses:
ExceptionDecl, FileDecl, LabelDecl, RoutineDecl, StmtFtnDecl, TypeDecl, TypeName, ValueDecl

public abstract class Declaration
extends Node
implements java.lang.Comparable

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

$Id: Declaration.java,v 1.106 2007-10-04 19:58:03 burrill Exp $

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


Constructor Summary
protected Declaration(java.lang.String name)
          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
 Accessibility accessibility()
          Return the declaration accessibility.
 boolean addressTaken()
          Return true if the address of this Declaration has been taken.
 int compareTo(java.lang.Object a)
           
abstract  Declaration copy(java.lang.String name)
          Return a copy of this Declaration but with a different name.
 Type getActualType()
          Return the type of the Declaration.
 int getAddressRegister()
          Return the register the code generator assigned to the address of this variable.
 java.lang.String getAlias()
          Return the alias for this declaration.
 Literal getConstantValue()
          Return the constant value of the expression.
 Type getCoreType()
          Return the type of the Declaration without attributes.
 Declaration getDecl()
          Return any Declaration associated with this Node.
 Displacement getDisplacement()
          Return the code generator displacement associated with this call node.
 DColor getDisplayColorHint()
          Return a String specifying the color to use for coloring this node in a graphical display.
 java.lang.String getDisplayLabel()
          Return a String suitable for labeling this node in a graphical display.
 DShape getDisplayShapeHint()
          Return a String specifying a shape to use when drawing this node in a graphical display.
 ParameterMode getMode()
          Return the parameter passing mode of this declaration.
 java.lang.String getName()
          Return the name of the Declaration.
 Type getPointedToCore()
          Return the type of the thing pointed to by the type of the expression.
 Assigned getStorageLoc()
          Return the location type used for this declaration.
 int getTag()
          Return the tag associated with this variable.
 Type getType()
          Return the type of the Declaration.
 int getValueRegister()
          Return the register the code generator assigned to this variable.
 int hashCode()
          Use the name of the declaration instead of the address of the instance so things are more predictable.
 boolean hasHiddenAliases()
          Return true if the declaration may be modified in an unknown way.
 boolean inMemory()
          Return true if this declaration is to be allocated to memory.
 boolean isCaseLabelDecl()
          Return true if CaseLabelDecl instance.
 boolean isCommonBaseVariable()
          Return true if this is the base variable of a Fortran COMMON area.
 boolean isConst()
          Return true.
 boolean isEnumElementDecl()
          Return true if EnumElementDecl instance.
 boolean isEquivalenceDecl()
          Return true if the declaration is a variable in Fortran COMMON.
 boolean isExceptionDecl()
          Return true if ExceptionDecl instance.
 boolean isFieldDecl()
          Return true if FieldDecl instance.
 boolean isFileDecl()
          Return true if FileDecl instance.
 boolean isFormalDecl()
          Return true if this declaration is a formal parameter to the routine.
 boolean isForwardProcedureDecl()
          Return true if ForwardProcedureDecl instance.
 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 isLabelDecl()
          Return true if LabelDecl instance.
 boolean isProcedureDecl()
          Return true if ProcedureDecl instance.
 boolean isPure()
          Return true if this declaration has a purity level of PUREGV.
 boolean isReferenced()
          Return true if the declaration is referenced somewhere in the Clef AST.
 boolean isRenamed()
          Return true if the declaration is a renamed variable.
 boolean isRenamedVariableDecl()
          Return true if RenamedVariableDecl instance.
 boolean isRoutineDecl()
          Return true if RoutineDecl instance.
 boolean isStmtFtnDecl()
          Return true if StmtFtnDecl instance.
 boolean isTemporary()
          Return true if the declaration is a temporary variable.
 boolean isTypeDecl()
          Return true if TypeDecl instance.
 boolean isTypeName()
          Return true if TypeName instance.
 boolean isUnknownFormals()
          Return true if UnknownFormals instance.
 boolean isValueDecl()
          Return true if ValueDecl instance.
 boolean isVariableDecl()
          Return true if VariableDecl instance.
 boolean isVirtual()
          Return true if the declaration is a virtual variable.
 boolean isWeak()
          Return true if the declaration has the "weak" attribute.
 Residency residency()
          Return the declaration residency.
 CaseLabelDecl returnCaseLabelDecl()
          Return a CaseLabelDecl instance or null.
 EnumElementDecl returnEnumElementDecl()
          Return a EnumElementDecl instance or null.
 EquivalenceDecl returnEquivalenceDecl()
          Return a EquivalenceDecl instance or null.
 ExceptionDecl returnExceptionDecl()
          Return a ExceptionDecl instance or null.
 FieldDecl returnFieldDecl()
          R a FieldDecl instance or null.
 FileDecl returnFileDecl()
          a FileDecl instance or null.
 FormalDecl returnFormalDecl()
          Re a FormalDecl instance or null.
 ForwardProcedureDecl returnForwardProcedureDecl()
          Return a For a ForwardProcedureDecl instance or null.
 LabelDecl returnLabelDecl()
          R a LabelDecl instance or null.
 ProcedureDecl returnProcedureDecl()
          Return a ProcedureDecl instance or null.
 RenamedVariableDecl returnRenamedVariableDecl()
          Return a Re a RenamedVariableDecl instance or null.
 RoutineDecl returnRoutineDecl()
          Return a RoutineDecl instance or null.
 StmtFtnDecl returnStmtFtnDecl()
          Return a StmtFtnDecl instance or null.
 TypeDecl returnTypeDecl()
          Return a TypeDecl instance or null.
 TypeName returnTypeName()
          Return a TypeName instance or null.
 UnknownFormals returnUnknownFormals()
          Return a UnknownFormals instance or null.
 ValueDecl returnValueDecl()
          Return a ValueDecl instance or null.
 VariableDecl returnVariableDecl()
          Return a VariableDecl instance or null.
 void setAccessibility(Accessibility accessibility)
          Specify the accessibility of the declaration.
 void setAddressRegister(int reg)
          Specify the register the code generator assigned to the address of this variable.
 void setAddressTaken()
          Record that the address is used.
 void setAlias(java.lang.String alias)
          Set the alias for this declaration.
 void setDisplacement(Displacement disp)
          Specify the code generator displacement associated with this call node.
 void setName(java.lang.String name)
          Change the display name of the declaration.
 void setReferenced()
          Specify that the Declaration is referenced somewhere in the Clef AST.
 void setResidency(Residency residency)
          Specify the residency of the declaration.
 void setStorageLoc(Assigned loc)
          Set the location type used for this declaration.
 void setTag(int tag)
          Set the tag for this variable.
 void setType(Type type)
          Specify the type of this declaration.
 void setValueRegister(int reg, ResultMode mode)
          Specify the register the code generator assigned to this variable.
 void setVisibility(Visibility visibility)
          Specify the visibility of the declaration.
 void setWeak(boolean weak)
          Specify that the declaration has the "weak" attribute.
 java.lang.String toStringSpecial()
          This method allows sub-classes to provide class specific stuff to the string.
 ResultMode valueRegMode()
          Return true if the register the code generator assigned to this variable contains the address and not the value.
 Visibility visibility()
          Return the declaration visibility.
 void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.clef.Node
getChild, getSourceLineNumber, numChildren, setAnnotationLevel, setReportLevel, setSourceLineNumber, toString, toString, toStringChildren
 
Methods inherited from class scale.common.Root
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayName, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, 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

Declaration

protected Declaration(java.lang.String name)
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

hashCode

public int hashCode()
Use the name of the declaration instead of the address of the instance so things are more predictable.

Overrides:
hashCode in class Root

compareTo

public final int compareTo(java.lang.Object a)
Specified by:
compareTo in interface java.lang.Comparable

setAccessibility

public void setAccessibility(Accessibility accessibility)
Specify the accessibility of the declaration.

Parameters:
accessibility - is the accessibility of the declaration
See Also:
Accessibility

accessibility

public Accessibility accessibility()
Return the declaration accessibility.

See Also:
Accessibility

setVisibility

public void setVisibility(Visibility visibility)
Specify the visibility of the declaration.

Parameters:
visibility - is the visibility of the declaration
See Also:
Visibility

visibility

public Visibility visibility()
Return the declaration visibility.

See Also:
Visibility

isWeak

public final boolean isWeak()
Return true if the declaration has the "weak" attribute.


setWeak

public final void setWeak(boolean weak)
Specify that the declaration has the "weak" attribute.


getAlias

public final java.lang.String getAlias()
Return the alias for this declaration.


setAlias

public final void setAlias(java.lang.String alias)
Set the alias for this declaration. Variable declared to be extern may be aliased to another name.


setResidency

public void setResidency(Residency residency)
Specify the residency of the declaration.

Parameters:
residency - is the residency of the declaration
See Also:
Residency

residency

public Residency residency()
Return the declaration residency.

See Also:
Residency

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.


hasHiddenAliases

public boolean hasHiddenAliases()
Return true if the declaration may be modified in an unknown way.


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.


getStorageLoc

public Assigned getStorageLoc()
Return the location type used for this declaration.


getValueRegister

public int getValueRegister()
Return the register the code generator assigned to this variable.


valueRegMode

public ResultMode valueRegMode()
Return true if the register the code generator assigned to this variable contains the address and not the value.


setValueRegister

public void setValueRegister(int reg,
                             ResultMode mode)
Specify the register the code generator assigned to this variable.


getAddressRegister

public int getAddressRegister()
Return the register the code generator assigned to the address of this variable.


setAddressRegister

public void setAddressRegister(int reg)
Specify the register the code generator assigned to the address of this variable.


setStorageLoc

public void setStorageLoc(Assigned loc)
Set the location type used for this declaration.


getDisplacement

public Displacement getDisplacement()
Return the code generator displacement associated with this call node.


setDisplacement

public void setDisplacement(Displacement disp)
Specify the code generator displacement associated with this call node.


getDecl

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

Overrides:
getDecl in class Node

toStringSpecial

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

Overrides:
toStringSpecial in class Node

getDisplayLabel

public java.lang.String getDisplayLabel()
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.

Specified by:
getDisplayLabel in interface DisplayNode
Overrides:
getDisplayLabel in class Root

getDisplayColorHint

public DColor 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.

Specified by:
getDisplayColorHint in interface DisplayNode
Overrides:
getDisplayColorHint in class Root
See Also:
DColor

getDisplayShapeHint

public DShape 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".

Specified by:
getDisplayShapeHint in interface DisplayNode
Overrides:
getDisplayShapeHint in class Root
See Also:
DShape

visit

public void visit(Predicate p)
Description copied from class: Node
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.

Specified by:
visit in class Node
See Also:
Predicate

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; if the type is a completed incomplete type, the completed type is returned.

Overrides:
getType in class Node

getActualType

public final Type getActualType()
Return the type of the Declaration.


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
See Also:
Node.getType(), RefType

getPointedToCore

public final Type getPointedToCore()
Return the type of the thing pointed to by the type of the expression. Equivalent to
   getCoreType().getPointedTo().getCoreType()
 


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 void setType(Type type)
Specify the type of this declaration.


getConstantValue

public Literal 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.


isCaseLabelDecl

public boolean isCaseLabelDecl()
Return true if CaseLabelDecl instance.


returnCaseLabelDecl

public CaseLabelDecl returnCaseLabelDecl()
Return a CaseLabelDecl instance or null.


isEnumElementDecl

public boolean isEnumElementDecl()
Return true if EnumElementDecl instance.


returnEnumElementDecl

public EnumElementDecl returnEnumElementDecl()
Return a EnumElementDecl instance or null.


isEquivalenceDecl

public boolean isEquivalenceDecl()
Return true if the declaration is a variable in Fortran COMMON.


returnEquivalenceDecl

public EquivalenceDecl returnEquivalenceDecl()
Return a EquivalenceDecl instance or null.


isExceptionDecl

public boolean isExceptionDecl()
Return true if ExceptionDecl instance.


returnExceptionDecl

public ExceptionDecl returnExceptionDecl()
Return a ExceptionDecl instance or null.


isFieldDecl

public boolean isFieldDecl()
Return true if FieldDecl instance.


returnFieldDecl

public FieldDecl returnFieldDecl()
R a FieldDecl instance or null.


isFileDecl

public boolean isFileDecl()
Return true if FileDecl instance.


returnFileDecl

public FileDecl returnFileDecl()
a FileDecl instance or null.


isFormalDecl

public boolean isFormalDecl()
Return true if this declaration is a formal parameter to the routine.


returnFormalDecl

public FormalDecl returnFormalDecl()
Re a FormalDecl instance or null.


isForwardProcedureDecl

public boolean isForwardProcedureDecl()
Return true if ForwardProcedureDecl instance.


returnForwardProcedureDecl

public ForwardProcedureDecl returnForwardProcedureDecl()
Return a For a ForwardProcedureDecl instance or null.


isLabelDecl

public boolean isLabelDecl()
Return true if LabelDecl instance.


returnLabelDecl

public LabelDecl returnLabelDecl()
R a LabelDecl instance or null.


isProcedureDecl

public boolean isProcedureDecl()
Return true if ProcedureDecl instance.


returnProcedureDecl

public ProcedureDecl returnProcedureDecl()
Return a ProcedureDecl instance or null.


isRenamedVariableDecl

public boolean isRenamedVariableDecl()
Return true if RenamedVariableDecl instance.


returnRenamedVariableDecl

public RenamedVariableDecl returnRenamedVariableDecl()
Return a Re a RenamedVariableDecl instance or null.


isRoutineDecl

public boolean isRoutineDecl()
Return true if RoutineDecl instance.


returnRoutineDecl

public RoutineDecl returnRoutineDecl()
Return a RoutineDecl instance or null.


isStmtFtnDecl

public boolean isStmtFtnDecl()
Return true if StmtFtnDecl instance.


returnStmtFtnDecl

public StmtFtnDecl returnStmtFtnDecl()
Return a StmtFtnDecl instance or null.


isTypeDecl

public boolean isTypeDecl()
Return true if TypeDecl instance.


returnTypeDecl

public TypeDecl returnTypeDecl()
Return a TypeDecl instance or null.


isValueDecl

public boolean isValueDecl()
Return true if ValueDecl instance.


returnValueDecl

public ValueDecl returnValueDecl()
Return a ValueDecl instance or null.


isVariableDecl

public boolean isVariableDecl()
Return true if VariableDecl instance.


returnVariableDecl

public VariableDecl returnVariableDecl()
Return a VariableDecl instance or null.


isTypeName

public boolean isTypeName()
Return true if TypeName instance.


returnTypeName

public TypeName returnTypeName()
Return a TypeName instance or null.


isUnknownFormals

public boolean isUnknownFormals()
Return true if UnknownFormals instance.


returnUnknownFormals

public UnknownFormals returnUnknownFormals()
Return a UnknownFormals instance or null.


isCommonBaseVariable

public boolean isCommonBaseVariable()
Return true if this is the base variable of a Fortran COMMON area.


isVirtual

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


isRenamed

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


isPure

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


isConst

public boolean isConst()
Return true.


getMode

public ParameterMode getMode()
Return the parameter passing mode of this declaration. Unless this declaration is a formal parameter to a routine, the value returned is cValue.


copy

public abstract Declaration copy(java.lang.String name)
Return a copy of this Declaration but with a different name.