aslsupport.l revision 1.1 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: aslsupport.l - Flex/lex scanner C support routines.
4 1.1 christos * NOTE: Included into aslcompile.l, not compiled by itself.
5 1.1 christos *
6 1.1 christos *****************************************************************************/
7 1.1 christos
8 1.1 christos /*
9 1.1 christos * Copyright (C) 2000 - 2013, Intel Corp.
10 1.1 christos * All rights reserved.
11 1.1 christos *
12 1.1 christos * Redistribution and use in source and binary forms, with or without
13 1.1 christos * modification, are permitted provided that the following conditions
14 1.1 christos * are met:
15 1.1 christos * 1. Redistributions of source code must retain the above copyright
16 1.1 christos * notice, this list of conditions, and the following disclaimer,
17 1.1 christos * without modification.
18 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1 christos * including a substantially similar Disclaimer requirement for further
22 1.1 christos * binary redistribution.
23 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1 christos * of any contributors may be used to endorse or promote products derived
25 1.1 christos * from this software without specific prior written permission.
26 1.1 christos *
27 1.1 christos * Alternatively, this software may be distributed under the terms of the
28 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1 christos * Software Foundation.
30 1.1 christos *
31 1.1 christos * NO WARRANTY
32 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
43 1.1 christos */
44 1.1 christos
45 1.1 christos
46 1.1 christos /* Configuration */
47 1.1 christos
48 1.1 christos #define ASL_SPACES_PER_TAB 4
49 1.1 christos
50 1.1 christos #define ASL_NORMAL_CHAR 0
51 1.1 christos #define ASL_ESCAPE_SEQUENCE 1
52 1.1 christos #define ASL_OCTAL_CONSTANT 2
53 1.1 christos #define ASL_HEX_CONSTANT 3
54 1.1 christos
55 1.1 christos
56 1.1 christos /* File node - used for "Include" operator file stack */
57 1.1 christos
58 1.1 christos typedef struct asl_file_node
59 1.1 christos {
60 1.1 christos FILE *File;
61 1.1 christos UINT32 CurrentLineNumber;
62 1.1 christos YY_BUFFER_STATE State;
63 1.1 christos char *Filename;
64 1.1 christos struct asl_file_node *Next;
65 1.1 christos
66 1.1 christos } ASL_FILE_NODE;
67 1.1 christos
68 1.1 christos /* File stack for the "Include" operator (NOT #include operator) */
69 1.1 christos
70 1.1 christos ASL_FILE_NODE *Gbl_IncludeFileStack = NULL;
71 1.1 christos
72 1.1 christos
73 1.1 christos /*******************************************************************************
74 1.1 christos *
75 1.1 christos * FUNCTION: AslDoLineDirective
76 1.1 christos *
77 1.1 christos * PARAMETERS: None. Uses input() to access current source code line
78 1.1 christos *
79 1.1 christos * RETURN: Updates global line number and filename
80 1.1 christos *
81 1.1 christos * DESCRIPTION: Handle #line directives emitted by the preprocessor.
82 1.1 christos *
83 1.1 christos * The #line directive is emitted by the preprocesser, and is used to
84 1.1 christos * pass through line numbers from the original source code file to the
85 1.1 christos * preprocessor output file (.i). This allows any compiler-generated
86 1.1 christos * error messages to be displayed with the correct line number.
87 1.1 christos *
88 1.1 christos ******************************************************************************/
89 1.1 christos
90 1.1 christos static void
91 1.1 christos AslDoLineDirective (
92 1.1 christos void)
93 1.1 christos {
94 1.1 christos int c;
95 1.1 christos char *Token;
96 1.1 christos UINT32 LineNumber;
97 1.1 christos char *Filename;
98 1.1 christos UINT32 i;
99 1.1 christos
100 1.1 christos
101 1.1 christos /* Eat the entire line that contains the #line directive */
102 1.1 christos
103 1.1 christos Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
104 1.1 christos
105 1.1 christos while ((c = input()) != '\n' && c != EOF)
106 1.1 christos {
107 1.1 christos *Gbl_LineBufPtr = c;
108 1.1 christos Gbl_LineBufPtr++;
109 1.1 christos }
110 1.1 christos *Gbl_LineBufPtr = 0;
111 1.1 christos
112 1.1 christos /* First argument is the actual line number */
113 1.1 christos
114 1.1 christos Token = strtok (Gbl_CurrentLineBuffer, " ");
115 1.1 christos if (!Token)
116 1.1 christos {
117 1.1 christos goto ResetAndExit;
118 1.1 christos }
119 1.1 christos
120 1.1 christos /* First argument is the line number */
121 1.1 christos
122 1.1 christos LineNumber = (UINT32) UtDoConstant (Token);
123 1.1 christos
124 1.1 christos /* Emit the appropriate number of newlines */
125 1.1 christos
126 1.1 christos Gbl_CurrentColumn = 0;
127 1.1 christos if (LineNumber > Gbl_CurrentLineNumber)
128 1.1 christos {
129 1.1 christos for (i = 0; i < (LineNumber - Gbl_CurrentLineNumber); i++)
130 1.1 christos {
131 1.1 christos FlWriteFile (ASL_FILE_SOURCE_OUTPUT, "\n", 1);
132 1.1 christos Gbl_CurrentColumn++;
133 1.1 christos }
134 1.1 christos }
135 1.1 christos
136 1.1 christos FlSetLineNumber (LineNumber);
137 1.1 christos
138 1.1 christos /* Second argument is the optional filename (in double quotes) */
139 1.1 christos
140 1.1 christos Token = strtok (NULL, " \"");
141 1.1 christos if (Token)
142 1.1 christos {
143 1.1 christos Filename = ACPI_ALLOCATE_ZEROED (strlen (Token) + 1);
144 1.1 christos strcpy (Filename, Token);
145 1.1 christos FlSetFilename (Filename);
146 1.1 christos }
147 1.1 christos
148 1.1 christos /* Third argument is not supported at this time */
149 1.1 christos
150 1.1 christos ResetAndExit:
151 1.1 christos
152 1.1 christos /* Reset globals for a new line */
153 1.1 christos
154 1.1 christos Gbl_CurrentLineOffset += Gbl_CurrentColumn;
155 1.1 christos Gbl_CurrentColumn = 0;
156 1.1 christos Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
157 1.1 christos }
158 1.1 christos
159 1.1 christos
160 1.1 christos /*******************************************************************************
161 1.1 christos *
162 1.1 christos * FUNCTION: AslPopInputFileStack
163 1.1 christos *
164 1.1 christos * PARAMETERS: None
165 1.1 christos *
166 1.1 christos * RETURN: 0 if a node was popped, -1 otherwise
167 1.1 christos *
168 1.1 christos * DESCRIPTION: Pop the top of the input file stack and point the parser to
169 1.1 christos * the saved parse buffer contained in the fnode. Also, set the
170 1.1 christos * global line counters to the saved values. This function is
171 1.1 christos * called when an include file reaches EOF.
172 1.1 christos *
173 1.1 christos ******************************************************************************/
174 1.1 christos
175 1.1 christos int
176 1.1 christos AslPopInputFileStack (
177 1.1 christos void)
178 1.1 christos {
179 1.1 christos ASL_FILE_NODE *Fnode;
180 1.1 christos
181 1.1 christos
182 1.1 christos Fnode = Gbl_IncludeFileStack;
183 1.1 christos DbgPrint (ASL_PARSE_OUTPUT, "\nPop InputFile Stack, Fnode %p\n\n", Fnode);
184 1.1 christos
185 1.1 christos if (!Fnode)
186 1.1 christos {
187 1.1 christos return (-1);
188 1.1 christos }
189 1.1 christos
190 1.1 christos /* Close the current include file */
191 1.1 christos
192 1.1 christos fclose (yyin);
193 1.1 christos
194 1.1 christos /* Update the top-of-stack */
195 1.1 christos
196 1.1 christos Gbl_IncludeFileStack = Fnode->Next;
197 1.1 christos
198 1.1 christos /* Reset global line counter and filename */
199 1.1 christos
200 1.1 christos Gbl_Files[ASL_FILE_INPUT].Filename = Fnode->Filename;
201 1.1 christos Gbl_CurrentLineNumber = Fnode->CurrentLineNumber;
202 1.1 christos
203 1.1 christos /* Point the parser to the popped file */
204 1.1 christos
205 1.1 christos yy_delete_buffer (YY_CURRENT_BUFFER);
206 1.1 christos yy_switch_to_buffer (Fnode->State);
207 1.1 christos
208 1.1 christos /* All done with this node */
209 1.1 christos
210 1.1 christos ACPI_FREE (Fnode);
211 1.1 christos return (0);
212 1.1 christos }
213 1.1 christos
214 1.1 christos
215 1.1 christos /*******************************************************************************
216 1.1 christos *
217 1.1 christos * FUNCTION: AslPushInputFileStack
218 1.1 christos *
219 1.1 christos * PARAMETERS: InputFile - Open file pointer
220 1.1 christos * Filename - Name of the file
221 1.1 christos *
222 1.1 christos * RETURN: None
223 1.1 christos *
224 1.1 christos * DESCRIPTION: Push the InputFile onto the file stack, and point the parser
225 1.1 christos * to this file. Called when an include file is successfully
226 1.1 christos * opened.
227 1.1 christos *
228 1.1 christos ******************************************************************************/
229 1.1 christos
230 1.1 christos void
231 1.1 christos AslPushInputFileStack (
232 1.1 christos FILE *InputFile,
233 1.1 christos char *Filename)
234 1.1 christos {
235 1.1 christos ASL_FILE_NODE *Fnode;
236 1.1 christos YY_BUFFER_STATE State;
237 1.1 christos
238 1.1 christos
239 1.1 christos /* Save the current state in an Fnode */
240 1.1 christos
241 1.1 christos Fnode = UtLocalCalloc (sizeof (ASL_FILE_NODE));
242 1.1 christos
243 1.1 christos Fnode->File = yyin;
244 1.1 christos Fnode->Next = Gbl_IncludeFileStack;
245 1.1 christos Fnode->State = YY_CURRENT_BUFFER;
246 1.1 christos Fnode->CurrentLineNumber = Gbl_CurrentLineNumber;
247 1.1 christos Fnode->Filename = Gbl_Files[ASL_FILE_INPUT].Filename;
248 1.1 christos
249 1.1 christos /* Push it on the stack */
250 1.1 christos
251 1.1 christos Gbl_IncludeFileStack = Fnode;
252 1.1 christos
253 1.1 christos /* Point the parser to this file */
254 1.1 christos
255 1.1 christos State = yy_create_buffer (InputFile, YY_BUF_SIZE);
256 1.1 christos yy_switch_to_buffer (State);
257 1.1 christos
258 1.1 christos DbgPrint (ASL_PARSE_OUTPUT, "\nPush InputFile Stack, returning %p\n\n", InputFile);
259 1.1 christos
260 1.1 christos /* Reset the global line count and filename */
261 1.1 christos
262 1.1 christos Gbl_Files[ASL_FILE_INPUT].Filename = Filename;
263 1.1 christos Gbl_CurrentLineNumber = 1;
264 1.1 christos yyin = InputFile;
265 1.1 christos }
266 1.1 christos
267 1.1 christos
268 1.1 christos /*******************************************************************************
269 1.1 christos *
270 1.1 christos * FUNCTION: AslResetCurrentLineBuffer
271 1.1 christos *
272 1.1 christos * PARAMETERS: None
273 1.1 christos *
274 1.1 christos * RETURN: None
275 1.1 christos *
276 1.1 christos * DESCRIPTION: Reset the Line Buffer to zero, increment global line numbers.
277 1.1 christos *
278 1.1 christos ******************************************************************************/
279 1.1 christos
280 1.1 christos void
281 1.1 christos AslResetCurrentLineBuffer (
282 1.1 christos void)
283 1.1 christos {
284 1.1 christos
285 1.1 christos if (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle)
286 1.1 christos {
287 1.1 christos FlWriteFile (ASL_FILE_SOURCE_OUTPUT, Gbl_CurrentLineBuffer,
288 1.1 christos Gbl_LineBufPtr - Gbl_CurrentLineBuffer);
289 1.1 christos }
290 1.1 christos
291 1.1 christos Gbl_CurrentLineOffset += Gbl_CurrentColumn;
292 1.1 christos Gbl_CurrentColumn = 0;
293 1.1 christos
294 1.1 christos Gbl_CurrentLineNumber++;
295 1.1 christos Gbl_LogicalLineNumber++;
296 1.1 christos Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
297 1.1 christos }
298 1.1 christos
299 1.1 christos
300 1.1 christos /*******************************************************************************
301 1.1 christos *
302 1.1 christos * FUNCTION: AslInsertLineBuffer
303 1.1 christos *
304 1.1 christos * PARAMETERS: SourceChar - One char from the input ASL source file
305 1.1 christos *
306 1.1 christos * RETURN: None
307 1.1 christos *
308 1.1 christos * DESCRIPTION: Put one character of the source file into the temp line buffer
309 1.1 christos *
310 1.1 christos ******************************************************************************/
311 1.1 christos
312 1.1 christos void
313 1.1 christos AslInsertLineBuffer (
314 1.1 christos int SourceChar)
315 1.1 christos {
316 1.1 christos UINT32 i;
317 1.1 christos UINT32 Count = 1;
318 1.1 christos
319 1.1 christos
320 1.1 christos if (SourceChar == EOF)
321 1.1 christos {
322 1.1 christos return;
323 1.1 christos }
324 1.1 christos
325 1.1 christos Gbl_InputByteCount++;
326 1.1 christos
327 1.1 christos /* Handle tabs. Convert to spaces */
328 1.1 christos
329 1.1 christos if (SourceChar == '\t')
330 1.1 christos {
331 1.1 christos SourceChar = ' ';
332 1.1 christos Count = ASL_SPACES_PER_TAB -
333 1.1 christos (Gbl_CurrentColumn & (ASL_SPACES_PER_TAB-1));
334 1.1 christos }
335 1.1 christos
336 1.1 christos for (i = 0; i < Count; i++)
337 1.1 christos {
338 1.1 christos Gbl_CurrentColumn++;
339 1.1 christos
340 1.1 christos /* Insert the character into the line buffer */
341 1.1 christos
342 1.1 christos *Gbl_LineBufPtr = (UINT8) SourceChar;
343 1.1 christos Gbl_LineBufPtr++;
344 1.1 christos
345 1.1 christos if (Gbl_LineBufPtr > (Gbl_CurrentLineBuffer + (Gbl_LineBufferSize - 1)))
346 1.1 christos {
347 1.1 christos #if 0
348 1.1 christos /*
349 1.1 christos * Warning if we have split a long source line.
350 1.1 christos * <Probably overkill>
351 1.1 christos */
352 1.1 christos sprintf (MsgBuffer, "Max %u", Gbl_LineBufferSize);
353 1.1 christos AslCommonError (ASL_WARNING, ASL_MSG_LONG_LINE,
354 1.1 christos Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
355 1.1 christos Gbl_CurrentLineOffset, Gbl_CurrentColumn,
356 1.1 christos Gbl_Files[ASL_FILE_INPUT].Filename, MsgBuffer);
357 1.1 christos #endif
358 1.1 christos
359 1.1 christos AslResetCurrentLineBuffer ();
360 1.1 christos }
361 1.1 christos else if (SourceChar == '\n')
362 1.1 christos {
363 1.1 christos /* End of line */
364 1.1 christos
365 1.1 christos AslResetCurrentLineBuffer ();
366 1.1 christos }
367 1.1 christos }
368 1.1 christos }
369 1.1 christos
370 1.1 christos
371 1.1 christos /*******************************************************************************
372 1.1 christos *
373 1.1 christos * FUNCTION: count
374 1.1 christos *
375 1.1 christos * PARAMETERS: yytext - Contains the matched keyword.
376 1.1 christos * Type - Keyword/Character type:
377 1.1 christos * 0 = anything except a keyword
378 1.1 christos * 1 = pseudo-keywords
379 1.1 christos * 2 = non-executable ASL keywords
380 1.1 christos * 3 = executable ASL keywords
381 1.1 christos *
382 1.1 christos * RETURN: None
383 1.1 christos *
384 1.1 christos * DESCRIPTION: Count keywords and put them into the line buffer
385 1.1 christos *
386 1.1 christos ******************************************************************************/
387 1.1 christos
388 1.1 christos static void
389 1.1 christos count (
390 1.1 christos int Type)
391 1.1 christos {
392 1.1 christos int i;
393 1.1 christos
394 1.1 christos
395 1.1 christos switch (Type)
396 1.1 christos {
397 1.1 christos case 2:
398 1.1 christos
399 1.1 christos TotalKeywords++;
400 1.1 christos TotalNamedObjects++;
401 1.1 christos break;
402 1.1 christos
403 1.1 christos case 3:
404 1.1 christos
405 1.1 christos TotalKeywords++;
406 1.1 christos TotalExecutableOpcodes++;
407 1.1 christos break;
408 1.1 christos
409 1.1 christos default:
410 1.1 christos
411 1.1 christos break;
412 1.1 christos }
413 1.1 christos
414 1.1 christos for (i = 0; (yytext[i] != 0) && (yytext[i] != EOF); i++)
415 1.1 christos {
416 1.1 christos AslInsertLineBuffer (yytext[i]);
417 1.1 christos *Gbl_LineBufPtr = 0;
418 1.1 christos }
419 1.1 christos }
420 1.1 christos
421 1.1 christos
422 1.1 christos /*******************************************************************************
423 1.1 christos *
424 1.1 christos * FUNCTION: AslDoComment
425 1.1 christos *
426 1.1 christos * PARAMETERS: none
427 1.1 christos *
428 1.1 christos * RETURN: none
429 1.1 christos *
430 1.1 christos * DESCRIPTION: Process a standard comment.
431 1.1 christos *
432 1.1 christos ******************************************************************************/
433 1.1 christos
434 1.1 christos static char
435 1.1 christos AslDoComment (
436 1.1 christos void)
437 1.1 christos {
438 1.1 christos int c;
439 1.1 christos int c1 = 0;
440 1.1 christos
441 1.1 christos
442 1.1 christos AslInsertLineBuffer ('/');
443 1.1 christos AslInsertLineBuffer ('*');
444 1.1 christos
445 1.1 christos loop:
446 1.1 christos
447 1.1 christos /* Eat chars until end-of-comment */
448 1.1 christos
449 1.1 christos while ((c = input()) != '*' && c != EOF)
450 1.1 christos {
451 1.1 christos AslInsertLineBuffer (c);
452 1.1 christos c1 = c;
453 1.1 christos }
454 1.1 christos
455 1.1 christos if (c == EOF)
456 1.1 christos {
457 1.1 christos goto EarlyEOF;
458 1.1 christos }
459 1.1 christos
460 1.1 christos /*
461 1.1 christos * Check for nested comment -- can help catch cases where a previous
462 1.1 christos * comment was accidently left unterminated
463 1.1 christos */
464 1.1 christos if ((c1 == '/') && (c == '*'))
465 1.1 christos {
466 1.1 christos AslCommonError (ASL_WARNING, ASL_MSG_NESTED_COMMENT,
467 1.1 christos Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
468 1.1 christos Gbl_InputByteCount, Gbl_CurrentColumn,
469 1.1 christos Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
470 1.1 christos }
471 1.1 christos
472 1.1 christos /* Comment is closed only if the NEXT character is a slash */
473 1.1 christos
474 1.1 christos AslInsertLineBuffer (c);
475 1.1 christos
476 1.1 christos if ((c1 = input()) != '/' && c1 != EOF)
477 1.1 christos {
478 1.1 christos unput(c1);
479 1.1 christos goto loop;
480 1.1 christos }
481 1.1 christos
482 1.1 christos if (c1 == EOF)
483 1.1 christos {
484 1.1 christos goto EarlyEOF;
485 1.1 christos }
486 1.1 christos
487 1.1 christos AslInsertLineBuffer (c1);
488 1.1 christos return (TRUE);
489 1.1 christos
490 1.1 christos
491 1.1 christos EarlyEOF:
492 1.1 christos /*
493 1.1 christos * Premature End-Of-File
494 1.1 christos */
495 1.1 christos AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF,
496 1.1 christos Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
497 1.1 christos Gbl_CurrentLineOffset, Gbl_CurrentColumn,
498 1.1 christos Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
499 1.1 christos return (FALSE);
500 1.1 christos }
501 1.1 christos
502 1.1 christos
503 1.1 christos /*******************************************************************************
504 1.1 christos *
505 1.1 christos * FUNCTION: AslDoCommentType2
506 1.1 christos *
507 1.1 christos * PARAMETERS: none
508 1.1 christos *
509 1.1 christos * RETURN: none
510 1.1 christos *
511 1.1 christos * DESCRIPTION: Process a new "//" comment.
512 1.1 christos *
513 1.1 christos ******************************************************************************/
514 1.1 christos
515 1.1 christos static char
516 1.1 christos AslDoCommentType2 (
517 1.1 christos void)
518 1.1 christos {
519 1.1 christos int c;
520 1.1 christos
521 1.1 christos
522 1.1 christos AslInsertLineBuffer ('/');
523 1.1 christos AslInsertLineBuffer ('/');
524 1.1 christos
525 1.1 christos while ((c = input()) != '\n' && c != EOF)
526 1.1 christos {
527 1.1 christos AslInsertLineBuffer (c);
528 1.1 christos }
529 1.1 christos
530 1.1 christos if (c == EOF)
531 1.1 christos {
532 1.1 christos /* End of file is OK, change to newline. Let parser detect EOF later */
533 1.1 christos
534 1.1 christos c = '\n';
535 1.1 christos }
536 1.1 christos
537 1.1 christos AslInsertLineBuffer (c);
538 1.1 christos return (TRUE);
539 1.1 christos }
540 1.1 christos
541 1.1 christos
542 1.1 christos /*******************************************************************************
543 1.1 christos *
544 1.1 christos * FUNCTION: AslDoStringLiteral
545 1.1 christos *
546 1.1 christos * PARAMETERS: none
547 1.1 christos *
548 1.1 christos * RETURN: none
549 1.1 christos *
550 1.1 christos * DESCRIPTION: Process a string literal (surrounded by quotes)
551 1.1 christos *
552 1.1 christos ******************************************************************************/
553 1.1 christos
554 1.1 christos static char
555 1.1 christos AslDoStringLiteral (
556 1.1 christos void)
557 1.1 christos {
558 1.1 christos char *StringBuffer = MsgBuffer;
559 1.1 christos char *EndBuffer = MsgBuffer + ASL_MSG_BUFFER_SIZE;
560 1.1 christos char *CleanString;
561 1.1 christos int StringChar;
562 1.1 christos UINT32 State = ASL_NORMAL_CHAR;
563 1.1 christos UINT32 i = 0;
564 1.1 christos UINT8 Digit;
565 1.1 christos char ConvertBuffer[4];
566 1.1 christos
567 1.1 christos
568 1.1 christos /*
569 1.1 christos * Eat chars until end-of-literal.
570 1.1 christos * NOTE: Put back the original surrounding quotes into the
571 1.1 christos * source line buffer.
572 1.1 christos */
573 1.1 christos AslInsertLineBuffer ('\"');
574 1.1 christos while ((StringChar = input()) != EOF)
575 1.1 christos {
576 1.1 christos AslInsertLineBuffer (StringChar);
577 1.1 christos
578 1.1 christos DoCharacter:
579 1.1 christos switch (State)
580 1.1 christos {
581 1.1 christos case ASL_NORMAL_CHAR:
582 1.1 christos
583 1.1 christos switch (StringChar)
584 1.1 christos {
585 1.1 christos case '\\':
586 1.1 christos /*
587 1.1 christos * Special handling for backslash-escape sequence. We will
588 1.1 christos * toss the backslash and translate the escape char(s).
589 1.1 christos */
590 1.1 christos State = ASL_ESCAPE_SEQUENCE;
591 1.1 christos continue;
592 1.1 christos
593 1.1 christos case '\"':
594 1.1 christos
595 1.1 christos /* String terminator */
596 1.1 christos
597 1.1 christos goto CompletedString;
598 1.1 christos
599 1.1 christos default:
600 1.1 christos
601 1.1 christos break;
602 1.1 christos }
603 1.1 christos break;
604 1.1 christos
605 1.1 christos
606 1.1 christos case ASL_ESCAPE_SEQUENCE:
607 1.1 christos
608 1.1 christos State = ASL_NORMAL_CHAR;
609 1.1 christos switch (StringChar)
610 1.1 christos {
611 1.1 christos case 'a':
612 1.1 christos
613 1.1 christos StringChar = 0x07; /* BELL */
614 1.1 christos break;
615 1.1 christos
616 1.1 christos case 'b':
617 1.1 christos
618 1.1 christos StringChar = 0x08; /* BACKSPACE */
619 1.1 christos break;
620 1.1 christos
621 1.1 christos case 'f':
622 1.1 christos
623 1.1 christos StringChar = 0x0C; /* FORMFEED */
624 1.1 christos break;
625 1.1 christos
626 1.1 christos case 'n':
627 1.1 christos
628 1.1 christos StringChar = 0x0A; /* LINEFEED */
629 1.1 christos break;
630 1.1 christos
631 1.1 christos case 'r':
632 1.1 christos
633 1.1 christos StringChar = 0x0D; /* CARRIAGE RETURN*/
634 1.1 christos break;
635 1.1 christos
636 1.1 christos case 't':
637 1.1 christos
638 1.1 christos StringChar = 0x09; /* HORIZONTAL TAB */
639 1.1 christos break;
640 1.1 christos
641 1.1 christos case 'v':
642 1.1 christos
643 1.1 christos StringChar = 0x0B; /* VERTICAL TAB */
644 1.1 christos break;
645 1.1 christos
646 1.1 christos case 'x':
647 1.1 christos
648 1.1 christos State = ASL_HEX_CONSTANT;
649 1.1 christos i = 0;
650 1.1 christos continue;
651 1.1 christos
652 1.1 christos case '\'': /* Single Quote */
653 1.1 christos case '\"': /* Double Quote */
654 1.1 christos case '\\': /* Backslash */
655 1.1 christos
656 1.1 christos break;
657 1.1 christos
658 1.1 christos default:
659 1.1 christos
660 1.1 christos /* Check for an octal digit (0-7) */
661 1.1 christos
662 1.1 christos if (ACPI_IS_OCTAL_DIGIT (StringChar))
663 1.1 christos {
664 1.1 christos State = ASL_OCTAL_CONSTANT;
665 1.1 christos ConvertBuffer[0] = StringChar;
666 1.1 christos i = 1;
667 1.1 christos continue;
668 1.1 christos }
669 1.1 christos
670 1.1 christos /* Unknown escape sequence issue warning, but use the character */
671 1.1 christos
672 1.1 christos AslCommonError (ASL_WARNING, ASL_MSG_INVALID_ESCAPE,
673 1.1 christos Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
674 1.1 christos Gbl_CurrentLineOffset, Gbl_CurrentColumn,
675 1.1 christos Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
676 1.1 christos break;
677 1.1 christos }
678 1.1 christos break;
679 1.1 christos
680 1.1 christos
681 1.1 christos case ASL_OCTAL_CONSTANT:
682 1.1 christos
683 1.1 christos /* Up to three octal digits allowed */
684 1.1 christos
685 1.1 christos if (!ACPI_IS_OCTAL_DIGIT (StringChar) ||
686 1.1 christos (i > 2))
687 1.1 christos {
688 1.1 christos /*
689 1.1 christos * Reached end of the constant. Convert the assembled ASCII
690 1.1 christos * string and resume processing of the next character
691 1.1 christos */
692 1.1 christos ConvertBuffer[i] = 0;
693 1.1 christos Digit = (UINT8) ACPI_STRTOUL (ConvertBuffer, NULL, 8);
694 1.1 christos
695 1.1 christos /* Check for NULL or non-ascii character (ignore if so) */
696 1.1 christos
697 1.1 christos if ((Digit == 0) || (Digit > ACPI_ASCII_MAX))
698 1.1 christos {
699 1.1 christos AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING,
700 1.1 christos Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
701 1.1 christos Gbl_CurrentLineOffset, Gbl_CurrentColumn,
702 1.1 christos Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
703 1.1 christos }
704 1.1 christos else
705 1.1 christos {
706 1.1 christos *StringBuffer = (char) Digit;
707 1.1 christos StringBuffer++;
708 1.1 christos if (StringBuffer >= EndBuffer)
709 1.1 christos {
710 1.1 christos goto BufferOverflow;
711 1.1 christos }
712 1.1 christos }
713 1.1 christos
714 1.1 christos State = ASL_NORMAL_CHAR;
715 1.1 christos goto DoCharacter;
716 1.1 christos break;
717 1.1 christos }
718 1.1 christos
719 1.1 christos /* Append another digit of the constant */
720 1.1 christos
721 1.1 christos ConvertBuffer[i] = StringChar;
722 1.1 christos i++;
723 1.1 christos continue;
724 1.1 christos
725 1.1 christos case ASL_HEX_CONSTANT:
726 1.1 christos
727 1.1 christos /* Up to two hex digits allowed */
728 1.1 christos
729 1.1 christos if (!ACPI_IS_XDIGIT (StringChar) ||
730 1.1 christos (i > 1))
731 1.1 christos {
732 1.1 christos /*
733 1.1 christos * Reached end of the constant. Convert the assembled ASCII
734 1.1 christos * string and resume processing of the next character
735 1.1 christos */
736 1.1 christos ConvertBuffer[i] = 0;
737 1.1 christos Digit = (UINT8) ACPI_STRTOUL (ConvertBuffer, NULL, 16);
738 1.1 christos
739 1.1 christos /* Check for NULL or non-ascii character (ignore if so) */
740 1.1 christos
741 1.1 christos if ((Digit == 0) || (Digit > ACPI_ASCII_MAX))
742 1.1 christos {
743 1.1 christos AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING,
744 1.1 christos Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
745 1.1 christos Gbl_CurrentLineOffset, Gbl_CurrentColumn,
746 1.1 christos Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
747 1.1 christos }
748 1.1 christos else
749 1.1 christos {
750 1.1 christos *StringBuffer = (char) Digit;
751 1.1 christos StringBuffer++;
752 1.1 christos if (StringBuffer >= EndBuffer)
753 1.1 christos {
754 1.1 christos goto BufferOverflow;
755 1.1 christos }
756 1.1 christos }
757 1.1 christos
758 1.1 christos State = ASL_NORMAL_CHAR;
759 1.1 christos goto DoCharacter;
760 1.1 christos break;
761 1.1 christos }
762 1.1 christos
763 1.1 christos /* Append another digit of the constant */
764 1.1 christos
765 1.1 christos ConvertBuffer[i] = StringChar;
766 1.1 christos i++;
767 1.1 christos continue;
768 1.1 christos
769 1.1 christos default:
770 1.1 christos
771 1.1 christos break;
772 1.1 christos }
773 1.1 christos
774 1.1 christos /* Save the finished character */
775 1.1 christos
776 1.1 christos *StringBuffer = StringChar;
777 1.1 christos StringBuffer++;
778 1.1 christos if (StringBuffer >= EndBuffer)
779 1.1 christos {
780 1.1 christos goto BufferOverflow;
781 1.1 christos }
782 1.1 christos }
783 1.1 christos
784 1.1 christos /*
785 1.1 christos * Premature End-Of-File
786 1.1 christos */
787 1.1 christos AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF,
788 1.1 christos Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
789 1.1 christos Gbl_CurrentLineOffset, Gbl_CurrentColumn,
790 1.1 christos Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
791 1.1 christos return (FALSE);
792 1.1 christos
793 1.1 christos
794 1.1 christos CompletedString:
795 1.1 christos /*
796 1.1 christos * Null terminate the input string and copy string to a new buffer
797 1.1 christos */
798 1.1 christos *StringBuffer = 0;
799 1.1 christos
800 1.1 christos CleanString = UtGetStringBuffer (strlen (MsgBuffer) + 1);
801 1.1 christos if (!CleanString)
802 1.1 christos {
803 1.1 christos AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION,
804 1.1 christos Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
805 1.1 christos Gbl_CurrentLineOffset, Gbl_CurrentColumn,
806 1.1 christos Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
807 1.1 christos return (FALSE);
808 1.1 christos }
809 1.1 christos
810 1.1 christos ACPI_STRCPY (CleanString, MsgBuffer);
811 1.1 christos AslCompilerlval.s = CleanString;
812 1.1 christos return (TRUE);
813 1.1 christos
814 1.1 christos
815 1.1 christos BufferOverflow:
816 1.1 christos
817 1.1 christos /* Literal was too long */
818 1.1 christos
819 1.1 christos AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH,
820 1.1 christos Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
821 1.1 christos Gbl_CurrentLineOffset, Gbl_CurrentColumn,
822 1.1 christos Gbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096");
823 1.1 christos return (FALSE);
824 1.1 christos }
825