2016-12-28 20:32:00 +00:00
|
|
|
// ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
|
2020-05-06 11:40:06 +00:00
|
|
|
// Copyright (C) 1998-2020 Marco Baye
|
2012-02-27 21:14:46 +00:00
|
|
|
// Have a look at "acme.c" for further info
|
|
|
|
//
|
2014-12-22 00:47:52 +00:00
|
|
|
// tree stuff
|
2012-02-27 21:14:46 +00:00
|
|
|
#ifndef tree_H
|
|
|
|
#define tree_H
|
|
|
|
|
|
|
|
|
2014-12-22 00:47:52 +00:00
|
|
|
#include <stdio.h> // for FILE
|
2020-05-06 12:27:32 +00:00
|
|
|
#include "config.h"
|
2012-02-27 21:14:46 +00:00
|
|
|
|
|
|
|
|
2014-12-22 00:47:52 +00:00
|
|
|
// macros for pre-defining tree node tables
|
2012-02-27 21:14:46 +00:00
|
|
|
#define PREDEFNODE(s, v) {NULL, NULL, 1, s, (void *) (v)}
|
|
|
|
#define PREDEFLAST(s, v) {NULL, NULL, 0, s, (void *) (v)}
|
|
|
|
|
|
|
|
|
|
|
|
// type definitions
|
|
|
|
|
2014-11-26 17:30:51 +00:00
|
|
|
typedef unsigned int hash_t; // must be unsigned, otherwise the hash algorithm won't be very useful!
|
2012-02-27 21:14:46 +00:00
|
|
|
|
2014-11-24 14:52:05 +00:00
|
|
|
// tree node structure type definition for lookups in "read-only" (i.e. keyword) trees
|
|
|
|
struct ronode {
|
|
|
|
struct ronode *greater_than; // pointer to sub-tree
|
|
|
|
struct ronode *less_than_or_equal; // pointer to sub-tree
|
2012-02-27 21:14:46 +00:00
|
|
|
hash_t hash_value;
|
|
|
|
const char *id_string; // name, zero-terminated
|
|
|
|
void *body; // bytes, handles or handler function
|
|
|
|
};
|
|
|
|
|
2016-08-05 09:59:07 +00:00
|
|
|
// tree node structure type definition for "read/write" items, i.e. macros/symbols
|
2014-11-24 14:52:05 +00:00
|
|
|
struct rwnode {
|
|
|
|
struct rwnode *greater_than; // pointer to sub-tree
|
|
|
|
struct rwnode *less_than_or_equal; // pointer to sub-tree
|
|
|
|
hash_t hash_value;
|
|
|
|
char *id_string; // name, zero-terminated
|
2016-08-05 09:59:07 +00:00
|
|
|
void *body; // macro/symbol body
|
2020-05-14 10:35:54 +00:00
|
|
|
int id_number; // scope number
|
2012-02-27 21:14:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-12-22 00:47:52 +00:00
|
|
|
// prototypes
|
2012-02-27 21:14:46 +00:00
|
|
|
|
|
|
|
// Add predefined tree items to given tree.
|
2014-11-24 14:52:05 +00:00
|
|
|
extern void Tree_add_table(struct ronode **tree, struct ronode *table_to_add);
|
|
|
|
// Search for a given ID string in a given tree. Store "body" component in
|
|
|
|
// node_body and return TRUE. Return FALSE if no matching item found.
|
2014-12-22 00:47:52 +00:00
|
|
|
struct dynabuf;
|
2014-11-24 14:52:05 +00:00
|
|
|
extern int Tree_easy_scan(struct ronode *tree, void **node_body, struct dynabuf *dyna_buf);
|
2012-02-27 21:14:46 +00:00
|
|
|
// Search for a "RAM tree" item. Save pointer to found tree item in given
|
2014-11-24 14:52:05 +00:00
|
|
|
// location. If no matching item is found, check the "create" flag: If set,
|
2012-02-27 21:14:46 +00:00
|
|
|
// create new tree item, link to tree, fill with data and store its pointer.
|
2020-05-12 15:08:24 +00:00
|
|
|
// If "create" is FALSE, store NULL. Returns whether item was created.
|
2020-05-06 11:40:06 +00:00
|
|
|
extern int Tree_hard_scan(struct rwnode **result, struct rwnode **forest, int id_number, boolean create);
|
2012-02-27 21:14:46 +00:00
|
|
|
// Calls given function for each node of each tree of given forest.
|
2020-05-14 10:35:54 +00:00
|
|
|
extern void Tree_dump_forest(struct rwnode **, int id_number, void (*)(struct rwnode *, FILE *), FILE *);
|
2012-02-27 21:14:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|