===================================================================
@@ -25,14 +25,117 @@
represented by a bitmap. */
typedef unsigned lang_bitmap;
-/* A file position, mostly for error messages.
- The FILE element may be compared using pointer equality. */
+/* Variable length structure representing an input file. A hash table
+ ensure uniqueness for a given input file name. The only function
+ allocating input_file-s is input_file_by_name. */
/* Variable length structure representing an input file. Each unique given
file name has one and only one variable of this type, stored in a hash
table input_file_htab in gengtype.c. */
===================================================================
@@ -24,7 +24,9 @@ along with GCC; see the file COPYING3. If not see
%{
#include "bconfig.h"
#include "system.h"
+#include "errors.h" /* for fatal, needed by gengtype.h */
+
#define malloc xmalloc
#define realloc xrealloc
@@ -202,7 +204,7 @@ yybegin (const char *fname)
perror (fname);
exit (1);
}
- lexer_line.file = fname;
+ lexer_line.file = input_file_by_name (fname);
lexer_line.line = 1;
}
We have discussed this before but I still do not follow. This patch
does not add include of gengtype.h, so if it worked previsouly without
#include "errors.h", it should still work. Likewise for
gengtype-parse.c.
@@ -708,6 +710,7 @@ static type_p
type (options_p *optsp, bool nested)
{
const char *s;
+ static int anonymous_count; /* To generate unique pseudo-identifiers! */
*optsp = 0;
switch (token ())
{
@@ -750,7 +753,32 @@ type (options_p *optsp, bool nested)
if (token () == ID)
s = advance ();
else
- s = xasprintf ("anonymous:%s:%d", lexer_line.file, lexer_line.line);
+ {
+ /* We don't want to wire in the source directory (because
+ in plugin mode, the source directory can be unavailable
+ since gengtype has read its state). So if the input is
+ from GCC source directory, we use its relative path to
+ build an anonymous unique tag. */
+ const char* relp = get_file_srcdir_relative_path (lexer_line.file);
+ anonymous_count++;
+ if (relp)
+ {
+ /* The input file is a GCC source file, we use a double
+ colon after anonymous. To be sure s is truly unique,
+ we also use anonymous_count. */
+ s = xasprintf ("anonymous::%s:%d::%d",
+ relp, lexer_line.line, anonymous_count);
+ }
+ else
+ {
+ /* The input file is outside of GCC source tree, we use
+ a single colon after anonymous. To be sure s is
+ truly unique, we also use anonymous_count. */
+ s = xasprintf ("anonymous:%s:%d::%d",
+ get_input_file_name (lexer_line.file),
+ lexer_line.line, anonymous_count);
+ }
+ }
/* Unfortunately above GTY_TOKEN check does not capture the
typedef struct_type GTY case. */
@@ -787,7 +815,19 @@ type (options_p *optsp, bool nested)
if (token () == ID)
s = advance ();
else
- s = xasprintf ("anonymous:%s:%d", lexer_line.file, lexer_line.line);
+ {
+ /* Again, we don't want to wire in the GCC source tree
+ directory. */
+ const char* relp = get_file_srcdir_relative_path (lexer_line.file);
+ anonymous_count++;
+ if (relp)
+ s = xasprintf ("anonymous::%s:%d::%d",
+ relp, lexer_line.line, anonymous_count);
+ else
+ s = xasprintf ("anonymous:%s:%d::%d",
+ get_input_file_name (lexer_line.file),
+ lexer_line.line, anonymous_count);
+ }
if (token () == '{')
consume_balanced ('{', '}');
Separate patch please.
2010/10/20 Basile Starynkevitch <basile@starynkevitch.net>:
>
> Hello all,
>
> References:
> http://gcc.gnu.org/ml/gcc-patches/2010-09/msg01742.html
> http://gcc.gnu.org/ml/gcc-patches/2010-10/msg01536.html
> http://gcc.gnu.org/ml/gcc-patches/2010-10/msg01452.html
>
> and others linked from them.
>
> After having separately commited the removal of location_s and having
> taken account Laurynas's comments
> http://gcc.gnu.org/ml/gcc-patches/2010-10/msg01452.html I am attaching
> a patch on gengtype adding a real input_file structure relative to