avoid busting bash's stack with a too big if body in configure
[m6w6/ext-psi] / src / context.c
index c3f1cb11ac5e57221909d8bc2a3301153c646a44..fd315eefcbc413558bdc10a6e91ff1ec296a040a 100644 (file)
@@ -129,6 +129,15 @@ static struct psi_std_type {
        {0}
 };
 
+#include "php_psi_types.h"
+#include "php_psi_consts.h"
+#include "php_psi_macros.h"
+#include "php_psi_redirs.h"
+#include "php_psi_decls.h"
+#include "php_psi_va_decls.h"
+#include "php_psi_structs.h"
+
+/*
 static struct psi_predef_type {
        token_t type_tag;
        const char *type_name;
@@ -207,7 +216,7 @@ static struct psi_predef_struct {
        PSI_STRUCTS
        {0}
 };
-
+*/
 static int validate_lib(PSI_Data *data, void **dlopened) {
        char lib[MAXPATHLEN];
        const char *ptr = data->psi.file.ln;
@@ -957,6 +966,33 @@ static inline int validate_impl_stmts(PSI_Data *data, impl *impl) {
        return 1;
 }
 
+static inline int validate_impl_args(PSI_Data *data, impl *impl) {
+       int def = 0;
+       size_t i;
+
+       for (i = 0; i < impl->func->args->count; ++i) {
+               impl_arg *iarg = impl->func->args->args[i];
+
+               if (iarg->def) {
+                       def = 1;
+               } else if (def) {
+                       data->error(impl->func->token, PSI_WARNING,
+                                       "Non-optional argument %zu '$%s' of implementation '%s'"
+                                       " follows optional argument",
+                                       i+1, iarg->var->name, impl->func->name);
+                       return 0;
+               }
+       }
+
+       return 1;
+}
+static inline int validate_impl(PSI_Data *data, impl *impl) {
+       if (!validate_impl_args(data, impl)) {
+               return 0;
+       }
+       return validate_impl_stmts(data, impl);
+}
+
 PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErrorFunc error)
 {
        size_t i;
@@ -1153,7 +1189,7 @@ int PSI_ContextValidate(PSI_Context *C, PSI_Parser *P)
                size_t i;
 
                for (i = 0; i < D->impls->count; ++i) {
-                       if (validate_impl_stmts(PSI_DATA(C), D->impls->list[i])) {
+                       if (validate_impl(PSI_DATA(C), D->impls->list[i])) {
                                C->impls = add_impl(C->impls, D->impls->list[i]);
                        }
                }