of a C string constant. This is the source file that was specified
on the command line of the preprocessor or C compiler.
+@item __FILE_NAME__
+This macro expands to the basename of the current input file, in the
+form of a C string constant. This is the last path component by which
+the preprocessor opened the file. For example, processing
+@code{"/usr/local/include/myheader.h"} would set this
+macro to @code{"myheader.h"}.
+
@item __INCLUDE_LEVEL__
This macro expands to a decimal integer constant that represents the
depth of nesting in include files. The value of this macro is
--- /dev/null
+/* { dg-do preprocess } */
+/* { dg-additional-options -Wno-pedantic } */
+
+main-1 __FILE_NAME__
+
+# 7 "inner.h" 1
+inner-1 __FILE_NAME__
+# 9 "subdir/inside.h" 1
+inside-1 __FILE_NAME__
+inside-2 __FILE__
+# 11 "" 2
+inner-2 __FILE_NAME__
+#13 "" 2
+main-2 __FILE_NAME__
+
+
+/* { dg-final { scan-file file-name-1.i "main-1 \"\[^\n]*file-name-1.c\"\n" } } */
+/* { dg-final { scan-file file-name-1.i "main-2 \"\[^\n]*file-name-1.c\"\n" } } */
+/* { dg-final { scan-file file-name-1.i "inner-1 \"inner.h\"\n" } } */
+/* { dg-final { scan-file file-name-1.i "inner-2 \"inner.h\"\n" } } */
+/* { dg-final { scan-file file-name-1.i "inside-1 \"inside.h\"\n" } } */
+/* { dg-final { scan-file file-name-1.i "inside-2 \"subdir/inside.h\"\n" } } */
/* { dg-error "did you mean '__FILE__'" "" { target c } misspelled__FILE_ } */
/* { dg-error "'__FILE_' was not declared in this scope; did you mean '__FILE__'\\?" "" { target c++ } misspelled__FILE_ } */
}
+
+/* Verify that we can correct "__FILE_NAME_" to "__FILE_NAME__". */
+
+const char * test_4 (void)
+{
+ return __FILE_NAME_; /* { dg-line misspelled__FILE_NAME_ } */
+ /* { dg-error "did you mean '__FILE_NAME__'" "" { target c } misspelled__FILE_NAME_ } */
+ /* { dg-error "'__FILE_NAME_' was not declared in this scope; did you mean '__FILE_NAME__'\\?" "" { target c++ } misspelled__FILE_NAME_ } */
+}
+
+/* Verify that we can correct "__FILENAME__" to "__FILE_NAME__". */
+
+const char * test_5 (void)
+{
+ return __FILENAME__; /* { dg-line misspelled__FILENAME__ } */
+ /* { dg-error "did you mean '__FILE_NAME__'" "" { target c } misspelled__FILENAME__ } */
+ /* { dg-error "'__FILENAME__' was not declared in this scope; did you mean '__FILE_NAME__'\\?" "" { target c++ } misspelled__FILENAME__ } */
+}
BT_SPECLINE = 0, /* `__LINE__' */
BT_DATE, /* `__DATE__' */
BT_FILE, /* `__FILE__' */
+ BT_FILE_NAME, /* `__FILE_NAME__' */
BT_BASE_FILE, /* `__BASE_FILE__' */
BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
BT_TIME, /* `__TIME__' */
B("__TIME__", BT_TIME, false),
B("__DATE__", BT_DATE, false),
B("__FILE__", BT_FILE, false),
+ B("__FILE_NAME__", BT_FILE_NAME, false),
B("__BASE_FILE__", BT_BASE_FILE, false),
B("__LINE__", BT_SPECLINE, true),
B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL, true),
}
break;
case BT_FILE:
+ case BT_FILE_NAME:
case BT_BASE_FILE:
{
unsigned int len;
const char *name;
uchar *buf;
-
- if (node->value.builtin == BT_FILE)
- name = linemap_get_expansion_filename (pfile->line_table,
- pfile->line_table->highest_line);
+
+ if (node->value.builtin == BT_FILE
+ || node->value.builtin == BT_FILE_NAME)
+ {
+ name = linemap_get_expansion_filename (pfile->line_table,
+ pfile->line_table->highest_line);
+ if ((node->value.builtin == BT_FILE_NAME) && name)
+ name = lbasename (name);
+ }
else
{
name = _cpp_get_file_name (pfile->main_file);