prmacros.c revision 1.1 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: prmacros - Preprocessor #define macro support
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1 christos * Copyright (C) 2000 - 2013, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #include "aslcompiler.h"
45 1.1 christos #include "dtcompiler.h"
46 1.1 christos
47 1.1 christos
48 1.1 christos #define _COMPONENT ASL_PREPROCESSOR
49 1.1 christos ACPI_MODULE_NAME ("prmacros")
50 1.1 christos
51 1.1 christos
52 1.1 christos /*******************************************************************************
53 1.1 christos *
54 1.1 christos * FUNCTION: PrDumpPredefinedNames
55 1.1 christos *
56 1.1 christos * PARAMETERS: None
57 1.1 christos *
58 1.1 christos * RETURN: None
59 1.1 christos *
60 1.1 christos * DESCRIPTION: Dump the list of #defines. Used as the preprocessor starts, to
61 1.1 christos * display the names that were defined on the command line.
62 1.1 christos * Debug information only.
63 1.1 christos *
64 1.1 christos ******************************************************************************/
65 1.1 christos
66 1.1 christos void
67 1.1 christos PrDumpPredefinedNames (
68 1.1 christos void)
69 1.1 christos {
70 1.1 christos PR_DEFINE_INFO *DefineInfo;
71 1.1 christos
72 1.1 christos
73 1.1 christos DefineInfo = Gbl_DefineList;
74 1.1 christos while (DefineInfo)
75 1.1 christos {
76 1.1 christos DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
77 1.1 christos "Predefined #define: %s->%s\n",
78 1.1 christos 0, DefineInfo->Identifier, DefineInfo->Replacement);
79 1.1 christos
80 1.1 christos DefineInfo = DefineInfo->Next;
81 1.1 christos }
82 1.1 christos }
83 1.1 christos
84 1.1 christos
85 1.1 christos /*******************************************************************************
86 1.1 christos *
87 1.1 christos * FUNCTION: PrAddDefine
88 1.1 christos *
89 1.1 christos * PARAMETERS: Identifier - Name to be replaced
90 1.1 christos * Replacement - Replacement for Identifier
91 1.1 christos * Persist - Keep define across multiple compiles?
92 1.1 christos *
93 1.1 christos * RETURN: A new define_info struct. NULL on error.
94 1.1 christos *
95 1.1 christos * DESCRIPTION: Add a new #define to the global list
96 1.1 christos *
97 1.1 christos ******************************************************************************/
98 1.1 christos
99 1.1 christos PR_DEFINE_INFO *
100 1.1 christos PrAddDefine (
101 1.1 christos char *Identifier,
102 1.1 christos char *Replacement,
103 1.1 christos BOOLEAN Persist)
104 1.1 christos {
105 1.1 christos char *IdentifierString;
106 1.1 christos char *ReplacementString;
107 1.1 christos PR_DEFINE_INFO *DefineInfo;
108 1.1 christos
109 1.1 christos
110 1.1 christos if (!Replacement)
111 1.1 christos {
112 1.1 christos Replacement = "";
113 1.1 christos }
114 1.1 christos
115 1.1 christos /* Check for already-defined first */
116 1.1 christos
117 1.1 christos DefineInfo = PrMatchDefine (Identifier);
118 1.1 christos if (DefineInfo)
119 1.1 christos {
120 1.1 christos DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID,
121 1.1 christos "#define: name already exists: %s\n",
122 1.1 christos Gbl_CurrentLineNumber, Identifier);
123 1.1 christos
124 1.1 christos /*
125 1.1 christos * Name already exists. This is only an error if the target name
126 1.1 christos * is different.
127 1.1 christos */
128 1.1 christos if (strcmp (Replacement, DefineInfo->Replacement))
129 1.1 christos {
130 1.1 christos PrError (ASL_ERROR, ASL_MSG_EXISTING_NAME,
131 1.1 christos THIS_TOKEN_OFFSET (Identifier));
132 1.1 christos
133 1.1 christos return (NULL);
134 1.1 christos }
135 1.1 christos
136 1.1 christos return (DefineInfo);
137 1.1 christos }
138 1.1 christos
139 1.1 christos /* Copy input strings */
140 1.1 christos
141 1.1 christos IdentifierString = UtLocalCalloc (strlen (Identifier) + 1);
142 1.1 christos strcpy (IdentifierString, Identifier);
143 1.1 christos
144 1.1 christos ReplacementString = UtLocalCalloc (strlen (Replacement) + 1);
145 1.1 christos strcpy (ReplacementString, Replacement);
146 1.1 christos
147 1.1 christos /* Init and link new define info struct */
148 1.1 christos
149 1.1 christos DefineInfo = UtLocalCalloc (sizeof (PR_DEFINE_INFO));
150 1.1 christos DefineInfo->Replacement = ReplacementString;
151 1.1 christos DefineInfo->Identifier = IdentifierString;
152 1.1 christos DefineInfo->Persist = Persist;
153 1.1 christos
154 1.1 christos if (Gbl_DefineList)
155 1.1 christos {
156 1.1 christos Gbl_DefineList->Previous = DefineInfo;
157 1.1 christos }
158 1.1 christos
159 1.1 christos DefineInfo->Next = Gbl_DefineList;
160 1.1 christos Gbl_DefineList = DefineInfo;
161 1.1 christos return (DefineInfo);
162 1.1 christos }
163 1.1 christos
164 1.1 christos
165 1.1 christos /*******************************************************************************
166 1.1 christos *
167 1.1 christos * FUNCTION: PrRemoveDefine
168 1.1 christos *
169 1.1 christos * PARAMETERS: DefineName - Name of define to be removed
170 1.1 christos *
171 1.1 christos * RETURN: None
172 1.1 christos *
173 1.1 christos * DESCRIPTION: Implements #undef. Remove a #define if found in the global
174 1.1 christos * list. No error if the target of the #undef does not exist,
175 1.1 christos * as per the C #undef definition.
176 1.1 christos *
177 1.1 christos ******************************************************************************/
178 1.1 christos
179 1.1 christos void
180 1.1 christos PrRemoveDefine (
181 1.1 christos char *DefineName)
182 1.1 christos {
183 1.1 christos PR_DEFINE_INFO *DefineInfo;
184 1.1 christos
185 1.1 christos
186 1.1 christos /* Match name and delete the node */
187 1.1 christos
188 1.1 christos DefineInfo = Gbl_DefineList;
189 1.1 christos while (DefineInfo)
190 1.1 christos {
191 1.1 christos if (!strcmp (DefineName, DefineInfo->Identifier))
192 1.1 christos {
193 1.1 christos /* Remove from linked list */
194 1.1 christos
195 1.1 christos if (DefineInfo->Previous)
196 1.1 christos {
197 1.1 christos (DefineInfo->Previous)->Next = DefineInfo->Next;
198 1.1 christos }
199 1.1 christos else
200 1.1 christos {
201 1.1 christos Gbl_DefineList = DefineInfo->Next;
202 1.1 christos }
203 1.1 christos
204 1.1 christos if (DefineInfo->Next)
205 1.1 christos {
206 1.1 christos (DefineInfo->Next)->Previous = DefineInfo->Previous;
207 1.1 christos }
208 1.1 christos
209 1.1 christos free (DefineInfo);
210 1.1 christos return;
211 1.1 christos }
212 1.1 christos
213 1.1 christos DefineInfo = DefineInfo->Next;
214 1.1 christos }
215 1.1 christos
216 1.1 christos /*
217 1.1 christos * Name was not found. By definition of #undef, this is not
218 1.1 christos * an error, however.
219 1.1 christos */
220 1.1 christos DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
221 1.1 christos "#undef: could not find %s\n",
222 1.1 christos Gbl_CurrentLineNumber, DefineName);
223 1.1 christos }
224 1.1 christos
225 1.1 christos
226 1.1 christos /*******************************************************************************
227 1.1 christos *
228 1.1 christos * FUNCTION: PrMatchDefine
229 1.1 christos *
230 1.1 christos * PARAMETERS: MatchString - Name associated with the #define
231 1.1 christos *
232 1.1 christos * RETURN: Matched string if found. NULL otherwise.
233 1.1 christos *
234 1.1 christos * DESCRIPTION: Find a name in global #define list
235 1.1 christos *
236 1.1 christos ******************************************************************************/
237 1.1 christos
238 1.1 christos PR_DEFINE_INFO *
239 1.1 christos PrMatchDefine (
240 1.1 christos char *MatchString)
241 1.1 christos {
242 1.1 christos PR_DEFINE_INFO *DefineInfo;
243 1.1 christos
244 1.1 christos
245 1.1 christos DefineInfo = Gbl_DefineList;
246 1.1 christos while (DefineInfo)
247 1.1 christos {
248 1.1 christos if (!strcmp (MatchString, DefineInfo->Identifier))
249 1.1 christos {
250 1.1 christos return (DefineInfo);
251 1.1 christos }
252 1.1 christos
253 1.1 christos DefineInfo = DefineInfo->Next;
254 1.1 christos }
255 1.1 christos
256 1.1 christos return (NULL);
257 1.1 christos }
258 1.1 christos
259 1.1 christos
260 1.1 christos /*******************************************************************************
261 1.1 christos *
262 1.1 christos * FUNCTION: PrAddMacro
263 1.1 christos *
264 1.1 christos * PARAMETERS: Name - Start of the macro definition
265 1.1 christos * Next - "Next" buffer from GetNextToken
266 1.1 christos *
267 1.1 christos * RETURN: None
268 1.1 christos *
269 1.1 christos * DESCRIPTION: Add a new macro to the list of #defines. Handles argument
270 1.1 christos * processing.
271 1.1 christos *
272 1.1 christos ******************************************************************************/
273 1.1 christos
274 1.1 christos void
275 1.1 christos PrAddMacro (
276 1.1 christos char *Name,
277 1.1 christos char **Next)
278 1.1 christos {
279 1.1 christos char *Token = NULL;
280 1.1 christos ACPI_SIZE TokenOffset;
281 1.1 christos ACPI_SIZE MacroBodyOffset;
282 1.1 christos PR_DEFINE_INFO *DefineInfo;
283 1.1 christos PR_MACRO_ARG *Args;
284 1.1 christos char *Body;
285 1.1 christos char *BodyInSource;
286 1.1 christos UINT32 i;
287 1.1 christos UINT16 UseCount = 0;
288 1.1 christos UINT16 ArgCount = 0;
289 1.1 christos UINT32 Depth = 1;
290 1.1 christos UINT32 EndOfArgList;
291 1.1 christos char BufferChar;
292 1.1 christos
293 1.1 christos
294 1.1 christos /* Find the end of the arguments list */
295 1.1 christos
296 1.1 christos TokenOffset = Name - Gbl_MainTokenBuffer + strlen (Name) + 1;
297 1.1 christos while (1)
298 1.1 christos {
299 1.1 christos BufferChar = Gbl_CurrentLineBuffer[TokenOffset];
300 1.1 christos if (BufferChar == '(')
301 1.1 christos {
302 1.1 christos Depth++;
303 1.1 christos }
304 1.1 christos else if (BufferChar == ')')
305 1.1 christos {
306 1.1 christos Depth--;
307 1.1 christos }
308 1.1 christos else if (BufferChar == 0)
309 1.1 christos {
310 1.1 christos PrError (ASL_ERROR, ASL_MSG_MACRO_SYNTAX, TokenOffset);
311 1.1 christos return;
312 1.1 christos }
313 1.1 christos
314 1.1 christos if (Depth == 0)
315 1.1 christos {
316 1.1 christos /* Found arg list end */
317 1.1 christos
318 1.1 christos EndOfArgList = TokenOffset;
319 1.1 christos break;
320 1.1 christos }
321 1.1 christos
322 1.1 christos TokenOffset++;
323 1.1 christos }
324 1.1 christos
325 1.1 christos /* At this point, we know that we have a reasonable argument list */
326 1.1 christos
327 1.1 christos Args = UtLocalCalloc (sizeof (PR_MACRO_ARG) * PR_MAX_MACRO_ARGS);
328 1.1 christos
329 1.1 christos /* Get the macro argument names */
330 1.1 christos
331 1.1 christos for (i = 0; i < PR_MAX_MACRO_ARGS; i++)
332 1.1 christos {
333 1.1 christos Token = PrGetNextToken (NULL, PR_MACRO_SEPARATORS, Next);
334 1.1 christos if (!Token)
335 1.1 christos {
336 1.1 christos /* This is the case for a NULL macro body */
337 1.1 christos
338 1.1 christos BodyInSource = "";
339 1.1 christos goto AddMacroToList;
340 1.1 christos }
341 1.1 christos
342 1.1 christos /* Don't go beyond the argument list */
343 1.1 christos
344 1.1 christos TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token);
345 1.1 christos if (TokenOffset > EndOfArgList)
346 1.1 christos {
347 1.1 christos break;
348 1.1 christos }
349 1.1 christos
350 1.1 christos DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
351 1.1 christos "Macro arg: %s \n",
352 1.1 christos Gbl_CurrentLineNumber, Token);
353 1.1 christos
354 1.1 christos Args[i].Name = UtLocalCalloc (strlen (Token) + 1);
355 1.1 christos strcpy (Args[i].Name, Token);
356 1.1 christos
357 1.1 christos Args[i].UseCount = 0;
358 1.1 christos
359 1.1 christos ArgCount++;
360 1.1 christos if (ArgCount >= PR_MAX_MACRO_ARGS)
361 1.1 christos {
362 1.1 christos PrError (ASL_ERROR, ASL_MSG_TOO_MANY_ARGUMENTS, TokenOffset);
363 1.1 christos return;
364 1.1 christos }
365 1.1 christos }
366 1.1 christos
367 1.1 christos /* Get the macro body. Token now points to start of body */
368 1.1 christos
369 1.1 christos MacroBodyOffset = Token - Gbl_MainTokenBuffer;
370 1.1 christos
371 1.1 christos /* Match each method arg in the macro body for later use */
372 1.1 christos
373 1.1 christos Token = PrGetNextToken (NULL, PR_MACRO_SEPARATORS, Next);
374 1.1 christos while (Token)
375 1.1 christos {
376 1.1 christos /* Search the macro arg list for matching arg */
377 1.1 christos
378 1.1 christos for (i = 0; Args[i].Name && (i < PR_MAX_MACRO_ARGS); i++)
379 1.1 christos {
380 1.1 christos /*
381 1.1 christos * Save argument offset within macro body. This is the mechanism
382 1.1 christos * used to expand the macro upon invocation.
383 1.1 christos *
384 1.1 christos * Handles multiple instances of the same argument
385 1.1 christos */
386 1.1 christos if (!strcmp (Token, Args[i].Name))
387 1.1 christos {
388 1.1 christos UseCount = Args[i].UseCount;
389 1.1 christos
390 1.1 christos Args[i].Offset[UseCount] = (Token - Gbl_MainTokenBuffer) - MacroBodyOffset;
391 1.1 christos
392 1.1 christos DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
393 1.1 christos "Macro Arg #%u: %s UseCount %u Offset %u \n",
394 1.1 christos Gbl_CurrentLineNumber, i, Token,
395 1.1 christos UseCount+1, Args[i].Offset[UseCount]);
396 1.1 christos
397 1.1 christos Args[i].UseCount++;
398 1.1 christos if (Args[i].UseCount >= PR_MAX_ARG_INSTANCES)
399 1.1 christos {
400 1.1 christos PrError (ASL_ERROR, ASL_MSG_TOO_MANY_ARGUMENTS,
401 1.1 christos THIS_TOKEN_OFFSET (Token));
402 1.1 christos
403 1.1 christos return;
404 1.1 christos }
405 1.1 christos break;
406 1.1 christos }
407 1.1 christos }
408 1.1 christos
409 1.1 christos Token = PrGetNextToken (NULL, PR_MACRO_SEPARATORS, Next);
410 1.1 christos }
411 1.1 christos
412 1.1 christos BodyInSource = &Gbl_CurrentLineBuffer[MacroBodyOffset];
413 1.1 christos
414 1.1 christos
415 1.1 christos AddMacroToList:
416 1.1 christos
417 1.1 christos /* Check if name is already defined first */
418 1.1 christos
419 1.1 christos DefineInfo = PrMatchDefine (Name);
420 1.1 christos if (DefineInfo)
421 1.1 christos {
422 1.1 christos DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
423 1.1 christos "#define: macro name already exists: %s\n",
424 1.1 christos Gbl_CurrentLineNumber, Name);
425 1.1 christos
426 1.1 christos /* Error only if not exactly the same macro */
427 1.1 christos
428 1.1 christos if (strcmp (DefineInfo->Body, BodyInSource) ||
429 1.1 christos (DefineInfo->ArgCount != ArgCount))
430 1.1 christos {
431 1.1 christos PrError (ASL_ERROR, ASL_MSG_EXISTING_NAME,
432 1.1 christos THIS_TOKEN_OFFSET (Name));
433 1.1 christos }
434 1.1 christos
435 1.1 christos return;
436 1.1 christos }
437 1.1 christos
438 1.1 christos DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
439 1.1 christos "Macro body: %s \n",
440 1.1 christos Gbl_CurrentLineNumber, BodyInSource);
441 1.1 christos
442 1.1 christos /* Add macro to the #define list */
443 1.1 christos
444 1.1 christos DefineInfo = PrAddDefine (Name, BodyInSource, FALSE);
445 1.1 christos if (DefineInfo)
446 1.1 christos {
447 1.1 christos Body = UtLocalCalloc (strlen (BodyInSource) + 1);
448 1.1 christos strcpy (Body, BodyInSource);
449 1.1 christos
450 1.1 christos DefineInfo->Body = Body;
451 1.1 christos DefineInfo->Args = Args;
452 1.1 christos DefineInfo->ArgCount = ArgCount;
453 1.1 christos }
454 1.1 christos }
455 1.1 christos
456 1.1 christos
457 1.1 christos /*******************************************************************************
458 1.1 christos *
459 1.1 christos * FUNCTION: PrDoMacroInvocation
460 1.1 christos *
461 1.1 christos * PARAMETERS: TokenBuffer - Current line buffer
462 1.1 christos * MacroStart - Start of the macro invocation within
463 1.1 christos * the token buffer
464 1.1 christos * DefineInfo - Info for this macro
465 1.1 christos * Next - "Next" buffer from GetNextToken
466 1.1 christos *
467 1.1 christos * RETURN: None
468 1.1 christos *
469 1.1 christos * DESCRIPTION: Expand a macro invocation
470 1.1 christos *
471 1.1 christos ******************************************************************************/
472 1.1 christos
473 1.1 christos void
474 1.1 christos PrDoMacroInvocation (
475 1.1 christos char *TokenBuffer,
476 1.1 christos char *MacroStart,
477 1.1 christos PR_DEFINE_INFO *DefineInfo,
478 1.1 christos char **Next)
479 1.1 christos {
480 1.1 christos PR_MACRO_ARG *Args;
481 1.1 christos char *Token = NULL;
482 1.1 christos UINT32 TokenOffset;
483 1.1 christos UINT32 Length;
484 1.1 christos UINT32 i;
485 1.1 christos
486 1.1 christos
487 1.1 christos /* Take a copy of the macro body for expansion */
488 1.1 christos
489 1.1 christos strcpy (Gbl_MacroTokenBuffer, DefineInfo->Body);
490 1.1 christos
491 1.1 christos /* Replace each argument within the prototype body */
492 1.1 christos
493 1.1 christos Args = DefineInfo->Args;
494 1.1 christos if (!Args->Name)
495 1.1 christos {
496 1.1 christos /* This macro has no arguments */
497 1.1 christos
498 1.1 christos Token = PrGetNextToken (NULL, PR_MACRO_ARGUMENTS, Next);
499 1.1 christos if (!Token)
500 1.1 christos {
501 1.1 christos goto BadInvocation;
502 1.1 christos }
503 1.1 christos
504 1.1 christos TokenOffset = (MacroStart - TokenBuffer);
505 1.1 christos Length = Token - MacroStart + strlen (Token) + 1;
506 1.1 christos
507 1.1 christos PrReplaceData (
508 1.1 christos &Gbl_CurrentLineBuffer[TokenOffset], Length,
509 1.1 christos Gbl_MacroTokenBuffer, strlen (Gbl_MacroTokenBuffer));
510 1.1 christos return;
511 1.1 christos }
512 1.1 christos
513 1.1 christos while (Args->Name)
514 1.1 christos {
515 1.1 christos /* Get the next argument from macro invocation */
516 1.1 christos
517 1.1 christos Token = PrGetNextToken (NULL, PR_MACRO_SEPARATORS, Next);
518 1.1 christos if (!Token)
519 1.1 christos {
520 1.1 christos goto BadInvocation;
521 1.1 christos }
522 1.1 christos
523 1.1 christos /* Replace all instances of this argument */
524 1.1 christos
525 1.1 christos for (i = 0; i < Args->UseCount; i++)
526 1.1 christos {
527 1.1 christos /* Offset zero indicates "arg not used" */
528 1.1 christos /* TBD: Not really needed now, with UseCount available */
529 1.1 christos
530 1.1 christos if (Args->Offset[i] == 0)
531 1.1 christos {
532 1.1 christos break;
533 1.1 christos }
534 1.1 christos
535 1.1 christos PrReplaceData (
536 1.1 christos &Gbl_MacroTokenBuffer[Args->Offset[i]], strlen (Args->Name),
537 1.1 christos Token, strlen (Token));
538 1.1 christos
539 1.1 christos DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
540 1.1 christos "ExpandArg: %s \n",
541 1.1 christos Gbl_CurrentLineNumber, Gbl_MacroTokenBuffer);
542 1.1 christos }
543 1.1 christos
544 1.1 christos Args++;
545 1.1 christos }
546 1.1 christos
547 1.1 christos /* TBD: need to make sure macro was not invoked with too many arguments */
548 1.1 christos
549 1.1 christos if (!Token)
550 1.1 christos {
551 1.1 christos return;
552 1.1 christos }
553 1.1 christos
554 1.1 christos /* Replace the entire macro invocation with the expanded macro */
555 1.1 christos
556 1.1 christos TokenOffset = (MacroStart - TokenBuffer);
557 1.1 christos Length = Token - MacroStart + strlen (Token) + 1;
558 1.1 christos
559 1.1 christos PrReplaceData (
560 1.1 christos &Gbl_CurrentLineBuffer[TokenOffset], Length,
561 1.1 christos Gbl_MacroTokenBuffer, strlen (Gbl_MacroTokenBuffer));
562 1.1 christos
563 1.1 christos return;
564 1.1 christos
565 1.1 christos
566 1.1 christos BadInvocation:
567 1.1 christos PrError (ASL_ERROR, ASL_MSG_INVALID_INVOCATION,
568 1.1 christos THIS_TOKEN_OFFSET (MacroStart));
569 1.1 christos
570 1.1 christos DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
571 1.1 christos "Bad macro invocation: %s \n",
572 1.1 christos Gbl_CurrentLineNumber, Gbl_MacroTokenBuffer);
573 1.1 christos return;
574 1.1 christos }
575