From f6da7b6291706ae2be3041d24f35eba4038c9236 Mon Sep 17 00:00:00 2001 From: Martin Nilsson <mani@lysator.liu.se> Date: Sun, 27 Jun 2004 16:11:40 +0200 Subject: [PATCH] Errors in resolving #if constants is now only warnings. Rev: lib/master.pike.in:1.351 Rev: src/cpp.c:1.137 Rev: src/cpp.h:1.10 --- lib/master.pike.in | 24 ++++++++++++++++++++---- src/cpp.c | 46 ++++++++++++++++++++++++++++++---------------- src/cpp.h | 4 +++- 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/lib/master.pike.in b/lib/master.pike.in index 209ddd5ed7..04cd31f1c2 100644 --- a/lib/master.pike.in +++ b/lib/master.pike.in @@ -6,7 +6,7 @@ // Pike is distributed under GPL, LGPL and MPL. See the file COPYING // for more information. // -// $Id: master.pike.in,v 1.350 2004/06/17 16:01:40 mast Exp $ +// $Id: master.pike.in,v 1.351 2004/06/27 14:11:40 nilsson Exp $ #pike __REAL_VERSION__ //#pragma strict_types @@ -81,6 +81,8 @@ int compat_major=-1; //! int compat_minor=-1; +//! +int show_if_constant_errors = 0; // --- Functions begin here. @@ -341,10 +343,14 @@ mapping(string:int) load_time=([]); program compile_string(string source, void|string filename, object|void handler, void|program p, - void|object o) + void|object o, + void|int _show_if_constant_errors) { return compile(cpp(source, filename||"-", 1, handler, - compat_major, compat_minor), + compat_major, compat_minor, + (zero_type(_show_if_constant_errors)? + show_if_constant_errors: + _show_if_constant_errors)), handler, compat_major, compat_minor, @@ -2368,6 +2374,7 @@ void _main(array(string) orig_argv, array(string) env) ({"ignore", MAY_HAVE_ARG, ({"-Dqdatplr"}), 0, 1}), ({"ignore", HAS_ARG, ({"-s"}), 0, 0}), ({"run_tool", NO_ARG, ({"-x"}), 0, 0}), + ({"show_cpp_warn", NO_ARG, ({"--show-all-cpp-warnings"}), 0, 0}), }), 1); /* Parse -M and -I backwards */ @@ -2466,6 +2473,10 @@ void _main(array(string) orig_argv, array(string) env) case "run_tool": run_tool = 1; break; + + case "show_cpp_warn": + show_if_constant_errors = 1; + break; } } @@ -2635,9 +2646,14 @@ void _main(array(string) orig_argv, array(string) env) prog=(program)argv[0]; }; - if (err) + if (err) { + if( !file_stat(argv[0]) ) + exit(1, "Could not find file %O.\n", argv[0]); + if( !file_stat(argv[0])->isreg ) + exit(1, "File %O is not a regular file.\n", argv[0]); error( "Pike: Failed to compile script:\n" "%s\n", stringp(err[0])?err[0]:describe_backtrace(err) ); + } } if(!prog) diff --git a/src/cpp.c b/src/cpp.c index 7396ebddaf..e990342011 100644 --- a/src/cpp.c +++ b/src/cpp.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: cpp.c,v 1.136 2004/05/22 12:14:48 nilsson Exp $ +|| $Id: cpp.c,v 1.137 2004/06/27 14:11:15 nilsson Exp $ */ #include "global.h" @@ -111,6 +111,7 @@ struct cpp int compat_major; int compat_minor; struct pike_string *data; + int warn_if_constant_throws; }; struct define *defined_macro =0; @@ -183,13 +184,21 @@ void cpp_handle_exception(struct cpp *this, const char *cpp_error_fmt, ...) free_svalue(&thrown); } -static void cpp_warning(struct cpp *this, const char *err) +static void cpp_warning(struct cpp *this, const char *cpp_warn_fmt, ...) + ATTRIBUTE((format(printf,2,3))) { + char msg[8192]; + va_list args; + + va_start(args, cpp_warn_fmt); + VSNPRINTF(msg, sizeof(msg), cpp_warn_fmt, args); + va_end(args); + if((this->handler && this->handler->prog) || get_master()) { ref_push_string(this->current_file); push_int(this->current_line); - push_text(err); + push_text(msg); low_safe_apply_handler("compile_warning", this->handler, this->compat_handler, 3); pop_stack(); @@ -197,7 +206,7 @@ static void cpp_warning(struct cpp *this, const char *err) (void)fprintf(stderr, "%s:%ld: %s\n", this->current_file->str, (long)this->current_line, - err); + msg); fflush(stderr); } } @@ -1375,7 +1384,7 @@ static void check_constant(struct cpp *this, MEMCPY(str, data.ptr, dlen); str[dlen] = 0; cpp_error_sprintf (this, "Got placeholder %s (resolver problem) " - "when resolving '%s'.", + "when resolving \"%s\".", get_name_of_type (Pike_sp[-1].type), str); free (str); } @@ -1394,16 +1403,16 @@ static void check_constant(struct cpp *this, throw_value.type = T_INT; res = 0; } - else { + else if(this->warn_if_constant_throws) { if (!data.shift) { char *str = malloc(dlen + 1); MEMCPY(str, data.ptr, dlen); str[dlen] = 0; - cpp_handle_exception (this, "Error resolving '%s'.", str); + cpp_warning (this, "Error resolving \"%s\".", str); free(str); } else - cpp_handle_exception (this, "Error resolving identifier."); + cpp_warning (this, "Error resolving identifier."); res = 0; } } @@ -1426,7 +1435,7 @@ static void check_constant(struct cpp *this, BIT_MAPPING|BIT_OBJECT|BIT_PROGRAM)) res = !(SAFE_IS_ZERO(sp-1) && sp[-1].subtype == NUMBER_UNDEFINED); else { - cpp_handle_exception (this, "Error importing '.'."); + cpp_handle_exception (this, "Error importing \".\"."); res = 0; } } @@ -1539,11 +1548,11 @@ static int do_safe_index_call(struct cpp *this, struct pike_string *s) free_svalue (&throw_value); throw_value.type = T_INT; } - else { + else if(this->warn_if_constant_throws) { if (!s->size_shift) - cpp_handle_exception (this, "Error indexing module with \"%s\".", s->str); + cpp_warning (this, "Error indexing module with \"%s\".", s->str); else - cpp_handle_exception (this, "Error indexing module in '.' operator."); + cpp_warning (this, "Error indexing module in \".\" operator."); } res = 0; push_undefined(); @@ -1689,7 +1698,8 @@ static int do_safe_index_call(struct cpp *this, struct pike_string *s) /*! @decl string cpp(string data, string|void current_file, @ *! int|string|void charset, object|void handler, @ - *! void|int compat_major, void|int compat_minor) + *! void|int compat_major, void|int compat_minor, @ + *! void|int warn_if_constant_throws) *! *! Run a string through the preprocessor. *! @@ -1740,19 +1750,21 @@ void f_cpp(INT32 args) struct object *handler = 0; - int compat_major, compat_minor; + int compat_major, compat_minor, wicit; ONERROR err; #ifdef PIKE_DEBUG ONERROR tmp; #endif /* PIKE_DEBUG */ - get_all_args("cpp", args, "%t.%T%*%O%i%i", &data, ¤t_file, - &charset_sv, &handler, &compat_major, &compat_minor); + get_all_args("cpp", args, "%t.%T%*%O%i%i%i", &data, ¤t_file, + &charset_sv, &handler, &compat_major, &compat_minor, + &wicit); this.current_line=1; this.compile_errors=0; this.defines=0; + this.warn_if_constant_throws=0; this.data = data; add_ref(data); @@ -1798,6 +1810,8 @@ void f_cpp(INT32 args) if(args > 5) cpp_change_compat(&this, compat_major, compat_minor); + if(args > 6) + this.warn_if_constant_throws = wicit; if (use_initial_predefs) /* Typically compiling the master here. */ diff --git a/src/cpp.h b/src/cpp.h index 80445f861c..9dcad3ae8e 100644 --- a/src/cpp.h +++ b/src/cpp.h @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: cpp.h,v 1.9 2004/04/15 22:07:48 mast Exp $ +|| $Id: cpp.h,v 1.10 2004/06/27 14:11:15 nilsson Exp $ */ #ifndef CPP_H @@ -24,6 +24,8 @@ void cpp_error_sprintf(struct cpp *this, const char *fmt, ...) ATTRIBUTE((format(printf,2,3))); void cpp_handle_exception(struct cpp *this, const char *cpp_error_fmt, ...) ATTRIBUTE((format(printf,2,3))); +void cpp_warning(struct cpp *this, const char *cpp_warn_fmt, ...) + ATTRIBUTE((format(printf,2,3))); void PUSH_STRING(char *str, INT32 len, dynamic_buffer *buf); -- GitLab