comparison lwcc/cpp.c @ 308:670ea8f90212 ccdev

Converted preproc logic to library and moved some utility stuff to lwlib The strbuf and strpool stuff is generally useful so move it to lwlib where other such things live. Also, package the preprocessor logic into a library for easy use in multiple places.
author William Astle <lost@l-w.ca>
date Sat, 21 Sep 2013 13:33:54 -0600
parents b08787e5b9f3
children
comparison
equal deleted inserted replaced
307:9e342c4e4b66 308:670ea8f90212
25 #include <string.h> 25 #include <string.h>
26 26
27 #include <lw_alloc.h> 27 #include <lw_alloc.h>
28 #include <lw_string.h> 28 #include <lw_string.h>
29 #include <lw_stringlist.h> 29 #include <lw_stringlist.h>
30 #include <lw_strpool.h>
31 #include "cpp.h"
30 32
31 #include "cpp.h"
32 #include "strpool.h"
33 33
34 struct token *preproc_lex_next_token(struct preproc_info *); 34 struct token *preproc_lex_next_token(struct preproc_info *);
35 35
36 struct preproc_info *preproc_init(const char *fn) 36 struct preproc_info *preproc_init(const char *fn)
37 { 37 {
49 if (!fp) 49 if (!fp)
50 return NULL; 50 return NULL;
51 51
52 pp = lw_alloc(sizeof(struct preproc_info)); 52 pp = lw_alloc(sizeof(struct preproc_info));
53 memset(pp, 0, sizeof(struct preproc_info)); 53 memset(pp, 0, sizeof(struct preproc_info));
54 pp -> strpool = strpool_create(); 54 pp -> strpool = lw_strpool_create();
55 pp -> fn = strpool_strdup(pp -> strpool, fn); 55 pp -> fn = lw_strpool_strdup(pp -> strpool, fn);
56 pp -> fp = fp; 56 pp -> fp = fp;
57 pp -> ra = CPP_NOUNG; 57 pp -> ra = CPP_NOUNG;
58 pp -> unget = CPP_NOUNG; 58 pp -> unget = CPP_NOUNG;
59 pp -> ppeolseen = 1; 59 pp -> ppeolseen = 1;
60 pp -> lineno = 1; 60 pp -> lineno = 1;
136 while (pp -> tokqueue) 136 while (pp -> tokqueue)
137 { 137 {
138 preproc_next_token(pp); 138 preproc_next_token(pp);
139 token_free(pp -> curtok); 139 token_free(pp -> curtok);
140 } 140 }
141 strpool_free(pp -> strpool); 141 lw_strpool_free(pp -> strpool);
142 lw_free(pp); 142 lw_free(pp);
143 } 143 }
144 144
145 void preproc_register_error_callback(struct preproc_info *pp, void (*cb)(const char *)) 145 void preproc_register_error_callback(struct preproc_info *pp, void (*cb)(const char *))
146 { 146 {