[patch] __TIMESTAMP__ predefined macro
Andrew Pinski
pinskia@physics.uc.edu
Wed Feb 15 14:40:00 GMT 2006
> Hi!
>
> The patch implements __TIMESTAMP__ predefined macro in the form similar
> to MSVC and ICC compilers - date and time of the last modification of
> the current source file like "Thu Feb 9 18:07:36 2006". This macro
> seems to be widely used but not implemented in GCC yet.
>
> Verified at x86_64-redhat-linux-gnu.
>
> Ok for mainline?
>
> - Grigory
>
> 2006-02-15 Grigory Zagorodnev <grigory_zagorodnev@linux.intel.com>
>
> * gcc/doc/cpp.texi: add description of __TIMESTAMP__ macro to the
> user's documentation
> * gcc/testsuite/gcc.dg/cpp/undef2.c: enlarge tests to cover new
> predefined macro
> * gcc/testsuite/gcc.dg/cpp/trad/builtins.c: same as above
> * libcpp/macro.c (_cpp_builtin_macro_text): generate text for
> __TIMESTAMP__ built-in macro
> * libcpp/files.c (_cpp_get_file_stat): new function - interface to
> file statistics record in _cpp_file structure.
> * libcpp/include/cpplib.h: new constant to process __TIMESTAMP__
> macro definition
> * libcpp/init.c: new built in macro definition
> * libcpp/internal.h: new declaration of _cpp_get_file_stat; new
> field timestamp of cpp_buffer structure to hold generated string for
> future possible reuse
It would be better if you added new testcases instead of modifying the ones already
there so it is easier to compare results between GCC versions.
A better way to write this changeLog is:
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.
Some comments about the patch:
+ struct stat *st = _cpp_get_file_stat(file);
+ if (st)
+ tb = localtime (&(st->st_mtime));
Why not make a function which returns a pointer to the modification date instead of returning one
to the stat?
+ sprintf ((char *)pbuffer->timestamp,
+ "\"%3s %3s %2d %02d:%02d:%02d %4d\"",
+ daynames[tb->tm_wday], monthnames[tb->tm_mon],
+ tb->tm_mday, tb->tm_hour, tb->tm_min,
+ tb->tm_sec, tb->tm_year + 1900);
Also why don't you just use ctime or asctime instead of spelling it out?
Considering ctime and asctim are C89, I would expect most targets to define it anyways.
Thanks,
Andrew Pinski
More information about the Gcc-patches
mailing list