linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christopher Li <sparse@chrisli.org>
To: Pavel Roskin <proski@gnu.org>
Cc: linux-sparse@vger.kernel.org
Subject: Re: [RFC PATCH] Handling multiple -include directives
Date: Fri, 22 Dec 2006 01:47:48 -0800	[thread overview]
Message-ID: <20061222094748.GA32376@chrisli.org> (raw)
In-Reply-To: <1166773008.21614.4.camel@dv>

On Fri, Dec 22, 2006 at 02:36:48AM -0500, Pavel Roskin wrote:
> On Fri, 2006-12-22 at 02:06 -0500, Pavel Roskin wrote:
> > It seems to me that the existing add_pre_buffer() mechanism can be used
> > instead.  I'm just a bit worried why it wasn't done like this in the
> > first place.

I believe the reason it is not in the pre buffer is that it should first
search the current directory instead of the source file directory. The command
line -include has some subtle differences with #include "filename"

> 
> There was a reason to worry.  Now create_builtin_stream() is run after
> the includes have been processed, so that e.g. the Linux compiler.h
> tells me that my compiler is too old (because it was included from the
> command line before __GNUC__ was defined).

That is the other reason as well :-)

Can you please try this patch and see if it works for you?

Chris

Index: sparse/pre-process.c
===================================================================
Index: sparse/lib.c
===================================================================
--- sparse.orig/lib.c	2006-12-05 16:17:39.000000000 -0800
+++ sparse/lib.c	2006-12-22 01:51:00.000000000 -0800
@@ -192,7 +192,10 @@ int Wdo_while = 1;
 int Wuninitialized = 1;
 int preprocess_only;
 char *include;
-int include_fd = -1;
+
+#define CMDLINE_INCLUDE 20
+int cmdline_include_nr = 0;
+struct cmdline_include cmdline_include[CMDLINE_INCLUDE];
 
 
 void add_pre_buffer(const char *fmt, ...)
@@ -262,26 +265,26 @@ static char **handle_switch_I(char *arg,
 	return next;
 }
 
-static char **handle_switch_i(char *arg, char **next)
+static void add_cmdline_include(char *filename)
 {
-	if (*next && !strcmp(arg, "include")) {
-		char *name = *++next;
-		int fd = open(name, O_RDONLY);
-
-		include_fd = fd;
-		include = name;
-		if (fd < 0)
-			perror(name);
-	}
-	if (*next && !strcmp(arg, "imacros")) {
-		char *name = *++next;
-		int fd = open(name, O_RDONLY);
+	int fd = open(filename, O_RDONLY);
+	if (fd < 0) {
+		perror(filename);
+		return;
+	}
+	if (cmdline_include_nr >= CMDLINE_INCLUDE)
+		die("too many include files for %s\n", filename);
+	cmdline_include[cmdline_include_nr].filename = filename;
+	cmdline_include[cmdline_include_nr].fd = fd;
+	cmdline_include_nr++;
+}
 
-		include_fd = fd;
-		include = name;
-		if (fd < 0)
-			perror(name);
-	}
+static char **handle_switch_i(char *arg, char **next)
+{
+	if (*next && !strcmp(arg, "include"))
+		add_cmdline_include(*++next);
+	else if (*next && !strcmp(arg, "imacros"))
+		add_cmdline_include(*++next);
 	else if (*next && !strcmp(arg, "isystem")) {
 		char *path = *++next;
 		if (!path)
@@ -623,12 +626,14 @@ static struct symbol_list *sparse_file(c
 static struct symbol_list *sparse_initial(void)
 {
 	struct token *token;
+	int i;
 
 	// Prepend any "include" file to the stream.
 	// We're in global scope, it will affect all files!
 	token = NULL;
-	if (include_fd >= 0)
-		token = tokenize(include, include_fd, NULL, includepath);
+	for (i = cmdline_include_nr - 1; i >= 0; i--)
+		token = tokenize(cmdline_include[i].filename, cmdline_include[i].fd,
+				 token, includepath);
 
 	// Prepend the initial built-in stream
 	token = tokenize_buffer(pre_buffer, pre_buffer_size, token);
Index: sparse/token.h
===================================================================
Index: sparse/lib.h
===================================================================
--- sparse.orig/lib.h	2006-12-22 01:25:52.000000000 -0800
+++ sparse/lib.h	2006-12-22 01:42:32.000000000 -0800
@@ -33,6 +33,15 @@ struct position {
 		     noexpand:1;
 };
 
+struct cmdline_include {
+	char *filename;
+	int fd;
+};
+
+extern struct cmdline_include cmdline_include[];
+extern int cmdline_include_nr;
+
+
 struct ident;
 struct token;
 struct symbol;

  reply	other threads:[~2006-12-22 10:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-22  7:06 [RFC PATCH] Handling multiple -include directives Pavel Roskin
2006-12-22  7:36 ` Pavel Roskin
2006-12-22  9:47   ` Christopher Li [this message]
2006-12-22 22:27     ` Pavel Roskin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061222094748.GA32376@chrisli.org \
    --to=sparse@chrisli.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=proski@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).