vrq
cfref.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 1997-2007, Mark Hummel
3  * This file is part of Vrq.
4  *
5  * Vrq is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * Vrq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301 USA
19  *****************************************************************************
20  */
21 /******************************************************************************
22  *
23  *
24  * cfref.hpp
25  * - class definition of forward reference
26  * definition nodes
27  *
28  ******************************************************************************
29  */
30 
31 #ifndef CFREF_HPP
32 #define CFREF_HPP
33 
34 #include <stdio.h>
35 #include <set>
36 #include <list>
37 #include <algorithm>
38 #include "glue.h"
39 #include "cnode.h"
40 #include "cdecl.h"
41 
42 
43 class CNode;
44 
51 class CFref : public CDecl
52 {
53 private:
54  CDecl* decl;
55  Decl_t direction;
56  int constrained;
57  set<Decl_t> typeConstraints;
58  CNode* msb;
59  CNode* lsb;
60  int lval;
61  int isArray;
63  int lsbVolatile;
64  int msbVolatile;
65  int lsbConstant;
66  int msbConstant;
67  int isInconsistant;
68  int currentDirection;
70  int refCount;
72 public:
78  CFref( CSymbol* symbol, Coord_t* aLoc );
84  virtual CDecl* Clone( CObstack* heap );
89  void SetDecl( CDecl* aDecl );
94  CDecl* GetDecl( void );
100  void SetRangeInfo( int isArray, CNode* range );
105  CNode* GetMsb( void );
110  CNode* GetLsb( void );
114  void DisableWidthInferencing() { isInconsistant = TRUE; }
120  virtual int IsWidthConstant( void );
126  virtual int IsWidthVolatile( void );
131  virtual int IsWidthEvaluateable( void );
136  virtual INT32 GetWidth( void );
141  virtual CNode* GetRange();
146  Decl_t Direction() { return direction; }
151  void Direction( Decl_t d ) { direction = d; }
156  void Lval( int aLval ) { lval = aLval; }
161  int Lval() { return lval; }
166  void IsArray( int v ) { isArray = v; }
171  int IsArray() { return isArray; }
176  int IndicesRangeValid();
182  void ConstrainTypes( const list<Decl_t>& aTypes ) {
183  list<Decl_t> types(aTypes);
184 
185  list<Decl_t>::const_iterator ptr;
186  for( ptr = aTypes.begin(); ptr != aTypes.end(); ++ptr ) {
187  CDecl::GetMembers( *ptr, types );
188  }
189  if( typeConstraints.size() == 0 ) {
190  MASSERT( !constrained );
191  set_union( types.begin(), types.end(),
192  typeConstraints.begin(), typeConstraints.end(),
193  inserter( typeConstraints,
194  typeConstraints.begin() ) );
195  } else {
196  set_intersection( types.begin(), types.end(),
197  typeConstraints.begin(), typeConstraints.end(),
198  inserter( typeConstraints,
199  typeConstraints.begin() ) );
200  }
201  constrained = TRUE;
202  }
208  int IsTypeValid( Decl_t t ) {
209  if( !constrained ) {
210  MASSERT( typeConstraints.size() == 0 );
211  return TRUE;
212  }
213  list<Decl_t> searchList;
214  CDecl::GetMembers( t, searchList );
215  list<Decl_t>::iterator ptr;
216  if( typeConstraints.count( t ) != 0 ) {
217  return TRUE;
218  }
219  for( ptr = searchList.begin();
220  ptr != searchList.end(); ++ptr ) {
221  if( typeConstraints.count( *ptr ) != 0 ) {
222  return TRUE;
223  }
224  }
225  return FALSE;
226  }
231  virtual void Dump( FILE* f );
232 private:
236  void SetRange( CNode* ) { MASSERT( FALSE ); }
237  CFref( const CFref& );
238 };
239 
240 #endif // CFREF_HPP
void Direction(Decl_t d)
Set direction of declaration.
Definition: cfref.h:151
virtual CNode * GetRange()
Get expression for declaration&#39;s range (msb/lsb)
CFref(CSymbol *symbol, Coord_t *aLoc)
Create a forward reference.
virtual int IsWidthConstant(void)
Determine if packed width of declaration is constant, ie dependent upon only constants and parameters...
virtual void Dump(FILE *f)
Dump declaration info to file descriptor.
Decl_t
Declaration types.
Definition: cdecl.h:74
virtual int IsWidthEvaluateable(void)
Determine if packed width of declaration can be evaluated.
void Lval(int aLval)
Set lval flag.
Definition: cfref.h:156
long INT32
Short cut for signed 32 bit integer.
Definition: glue.h:38
virtual INT32 GetWidth(void)
Evaluate packed width of declaration.
int IsArray()
Get array flag.
Definition: cfref.h:171
void ConstrainTypes(const list< Decl_t > &aTypes)
Add a constraint on valid types for this declaration.
Definition: cfref.h:182
int IsTypeValid(Decl_t t)
Test if a give declaration type is valid for this reference.
Definition: cfref.h:208
Structure to hold file coordinates.
Definition: cdecl.h:47
Holder for character strings.
Definition: csymbol.h:44
int Lval()
Get lval flag.
Definition: cfref.h:161
CDecl * GetDecl(void)
Get forward reference&#39;s actual declaration.
Forward reference declaration.
Definition: cfref.h:51
Bulk object allocation object.
Definition: cobstack.h:46
Primary data structure representing parse tree nodes.
Definition: cnode.h:197
static void GetMembers(Decl_t type, list< Decl_t > &result)
Get a list of members of the given declaration class/type.
Definition: cdecl.h:451
virtual CDecl * Clone(CObstack *heap)
Create a clone of this declaration.
Base class for describing declaration objects.
Definition: cdecl.h:164
void SetRangeInfo(int isArray, CNode *range)
Set range info for declaration.
virtual int IsWidthVolatile(void)
Determine if packed width of declaration is volatile, ie depend upon parameters or variables...
void IsArray(int v)
Set array flag.
Definition: cfref.h:166
CNode * GetLsb(void)
Get lsb of vector range.
CNode * GetMsb(void)
Get msb of vector range.
void DisableWidthInferencing()
Disable width inferencing.
Definition: cfref.h:114
void SetDecl(CDecl *aDecl)
Set forward declaration&#39;s actual declaration.
int IndicesRangeValid()
Determine if range can be inferred.
Decl_t Direction()
Get direction of declaration.
Definition: cfref.h:146