From: Michael Wallner Date: Mon, 10 Dec 2018 08:38:51 +0000 (+0100) Subject: CPP builtins X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=f9a22bf3b60ca02611f7040cd5dcde433849a09b;p=m6w6%2Fext-psi CPP builtins * __FILE__ * __LINE__ --- diff --git a/src/builtin.c b/src/builtin.c index 057e6f2..5d9d7e4 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -45,7 +45,9 @@ static bool has_feature(struct psi_cpp *cpp, struct psi_token *target, struct ps static bool builtin_constant_p(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); static bool BASE_FILE__(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); static bool COUNTER__(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); +static bool FILE__(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); static bool INCLUDE_LEVEL__(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); +static bool LINE__(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); static bool TIMESTAMP__(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res); static inline struct psi_plist *builtin_sig(token_t typ, ...) @@ -107,7 +109,9 @@ PHP_MINIT_FUNCTION(psi_builtin) PSI_BUILTIN(BASE_FILE__, -1); PSI_BUILTIN(COUNTER__, -1); + PSI_BUILTIN(FILE__, -1); PSI_BUILTIN(INCLUDE_LEVEL__, -1); + PSI_BUILTIN(LINE__, -1); PSI_BUILTIN(TIMESTAMP__, -1); return SUCCESS; @@ -230,6 +234,13 @@ static bool COUNTER__(struct psi_cpp *cpp, struct psi_token *target, return true; } +static bool FILE__(struct psi_cpp *cpp, struct psi_token *target, + struct psi_plist **args, struct psi_plist **res) +{ + ADD_QUOTED_ZSTRING(target->file); + return true; +} + static bool INCLUDE_LEVEL__(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res) { @@ -237,6 +248,13 @@ static bool INCLUDE_LEVEL__(struct psi_cpp *cpp, struct psi_token *target, return true; } +static bool LINE__(struct psi_cpp *cpp, struct psi_token *target, + struct psi_plist **args, struct psi_plist **res) +{ + ADD_UNSIGNED_NUMBER(target->line); + return true; +} + static bool TIMESTAMP__(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res) { diff --git a/tests/parser/cpp004.phpt b/tests/parser/cpp004.phpt index 8f24f1c..69d448f 100644 --- a/tests/parser/cpp004.phpt +++ b/tests/parser/cpp004.phpt @@ -12,7 +12,7 @@ LC_TIME=C ===TEST=== ===DONE=== --EXPECTF-- @@ -26,4 +26,6 @@ int(5005) string(%d) "%s/tests/parser/cpp004/builtins.psi" int(2) string(24) "%s %s %w%d %d:%d:%d %d" +string(54) "/%s/tests/parser/cpp004/include_level.h" +int(3) ===DONE=== diff --git a/tests/parser/cpp004/include_level.h b/tests/parser/cpp004/include_level.h index e5ab1e3..2658afd 100644 --- a/tests/parser/cpp004/include_level.h +++ b/tests/parser/cpp004/include_level.h @@ -1 +1,4 @@ const \include_level = __INCLUDE_LEVEL__; +const \file = __FILE__; +const \line = __LINE__; +