#pragma lib
[m6w6/ext-psi] / src / types / cpp_exp.c
index 6f0fff04d74c748e6f1d08c80f7795e226c9d867..6b21b75ec6f281e361d603cd64c8c9dbe3f48a02 100644 (file)
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/
 
-#include "php_psi_stdinc.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#else
+# include "php_config.h"
+#endif
 
 #include <assert.h>
 
 #include "data.h"
 #include "cpp.h"
+#include "debug.h"
 
 struct psi_cpp_exp *psi_cpp_exp_init(token_t type, void *data)
 {
-       struct psi_cpp_exp *exp = calloc(1, sizeof(*exp));
+       struct psi_cpp_exp *exp = pecalloc(1, sizeof(*exp), 1);
 
        switch ((exp->type = type)) {
        case PSI_T_WARNING:
@@ -46,6 +51,7 @@ struct psi_cpp_exp *psi_cpp_exp_init(token_t type, void *data)
                exp->data.tok = data;
                break;
        case PSI_T_DEFINE:
+       case PSI_T_PRAGMA:
                exp->data.decl = data;
                break;
        case PSI_T_IF:
@@ -54,7 +60,6 @@ struct psi_cpp_exp *psi_cpp_exp_init(token_t type, void *data)
                break;
        case PSI_T_ENDIF:
        case PSI_T_ELSE:
-       case PSI_T_PRAGMA_ONCE:
                break;
        default:
                assert(0);
@@ -82,6 +87,7 @@ void psi_cpp_exp_free(struct psi_cpp_exp **exp_ptr)
                        psi_token_free(&exp->data.tok);
                        break;
                case PSI_T_DEFINE:
+               case PSI_T_PRAGMA:
                        psi_cpp_macro_decl_free(&exp->data.decl);
                        break;
                case PSI_T_IF:
@@ -101,9 +107,9 @@ void psi_cpp_exp_free(struct psi_cpp_exp **exp_ptr)
        }
 }
 
-void psi_cpp_exp_dump(int fd, struct psi_cpp_exp *exp)
+void psi_cpp_exp_dump(struct psi_dump *dump, struct psi_cpp_exp *exp)
 {
-       dprintf(fd, "#%s ", exp->token->text->val);
+       PSI_DUMP(dump, "#%s ", exp->token->text->val);
        switch (exp->type) {
        case PSI_T_WARNING:
        case PSI_T_ERROR:
@@ -114,23 +120,24 @@ void psi_cpp_exp_dump(int fd, struct psi_cpp_exp *exp)
        case PSI_T_UNDEF:
        case PSI_T_IFDEF:
        case PSI_T_IFNDEF:
-               dprintf(fd, "%s", exp->data.tok->text->val);
+               PSI_DUMP(dump, "%s", exp->data.tok->text->val);
                break;
        case PSI_T_IMPORT:
        case PSI_T_INCLUDE:
        case PSI_T_INCLUDE_NEXT:
                if (exp->data.tok->type == PSI_T_CPP_HEADER) {
-                       dprintf(fd, "<%s>", exp->data.tok->text->val);
+                       PSI_DUMP(dump, "<%s>", exp->data.tok->text->val);
                } else {
-                       dprintf(fd, "\"%s\"", exp->data.tok->text->val);
+                       PSI_DUMP(dump, "\"%s\"", exp->data.tok->text->val);
                }
                break;
        case PSI_T_DEFINE:
-               psi_cpp_macro_decl_dump(fd, exp->data.decl);
+       case PSI_T_PRAGMA:
+               psi_cpp_macro_decl_dump(dump, exp->data.decl);
                break;
        case PSI_T_IF:
        case PSI_T_ELIF:
-               psi_num_exp_dump(fd, exp->data.num);
+               psi_num_exp_dump(dump, exp->data.num);
                break;
        case PSI_T_ENDIF:
        case PSI_T_ELSE:
@@ -140,7 +147,7 @@ void psi_cpp_exp_dump(int fd, struct psi_cpp_exp *exp)
                assert(0);
                break;
        }
-       dprintf(fd, "\n");
+       PSI_DUMP(dump, "\n");
 }
 
 
@@ -184,9 +191,8 @@ void psi_cpp_exp_exec(struct psi_cpp_exp *exp, struct psi_cpp *cpp, struct psi_d
                        exp->token->text->val, cpp->level, cpp->skip);
 
 #if PSI_CPP_DEBUG
-       fflush(stderr);
-       dprintf(2, "PSI: CPP exec -> ");
-       psi_cpp_exp_dump(2, exp);
+       PSI_DEBUG_PRINT(cpp->parser, "PSI: CPP exec -> ");
+       PSI_DEBUG_DUMP(cpp->parser, psi_cpp_exp_dump, exp);
 #endif
 
        switch (exp->type) {
@@ -214,6 +220,11 @@ void psi_cpp_exp_exec(struct psi_cpp_exp *exp, struct psi_cpp *cpp, struct psi_d
                        exp->data.decl = NULL;
                }
                break;
+       case PSI_T_PRAGMA:
+               if (!cpp->skip) {
+                       psi_cpp_pragma(cpp, exp->data.decl);
+               }
+               break;
        case PSI_T_IFDEF:
                ++cpp->level;
                if (!cpp->skip) {
@@ -298,21 +309,24 @@ void psi_cpp_exp_exec(struct psi_cpp_exp *exp, struct psi_cpp *cpp, struct psi_d
        case PSI_T_INCLUDE:
                if (!cpp->skip) {
                        if (!psi_cpp_include(cpp, exp->data.tok, PSI_CPP_INCLUDE)) {
-                               D->error(D, exp->token, PSI_WARNING, "Failed to include %s", exp->data.tok->text->val);
+                               D->error(D, exp->token, PSI_WARNING, "Failed to include %s: %s",
+                                               exp->data.tok->text->val, strerror(errno));
                        }
                }
                break;
        case PSI_T_INCLUDE_NEXT:
                if (!cpp->skip) {
                        if (!psi_cpp_include(cpp, exp->data.tok, PSI_CPP_INCLUDE_NEXT)) {
-                               D->error(D, exp->token, PSI_WARNING, "Failed to include %s", exp->data.tok->text->val);
+                               D->error(D, exp->token, PSI_WARNING, "Failed to include next %s: %s",
+                                               exp->data.tok->text->val, strerror(errno));
                        }
                }
                break;
        case PSI_T_IMPORT:
                if (!cpp->skip) {
                        if (!psi_cpp_include(cpp, exp->data.tok, PSI_CPP_INCLUDE_ONCE)) {
-                               D->error(D, exp->token, PSI_WARNING, "Failed to include %s", exp->data.tok->text->val);
+                               D->error(D, exp->token, PSI_WARNING, "Failed to include once %s: %s",
+                                               exp->data.tok->text->val, strerror(errno));
                        }
                }
                break;