summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorGrigory Zagorodnev <grigory_zagorodnev@linux.intel.com>2006-02-18 09:25:31 +0000
committerMarcin Dalecki <dalecki@gcc.gnu.org>2006-02-18 10:25:31 +0100
commitbe8ac3e243dda9430ee53a245a3c1ee3a6acbc7c (patch)
tree7042da2d52f0b0578ba88e4df4ca0cbceeee00ab /libcpp
parent8d08b2d786e93fffe4c6802239b6808680785bc9 (diff)
downloadgcc-be8ac3e243dda9430ee53a245a3c1ee3a6acbc7c.tar.gz
cpp.texi (__TIMESTAMP__): Document.
2006-02-17 Grigory Zagorodnev <grigory_zagorodnev@linux.intel.com> gcc/ChangeLog: * doc/cpp.texi (__TIMESTAMP__): Document. libcpp/ChangeLog: * macro.c (_cpp_builtin_macro_text): Handle BT_TIMESTAMP. * files.c (_cpp_get_file_stat): New function. * include/cpplib.h (builtin_type): Add BT_TIMESTAMP. * init.c (builtin_array): Add support for __TIMESTAMP__/BT_TIMESTAMP. * internal.h (_cpp_get_file_stat): Prototype. (struct cpp_buffer): Add timestamp. gcc/testsuite/ChangeLog: * gcc.dg/cpp/undef3.c: New test. * gcc.dg/cpp/trad/builtins2.c: New test. From-SVN: r111232
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog9
-rw-r--r--libcpp/files.c7
-rw-r--r--libcpp/include/cpplib.h3
-rw-r--r--libcpp/init.c1
-rw-r--r--libcpp/internal.h5
-rw-r--r--libcpp/macro.c38
6 files changed, 62 insertions, 1 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 3a4885fc950..3b42cc104a1 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,12 @@
+2006-02-17 Grigory Zagorodnev <grigory_zagorodnev@linux.intel.com>
+
+ * macro.c (_cpp_builtin_macro_text): Handle BT_TIMESTAMP.
+ * files.c (_cpp_get_file_stat): New function.
+ * include/cpplib.h (builtin_type): Add BT_TIMESTAMP.
+ * init.c (builtin_array): Add support for __TIMESTAMP__/BT_TIMESTAMP.
+ * internal.h (_cpp_get_file_stat): Prototype.
+ (struct cpp_buffer): Add timestamp.
+
2006-01-23 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/25717
diff --git a/libcpp/files.c b/libcpp/files.c
index 31c38d0bb80..83342180590 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -1147,6 +1147,13 @@ _cpp_pop_file_buffer (cpp_reader *pfile, _cpp_file *file)
}
}
+/* Inteface to file statistics record in _cpp_file structure. */
+struct stat *
+_cpp_get_file_stat (_cpp_file *file)
+{
+ return &file->st;
+}
+
/* Set the include chain for "" to QUOTE, for <> to BRACKET. If
QUOTE_IGNORES_SOURCE_DIR, then "" includes do not look in the
directory of the including file.
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index f1b5eab93e2..2cea1f5afd2 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -555,7 +555,8 @@ enum builtin_type
BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
BT_TIME, /* `__TIME__' */
BT_STDC, /* `__STDC__' */
- BT_PRAGMA /* `_Pragma' operator */
+ BT_PRAGMA, /* `_Pragma' operator */
+ BT_TIMESTAMP /* `__TIMESTAMP__' */
};
#define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE))
diff --git a/libcpp/init.c b/libcpp/init.c
index bf4c34cf5dc..4330f884be7 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -301,6 +301,7 @@ struct builtin
#define B(n, t) { DSC(n), t }
static const struct builtin builtin_array[] =
{
+ B("__TIMESTAMP__", BT_TIMESTAMP),
B("__TIME__", BT_TIME),
B("__DATE__", BT_DATE),
B("__FILE__", BT_FILE),
diff --git a/libcpp/internal.h b/libcpp/internal.h
index 8ac1103c2d7..857bfe1d8c5 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -264,6 +264,10 @@ struct cpp_buffer
Used for include_next and to record control macros. */
struct _cpp_file *file;
+ /* Saved value of __TIMESTAMP__ macro - date and time of last modification
+ of the assotiated file. */
+ const unsigned char *timestamp;
+
/* Value of if_stack at start of this file.
Used to prohibit unmatched #endif (etc) in an include file. */
struct if_stack *if_stack;
@@ -524,6 +528,7 @@ extern void _cpp_cleanup_files (cpp_reader *);
extern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *);
extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f);
extern bool _cpp_read_file_entries (cpp_reader *, FILE *);
+extern struct stat *_cpp_get_file_stat (_cpp_file *);
/* In expr.c */
extern bool _cpp_parse_expr (cpp_reader *);
diff --git a/libcpp/macro.c b/libcpp/macro.c
index 3204e553b02..67e936ee31a 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -123,6 +123,44 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
NODE_NAME (node));
break;
+ case BT_TIMESTAMP:
+ {
+ cpp_buffer *pbuffer = cpp_get_buffer (pfile);
+ if (pbuffer->timestamp == NULL)
+ {
+ /* Initialize timestamp value of the assotiated file. */
+ struct _cpp_file *file = cpp_get_file (pbuffer);
+ if (file)
+ {
+ /* Generate __TIMESTAMP__ string, that represents
+ the date and time of the last modification
+ of the current source file. The string constant
+ looks like "Sun Sep 16 01:03:52 1973". */
+ struct tm *tb = NULL;
+ struct stat *st = _cpp_get_file_stat (file);
+ if (st)
+ tb = localtime (&st->st_mtime);
+ if (tb)
+ {
+ char *str = asctime (tb);
+ size_t len = strlen (str);
+ unsigned char *buf = _cpp_unaligned_alloc (pfile, len + 2);
+ buf[0] = '"';
+ strcpy ((char *) buf + 1, str);
+ buf[len] = '"';
+ pbuffer->timestamp = buf;
+ }
+ else
+ {
+ cpp_errno (pfile, CPP_DL_WARNING,
+ "could not determine file timestamp");
+ pbuffer->timestamp = U"\"??? ??? ?? ??:??:?? ????\"";
+ }
+ }
+ }
+ result = pbuffer->timestamp;
+ }
+ break;
case BT_FILE:
case BT_BASE_FILE:
{