/* Values for the origin field of struct directive. KANDR directives
come from traditional (K&R) C. STDC89 directives come from the
- 1989 C standard. EXTENSION directives are extensions. */
+ 1989 C standard. STDC2X directives come from the C2X standard. EXTENSION
+ directives are extensions. */
#define KANDR 0
#define STDC89 1
-#define EXTENSION 2
+#define STDC2X 2
+#define EXTENSION 3
/* Values for the flags field of struct directive. COND indicates a
conditional; IF_COND an opening conditional. INCL means to treat
means this directive should be handled even if -fpreprocessed is in
effect (these are the directives with callback hooks).
- EXPAND is set on directives that are always macro-expanded. */
+ EXPAND is set on directives that are always macro-expanded.
+
+ ELIFDEF is set on directives that are only handled for standards with the
+ #elifdef / #elifndef feature. */
#define COND (1 << 0)
#define IF_COND (1 << 1)
#define INCL (1 << 2)
#define IN_I (1 << 3)
#define EXPAND (1 << 4)
#define DEPRECATED (1 << 5)
+#define ELIFDEF (1 << 6)
/* Defines one #-directive, including how to handle it. */
typedef void (*directive_handler) (cpp_reader *);
D(undef, T_UNDEF, KANDR, IN_I) \
D(line, T_LINE, KANDR, EXPAND) \
D(elif, T_ELIF, STDC89, COND | EXPAND) \
+ D(elifdef, T_ELIFDEF, STDC2X, COND | ELIFDEF) \
+ D(elifndef, T_ELIFNDEF, STDC2X, COND | ELIFDEF) \
D(error, T_ERROR, STDC89, 0) \
D(pragma, T_PRAGMA, STDC89, IN_I) \
D(warning, T_WARNING, EXTENSION, 0) \
if (dname->type == CPP_NAME)
{
if (dname->val.node.node->is_directive)
- dir = &dtable[dname->val.node.node->directive_index];
+ {
+ dir = &dtable[dname->val.node.node->directive_index];
+ if ((dir->flags & ELIFDEF) && !CPP_OPTION (pfile, elifdef))
+ dir = 0;
+ }
}
/* We do not recognize the # followed by a number extension in
assembler code. */
}
}
-/* Handle a #elif directive by not changing if_stack either. See the
- comment above do_else. */
+/* Handle a #elif, #elifdef or #elifndef directive by not changing if_stack
+ either. See the comment above do_else. */
static void
do_elif (cpp_reader *pfile)
{
struct if_stack *ifs = buffer->if_stack;
if (ifs == NULL)
- cpp_error (pfile, CPP_DL_ERROR, "#elif without #if");
+ cpp_error (pfile, CPP_DL_ERROR, "#%s without #if", pfile->directive->name);
else
{
if (ifs->type == T_ELSE)
{
- cpp_error (pfile, CPP_DL_ERROR, "#elif after #else");
+ cpp_error (pfile, CPP_DL_ERROR, "#%s after #else",
+ pfile->directive->name);
cpp_error_with_line (pfile, CPP_DL_ERROR, ifs->line, 0,
"the conditional began here");
}
pfile->state.skipping = 1;
else
{
- pfile->state.skipping = ! _cpp_parse_expr (pfile, false);
- ifs->skip_elses = ! pfile->state.skipping;
+ if (pfile->directive == &dtable[T_ELIF])
+ pfile->state.skipping = !_cpp_parse_expr (pfile, false);
+ else
+ {
+ cpp_hashnode *node = lex_macro_node (pfile, false);
+
+ if (node)
+ {
+ bool macro_defined = _cpp_defined_macro_p (node);
+ if (!_cpp_maybe_notify_macro_use (pfile, node,
+ pfile->directive_line))
+ /* It wasn't a macro after all. */
+ macro_defined = false;
+ bool skip = (pfile->directive == &dtable[T_ELIFDEF]
+ ? !macro_defined
+ : macro_defined);
+ if (pfile->cb.used)
+ pfile->cb.used (pfile, pfile->directive_line, node);
+ check_eol (pfile, false);
+ pfile->state.skipping = skip;
+ }
+ }
+ ifs->skip_elses = !pfile->state.skipping;
}
/* Invalidate any controlling macro. */
}
}
+/* Handle a #elifdef directive. */
+static void
+do_elifdef (cpp_reader *pfile)
+{
+ do_elif (pfile);
+}
+
+/* Handle a #elifndef directive. */
+static void
+do_elifndef (cpp_reader *pfile)
+{
+ do_elif (pfile);
+}
+
/* #endif pops the if stack and resets pfile->state.skipping. */
static void
do_endif (cpp_reader *pfile)
char scope;
char dfp_constants;
char size_t_literals;
+ char elifdef;
};
static const struct lang_flags lang_defaults[] =
-{ /* c99 c++ xnum xid c11 std digr ulit rlit udlit bincst digsep trig u8chlit vaopt scope dfp szlit */
- /* GNUC89 */ { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
- /* GNUC99 */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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0 },
- /* GNUCXX17 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0 },
- /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0 },
- /* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0 },
- /* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0 },
- /* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1 },
- /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1 },
- /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+{ /* c99 c++ xnum xid c11 std digr ulit rlit udlit bincst digsep trig u8chlit vaopt scope dfp szlit elifdef */
+ /* GNUC89 */ { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
+ /* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
+ /* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
+ /* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
+ /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1 },
+ /* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
+ /* STDC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 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0 },
+ /* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0 },
+ /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0 },
+ /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
/* Sets internal flags correctly for a given language. */
CPP_OPTION (pfile, scope) = l->scope;
CPP_OPTION (pfile, dfp_constants) = l->dfp_constants;
CPP_OPTION (pfile, size_t_literals) = l->size_t_literals;
+ CPP_OPTION (pfile, elifdef) = l->elifdef;
}
/* Initialize library global state. */