comparison libcpp/macro.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
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, 2010 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
63 63
64 /* #define directive parsing and handling. */ 64 /* #define directive parsing and handling. */
65 65
66 static cpp_token *alloc_expansion_token (cpp_reader *, cpp_macro *); 66 static cpp_token *alloc_expansion_token (cpp_reader *, cpp_macro *);
67 static cpp_token *lex_expansion_token (cpp_reader *, cpp_macro *); 67 static cpp_token *lex_expansion_token (cpp_reader *, cpp_macro *);
68 static bool warn_of_redefinition (cpp_reader *, const cpp_hashnode *, 68 static bool warn_of_redefinition (cpp_reader *, cpp_hashnode *,
69 const cpp_macro *); 69 const cpp_macro *);
70 static bool parse_params (cpp_reader *, cpp_macro *); 70 static bool parse_params (cpp_reader *, cpp_macro *);
71 static void check_trad_stringification (cpp_reader *, const cpp_macro *, 71 static void check_trad_stringification (cpp_reader *, const cpp_macro *,
72 const cpp_string *); 72 const cpp_string *);
73 73
833 pfile->state.angled_headers = false; 833 pfile->state.angled_headers = false;
834 834
835 if ((node->flags & NODE_BUILTIN) && !(node->flags & NODE_USED)) 835 if ((node->flags & NODE_BUILTIN) && !(node->flags & NODE_USED))
836 { 836 {
837 node->flags |= NODE_USED; 837 node->flags |= NODE_USED;
838 if (pfile->cb.used_define) 838 if ((!pfile->cb.user_builtin_macro
839 || !pfile->cb.user_builtin_macro (pfile, node))
840 && pfile->cb.used_define)
839 pfile->cb.used_define (pfile, pfile->directive_line, node); 841 pfile->cb.used_define (pfile, pfile->directive_line, node);
840 } 842 }
841 843
842 /* Handle standard macros. */ 844 /* Handle standard macros. */
843 if (! (node->flags & NODE_BUILTIN)) 845 if (! (node->flags & NODE_BUILTIN))
1428 1430
1429 /* #define directive parsing and handling. */ 1431 /* #define directive parsing and handling. */
1430 1432
1431 /* Returns nonzero if a macro redefinition warning is required. */ 1433 /* Returns nonzero if a macro redefinition warning is required. */
1432 static bool 1434 static bool
1433 warn_of_redefinition (cpp_reader *pfile, const cpp_hashnode *node, 1435 warn_of_redefinition (cpp_reader *pfile, cpp_hashnode *node,
1434 const cpp_macro *macro2) 1436 const cpp_macro *macro2)
1435 { 1437 {
1436 const cpp_macro *macro1; 1438 const cpp_macro *macro1;
1437 unsigned int i; 1439 unsigned int i;
1438 1440
1440 if (node->flags & NODE_WARN) 1442 if (node->flags & NODE_WARN)
1441 return true; 1443 return true;
1442 1444
1443 /* Suppress warnings for builtins that lack the NODE_WARN flag. */ 1445 /* Suppress warnings for builtins that lack the NODE_WARN flag. */
1444 if (node->flags & NODE_BUILTIN) 1446 if (node->flags & NODE_BUILTIN)
1445 return false; 1447 {
1448 if (!pfile->cb.user_builtin_macro
1449 || !pfile->cb.user_builtin_macro (pfile, node))
1450 return false;
1451 }
1446 1452
1447 /* Redefinitions of conditional (context-sensitive) macros, on 1453 /* Redefinitions of conditional (context-sensitive) macros, on
1448 the other hand, must be allowed silently. */ 1454 the other hand, must be allowed silently. */
1449 if (node->flags & NODE_CONDITIONAL) 1455 if (node->flags & NODE_CONDITIONAL)
1450 return false; 1456 return false;
1581 { 1587 {
1582 _cpp_save_parameter (pfile, macro, 1588 _cpp_save_parameter (pfile, macro,
1583 pfile->spec_nodes.n__VA_ARGS__); 1589 pfile->spec_nodes.n__VA_ARGS__);
1584 pfile->state.va_args_ok = 1; 1590 pfile->state.va_args_ok = 1;
1585 if (! CPP_OPTION (pfile, c99) 1591 if (! CPP_OPTION (pfile, c99)
1586 && CPP_OPTION (pfile, pedantic) 1592 && CPP_OPTION (pfile, cpp_pedantic)
1587 && CPP_OPTION (pfile, warn_variadic_macros)) 1593 && CPP_OPTION (pfile, warn_variadic_macros))
1588 cpp_pedwarning 1594 cpp_pedwarning
1589 (pfile, CPP_W_VARIADIC_MACROS, 1595 (pfile, CPP_W_VARIADIC_MACROS,
1590 "anonymous variadic macros were introduced in C99"); 1596 "anonymous variadic macros were introduced in C99");
1591 } 1597 }
1592 else if (CPP_OPTION (pfile, pedantic) 1598 else if (CPP_OPTION (pfile, cpp_pedantic)
1593 && CPP_OPTION (pfile, warn_variadic_macros)) 1599 && CPP_OPTION (pfile, warn_variadic_macros))
1594 cpp_pedwarning (pfile, CPP_W_VARIADIC_MACROS, 1600 cpp_pedwarning (pfile, CPP_W_VARIADIC_MACROS,
1595 "ISO C does not permit named variadic macros"); 1601 "ISO C does not permit named variadic macros");
1596 1602
1597 /* We're at the end, and just expect a closing parenthesis. */ 1603 /* We're at the end, and just expect a closing parenthesis. */
1980 suitable to be read back in again, and therefore also for DWARF 2 1986 suitable to be read back in again, and therefore also for DWARF 2
1981 debugging info. e.g. "PASTE(X, Y) X ## Y", or "MACNAME EXPANSION". 1987 debugging info. e.g. "PASTE(X, Y) X ## Y", or "MACNAME EXPANSION".
1982 Caller is expected to generate the "#define" bit if needed. The 1988 Caller is expected to generate the "#define" bit if needed. The
1983 returned text is temporary, and automatically freed later. */ 1989 returned text is temporary, and automatically freed later. */
1984 const unsigned char * 1990 const unsigned char *
1985 cpp_macro_definition (cpp_reader *pfile, const cpp_hashnode *node) 1991 cpp_macro_definition (cpp_reader *pfile, cpp_hashnode *node)
1986 { 1992 {
1987 unsigned int i, len; 1993 unsigned int i, len;
1988 const cpp_macro *macro = node->value.macro; 1994 const cpp_macro *macro;
1989 unsigned char *buffer; 1995 unsigned char *buffer;
1990 1996
1991 if (node->type != NT_MACRO || (node->flags & NODE_BUILTIN)) 1997 if (node->type != NT_MACRO || (node->flags & NODE_BUILTIN))
1992 { 1998 {
1993 cpp_error (pfile, CPP_DL_ICE, 1999 if (node->type != NT_MACRO
1994 "invalid hash type %d in cpp_macro_definition", node->type); 2000 || !pfile->cb.user_builtin_macro
1995 return 0; 2001 || !pfile->cb.user_builtin_macro (pfile, node))
1996 } 2002 {
1997 2003 cpp_error (pfile, CPP_DL_ICE,
2004 "invalid hash type %d in cpp_macro_definition",
2005 node->type);
2006 return 0;
2007 }
2008 }
2009
2010 macro = node->value.macro;
1998 /* Calculate length. */ 2011 /* Calculate length. */
1999 len = NODE_LEN (node) + 2; /* ' ' and NUL. */ 2012 len = NODE_LEN (node) + 2; /* ' ' and NUL. */
2000 if (macro->fun_like) 2013 if (macro->fun_like)
2001 { 2014 {
2002 len += 4; /* "()" plus possible final ".." of named 2015 len += 4; /* "()" plus possible final ".." of named