Fix -nopreprocess option to correctly generate output filenames and display filenames in warnings and errors

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10930 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2008-11-16 21:40:28 +00:00
commit 8ac9453f62
5 changed files with 81 additions and 53 deletions

View file

@ -1,9 +1,14 @@
2008-09-26 Mikel Bancroft <mikel@franz.com>
Version 1.3.37 (in progress) Version 1.3.37 (in progress)
============================ ============================
2008-11-01: wsfulton 2008-11-16: wsfulton
Fix -nopreprocess option to:
- correctly report file names in warning and error messages.
- use the original input filename that created the preprocessed output when
determining the C++ wrapper file name (in the absence of -o). Previously
the name of the input file containing the preprocessed output was used.
2008-11-11: wsfulton
[Java] Add patch #2152691 from MATSUURA Takanori which fixes compiles using the [Java] Add patch #2152691 from MATSUURA Takanori which fixes compiles using the
Intel compiler Intel compiler

View file

@ -34,7 +34,9 @@ extern "C" {
extern void scanner_ignore_typedef(void); extern void scanner_ignore_typedef(void);
extern void scanner_last_id(int); extern void scanner_last_id(int);
extern void scanner_clear_rename(void); extern void scanner_clear_rename(void);
extern void scanner_set_location(String_or_char *, int line); extern void scanner_set_location(String_or_char *file, int line);
extern void scanner_set_main_input_file(String *file);
extern String *scanner_get_main_input_file();
extern void Swig_cparse_follow_locators(int); extern void Swig_cparse_follow_locators(int);
extern void start_inline(char *, int); extern void start_inline(char *, int);
extern String *scanner_ccode; extern String *scanner_ccode;

View file

@ -22,7 +22,10 @@ char cvsroot_cscanner_c[] = "$Id$";
static Scanner *scan = 0; static Scanner *scan = 0;
/* Global string containing C code. Used by the parser to grab code blocks */ /* Global string containing C code. Used by the parser to grab code blocks */
DOHString *scanner_ccode = 0; String *scanner_ccode = 0;
/* The main file being parsed */
static String *main_input_file = 0;
/* Error reporting/location information */ /* Error reporting/location information */
int cparse_line = 1; int cparse_line = 1;
@ -467,6 +470,14 @@ void scanner_next_token(int tok) {
next_token = tok; next_token = tok;
} }
void scanner_set_main_input_file(String *file) {
main_input_file = file;
}
String *scanner_get_main_input_file() {
return main_input_file;
}
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* int yylex() * int yylex()
* *

View file

@ -1894,6 +1894,8 @@ include_directive: includetype options string LBRACKET {
$1.filename = Copy(cparse_file); $1.filename = Copy(cparse_file);
$1.line = cparse_line; $1.line = cparse_line;
scanner_set_location(NewString($3),1); scanner_set_location(NewString($3),1);
if ($2 && GetFlag($2, "maininput"))
scanner_set_main_input_file(NewString($3));
} interface RBRACKET { } interface RBRACKET {
String *mname = 0; String *mname = 0;
$$ = $6; $$ = $6;

View file

@ -965,11 +965,6 @@ int SWIG_main(int argc, char *argv[], Language *l) {
} }
} }
} else { } else {
// Check the suffix for a .c file. If so, we're going to
// declare everything we see as "extern"
ForceExtern = check_suffix(input_file);
// Run the preprocessor // Run the preprocessor
if (Verbose) if (Verbose)
printf("Preprocessing...\n"); printf("Preprocessing...\n");
@ -997,7 +992,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (lang_config) { if (lang_config) {
Printf(fs, "\n%%include <%s>\n", lang_config); Printf(fs, "\n%%include <%s>\n", lang_config);
} }
Printf(fs, "%%include \"%s\"\n", Swig_last_file()); Printf(fs, "%%include(maininput=1) \"%s\"\n", Swig_last_file());
for (i = 0; i < Len(libfiles); i++) { for (i = 0; i < Len(libfiles); i++) {
Printf(fs, "\n%%include \"%s\"\n", Getitem(libfiles, i)); Printf(fs, "\n%%include \"%s\"\n", Getitem(libfiles, i));
} }
@ -1006,7 +1001,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Delete(fs); Delete(fs);
} else { } else {
df = Swig_open(input_file); df = Swig_open(input_file);
cpps = NewFileFromFile(df); cpps = Swig_read_file(df);
} }
if (Swig_error_count()) { if (Swig_error_count()) {
SWIG_exit(EXIT_FAILURE); SWIG_exit(EXIT_FAILURE);
@ -1016,6 +1011,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
SWIG_exit(EXIT_SUCCESS); SWIG_exit(EXIT_SUCCESS);
} }
if (depend) { if (depend) {
if (!no_cpp) {
String *outfile; String *outfile;
if (!outfile_name) { if (!outfile_name) {
if (CPlusPlus || lang->cplus_runtime_mode()) { if (CPlusPlus || lang->cplus_runtime_mode()) {
@ -1057,6 +1053,11 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Close(f_dependencies_file); Close(f_dependencies_file);
if (depend_only) if (depend_only)
SWIG_exit(EXIT_SUCCESS); SWIG_exit(EXIT_SUCCESS);
} else {
Printf(stderr, "Cannot generate dependencies with -nopreprocess\n");
// Actually we could but it would be inefficient when just generating dependencies, as it would be done after Swig_cparse
SWIG_exit(EXIT_FAILURE);
}
} }
Seek(cpps, 0, SEEK_SET); Seek(cpps, 0, SEEK_SET);
} }
@ -1138,18 +1139,20 @@ int SWIG_main(int argc, char *argv[], Language *l) {
SWIG_exit(EXIT_FAILURE); SWIG_exit(EXIT_FAILURE);
} else { } else {
/* Set some filename information on the object */ /* Set some filename information on the object */
Setattr(top, "infile", input_file); String *infile = scanner_get_main_input_file();
Setattr(top, "infile", infile); // Note: if nopreprocess then infile is the original input file, otherwise input_file
Setattr(top, "inputfile", input_file);
if (!outfile_name) { if (!outfile_name) {
if (CPlusPlus || lang->cplus_runtime_mode()) { if (CPlusPlus || lang->cplus_runtime_mode()) {
Setattr(top, "outfile", NewStringf("%s_wrap.%s", Swig_file_basename(input_file), cpp_extension)); Setattr(top, "outfile", NewStringf("%s_wrap.%s", Swig_file_basename(infile), cpp_extension));
} else { } else {
Setattr(top, "outfile", NewStringf("%s_wrap.c", Swig_file_basename(input_file))); Setattr(top, "outfile", NewStringf("%s_wrap.c", Swig_file_basename(infile)));
} }
} else { } else {
Setattr(top, "outfile", outfile_name); Setattr(top, "outfile", outfile_name);
} }
if (!outfile_name_h) { if (!outfile_name_h) {
Setattr(top, "outfile_h", NewStringf("%s_wrap.%s", Swig_file_basename(input_file), hpp_extension)); Setattr(top, "outfile_h", NewStringf("%s_wrap.%s", Swig_file_basename(infile), hpp_extension));
} else { } else {
Setattr(top, "outfile_h", outfile_name_h); Setattr(top, "outfile_h", outfile_name_h);
} }
@ -1157,7 +1160,12 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (Swig_contract_mode_get()) { if (Swig_contract_mode_get()) {
Swig_contracts(top); Swig_contracts(top);
} }
// Check the suffix for a c/c++ file. If so, we're going to declare everything we see as "extern"
ForceExtern = check_suffix(input_file);
lang->top(top); lang->top(top);
if (browse) { if (browse) {
Swig_browser(top, 0); Swig_browser(top, 0);
} }