annotatec/graph.h -rw-r--r-- 1.8 KiB View raw
                                                                                
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef _GRAPH_H
#define _GRAPH_H
#include <stdbool.h>

struct symbol_definition;
struct symbol_reference;
struct source_file;

struct symbol_cache {
	struct scache_entry *buckets[256];
};

struct scache_entry {
	struct scache_entry *next;
	unsigned int hash;
	struct symbol_definition *symbol;
};

struct file_cache {
	struct fcache_entry *buckets[256];
};

struct fcache_entry {
	struct fcache_entry *next;
	unsigned int hash;
	struct source_file *file;
};

struct typedef_declaration {
	struct typedef_declaration *next;
	char *name;
	int lineno, colno;
};

struct symbol_definition {
	struct symbol_definition *next, *prev;
	struct symbol_reference *references;
	struct source_file *file;
	char *name;
	int lineno, colno;
	int nrefs;
	bool is_static;
};

struct symbol_reference {
	/* Linked via both files and definitions */
	struct symbol_reference *snext, *fnext;
	struct symbol_definition *symbol;
	struct source_file *file;
	int lineno, colno;
};

struct source_file {
	struct source_file *next;
	char *path, *oid;
	struct typedef_declaration *typedefs;
	struct symbol_definition *symbols;
	struct symbol_reference *references;
	int nsyms, nrefs;
};

struct project_graph {
	struct source_file *files;
	struct symbol_definition *orphans;
	struct symbol_cache symbol_cache;
	struct file_cache file_cache;
	int norphans;
};

struct symbol_definition *define_symbol(
		struct project_graph *graph, struct source_file *file,
		char *name, bool is_static, int lineno, int colno);

struct symbol_reference *reference_symbol(
		struct project_graph *graph, struct source_file *file,
		char *name, int lineno, int colno);

extern struct project_graph graph;

struct source_file *get_source_file(
		struct project_graph *graph, const char *path);
void cache_source_file(struct project_graph *graph, struct source_file *file);

#endif