FreeBASIC  0.91.0
symb-scope.bas
Go to the documentation of this file.
1 '' symbol table module for scopes
2 ''
3 '' chng: sep/2004 written [v1ctor]
4 
5 
6 #include once "fb.bi"
7 #include once "fbint.bi"
8 #include once "parser.bi"
9 #include once "list.bi"
10 #include once "ast.bi"
11 #include once "rtl.bi"
12 
13 '':::::
14 function symbAddScope _
15  ( _
16  byval backnode as ASTNODE ptr _
17  ) as FBSYMBOL ptr
18 
19  dim as FBSYMBOL ptr s
20 
21  s = symbNewSymbol( FB_SYMBOPT_NONE, _
22  NULL, _
23  symb.symtb, NULL, _
24  FB_SYMBCLASS_SCOPE, _
25  NULL, NULL, _
26  FB_DATATYPE_INVALID, NULL )
27 
28  symbSymbTbInit( s->scp.symtb, s )
29  s->scp.backnode = backnode
30 
31  function = s
32 
33 end function
34 
35 '':::::
36 sub symbDelScope _
37  ( _
38  byval scp as FBSYMBOL ptr _
39  )
40 
41  if( scp = NULL ) then
42  exit sub
43  end if
44 
45  '' del all symbols inside the scope block
46  do
47  '' starting from last because of the USING's that could be
48  '' referencing a namespace in the same scope block
49  dim as FBSYMBOL ptr s = scp->scp.symtb.tail
50  if( s = NULL ) then
51  exit do
52  end if
53 
54  symbDelSymbol( s, TRUE )
55  loop
56 
57  '' del the scope node
58  symbFreeSymbol( scp )
59 
60 end sub
61 
62 '':::::
63 sub symbDelScopeTb _
64  ( _
65  byval scp as FBSYMBOL ptr _
66  )
67 
68  '' for each symbol declared inside the SCOPE block..
69  dim as FBSYMBOL ptr s = scp->scp.symtb.tail
70  do while( s <> NULL )
71  '' remove from hash only
72 
73  '' not a namespace import (USING)?
74  if( s->class <> FB_SYMBCLASS_NSIMPORT ) then
75  symbDelFromHash( s )
76  else
77  symbNamespaceRemove( s, TRUE )
78  end if
79 
80  s = s->prev
81  loop
82 
83 end sub
84