aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2007-09-06 16:24:05 +0000
committerTom Tromey <tromey@gcc.gnu.org>2007-09-06 16:24:05 +0000
commit5ffeb913b1a455fe79c1c116fc75f09c21194815 (patch)
treeae71ddc2b3a15a8f7bcf6b36b1592c9fb9c5138e /libcpp
parent111f1fca4d2d4e4fabf92b39c4310a3add21f29a (diff)
tree-cfg.c (remove_bb): Only warn if line is non-zero.
gcc: * tree-cfg.c (remove_bb): Only warn if line is non-zero. * c-pch.c (c_common_read_pch): Restore current location after reading PCH file. * tree.c (expand_location): Update. (expr_filename): Changed return type. Unified the two cases. (expr_lineno): Likewise. (annotate_with_file_line): Don't use EXPR_LINENO and EXPR_FILENAME as lvalues. * toplev.c (line_table): Changed type. (general_init): Update. (realloc_for_line_map): New function. (general_init): Allocate line_table using GC. * fix-header.c (line_table): Changed type. (read_scan_file): Update. (read_scan_file): Update. * c-ppoutput.c (maybe_print_line): Update. (print_line): Update. (cb_line_change): Update. (cb_define): Update. (pp_file_change): Update. * c-opts.c (c_common_init_options): Update. (finish_options): Update. (push_command_line_include): Update. * c-lex.c (cb_line_change): Update. (cb_def_pragma): Update. (cb_define): Update. (cb_undef): Update. (c_lex_with_flags): Use cpp_get_token_with_location. * input.h (line_table): Changed type. (location_from_locus): New macro. * tree.h (EXPR_FILENAME): No longer an lvalue. (EXPR_LINENO): Likewise. (expr_locus, set_expr_locus): Declare separately for USE_MAPPED_LOCATION. (expr_filename, expr_lineno): Changed return type. * gimplify.c (tree_to_gimple_tuple): Use SET_EXPR_LOCUS. * cfgexpand.c (expand_gimple_cond_expr): Use location_from_locus. (expand_gimple_basic_block): Likewise. * final.c (final_scan_insn): Use expanded_location. gcc/cp: * decl.c (finish_function): Put return's location on line zero of file. gcc/fortran: * scanner.c (get_file): Update. (load_file): Update. (gfc_next_char_literal): Use gfc_linebuf_linenum. * f95-lang.c (gfc_init): Update. * gfortran.h (gfc_linebuf_linenum): New macro. gcc/java: * lang.c (java_post_options): Update. * jcf-parse.c (set_source_filename): Update. (give_name_to_class): Update. (jcf_parse): Update. (duplicate_class_warning): Update. (parse_class_file): Update. (java_parse_file): Update. * expr.c (expand_byte_code): Update. gcc/testsuite: * lib/g++.exp (g++_target_compile): Use -fno-show-column. gcc/treelang: * tree1.c (treelang_init): Update. (treelang_parse_file): Update. (treelang_parse_file): Update. (treelang_parse_file): Update. * lex.l: Update. (update_lineno_charno): Likewise. libcpp: * internal.h (struct cpp_reader) <invocation_location>: New field. (struct cpp_reader) <set_invocation_location>: Likewise. * init.c (cpp_set_line_map): New function. * line-map.c (linemap_add): Use linemap's allocator. * include/line-map.h (GTY): Define. (line_map_realloc): New typedef. (struct line_map): Mark with GTY. (struct line_maps): Likewise. (struct line_maps) <maps>: Likewise. (struct line_maps) <reallocator>: New field. * include/symtab.h (GTY): Conditionally define. * include/cpplib.h (cpp_set_line_map): Declare. (cpp_get_token_with_location): Declare. * macro.c (cpp_get_token): Set invocation_location on the reader. (cpp_get_token_with_location): New function. From-SVN: r128190
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog19
-rw-r--r--libcpp/include/cpplib.h8
-rw-r--r--libcpp/include/line-map.h19
-rw-r--r--libcpp/include/symtab.h4
-rw-r--r--libcpp/init.c10
-rw-r--r--libcpp/internal.h8
-rw-r--r--libcpp/line-map.c11
-rw-r--r--libcpp/macro.c29
8 files changed, 98 insertions, 10 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index c24f47e1eff..08e5f86af1e 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,22 @@
+2007-09-06 Tom Tromey <tromey@redhat.com>
+
+ * internal.h (struct cpp_reader) <invocation_location>: New
+ field.
+ (struct cpp_reader) <set_invocation_location>: Likewise.
+ * init.c (cpp_set_line_map): New function.
+ * line-map.c (linemap_add): Use linemap's allocator.
+ * include/line-map.h (GTY): Define.
+ (line_map_realloc): New typedef.
+ (struct line_map): Mark with GTY.
+ (struct line_maps): Likewise.
+ (struct line_maps) <maps>: Likewise.
+ (struct line_maps) <reallocator>: New field.
+ * include/symtab.h (GTY): Conditionally define.
+ * include/cpplib.h (cpp_set_line_map): Declare.
+ (cpp_get_token_with_location): Declare.
+ * macro.c (cpp_get_token): Set invocation_location on the reader.
+ (cpp_get_token_with_location): New function.
+
2007-08-30 Chao-ying Fu <fu@mips.com>
* expr.c (interpret_float_suffix): Support hr, r, lr, llr, uhr, ur,
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 039dfbbf193..ff13cd6b532 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -1,6 +1,6 @@
/* Definitions for CPP library.
Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
- 2004, 2005
+ 2004, 2005, 2007
Free Software Foundation, Inc.
Written by Per Bothner, 1994-95.
@@ -623,6 +623,10 @@ struct cpp_hashnode GTY(())
extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *,
struct line_maps *);
+/* Reset the cpp_reader's line_map. This is only used after reading a
+ PCH file. */
+extern void cpp_set_line_map (cpp_reader *, struct line_maps *);
+
/* Call this to change the selected language standard (e.g. because of
command line options). */
extern void cpp_set_lang (cpp_reader *, enum c_lang);
@@ -687,6 +691,8 @@ extern void cpp_register_deferred_pragma (cpp_reader *, const char *,
extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
const cpp_token *);
extern const cpp_token *cpp_get_token (cpp_reader *);
+extern const cpp_token *cpp_get_token_with_location (cpp_reader *,
+ source_location *);
extern const unsigned char *cpp_macro_definition (cpp_reader *,
const cpp_hashnode *);
extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 7e9ede01a1a..cddc74d432e 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1,5 +1,5 @@
/* Map logical line numbers to (source file, line number) pairs.
- Copyright (C) 2001, 2003, 2004
+ Copyright (C) 2001, 2003, 2004, 2007
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -23,6 +23,10 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef LIBCPP_LINE_MAP_H
#define LIBCPP_LINE_MAP_H
+#ifndef GTY
+#define GTY(x) /* nothing */
+#endif
+
/* Reason for adding a line change with add_line_map (). LC_ENTER is
when including a new file, e.g. a #include directive in C.
LC_LEAVE is when reaching a file's end. LC_RENAME is when a file
@@ -35,6 +39,9 @@ enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME};
and effectively typedef source_location location_t. */
typedef unsigned int source_location;
+/* Memory allocation function typedef. Works like xrealloc. */
+typedef void *(*line_map_realloc) (void *, size_t);
+
/* Physical source file TO_FILE at line TO_LINE at column 0 is represented
by the logical START_LOCATION. TO_LINE+L at column C is represented by
START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
@@ -47,7 +54,7 @@ typedef unsigned int source_location;
creation of this line map, SYSP is one for a system header, two for
a C system header file that therefore needs to be extern "C"
protected in C++, and zero otherwise. */
-struct line_map
+struct line_map GTY(())
{
const char *to_file;
unsigned int to_line;
@@ -61,9 +68,9 @@ struct line_map
};
/* A set of chronological line_map structures. */
-struct line_maps
+struct line_maps GTY(())
{
- struct line_map *maps;
+ struct line_map * GTY ((length ("%h.used"))) maps;
unsigned int allocated;
unsigned int used;
@@ -89,6 +96,10 @@ struct line_maps
/* The maximum column number we can quickly allocate. Higher numbers
may require allocating a new line_map. */
unsigned int max_column_hint;
+
+ /* If non-null, the allocator to use when resizing 'maps'. If null,
+ xrealloc is used. */
+ line_map_realloc reallocator;
};
/* Initialize a line map set. */
diff --git a/libcpp/include/symtab.h b/libcpp/include/symtab.h
index 3ddee79eb1b..2bd45cf7f19 100644
--- a/libcpp/include/symtab.h
+++ b/libcpp/include/symtab.h
@@ -1,5 +1,5 @@
/* Hash tables.
- Copyright (C) 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2003, 2004, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -19,7 +19,9 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#define LIBCPP_SYMTAB_H
#include "obstack.h"
+#ifndef GTY
#define GTY(x) /* nothing */
+#endif
/* This is what each hash table entry points to. It may be embedded
deeply within another object. */
diff --git a/libcpp/init.c b/libcpp/init.c
index 62f4f95dcf4..aa0c0b10e3d 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -1,6 +1,6 @@
/* CPP Library.
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994-95.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -227,6 +227,14 @@ cpp_create_reader (enum c_lang lang, hash_table *table,
return pfile;
}
+/* Set the line_table entry in PFILE. This is called after reading a
+ PCH file, as the old line_table will be incorrect. */
+void
+cpp_set_line_map (cpp_reader *pfile, struct line_maps *line_table)
+{
+ pfile->line_table = line_table;
+}
+
/* Free resources used by PFILE. Accessing PFILE after this function
returns leads to undefined behavior. Returns the error count. */
void
diff --git a/libcpp/internal.h b/libcpp/internal.h
index 8561088f905..59332df4fe3 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -339,6 +339,14 @@ struct cpp_reader
/* Token generated while handling a directive, if any. */
cpp_token directive_result;
+ /* When expanding a macro at top-level, this is the location of the
+ macro invocation. */
+ source_location invocation_location;
+
+ /* True if this call to cpp_get_token should consider setting
+ invocation_location. */
+ bool set_invocation_location;
+
/* Search paths for include files. */
struct cpp_dir *quote_include; /* "" */
struct cpp_dir *bracket_include; /* <> */
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index c95eacde7e3..c13a82dcafc 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -1,5 +1,5 @@
/* Map logical line numbers to (source file, line number) pairs.
- Copyright (C) 2001, 2003, 2004
+ Copyright (C) 2001, 2003, 2004, 2007
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -96,8 +96,15 @@ linemap_add (struct line_maps *set, enum lc_reason reason,
if (set->used == set->allocated)
{
+ line_map_realloc reallocator
+ = set->reallocator ? set->reallocator : xrealloc;
set->allocated = 2 * set->allocated + 256;
- set->maps = XRESIZEVEC (struct line_map, set->maps, set->allocated);
+ set->maps
+ = (struct line_map *) (*reallocator) (set->maps,
+ set->allocated
+ * sizeof (struct line_map));
+ memset (&set->maps[set->used], 0, ((set->allocated - set->used)
+ * sizeof (struct line_map)));
}
map = &set->maps[set->used];
diff --git a/libcpp/macro.c b/libcpp/macro.c
index f2427172ca0..e80815b7bf2 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -1,7 +1,7 @@
/* Part of CPP library. (Macro and #define handling.)
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005,
- 2006 Free Software Foundation, Inc.
+ 2006, 2007 Free Software Foundation, Inc.
Written by Per Bothner, 1994.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -1094,6 +1094,8 @@ const cpp_token *
cpp_get_token (cpp_reader *pfile)
{
const cpp_token *result;
+ bool can_set = pfile->set_invocation_location;
+ pfile->set_invocation_location = false;
for (;;)
{
@@ -1139,6 +1141,10 @@ cpp_get_token (cpp_reader *pfile)
if (!(node->flags & NODE_DISABLED))
{
+ /* If not in a macro context, and we're going to start an
+ expansion, record the location. */
+ if (can_set && !context->macro)
+ pfile->invocation_location = result->src_loc;
if (!pfile->state.prevent_expansion
&& enter_macro_context (pfile, node))
{
@@ -1164,6 +1170,27 @@ cpp_get_token (cpp_reader *pfile)
return result;
}
+/* Like cpp_get_token, but also returns a location separate from the
+ one provided by the returned token. LOC is an out parameter; *LOC
+ is set to the location "as expected by the user". This matters
+ when a token results from macro expansion -- the token's location
+ will indicate where the macro is defined, but *LOC will be the
+ location of the start of the expansion. */
+const cpp_token *
+cpp_get_token_with_location (cpp_reader *pfile, source_location *loc)
+{
+ const cpp_token *result;
+
+ pfile->set_invocation_location = true;
+ result = cpp_get_token (pfile);
+ if (pfile->context->macro)
+ *loc = pfile->invocation_location;
+ else
+ *loc = result->src_loc;
+
+ return result;
+}
+
/* Returns true if we're expanding an object-like macro that was
defined in a system header. Just checks the macro at the top of
the stack. Used for diagnostic suppression. */