diff options
| author | Linus Torvalds <torvalds@home.transmeta.com> | 2003-03-24 23:31:58 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 20:59:45 -0700 |
| commit | 07eb1d52c06c22da1e61a8720c764e31ac0f2eaa (patch) | |
| tree | 599bb74f228798edf3f37d1be9c53050fe081dc5 | |
| parent | 727afd6233aad79650a6c9dd0a667b328789ad33 (diff) | |
| download | sparse-dev-07eb1d52c06c22da1e61a8720c764e31ac0f2eaa.tar.gz | |
Handle __LINE__ and __FILE__ in pre-processor.
| -rw-r--r-- | pre-process.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pre-process.c b/pre-process.c index 132600c9..7118be1e 100644 --- a/pre-process.c +++ b/pre-process.c @@ -121,6 +121,25 @@ static struct token *expand_defined(struct token *head) /* Expand symbol 'sym' between 'head->next' and 'head->next->next' */ static struct token *expand(struct token *, struct symbol *); +static void replace_with_string(struct token *token, const char *str) +{ + int size = strlen(str) + 1; + struct string *s = __alloc_string(size); + + s->length = size; + memcpy(s->data, str, size); + token->type = TOKEN_STRING; + token->string = s; +} + +static void replace_with_integer(struct token *token, unsigned int val) +{ + char *buf = __alloc_bytes(10); + sprintf(buf, "%d", val); + token->type = TOKEN_INTEGER; + token->integer = buf; +} + struct token *expand_one_symbol(struct token *head, struct token *token) { struct symbol *sym = lookup_symbol(token->ident, NS_PREPROCESSOR); @@ -129,6 +148,11 @@ struct token *expand_one_symbol(struct token *head, struct token *token) return token; return expand(head, sym); } + if (!memcmp(token->ident->name, "__LINE__", 9)) { + replace_with_integer(token, token->line); + } else if (!memcmp(token->ident->name, "__FILE__", 9)) { + replace_with_string(token, (input_streams + token->stream)->name); + } return token; } |
