macroexp.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Interface to C preprocessor macro expansion for GDB.
  2. Copyright (C) 2002-2022 Free Software Foundation, Inc.
  3. Contributed by Red Hat, Inc.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef MACROEXP_H
  16. #define MACROEXP_H
  17. struct macro_scope;
  18. /* Expand any preprocessor macros in SOURCE (a null-terminated string), and
  19. return the expanded text.
  20. Use SCOPE to find identifiers' preprocessor definitions.
  21. The result is a null-terminated string. */
  22. gdb::unique_xmalloc_ptr<char> macro_expand (const char *source,
  23. const macro_scope &scope);
  24. /* Expand all preprocessor macro references that appear explicitly in SOURCE
  25. (a null-terminated string), but do not expand any new macro references
  26. introduced by that first level of expansion.
  27. Use SCOPE to find identifiers' preprocessor definitions.
  28. The result is a null-terminated string. */
  29. gdb::unique_xmalloc_ptr<char> macro_expand_once (const char *source,
  30. const macro_scope &scope);
  31. /* If the null-terminated string pointed to by *LEXPTR begins with a
  32. macro invocation, return the result of expanding that invocation as
  33. a null-terminated string, and set *LEXPTR to the next character
  34. after the invocation. The result is completely expanded; it
  35. contains no further macro invocations.
  36. Otherwise, if *LEXPTR does not start with a macro invocation,
  37. return nullptr, and leave *LEXPTR unchanged.
  38. Use SCOPE to find macro definitions.
  39. If this function returns a string, the caller is responsible for
  40. freeing it, using xfree.
  41. We need this expand-one-token-at-a-time interface in order to
  42. accomodate GDB's C expression parser, which may not consume the
  43. entire string. When the user enters a command like
  44. (gdb) break *func+20 if x == 5
  45. the parser is expected to consume `func+20', and then stop when it
  46. sees the "if". But of course, "if" appearing in a character string
  47. or as part of a larger identifier doesn't count. So you pretty
  48. much have to do tokenization to find the end of the string that
  49. needs to be macro-expanded. Our C/C++ tokenizer isn't really
  50. designed to be called by anything but the yacc parser engine. */
  51. gdb::unique_xmalloc_ptr<char> macro_expand_next (const char **lexptr,
  52. const macro_scope &scope);
  53. /* Functions to classify characters according to cpp rules. */
  54. int macro_is_whitespace (int c);
  55. int macro_is_identifier_nondigit (int c);
  56. int macro_is_digit (int c);
  57. /* Stringify STR according to C rules and return a null-terminated string. */
  58. gdb::unique_xmalloc_ptr<char> macro_stringify (const char *str);
  59. #endif /* MACROEXP_H */