Cygwin's emulation can generate non-unique inodes, so don't use it.
VMS has non-numeric inodes. */
#ifdef VMS
-#define INO_T_EQ(a, b) (!memcmp (&(a), &(b), sizeof (a)))
-#elif (defined _WIN32 && ! defined (_UWIN)) || defined __MSDOS__
-#define INO_T_EQ(a, b) 0
+# define INO_T_EQ(a, b) (!memcmp (&(a), &(b), sizeof (a)))
#else
-#define INO_T_EQ(a, b) ((a) == (b))
+# if (defined _WIN32 && ! defined (_UWIN)) || defined __MSDOS__
+# define INO_T_EQ(a, b) 0
+# else
+# define INO_T_EQ(a, b) ((a) == (b))
+# endif
#endif
/* Internal structures and prototypes. */
cpp_reader *pfile;
char *dir;
int path;
- int cxx_aware;
+ int cxx_aware ATTRIBUTE_UNUSED;
{
struct cpp_pending *pend = CPP_OPTION (pfile, pending);
struct file_name_list *new;
new->ino = st.st_ino;
new->dev = st.st_dev;
if (path == SYSTEM)
+#ifdef NO_IMPLICIT_EXTERN_C
+ new->sysp = 1;
+#else
new->sysp = cxx_aware ? 1 : 2;
+#endif
else
new->sysp = 0;
new->name_map = NULL;
cpp_reader *pfile;
enum c_lang lang;
{
- struct cpp_pending *pend = CPP_OPTION (pfile, pending);
-
/* Defaults. */
CPP_OPTION (pfile, lang) = lang;
CPP_OPTION (pfile, objc) = 0;
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, c99) = 1;
- new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
break;
case CLK_GNUC89:
CPP_OPTION (pfile, trigraphs) = 0;
/* ISO C. */
case CLK_STDC94:
- new_pending_directive (pend, "__STDC_VERSION__=199409L", cpp_define);
case CLK_STDC89:
CPP_OPTION (pfile, trigraphs) = 1;
CPP_OPTION (pfile, dollars_in_ident) = 0;
CPP_OPTION (pfile, digraphs) = lang == CLK_STDC94;
CPP_OPTION (pfile, c99) = 0;
CPP_OPTION (pfile, extended_numbers) = 0;
- new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
break;
case CLK_STDC99:
CPP_OPTION (pfile, trigraphs) = 1;
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, c99) = 1;
- new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
- new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
break;
/* Objective C. */
case CLK_OBJCXX:
- new_pending_directive (pend, "__cplusplus", cpp_define);
CPP_OPTION (pfile, cplusplus) = 1;
case CLK_OBJC:
CPP_OPTION (pfile, trigraphs) = 0;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, c99) = 0;
CPP_OPTION (pfile, objc) = 1;
- new_pending_directive (pend, "__OBJC__", cpp_define);
break;
/* C++. */
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, c99) = 0;
- new_pending_directive (pend, "__cplusplus", cpp_define);
break;
/* Assembler. */
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, digraphs) = 0;
CPP_OPTION (pfile, c99) = 0;
- new_pending_directive (pend, "__ASSEMBLER__", cpp_define);
break;
}
}
pfile = (cpp_reader *) xcalloc (1, sizeof (cpp_reader));
+ set_lang (pfile, lang);
CPP_OPTION (pfile, warn_import) = 1;
CPP_OPTION (pfile, discard_comments) = 1;
CPP_OPTION (pfile, show_column) = 1;
CPP_OPTION (pfile, pending) =
(struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
- /* After creating pfile->pending. */
- set_lang (pfile, lang);
-
/* It's simplest to just create this struct whether or not it will
be needed. */
pfile->deps = deps_init ();
s = &pfile->spec_nodes;
s->n_L = cpp_lookup (pfile, DSC("L"));
s->n_defined = cpp_lookup (pfile, DSC("defined"));
+ s->n_true = cpp_lookup (pfile, DSC("true"));
+ s->n_false = cpp_lookup (pfile, DSC("false"));
s->n__Pragma = cpp_lookup (pfile, DSC("_Pragma"));
s->n__STRICT_ANSI__ = cpp_lookup (pfile, DSC("__STRICT_ANSI__"));
s->n__CHAR_UNSIGNED__ = cpp_lookup (pfile, DSC("__CHAR_UNSIGNED__"));
return pfile;
}
-/* Free resources used by PFILE.
- This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
-void
-cpp_cleanup (pfile)
+/* Free resources used by PFILE. Accessing PFILE after this function
+ returns leads to undefined behaviour. */
+int
+cpp_destroy (pfile)
cpp_reader *pfile;
{
+ int result;
struct file_name_list *dir, *dirn;
cpp_context *context, *contextn;
contextn = context->next;
free (context);
}
+
+ result = pfile->errors;
+ free (pfile);
+
+ return result;
}
/* This structure defines one built-in identifier. A node will be
entered in the hash table under the name NAME, with value VALUE (if
any). If flags has OPERATOR, the node's operator field is used; if
- flags has BUILTIN the node's builtin field is used.
+ flags has BUILTIN the node's builtin field is used. Macros that are
+ known at build time should not be flagged BUILTIN, as then they do
+ not appear in macro dumps with e.g. -dM or -dD.
Two values are not compile time constants, so we tag
them in the FLAGS field instead:
B("__BASE_FILE__", BT_BASE_FILE),
B("__LINE__", BT_SPECLINE),
B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL),
- B("__STDC__", BT_STDC),
X("__VERSION__", VERS),
X("__USER_LABEL_PREFIX__", ULP),
#ifndef NO_BUILTIN_WINT_TYPE
C("__WINT_TYPE__", WINT_TYPE),
#endif
+#ifdef STDC_0_IN_SYSTEM_HEADERS
+ B("__STDC__", BT_STDC),
+#else
+ C("__STDC__", "1"),
+#endif
/* Named operators known to the preprocessor. These cannot be #defined
and always have their stated meaning. They are treated like normal
else
{
hp->type = NT_MACRO;
- hp->flags |= NODE_BUILTIN;
+ hp->flags |= NODE_BUILTIN | NODE_WARN;
hp->value.builtin = b->builtin;
}
}
_cpp_define_builtin (pfile, str);
}
}
+
+ if (CPP_OPTION (pfile, cplusplus))
+ {
+ _cpp_define_builtin (pfile, "__cplusplus 1");
+ if (SUPPORTS_ONE_ONLY)
+ _cpp_define_builtin (pfile, "__GXX_WEAK__ 1");
+ else
+ _cpp_define_builtin (pfile, "__GXX_WEAK__ 0");
+ }
+ if (CPP_OPTION (pfile, objc))
+ _cpp_define_builtin (pfile, "__OBJC__ 1");
+
+ if (CPP_OPTION (pfile, lang) == CLK_STDC94)
+ _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
+ else if (CPP_OPTION (pfile, c99))
+ _cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");
+
+ if (CPP_OPTION (pfile, lang) == CLK_STDC89
+ || CPP_OPTION (pfile, lang) == CLK_STDC94
+ || CPP_OPTION (pfile, lang) == CLK_STDC99)
+ _cpp_define_builtin (pfile, "__STRICT_ANSI__ 1");
+ else if (CPP_OPTION (pfile, lang) == CLK_ASM)
+ _cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
}
#undef BUILTIN
#undef OPERATOR
}
/* This is called after options have been processed. Setup for
- processing input from the file named FNAME. (Use standard input if
- FNAME == NULL.) Return 1 on success, 0 on failure. */
-
+ processing input from the file named FNAME, or stdin if it is the
+ empty string. Return 1 on success, 0 on failure. */
int
cpp_start_read (pfile, fname)
cpp_reader *pfile;
fprintf (stderr, _("End of search list.\n"));
}
- if (CPP_OPTION (pfile, in_fname) == NULL
- || *CPP_OPTION (pfile, in_fname) == 0)
- {
- CPP_OPTION (pfile, in_fname) = fname;
- if (CPP_OPTION (pfile, in_fname) == NULL)
- CPP_OPTION (pfile, in_fname) = "";
- }
- if (CPP_OPTION (pfile, out_fname) == NULL)
- CPP_OPTION (pfile, out_fname) = "";
-
if (CPP_OPTION (pfile, print_deps))
- {
- /* Set the default target (if there is none already), and
- the dependency on the main file. */
- deps_add_default_target (pfile->deps, CPP_OPTION (pfile, in_fname));
-
- deps_add_dep (pfile->deps, CPP_OPTION (pfile, in_fname));
- }
+ /* Set the default target (if there is none already). */
+ deps_add_default_target (pfile->deps, fname);
/* Open the main input file. This must be done early, so we have a
buffer to stand on. */
/* This is the list of all command line options, with the leading
"-" removed. It must be sorted in ASCII collating order. */
#define COMMAND_LINE_OPTIONS \
- DEF_OPT("", 0, OPT_stdin_stdout) \
DEF_OPT("$", 0, OPT_dollar) \
DEF_OPT("+", 0, OPT_plus) \
DEF_OPT("-help", 0, OPT__help) \
int i = 0;
struct cpp_pending *pend = CPP_OPTION (pfile, pending);
- if (argv[i][0] != '-')
+ /* Interpret "-" or a non-option as a file name. */
+ if (argv[i][0] != '-' || argv[i][1] == '\0')
{
- if (CPP_OPTION (pfile, out_fname) != NULL)
- cpp_fatal (pfile, "Too many arguments. Type %s --help for usage info",
- progname);
- else if (CPP_OPTION (pfile, in_fname) != NULL)
+ if (CPP_OPTION (pfile, in_fname) == NULL)
+ CPP_OPTION (pfile, in_fname) = argv[i];
+ else if (CPP_OPTION (pfile, out_fname) == NULL)
CPP_OPTION (pfile, out_fname) = argv[i];
else
- CPP_OPTION (pfile, in_fname) = argv[i];
+ cpp_fatal (pfile, "Too many filenames. Type %s --help for usage info",
+ progname);
}
else
{
CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
break;
case OPT_o:
- if (CPP_OPTION (pfile, out_fname) != NULL)
+ if (CPP_OPTION (pfile, out_fname) == NULL)
+ CPP_OPTION (pfile, out_fname) = arg;
+ else
{
cpp_fatal (pfile, "Output filename specified twice");
return argc;
}
- CPP_OPTION (pfile, out_fname) = arg;
- if (!strcmp (CPP_OPTION (pfile, out_fname), "-"))
- CPP_OPTION (pfile, out_fname) = "";
- break;
- case OPT_stdin_stdout:
- /* JF handle '-' as file name meaning stdin or stdout. */
- if (CPP_OPTION (pfile, in_fname) == NULL)
- CPP_OPTION (pfile, in_fname) = "";
- else if (CPP_OPTION (pfile, out_fname) == NULL)
- CPP_OPTION (pfile, out_fname) = "";
break;
case OPT_d:
/* Args to -d specify what parts of macros to dump.
cpp_post_options (pfile)
cpp_reader *pfile;
{
+ /* Canonicalize in_fname and out_fname. We guarantee they are not
+ NULL, and that the empty string represents stdin / stdout. */
+ if (CPP_OPTION (pfile, in_fname) == NULL
+ || !strcmp (CPP_OPTION (pfile, in_fname), "-"))
+ CPP_OPTION (pfile, in_fname) = "";
+
+ if (CPP_OPTION (pfile, out_fname) == NULL
+ || !strcmp (CPP_OPTION (pfile, out_fname), "-"))
+ CPP_OPTION (pfile, out_fname) = "";
+
/* -Wtraditional is not useful in C++ mode. */
if (CPP_OPTION (pfile, cplusplus))
CPP_OPTION (pfile, warn_traditional) = 0;