File: identifier.h

package info (click to toggle)
harec 0.26.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,480 kB
  • sloc: ansic: 20,054; asm: 335; makefile: 116; lisp: 80; sh: 45
file content (53 lines) | stat: -rw-r--r-- 1,428 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef HARE_IDENTIFIER_H
#define HARE_IDENTIFIER_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

// Maximum length of an identifier, as the sum of the lengths (excluding NUL
// terminators) of its parts plus one for each namespace deliniation.
//
// In other words, the length of "a::b::c" is 5.
#define IDENT_MAX 255

// Minimum buffer size needed to store an unparsed identifier, including the
// terminating NUL byte.
#define IDENT_BUFSIZ (IDENT_MAX / 2 + IDENT_MAX + 1)

struct ident {
	const char *name;
	struct ident *ns;
};

struct identifiers {
	struct ident *ident;
	struct identifiers *next;
};

struct bucket {
	void **ids;
	size_t sz;
	size_t cap;
};

struct intern_table {
	struct bucket *sbuckets;
	struct bucket *ibuckets;
};

bool ident_equal(const struct ident *a, const struct ident *b);
uint32_t ident_hash(uint32_t init, const struct ident *ident);
char *ident_unparse(const struct ident *ident);
int ident_unparse_static(const struct ident *ident, char *buf);
const char *ident_to_sym(struct intern_table *itbl, const struct ident *ident);

void intern_init(struct intern_table *itbl);

const char *intern_copy(struct intern_table *itbl, const char *s);
const char *intern_owned(struct intern_table *itbl, char *s);

struct ident *intern_ident(struct intern_table *itbl,
		const char *name, struct ident *ns);
struct ident *intern_name(struct intern_table *itbl, const char *name);

#endif