Mercurial > hg > index.cgi
comparison lwcc/cpp.c @ 304:d85d173ba120 ccdev
Checkpoint lwcc development - preprocessor is runnable but nonfunctional
The preprocessor is currently runnable but doesn't actually do anything
useful. This is just a checkpoint.
author | William Astle <lost@l-w.ca> |
---|---|
date | Tue, 17 Sep 2013 19:33:41 -0600 |
parents | 83fcc1ed6ad6 |
children | 54f213c8fb81 |
comparison
equal
deleted
inserted
replaced
303:659e0e4ce50c | 304:d85d173ba120 |
---|---|
26 | 26 |
27 #include <lw_alloc.h> | 27 #include <lw_alloc.h> |
28 #include <lw_string.h> | 28 #include <lw_string.h> |
29 | 29 |
30 #include "cpp.h" | 30 #include "cpp.h" |
31 #include "strpool.h" | |
31 | 32 |
32 struct token *preproc_lex_next_token(struct preproc_info *); | 33 struct token *preproc_lex_next_token(struct preproc_info *); |
33 | 34 |
34 struct preproc_info *preproc_init(const char *fn) | 35 struct preproc_info *preproc_init(const char *fn) |
35 { | 36 { |
47 if (!fp) | 48 if (!fp) |
48 return NULL; | 49 return NULL; |
49 | 50 |
50 pp = lw_alloc(sizeof(struct preproc_info)); | 51 pp = lw_alloc(sizeof(struct preproc_info)); |
51 memset(pp, 0, sizeof(struct preproc_info)); | 52 memset(pp, 0, sizeof(struct preproc_info)); |
52 pp -> fn = lw_strdup(fn); | 53 pp -> strpool = strpool_create(); |
54 pp -> fn = strpool_strdup(pp -> strpool, fn); | |
53 pp -> fp = fp; | 55 pp -> fp = fp; |
54 pp -> ra = CPP_NOUNG; | 56 pp -> ra = CPP_NOUNG; |
55 pp -> ppeolseen = 1; | 57 pp -> ppeolseen = 1; |
56 return pp; | 58 return pp; |
57 } | 59 } |
110 pp -> curtok = NULL; | 112 pp -> curtok = NULL; |
111 } | 113 } |
112 | 114 |
113 void preproc_finish(struct preproc_info *pp) | 115 void preproc_finish(struct preproc_info *pp) |
114 { | 116 { |
115 lw_free((void *)(pp -> fn)); | |
116 fclose(pp -> fp); | 117 fclose(pp -> fp); |
117 if (pp -> curtok) | 118 if (pp -> curtok) |
118 token_free(pp -> curtok); | 119 token_free(pp -> curtok); |
119 while (pp -> tokqueue) | 120 while (pp -> tokqueue) |
120 { | 121 { |
121 preproc_next_token(pp); | 122 preproc_next_token(pp); |
122 token_free(pp -> curtok); | 123 token_free(pp -> curtok); |
123 } | 124 } |
125 strpool_free(pp -> strpool); | |
124 lw_free(pp); | 126 lw_free(pp); |
125 } | 127 } |
126 | 128 |
127 void preproc_register_error_callback(struct preproc_info *pp, void (*cb)(const char *)) | 129 void preproc_register_error_callback(struct preproc_info *pp, void (*cb)(const char *)) |
128 { | 130 { |