* threaded parser
[m6w6/ext-psi] / src / builtin.c
index e4e2e9bdd4348cdec0e7eaad857a754269aab5e4..2d92432159983dba3fdbf4b1fab211f93381a9ec 100644 (file)
@@ -36,6 +36,7 @@ HashTable psi_builtins;
 
 static bool has_include(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res);
 static bool has_include_next(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res);
+static bool has_feature(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 COUNTER__(struct psi_cpp *cpp, struct psi_token *target, struct psi_plist **args, struct psi_plist **res);
 
@@ -92,7 +93,9 @@ PHP_MINIT_FUNCTION(psi_builtin)
        zend_hash_init(&psi_builtins, 0, NULL, free_builtin, 1);
        PSI_BUILTIN(has_include, PSI_T_CPP_HEADER);
        PSI_BUILTIN(has_include_next, PSI_T_CPP_HEADER);
+       PSI_BUILTIN(has_feature, PSI_T_NAME);
        PSI_BUILTIN(builtin_constant_p, PSI_T_NAME);
+
        PSI_BUILTIN(COUNTER__, -1);
 
        return SUCCESS;
@@ -158,6 +161,12 @@ static bool has_include_next(struct psi_cpp *cpp, struct psi_token *target,
        return false;
 }
 
+static bool has_feature(struct psi_cpp *cpp, struct psi_token *target,
+               struct psi_plist **args, struct psi_plist **res_ptr)
+{
+       return false;
+}
+
 static bool builtin_constant_p(struct psi_cpp *cpp, struct psi_token *target,
                struct psi_plist **args, struct psi_plist **res_ptr)
 {
@@ -178,3 +187,43 @@ static bool COUNTER__(struct psi_cpp *cpp, struct psi_token *target,
 
        return true;
 }
+
+#ifdef __APPLE__
+#include <libkern/OSByteOrder.h>
+# define bswap_16(u) _OSSwapInt16(u)
+# define bswap_32(u) _OSSwapInt32(u)
+# define bswap_64(u) _OSSwapInt64(u)
+#elif defined(__FreeBSD__)
+# include <sys/endian.h>
+# define bswap_16(u) bswap16(u)
+# define bswap_32(u) bswap32(u)
+# define bswap_64(u) bswap64(u)
+#elif defined(__OpenBSD__)
+# include <sys/types.h>
+# define bswap_16(u) swap16(u)
+# define bswap_32(u) swap32(u)
+# define bswap_64(u) swap64(u)
+#elif defined(__NetBSD__)
+# include <sys/types.h>
+# include <machine/bswap.h>
+# define bswap_16(u) bswap16(u)
+# define bswap_32(u) bswap32(u)
+# define bswap_64(u) bswap64(u)
+#else
+# include <byteswap.h>
+#endif
+
+uint16_t psi_swap16(uint16_t u)
+{
+       return bswap_16(u);
+}
+
+uint32_t psi_swap32(uint32_t u)
+{
+       return bswap_32(u);
+}
+
+uint64_t psi_swap64(uint64_t u)
+{
+       return bswap_64(u);
+}