scale.clef.decl
Class FieldDecl

java.lang.Object
  extended by scale.common.Root
      extended by scale.clef.Node
          extended by scale.clef.decl.Declaration
              extended by scale.clef.decl.ValueDecl
                  extended by scale.clef.decl.FieldDecl
All Implemented Interfaces:
java.lang.Comparable, AnnotationInterface, DisplayNode

public class FieldDecl
extends ValueDecl

This class represents a component of an aggregate data structure.

$Id: FieldDecl.java,v 1.40 2007-10-04 19:58:04 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
FieldDecl(java.lang.String name, Type type)
           
FieldDecl(java.lang.String name, Type type, long fieldOffset)
           
FieldDecl(java.lang.String name, Type type, long fieldOffset, int fieldAlignment)
           
FieldDecl(java.lang.String name, Type type, long fieldOffset, int fieldAlignment, Expression initialValue)
          Create a declaration of a field of a structure.
FieldDecl(java.lang.String name, Type type, long fieldOffset, int fieldAlignment, Expression initialValue, int bits)
          Create a declaration of a field of a structure.
 
Method Summary
 Accessibility accessibility()
          Return the declaration accessibility.
 Declaration copy(java.lang.String name)
          Return a copy of this Declaration but with a different name.
 int getBitOffset()
          Return the bit offset from the appropriate (word) boundary in the structure.
 int getBits()
          Return the number of bits specified for the field - 0 means none specified.
 int getFieldAlignment()
          Return the required field alignment for the field.
 long getFieldOffset()
          Return the required field offset for the field.
 Expression getInitialValue()
          Return the initializer for the field.
 AggregateType getMyStruct()
          Return the class that this field belong to, if applicable.
 boolean isFieldDecl()
          Return true if FieldDecl instance.
 boolean isPackedField(Machine machine)
          Return true if the field is not aligned on a natural boundary for its type.
 FieldDecl returnFieldDecl()
          R a FieldDecl instance or null.
 void setAccessibility(Accessibility accessibility)
          Specify the accessibility of the declaration.
 void setBitOffset(int bitOffset)
          Set the bit offset from the appropriate (word) boundary in the structure.
 void setBits(int bits, int bitOffset)
          Set the number of bits specified for the field - 0 means none specified.
 void setFieldAlignment(int fieldAlignment)
          Set the required field alignment for the field.
 void setFieldOffset(long fieldOffset)
          Set the required field offset for the field.
 void setFieldTargetAttributes(long fieldOffset, int fieldAlignment, int bitOffset)
          Set the target attributes of the field.
protected  void setInitialValue(Expression i)
          Specify the initializer for the field.
 void setMyStruct(AggregateType n)
          Specify the structure to which this FieldDecl belongs.
 java.lang.String toStringSpecial()
          This method allows sub-classes to provide class specific stuff to the string.
 void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.clef.decl.ValueDecl
getChild, getConstantValue, getValue, isConst, isValueDecl, numChildren, returnValueDecl, setValue
 
Methods inherited from class scale.clef.decl.Declaration
addressTaken, compareTo, getActualType, getAddressRegister, getAlias, getCoreType, getDecl, getDisplacement, getDisplayColorHint, getDisplayLabel, getDisplayShapeHint, getMode, getName, getPointedToCore, getStorageLoc, getTag, getType, getValueRegister, hashCode, hasHiddenAliases, inMemory, isCaseLabelDecl, isCommonBaseVariable, isEnumElementDecl, isEquivalenceDecl, isExceptionDecl, isFileDecl, isFormalDecl, isForwardProcedureDecl, isFtnResultVar, isGlobal, isLabelDecl, isProcedureDecl, isPure, isReferenced, isRenamed, isRenamedVariableDecl, isRoutineDecl, isStmtFtnDecl, isTemporary, isTypeDecl, isTypeName, isUnknownFormals, isVariableDecl, isVirtual, isWeak, residency, returnCaseLabelDecl, returnEnumElementDecl, returnEquivalenceDecl, returnExceptionDecl, returnFileDecl, returnFormalDecl, returnForwardProcedureDecl, returnLabelDecl, returnProcedureDecl, returnRenamedVariableDecl, returnRoutineDecl, returnStmtFtnDecl, returnTypeDecl, returnTypeName, returnUnknownFormals, returnVariableDecl, setAddressRegister, setAddressTaken, setAlias, setDisplacement, setName, setReferenced, setResidency, setStorageLoc, setTag, setType, setValueRegister, setVisibility, setWeak, valueRegMode, visibility
 
Methods inherited from class scale.clef.Node
getSourceLineNumber, 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

FieldDecl

public FieldDecl(java.lang.String name,
                 Type type,
                 long fieldOffset,
                 int fieldAlignment,
                 Expression initialValue,
                 int bits)
Create a declaration of a field of a structure.

Parameters:
name - is the name of the field
type - is the type of the field
fieldOffset - is the offset in bytes of the field in the structure
fieldAlignment - is the required alignment of the field in the structure
initialValue - is the initial value for the field
bits - specifies the size of a C bit field

FieldDecl

public FieldDecl(java.lang.String name,
                 Type type,
                 long fieldOffset,
                 int fieldAlignment,
                 Expression initialValue)
Create a declaration of a field of a structure.

Parameters:
name - is the name of the field
type - is the type of the field
fieldOffset - is the offset in bytes of the field in the structure
fieldAlignment - is the required alignment of the field in the structure
initialValue - is the initial value for the field

FieldDecl

public FieldDecl(java.lang.String name,
                 Type type,
                 long fieldOffset,
                 int fieldAlignment)

FieldDecl

public FieldDecl(java.lang.String name,
                 Type type,
                 long fieldOffset)

FieldDecl

public FieldDecl(java.lang.String name,
                 Type type)
Method Detail

setAccessibility

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

Overrides:
setAccessibility in class Declaration
Parameters:
accessibility - is the accessibility of the declaration
See Also:
Accessibility

accessibility

public final Accessibility accessibility()
Return the declaration accessibility.

Overrides:
accessibility in class Declaration
See Also:
Accessibility

getBits

public final int getBits()
Return the number of bits specified for the field - 0 means none specified.


setBits

public final void setBits(int bits,
                          int bitOffset)
Set the number of bits specified for the field - 0 means none specified.


getBitOffset

public final int getBitOffset()
Return the bit offset from the appropriate (word) boundary in the structure.


setBitOffset

public final void setBitOffset(int bitOffset)
Set the bit offset from the appropriate (word) boundary in the structure.


getFieldOffset

public final long getFieldOffset()
Return the required field offset for the field.


setFieldOffset

public final void setFieldOffset(long fieldOffset)
Set the required field offset for the field.


getFieldAlignment

public final int getFieldAlignment()
Return the required field alignment for the field.


setFieldAlignment

public final void setFieldAlignment(int fieldAlignment)
Set the required field alignment for the field.


setFieldTargetAttributes

public final void setFieldTargetAttributes(long fieldOffset,
                                           int fieldAlignment,
                                           int bitOffset)
Set the target attributes of the field.


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.

Overrides:
visit in class ValueDecl
See Also:
Predicate

getInitialValue

public final Expression getInitialValue()
Return the initializer for the field. For C programs this is always null.


setInitialValue

protected final void setInitialValue(Expression i)
Specify the initializer for the field. For C programs this is always null.


getMyStruct

public final AggregateType getMyStruct()
Return the class that this field belong to, if applicable.


setMyStruct

public final void setMyStruct(AggregateType n)
Specify the structure to which this FieldDecl belongs.

Parameters:
n - the aggregate structure (record or class) to which I belong

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 Declaration

copy

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

Specified by:
copy in class Declaration

isPackedField

public boolean isPackedField(Machine machine)
Return true if the field is not aligned on a natural boundary for its type.


isFieldDecl

public final boolean isFieldDecl()
Description copied from class: Declaration
Return true if FieldDecl instance.

Overrides:
isFieldDecl in class Declaration

returnFieldDecl

public final FieldDecl returnFieldDecl()
Description copied from class: Declaration
R a FieldDecl instance or null.

Overrides:
returnFieldDecl in class Declaration