| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include "section.h" |
| 7 |
#include "config.h" |
| 8 |
#include "dynabuf.h" |
| 9 |
#include "global.h" |
| 10 |
#include "input.h" |
| 11 |
#include "symbol.h" |
| 12 |
#include "tree.h" |
| 13 |
|
| 14 |
|
| 15 |
#define SCOPE_INCREMENT 2 // inc by 2 so locals are even and cheaps are odd |
| 16 |
|
| 17 |
|
| 18 |
static struct section initial_section = { |
| 19 |
0, |
| 20 |
1, |
| 21 |
"during", |
| 22 |
"init", |
| 23 |
FALSE, |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
struct section *section_now = &initial_section; |
| 29 |
static struct section outer_section; |
| 30 |
static scope_t local_scope_max; |
| 31 |
static scope_t cheap_scope_max; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
void section_new(struct section *section, const char *type, char *title, boolean allocated) |
| 36 |
{ |
| 37 |
|
| 38 |
local_scope_max += SCOPE_INCREMENT; |
| 39 |
section->local_scope = local_scope_max; |
| 40 |
|
| 41 |
section->cheap_scope = section_now->cheap_scope; |
| 42 |
|
| 43 |
section->type = type; |
| 44 |
section->title = title; |
| 45 |
section->allocated = allocated; |
| 46 |
|
| 47 |
section_now = section; |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
void section_new_cheap_scope(struct section *section) |
| 54 |
{ |
| 55 |
|
| 56 |
cheap_scope_max += SCOPE_INCREMENT; |
| 57 |
section->cheap_scope = cheap_scope_max; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
void section_finalize(struct section *section) |
| 65 |
{ |
| 66 |
if (section->allocated) |
| 67 |
free(section->title); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
void section_passinit(void) |
| 73 |
{ |
| 74 |
|
| 75 |
local_scope_max = 0; |
| 76 |
section_new(&outer_section, "Zone", s_untitled, FALSE); |
| 77 |
cheap_scope_max = -1; |
| 78 |
section_new_cheap_scope(&outer_section); |
| 79 |
} |