xref: /freebsd/sys/contrib/dev/acpica/compiler/aslsupport.l (revision ca86bcf2531c7b149c95244a67853d44323e7855)
1 /******************************************************************************
2  *
3  * Module Name: aslsupport.l - Flex/lex scanner C support routines.
4  *              NOTE: Included into aslcompile.l, not compiled by itself.
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights. You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code. No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision. In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change. Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee. Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution. In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government. In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************
116  *
117  * Alternatively, you may choose to be licensed under the terms of the
118  * following license:
119  *
120  * Redistribution and use in source and binary forms, with or without
121  * modification, are permitted provided that the following conditions
122  * are met:
123  * 1. Redistributions of source code must retain the above copyright
124  *    notice, this list of conditions, and the following disclaimer,
125  *    without modification.
126  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
127  *    substantially similar to the "NO WARRANTY" disclaimer below
128  *    ("Disclaimer") and any redistribution must be conditioned upon
129  *    including a substantially similar Disclaimer requirement for further
130  *    binary redistribution.
131  * 3. Neither the names of the above-listed copyright holders nor the names
132  *    of any contributors may be used to endorse or promote products derived
133  *    from this software without specific prior written permission.
134  *
135  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
136  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
138  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146  *
147  * Alternatively, you may choose to be licensed under the terms of the
148  * GNU General Public License ("GPL") version 2 as published by the Free
149  * Software Foundation.
150  *
151  *****************************************************************************/
152 
153 /* Configuration */
154 
155 #define ASL_SPACES_PER_TAB      4
156 
157 #define ASL_NORMAL_CHAR         0
158 #define ASL_ESCAPE_SEQUENCE     1
159 #define ASL_OCTAL_CONSTANT      2
160 #define ASL_HEX_CONSTANT        3
161 
162 
163 void
164 yyerror (char const *s)
165 {
166 
167   AcpiOsPrintf ("YYERROR: %s\n", s);
168 }
169 
170 
171 /*******************************************************************************
172  *
173  * FUNCTION:    AslParserCleanup
174  *
175  * Used to delete the current buffer
176  *
177  ******************************************************************************/
178 
179 void
180 AslParserCleanup (
181     void)
182 {
183 
184     yy_delete_buffer (YY_CURRENT_BUFFER);
185 }
186 
187 
188 /*******************************************************************************
189  *
190  * FUNCTION:    AslDoLineDirective
191  *
192  * PARAMETERS:  None. Uses input() to access current source code line
193  *
194  * RETURN:      Updates global line number and filename
195  *
196  * DESCRIPTION: Handle #line directives emitted by the preprocessor.
197  *
198  * The #line directive is emitted by the preprocesser, and is used to
199  * pass through line numbers from the original source code file to the
200  * preprocessor output file (.i). This allows any compiler-generated
201  * error messages to be displayed with the correct line number.
202  *
203  ******************************************************************************/
204 
205 static void
206 AslDoLineDirective (
207     void)
208 {
209     int                     c;
210     char                    *Token;
211     UINT32                  LineNumber;
212     char                    *Filename;
213     UINT32                  i;
214 
215    Gbl_HasIncludeFiles = TRUE;
216 
217     /* Eat the entire line that contains the #line directive */
218 
219     Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
220 
221     while ((c = input()) != '\n' && c != EOF)
222     {
223         *Gbl_LineBufPtr = c;
224         Gbl_LineBufPtr++;
225     }
226     *Gbl_LineBufPtr = 0;
227 
228     /* First argument is the actual line number */
229 
230     Token = strtok (Gbl_CurrentLineBuffer, " ");
231     if (!Token)
232     {
233         goto ResetAndExit;
234     }
235 
236     /* First argument is the line number */
237 
238     LineNumber = (UINT32) UtDoConstant (Token);
239 
240     /* Emit the appropriate number of newlines */
241 
242     Gbl_CurrentColumn = 0;
243     if (LineNumber > Gbl_CurrentLineNumber)
244     {
245         for (i = 0; i < (LineNumber - Gbl_CurrentLineNumber); i++)
246         {
247             FlWriteFile (ASL_FILE_SOURCE_OUTPUT, "\n", 1);
248             Gbl_CurrentColumn++;
249         }
250     }
251 
252     FlSetLineNumber (LineNumber);
253 
254     /* Second argument is the optional filename (in double quotes) */
255 
256     Token = strtok (NULL, " \"");
257     if (Token)
258     {
259         Filename = ACPI_ALLOCATE_ZEROED (strlen (Token) + 1);
260         strcpy (Filename, Token);
261         FlSetFilename (Filename);
262     }
263 
264     /* Third argument is not supported at this time */
265 
266 ResetAndExit:
267 
268     /* Reset globals for a new line */
269 
270     Gbl_CurrentLineOffset += Gbl_CurrentColumn;
271     Gbl_CurrentColumn = 0;
272     Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
273 }
274 
275 
276 /*******************************************************************************
277  *
278  * FUNCTION:    AslPopInputFileStack
279  *
280  * PARAMETERS:  None
281  *
282  * RETURN:      0 if a node was popped, -1 otherwise
283  *
284  * DESCRIPTION: Pop the top of the input file stack and point the parser to
285  *              the saved parse buffer contained in the fnode. Also, set the
286  *              global line counters to the saved values. This function is
287  *              called when an include file reaches EOF.
288  *
289  ******************************************************************************/
290 
291 int
292 AslPopInputFileStack (
293     void)
294 {
295     ASL_FILE_NODE           *Fnode;
296 
297 
298     Gbl_PreviousIncludeFilename = Gbl_Files[ASL_FILE_INPUT].Filename;
299     Fnode = Gbl_IncludeFileStack;
300     DbgPrint (ASL_PARSE_OUTPUT,
301         "\nPop InputFile Stack, Fnode %p\n", Fnode);
302 
303     DbgPrint (ASL_PARSE_OUTPUT,
304         "Include: Closing \"%s\"\n\n", Gbl_Files[ASL_FILE_INPUT].Filename);
305 
306     if (!Fnode)
307     {
308         return (-1);
309     }
310 
311     /* Close the current include file */
312 
313     fclose (yyin);
314 
315     /* Update the top-of-stack */
316 
317     Gbl_IncludeFileStack = Fnode->Next;
318 
319     /* Reset global line counter and filename */
320 
321     Gbl_Files[ASL_FILE_INPUT].Filename = Fnode->Filename;
322     Gbl_CurrentLineNumber = Fnode->CurrentLineNumber;
323 
324     /* Point the parser to the popped file */
325 
326     yy_delete_buffer (YY_CURRENT_BUFFER);
327     yy_switch_to_buffer (Fnode->State);
328 
329     /* All done with this node */
330 
331     ACPI_FREE (Fnode);
332     return (0);
333 }
334 
335 
336 /*******************************************************************************
337  *
338  * FUNCTION:    AslPushInputFileStack
339  *
340  * PARAMETERS:  InputFile           - Open file pointer
341  *              Filename            - Name of the file
342  *
343  * RETURN:      None
344  *
345  * DESCRIPTION: Push the InputFile onto the file stack, and point the parser
346  *              to this file. Called when an include file is successfully
347  *              opened.
348  *
349  ******************************************************************************/
350 
351 void
352 AslPushInputFileStack (
353     FILE                    *InputFile,
354     char                    *Filename)
355 {
356     ASL_FILE_NODE           *Fnode;
357     YY_BUFFER_STATE         State;
358 
359 
360     /* Save the current state in an Fnode */
361 
362     Fnode = UtLocalCalloc (sizeof (ASL_FILE_NODE));
363 
364     Fnode->File = yyin;
365     Fnode->Next = Gbl_IncludeFileStack;
366     Fnode->State = YY_CURRENT_BUFFER;
367     Fnode->Filename = Gbl_Files[ASL_FILE_INPUT].Filename;
368     Fnode->CurrentLineNumber = Gbl_CurrentLineNumber;
369 
370     /* Push it on the stack */
371 
372     Gbl_IncludeFileStack = Fnode;
373 
374     /* Point the parser to this file */
375 
376     State = yy_create_buffer (InputFile, YY_BUF_SIZE);
377     yy_switch_to_buffer (State);
378 
379     DbgPrint (ASL_PARSE_OUTPUT,
380         "\nPush InputFile Stack, returning %p\n\n", InputFile);
381 
382     /* Reset the global line count and filename */
383 
384     Gbl_Files[ASL_FILE_INPUT].Filename =
385         UtStringCacheCalloc (strlen (Filename) + 1);
386 
387     strcpy (Gbl_Files[ASL_FILE_INPUT].Filename, Filename);
388 
389     Gbl_CurrentLineNumber = 1;
390     yyin = InputFile;
391 
392     /* converter: reset the comment state to STANDARD_COMMENT */
393 
394     Gbl_CommentState.CommentType = STANDARD_COMMENT;
395 }
396 
397 
398 /*******************************************************************************
399  *
400  * FUNCTION:    AslResetCurrentLineBuffer
401  *
402  * PARAMETERS:  None
403  *
404  * RETURN:      None
405  *
406  * DESCRIPTION: Reset the Line Buffer to zero, increment global line numbers.
407  *
408  ******************************************************************************/
409 
410 void
411 AslResetCurrentLineBuffer (
412     void)
413 {
414 
415     if (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle)
416     {
417         FlWriteFile (ASL_FILE_SOURCE_OUTPUT, Gbl_CurrentLineBuffer,
418             Gbl_LineBufPtr - Gbl_CurrentLineBuffer);
419     }
420 
421     Gbl_CurrentLineOffset += Gbl_CurrentColumn;
422     Gbl_CurrentColumn = 0;
423 
424     Gbl_CurrentLineNumber++;
425     Gbl_LogicalLineNumber++;
426     Gbl_LineBufPtr = Gbl_CurrentLineBuffer;
427 }
428 
429 
430 /*******************************************************************************
431  *
432  * FUNCTION:    AslInsertLineBuffer
433  *
434  * PARAMETERS:  SourceChar          - One char from the input ASL source file
435  *
436  * RETURN:      None
437  *
438  * DESCRIPTION: Put one character of the source file into the temp line buffer
439  *
440  ******************************************************************************/
441 
442 void
443 AslInsertLineBuffer (
444     int                     SourceChar)
445 {
446     UINT32                  i;
447     UINT32                  Count = 1;
448 
449 
450     if (SourceChar == EOF)
451     {
452         return;
453     }
454 
455     Gbl_InputByteCount++;
456 
457     /* Handle tabs. Convert to spaces */
458 
459     if (SourceChar == '\t')
460     {
461         SourceChar = ' ';
462         Count = ASL_SPACES_PER_TAB -
463                     (Gbl_CurrentColumn & (ASL_SPACES_PER_TAB-1));
464     }
465 
466     for (i = 0; i < Count; i++)
467     {
468         Gbl_CurrentColumn++;
469 
470         /* Insert the character into the line buffer */
471 
472         *Gbl_LineBufPtr = (UINT8) SourceChar;
473         Gbl_LineBufPtr++;
474 
475         if (Gbl_LineBufPtr >
476             (Gbl_CurrentLineBuffer + (Gbl_LineBufferSize - 1)))
477         {
478 #if 0
479             /*
480              * Warning if we have split a long source line.
481              * <Probably overkill>
482              */
483             sprintf (MsgBuffer, "Max %u", Gbl_LineBufferSize);
484             AslCommonError (ASL_WARNING, ASL_MSG_LONG_LINE,
485                 Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
486                 Gbl_CurrentLineOffset, Gbl_CurrentColumn,
487                 Gbl_Files[ASL_FILE_INPUT].Filename, MsgBuffer);
488 #endif
489 
490             AslResetCurrentLineBuffer ();
491         }
492         else if (SourceChar == '\n')
493         {
494             /* End of line */
495 
496             AslResetCurrentLineBuffer ();
497         }
498 
499         if (Gbl_CaptureComments)
500         {
501             CvProcessCommentState (SourceChar);
502         }
503     }
504 }
505 
506 
507 /*******************************************************************************
508  *
509  * FUNCTION:    count
510  *
511  * PARAMETERS:  yytext              - Contains the matched keyword.
512  *              Type                - Keyword/Character type:
513  *                                      0 = anything except a keyword
514  *                                      1 = pseudo-keywords
515  *                                      2 = non-executable ASL keywords
516  *                                      3 = executable ASL keywords
517  *
518  * RETURN:      None
519  *
520  * DESCRIPTION: Count keywords and put them into the line buffer
521  *
522  ******************************************************************************/
523 
524 static void
525 count (
526     int                 Type)
527 {
528     int                 i;
529 
530 
531     switch (Type)
532     {
533     case 2:
534 
535         TotalKeywords++;
536         TotalNamedObjects++;
537         break;
538 
539     case 3:
540 
541         TotalKeywords++;
542         TotalExecutableOpcodes++;
543         break;
544 
545     default:
546 
547         break;
548     }
549 
550     for (i = 0; (yytext[i] != 0) && (yytext[i] != EOF); i++)
551     {
552         AslInsertLineBuffer (yytext[i]);
553         *Gbl_LineBufPtr = 0;
554     }
555 }
556 
557 
558 /*******************************************************************************
559  *
560  * FUNCTION:    AslDoComment
561  *
562  * PARAMETERS:  none
563  *
564  * RETURN:      none
565  *
566  * DESCRIPTION: Process a standard comment.
567  *
568  ******************************************************************************/
569 
570 static BOOLEAN
571 AslDoComment (
572     void)
573 {
574     int                     c;
575     int                     c1 = 0;
576     char                    *StringBuffer = MsgBuffer;
577     char                    *EndBuffer = MsgBuffer + ASL_MSG_BUFFER_SIZE;
578     ASL_COMMENT_STATE       CurrentState = Gbl_CommentState; /* to reference later on */
579 
580 
581     AslInsertLineBuffer ('/');
582     AslInsertLineBuffer ('*');
583     if (Gbl_CaptureComments && CurrentState.CaptureComments)
584     {
585         *StringBuffer = '/';
586         ++StringBuffer;
587         *StringBuffer = '*';
588         ++StringBuffer;
589     }
590 
591 loop:
592 
593     /* Eat chars until end-of-comment */
594 
595     while (((c = input ()) != '*') && (c != EOF))
596     {
597         AslInsertLineBuffer (c);
598         if (Gbl_CaptureComments && CurrentState.CaptureComments)
599         {
600             *StringBuffer = c;
601             ++StringBuffer;
602         }
603         c1 = c;
604     }
605 
606     if (c == EOF)
607     {
608         goto EarlyEOF;
609     }
610 
611     /*
612      * Check for nested comment -- can help catch cases where a previous
613      * comment was accidently left unterminated
614      */
615     if ((c1 == '/') && (c == '*'))
616     {
617         AslCommonError (ASL_WARNING, ASL_MSG_NESTED_COMMENT,
618             Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
619             Gbl_InputByteCount, Gbl_CurrentColumn,
620             Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
621     }
622 
623     /* Comment is closed only if the NEXT character is a slash */
624 
625     AslInsertLineBuffer (c);
626     if (Gbl_CaptureComments && CurrentState.CaptureComments)
627     {
628         *StringBuffer = c;
629         ++StringBuffer;
630     }
631 
632     if (((c1 = input ()) != '/') && (c1 != EOF))
633     {
634         unput (c1);
635         goto loop;
636     }
637 
638     if (c1 == EOF)
639     {
640         goto EarlyEOF;
641     }
642     if (StringBuffer > EndBuffer)
643     {
644         goto BufferOverflow;
645     }
646 
647     AslInsertLineBuffer (c1);
648     CvProcessComment (CurrentState, StringBuffer, c1);
649     return (TRUE);
650 
651 
652 EarlyEOF:
653     /*
654      * Premature End-Of-File
655      */
656     AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF,
657         Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
658         Gbl_CurrentLineOffset, Gbl_CurrentColumn,
659         Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
660     return (FALSE);
661 
662 
663 BufferOverflow:
664 
665     /* Comment was too long */
666 
667     AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH,
668         Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
669         Gbl_CurrentLineOffset, Gbl_CurrentColumn,
670         Gbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096");
671     return (FALSE);
672 
673 }
674 
675 
676 /*******************************************************************************
677  *
678  * FUNCTION:    AslDoCommentType2
679  *
680  * PARAMETERS:  none
681  *
682  * RETURN:      none
683  *
684  * DESCRIPTION: Process a new "//" comment. Inline comments will be converted
685  *              to "/ *" standard comments.
686  *
687  ******************************************************************************/
688 
689 static BOOLEAN
690 AslDoCommentType2 (
691     void)
692 {
693     int                     c;
694     char                    *StringBuffer = MsgBuffer;
695     char                    *EndBuffer = MsgBuffer + ASL_MSG_BUFFER_SIZE;
696     ASL_COMMENT_STATE       CurrentState = Gbl_CommentState;
697 
698 
699     AslInsertLineBuffer ('/');
700     AslInsertLineBuffer ('*');
701 
702     if (Gbl_CaptureComments && CurrentState.CaptureComments)
703     {
704         *StringBuffer = '/';
705         ++StringBuffer;
706         *StringBuffer = '*';
707         ++StringBuffer;
708     }
709 
710     while (((c = input ()) != '\n') && (c != EOF))
711     {
712         AslInsertLineBuffer (c);
713         if (Gbl_CaptureComments && CurrentState.CaptureComments)
714         {
715             *StringBuffer = c;
716             ++StringBuffer;
717         }
718     }
719 
720     if (c == EOF)
721     {
722         /* End of file is OK, change to newline. Let parser detect EOF later */
723 
724         c = '\n';
725     }
726 
727     if (StringBuffer > EndBuffer)
728     {
729         goto BufferOverflow;
730     }
731     AslInsertLineBuffer (c);
732 
733     CvProcessCommentType2 (CurrentState, StringBuffer);
734     return (TRUE);
735 
736 
737 BufferOverflow:
738 
739     /* Comment was too long */
740 
741     AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH,
742         Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
743         Gbl_CurrentLineOffset, Gbl_CurrentColumn,
744         Gbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096");
745     return (FALSE);
746 
747 }
748 
749 
750 /*******************************************************************************
751  *
752  * FUNCTION:    AslDoStringLiteral
753  *
754  * PARAMETERS:  none
755  *
756  * RETURN:      none
757  *
758  * DESCRIPTION: Process a string literal (surrounded by quotes)
759  *
760  ******************************************************************************/
761 
762 static char
763 AslDoStringLiteral (
764     void)
765 {
766     char                *StringBuffer = MsgBuffer;
767     char                *EndBuffer = MsgBuffer + ASL_MSG_BUFFER_SIZE;
768     char                *CleanString;
769     int                 StringChar;
770     UINT32              State = ASL_NORMAL_CHAR;
771     UINT32              i = 0;
772     UINT8               Digit;
773     char                ConvertBuffer[4];
774 
775 
776     /*
777      * Eat chars until end-of-literal.
778      * NOTE:  Put back the original surrounding quotes into the
779      * source line buffer.
780      */
781     AslInsertLineBuffer ('\"');
782     while ((StringChar = input()) != EOF)
783     {
784         AslInsertLineBuffer (StringChar);
785 
786 DoCharacter:
787         switch (State)
788         {
789         case ASL_NORMAL_CHAR:
790 
791             switch (StringChar)
792             {
793             case '\\':
794                 /*
795                  * Special handling for backslash-escape sequence. We will
796                  * toss the backslash and translate the escape char(s).
797                  */
798                 State = ASL_ESCAPE_SEQUENCE;
799                 continue;
800 
801             case '\"':
802 
803                 /* String terminator */
804 
805                 goto CompletedString;
806 
807             default:
808 
809                 break;
810             }
811             break;
812 
813 
814         case ASL_ESCAPE_SEQUENCE:
815 
816             State = ASL_NORMAL_CHAR;
817             switch (StringChar)
818             {
819             case 'a':
820 
821                 StringChar = 0x07;      /* BELL */
822                 break;
823 
824             case 'b':
825 
826                 StringChar = 0x08;      /* BACKSPACE */
827                 break;
828 
829             case 'f':
830 
831                 StringChar = 0x0C;      /* FORMFEED */
832                 break;
833 
834             case 'n':
835 
836                 StringChar = 0x0A;      /* LINEFEED */
837                 break;
838 
839             case 'r':
840 
841                 StringChar = 0x0D;      /* CARRIAGE RETURN*/
842                 break;
843 
844             case 't':
845 
846                 StringChar = 0x09;      /* HORIZONTAL TAB */
847                 break;
848 
849             case 'v':
850 
851                 StringChar = 0x0B;      /* VERTICAL TAB */
852                 break;
853 
854             case 'x':
855 
856                 State = ASL_HEX_CONSTANT;
857                 i = 0;
858                 continue;
859 
860             case '\'':                  /* Single Quote */
861             case '\"':                  /* Double Quote */
862             case '\\':                  /* Backslash */
863 
864                 break;
865 
866             default:
867 
868                 /* Check for an octal digit (0-7) */
869 
870                 if (ACPI_IS_OCTAL_DIGIT (StringChar))
871                 {
872                     State = ASL_OCTAL_CONSTANT;
873                     ConvertBuffer[0] = StringChar;
874                     i = 1;
875                     continue;
876                 }
877 
878                 /* Unknown escape sequence issue warning, but use the character */
879 
880                 AslCommonError (ASL_WARNING, ASL_MSG_INVALID_ESCAPE,
881                     Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
882                     Gbl_CurrentLineOffset, Gbl_CurrentColumn,
883                     Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
884                 break;
885             }
886             break;
887 
888 
889         case ASL_OCTAL_CONSTANT:
890 
891             /* Up to three octal digits allowed */
892 
893             if (!ACPI_IS_OCTAL_DIGIT (StringChar) ||
894                 (i > 2))
895             {
896                 /*
897                  * Reached end of the constant. Convert the assembled ASCII
898                  * string and resume processing of the next character
899                  */
900                 ConvertBuffer[i] = 0;
901                 Digit = (UINT8) strtoul (ConvertBuffer, NULL, 8);
902 
903                 /* Check for NULL or non-ascii character (ignore if so) */
904 
905                 if ((Digit == 0) || (Digit > ACPI_ASCII_MAX))
906                 {
907                     AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING,
908                         Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
909                         Gbl_CurrentLineOffset, Gbl_CurrentColumn,
910                         Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
911                 }
912                 else
913                 {
914                     *StringBuffer = (char) Digit;
915                     StringBuffer++;
916                     if (StringBuffer >= EndBuffer)
917                     {
918                         goto BufferOverflow;
919                     }
920                 }
921 
922                 State = ASL_NORMAL_CHAR;
923                 goto DoCharacter;
924                 break;
925             }
926 
927             /* Append another digit of the constant */
928 
929             ConvertBuffer[i] = StringChar;
930             i++;
931             continue;
932 
933         case ASL_HEX_CONSTANT:
934 
935             /* Up to two hex digits allowed */
936 
937             if (!isxdigit (StringChar) ||
938                 (i > 1))
939             {
940                 /*
941                  * Reached end of the constant. Convert the assembled ASCII
942                  * string and resume processing of the next character
943                  */
944                 ConvertBuffer[i] = 0;
945                 Digit = (UINT8) strtoul (ConvertBuffer, NULL, 16);
946 
947                 /* Check for NULL or non-ascii character (ignore if so) */
948 
949                 if ((Digit == 0) || (Digit > ACPI_ASCII_MAX))
950                 {
951                     AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING,
952                         Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
953                         Gbl_CurrentLineOffset, Gbl_CurrentColumn,
954                         Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
955                 }
956                 else
957                 {
958                     *StringBuffer = (char) Digit;
959                     StringBuffer++;
960                     if (StringBuffer >= EndBuffer)
961                     {
962                         goto BufferOverflow;
963                     }
964                 }
965 
966                 State = ASL_NORMAL_CHAR;
967                 goto DoCharacter;
968                 break;
969             }
970 
971             /* Append another digit of the constant */
972 
973             ConvertBuffer[i] = StringChar;
974             i++;
975             continue;
976 
977         default:
978 
979             break;
980         }
981 
982         /* Save the finished character */
983 
984         *StringBuffer = StringChar;
985         StringBuffer++;
986         if (StringBuffer >= EndBuffer)
987         {
988             goto BufferOverflow;
989         }
990     }
991 
992     /*
993      * Premature End-Of-File
994      */
995     AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF,
996         Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
997         Gbl_CurrentLineOffset, Gbl_CurrentColumn,
998         Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
999     return (FALSE);
1000 
1001 
1002 CompletedString:
1003     /*
1004      * Null terminate the input string and copy string to a new buffer
1005      */
1006     *StringBuffer = 0;
1007 
1008     CleanString = UtStringCacheCalloc (strlen (MsgBuffer) + 1);
1009     if (!CleanString)
1010     {
1011         AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION,
1012             Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
1013             Gbl_CurrentLineOffset, Gbl_CurrentColumn,
1014             Gbl_Files[ASL_FILE_INPUT].Filename, NULL);
1015         return (FALSE);
1016     }
1017 
1018     strcpy (CleanString, MsgBuffer);
1019     AslCompilerlval.s = CleanString;
1020     return (TRUE);
1021 
1022 
1023 BufferOverflow:
1024 
1025     /* Literal was too long */
1026 
1027     AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH,
1028         Gbl_CurrentLineNumber, Gbl_LogicalLineNumber,
1029         Gbl_CurrentLineOffset, Gbl_CurrentColumn,
1030         Gbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096");
1031     return (FALSE);
1032 }
1033