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