Polaris: VariableSymbol.h Source File

VariableSymbol.h

Go to the documentation of this file.
00001 ///
00002 #ifndef _VARIABLE_SYMBOL_H
00003 #define _VARIABLE_SYMBOL_H
00004 ///
00005 /// \class VariableSymbol 
00006 /// \brief a Symbol of class VARIABLE_CLASS
00007 /// \defgroup Polaris
00008 /// \ingroup Polaris
00009 ///  C++ VDL
00010 /// \see Symbol.h
00011 /// \see Symbol.h
00012 /// \see VariableSymbol.h
00013 /// \see Symbol.cc
00014 ///
00015 /// \endcode
00016 /// \section Description Description
00017 /// A VariableSymbol is a Symbol representing a Fortran variable.
00018 ///
00019 /// The additional fields it adds to Symbol's fields are
00020 /// the type, equivalence, dim, formal and common fields.
00021 ///
00022 /// The type field indicates the type of variable.
00023 ///
00024 /// The equivalence field is a pointer to an Equivalence
00025 /// class if this Symbol is associated with any
00026 /// equivalences.
00027 ///
00028 /// The dim field is a list of array bounds if this symbol
00029 /// is an array (if is_array() is true -- if not, this
00030 /// list will be empty).
00031 ///
00032 /// The shared_dim field is a list of shared distributions if this 
00033 /// symbol is shared (if is_shared() is true -- if not, this
00034 /// list will be empty).
00035 ///
00036 /// The formal field indicates whether or not this variable
00037 /// is a formal variable of a function or subroutine.
00038 ///
00039 /// The allocatable field indicates whether this is an array
00040 /// which may be dynamically allocated.
00041 ///
00042 /// The common field is a pointer to a CommonBlock structure
00043 /// if this variable is a commoned variable.
00044 ///
00045 /// The only virtual methods inherited from Symbol which are
00046 /// valid for this class (which will not give errors messages,
00047 /// with the exception of Symbol::is_array()) are those which
00048 /// are explicitly overridden here.
00049 ///
00050 /// See Symbol for more information.
00051 ///
00052 #ifdef POLARIS_GNU_PRAGMAS
00053 #pragma interface
00054 #endif
00055 ///
00056 #ifndef _SYMBOL_H
00057 #include "Symbol.h"
00058 #endif
00059 ///
00060 #include "../SharedDims.h"
00061 ///
00062 class VariableSymbol : public Symbol {
00063     friend class         CommonBlock;
00064     friend class         PostPass;
00065 
00066  protected:
00067     Type            _type;
00068     unsigned        _formal:1, _saved:1, _initial_value:1, _global:1, _allocatable:1;
00069     Equivalence    *_equivalence;
00070     ArrayDims       _dim;
00071     SharedDims      _shared_dim;
00072     CommonBlock    *_common;
00073     virtual void   _dims(ArrayDims *);
00074 
00075     Expression     *_shared_expr;
00076     ///<_ points to Expression in the AS_SHARED assertion in FLOW_ENTRY_STMT
00077     ///<_ if this symbol is shared. (only applicable to T3D now)
00078 
00079     Symbol         *_gsa_base_symbol;
00080     ///< If non-NULL, this symbol is a symbol generated for the GSA representation
00081     ///< and points to the symbol with the original name.
00082 
00083  public:
00084     VariableSymbol(const char *name,
00085                    const Type & type,
00086                    FORMAL_BOOL formal,
00087                    SAVED_BOOL saved,
00088                    ArrayBounds * bounds1 = 0,
00089                    ArrayBounds * bounds2 = 0,
00090                    ArrayBounds * bounds3 = 0,
00091                    ArrayBounds * bounds4 = 0,
00092                    ArrayBounds * bounds5 = 0,
00093                    ArrayBounds * bounds6 = 0,
00094                    ArrayBounds * bounds7 = 0);
00095 
00096     ///< Constructor.  Equivalence and CommonBlock information, if
00097     ///< desired, must be entered separately using the appropriate
00098     ///< functions.
00099     ///< If the variable is an array, the dimension bounds may be
00100     ///< initialized here, up to 5 dimensions.  If more are needed,
00101     ///< insert them directly into the array dimensions field using
00102     ///< code such as
00103     ///<
00104     ///< VariableSymbol *var("VAR1", make_type(INTEGER_TYPE),
00105     ///<                     IS_FORMAL, NOT_SAVED);
00106     ///< var.dim().ins_last(new ArrayBounds(new IntConstExpr(1),
00107     ///< new IntconstExpr(100));
00108     ///< // First dimension is '1:100'
00109     ///< etc.
00110     VariableSymbol(const char *name,
00111                    const Type & type,
00112                    FORMAL_BOOL formal,
00113                    SAVED_BOOL saved,
00114                    GLOBAL_BOOL  global,
00115                    ArrayBounds * bounds1 = 0,
00116                    ArrayBounds * bounds2 = 0,
00117                    ArrayBounds * bounds3 = 0,
00118                    ArrayBounds * bounds4 = 0,
00119                    ArrayBounds * bounds5 = 0,
00120                    ArrayBounds * bounds6 = 0,
00121                    ArrayBounds * bounds7 = 0);
00122 
00123     VariableSymbol(const char *name,
00124                    const Type & type,
00125                    FORMAL_BOOL formal,
00126                    SAVED_BOOL saved,
00127                    GLOBAL_BOOL  global,
00128                    ArrayDims * dims);
00129 
00130     VariableSymbol(const char *name,
00131                    const Type & type,
00132                    ALLOC_BOOL allocatable,
00133                    FORMAL_BOOL formal,
00134                    SAVED_BOOL saved,
00135                    ArrayBounds * bounds1 = 0,
00136                    ArrayBounds * bounds2 = 0,
00137                    ArrayBounds * bounds3 = 0,
00138                    ArrayBounds * bounds4 = 0,
00139                    ArrayBounds * bounds5 = 0,
00140                    ArrayBounds * bounds6 = 0,
00141                    ArrayBounds * bounds7 = 0);
00142 
00143     VariableSymbol(const char *name,
00144                    const Type & type,
00145                    ALLOC_BOOL allocatable,
00146                    FORMAL_BOOL formal,
00147                    SAVED_BOOL saved,
00148                    GLOBAL_BOOL  global,
00149                    ArrayBounds * bounds1 = 0,
00150                    ArrayBounds * bounds2 = 0,
00151                    ArrayBounds * bounds3 = 0,
00152                    ArrayBounds * bounds4 = 0,
00153                    ArrayBounds * bounds5 = 0,
00154                    ArrayBounds * bounds6 = 0,
00155                    ArrayBounds * bounds7 = 0);
00156 
00157     VariableSymbol(const char *name,
00158                    const Type & type,
00159                    ALLOC_BOOL allocatable,
00160                    FORMAL_BOOL formal,
00161                    SAVED_BOOL saved,
00162                    GLOBAL_BOOL  global,
00163                    ArrayDims * dims);
00164 
00165     VariableSymbol(const VariableSymbol & vsym);
00166 
00167     VariableSymbol & operator = (const VariableSymbol & vsym);
00168 
00169     bool is_gsa_symbol() const;
00170     ///< True if there is a pointer to the GSA base variable (_gsa_base_symbol).
00171 
00172     Symbol & gsa_base_symbol() const ;
00173     ///< Returns the value of _gsa_base_symbol (NULL if this is not a GSA-generated symbol)
00174 
00175     void gsa_base_symbol( Symbol & base_ptr );
00176     ///< Deposits a value in _gsa_base_symbol
00177 
00178     virtual Symbol *clone() const;
00179     ///< Clone constructor -- returns base pointer to a new clone of 
00180     ///< this Symbol.
00181 
00182     virtual Symbol *clone_all() const;
00183     ///< Clone constructor -- returns base pointer to a new clone of 
00184     ///< this Symbol.
00185 
00186     virtual ~VariableSymbol();
00187 
00188     virtual const   Type & type() const;
00189     virtual void    type(const Type & type);
00190 
00191     virtual Equivalence *equivalence_ref() const;
00192     virtual void    equivalence(Equivalence & e, int byte_base);
00193     virtual void    clear_equivalence();
00194 
00195     virtual const ArrayDims & dim() const;
00196     virtual ArrayDims &       dim() ;
00197 
00198     virtual const SharedDims & shared_dim() const;
00199     virtual SharedDims &       shared_dim() ;
00200 
00201     virtual INITIAL_BOOL initial_value() const;
00202     virtual void    initial_value(INITIAL_BOOL ourbool);
00203 
00204     virtual ALLOC_BOOL allocatable() const;
00205     virtual void    allocatable(ALLOC_BOOL ourbool);
00206 
00207     virtual FORMAL_BOOL formal() const;
00208     virtual void    formal(FORMAL_BOOL ourbool);
00209 
00210     virtual SAVED_BOOL saved() const;
00211     virtual void    saved(SAVED_BOOL ourbool);
00212 
00213     virtual GLOBAL_BOOL global() const;
00214     virtual void    global(GLOBAL_BOOL ourbool);
00215 
00216     virtual const CommonBlock *common_ref() const;
00217     virtual CommonBlock       *common_ref() ;
00218 
00219     virtual void    common(CommonBlock & cb, int index);
00220     ///< Insert this variable into common block cb at position
00221     ///< index (1 = first element).
00222     ///< If the variable previously was in a different common block,
00223     ///< it is automatically removed from the common block.  Then
00224     ///< it is automatically inserted into the given common block's (cb)
00225     ///< list.  Finally, the variable's common field
00226     ///< is updated to the value of cb.  Thus, to change a variable's
00227     ///< common block, use either this routine or the routine in
00228     ///< CommonBlock.h, but not both.
00229 
00230     virtual void shared_expr(Expression *shared);
00231     ///< 'shared' must be an expression whose 'symbol' is this itself.
00232     ///< and it must DISTRIBUTE_OP or ID_OP
00233     virtual void set_to_private();
00234     ///< this symbol turns back to be a private by resetting _shared_expr to 0
00235     virtual Expression *shared_expr() const;
00236     ///<_ If thie is VariableSymbol and shared data object, it returns to the
00237     ///<_ pointer to its correspoding distribution expression.
00238     ///<_ The returned expression must be either ID_OP or DISTRIBUTE_OP.
00239     ///<_ If this is private, it returns 0. (only applicable to Cray T3D)
00240 
00241     virtual void    clear_common();
00242 
00243     virtual int     is_scalar() const;
00244 
00245     virtual int     is_array() const;
00246 
00247     virtual int     is_shared() const;
00248 
00249     virtual int     is_pointer() const;
00250 
00251     virtual int     size() const;
00252     ///< Return the size in bytes of the memory refered to by the symbol.
00253 
00254     virtual void    print(ostream & o) const;
00255     ///< Print onto stream 'o'
00256 
00257     virtual void    fill_in(const BinRep & binstr,
00258                             ExprTable & exprs,
00259                             const Dictionary<VoidPtrDef>&stmts,
00260                             const Dictionary<VoidPtrDef>&commons,
00261                             const Dictionary<VoidPtrDef>&equivalences);
00262     ///< Fill in all relevant info from a binstr object
00263 
00264     int             structures_OK() const;
00265     ///< Check the structure of the data for errors or inconsistency
00266     ///< Return 0 and print error message if problems found, otherwise
00267     ///< return 1 without message.
00268  
00269     virtual void    exchange_convert( VDL &vdl );
00270     ///< Convert the Symbol into the exchange format.
00271 
00272     virtual void    relink_dptrs(ProgramUnit & p);
00273     ///< Change all pointers found in a VariableSymbol element to
00274     ///< point into the given ProgramUnit.
00275 
00276 };
00277 
00278 inline 
00279 VariableSymbol::VariableSymbol(const VariableSymbol &vsym)
00280     : Symbol(vsym._tag, VARIABLE_CLASS)
00281 {
00282     *this = vsym;
00283 }
00284 
00285 inline int
00286 VariableSymbol::is_pointer() const
00287 {
00288     return 0;
00289 }
00290 
00291 inline void 
00292 VariableSymbol::_dims (ArrayDims * dims) 
00293 {
00294     _dim = *dims;
00295 }
00296 
00297 inline bool
00298 VariableSymbol::is_gsa_symbol( ) const
00299 {
00300     if (_gsa_base_symbol)
00301     return true;
00302     else 
00303     return false;
00304 }
00305 
00306 inline Symbol &
00307 VariableSymbol::gsa_base_symbol() const
00308 {
00309     return *_gsa_base_symbol;
00310 }
00311 
00312 inline void
00313 VariableSymbol::gsa_base_symbol( Symbol & base_ptr ) 
00314 {
00315     _gsa_base_symbol = &base_ptr;
00316 }
00317 #endif
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:06:16 2005