FreeBASIC  0.91.0
symb-enum.bas
Go to the documentation of this file.
1 '' symbol table module for enumerations
2 ''
3 '' chng: sep/2004 written [v1ctor]
4 '' jan/2005 updated to use real linked-lists [v1ctor]
5 
6 
7 #include once "fb.bi"
8 #include once "fbint.bi"
9 #include once "parser.bi"
10 #include once "hash.bi"
11 #include once "list.bi"
12 
13 '':::::
14 function symbAddEnum _
15  ( _
16  byval id as zstring ptr, _
17  byval id_alias as zstring ptr, _
18  byval attrib as integer _
19  ) as FBSYMBOL ptr
20 
21  dim as FBSYMBOL ptr e = any
22 
23  '' no explict alias given?
24  if( id_alias = NULL ) then
25  '' only preserve a case-sensitive version if in BASIC mangling
26  if( parser.mangling <> FB_MANGLING_BASIC ) then
27  id_alias = id
28  end if
29  end if
30 
31  e = symbNewSymbol( FB_SYMBOPT_DOHASH, _
32  NULL, _
33  NULL, NULL, _
34  FB_SYMBCLASS_ENUM, _
35  id, id_alias, _
36  FB_DATATYPE_ENUM, NULL, attrib )
37  if( e = NULL ) then
38  return NULL
39  end if
40 
41  '' init tables
42  symbSymbTbInit( e->enum_.ns.symtb, e )
43  symbHashTbInit( e->enum_.ns.hashtb, e, FB_INITFIELDNODES )
44 
45  '' unused (while mixins aren't supported)
46  e->enum_.ns.ext = NULL
47 
48  e->enum_.elements = 0
49  e->enum_.dbg.typenum = INVALID
50 
51  '' check for forward references
52  if( symb.fwdrefcnt > 0 ) then
53  symbCheckFwdRef( e )
54  end if
55 
56  function = e
57 
58 end function
59 
60 function symbAddEnumElement _
61  ( _
62  byval parent as FBSYMBOL ptr, _
63  byval id as zstring ptr, _
64  byval intval as longint, _
65  byval attrib as integer _
66  ) as FBSYMBOL ptr
67 
68  dim as FBSYMBOL ptr s = any
69 
70  dim as FBVALUE v
71  v.i = intval
72 
73  s = symbAddConst( id, FB_DATATYPE_ENUM, parent, @v, attrib )
74 
75  parent->enum_.elements += 1
76 
77  function = s
78 end function
79 
80 sub symbDelEnum( byval s as FBSYMBOL ptr )
81  symbDelNamespaceMembers( s, TRUE )
82  symbFreeSymbol( s )
83 end sub
84 
85 '':::::
86 function symbGetEnumFirstElm _
87  ( _
88  byval parent as FBSYMBOL ptr _
89  ) as FBSYMBOL ptr
90 
91  dim as FBSYMBOL ptr sym = symbGetEnumSymbTbHead( parent )
92 
93  '' find the first const
94  do while( sym <> NULL )
95  if( symbIsConst( sym ) ) then
96  return sym
97  end if
98  sym = sym->next
99  loop
100 
101  function = NULL
102 
103 end function
104 
105 '':::::
106 function symbGetEnumNextElm _
107  ( _
108  byval sym as FBSYMBOL ptr _
109  ) as FBSYMBOL ptr
110 
111  '' find the next const
112  sym = sym->next
113  do while( sym <> NULL )
114  if( symbIsConst( sym ) ) then
115  return sym
116  end if
117  sym = sym->next
118  loop
119 
120  function = NULL
121 
122 end function
123