1 /*
2   Copyright 2002-2004 John Plevyak, All Rights Reserved
3 */
4 #ifndef _dsymtab_H_
5 #define _dsymtab_H_
6 
7 #ifndef D_UserSym
8 #define D_UserSym unsigned int
9 #endif
10 
11 struct D_SymHash;
12 struct D_Scope;
13 
14 typedef struct D_Sym {
15   char *name;
16   int len;
17   unsigned int hash;
18   struct D_Scope *scope;
19   struct D_Sym *update_of;
20   struct D_Sym *next;
21   D_UserSym user;
22 } D_Sym;
23 
24 #define D_SCOPE_INHERIT 0
25 #define D_SCOPE_RECURSIVE 1
26 #define D_SCOPE_PARALLEL 2
27 #define D_SCOPE_SEQUENTIAL 3
28 
29 typedef struct D_Scope {
30   unsigned int kind : 2;
31   unsigned int owned_by_user : 1; /* don't automatically delete */
32   unsigned int depth;
33   D_Sym *ll;
34   struct D_SymHash *hash;
35   D_Sym *updates;
36   struct D_Scope *search;     /* scope to start search */
37   struct D_Scope *dynamic;    /* dynamic scope (e.g. methods) */
38   struct D_Scope *up;         /* enclosing scope */
39   struct D_Scope *up_updates; /* prior scope in speculative parse */
40   struct D_Scope *down;       /* enclosed scopes (for FREE) */
41   struct D_Scope *down_next;  /* next enclosed scope */
42 } D_Scope;
43 
44 D_Scope *new_D_Scope(D_Scope *parent);
45 D_Scope *enter_D_Scope(D_Scope *current, D_Scope *scope);
46 D_Scope *commit_D_Scope(D_Scope *scope);
47 D_Scope *equiv_D_Scope(D_Scope *scope);
48 D_Scope *global_D_Scope(D_Scope *scope);
49 D_Scope *scope_D_Scope(D_Scope *current, D_Scope *scope);
50 void free_D_Scope(D_Scope *st, int force);
51 D_Sym *new_D_Sym(D_Scope *st, char *name, char *end, int sizeof_D_Sym);
52 #define NEW_D_SYM(_st, _name, _end) new_D_Sym(_st, _name, _end, sizeof(D_Sym))
53 void free_D_Sym(D_Sym *sym);
54 D_Sym *find_D_Sym(D_Scope *st, char *name, char *end);
55 D_Sym *find_global_D_Sym(D_Scope *st, char *name, char *end);
56 /* use for first update in a production to update scope */
57 D_Sym *update_D_Sym(D_Sym *sym, D_Scope **st, int sizeof_D_Sym);
58 #define UPDATE_D_SYM(_sym, _st) update_D_Sym(_sym, _st, sizeof(D_Sym))
59 /* use for first subsequent updates in a production */
60 D_Sym *update_additional_D_Sym(D_Scope *st, D_Sym *sym, int sizeof_D_Sym);
61 #define UPDATE_ADDITIONAL_D_SYM(_st, _sym) update_additional_D_Sym(_st, _sym, sizeof(D_Sym))
62 D_Sym *current_D_Sym(D_Scope *st, D_Sym *sym);
63 D_Sym *find_D_Sym_in_Scope(D_Scope *st, D_Scope *cur, char *name, char *end);
64 D_Sym *next_D_Sym_in_Scope(D_Scope **st, D_Sym **sym);
65 void print_scope(D_Scope *st);
66 
67 #endif
68