Mercurial > hg > index.cgi
comparison lwcc/token.h @ 299:856caf91ffaa ccdev
Added token list structure and switched some stuff to use it
Swithced to using a token list structure instead of manually fiddling
pointers throughout the macro expansion code. Also fixed up some problematic
things related to stringification and concatenation.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 15 Sep 2013 13:06:00 -0600 |
parents | 83fcc1ed6ad6 |
children | 54f213c8fb81 |
comparison
equal
deleted
inserted
replaced
298:6112c67728ba | 299:856caf91ffaa |
---|---|
91 TOK_CHR_LIT, | 91 TOK_CHR_LIT, |
92 TOK_STR_LIT, | 92 TOK_STR_LIT, |
93 TOK_ARROW, | 93 TOK_ARROW, |
94 TOK_ENDEXPAND, | 94 TOK_ENDEXPAND, |
95 TOK_STARTEXPAND, | 95 TOK_STARTEXPAND, |
96 TOK_ERROR, | |
96 TOK_MAX | 97 TOK_MAX |
97 }; | 98 }; |
98 | 99 |
99 struct token | 100 struct token |
100 { | 101 { |
101 int ttype; // token type | 102 int ttype; // token type |
102 char *strval; // the token value if relevant | 103 char *strval; // the token value if relevant |
103 struct token *prev; // previous token in a list | 104 struct token *prev; // previous token in a list |
104 struct token *next; // next token in a list | 105 struct token *next; // next token in a list |
106 struct token_list *list;// pointer to head of list descriptor this token is on | |
105 int lineno; // line number token came from | 107 int lineno; // line number token came from |
106 int column; // character column token came from | 108 int column; // character column token came from |
107 const char *fn; // file name token came from | 109 const char *fn; // file name token came from |
110 }; | |
111 | |
112 struct token_list | |
113 { | |
114 struct token *head; // the head of the list | |
115 struct token *tail; // the tail of the list | |
108 }; | 116 }; |
109 | 117 |
110 extern void token_free(struct token *); | 118 extern void token_free(struct token *); |
111 extern struct token *token_create(int, char *strval, int, int, const char *); | 119 extern struct token *token_create(int, char *strval, int, int, const char *); |
112 extern struct token *token_dup(struct token *); | 120 extern struct token *token_dup(struct token *); |
113 /* add a token to the end of a list */ | 121 /* add a token to the end of a list */ |
114 extern void token_append(struct token *, struct token *); | 122 extern void token_list_append(struct token_list *, struct token *); |
115 /* add a token to the start of a list */ | 123 /* add a token to the start of a list */ |
116 extern void token_prepend(struct token *, struct token *); | 124 extern void token_list_prepend(struct token_list *, struct token *); |
117 /* remove individual token from whatever list it is on */ | 125 /* remove individual token from whatever list it is on */ |
118 extern void token_remove(struct token *); | 126 extern void token_list_remove(struct token *); |
119 /* replace token with list of tokens specified */ | 127 /* replace token with list of tokens specified */ |
120 extern void token_replace(struct token *, struct token *); | 128 extern void token_list_insert(struct token_list *, struct token *, struct token *); |
129 /* duplicate a list to a new list pointer */ | |
130 extern struct token_list *token_list_dup(struct token_list *); | |
121 /* print a token out */ | 131 /* print a token out */ |
132 extern struct token_list *token_list_create(void); | |
133 extern void token_list_destroy(struct token_list *); | |
134 | |
122 extern void token_print(struct token *, FILE *); | 135 extern void token_print(struct token *, FILE *); |
123 | 136 |
124 #endif // token_h_seen___ | 137 #endif // token_h_seen___ |