-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "compiler.h" | ||
|
||
int preprocessor_line_macro_evaluate(struct preprocessor_definition *def, | ||
struct preprocessor_function_args *args) { | ||
struct preprocessor *preprocessor = def->preprocessor; | ||
struct compile_process *compiler = preprocessor->compiler; | ||
if (args) { | ||
compiler_error(compiler, "line macro does not accept arguments"); | ||
} | ||
|
||
struct token *prev_token = preprocessor_prev_token(compiler); | ||
return prev_token->pos.line; | ||
} | ||
|
||
struct vector * | ||
preprocessor_line_macro_value(struct preprocessor_definition *def, | ||
struct preprocessor_function_args *args) { | ||
struct preprocessor *preprocessor = def->preprocessor; | ||
struct compile_process *compiler = preprocessor->compiler; | ||
if (args) { | ||
compiler_error(compiler, "line macro does not accept arguments"); | ||
} | ||
|
||
struct token *prev_token = preprocessor_prev_token(compiler); | ||
return preprocessor_build_value_vector_for_integer(prev_token->pos.line); | ||
} | ||
|
||
void preprocessor_create_defs(struct preprocessor *preprocessor) { | ||
preprocessor_definition_create_native( | ||
"__LINE__", preprocessor_line_macro_evaluate, | ||
preprocessor_line_macro_value, preprocessor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
#define TEST(a, b) a##b | ||
/* | ||
int printf(const char *fmt, ...); | ||
int main() { printf("%i", TEST(20, 30)); } | ||
*/ | ||
|
||
int x = __LINE__; | ||
|
||
int main() { return __LINE__; } |