Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

trees.h

Go to the documentation of this file.
00001 
00002 #ifndef TREES_H
00003 #define TREES_H
00004 
00013 /*===============================<o>=====================================
00014 
00015 Copyright 1996, 1997, 2004 Ian Kaplan, Bear Products International,
00016 www.bearcave.com.
00017 
00018 All Rights Reserved
00019 
00020 You may use this software in software components for which you do
00021 not collect money (e.g., non-commercial software).  All commercial
00022 use is reserved.
00023 
00024 ===============================<o>=====================================*/
00025 
00026 
00027 enum { nd_bad_node,
00028        nd_const,
00029        nd_type,
00030        nd_sym
00031      };
00032 
00105 class node {
00106 private:
00107     node *kids;
00108     node *sib;
00110     uint kid_cnt;         
00111 
00112     uint name      : 16,  // n_icon, n_plus, etc...
00113          td_rmark  :  1,  // tree dictionary: referenced flag
00114          td_rdonly :  1,  // tree dicitonary: VN reference copy
00115          unused    : 14;
00116 
00117     SRC_REF sref;         // source reference information
00118 
00119 public:
00120     node() 
00121     {
00122         kids = NULL;
00123         sib = NULL;
00124         name = n_bad_name;
00125         td_rmark = FALSE;
00126         td_rdonly = FALSE;
00127     }
00128 
00129     
00130     void *operator new( unsigned int num_bytes )
00131     {
00132         assert( FALSE );
00133         return NULL;
00134     }
00135 
00136     void *operator new( unsigned int num_bytes, pool *mem_pool )
00137     {
00138         return mem_pool->GetMem( num_bytes );
00139     }
00140 
00141     void set_name( node_name n )  { name = n; }
00142     node_name get_name(void)  { return name; }
00143 
00144     void set_kid( node *kid )  { kids = kid; }
00145     node *get_kid(void)        { return kids; }
00146 
00147     void set_sib( node *s )    { sib = s; };
00148     node *get_sib(void)        { return sib; }
00149 
00150     /* tree "macros" */
00151     uint is_leaf(void) { return kids == NULL; }
00152     uint is_nonleaf(void) { return kids != NULL; }
00153 
00154     node *first_kid(void)  { return kids; }
00155     node *second_kid(void) { return kids->get_sib(); }
00156     node *third_kid(void)  { return kids->get_sib()->get_sib(); }
00157     node *fourth_kid(void) { return kids->get_sib()->get_sib()->get_sib(); }
00158     node *fifth_kid(void)  { return kids->get_sib()->get_sib()->get_sib()->get_sib(); }
00159     
00160     // Virtual functions
00161     virtual uint get_kind(void) { return nd_bad_node; }
00162 
00163     //
00164     // node_const
00165     // 
00166     virtual void set_const( pConst c )
00167     {
00168         assert( FALSE );
00169     }
00170     virtual const pConst get_const(void)
00171     {
00172         return NULL;
00173     }
00174     //
00175     // node_type
00176     //
00177     virtual void set_type( pType t )
00178     {
00179         assert( FALSE );
00180     }
00181     virtual const pType get_type(void)
00182     {
00183         return NULL;
00184     }
00185     //
00186     // node_sym
00187     //
00188     virtual void set_sym( pSym s )
00189     {
00190         assert( FALSE );
00191     }
00192     virtual const pSym get_sym(void)
00193     {
00194         return NULL;
00195     }
00196 }; // node
00197 
00198 
00199 class node_const : public node {
00200 private:
00201     pConst con;   // pointer to a constant object
00202 public:
00203     node_const() : node {}
00204     uint get_kind(void) { return nd_const; }
00205     
00206     void set_const( pConst c )
00207     {
00208         con = c;
00209     }
00210     const pConst get_const(void)
00211     {
00212         return con;
00213     }
00214 
00215 }; // node_const
00216 
00217 
00218 
00219 class node_type : public node {
00220 private:
00221     pType ty;     // pointer to a type object
00222 public:
00223     uint get_kind(void) { return nd_type; }
00224 
00225     void set_type( pType t )
00226     {
00227         ty = t;
00228     }
00229     const pType get_type(void)
00230     {
00231         return ty;
00232     }
00233 }; // node_const
00234 
00235 
00236 
00237 class node_sym : public node {
00238 private:
00239     pSym sy;     // pointer to a symbol
00240 public:
00241     uint get_kind(void) { return nd_type; }
00242 
00243     void set_sym( pSym s )
00244     {
00245         sy = s;
00246     }
00247     const pSym get_sym(void)
00248     {
00249         return sy;
00250     }
00251 }; // node_const
00252 
00253 
00254 #endif

Generated on Wed Mar 31 21:15:55 2004 for Data Structures for a VHDL Compiler by doxygen 1.3.3