summaryrefslogtreecommitdiff
path: root/igen/preprocessor.h
blob: 951f36c3d8a923803fb851ff921fdb5779989990 (plain)
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
#ifndef PREPROCESSOR_H
#define PREPROCESSOR_H

#include "lexer.h"


typedef enum comment_type comment_type;
typedef enum directive_type directive_type;
typedef struct stmt stmt;
typedef struct linked_list linked_list;
typedef struct keyword keyword;
typedef struct cursor cursor;
typedef struct whitespace whitespace;
typedef struct comment comment;
typedef struct source source;
typedef void *(keyword_cb)(void *ctx, int dbg);

enum directive_type {
	DIR_NONE,
	DIR_INCLUDE,
	NUM_DIRS
};

enum comment_type {
	COMM_NONE,
	COMM_MULTI,
	COMM_SINGLE,
	NUM_COMMS
};

struct linked_list {
	void *data;
	linked_list *next;
};

struct keyword {
	char *name;
	int id;
	keyword_cb *found_keyword;
};

struct cursor {
	int line;
	int column;
};

struct whitespace {
	int spaces;
	int bspaces;
	int tabs;
	int vtabs;
	int lines;
};

struct comment {
	enum comment_type type;
	char *text;
	cursor start_pos;
	cursor end_pos;
	whitespace wsp;
};

struct source {
	source *parent;
	source **include_list;
	comment **comments;
	char *filename;
	char *text;
	int included : 1;
	int tab_width;
	cursor cur;
	stmt *root;
	stmt *last;
};

/*extern keyword *find_keyword(const char *key, keyword **keywords, int dbg);*/
extern char *skip_whitespace(source *src, whitespace *wspace, int count_lines, int count_columns, int dbg);
extern char *skip_comment(source *src, whitespace *wspace, comment_type *type, int dbg);
extern int find_keyword(const char *key, keyword **keywords, void *ctx, void **callback_ret, int dbg);
extern source *preprocess(source *parent, const char *filename, int dbg);
#endif