macro.c (259405) | macro.c (259890) |
---|---|
1/* Part of CPP library. (Macro and #define handling.) 2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998, | 1/* Part of CPP library. (Macro and #define handling.) 2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998, |
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | 3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 4 2006 Free Software Foundation, Inc. |
4 Written by Per Bothner, 1994. 5 Based on CCCP program by Paul Rubin, June 1986 6 Adapted to ANSI C, Richard Stallman, Jan 1987 7 8This program is free software; you can redistribute it and/or modify it 9under the terms of the GNU General Public License as published by the 10Free Software Foundation; either version 2, or (at your option) any 11later version. --- 421 unchanged lines hidden (view full) --- 433 434/* Try to paste two tokens. On success, return nonzero. In any 435 case, PLHS is updated to point to the pasted token, which is 436 guaranteed to not have the PASTE_LEFT flag set. */ 437static bool 438paste_tokens (cpp_reader *pfile, const cpp_token **plhs, const cpp_token *rhs) 439{ 440 unsigned char *buf, *end, *lhsend; | 5 Written by Per Bothner, 1994. 6 Based on CCCP program by Paul Rubin, June 1986 7 Adapted to ANSI C, Richard Stallman, Jan 1987 8 9This program is free software; you can redistribute it and/or modify it 10under the terms of the GNU General Public License as published by the 11Free Software Foundation; either version 2, or (at your option) any 12later version. --- 421 unchanged lines hidden (view full) --- 434 435/* Try to paste two tokens. On success, return nonzero. In any 436 case, PLHS is updated to point to the pasted token, which is 437 guaranteed to not have the PASTE_LEFT flag set. */ 438static bool 439paste_tokens (cpp_reader *pfile, const cpp_token **plhs, const cpp_token *rhs) 440{ 441 unsigned char *buf, *end, *lhsend; |
441 const cpp_token *lhs; | 442 cpp_token *lhs; |
442 unsigned int len; 443 | 443 unsigned int len; 444 |
444 lhs = *plhs; 445 len = cpp_token_len (lhs) + cpp_token_len (rhs) + 1; | 445 len = cpp_token_len (*plhs) + cpp_token_len (rhs) + 1; |
446 buf = (unsigned char *) alloca (len); | 446 buf = (unsigned char *) alloca (len); |
447 end = lhsend = cpp_spell_token (pfile, lhs, buf, false); | 447 end = lhsend = cpp_spell_token (pfile, *plhs, buf, false); |
448 449 /* Avoid comment headers, since they are still processed in stage 3. 450 It is simpler to insert a space here, rather than modifying the 451 lexer to ignore comments in some circumstances. Simply returning 452 false doesn't work, since we want to clear the PASTE_LEFT flag. */ | 448 449 /* Avoid comment headers, since they are still processed in stage 3. 450 It is simpler to insert a space here, rather than modifying the 451 lexer to ignore comments in some circumstances. Simply returning 452 false doesn't work, since we want to clear the PASTE_LEFT flag. */ |
453 if (lhs->type == CPP_DIV && rhs->type != CPP_EQ) | 453 if ((*plhs)->type == CPP_DIV && rhs->type != CPP_EQ) |
454 *end++ = ' '; 455 end = cpp_spell_token (pfile, rhs, end, false); 456 *end = '\n'; 457 458 cpp_push_buffer (pfile, buf, end - buf, /* from_stage3 */ true); 459 _cpp_clean_line (pfile); 460 461 /* Set pfile->cur_token as required by _cpp_lex_direct. */ 462 pfile->cur_token = _cpp_temp_token (pfile); | 454 *end++ = ' '; 455 end = cpp_spell_token (pfile, rhs, end, false); 456 *end = '\n'; 457 458 cpp_push_buffer (pfile, buf, end - buf, /* from_stage3 */ true); 459 _cpp_clean_line (pfile); 460 461 /* Set pfile->cur_token as required by _cpp_lex_direct. */ 462 pfile->cur_token = _cpp_temp_token (pfile); |
463 *plhs = _cpp_lex_direct (pfile); | 463 lhs = _cpp_lex_direct (pfile); |
464 if (pfile->buffer->cur != pfile->buffer->rlimit) 465 { | 464 if (pfile->buffer->cur != pfile->buffer->rlimit) 465 { |
466 source_location saved_loc = lhs->src_loc; 467 |
|
466 _cpp_pop_buffer (pfile); 467 _cpp_backup_tokens (pfile, 1); 468 *lhsend = '\0'; 469 | 468 _cpp_pop_buffer (pfile); 469 _cpp_backup_tokens (pfile, 1); 470 *lhsend = '\0'; 471 |
472 /* We have to remove the PASTE_LEFT flag from the old lhs, but 473 we want to keep the new location. */ 474 *lhs = **plhs; 475 *plhs = lhs; 476 lhs->src_loc = saved_loc; 477 lhs->flags &= ~PASTE_LEFT; 478 |
|
470 /* Mandatory error for all apart from assembler. */ 471 if (CPP_OPTION (pfile, lang) != CLK_ASM) 472 cpp_error (pfile, CPP_DL_ERROR, 473 "pasting \"%s\" and \"%s\" does not give a valid preprocessing token", 474 buf, cpp_token_as_text (pfile, rhs)); 475 return false; 476 } 477 | 479 /* Mandatory error for all apart from assembler. */ 480 if (CPP_OPTION (pfile, lang) != CLK_ASM) 481 cpp_error (pfile, CPP_DL_ERROR, 482 "pasting \"%s\" and \"%s\" does not give a valid preprocessing token", 483 buf, cpp_token_as_text (pfile, rhs)); 484 return false; 485 } 486 |
487 *plhs = lhs; |
|
478 _cpp_pop_buffer (pfile); 479 return true; 480} 481 482/* Handles an arbitrarily long sequence of ## operators, with initial 483 operand LHS. This implementation is left-associative, 484 non-recursive, and finishes a paste before handling succeeding 485 ones. If a paste fails, we back up to the RHS of the failing ## --- 914 unchanged lines hidden (view full) --- 1400 return &((cpp_token *) BUFF_FRONT (pfile->a_buff))[macro->count++]; 1401} 1402 1403/* Lex a token from the expansion of MACRO, but mark parameters as we 1404 find them and warn of traditional stringification. */ 1405static cpp_token * 1406lex_expansion_token (cpp_reader *pfile, cpp_macro *macro) 1407{ | 488 _cpp_pop_buffer (pfile); 489 return true; 490} 491 492/* Handles an arbitrarily long sequence of ## operators, with initial 493 operand LHS. This implementation is left-associative, 494 non-recursive, and finishes a paste before handling succeeding 495 ones. If a paste fails, we back up to the RHS of the failing ## --- 914 unchanged lines hidden (view full) --- 1410 return &((cpp_token *) BUFF_FRONT (pfile->a_buff))[macro->count++]; 1411} 1412 1413/* Lex a token from the expansion of MACRO, but mark parameters as we 1414 find them and warn of traditional stringification. */ 1415static cpp_token * 1416lex_expansion_token (cpp_reader *pfile, cpp_macro *macro) 1417{ |
1408 cpp_token *token; | 1418 cpp_token *token, *saved_cur_token; |
1409 | 1419 |
1420 saved_cur_token = pfile->cur_token; |
|
1410 pfile->cur_token = alloc_expansion_token (pfile, macro); 1411 token = _cpp_lex_direct (pfile); | 1421 pfile->cur_token = alloc_expansion_token (pfile, macro); 1422 token = _cpp_lex_direct (pfile); |
1423 pfile->cur_token = saved_cur_token; |
|
1412 1413 /* Is this a parameter? */ 1414 if (token->type == CPP_NAME 1415 && (token->val.node->flags & NODE_MACRO_ARG) != 0) 1416 { 1417 token->type = CPP_MACRO_ARG; 1418 token->val.arg_no = token->val.node->value.arg_index; 1419 } --- 172 unchanged lines hidden (view full) --- 1592 macro->fun_like = 0; 1593 /* To suppress some diagnostics. */ 1594 macro->syshdr = pfile->buffer && pfile->buffer->sysp != 0; 1595 1596 if (CPP_OPTION (pfile, traditional)) 1597 ok = _cpp_create_trad_definition (pfile, macro); 1598 else 1599 { | 1424 1425 /* Is this a parameter? */ 1426 if (token->type == CPP_NAME 1427 && (token->val.node->flags & NODE_MACRO_ARG) != 0) 1428 { 1429 token->type = CPP_MACRO_ARG; 1430 token->val.arg_no = token->val.node->value.arg_index; 1431 } --- 172 unchanged lines hidden (view full) --- 1604 macro->fun_like = 0; 1605 /* To suppress some diagnostics. */ 1606 macro->syshdr = pfile->buffer && pfile->buffer->sysp != 0; 1607 1608 if (CPP_OPTION (pfile, traditional)) 1609 ok = _cpp_create_trad_definition (pfile, macro); 1610 else 1611 { |
1600 cpp_token *saved_cur_token = pfile->cur_token; 1601 | |
1602 ok = create_iso_definition (pfile, macro); 1603 | 1612 ok = create_iso_definition (pfile, macro); 1613 |
1604 /* Restore lexer position because of games lex_expansion_token() 1605 plays lexing the macro. We set the type for SEEN_EOL() in 1606 directives.c. | 1614 /* We set the type for SEEN_EOL() in directives.c. |
1607 1608 Longer term we should lex the whole line before coming here, 1609 and just copy the expansion. */ | 1615 1616 Longer term we should lex the whole line before coming here, 1617 and just copy the expansion. */ |
1610 saved_cur_token[-1].type = pfile->cur_token[-1].type; 1611 pfile->cur_token = saved_cur_token; | |
1612 1613 /* Stop the lexer accepting __VA_ARGS__. */ 1614 pfile->state.va_args_ok = 0; 1615 } 1616 1617 /* Clear the fast argument lookup indices. */ 1618 for (i = macro->paramc; i-- > 0; ) 1619 { --- 209 unchanged lines hidden --- | 1618 1619 /* Stop the lexer accepting __VA_ARGS__. */ 1620 pfile->state.va_args_ok = 0; 1621 } 1622 1623 /* Clear the fast argument lookup indices. */ 1624 for (i = macro->paramc; i-- > 0; ) 1625 { --- 209 unchanged lines hidden --- |