Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1043)

Side by Side Diff: gcc/libcpp/macro.c

Issue 3050029: [gcc] GCC 4.5.0=>4.5.1 (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/nacl-toolchain.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gcc/libcpp/line-map.c ('k') | gcc/libcpp/makedepend.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Part of CPP library. (Macro and #define handling.) 1 /* Part of CPP library. (Macro and #define handling.)
2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998, 2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 3 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 2006, 2007, 2008, 2009 Free Software Foundation, Inc. 4 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5 Written by Per Bothner, 1994. 5 Written by Per Bothner, 1994.
6 Based on CCCP program by Paul Rubin, June 1986 6 Based on CCCP program by Paul Rubin, June 1986
7 Adapted to ANSI C, Richard Stallman, Jan 1987 7 Adapted to ANSI C, Richard Stallman, Jan 1987
8 8
9 This program is free software; you can redistribute it and/or modify it 9 This program is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the 10 under the terms of the GNU General Public License as published by the
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 dest = BUFF_FRONT (pfile->u_buff); 362 dest = BUFF_FRONT (pfile->u_buff);
363 *dest++ = '"'; 363 *dest++ = '"';
364 364
365 /* Loop, reading in the argument's tokens. */ 365 /* Loop, reading in the argument's tokens. */
366 for (i = 0; i < arg->count; i++) 366 for (i = 0; i < arg->count; i++)
367 { 367 {
368 const cpp_token *token = arg->first[i]; 368 const cpp_token *token = arg->first[i];
369 369
370 if (token->type == CPP_PADDING) 370 if (token->type == CPP_PADDING)
371 { 371 {
372 » if (source == NULL) 372 » if (source == NULL
373 » || (!(source->flags & PREV_WHITE)
374 » » && token->val.source == NULL))
373 source = token->val.source; 375 source = token->val.source;
374 continue; 376 continue;
375 } 377 }
376 378
377 escape_it = (token->type == CPP_STRING || token->type == CPP_CHAR 379 escape_it = (token->type == CPP_STRING || token->type == CPP_CHAR
378 || token->type == CPP_WSTRING || token->type == CPP_WCHAR 380 || token->type == CPP_WSTRING || token->type == CPP_WCHAR
379 || token->type == CPP_STRING32 || token->type == CPP_CHAR32 381 || token->type == CPP_STRING32 || token->type == CPP_CHAR32
380 » » || token->type == CPP_STRING16 || token->type == CPP_CHAR16); 382 » » || token->type == CPP_STRING16 || token->type == CPP_CHAR16
383 » » || token->type == CPP_UTF8STRING);
381 384
382 /* Room for each char being written in octal, initial space and 385 /* Room for each char being written in octal, initial space and
383 final quote and NUL. */ 386 final quote and NUL. */
384 len = cpp_token_len (token); 387 len = cpp_token_len (token);
385 if (escape_it) 388 if (escape_it)
386 len *= 4; 389 len *= 4;
387 len += 3; 390 len += 3;
388 391
389 if ((size_t) (BUFF_LIMIT (pfile->u_buff) - dest) < len) 392 if ((size_t) (BUFF_LIMIT (pfile->u_buff) - dest) < len)
390 { 393 {
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 up more than one token when expanding macros is in general 796 up more than one token when expanding macros is in general
794 too difficult. We re-insert it in its own context. */ 797 too difficult. We re-insert it in its own context. */
795 _cpp_backup_tokens (pfile, 1); 798 _cpp_backup_tokens (pfile, 1);
796 if (padding) 799 if (padding)
797 _cpp_push_token_context (pfile, NULL, padding, 1); 800 _cpp_push_token_context (pfile, NULL, padding, 1);
798 } 801 }
799 802
800 return NULL; 803 return NULL;
801 } 804 }
802 805
806 /* Return the real number of tokens in the expansion of MACRO. */
807 static inline unsigned int
808 macro_real_token_count (const cpp_macro *macro)
809 {
810 unsigned int i;
811 if (__builtin_expect (!macro->extra_tokens, true))
812 return macro->count;
813 for (i = 0; i < macro->count; i++)
814 if (macro->exp.tokens[i].type == CPP_PASTE)
815 return i;
816 abort ();
817 }
818
803 /* Push the context of a macro with hash entry NODE onto the context 819 /* Push the context of a macro with hash entry NODE onto the context
804 stack. If we can successfully expand the macro, we push a context 820 stack. If we can successfully expand the macro, we push a context
805 containing its yet-to-be-rescanned replacement list and return one. 821 containing its yet-to-be-rescanned replacement list and return one.
806 If there were additionally any unexpanded deferred #pragma directives 822 If there were additionally any unexpanded deferred #pragma directives
807 among macro arguments, push another context containing the 823 among macro arguments, push another context containing the
808 pragma tokens before the yet-to-be-rescanned replacement list 824 pragma tokens before the yet-to-be-rescanned replacement list
809 and return two. Otherwise, we don't push a context and return zero. */ 825 and return two. Otherwise, we don't push a context and return zero. */
810 static int 826 static int
811 enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, 827 enter_macro_context (cpp_reader *pfile, cpp_hashnode *node,
812 const cpp_token *result) 828 const cpp_token *result)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 /* Disable the macro within its expansion. */ 878 /* Disable the macro within its expansion. */
863 node->flags |= NODE_DISABLED; 879 node->flags |= NODE_DISABLED;
864 880
865 if (!(node->flags & NODE_USED)) 881 if (!(node->flags & NODE_USED))
866 { 882 {
867 node->flags |= NODE_USED; 883 node->flags |= NODE_USED;
868 if (pfile->cb.used_define) 884 if (pfile->cb.used_define)
869 pfile->cb.used_define (pfile, pfile->directive_line, node); 885 pfile->cb.used_define (pfile, pfile->directive_line, node);
870 } 886 }
871 887
888 if (pfile->cb.used)
889 pfile->cb.used (pfile, result->src_loc, node);
890
872 macro->used = 1; 891 macro->used = 1;
873 892
874 if (macro->paramc == 0) 893 if (macro->paramc == 0)
875 » _cpp_push_token_context (pfile, node, macro->exp.tokens, macro->count); 894 » _cpp_push_token_context (pfile, node, macro->exp.tokens,
895 » » » » macro_real_token_count (macro));
876 896
877 if (pragma_buff) 897 if (pragma_buff)
878 { 898 {
879 if (!pfile->state.in_directive) 899 if (!pfile->state.in_directive)
880 _cpp_push_token_context (pfile, NULL, 900 _cpp_push_token_context (pfile, NULL,
881 padding_token (pfile, result), 1); 901 padding_token (pfile, result), 1);
882 do 902 do
883 { 903 {
884 _cpp_buff *tail = pragma_buff->next; 904 _cpp_buff *tail = pragma_buff->next;
885 pragma_buff->next = NULL; 905 pragma_buff->next = NULL;
(...skipping 19 matching lines...) Expand all
905 Expand each argument before replacing, unless it is operated upon 925 Expand each argument before replacing, unless it is operated upon
906 by the # or ## operators. */ 926 by the # or ## operators. */
907 static void 927 static void
908 replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg *args) 928 replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg *args)
909 { 929 {
910 unsigned int i, total; 930 unsigned int i, total;
911 const cpp_token *src, *limit; 931 const cpp_token *src, *limit;
912 const cpp_token **dest, **first; 932 const cpp_token **dest, **first;
913 macro_arg *arg; 933 macro_arg *arg;
914 _cpp_buff *buff; 934 _cpp_buff *buff;
935 unsigned int count;
915 936
916 /* First, fully macro-expand arguments, calculating the number of 937 /* First, fully macro-expand arguments, calculating the number of
917 tokens in the final expansion as we go. The ordering of the if 938 tokens in the final expansion as we go. The ordering of the if
918 statements below is subtle; we must handle stringification before 939 statements below is subtle; we must handle stringification before
919 pasting. */ 940 pasting. */
920 total = macro->count; 941 count = macro_real_token_count (macro);
921 limit = macro->exp.tokens + macro->count; 942 total = count;
943 limit = macro->exp.tokens + count;
922 944
923 for (src = macro->exp.tokens; src < limit; src++) 945 for (src = macro->exp.tokens; src < limit; src++)
924 if (src->type == CPP_MACRO_ARG) 946 if (src->type == CPP_MACRO_ARG)
925 { 947 {
926 /* Leading and trailing padding tokens. */ 948 /* Leading and trailing padding tokens. */
927 total += 2; 949 total += 2;
928 950
929 /* We have an argument. If it is not being stringified or 951 /* We have an argument. If it is not being stringified or
930 pasted it is macro-replaced before insertion. */ 952 pasted it is macro-replaced before insertion. */
931 » arg = &args[src->val.arg_no - 1]; 953 » arg = &args[src->val.macro_arg.arg_no - 1];
932 954
933 if (src->flags & STRINGIFY_ARG) 955 if (src->flags & STRINGIFY_ARG)
934 { 956 {
935 if (!arg->stringified) 957 if (!arg->stringified)
936 arg->stringified = stringify_arg (pfile, arg); 958 arg->stringified = stringify_arg (pfile, arg);
937 } 959 }
938 else if ((src->flags & PASTE_LEFT) 960 else if ((src->flags & PASTE_LEFT)
939 || (src > macro->exp.tokens && (src[-1].flags & PASTE_LEFT))) 961 || (src > macro->exp.tokens && (src[-1].flags & PASTE_LEFT)))
940 total += arg->count - 1; 962 total += arg->count - 1;
941 else 963 else
(...skipping 15 matching lines...) Expand all
957 unsigned int count; 979 unsigned int count;
958 const cpp_token **from, **paste_flag; 980 const cpp_token **from, **paste_flag;
959 981
960 if (src->type != CPP_MACRO_ARG) 982 if (src->type != CPP_MACRO_ARG)
961 { 983 {
962 *dest++ = src; 984 *dest++ = src;
963 continue; 985 continue;
964 } 986 }
965 987
966 paste_flag = 0; 988 paste_flag = 0;
967 arg = &args[src->val.arg_no - 1]; 989 arg = &args[src->val.macro_arg.arg_no - 1];
968 if (src->flags & STRINGIFY_ARG) 990 if (src->flags & STRINGIFY_ARG)
969 count = 1, from = &arg->stringified; 991 count = 1, from = &arg->stringified;
970 else if (src->flags & PASTE_LEFT) 992 else if (src->flags & PASTE_LEFT)
971 count = arg->count, from = arg->first; 993 count = arg->count, from = arg->first;
972 else if (src != macro->exp.tokens && (src[-1].flags & PASTE_LEFT)) 994 else if (src != macro->exp.tokens && (src[-1].flags & PASTE_LEFT))
973 { 995 {
974 count = arg->count, from = arg->first; 996 count = arg->count, from = arg->first;
975 if (dest != first) 997 if (dest != first)
976 { 998 {
977 if (dest[-1]->type == CPP_COMMA 999 if (dest[-1]->type == CPP_COMMA
978 && macro->variadic 1000 && macro->variadic
979 » » && src->val.arg_no == macro->paramc) 1001 » » && src->val.macro_arg.arg_no == macro->paramc)
980 { 1002 {
981 /* Swallow a pasted comma if from == NULL, otherwise 1003 /* Swallow a pasted comma if from == NULL, otherwise
982 drop the paste flag. */ 1004 drop the paste flag. */
983 if (from == NULL) 1005 if (from == NULL)
984 dest--; 1006 dest--;
985 else 1007 else
986 paste_flag = dest - 1; 1008 paste_flag = dest - 1;
987 } 1009 }
988 /* Remove the paste flag if the RHS is a placemarker. */ 1010 /* Remove the paste flag if the RHS is a placemarker. */
989 else if (count == 0) 1011 else if (count == 0)
(...skipping 20 matching lines...) Expand all
1010 } 1032 }
1011 else if (CPP_PEDANTIC (pfile) && ! macro->syshdr 1033 else if (CPP_PEDANTIC (pfile) && ! macro->syshdr
1012 && ! CPP_OPTION (pfile, c99) 1034 && ! CPP_OPTION (pfile, c99)
1013 && ! cpp_in_system_header (pfile)) 1035 && ! cpp_in_system_header (pfile))
1014 { 1036 {
1015 cpp_error (pfile, CPP_DL_PEDWARN, 1037 cpp_error (pfile, CPP_DL_PEDWARN,
1016 "invoking macro %s argument %d: " 1038 "invoking macro %s argument %d: "
1017 "empty macro arguments are undefined" 1039 "empty macro arguments are undefined"
1018 " in ISO C90 and ISO C++98", 1040 " in ISO C90 and ISO C++98",
1019 NODE_NAME (node), 1041 NODE_NAME (node),
1020 » » src->val.arg_no); 1042 » » src->val.macro_arg.arg_no);
1021 } 1043 }
1022 1044
1023 /* Avoid paste on RHS (even case count == 0). */ 1045 /* Avoid paste on RHS (even case count == 0). */
1024 if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT)) 1046 if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT))
1025 *dest++ = &pfile->avoid_paste; 1047 *dest++ = &pfile->avoid_paste;
1026 1048
1027 /* Add a new paste flag, or remove an unwanted one. */ 1049 /* Add a new paste flag, or remove an unwanted one. */
1028 if (paste_flag) 1050 if (paste_flag)
1029 { 1051 {
1030 cpp_token *token = _cpp_temp_token (pfile); 1052 cpp_token *token = _cpp_temp_token (pfile);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 continue; 1258 continue;
1237 return &pfile->avoid_paste; 1259 return &pfile->avoid_paste;
1238 } 1260 }
1239 1261
1240 if (pfile->state.in_directive && result->type == CPP_COMMENT) 1262 if (pfile->state.in_directive && result->type == CPP_COMMENT)
1241 continue; 1263 continue;
1242 1264
1243 if (result->type != CPP_NAME) 1265 if (result->type != CPP_NAME)
1244 break; 1266 break;
1245 1267
1246 node = result->val.node; 1268 node = result->val.node.node;
1247 1269
1248 if (node->type != NT_MACRO || (result->flags & NO_EXPAND)) 1270 if (node->type != NT_MACRO || (result->flags & NO_EXPAND))
1249 break; 1271 break;
1250 1272
1251 if (!(node->flags & NODE_DISABLED)) 1273 if (!(node->flags & NODE_DISABLED))
1252 { 1274 {
1253 int ret = 0; 1275 int ret = 0;
1254 /* If not in a macro context, and we're going to start an 1276 /* If not in a macro context, and we're going to start an
1255 expansion, record the location. */ 1277 expansion, record the location. */
1256 if (can_set && !context->macro) 1278 if (can_set && !context->macro)
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 1550
1529 case CPP_NAME: 1551 case CPP_NAME:
1530 if (prev_ident) 1552 if (prev_ident)
1531 { 1553 {
1532 cpp_error (pfile, CPP_DL_ERROR, 1554 cpp_error (pfile, CPP_DL_ERROR,
1533 "macro parameters must be comma-separated"); 1555 "macro parameters must be comma-separated");
1534 return false; 1556 return false;
1535 } 1557 }
1536 prev_ident = 1; 1558 prev_ident = 1;
1537 1559
1538 » if (_cpp_save_parameter (pfile, macro, token->val.node)) 1560 » if (_cpp_save_parameter (pfile, macro, token->val.node.node))
1539 return false; 1561 return false;
1540 continue; 1562 continue;
1541 1563
1542 case CPP_CLOSE_PAREN: 1564 case CPP_CLOSE_PAREN:
1543 if (prev_ident || macro->paramc == 0) 1565 if (prev_ident || macro->paramc == 0)
1544 return true; 1566 return true;
1545 1567
1546 /* Fall through to pick up the error. */ 1568 /* Fall through to pick up the error. */
1547 case CPP_COMMA: 1569 case CPP_COMMA:
1548 if (!prev_ident) 1570 if (!prev_ident)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 { 1623 {
1602 cpp_token *token, *saved_cur_token; 1624 cpp_token *token, *saved_cur_token;
1603 1625
1604 saved_cur_token = pfile->cur_token; 1626 saved_cur_token = pfile->cur_token;
1605 pfile->cur_token = alloc_expansion_token (pfile, macro); 1627 pfile->cur_token = alloc_expansion_token (pfile, macro);
1606 token = _cpp_lex_direct (pfile); 1628 token = _cpp_lex_direct (pfile);
1607 pfile->cur_token = saved_cur_token; 1629 pfile->cur_token = saved_cur_token;
1608 1630
1609 /* Is this a parameter? */ 1631 /* Is this a parameter? */
1610 if (token->type == CPP_NAME 1632 if (token->type == CPP_NAME
1611 && (token->val.node->flags & NODE_MACRO_ARG) != 0) 1633 && (token->val.node.node->flags & NODE_MACRO_ARG) != 0)
1612 { 1634 {
1613 token->type = CPP_MACRO_ARG; 1635 token->type = CPP_MACRO_ARG;
1614 token->val.arg_no = token->val.node->value.arg_index; 1636 token->val.macro_arg.arg_no = token->val.node.node->value.arg_index;
1615 } 1637 }
1616 else if (CPP_WTRADITIONAL (pfile) && macro->paramc > 0 1638 else if (CPP_WTRADITIONAL (pfile) && macro->paramc > 0
1617 && (token->type == CPP_STRING || token->type == CPP_CHAR)) 1639 && (token->type == CPP_STRING || token->type == CPP_CHAR))
1618 check_trad_stringification (pfile, macro, &token->val.str); 1640 check_trad_stringification (pfile, macro, &token->val.str);
1619 1641
1620 return token; 1642 return token;
1621 } 1643 }
1622 1644
1623 static bool 1645 static bool
1624 create_iso_definition (cpp_reader *pfile, cpp_macro *macro) 1646 create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
1625 { 1647 {
1626 cpp_token *token; 1648 cpp_token *token;
1627 const cpp_token *ctoken; 1649 const cpp_token *ctoken;
1628 bool following_paste_op = false; 1650 bool following_paste_op = false;
1629 const char *paste_op_error_msg = 1651 const char *paste_op_error_msg =
1630 N_("'##' cannot appear at either end of a macro expansion"); 1652 N_("'##' cannot appear at either end of a macro expansion");
1653 unsigned int num_extra_tokens = 0;
1631 1654
1632 /* Get the first token of the expansion (or the '(' of a 1655 /* Get the first token of the expansion (or the '(' of a
1633 function-like macro). */ 1656 function-like macro). */
1634 ctoken = _cpp_lex_token (pfile); 1657 ctoken = _cpp_lex_token (pfile);
1635 1658
1636 if (ctoken->type == CPP_OPEN_PAREN && !(ctoken->flags & PREV_WHITE)) 1659 if (ctoken->type == CPP_OPEN_PAREN && !(ctoken->flags & PREV_WHITE))
1637 { 1660 {
1638 bool ok = parse_params (pfile, macro); 1661 bool ok = parse_params (pfile, macro);
1639 macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff); 1662 macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff);
1640 if (!ok) 1663 if (!ok)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 } 1721 }
1699 1722
1700 for (;;) 1723 for (;;)
1701 { 1724 {
1702 /* Check the stringifying # constraint 6.10.3.2.1 of 1725 /* Check the stringifying # constraint 6.10.3.2.1 of
1703 function-like macros when lexing the subsequent token. */ 1726 function-like macros when lexing the subsequent token. */
1704 if (macro->count > 1 && token[-1].type == CPP_HASH && macro->fun_like) 1727 if (macro->count > 1 && token[-1].type == CPP_HASH && macro->fun_like)
1705 { 1728 {
1706 if (token->type == CPP_MACRO_ARG) 1729 if (token->type == CPP_MACRO_ARG)
1707 { 1730 {
1731 if (token->flags & PREV_WHITE)
1732 token->flags |= SP_PREV_WHITE;
1733 if (token[-1].flags & DIGRAPH)
1734 token->flags |= SP_DIGRAPH;
1708 token->flags &= ~PREV_WHITE; 1735 token->flags &= ~PREV_WHITE;
1709 token->flags |= STRINGIFY_ARG; 1736 token->flags |= STRINGIFY_ARG;
1710 token->flags |= token[-1].flags & PREV_WHITE; 1737 token->flags |= token[-1].flags & PREV_WHITE;
1711 token[-1] = token[0]; 1738 token[-1] = token[0];
1712 macro->count--; 1739 macro->count--;
1713 } 1740 }
1714 /* Let assembler get away with murder. */ 1741 /* Let assembler get away with murder. */
1715 else if (CPP_OPTION (pfile, lang) != CLK_ASM) 1742 else if (CPP_OPTION (pfile, lang) != CLK_ASM)
1716 { 1743 {
1717 cpp_error (pfile, CPP_DL_ERROR, 1744 cpp_error (pfile, CPP_DL_ERROR,
(...skipping 19 matching lines...) Expand all
1737 if (token->type == CPP_PASTE) 1764 if (token->type == CPP_PASTE)
1738 { 1765 {
1739 /* Token-paste ##, can appear in both object-like and 1766 /* Token-paste ##, can appear in both object-like and
1740 function-like macros, but not at the beginning. */ 1767 function-like macros, but not at the beginning. */
1741 if (macro->count == 1) 1768 if (macro->count == 1)
1742 { 1769 {
1743 cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg); 1770 cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg);
1744 return false; 1771 return false;
1745 } 1772 }
1746 1773
1747 » --macro->count; 1774 » if (token[-1].flags & PASTE_LEFT)
1748 » token[-1].flags |= PASTE_LEFT; 1775 » {
1776 » macro->extra_tokens = 1;
1777 » num_extra_tokens++;
1778 » token->val.token_no = macro->count - 1;
1779 » }
1780 » else
1781 » {
1782 » --macro->count;
1783 » token[-1].flags |= PASTE_LEFT;
1784 » if (token->flags & DIGRAPH)
1785 » » token[-1].flags |= SP_DIGRAPH;
1786 » if (token->flags & PREV_WHITE)
1787 » » token[-1].flags |= SP_PREV_WHITE;
1788 » }
1749 } 1789 }
1750 1790
1751 following_paste_op = (token->type == CPP_PASTE); 1791 following_paste_op = (token->type == CPP_PASTE);
1752 token = lex_expansion_token (pfile, macro); 1792 token = lex_expansion_token (pfile, macro);
1753 } 1793 }
1754 1794
1755 macro->exp.tokens = (cpp_token *) BUFF_FRONT (pfile->a_buff); 1795 macro->exp.tokens = (cpp_token *) BUFF_FRONT (pfile->a_buff);
1756 macro->traditional = 0; 1796 macro->traditional = 0;
1757 1797
1758 /* Don't count the CPP_EOF. */ 1798 /* Don't count the CPP_EOF. */
1759 macro->count--; 1799 macro->count--;
1760 1800
1761 /* Clear whitespace on first token for warn_of_redefinition(). */ 1801 /* Clear whitespace on first token for warn_of_redefinition(). */
1762 if (macro->count) 1802 if (macro->count)
1763 macro->exp.tokens[0].flags &= ~PREV_WHITE; 1803 macro->exp.tokens[0].flags &= ~PREV_WHITE;
1764 1804
1765 /* Commit or allocate the memory. */ 1805 /* Commit or allocate the memory. */
1766 if (pfile->hash_table->alloc_subobject) 1806 if (pfile->hash_table->alloc_subobject)
1767 { 1807 {
1768 cpp_token *tokns = 1808 cpp_token *tokns =
1769 (cpp_token *) pfile->hash_table->alloc_subobject (sizeof (cpp_token) 1809 (cpp_token *) pfile->hash_table->alloc_subobject (sizeof (cpp_token)
1770 * macro->count); 1810 * macro->count);
1771 memcpy (tokns, macro->exp.tokens, sizeof (cpp_token) * macro->count); 1811 if (num_extra_tokens)
1812 » {
1813 » /* Place second and subsequent ## or %:%: tokens in
1814 » sequences of consecutive such tokens at the end of the
1815 » list to preserve information about where they appear, how
1816 » they are spelt and whether they are preceded by
1817 » whitespace without otherwise interfering with macro
1818 » expansion. */
1819 » cpp_token *normal_dest = tokns;
1820 » cpp_token *extra_dest = tokns + macro->count - num_extra_tokens;
1821 » unsigned int i;
1822 » for (i = 0; i < macro->count; i++)
1823 » {
1824 » if (macro->exp.tokens[i].type == CPP_PASTE)
1825 » » *extra_dest++ = macro->exp.tokens[i];
1826 » else
1827 » » *normal_dest++ = macro->exp.tokens[i];
1828 » }
1829 » }
1830 else
1831 » memcpy (tokns, macro->exp.tokens, sizeof (cpp_token) * macro->count);
1772 macro->exp.tokens = tokns; 1832 macro->exp.tokens = tokns;
1773 } 1833 }
1774 else 1834 else
1775 BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->exp.tokens[macro->count]; 1835 BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->exp.tokens[macro->count];
1776 1836
1777 return true; 1837 return true;
1778 } 1838 }
1779 1839
1780 /* Parse a macro and save its expansion. Returns nonzero on success. */ 1840 /* Parse a macro and save its expansion. Returns nonzero on success. */
1781 bool 1841 bool
1782 _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node) 1842 _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
1783 { 1843 {
1784 cpp_macro *macro; 1844 cpp_macro *macro;
1785 unsigned int i; 1845 unsigned int i;
1786 bool ok; 1846 bool ok;
1787 1847
1788 if (pfile->hash_table->alloc_subobject) 1848 if (pfile->hash_table->alloc_subobject)
1789 macro = (cpp_macro *) pfile->hash_table->alloc_subobject 1849 macro = (cpp_macro *) pfile->hash_table->alloc_subobject
1790 (sizeof (cpp_macro)); 1850 (sizeof (cpp_macro));
1791 else 1851 else
1792 macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro)); 1852 macro = (cpp_macro *) _cpp_aligned_alloc (pfile, sizeof (cpp_macro));
1793 macro->line = pfile->directive_line; 1853 macro->line = pfile->directive_line;
1794 macro->params = 0; 1854 macro->params = 0;
1795 macro->paramc = 0; 1855 macro->paramc = 0;
1796 macro->variadic = 0; 1856 macro->variadic = 0;
1797 macro->used = !CPP_OPTION (pfile, warn_unused_macros); 1857 macro->used = !CPP_OPTION (pfile, warn_unused_macros);
1798 macro->count = 0; 1858 macro->count = 0;
1799 macro->fun_like = 0; 1859 macro->fun_like = 0;
1860 macro->extra_tokens = 0;
1800 /* To suppress some diagnostics. */ 1861 /* To suppress some diagnostics. */
1801 macro->syshdr = pfile->buffer && pfile->buffer->sysp != 0; 1862 macro->syshdr = pfile->buffer && pfile->buffer->sysp != 0;
1802 1863
1803 if (CPP_OPTION (pfile, traditional)) 1864 if (CPP_OPTION (pfile, traditional))
1804 ok = _cpp_create_trad_definition (pfile, macro); 1865 ok = _cpp_create_trad_definition (pfile, macro);
1805 else 1866 else
1806 { 1867 {
1807 ok = create_iso_definition (pfile, macro); 1868 ok = create_iso_definition (pfile, macro);
1808 1869
1809 /* We set the type for SEEN_EOL() in directives.c. 1870 /* We set the type for SEEN_EOL() in directives.c.
(...skipping 16 matching lines...) Expand all
1826 if (!ok) 1887 if (!ok)
1827 return ok; 1888 return ok;
1828 1889
1829 if (node->type == NT_MACRO) 1890 if (node->type == NT_MACRO)
1830 { 1891 {
1831 if (CPP_OPTION (pfile, warn_unused_macros)) 1892 if (CPP_OPTION (pfile, warn_unused_macros))
1832 _cpp_warn_if_unused_macro (pfile, node, NULL); 1893 _cpp_warn_if_unused_macro (pfile, node, NULL);
1833 1894
1834 if (warn_of_redefinition (pfile, node, macro)) 1895 if (warn_of_redefinition (pfile, node, macro))
1835 { 1896 {
1836 » cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->directive_line, 0, 1897 » bool warned;
1837 » » » "\"%s\" redefined", NODE_NAME (node)); 1898 » warned = cpp_error_with_line (pfile, CPP_DL_PEDWARN,
1899 » » » » » pfile->directive_line, 0,
1900 » » » » » "\"%s\" redefined", NODE_NAME (node));
1838 1901
1839 » if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN)) 1902 » if (warned && node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
1840 » cpp_error_with_line (pfile, CPP_DL_PEDWARN, 1903 » cpp_error_with_line (pfile, CPP_DL_NOTE,
1841 node->value.macro->line, 0, 1904 node->value.macro->line, 0,
1842 "this is the location of the previous definition"); 1905 "this is the location of the previous definition");
1843 } 1906 }
1844 } 1907 }
1845 1908
1846 if (node->type != NT_VOID) 1909 if (node->type != NT_VOID)
1847 _cpp_free_definition (node); 1910 _cpp_free_definition (node);
1848 1911
1849 /* Enter definition in hash table. */ 1912 /* Enter definition in hash table. */
1850 node->type = NT_MACRO; 1913 node->type = NT_MACRO;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 varargs (we have + 1 below). */ 1998 varargs (we have + 1 below). */
1936 for (i = 0; i < macro->paramc; i++) 1999 for (i = 0; i < macro->paramc; i++)
1937 len += NODE_LEN (macro->params[i]) + 1; /* "," */ 2000 len += NODE_LEN (macro->params[i]) + 1; /* "," */
1938 } 2001 }
1939 2002
1940 /* This should match below where we fill in the buffer. */ 2003 /* This should match below where we fill in the buffer. */
1941 if (CPP_OPTION (pfile, traditional)) 2004 if (CPP_OPTION (pfile, traditional))
1942 len += _cpp_replacement_text_len (macro); 2005 len += _cpp_replacement_text_len (macro);
1943 else 2006 else
1944 { 2007 {
1945 for (i = 0; i < macro->count; i++) 2008 unsigned int count = macro_real_token_count (macro);
2009 for (i = 0; i < count; i++)
1946 { 2010 {
1947 cpp_token *token = &macro->exp.tokens[i]; 2011 cpp_token *token = &macro->exp.tokens[i];
1948 2012
1949 if (token->type == CPP_MACRO_ARG) 2013 if (token->type == CPP_MACRO_ARG)
1950 » len += NODE_LEN (macro->params[token->val.arg_no - 1]); 2014 » len += NODE_LEN (macro->params[token->val.macro_arg.arg_no - 1]);
1951 else 2015 else
1952 len += cpp_token_len (token); 2016 len += cpp_token_len (token);
1953 2017
1954 if (token->flags & STRINGIFY_ARG) 2018 if (token->flags & STRINGIFY_ARG)
1955 len++; /* "#" */ 2019 len++; /* "#" */
1956 if (token->flags & PASTE_LEFT) 2020 if (token->flags & PASTE_LEFT)
1957 len += 3; /* " ##" */ 2021 len += 3; /* " ##" */
1958 if (token->flags & PREV_WHITE) 2022 if (token->flags & PREV_WHITE)
1959 len++; /* " " */ 2023 len++; /* " " */
1960 } 2024 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1999 2063
2000 /* The Dwarf spec requires a space after the macro name, even if the 2064 /* The Dwarf spec requires a space after the macro name, even if the
2001 definition is the empty string. */ 2065 definition is the empty string. */
2002 *buffer++ = ' '; 2066 *buffer++ = ' ';
2003 2067
2004 if (CPP_OPTION (pfile, traditional)) 2068 if (CPP_OPTION (pfile, traditional))
2005 buffer = _cpp_copy_replacement_text (macro, buffer); 2069 buffer = _cpp_copy_replacement_text (macro, buffer);
2006 else if (macro->count) 2070 else if (macro->count)
2007 /* Expansion tokens. */ 2071 /* Expansion tokens. */
2008 { 2072 {
2009 for (i = 0; i < macro->count; i++) 2073 unsigned int count = macro_real_token_count (macro);
2074 for (i = 0; i < count; i++)
2010 { 2075 {
2011 cpp_token *token = &macro->exp.tokens[i]; 2076 cpp_token *token = &macro->exp.tokens[i];
2012 2077
2013 if (token->flags & PREV_WHITE) 2078 if (token->flags & PREV_WHITE)
2014 *buffer++ = ' '; 2079 *buffer++ = ' ';
2015 if (token->flags & STRINGIFY_ARG) 2080 if (token->flags & STRINGIFY_ARG)
2016 *buffer++ = '#'; 2081 *buffer++ = '#';
2017 2082
2018 if (token->type == CPP_MACRO_ARG) 2083 if (token->type == CPP_MACRO_ARG)
2019 { 2084 {
2020 memcpy (buffer, 2085 memcpy (buffer,
2021 » » NODE_NAME (macro->params[token->val.arg_no - 1]), 2086 » » NODE_NAME (macro->params[token->val.macro_arg.arg_no - 1]) ,
2022 » » NODE_LEN (macro->params[token->val.arg_no - 1])); 2087 » » NODE_LEN (macro->params[token->val.macro_arg.arg_no - 1])) ;
2023 » buffer += NODE_LEN (macro->params[token->val.arg_no - 1]); 2088 » buffer += NODE_LEN (macro->params[token->val.macro_arg.arg_no - 1] );
2024 } 2089 }
2025 else 2090 else
2026 buffer = cpp_spell_token (pfile, token, buffer, false); 2091 buffer = cpp_spell_token (pfile, token, buffer, false);
2027 2092
2028 if (token->flags & PASTE_LEFT) 2093 if (token->flags & PASTE_LEFT)
2029 { 2094 {
2030 *buffer++ = ' '; 2095 *buffer++ = ' ';
2031 *buffer++ = '#'; 2096 *buffer++ = '#';
2032 *buffer++ = '#'; 2097 *buffer++ = '#';
2033 /* Next has PREV_WHITE; see _cpp_create_definition. */ 2098 /* Next has PREV_WHITE; see _cpp_create_definition. */
2034 } 2099 }
2035 } 2100 }
2036 } 2101 }
2037 2102
2038 *buffer = '\0'; 2103 *buffer = '\0';
2039 return pfile->macro_buffer; 2104 return pfile->macro_buffer;
2040 } 2105 }
OLDNEW
« no previous file with comments | « gcc/libcpp/line-map.c ('k') | gcc/libcpp/makedepend.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698