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