Lines Matching refs:macro

71 /* Emits a warning if NODE is a macro defined in the main file that
79 cpp_macro *macro = node->value.macro;
81 if (!macro->used
82 && MAIN_FILE_P (linemap_lookup (pfile->line_table, macro->line)))
83 cpp_error_with_line (pfile, CPP_DL_WARNING, macro->line, 0,
84 "macro \"%s\" is not used", NODE_NAME (node));
112 a builtin macro. */
123 cpp_error (pfile, CPP_DL_ICE, "invalid built-in macro \"%s\"",
197 /* If __LINE__ is embedded in a macro, it must expand to the
198 line of the macro's invocation, not its definition.
320 cpp_error (pfile, CPP_DL_ICE, "invalid built-in macro \"%s\"",
509 object-like macro, or a function-like macro with arguments
531 invocation to a macro with no parameters should pass ARGC as zero.
536 _cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node, unsigned int argc)
538 if (argc == macro->paramc)
541 if (argc < macro->paramc)
551 if (argc + 1 == macro->paramc && macro->variadic)
553 if (CPP_PEDANTIC (pfile) && ! macro->syshdr)
560 "macro \"%s\" requires %u arguments, but only %u given",
561 NODE_NAME (node), macro->paramc, argc);
565 "macro \"%s\" passed %u arguments, but takes just %u",
566 NODE_NAME (node), argc, macro->paramc);
571 /* Reads and returns the arguments to a function-like macro
580 cpp_macro *macro;
585 macro = node->value.macro;
586 if (macro->paramc)
587 argc = macro->paramc;
639 && ! (macro->variadic && argc == macro->paramc))
658 if (argc <= macro->paramc)
661 if (argc != macro->paramc)
670 pre-expansion of a macro argument. Step back is not
676 "unterminated argument list invoking macro \"%s\"",
682 if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
684 if (_cpp_arguments_ok (pfile, macro, node, argc))
689 If the macro takes just one (varargs) parameter, then we
693 if (macro->variadic && (argc < macro->paramc
696 args[macro->paramc - 1].first = NULL;
706 /* Search for an opening parenthesis to the macro of NODE, in such a
731 /* CPP_EOF can be the end of macro arguments, or the end of the
746 /* Push the context of a macro with hash entry NODE onto the context
747 stack. If we can successfully expand the macro, we push a context
753 /* The presence of a macro invalidates a file's controlling macro. */
761 cpp_macro *macro = node->value.macro;
763 if (macro->fun_like)
777 if (CPP_WTRADITIONAL (pfile) && ! node->value.macro->syshdr)
779 "function-like macro \"%s\" must be used with arguments in traditional C",
785 if (macro->paramc > 0)
786 replace_args (pfile, node, macro, (macro_arg *) buff->base);
790 /* Disable the macro within its expansion. */
793 macro->used = 1;
795 if (macro->paramc == 0)
796 _cpp_push_token_context (pfile, node, macro->exp.tokens, macro->count);
805 /* Replace the parameters in a function-like macro of NODE with the
810 replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg *args)
818 /* First, fully macro-expand arguments, calculating the number of
822 total = macro->count;
823 limit = macro->exp.tokens + macro->count;
825 for (src = macro->exp.tokens; src < limit; src++)
832 pasted it is macro-replaced before insertion. */
841 || (src > macro->exp.tokens && (src[-1].flags & PASTE_LEFT)))
857 for (src = macro->exp.tokens; src < limit; src++)
874 else if (src != macro->exp.tokens && (src[-1].flags & PASTE_LEFT))
880 && macro->variadic
881 && src->val.arg_no == macro->paramc)
900 && src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT))
933 for (i = 0; i < macro->paramc; i++)
976 push_ptoken_context (cpp_reader *pfile, cpp_hashnode *macro, _cpp_buff *buff,
982 context->macro = macro;
990 _cpp_push_token_context (cpp_reader *pfile, cpp_hashnode *macro,
996 context->macro = macro;
1002 /* Push a traditional macro's replacement text. */
1004 _cpp_push_text_context (cpp_reader *pfile, cpp_hashnode *macro,
1010 context->macro = macro;
1014 macro->flags |= NODE_DISABLED;
1018 function-like macro. This works by pushing a context with the
1065 /* Pop the current context off the stack, re-enabling the macro if the
1066 context represented a macro's replacement list. The context
1073 if (context->macro)
1074 context->macro->flags &= ~NODE_DISABLED;
1087 including entering included files. Thus tokens are post-macro
1090 a directive inside a macro call, when at the end of a directive and
1167 /* Returns true if we're expanding an object-like macro that was
1168 defined in a system header. Just checks the macro at the top of
1173 cpp_hashnode *node = pfile->context->macro;
1175 return node && node->value.macro && node->value.macro->syshdr;
1202 they are from the lexer, and not from macro expansion. */
1234 /* Returns nonzero if a macro redefinition warning is required. */
1246 /* Redefinition of a macro is allowed if and only if the old and new
1248 macro1 = node->value.macro;
1286 /* Save parameter NODE to the parameter list of macro MACRO. Returns
1289 _cpp_save_parameter (cpp_reader *pfile, cpp_macro *macro, cpp_hashnode *node)
1295 cpp_error (pfile, CPP_DL_ERROR, "duplicate macro parameter \"%s\"",
1301 < (macro->paramc + 1) * sizeof (cpp_hashnode *))
1304 ((cpp_hashnode **) BUFF_FRONT (pfile->a_buff))[macro->paramc++] = node;
1306 len = macro->paramc * sizeof (union _cpp_hashnode_value);
1313 ((union _cpp_hashnode_value *) pfile->macro_buffer)[macro->paramc - 1]
1316 node->value.arg_index = macro->paramc;
1323 parse_params (cpp_reader *pfile, cpp_macro *macro)
1335 preserving comments in macro expansions. */
1341 "\"%s\" may not appear in macro parameter list",
1349 "macro parameters must be comma-separated");
1354 if (_cpp_save_parameter (pfile, macro, token->val.node))
1359 if (prev_ident || macro->paramc == 0)
1373 macro->variadic = 1;
1376 _cpp_save_parameter (pfile, macro,
1397 cpp_error (pfile, CPP_DL_ERROR, "missing ')' in macro parameter list");
1403 /* Allocate room for a token from a macro's replacement list. */
1405 alloc_expansion_token (cpp_reader *pfile, cpp_macro *macro)
1407 if (BUFF_ROOM (pfile->a_buff) < (macro->count + 1) * sizeof (cpp_token))
1410 return &((cpp_token *) BUFF_FRONT (pfile->a_buff))[macro->count++];
1416 lex_expansion_token (cpp_reader *pfile, cpp_macro *macro)
1421 pfile->cur_token = alloc_expansion_token (pfile, macro);
1432 else if (CPP_WTRADITIONAL (pfile) && macro->paramc > 0
1434 check_trad_stringification (pfile, macro, &token->val.str);
1440 create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
1446 function-like macro). */
1451 bool ok = parse_params (pfile, macro);
1452 macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff);
1461 (sizeof (cpp_hashnode *) * macro->paramc);
1462 memcpy (params, macro->params,
1463 sizeof (cpp_hashnode *) * macro->paramc);
1464 macro->params = params;
1467 BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->params[macro->paramc];
1468 macro->fun_like = 1;
1473 in a macro definition, ISO C90 with TC1 allows there characters
1477 "ISO C99 requires whitespace after the macro name");
1501 "missing whitespace after the macro name");
1505 if (macro->fun_like)
1506 token = lex_expansion_token (pfile, macro);
1509 token = alloc_expansion_token (pfile, macro);
1517 if (macro->count > 1 && token[-1].type == CPP_HASH && macro->fun_like)
1525 macro->count--;
1531 "'#' is not followed by a macro parameter");
1544 if (--macro->count > 0)
1545 token = lex_expansion_token (pfile, macro);
1547 if (macro->count == 0 || token->type == CPP_EOF)
1550 "'##' cannot appear at either end of a macro expansion");
1557 token = lex_expansion_token (pfile, macro);
1560 macro->exp.tokens = (cpp_token *) BUFF_FRONT (pfile->a_buff);
1561 macro->traditional = 0;
1564 macro->count--;
1567 if (macro->count)
1568 macro->exp.tokens[0].flags &= ~PREV_WHITE;
1575 * macro->count);
1576 memcpy (tokns, macro->exp.tokens, sizeof (cpp_token) * macro->count);
1577 macro->exp.tokens = tokns;
1580 BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->exp.tokens[macro->count];
1585 /* Parse a macro and save its expansion. Returns nonzero on success. */
1589 cpp_macro *macro;
1594 macro = (cpp_macro *) pfile->hash_table->alloc_subobject
1597 macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
1598 macro->line = pfile->directive_line;
1599 macro->params = 0;
1600 macro->paramc = 0;
1601 macro->variadic = 0;
1602 macro->used = !CPP_OPTION (pfile, warn_unused_macros);
1603 macro->count = 0;
1604 macro->fun_like = 0;
1606 macro->syshdr = pfile->buffer && pfile->buffer->sysp != 0;
1609 ok = _cpp_create_trad_definition (pfile, macro);
1612 ok = create_iso_definition (pfile, macro);
1624 for (i = macro->paramc; i-- > 0; )
1626 struct cpp_hashnode *node = macro->params[i];
1639 if (warn_of_redefinition (pfile, node, macro))
1646 node->value.macro->line, 0,
1656 node->value.macro = macro;
1666 check_trad_stringification (cpp_reader *pfile, const cpp_macro *macro,
1687 /* Loop over the function macro arguments to see if the
1689 for (i = 0; i < macro->paramc; i++)
1691 const cpp_hashnode *node = macro->params[i];
1697 "macro argument \"%s\" would be stringified in traditional C",
1705 /* Returns the name, arguments and expansion of a macro, in a format
1714 const cpp_macro *macro = node->value.macro;
1726 if (macro->fun_like)
1730 for (i = 0; i < macro->paramc; i++)
1731 len += NODE_LEN (macro->params[i]) + 1; /* "," */
1736 len += _cpp_replacement_text_len (macro);
1739 for (i = 0; i < macro->count; i++)
1741 cpp_token *token = &macro->exp.tokens[i];
1744 len += NODE_LEN (macro->params[token->val.arg_no - 1]);
1764 /* Fill in the buffer. Start with the macro name. */
1770 if (macro->fun_like)
1773 for (i = 0; i < macro->paramc; i++)
1775 cpp_hashnode *param = macro->params[i];
1783 if (i + 1 < macro->paramc)
1788 else if (macro->variadic)
1794 /* The Dwarf spec requires a space after the macro name, even if the
1799 buffer = _cpp_copy_replacement_text (macro, buffer);
1800 else if (macro->count)
1803 for (i = 0; i < macro->count; i++)
1805 cpp_token *token = &macro->exp.tokens[i];
1815 NODE_NAME (macro->params[token->val.arg_no - 1]),
1816 NODE_LEN (macro->params[token->val.arg_no - 1]));
1817 buffer += NODE_LEN (macro->params[token->val.arg_no - 1]);