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