Debian Codegraph @

src/tree.h

raw symbols SCIP
1 // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
2 // Copyright (C) 1998-2024 Marco Baye
3 // Have a look at "acme.c" for further info
4 //
5 // tree stuff
6 #ifndef tree_H
7 #define tree_H
8
9
10 #include <stdio.h> // for FILE
11 #include "config.h"
12
13
14 // macros for pre-defining tree node tables
15 #define PREDEF_START {NULL, NULL, 0, NULL, NULL} // this is used to determine if list has been made into tree yet
16 #define PREDEFNODE(s, v) {NULL, NULL, 1, s, (void *) (v)}
17 #define PREDEF_END(s, v) {NULL, NULL, 0, s, (void *) (v)}
18
19 // type definitions
20
21 typedef unsigned int hash_t; // must be unsigned, otherwise the hash algorithm won't be very useful!
22
23 // tree node structure type definition for lookups in "read-only" (i.e. keyword) trees
24 struct ronode {
25 struct ronode *greater_than; // pointer to sub-tree
26 struct ronode *less_than_or_equal; // pointer to sub-tree
27 hash_t hash_value;
28 const char *id_string; // name, zero-terminated
29 void *body; // bytes, handles or handler function
30 };
31
32 // tree node structure type definition for "read/write" items, i.e. macros/symbols
33 struct rwnode {
34 struct rwnode *greater_than; // pointer to sub-tree
35 struct rwnode *less_than_or_equal; // pointer to sub-tree
36 hash_t hash_value;
37 char *id_string; // name, zero-terminated
38 void *body; // macro/symbol body
39 int id_number; // scope number (FIXME - get rid of this, use name prefixes instead!)
40 };
41
42
43 // prototypes
44
45 // Search for a given ID string in a given tree. Store "body" component in
46 // node_body and return TRUE. Return FALSE if no matching item found.
47 struct dynabuf;
48 extern int tree_easy_scan(struct ronode *tree, void **node_body, struct dynabuf *dyna_buf);
49
50 // Search for a "RAM tree" item. Save pointer to found tree item in given
51 // location. If no matching item is found, check the "create" flag: If set,
52 // create new tree item, link to tree, fill with data and store its pointer.
53 // If "create" is FALSE, store NULL. Returns whether item was created.
54 extern int tree_hard_scan(struct rwnode **result, struct rwnode **forest, int id_number, boolean create);
55
56 // Call given function for each node of each tree of given forest.
57 extern void tree_dump_forest(struct rwnode **, int id_number, void (*)(struct rwnode *, FILE *), FILE *);
58
59
60 #endif