macroexp.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  1. /* 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. #include "defs.h"
  16. #include "gdbsupport/gdb_obstack.h"
  17. #include "macrotab.h"
  18. #include "macroexp.h"
  19. #include "macroscope.h"
  20. #include "c-lang.h"
  21. /* A string type that we can use to refer to substrings of other
  22. strings. */
  23. struct shared_macro_buffer
  24. {
  25. /* An array of characters. This buffer is a pointer into some
  26. larger string and thus we can't assume in that the text is
  27. null-terminated. */
  28. const char *text;
  29. /* The number of characters in the string. */
  30. int len;
  31. /* For detecting token splicing.
  32. This is the index in TEXT of the first character of the token
  33. that abuts the end of TEXT. If TEXT contains no tokens, then we
  34. set this equal to LEN. If TEXT ends in whitespace, then there is
  35. no token abutting the end of TEXT (it's just whitespace), and
  36. again, we set this equal to LEN. We set this to -1 if we don't
  37. know the nature of TEXT. */
  38. int last_token = -1;
  39. /* If this buffer is holding the result from get_token, then this
  40. is non-zero if it is an identifier token, zero otherwise. */
  41. int is_identifier = 0;
  42. shared_macro_buffer ()
  43. : text (NULL),
  44. len (0)
  45. {
  46. }
  47. /* Set the macro buffer to refer to the LEN bytes at ADDR, as a
  48. shared substring. */
  49. shared_macro_buffer (const char *addr, int len)
  50. {
  51. set_shared (addr, len);
  52. }
  53. /* Set the macro buffer to refer to the LEN bytes at ADDR, as a
  54. shared substring. */
  55. void set_shared (const char *addr, int len_)
  56. {
  57. text = addr;
  58. len = len_;
  59. }
  60. };
  61. /* A string type that we can resize and quickly append to. */
  62. struct growable_macro_buffer
  63. {
  64. /* An array of characters. The first LEN bytes are the real text,
  65. but there are SIZE bytes allocated to the array. */
  66. char *text;
  67. /* The number of characters in the string. */
  68. int len;
  69. /* The number of characters allocated to the string. */
  70. int size;
  71. /* For detecting token splicing.
  72. This is the index in TEXT of the first character of the token
  73. that abuts the end of TEXT. If TEXT contains no tokens, then we
  74. set this equal to LEN. If TEXT ends in whitespace, then there is
  75. no token abutting the end of TEXT (it's just whitespace), and
  76. again, we set this equal to LEN. We set this to -1 if we don't
  77. know the nature of TEXT. */
  78. int last_token = -1;
  79. /* Set the macro buffer to the empty string, guessing that its
  80. final contents will fit in N bytes. (It'll get resized if it
  81. doesn't, so the guess doesn't have to be right.) Allocate the
  82. initial storage with xmalloc. */
  83. explicit growable_macro_buffer (int n)
  84. : len (0),
  85. size (n)
  86. {
  87. if (n > 0)
  88. text = (char *) xmalloc (n);
  89. else
  90. text = NULL;
  91. }
  92. DISABLE_COPY_AND_ASSIGN (growable_macro_buffer);
  93. ~growable_macro_buffer ()
  94. {
  95. xfree (text);
  96. }
  97. /* Release the text of the buffer to the caller. */
  98. gdb::unique_xmalloc_ptr<char> release ()
  99. {
  100. gdb_assert (size);
  101. char *result = text;
  102. text = NULL;
  103. return gdb::unique_xmalloc_ptr<char> (result);
  104. }
  105. /* Resize the buffer to be at least N bytes long. */
  106. void resize_buffer (int n)
  107. {
  108. if (size == 0)
  109. size = n;
  110. else
  111. while (size <= n)
  112. size *= 2;
  113. text = (char *) xrealloc (text, size);
  114. }
  115. /* Append the character C to the buffer. */
  116. void appendc (int c)
  117. {
  118. int new_len = len + 1;
  119. if (new_len > size)
  120. resize_buffer (new_len);
  121. text[len] = c;
  122. len = new_len;
  123. }
  124. /* Append the COUNT bytes at ADDR to the buffer. */
  125. void appendmem (const char *addr, int count)
  126. {
  127. int new_len = len + count;
  128. if (new_len > size)
  129. resize_buffer (new_len);
  130. memcpy (text + len, addr, count);
  131. len = new_len;
  132. }
  133. };
  134. /* Recognizing preprocessor tokens. */
  135. int
  136. macro_is_whitespace (int c)
  137. {
  138. return (c == ' '
  139. || c == '\t'
  140. || c == '\n'
  141. || c == '\v'
  142. || c == '\f');
  143. }
  144. int
  145. macro_is_digit (int c)
  146. {
  147. return ('0' <= c && c <= '9');
  148. }
  149. int
  150. macro_is_identifier_nondigit (int c)
  151. {
  152. return (c == '_'
  153. || ('a' <= c && c <= 'z')
  154. || ('A' <= c && c <= 'Z'));
  155. }
  156. static void
  157. set_token (shared_macro_buffer *tok, const char *start, const char *end)
  158. {
  159. tok->set_shared (start, end - start);
  160. tok->last_token = 0;
  161. /* Presumed; get_identifier may overwrite this. */
  162. tok->is_identifier = 0;
  163. }
  164. static int
  165. get_comment (shared_macro_buffer *tok, const char *p, const char *end)
  166. {
  167. if (p + 2 > end)
  168. return 0;
  169. else if (p[0] == '/'
  170. && p[1] == '*')
  171. {
  172. const char *tok_start = p;
  173. p += 2;
  174. for (; p < end; p++)
  175. if (p + 2 <= end
  176. && p[0] == '*'
  177. && p[1] == '/')
  178. {
  179. p += 2;
  180. set_token (tok, tok_start, p);
  181. return 1;
  182. }
  183. error (_("Unterminated comment in macro expansion."));
  184. }
  185. else if (p[0] == '/'
  186. && p[1] == '/')
  187. {
  188. const char *tok_start = p;
  189. p += 2;
  190. for (; p < end; p++)
  191. if (*p == '\n')
  192. break;
  193. set_token (tok, tok_start, p);
  194. return 1;
  195. }
  196. else
  197. return 0;
  198. }
  199. static int
  200. get_identifier (shared_macro_buffer *tok, const char *p, const char *end)
  201. {
  202. if (p < end
  203. && macro_is_identifier_nondigit (*p))
  204. {
  205. const char *tok_start = p;
  206. while (p < end
  207. && (macro_is_identifier_nondigit (*p)
  208. || macro_is_digit (*p)))
  209. p++;
  210. set_token (tok, tok_start, p);
  211. tok->is_identifier = 1;
  212. return 1;
  213. }
  214. else
  215. return 0;
  216. }
  217. static int
  218. get_pp_number (shared_macro_buffer *tok, const char *p, const char *end)
  219. {
  220. if (p < end
  221. && (macro_is_digit (*p)
  222. || (*p == '.'
  223. && p + 2 <= end
  224. && macro_is_digit (p[1]))))
  225. {
  226. const char *tok_start = p;
  227. while (p < end)
  228. {
  229. if (p + 2 <= end
  230. && strchr ("eEpP", *p)
  231. && (p[1] == '+' || p[1] == '-'))
  232. p += 2;
  233. else if (macro_is_digit (*p)
  234. || macro_is_identifier_nondigit (*p)
  235. || *p == '.')
  236. p++;
  237. else
  238. break;
  239. }
  240. set_token (tok, tok_start, p);
  241. return 1;
  242. }
  243. else
  244. return 0;
  245. }
  246. /* If the text starting at P going up to (but not including) END
  247. starts with a character constant, set *TOK to point to that
  248. character constant, and return 1. Otherwise, return zero.
  249. Signal an error if it contains a malformed or incomplete character
  250. constant. */
  251. static int
  252. get_character_constant (shared_macro_buffer *tok,
  253. const char *p, const char *end)
  254. {
  255. /* ISO/IEC 9899:1999 (E) Section 6.4.4.4 paragraph 1
  256. But of course, what really matters is that we handle it the same
  257. way GDB's C/C++ lexer does. So we call parse_escape in utils.c
  258. to handle escape sequences. */
  259. if ((p + 1 <= end && *p == '\'')
  260. || (p + 2 <= end
  261. && (p[0] == 'L' || p[0] == 'u' || p[0] == 'U')
  262. && p[1] == '\''))
  263. {
  264. const char *tok_start = p;
  265. int char_count = 0;
  266. if (*p == '\'')
  267. p++;
  268. else if (*p == 'L' || *p == 'u' || *p == 'U')
  269. p += 2;
  270. else
  271. gdb_assert_not_reached ("unexpected character constant");
  272. for (;;)
  273. {
  274. if (p >= end)
  275. error (_("Unmatched single quote."));
  276. else if (*p == '\'')
  277. {
  278. if (!char_count)
  279. error (_("A character constant must contain at least one "
  280. "character."));
  281. p++;
  282. break;
  283. }
  284. else if (*p == '\\')
  285. {
  286. const char *s, *o;
  287. s = o = ++p;
  288. char_count += c_parse_escape (&s, NULL);
  289. p += s - o;
  290. }
  291. else
  292. {
  293. p++;
  294. char_count++;
  295. }
  296. }
  297. set_token (tok, tok_start, p);
  298. return 1;
  299. }
  300. else
  301. return 0;
  302. }
  303. /* If the text starting at P going up to (but not including) END
  304. starts with a string literal, set *TOK to point to that string
  305. literal, and return 1. Otherwise, return zero. Signal an error if
  306. it contains a malformed or incomplete string literal. */
  307. static int
  308. get_string_literal (shared_macro_buffer *tok, const char *p, const char *end)
  309. {
  310. if ((p + 1 <= end
  311. && *p == '"')
  312. || (p + 2 <= end
  313. && (p[0] == 'L' || p[0] == 'u' || p[0] == 'U')
  314. && p[1] == '"'))
  315. {
  316. const char *tok_start = p;
  317. if (*p == '"')
  318. p++;
  319. else if (*p == 'L' || *p == 'u' || *p == 'U')
  320. p += 2;
  321. else
  322. gdb_assert_not_reached ("unexpected string literal");
  323. for (;;)
  324. {
  325. if (p >= end)
  326. error (_("Unterminated string in expression."));
  327. else if (*p == '"')
  328. {
  329. p++;
  330. break;
  331. }
  332. else if (*p == '\n')
  333. error (_("Newline characters may not appear in string "
  334. "constants."));
  335. else if (*p == '\\')
  336. {
  337. const char *s, *o;
  338. s = o = ++p;
  339. c_parse_escape (&s, NULL);
  340. p += s - o;
  341. }
  342. else
  343. p++;
  344. }
  345. set_token (tok, tok_start, p);
  346. return 1;
  347. }
  348. else
  349. return 0;
  350. }
  351. static int
  352. get_punctuator (shared_macro_buffer *tok, const char *p, const char *end)
  353. {
  354. /* Here, speed is much less important than correctness and clarity. */
  355. /* ISO/IEC 9899:1999 (E) Section 6.4.6 Paragraph 1.
  356. Note that this table is ordered in a special way. A punctuator
  357. which is a prefix of another punctuator must appear after its
  358. "extension". Otherwise, the wrong token will be returned. */
  359. static const char * const punctuators[] = {
  360. "[", "]", "(", ")", "{", "}", "?", ";", ",", "~",
  361. "...", ".",
  362. "->", "--", "-=", "-",
  363. "++", "+=", "+",
  364. "*=", "*",
  365. "!=", "!",
  366. "&&", "&=", "&",
  367. "/=", "/",
  368. "%>", "%:%:", "%:", "%=", "%",
  369. "^=", "^",
  370. "##", "#",
  371. ":>", ":",
  372. "||", "|=", "|",
  373. "<<=", "<<", "<=", "<:", "<%", "<",
  374. ">>=", ">>", ">=", ">",
  375. "==", "=",
  376. 0
  377. };
  378. int i;
  379. if (p + 1 <= end)
  380. {
  381. for (i = 0; punctuators[i]; i++)
  382. {
  383. const char *punctuator = punctuators[i];
  384. if (p[0] == punctuator[0])
  385. {
  386. int len = strlen (punctuator);
  387. if (p + len <= end
  388. && ! memcmp (p, punctuator, len))
  389. {
  390. set_token (tok, p, p + len);
  391. return 1;
  392. }
  393. }
  394. }
  395. }
  396. return 0;
  397. }
  398. /* Peel the next preprocessor token off of SRC, and put it in TOK.
  399. Mutate TOK to refer to the first token in SRC, and mutate SRC to
  400. refer to the text after that token. The resulting TOK will point
  401. into the same string SRC does. Initialize TOK's last_token field.
  402. Return non-zero if we succeed, or 0 if we didn't find any more
  403. tokens in SRC. */
  404. static int
  405. get_token (shared_macro_buffer *tok, shared_macro_buffer *src)
  406. {
  407. const char *p = src->text;
  408. const char *end = p + src->len;
  409. /* From the ISO C standard, ISO/IEC 9899:1999 (E), section 6.4:
  410. preprocessing-token:
  411. header-name
  412. identifier
  413. pp-number
  414. character-constant
  415. string-literal
  416. punctuator
  417. each non-white-space character that cannot be one of the above
  418. We don't have to deal with header-name tokens, since those can
  419. only occur after a #include, which we will never see. */
  420. while (p < end)
  421. if (macro_is_whitespace (*p))
  422. p++;
  423. else if (get_comment (tok, p, end))
  424. p += tok->len;
  425. else if (get_pp_number (tok, p, end)
  426. || get_character_constant (tok, p, end)
  427. || get_string_literal (tok, p, end)
  428. /* Note: the grammar in the standard seems to be
  429. ambiguous: L'x' can be either a wide character
  430. constant, or an identifier followed by a normal
  431. character constant. By trying `get_identifier' after
  432. we try get_character_constant and get_string_literal,
  433. we give the wide character syntax precedence. Now,
  434. since GDB doesn't handle wide character constants
  435. anyway, is this the right thing to do? */
  436. || get_identifier (tok, p, end)
  437. || get_punctuator (tok, p, end))
  438. {
  439. /* How many characters did we consume, including whitespace? */
  440. int consumed = p - src->text + tok->len;
  441. src->text += consumed;
  442. src->len -= consumed;
  443. return 1;
  444. }
  445. else
  446. {
  447. /* We have found a "non-whitespace character that cannot be
  448. one of the above." Make a token out of it. */
  449. int consumed;
  450. set_token (tok, p, p + 1);
  451. consumed = p - src->text + tok->len;
  452. src->text += consumed;
  453. src->len -= consumed;
  454. return 1;
  455. }
  456. return 0;
  457. }
  458. /* Appending token strings, with and without splicing */
  459. /* Append the macro buffer SRC to the end of DEST, and ensure that
  460. doing so doesn't splice the token at the end of SRC with the token
  461. at the beginning of DEST. SRC and DEST must have their last_token
  462. fields set. Upon return, DEST's last_token field is set correctly.
  463. For example:
  464. If DEST is "(" and SRC is "y", then we can return with
  465. DEST set to "(y" --- we've simply appended the two buffers.
  466. However, if DEST is "x" and SRC is "y", then we must not return
  467. with DEST set to "xy" --- that would splice the two tokens "x" and
  468. "y" together to make a single token "xy". However, it would be
  469. fine to return with DEST set to "x y". Similarly, "<" and "<" must
  470. yield "< <", not "<<", etc. */
  471. static void
  472. append_tokens_without_splicing (growable_macro_buffer *dest,
  473. shared_macro_buffer *src)
  474. {
  475. int original_dest_len = dest->len;
  476. shared_macro_buffer dest_tail, new_token;
  477. gdb_assert (src->last_token != -1);
  478. gdb_assert (dest->last_token != -1);
  479. /* First, just try appending the two, and call get_token to see if
  480. we got a splice. */
  481. dest->appendmem (src->text, src->len);
  482. /* If DEST originally had no token abutting its end, then we can't
  483. have spliced anything, so we're done. */
  484. if (dest->last_token == original_dest_len)
  485. {
  486. dest->last_token = original_dest_len + src->last_token;
  487. return;
  488. }
  489. /* Set DEST_TAIL to point to the last token in DEST, followed by
  490. all the stuff we just appended. */
  491. dest_tail.set_shared (dest->text + dest->last_token,
  492. dest->len - dest->last_token);
  493. /* Re-parse DEST's last token. We know that DEST used to contain
  494. at least one token, so if it doesn't contain any after the
  495. append, then we must have spliced "/" and "*" or "/" and "/" to
  496. make a comment start. (Just for the record, I got this right
  497. the first time. This is not a bug fix.) */
  498. if (get_token (&new_token, &dest_tail)
  499. && (new_token.text + new_token.len
  500. == dest->text + original_dest_len))
  501. {
  502. /* No splice, so we're done. */
  503. dest->last_token = original_dest_len + src->last_token;
  504. return;
  505. }
  506. /* Okay, a simple append caused a splice. Let's chop dest back to
  507. its original length and try again, but separate the texts with a
  508. space. */
  509. dest->len = original_dest_len;
  510. dest->appendc (' ');
  511. dest->appendmem (src->text, src->len);
  512. dest_tail.set_shared (dest->text + dest->last_token,
  513. dest->len - dest->last_token);
  514. /* Try to re-parse DEST's last token, as above. */
  515. if (get_token (&new_token, &dest_tail)
  516. && (new_token.text + new_token.len
  517. == dest->text + original_dest_len))
  518. {
  519. /* No splice, so we're done. */
  520. dest->last_token = original_dest_len + 1 + src->last_token;
  521. return;
  522. }
  523. /* As far as I know, there's no case where inserting a space isn't
  524. enough to prevent a splice. */
  525. internal_error (__FILE__, __LINE__,
  526. _("unable to avoid splicing tokens during macro expansion"));
  527. }
  528. /* Stringify an argument, and insert it into DEST. ARG is the text to
  529. stringify; it is LEN bytes long. */
  530. static void
  531. stringify (growable_macro_buffer *dest, const char *arg, int len)
  532. {
  533. /* Trim initial whitespace from ARG. */
  534. while (len > 0 && macro_is_whitespace (*arg))
  535. {
  536. ++arg;
  537. --len;
  538. }
  539. /* Trim trailing whitespace from ARG. */
  540. while (len > 0 && macro_is_whitespace (arg[len - 1]))
  541. --len;
  542. /* Insert the string. */
  543. dest->appendc ('"');
  544. while (len > 0)
  545. {
  546. /* We could try to handle strange cases here, like control
  547. characters, but there doesn't seem to be much point. */
  548. if (macro_is_whitespace (*arg))
  549. {
  550. /* Replace a sequence of whitespace with a single space. */
  551. dest->appendc (' ');
  552. while (len > 1 && macro_is_whitespace (arg[1]))
  553. {
  554. ++arg;
  555. --len;
  556. }
  557. }
  558. else if (*arg == '\\' || *arg == '"')
  559. {
  560. dest->appendc ('\\');
  561. dest->appendc (*arg);
  562. }
  563. else
  564. dest->appendc (*arg);
  565. ++arg;
  566. --len;
  567. }
  568. dest->appendc ('"');
  569. dest->last_token = dest->len;
  570. }
  571. /* See macroexp.h. */
  572. gdb::unique_xmalloc_ptr<char>
  573. macro_stringify (const char *str)
  574. {
  575. int len = strlen (str);
  576. growable_macro_buffer buffer (len);
  577. stringify (&buffer, str, len);
  578. buffer.appendc ('\0');
  579. return buffer.release ();
  580. }
  581. /* Expanding macros! */
  582. /* A singly-linked list of the names of the macros we are currently
  583. expanding --- for detecting expansion loops. */
  584. struct macro_name_list {
  585. const char *name;
  586. struct macro_name_list *next;
  587. };
  588. /* Return non-zero if we are currently expanding the macro named NAME,
  589. according to LIST; otherwise, return zero.
  590. You know, it would be possible to get rid of all the NO_LOOP
  591. arguments to these functions by simply generating a new lookup
  592. function and baton which refuses to find the definition for a
  593. particular macro, and otherwise delegates the decision to another
  594. function/baton pair. But that makes the linked list of excluded
  595. macros chained through untyped baton pointers, which will make it
  596. harder to debug. :( */
  597. static int
  598. currently_rescanning (struct macro_name_list *list, const char *name)
  599. {
  600. for (; list; list = list->next)
  601. if (strcmp (name, list->name) == 0)
  602. return 1;
  603. return 0;
  604. }
  605. /* Gather the arguments to a macro expansion.
  606. NAME is the name of the macro being invoked. (It's only used for
  607. printing error messages.)
  608. Assume that SRC is the text of the macro invocation immediately
  609. following the macro name. For example, if we're processing the
  610. text foo(bar, baz), then NAME would be foo and SRC will be (bar,
  611. baz).
  612. If SRC doesn't start with an open paren ( token at all, return
  613. false, leave SRC unchanged, and don't set *ARGS_PTR to anything.
  614. If SRC doesn't contain a properly terminated argument list, then
  615. raise an error.
  616. For a variadic macro, NARGS holds the number of formal arguments to
  617. the macro. For a GNU-style variadic macro, this should be the
  618. number of named arguments. For a non-variadic macro, NARGS should
  619. be -1.
  620. Otherwise, return true and set *ARGS_PTR to a vector of macro
  621. buffers referring to the argument texts. The macro buffers share
  622. their text with SRC, and their last_token fields are initialized.
  623. NOTE WELL: if SRC starts with a open paren ( token followed
  624. immediately by a close paren ) token (e.g., the invocation looks
  625. like "foo()"), we treat that as one argument, which happens to be
  626. the empty list of tokens. The caller should keep in mind that such
  627. a sequence of tokens is a valid way to invoke one-parameter
  628. function-like macros, but also a valid way to invoke zero-parameter
  629. function-like macros. Eeew.
  630. Consume the tokens from SRC; after this call, SRC contains the text
  631. following the invocation. */
  632. static bool
  633. gather_arguments (const char *name, shared_macro_buffer *src, int nargs,
  634. std::vector<shared_macro_buffer> *args_ptr)
  635. {
  636. shared_macro_buffer tok;
  637. std::vector<shared_macro_buffer> args;
  638. /* Does SRC start with an opening paren token? Read from a copy of
  639. SRC, so SRC itself is unaffected if we don't find an opening
  640. paren. */
  641. {
  642. shared_macro_buffer temp (src->text, src->len);
  643. if (! get_token (&tok, &temp)
  644. || tok.len != 1
  645. || tok.text[0] != '(')
  646. return false;
  647. }
  648. /* Consume SRC's opening paren. */
  649. get_token (&tok, src);
  650. for (;;)
  651. {
  652. shared_macro_buffer *arg;
  653. int depth;
  654. /* Initialize the next argument. */
  655. args.emplace_back ();
  656. arg = &args.back ();
  657. set_token (arg, src->text, src->text);
  658. /* Gather the argument's tokens. */
  659. depth = 0;
  660. for (;;)
  661. {
  662. if (! get_token (&tok, src))
  663. error (_("Malformed argument list for macro `%s'."), name);
  664. /* Is tok an opening paren? */
  665. if (tok.len == 1 && tok.text[0] == '(')
  666. depth++;
  667. /* Is tok is a closing paren? */
  668. else if (tok.len == 1 && tok.text[0] == ')')
  669. {
  670. /* If it's a closing paren at the top level, then that's
  671. the end of the argument list. */
  672. if (depth == 0)
  673. {
  674. /* In the varargs case, the last argument may be
  675. missing. Add an empty argument in this case. */
  676. if (nargs != -1 && args.size () == nargs - 1)
  677. {
  678. args.emplace_back ();
  679. arg = &args.back ();
  680. set_token (arg, src->text, src->text);
  681. }
  682. *args_ptr = std::move (args);
  683. return true;
  684. }
  685. depth--;
  686. }
  687. /* If tok is a comma at top level, then that's the end of
  688. the current argument. However, if we are handling a
  689. variadic macro and we are computing the last argument, we
  690. want to include the comma and remaining tokens. */
  691. else if (tok.len == 1 && tok.text[0] == ',' && depth == 0
  692. && (nargs == -1 || args.size () < nargs))
  693. break;
  694. /* Extend the current argument to enclose this token. If
  695. this is the current argument's first token, leave out any
  696. leading whitespace, just for aesthetics. */
  697. if (arg->len == 0)
  698. {
  699. arg->text = tok.text;
  700. arg->len = tok.len;
  701. arg->last_token = 0;
  702. }
  703. else
  704. {
  705. arg->len = (tok.text + tok.len) - arg->text;
  706. arg->last_token = tok.text - arg->text;
  707. }
  708. }
  709. }
  710. }
  711. /* The `expand' and `substitute_args' functions both invoke `scan'
  712. recursively, so we need a forward declaration somewhere. */
  713. static void scan (growable_macro_buffer *dest,
  714. shared_macro_buffer *src,
  715. struct macro_name_list *no_loop,
  716. const macro_scope &scope);
  717. /* A helper function for substitute_args.
  718. ARGV is a vector of all the arguments; ARGC is the number of
  719. arguments. IS_VARARGS is true if the macro being substituted is a
  720. varargs macro; in this case VA_ARG_NAME is the name of the
  721. "variable" argument. VA_ARG_NAME is ignored if IS_VARARGS is
  722. false.
  723. If the token TOK is the name of a parameter, return the parameter's
  724. index. If TOK is not an argument, return -1. */
  725. static int
  726. find_parameter (const shared_macro_buffer *tok,
  727. int is_varargs, const shared_macro_buffer *va_arg_name,
  728. int argc, const char * const *argv)
  729. {
  730. int i;
  731. if (! tok->is_identifier)
  732. return -1;
  733. for (i = 0; i < argc; ++i)
  734. if (tok->len == strlen (argv[i])
  735. && !memcmp (tok->text, argv[i], tok->len))
  736. return i;
  737. if (is_varargs && tok->len == va_arg_name->len
  738. && ! memcmp (tok->text, va_arg_name->text, tok->len))
  739. return argc - 1;
  740. return -1;
  741. }
  742. /* Helper function for substitute_args that gets the next token and
  743. updates the passed-in state variables. */
  744. static void
  745. get_next_token_for_substitution (shared_macro_buffer *replacement_list,
  746. shared_macro_buffer *token,
  747. const char **start,
  748. shared_macro_buffer *lookahead,
  749. const char **lookahead_start,
  750. int *lookahead_valid,
  751. bool *keep_going)
  752. {
  753. if (!*lookahead_valid)
  754. *keep_going = false;
  755. else
  756. {
  757. *keep_going = true;
  758. *token = *lookahead;
  759. *start = *lookahead_start;
  760. *lookahead_start = replacement_list->text;
  761. *lookahead_valid = get_token (lookahead, replacement_list);
  762. }
  763. }
  764. /* Given the macro definition DEF, being invoked with the actual
  765. arguments given by ARGV, substitute the arguments into the
  766. replacement list, and store the result in DEST.
  767. IS_VARARGS should be true if DEF is a varargs macro. In this case,
  768. VA_ARG_NAME should be the name of the "variable" argument -- either
  769. __VA_ARGS__ for c99-style varargs, or the final argument name, for
  770. GNU-style varargs. If IS_VARARGS is false, this parameter is
  771. ignored.
  772. If it is necessary to expand macro invocations in one of the
  773. arguments, use LOOKUP_FUNC and LOOKUP_BATON to find the macro
  774. definitions, and don't expand invocations of the macros listed in
  775. NO_LOOP. */
  776. static void
  777. substitute_args (growable_macro_buffer *dest,
  778. struct macro_definition *def,
  779. int is_varargs, const shared_macro_buffer *va_arg_name,
  780. const std::vector<shared_macro_buffer> &argv,
  781. struct macro_name_list *no_loop,
  782. const macro_scope &scope)
  783. {
  784. /* The token we are currently considering. */
  785. shared_macro_buffer tok;
  786. /* The replacement list's pointer from just before TOK was lexed. */
  787. const char *original_rl_start;
  788. /* We have a single lookahead token to handle token splicing. */
  789. shared_macro_buffer lookahead;
  790. /* The lookahead token might not be valid. */
  791. int lookahead_valid;
  792. /* The replacement list's pointer from just before LOOKAHEAD was
  793. lexed. */
  794. const char *lookahead_rl_start;
  795. /* A macro buffer for the macro's replacement list. */
  796. shared_macro_buffer replacement_list (def->replacement,
  797. strlen (def->replacement));
  798. gdb_assert (dest->len == 0);
  799. dest->last_token = 0;
  800. original_rl_start = replacement_list.text;
  801. if (! get_token (&tok, &replacement_list))
  802. return;
  803. lookahead_rl_start = replacement_list.text;
  804. lookahead_valid = get_token (&lookahead, &replacement_list);
  805. /* __VA_OPT__ state variable. The states are:
  806. 0 - nothing happening
  807. 1 - saw __VA_OPT__
  808. >= 2 in __VA_OPT__, the value encodes the parenthesis depth. */
  809. unsigned vaopt_state = 0;
  810. for (bool keep_going = true;
  811. keep_going;
  812. get_next_token_for_substitution (&replacement_list,
  813. &tok,
  814. &original_rl_start,
  815. &lookahead,
  816. &lookahead_rl_start,
  817. &lookahead_valid,
  818. &keep_going))
  819. {
  820. bool token_is_vaopt = (tok.len == 10
  821. && startswith (tok.text, "__VA_OPT__"));
  822. if (vaopt_state > 0)
  823. {
  824. if (token_is_vaopt)
  825. error (_("__VA_OPT__ cannot appear inside __VA_OPT__"));
  826. else if (tok.len == 1 && tok.text[0] == '(')
  827. {
  828. ++vaopt_state;
  829. /* We just entered __VA_OPT__, so don't emit this
  830. token. */
  831. continue;
  832. }
  833. else if (vaopt_state == 1)
  834. error (_("__VA_OPT__ must be followed by an open parenthesis"));
  835. else if (tok.len == 1 && tok.text[0] == ')')
  836. {
  837. --vaopt_state;
  838. if (vaopt_state == 1)
  839. {
  840. /* Done with __VA_OPT__. */
  841. vaopt_state = 0;
  842. /* Don't emit. */
  843. continue;
  844. }
  845. }
  846. /* If __VA_ARGS__ is empty, then drop the contents of
  847. __VA_OPT__. */
  848. if (argv.back ().len == 0)
  849. continue;
  850. }
  851. else if (token_is_vaopt)
  852. {
  853. if (!is_varargs)
  854. error (_("__VA_OPT__ is only valid in a variadic macro"));
  855. vaopt_state = 1;
  856. /* Don't emit this token. */
  857. continue;
  858. }
  859. /* Just for aesthetics. If we skipped some whitespace, copy
  860. that to DEST. */
  861. if (tok.text > original_rl_start)
  862. {
  863. dest->appendmem (original_rl_start, tok.text - original_rl_start);
  864. dest->last_token = dest->len;
  865. }
  866. /* Is this token the stringification operator? */
  867. if (tok.len == 1
  868. && tok.text[0] == '#')
  869. {
  870. int arg;
  871. if (!lookahead_valid)
  872. error (_("Stringification operator requires an argument."));
  873. arg = find_parameter (&lookahead, is_varargs, va_arg_name,
  874. def->argc, def->argv);
  875. if (arg == -1)
  876. error (_("Argument to stringification operator must name "
  877. "a macro parameter."));
  878. stringify (dest, argv[arg].text, argv[arg].len);
  879. /* Read one token and let the loop iteration code handle the
  880. rest. */
  881. lookahead_rl_start = replacement_list.text;
  882. lookahead_valid = get_token (&lookahead, &replacement_list);
  883. }
  884. /* Is this token the splicing operator? */
  885. else if (tok.len == 2
  886. && tok.text[0] == '#'
  887. && tok.text[1] == '#')
  888. error (_("Stray splicing operator"));
  889. /* Is the next token the splicing operator? */
  890. else if (lookahead_valid
  891. && lookahead.len == 2
  892. && lookahead.text[0] == '#'
  893. && lookahead.text[1] == '#')
  894. {
  895. int finished = 0;
  896. int prev_was_comma = 0;
  897. /* Note that GCC warns if the result of splicing is not a
  898. token. In the debugger there doesn't seem to be much
  899. benefit from doing this. */
  900. /* Insert the first token. */
  901. if (tok.len == 1 && tok.text[0] == ',')
  902. prev_was_comma = 1;
  903. else
  904. {
  905. int arg = find_parameter (&tok, is_varargs, va_arg_name,
  906. def->argc, def->argv);
  907. if (arg != -1)
  908. dest->appendmem (argv[arg].text, argv[arg].len);
  909. else
  910. dest->appendmem (tok.text, tok.len);
  911. }
  912. /* Apply a possible sequence of ## operators. */
  913. for (;;)
  914. {
  915. if (! get_token (&tok, &replacement_list))
  916. error (_("Splicing operator at end of macro"));
  917. /* Handle a comma before a ##. If we are handling
  918. varargs, and the token on the right hand side is the
  919. varargs marker, and the final argument is empty or
  920. missing, then drop the comma. This is a GNU
  921. extension. There is one ambiguous case here,
  922. involving pedantic behavior with an empty argument,
  923. but we settle that in favor of GNU-style (GCC uses an
  924. option). If we aren't dealing with varargs, we
  925. simply insert the comma. */
  926. if (prev_was_comma)
  927. {
  928. if (! (is_varargs
  929. && tok.len == va_arg_name->len
  930. && !memcmp (tok.text, va_arg_name->text, tok.len)
  931. && argv.back ().len == 0))
  932. dest->appendmem (",", 1);
  933. prev_was_comma = 0;
  934. }
  935. /* Insert the token. If it is a parameter, insert the
  936. argument. If it is a comma, treat it specially. */
  937. if (tok.len == 1 && tok.text[0] == ',')
  938. prev_was_comma = 1;
  939. else
  940. {
  941. int arg = find_parameter (&tok, is_varargs, va_arg_name,
  942. def->argc, def->argv);
  943. if (arg != -1)
  944. dest->appendmem (argv[arg].text, argv[arg].len);
  945. else
  946. dest->appendmem (tok.text, tok.len);
  947. }
  948. /* Now read another token. If it is another splice, we
  949. loop. */
  950. original_rl_start = replacement_list.text;
  951. if (! get_token (&tok, &replacement_list))
  952. {
  953. finished = 1;
  954. break;
  955. }
  956. if (! (tok.len == 2
  957. && tok.text[0] == '#'
  958. && tok.text[1] == '#'))
  959. break;
  960. }
  961. if (prev_was_comma)
  962. {
  963. /* We saw a comma. Insert it now. */
  964. dest->appendmem (",", 1);
  965. }
  966. dest->last_token = dest->len;
  967. if (finished)
  968. lookahead_valid = 0;
  969. else
  970. {
  971. /* Set up for the loop iterator. */
  972. lookahead = tok;
  973. lookahead_rl_start = original_rl_start;
  974. lookahead_valid = 1;
  975. }
  976. }
  977. else
  978. {
  979. /* Is this token an identifier? */
  980. int substituted = 0;
  981. int arg = find_parameter (&tok, is_varargs, va_arg_name,
  982. def->argc, def->argv);
  983. if (arg != -1)
  984. {
  985. /* Expand any macro invocations in the argument text,
  986. and append the result to dest. Remember that scan
  987. mutates its source, so we need to scan a new buffer
  988. referring to the argument's text, not the argument
  989. itself. */
  990. shared_macro_buffer arg_src (argv[arg].text, argv[arg].len);
  991. scan (dest, &arg_src, no_loop, scope);
  992. substituted = 1;
  993. }
  994. /* If it wasn't a parameter, then just copy it across. */
  995. if (! substituted)
  996. append_tokens_without_splicing (dest, &tok);
  997. }
  998. }
  999. if (vaopt_state > 0)
  1000. error (_("Unterminated __VA_OPT__"));
  1001. }
  1002. /* Expand a call to a macro named ID, whose definition is DEF. Append
  1003. its expansion to DEST. SRC is the input text following the ID
  1004. token. We are currently rescanning the expansions of the macros
  1005. named in NO_LOOP; don't re-expand them. Use LOOKUP_FUNC and
  1006. LOOKUP_BATON to find definitions for any nested macro references.
  1007. Return 1 if we decided to expand it, zero otherwise. (If it's a
  1008. function-like macro name that isn't followed by an argument list,
  1009. we don't expand it.) If we return zero, leave SRC unchanged. */
  1010. static int
  1011. expand (const char *id,
  1012. struct macro_definition *def,
  1013. growable_macro_buffer *dest,
  1014. shared_macro_buffer *src,
  1015. struct macro_name_list *no_loop,
  1016. const macro_scope &scope)
  1017. {
  1018. struct macro_name_list new_no_loop;
  1019. /* Create a new node to be added to the front of the no-expand list.
  1020. This list is appropriate for re-scanning replacement lists, but
  1021. it is *not* appropriate for scanning macro arguments; invocations
  1022. of the macro whose arguments we are gathering *do* get expanded
  1023. there. */
  1024. new_no_loop.name = id;
  1025. new_no_loop.next = no_loop;
  1026. /* What kind of macro are we expanding? */
  1027. if (def->kind == macro_object_like)
  1028. {
  1029. shared_macro_buffer replacement_list (def->replacement,
  1030. strlen (def->replacement));
  1031. scan (dest, &replacement_list, &new_no_loop, scope);
  1032. return 1;
  1033. }
  1034. else if (def->kind == macro_function_like)
  1035. {
  1036. shared_macro_buffer va_arg_name;
  1037. int is_varargs = 0;
  1038. if (def->argc >= 1)
  1039. {
  1040. if (strcmp (def->argv[def->argc - 1], "...") == 0)
  1041. {
  1042. /* In C99-style varargs, substitution is done using
  1043. __VA_ARGS__. */
  1044. va_arg_name.set_shared ("__VA_ARGS__", strlen ("__VA_ARGS__"));
  1045. is_varargs = 1;
  1046. }
  1047. else
  1048. {
  1049. int len = strlen (def->argv[def->argc - 1]);
  1050. if (len > 3
  1051. && strcmp (def->argv[def->argc - 1] + len - 3, "...") == 0)
  1052. {
  1053. /* In GNU-style varargs, the name of the
  1054. substitution parameter is the name of the formal
  1055. argument without the "...". */
  1056. va_arg_name.set_shared (def->argv[def->argc - 1], len - 3);
  1057. is_varargs = 1;
  1058. }
  1059. }
  1060. }
  1061. std::vector<shared_macro_buffer> argv;
  1062. /* If we couldn't find any argument list, then we don't expand
  1063. this macro. */
  1064. if (!gather_arguments (id, src, is_varargs ? def->argc : -1,
  1065. &argv))
  1066. return 0;
  1067. /* Check that we're passing an acceptable number of arguments for
  1068. this macro. */
  1069. if (argv.size () != def->argc)
  1070. {
  1071. if (is_varargs && argv.size () >= def->argc - 1)
  1072. {
  1073. /* Ok. */
  1074. }
  1075. /* Remember that a sequence of tokens like "foo()" is a
  1076. valid invocation of a macro expecting either zero or one
  1077. arguments. */
  1078. else if (! (argv.size () == 1
  1079. && argv[0].len == 0
  1080. && def->argc == 0))
  1081. error (_("Wrong number of arguments to macro `%s' "
  1082. "(expected %d, got %d)."),
  1083. id, def->argc, int (argv.size ()));
  1084. }
  1085. /* Note that we don't expand macro invocations in the arguments
  1086. yet --- we let subst_args take care of that. Parameters that
  1087. appear as operands of the stringifying operator "#" or the
  1088. splicing operator "##" don't get macro references expanded,
  1089. so we can't really tell whether it's appropriate to macro-
  1090. expand an argument until we see how it's being used. */
  1091. growable_macro_buffer substituted (0);
  1092. substitute_args (&substituted, def, is_varargs, &va_arg_name,
  1093. argv, no_loop, scope);
  1094. /* Now `substituted' is the macro's replacement list, with all
  1095. argument values substituted into it properly. Re-scan it for
  1096. macro references, but don't expand invocations of this macro.
  1097. We create a new buffer, `substituted_src', which points into
  1098. `substituted', and scan that. We can't scan `substituted'
  1099. itself, since the tokenization process moves the buffer's
  1100. text pointer around, and we still need to be able to find
  1101. `substituted's original text buffer after scanning it so we
  1102. can free it. */
  1103. shared_macro_buffer substituted_src (substituted.text, substituted.len);
  1104. scan (dest, &substituted_src, &new_no_loop, scope);
  1105. return 1;
  1106. }
  1107. else
  1108. internal_error (__FILE__, __LINE__, _("bad macro definition kind"));
  1109. }
  1110. /* If the single token in SRC_FIRST followed by the tokens in SRC_REST
  1111. constitute a macro invocation not forbidden in NO_LOOP, append its
  1112. expansion to DEST and return non-zero. Otherwise, return zero, and
  1113. leave DEST unchanged.
  1114. SRC_FIRST must be a string built by get_token. */
  1115. static int
  1116. maybe_expand (growable_macro_buffer *dest,
  1117. shared_macro_buffer *src_first,
  1118. shared_macro_buffer *src_rest,
  1119. struct macro_name_list *no_loop,
  1120. const macro_scope &scope)
  1121. {
  1122. /* Is this token an identifier? */
  1123. if (src_first->is_identifier)
  1124. {
  1125. /* Make a null-terminated copy of it, since that's what our
  1126. lookup function expects. */
  1127. std::string id (src_first->text, src_first->len);
  1128. /* If we're currently re-scanning the result of expanding
  1129. this macro, don't expand it again. */
  1130. if (! currently_rescanning (no_loop, id.c_str ()))
  1131. {
  1132. /* Does this identifier have a macro definition in scope? */
  1133. macro_definition *def = standard_macro_lookup (id.c_str (), scope);
  1134. if (def && expand (id.c_str (), def, dest, src_rest, no_loop, scope))
  1135. return 1;
  1136. }
  1137. }
  1138. return 0;
  1139. }
  1140. /* Expand macro references in SRC, appending the results to DEST.
  1141. Assume we are re-scanning the result of expanding the macros named
  1142. in NO_LOOP, and don't try to re-expand references to them. */
  1143. static void
  1144. scan (growable_macro_buffer *dest,
  1145. shared_macro_buffer *src,
  1146. struct macro_name_list *no_loop,
  1147. const macro_scope &scope)
  1148. {
  1149. for (;;)
  1150. {
  1151. shared_macro_buffer tok;
  1152. const char *original_src_start = src->text;
  1153. /* Find the next token in SRC. */
  1154. if (! get_token (&tok, src))
  1155. break;
  1156. /* Just for aesthetics. If we skipped some whitespace, copy
  1157. that to DEST. */
  1158. if (tok.text > original_src_start)
  1159. {
  1160. dest->appendmem (original_src_start, tok.text - original_src_start);
  1161. dest->last_token = dest->len;
  1162. }
  1163. if (! maybe_expand (dest, &tok, src, no_loop, scope))
  1164. /* We didn't end up expanding tok as a macro reference, so
  1165. simply append it to dest. */
  1166. append_tokens_without_splicing (dest, &tok);
  1167. }
  1168. /* Just for aesthetics. If there was any trailing whitespace in
  1169. src, copy it to dest. */
  1170. if (src->len)
  1171. {
  1172. dest->appendmem (src->text, src->len);
  1173. dest->last_token = dest->len;
  1174. }
  1175. }
  1176. gdb::unique_xmalloc_ptr<char>
  1177. macro_expand (const char *source, const macro_scope &scope)
  1178. {
  1179. shared_macro_buffer src (source, strlen (source));
  1180. growable_macro_buffer dest (0);
  1181. dest.last_token = 0;
  1182. scan (&dest, &src, 0, scope);
  1183. dest.appendc ('\0');
  1184. return dest.release ();
  1185. }
  1186. gdb::unique_xmalloc_ptr<char>
  1187. macro_expand_once (const char *source, const macro_scope &scope)
  1188. {
  1189. error (_("Expand-once not implemented yet."));
  1190. }
  1191. gdb::unique_xmalloc_ptr<char>
  1192. macro_expand_next (const char **lexptr, const macro_scope &scope)
  1193. {
  1194. shared_macro_buffer tok;
  1195. /* Set up SRC to refer to the input text, pointed to by *lexptr. */
  1196. shared_macro_buffer src (*lexptr, strlen (*lexptr));
  1197. /* Set up DEST to receive the expansion, if there is one. */
  1198. growable_macro_buffer dest (0);
  1199. dest.last_token = 0;
  1200. /* Get the text's first preprocessing token. */
  1201. if (! get_token (&tok, &src))
  1202. return nullptr;
  1203. /* If it's a macro invocation, expand it. */
  1204. if (maybe_expand (&dest, &tok, &src, 0, scope))
  1205. {
  1206. /* It was a macro invocation! Package up the expansion as a
  1207. null-terminated string and return it. Set *lexptr to the
  1208. start of the next token in the input. */
  1209. dest.appendc ('\0');
  1210. *lexptr = src.text;
  1211. return dest.release ();
  1212. }
  1213. else
  1214. {
  1215. /* It wasn't a macro invocation. */
  1216. return nullptr;
  1217. }
  1218. }