CPP builtins
authorMichael Wallner <mike@php.net>
Mon, 10 Dec 2018 08:38:51 +0000 (09:38 +0100)
committerMichael Wallner <mike@php.net>
Mon, 10 Dec 2018 08:38:51 +0000 (09:38 +0100)
* __FILE__
* __LINE__

src/builtin.c
tests/parser/cpp004.phpt
tests/parser/cpp004/include_level.h

index 057e6f2fa7f9407d16deb16af6843934d05ba396..5d9d7e42f00dd9574fd9548bd8b65a696cfaa889 100644 (file)
@@ -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 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 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, ...)
 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(BASE_FILE__, -1);
        PSI_BUILTIN(COUNTER__, -1);
+       PSI_BUILTIN(FILE__, -1);
        PSI_BUILTIN(INCLUDE_LEVEL__, -1);
        PSI_BUILTIN(INCLUDE_LEVEL__, -1);
+       PSI_BUILTIN(LINE__, -1);
        PSI_BUILTIN(TIMESTAMP__, -1);
 
        return SUCCESS;
        PSI_BUILTIN(TIMESTAMP__, -1);
 
        return SUCCESS;
@@ -230,6 +234,13 @@ static bool COUNTER__(struct psi_cpp *cpp, struct psi_token *target,
        return true;
 }
 
        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)
 {
 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;
 }
 
        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)
 {
 static bool TIMESTAMP__(struct psi_cpp *cpp, struct psi_token *target,
                struct psi_plist **args, struct psi_plist **res)
 {
index 8f24f1c15b24da3f9835fec620c93dee23f24f5e..69d448f08dda1f04a939642ac5c1cd3636b689df 100644 (file)
@@ -12,7 +12,7 @@ LC_TIME=C
 ===TEST===
 <?php 
 var_dump(CPP_TEST0, CPP_TEST1, CPP_TEST2, CPP_TEST3, CPP_TEST4, CPP_TEST5);
 ===TEST===
 <?php 
 var_dump(CPP_TEST0, CPP_TEST1, CPP_TEST2, CPP_TEST3, CPP_TEST4, CPP_TEST5);
-var_dump(base_file, include_level, timestamp);
+var_dump(base_file, include_level, timestamp, file, line);
 ?>
 ===DONE===
 --EXPECTF--
 ?>
 ===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(%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===
 ===DONE===
index e5ab1e3b30603d60293909450619dd5e97727e65..2658afdcff60119427af1cf85115a7397900f0a8 100644 (file)
@@ -1 +1,4 @@
 const \include_level = __INCLUDE_LEVEL__;
 const \include_level = __INCLUDE_LEVEL__;
+const \file = __FILE__;
+const \line = __LINE__;
+