Home | History | Annotate | Line # | Download | only in compiler
aslsupport.l revision 1.14
      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.13  christos  * Copyright (C) 2000 - 2019, 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.8  christos void
     56   1.8  christos yyerror (char const *s)
     57   1.1  christos {
     58   1.1  christos 
     59   1.8  christos   AcpiOsPrintf ("YYERROR: %s\n", s);
     60   1.8  christos }
     61   1.1  christos 
     62   1.1  christos 
     63   1.4  christos /*******************************************************************************
     64   1.4  christos  *
     65   1.4  christos  * FUNCTION:    AslParserCleanup
     66   1.4  christos  *
     67   1.4  christos  * Used to delete the current buffer
     68   1.4  christos  *
     69   1.4  christos  ******************************************************************************/
     70   1.4  christos 
     71   1.3  christos void
     72   1.3  christos AslParserCleanup (
     73   1.3  christos     void)
     74   1.3  christos {
     75   1.3  christos 
     76   1.3  christos     yy_delete_buffer (YY_CURRENT_BUFFER);
     77   1.3  christos }
     78   1.3  christos 
     79   1.3  christos 
     80   1.1  christos /*******************************************************************************
     81   1.1  christos  *
     82   1.1  christos  * FUNCTION:    AslDoLineDirective
     83   1.1  christos  *
     84   1.1  christos  * PARAMETERS:  None. Uses input() to access current source code line
     85   1.1  christos  *
     86   1.1  christos  * RETURN:      Updates global line number and filename
     87   1.1  christos  *
     88   1.1  christos  * DESCRIPTION: Handle #line directives emitted by the preprocessor.
     89   1.1  christos  *
     90   1.1  christos  * The #line directive is emitted by the preprocesser, and is used to
     91   1.1  christos  * pass through line numbers from the original source code file to the
     92   1.1  christos  * preprocessor output file (.i). This allows any compiler-generated
     93   1.1  christos  * error messages to be displayed with the correct line number.
     94   1.1  christos  *
     95   1.1  christos  ******************************************************************************/
     96   1.1  christos 
     97   1.1  christos static void
     98   1.1  christos AslDoLineDirective (
     99   1.1  christos     void)
    100   1.1  christos {
    101   1.1  christos     int                     c;
    102   1.1  christos     char                    *Token;
    103   1.1  christos     UINT32                  LineNumber;
    104   1.1  christos     char                    *Filename;
    105   1.1  christos     UINT32                  i;
    106   1.1  christos 
    107  1.12  christos    AslGbl_HasIncludeFiles = TRUE;
    108   1.1  christos 
    109   1.1  christos     /* Eat the entire line that contains the #line directive */
    110   1.1  christos 
    111  1.12  christos     AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer;
    112   1.1  christos 
    113   1.1  christos     while ((c = input()) != '\n' && c != EOF)
    114   1.1  christos     {
    115  1.14  christos         *AslGbl_LineBufPtr = (char) c;
    116  1.12  christos         AslGbl_LineBufPtr++;
    117   1.1  christos     }
    118  1.12  christos     *AslGbl_LineBufPtr = 0;
    119   1.1  christos 
    120   1.1  christos     /* First argument is the actual line number */
    121   1.1  christos 
    122  1.12  christos     Token = strtok (AslGbl_CurrentLineBuffer, " ");
    123   1.1  christos     if (!Token)
    124   1.1  christos     {
    125   1.1  christos         goto ResetAndExit;
    126   1.1  christos     }
    127   1.1  christos 
    128   1.1  christos     /* First argument is the line number */
    129   1.1  christos 
    130   1.1  christos     LineNumber = (UINT32) UtDoConstant (Token);
    131   1.1  christos 
    132   1.1  christos     /* Emit the appropriate number of newlines */
    133   1.1  christos 
    134  1.12  christos     AslGbl_CurrentColumn = 0;
    135  1.12  christos     if (LineNumber > AslGbl_CurrentLineNumber)
    136   1.1  christos     {
    137  1.12  christos         for (i = 0; i < (LineNumber - AslGbl_CurrentLineNumber); i++)
    138   1.1  christos         {
    139   1.1  christos             FlWriteFile (ASL_FILE_SOURCE_OUTPUT, "\n", 1);
    140  1.12  christos             AslGbl_CurrentColumn++;
    141   1.1  christos         }
    142   1.1  christos     }
    143   1.1  christos 
    144   1.1  christos     FlSetLineNumber (LineNumber);
    145   1.1  christos 
    146   1.1  christos     /* Second argument is the optional filename (in double quotes) */
    147   1.1  christos 
    148   1.1  christos     Token = strtok (NULL, " \"");
    149   1.1  christos     if (Token)
    150   1.1  christos     {
    151  1.12  christos         Filename = UtLocalCacheCalloc (strlen (Token) + 1);
    152   1.1  christos         strcpy (Filename, Token);
    153   1.1  christos         FlSetFilename (Filename);
    154   1.1  christos     }
    155   1.1  christos 
    156   1.1  christos     /* Third argument is not supported at this time */
    157   1.1  christos 
    158   1.1  christos ResetAndExit:
    159   1.1  christos 
    160   1.1  christos     /* Reset globals for a new line */
    161   1.1  christos 
    162  1.12  christos     AslGbl_CurrentLineOffset += AslGbl_CurrentColumn;
    163  1.12  christos     AslGbl_CurrentColumn = 0;
    164  1.12  christos     AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer;
    165   1.1  christos }
    166   1.1  christos 
    167   1.1  christos 
    168   1.1  christos /*******************************************************************************
    169   1.1  christos  *
    170   1.1  christos  * FUNCTION:    AslPopInputFileStack
    171   1.1  christos  *
    172   1.1  christos  * PARAMETERS:  None
    173   1.1  christos  *
    174   1.1  christos  * RETURN:      0 if a node was popped, -1 otherwise
    175   1.1  christos  *
    176   1.1  christos  * DESCRIPTION: Pop the top of the input file stack and point the parser to
    177   1.1  christos  *              the saved parse buffer contained in the fnode. Also, set the
    178   1.1  christos  *              global line counters to the saved values. This function is
    179   1.1  christos  *              called when an include file reaches EOF.
    180   1.1  christos  *
    181   1.1  christos  ******************************************************************************/
    182   1.1  christos 
    183   1.1  christos int
    184   1.1  christos AslPopInputFileStack (
    185   1.1  christos     void)
    186   1.1  christos {
    187   1.1  christos     ASL_FILE_NODE           *Fnode;
    188   1.1  christos 
    189   1.1  christos 
    190  1.12  christos     AslGbl_PreviousIncludeFilename = AslGbl_Files[ASL_FILE_INPUT].Filename;
    191  1.12  christos     Fnode = AslGbl_IncludeFileStack;
    192   1.4  christos     DbgPrint (ASL_PARSE_OUTPUT,
    193   1.6  christos         "\nPop InputFile Stack, Fnode %p\n", Fnode);
    194   1.6  christos 
    195   1.6  christos     DbgPrint (ASL_PARSE_OUTPUT,
    196  1.12  christos         "Include: Closing \"%s\"\n\n", AslGbl_Files[ASL_FILE_INPUT].Filename);
    197   1.1  christos 
    198   1.1  christos     if (!Fnode)
    199   1.1  christos     {
    200   1.1  christos         return (-1);
    201   1.1  christos     }
    202   1.1  christos 
    203   1.1  christos     /* Close the current include file */
    204   1.1  christos 
    205   1.1  christos     fclose (yyin);
    206   1.1  christos 
    207   1.1  christos     /* Update the top-of-stack */
    208   1.1  christos 
    209  1.12  christos     AslGbl_IncludeFileStack = Fnode->Next;
    210   1.1  christos 
    211   1.1  christos     /* Reset global line counter and filename */
    212   1.1  christos 
    213  1.12  christos     AslGbl_Files[ASL_FILE_INPUT].Filename = Fnode->Filename;
    214  1.12  christos     AslGbl_CurrentLineNumber = Fnode->CurrentLineNumber;
    215   1.1  christos 
    216   1.1  christos     /* Point the parser to the popped file */
    217   1.1  christos 
    218   1.1  christos     yy_delete_buffer (YY_CURRENT_BUFFER);
    219   1.1  christos     yy_switch_to_buffer (Fnode->State);
    220   1.1  christos 
    221   1.1  christos     /* All done with this node */
    222   1.1  christos 
    223   1.1  christos     ACPI_FREE (Fnode);
    224   1.1  christos     return (0);
    225   1.1  christos }
    226   1.1  christos 
    227   1.1  christos 
    228   1.1  christos /*******************************************************************************
    229   1.1  christos  *
    230   1.1  christos  * FUNCTION:    AslPushInputFileStack
    231   1.1  christos  *
    232   1.1  christos  * PARAMETERS:  InputFile           - Open file pointer
    233   1.1  christos  *              Filename            - Name of the file
    234   1.1  christos  *
    235   1.1  christos  * RETURN:      None
    236   1.1  christos  *
    237   1.1  christos  * DESCRIPTION: Push the InputFile onto the file stack, and point the parser
    238   1.1  christos  *              to this file. Called when an include file is successfully
    239   1.1  christos  *              opened.
    240   1.1  christos  *
    241   1.1  christos  ******************************************************************************/
    242   1.1  christos 
    243   1.1  christos void
    244   1.1  christos AslPushInputFileStack (
    245   1.1  christos     FILE                    *InputFile,
    246   1.1  christos     char                    *Filename)
    247   1.1  christos {
    248   1.1  christos     ASL_FILE_NODE           *Fnode;
    249   1.1  christos     YY_BUFFER_STATE         State;
    250   1.1  christos 
    251   1.1  christos 
    252   1.1  christos     /* Save the current state in an Fnode */
    253   1.1  christos 
    254   1.1  christos     Fnode = UtLocalCalloc (sizeof (ASL_FILE_NODE));
    255   1.1  christos 
    256   1.4  christos     Fnode->File = yyin;
    257  1.12  christos     Fnode->Next = AslGbl_IncludeFileStack;
    258   1.4  christos     Fnode->State = YY_CURRENT_BUFFER;
    259  1.12  christos     Fnode->Filename = AslGbl_Files[ASL_FILE_INPUT].Filename;
    260  1.12  christos     Fnode->CurrentLineNumber = AslGbl_CurrentLineNumber;
    261   1.1  christos 
    262   1.1  christos     /* Push it on the stack */
    263   1.1  christos 
    264  1.12  christos     AslGbl_IncludeFileStack = Fnode;
    265   1.1  christos 
    266   1.1  christos     /* Point the parser to this file */
    267   1.1  christos 
    268   1.1  christos     State = yy_create_buffer (InputFile, YY_BUF_SIZE);
    269   1.1  christos     yy_switch_to_buffer (State);
    270   1.1  christos 
    271   1.4  christos     DbgPrint (ASL_PARSE_OUTPUT,
    272   1.4  christos         "\nPush InputFile Stack, returning %p\n\n", InputFile);
    273   1.1  christos 
    274   1.1  christos     /* Reset the global line count and filename */
    275   1.1  christos 
    276  1.12  christos     AslGbl_Files[ASL_FILE_INPUT].Filename =
    277  1.10  christos         UtLocalCacheCalloc (strlen (Filename) + 1);
    278   1.3  christos 
    279  1.12  christos     strcpy (AslGbl_Files[ASL_FILE_INPUT].Filename, Filename);
    280   1.3  christos 
    281  1.12  christos     AslGbl_CurrentLineNumber = 1;
    282   1.1  christos     yyin = InputFile;
    283   1.8  christos 
    284   1.8  christos     /* converter: reset the comment state to STANDARD_COMMENT */
    285   1.8  christos 
    286  1.12  christos     AslGbl_CommentState.CommentType = STANDARD_COMMENT;
    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.12  christos     if (AslGbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle)
    308   1.1  christos     {
    309  1.12  christos         FlWriteFile (ASL_FILE_SOURCE_OUTPUT, AslGbl_CurrentLineBuffer,
    310  1.12  christos             AslGbl_LineBufPtr - AslGbl_CurrentLineBuffer);
    311   1.1  christos     }
    312   1.1  christos 
    313  1.12  christos     AslGbl_CurrentLineOffset += AslGbl_CurrentColumn;
    314  1.12  christos     AslGbl_CurrentColumn = 0;
    315   1.1  christos 
    316  1.12  christos     AslGbl_CurrentLineNumber++;
    317  1.12  christos     AslGbl_LogicalLineNumber++;
    318  1.12  christos     AslGbl_LineBufPtr = AslGbl_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.12  christos     AslGbl_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.12  christos                     (AslGbl_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.12  christos         AslGbl_CurrentColumn++;
    361   1.1  christos 
    362   1.1  christos         /* Insert the character into the line buffer */
    363   1.1  christos 
    364  1.12  christos         *AslGbl_LineBufPtr = (UINT8) SourceChar;
    365  1.12  christos         AslGbl_LineBufPtr++;
    366   1.1  christos 
    367  1.12  christos         if (AslGbl_LineBufPtr >
    368  1.12  christos             (AslGbl_CurrentLineBuffer + (AslGbl_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.12  christos             snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Max %u", Gbl_LineBufferSize);
    376   1.1  christos             AslCommonError (ASL_WARNING, ASL_MSG_LONG_LINE,
    377  1.12  christos                 AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
    378  1.12  christos                 AslGbl_CurrentLineOffset, AslGbl_CurrentColumn,
    379  1.12  christos                 AslGbl_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.8  christos 
    391  1.11  christos         if (AcpiGbl_CaptureComments)
    392   1.8  christos         {
    393  1.14  christos             CvProcessCommentState ((char) SourceChar);
    394   1.8  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.11  christos     char                *p;
    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.13  christos         ++AslGbl_TotalKeywords;
    428  1.13  christos         ++AslGbl_TotalNamedObjects;
    429  1.13  christos         ++AslGbl_FilesList->TotalKeywords;
    430  1.13  christos         ++AslGbl_FilesList->TotalNamedObjects;
    431   1.1  christos         break;
    432   1.1  christos 
    433   1.1  christos     case 3:
    434   1.1  christos 
    435  1.13  christos         ++AslGbl_TotalKeywords;
    436  1.13  christos         ++AslGbl_TotalExecutableOpcodes;
    437  1.13  christos         ++AslGbl_FilesList->TotalKeywords;
    438  1.13  christos         ++AslGbl_FilesList->TotalExecutableOpcodes;
    439   1.1  christos         break;
    440   1.1  christos 
    441   1.1  christos     default:
    442   1.1  christos 
    443   1.1  christos         break;
    444   1.1  christos     }
    445   1.1  christos 
    446  1.11  christos     for (p = yytext; *p != '\0'; p++)
    447   1.1  christos     {
    448  1.11  christos         AslInsertLineBuffer (*p);
    449  1.12  christos         *AslGbl_LineBufPtr = 0;
    450   1.1  christos     }
    451   1.1  christos }
    452   1.1  christos 
    453   1.1  christos 
    454   1.1  christos /*******************************************************************************
    455   1.1  christos  *
    456   1.1  christos  * FUNCTION:    AslDoComment
    457   1.1  christos  *
    458   1.1  christos  * PARAMETERS:  none
    459   1.1  christos  *
    460   1.1  christos  * RETURN:      none
    461   1.1  christos  *
    462   1.1  christos  * DESCRIPTION: Process a standard comment.
    463   1.1  christos  *
    464   1.1  christos  ******************************************************************************/
    465   1.1  christos 
    466   1.8  christos static BOOLEAN
    467   1.1  christos AslDoComment (
    468   1.1  christos     void)
    469   1.1  christos {
    470   1.8  christos     int                     c;
    471   1.8  christos     int                     c1 = 0;
    472  1.12  christos     char                    *StringBuffer = AslGbl_MsgBuffer;
    473  1.12  christos     char                    *EndBuffer = AslGbl_MsgBuffer + ASL_MSG_BUFFER_SIZE;
    474  1.12  christos     ASL_COMMENT_STATE       CurrentState = AslGbl_CommentState; /* to reference later on */
    475   1.1  christos 
    476   1.1  christos 
    477   1.1  christos     AslInsertLineBuffer ('/');
    478   1.1  christos     AslInsertLineBuffer ('*');
    479  1.11  christos     if (AcpiGbl_CaptureComments && CurrentState.CaptureComments)
    480   1.8  christos     {
    481   1.8  christos         *StringBuffer = '/';
    482   1.8  christos         ++StringBuffer;
    483   1.8  christos         *StringBuffer = '*';
    484   1.8  christos         ++StringBuffer;
    485   1.8  christos     }
    486   1.1  christos 
    487   1.1  christos loop:
    488   1.1  christos 
    489   1.1  christos     /* Eat chars until end-of-comment */
    490   1.1  christos 
    491   1.4  christos     while (((c = input ()) != '*') && (c != EOF))
    492   1.1  christos     {
    493   1.1  christos         AslInsertLineBuffer (c);
    494  1.11  christos         if (AcpiGbl_CaptureComments && CurrentState.CaptureComments)
    495   1.8  christos         {
    496  1.14  christos             *StringBuffer = (char) c;
    497   1.8  christos             ++StringBuffer;
    498   1.8  christos         }
    499   1.1  christos         c1 = c;
    500   1.1  christos     }
    501   1.1  christos 
    502   1.1  christos     if (c == EOF)
    503   1.1  christos     {
    504   1.1  christos         goto EarlyEOF;
    505   1.1  christos     }
    506   1.1  christos 
    507   1.1  christos     /*
    508   1.1  christos      * Check for nested comment -- can help catch cases where a previous
    509  1.13  christos      * comment was accidentally left unterminated
    510   1.1  christos      */
    511   1.1  christos     if ((c1 == '/') && (c == '*'))
    512   1.1  christos     {
    513   1.1  christos         AslCommonError (ASL_WARNING, ASL_MSG_NESTED_COMMENT,
    514  1.12  christos             AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
    515  1.12  christos             AslGbl_InputByteCount, AslGbl_CurrentColumn,
    516  1.12  christos             AslGbl_Files[ASL_FILE_INPUT].Filename, NULL);
    517   1.1  christos     }
    518   1.1  christos 
    519   1.1  christos     /* Comment is closed only if the NEXT character is a slash */
    520   1.1  christos 
    521   1.1  christos     AslInsertLineBuffer (c);
    522  1.11  christos     if (AcpiGbl_CaptureComments && CurrentState.CaptureComments)
    523   1.8  christos     {
    524  1.14  christos         *StringBuffer = (char) c;
    525   1.8  christos         ++StringBuffer;
    526   1.8  christos     }
    527   1.1  christos 
    528   1.4  christos     if (((c1 = input ()) != '/') && (c1 != EOF))
    529   1.1  christos     {
    530   1.8  christos         unput (c1);
    531   1.1  christos         goto loop;
    532   1.1  christos     }
    533   1.1  christos 
    534   1.1  christos     if (c1 == EOF)
    535   1.1  christos     {
    536   1.1  christos         goto EarlyEOF;
    537   1.1  christos     }
    538   1.8  christos     if (StringBuffer > EndBuffer)
    539   1.8  christos     {
    540   1.8  christos         goto BufferOverflow;
    541   1.8  christos     }
    542   1.1  christos 
    543   1.1  christos     AslInsertLineBuffer (c1);
    544   1.8  christos     CvProcessComment (CurrentState, StringBuffer, c1);
    545   1.1  christos     return (TRUE);
    546   1.1  christos 
    547   1.1  christos 
    548   1.1  christos EarlyEOF:
    549   1.1  christos     /*
    550   1.1  christos      * Premature End-Of-File
    551   1.1  christos      */
    552   1.1  christos     AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF,
    553  1.12  christos         AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
    554  1.12  christos         AslGbl_CurrentLineOffset, AslGbl_CurrentColumn,
    555  1.12  christos         AslGbl_Files[ASL_FILE_INPUT].Filename, NULL);
    556   1.1  christos     return (FALSE);
    557   1.8  christos 
    558   1.8  christos 
    559   1.8  christos BufferOverflow:
    560   1.8  christos 
    561   1.8  christos     /* Comment was too long */
    562   1.8  christos 
    563   1.8  christos     AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH,
    564  1.12  christos         AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
    565  1.12  christos         AslGbl_CurrentLineOffset, AslGbl_CurrentColumn,
    566  1.12  christos         AslGbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096");
    567   1.8  christos     return (FALSE);
    568   1.8  christos 
    569   1.1  christos }
    570   1.1  christos 
    571   1.1  christos 
    572   1.1  christos /*******************************************************************************
    573   1.1  christos  *
    574   1.1  christos  * FUNCTION:    AslDoCommentType2
    575   1.1  christos  *
    576   1.1  christos  * PARAMETERS:  none
    577   1.1  christos  *
    578   1.1  christos  * RETURN:      none
    579   1.1  christos  *
    580   1.8  christos  * DESCRIPTION: Process a new "//" comment. Inline comments will be converted
    581   1.8  christos  *              to "/ *" standard comments.
    582   1.1  christos  *
    583   1.1  christos  ******************************************************************************/
    584   1.1  christos 
    585   1.8  christos static BOOLEAN
    586   1.1  christos AslDoCommentType2 (
    587   1.1  christos     void)
    588   1.1  christos {
    589   1.8  christos     int                     c;
    590  1.12  christos     char                    *StringBuffer = AslGbl_MsgBuffer;
    591  1.12  christos     char                    *EndBuffer = AslGbl_MsgBuffer + ASL_MSG_BUFFER_SIZE;
    592  1.12  christos     ASL_COMMENT_STATE       CurrentState = AslGbl_CommentState;
    593   1.1  christos 
    594   1.1  christos 
    595   1.1  christos     AslInsertLineBuffer ('/');
    596   1.8  christos 
    597  1.11  christos     if (AcpiGbl_CaptureComments && CurrentState.CaptureComments)
    598   1.8  christos     {
    599   1.9  christos         AslInsertLineBuffer ('*');
    600   1.8  christos         *StringBuffer = '/';
    601   1.8  christos         ++StringBuffer;
    602   1.8  christos         *StringBuffer = '*';
    603   1.8  christos         ++StringBuffer;
    604   1.8  christos     }
    605   1.9  christos     else
    606   1.9  christos     {
    607   1.9  christos         AslInsertLineBuffer ('/');
    608   1.9  christos     }
    609   1.1  christos 
    610   1.4  christos     while (((c = input ()) != '\n') && (c != EOF))
    611   1.1  christos     {
    612   1.1  christos         AslInsertLineBuffer (c);
    613  1.11  christos         if (AcpiGbl_CaptureComments && CurrentState.CaptureComments)
    614   1.8  christos         {
    615  1.14  christos             *StringBuffer = (char) c;
    616   1.8  christos             ++StringBuffer;
    617   1.8  christos         }
    618   1.1  christos     }
    619   1.1  christos 
    620   1.1  christos     if (c == EOF)
    621   1.1  christos     {
    622   1.1  christos         /* End of file is OK, change to newline. Let parser detect EOF later */
    623   1.1  christos 
    624   1.1  christos         c = '\n';
    625   1.1  christos     }
    626   1.1  christos 
    627   1.8  christos     if (StringBuffer > EndBuffer)
    628   1.8  christos     {
    629   1.8  christos         goto BufferOverflow;
    630   1.8  christos     }
    631   1.1  christos     AslInsertLineBuffer (c);
    632   1.8  christos 
    633   1.8  christos     CvProcessCommentType2 (CurrentState, StringBuffer);
    634   1.1  christos     return (TRUE);
    635   1.8  christos 
    636   1.8  christos 
    637   1.8  christos BufferOverflow:
    638   1.8  christos 
    639   1.8  christos     /* Comment was too long */
    640   1.8  christos 
    641   1.8  christos     AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH,
    642  1.12  christos         AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
    643  1.12  christos         AslGbl_CurrentLineOffset, AslGbl_CurrentColumn,
    644  1.12  christos         AslGbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096");
    645   1.8  christos     return (FALSE);
    646   1.8  christos 
    647   1.1  christos }
    648   1.1  christos 
    649   1.1  christos 
    650   1.1  christos /*******************************************************************************
    651   1.1  christos  *
    652   1.1  christos  * FUNCTION:    AslDoStringLiteral
    653   1.1  christos  *
    654   1.1  christos  * PARAMETERS:  none
    655   1.1  christos  *
    656   1.1  christos  * RETURN:      none
    657   1.1  christos  *
    658   1.1  christos  * DESCRIPTION: Process a string literal (surrounded by quotes)
    659   1.1  christos  *
    660   1.1  christos  ******************************************************************************/
    661   1.1  christos 
    662   1.1  christos static char
    663   1.1  christos AslDoStringLiteral (
    664   1.1  christos     void)
    665   1.1  christos {
    666  1.12  christos     char                *StringBuffer = AslGbl_MsgBuffer;
    667  1.12  christos     char                *EndBuffer = AslGbl_MsgBuffer + ASL_MSG_BUFFER_SIZE;
    668   1.1  christos     char                *CleanString;
    669   1.1  christos     int                 StringChar;
    670   1.1  christos     UINT32              State = ASL_NORMAL_CHAR;
    671   1.1  christos     UINT32              i = 0;
    672   1.1  christos     UINT8               Digit;
    673   1.1  christos     char                ConvertBuffer[4];
    674   1.1  christos 
    675   1.1  christos 
    676   1.1  christos     /*
    677   1.1  christos      * Eat chars until end-of-literal.
    678   1.1  christos      * NOTE:  Put back the original surrounding quotes into the
    679   1.1  christos      * source line buffer.
    680   1.1  christos      */
    681   1.1  christos     AslInsertLineBuffer ('\"');
    682   1.1  christos     while ((StringChar = input()) != EOF)
    683   1.1  christos     {
    684   1.1  christos         AslInsertLineBuffer (StringChar);
    685   1.1  christos 
    686   1.1  christos DoCharacter:
    687   1.1  christos         switch (State)
    688   1.1  christos         {
    689   1.1  christos         case ASL_NORMAL_CHAR:
    690   1.1  christos 
    691   1.1  christos             switch (StringChar)
    692   1.1  christos             {
    693   1.1  christos             case '\\':
    694   1.1  christos                 /*
    695   1.1  christos                  * Special handling for backslash-escape sequence. We will
    696   1.1  christos                  * toss the backslash and translate the escape char(s).
    697   1.1  christos                  */
    698   1.1  christos                 State = ASL_ESCAPE_SEQUENCE;
    699   1.1  christos                 continue;
    700   1.1  christos 
    701   1.1  christos             case '\"':
    702   1.1  christos 
    703   1.1  christos                 /* String terminator */
    704   1.1  christos 
    705   1.1  christos                 goto CompletedString;
    706   1.1  christos 
    707   1.1  christos             default:
    708   1.1  christos 
    709   1.1  christos                 break;
    710   1.1  christos             }
    711   1.1  christos             break;
    712   1.1  christos 
    713   1.1  christos 
    714   1.1  christos         case ASL_ESCAPE_SEQUENCE:
    715   1.1  christos 
    716   1.1  christos             State = ASL_NORMAL_CHAR;
    717   1.1  christos             switch (StringChar)
    718   1.1  christos             {
    719   1.1  christos             case 'a':
    720   1.1  christos 
    721   1.1  christos                 StringChar = 0x07;      /* BELL */
    722   1.1  christos                 break;
    723   1.1  christos 
    724   1.1  christos             case 'b':
    725   1.1  christos 
    726   1.1  christos                 StringChar = 0x08;      /* BACKSPACE */
    727   1.1  christos                 break;
    728   1.1  christos 
    729   1.1  christos             case 'f':
    730   1.1  christos 
    731   1.1  christos                 StringChar = 0x0C;      /* FORMFEED */
    732   1.1  christos                 break;
    733   1.1  christos 
    734   1.1  christos             case 'n':
    735   1.1  christos 
    736   1.1  christos                 StringChar = 0x0A;      /* LINEFEED */
    737   1.1  christos                 break;
    738   1.1  christos 
    739   1.1  christos             case 'r':
    740   1.1  christos 
    741   1.1  christos                 StringChar = 0x0D;      /* CARRIAGE RETURN*/
    742   1.1  christos                 break;
    743   1.1  christos 
    744   1.1  christos             case 't':
    745   1.1  christos 
    746   1.1  christos                 StringChar = 0x09;      /* HORIZONTAL TAB */
    747   1.1  christos                 break;
    748   1.1  christos 
    749   1.1  christos             case 'v':
    750   1.1  christos 
    751   1.1  christos                 StringChar = 0x0B;      /* VERTICAL TAB */
    752   1.1  christos                 break;
    753   1.1  christos 
    754   1.1  christos             case 'x':
    755   1.1  christos 
    756   1.1  christos                 State = ASL_HEX_CONSTANT;
    757   1.1  christos                 i = 0;
    758   1.1  christos                 continue;
    759   1.1  christos 
    760   1.1  christos             case '\'':                  /* Single Quote */
    761   1.1  christos             case '\"':                  /* Double Quote */
    762   1.1  christos             case '\\':                  /* Backslash */
    763   1.1  christos 
    764   1.1  christos                 break;
    765   1.1  christos 
    766   1.1  christos             default:
    767   1.1  christos 
    768   1.1  christos                 /* Check for an octal digit (0-7) */
    769   1.1  christos 
    770   1.1  christos                 if (ACPI_IS_OCTAL_DIGIT (StringChar))
    771   1.1  christos                 {
    772   1.1  christos                     State = ASL_OCTAL_CONSTANT;
    773  1.14  christos                     ConvertBuffer[0] = (char) StringChar;
    774   1.1  christos                     i = 1;
    775   1.1  christos                     continue;
    776   1.1  christos                 }
    777   1.1  christos 
    778   1.1  christos                 /* Unknown escape sequence issue warning, but use the character */
    779   1.1  christos 
    780   1.1  christos                 AslCommonError (ASL_WARNING, ASL_MSG_INVALID_ESCAPE,
    781  1.12  christos                     AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
    782  1.12  christos                     AslGbl_CurrentLineOffset, AslGbl_CurrentColumn,
    783  1.12  christos                     AslGbl_Files[ASL_FILE_INPUT].Filename, NULL);
    784   1.1  christos                 break;
    785   1.1  christos             }
    786   1.1  christos             break;
    787   1.1  christos 
    788   1.1  christos 
    789   1.1  christos         case ASL_OCTAL_CONSTANT:
    790   1.1  christos 
    791   1.1  christos             /* Up to three octal digits allowed */
    792   1.1  christos 
    793   1.1  christos             if (!ACPI_IS_OCTAL_DIGIT (StringChar) ||
    794   1.1  christos                 (i > 2))
    795   1.1  christos             {
    796   1.1  christos                 /*
    797   1.1  christos                  * Reached end of the constant. Convert the assembled ASCII
    798   1.1  christos                  * string and resume processing of the next character
    799   1.1  christos                  */
    800   1.1  christos                 ConvertBuffer[i] = 0;
    801   1.5  christos                 Digit = (UINT8) strtoul (ConvertBuffer, NULL, 8);
    802   1.1  christos 
    803   1.1  christos                 /* Check for NULL or non-ascii character (ignore if so) */
    804   1.1  christos 
    805   1.1  christos                 if ((Digit == 0) || (Digit > ACPI_ASCII_MAX))
    806   1.1  christos                 {
    807   1.1  christos                     AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING,
    808  1.12  christos                         AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
    809  1.12  christos                         AslGbl_CurrentLineOffset, AslGbl_CurrentColumn,
    810  1.12  christos                         AslGbl_Files[ASL_FILE_INPUT].Filename, NULL);
    811   1.1  christos                 }
    812   1.1  christos                 else
    813   1.1  christos                 {
    814   1.1  christos                     *StringBuffer = (char) Digit;
    815   1.1  christos                     StringBuffer++;
    816   1.1  christos                     if (StringBuffer >= EndBuffer)
    817   1.1  christos                     {
    818   1.1  christos                         goto BufferOverflow;
    819   1.1  christos                     }
    820   1.1  christos                 }
    821   1.1  christos 
    822   1.1  christos                 State = ASL_NORMAL_CHAR;
    823   1.1  christos                 goto DoCharacter;
    824   1.1  christos                 break;
    825   1.1  christos             }
    826   1.1  christos 
    827   1.1  christos             /* Append another digit of the constant */
    828   1.1  christos 
    829  1.14  christos             ConvertBuffer[i] = (char) StringChar;
    830   1.1  christos             i++;
    831   1.1  christos             continue;
    832   1.1  christos 
    833   1.1  christos         case ASL_HEX_CONSTANT:
    834   1.1  christos 
    835   1.1  christos             /* Up to two hex digits allowed */
    836   1.1  christos 
    837   1.5  christos             if (!isxdigit (StringChar) ||
    838   1.1  christos                 (i > 1))
    839   1.1  christos             {
    840   1.1  christos                 /*
    841   1.1  christos                  * Reached end of the constant. Convert the assembled ASCII
    842   1.1  christos                  * string and resume processing of the next character
    843   1.1  christos                  */
    844   1.1  christos                 ConvertBuffer[i] = 0;
    845   1.5  christos                 Digit = (UINT8) strtoul (ConvertBuffer, NULL, 16);
    846   1.1  christos 
    847   1.1  christos                 /* Check for NULL or non-ascii character (ignore if so) */
    848   1.1  christos 
    849   1.1  christos                 if ((Digit == 0) || (Digit > ACPI_ASCII_MAX))
    850   1.1  christos                 {
    851   1.1  christos                     AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING,
    852  1.12  christos                         AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
    853  1.12  christos                         AslGbl_CurrentLineOffset, AslGbl_CurrentColumn,
    854  1.12  christos                         AslGbl_Files[ASL_FILE_INPUT].Filename, NULL);
    855   1.1  christos                 }
    856   1.1  christos                 else
    857   1.1  christos                 {
    858   1.1  christos                     *StringBuffer = (char) Digit;
    859   1.1  christos                     StringBuffer++;
    860   1.1  christos                     if (StringBuffer >= EndBuffer)
    861   1.1  christos                     {
    862   1.1  christos                         goto BufferOverflow;
    863   1.1  christos                     }
    864   1.1  christos                 }
    865   1.1  christos 
    866   1.1  christos                 State = ASL_NORMAL_CHAR;
    867   1.1  christos                 goto DoCharacter;
    868   1.1  christos                 break;
    869   1.1  christos             }
    870   1.1  christos 
    871   1.1  christos             /* Append another digit of the constant */
    872   1.1  christos 
    873  1.14  christos             ConvertBuffer[i] = (char) StringChar;
    874   1.1  christos             i++;
    875   1.1  christos             continue;
    876   1.1  christos 
    877   1.1  christos         default:
    878   1.1  christos 
    879   1.1  christos             break;
    880   1.1  christos         }
    881   1.1  christos 
    882   1.1  christos         /* Save the finished character */
    883   1.1  christos 
    884  1.14  christos         *StringBuffer = (char) StringChar;
    885   1.1  christos         StringBuffer++;
    886   1.1  christos         if (StringBuffer >= EndBuffer)
    887   1.1  christos         {
    888   1.1  christos             goto BufferOverflow;
    889   1.1  christos         }
    890   1.1  christos     }
    891   1.1  christos 
    892   1.1  christos     /*
    893   1.1  christos      * Premature End-Of-File
    894   1.1  christos      */
    895   1.1  christos     AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF,
    896  1.12  christos         AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
    897  1.12  christos         AslGbl_CurrentLineOffset, AslGbl_CurrentColumn,
    898  1.12  christos         AslGbl_Files[ASL_FILE_INPUT].Filename, NULL);
    899   1.1  christos     return (FALSE);
    900   1.1  christos 
    901   1.1  christos 
    902   1.1  christos CompletedString:
    903   1.1  christos     /*
    904   1.1  christos      * Null terminate the input string and copy string to a new buffer
    905   1.1  christos      */
    906   1.1  christos     *StringBuffer = 0;
    907   1.1  christos 
    908  1.12  christos     CleanString = UtLocalCacheCalloc (strlen (AslGbl_MsgBuffer) + 1);
    909  1.12  christos     strcpy (CleanString, AslGbl_MsgBuffer);
    910   1.1  christos     AslCompilerlval.s = CleanString;
    911   1.1  christos     return (TRUE);
    912   1.1  christos 
    913   1.1  christos 
    914   1.1  christos BufferOverflow:
    915   1.1  christos 
    916   1.1  christos     /* Literal was too long */
    917   1.1  christos 
    918   1.1  christos     AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH,
    919  1.12  christos         AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
    920  1.12  christos         AslGbl_CurrentLineOffset, AslGbl_CurrentColumn,
    921  1.12  christos         AslGbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096");
    922   1.1  christos     return (FALSE);
    923   1.1  christos }
    924