1eef1b955SJung-uk Kim /****************************************************************************** 2eef1b955SJung-uk Kim * 3eef1b955SJung-uk Kim * Module Name: aslsupport.l - Flex/lex scanner C support routines. 4eef1b955SJung-uk Kim * NOTE: Included into aslcompile.l, not compiled by itself. 5eef1b955SJung-uk Kim * 6eef1b955SJung-uk Kim *****************************************************************************/ 7eef1b955SJung-uk Kim 80d84335fSJung-uk Kim /****************************************************************************** 90d84335fSJung-uk Kim * 100d84335fSJung-uk Kim * 1. Copyright Notice 110d84335fSJung-uk Kim * 12e5e1f58aSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2019, Intel Corp. 13eef1b955SJung-uk Kim * All rights reserved. 14eef1b955SJung-uk Kim * 150d84335fSJung-uk Kim * 2. License 160d84335fSJung-uk Kim * 170d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property 180d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided 190d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual 200d84335fSJung-uk Kim * property rights. 210d84335fSJung-uk Kim * 220d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 230d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an 240d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 250d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy, 260d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered 270d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and 280d84335fSJung-uk Kim * 290d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 300d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel 310d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell, 320d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof 330d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright 340d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions 350d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right 360d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise; 370d84335fSJung-uk Kim * 380d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following 390d84335fSJung-uk Kim * conditions are met: 400d84335fSJung-uk Kim * 410d84335fSJung-uk Kim * 3. Conditions 420d84335fSJung-uk Kim * 430d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 440d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 450d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include 460d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions, 470d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition, 480d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to 490d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered 500d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the 510d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee 520d84335fSJung-uk Kim * must include a prominent statement that the modification is derived, 530d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code. 540d84335fSJung-uk Kim * 550d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 560d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 570d84335fSJung-uk Kim * Code or modification without rights to further distribute source must 580d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the 590d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In 600d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any 610d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the 620d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual 630d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and 640d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may 650d84335fSJung-uk Kim * make. 660d84335fSJung-uk Kim * 670d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any 680d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the 690d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance 700d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the 710d84335fSJung-uk Kim * distribution. 720d84335fSJung-uk Kim * 730d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original 740d84335fSJung-uk Kim * Intel Code. 750d84335fSJung-uk Kim * 760d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 770d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or 780d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code 790d84335fSJung-uk Kim * without prior written authorization from Intel. 800d84335fSJung-uk Kim * 810d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance 820d84335fSJung-uk Kim * 830d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 840d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 850d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 860d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 870d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 880d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 890d84335fSJung-uk Kim * PARTICULAR PURPOSE. 900d84335fSJung-uk Kim * 910d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 920d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 930d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 940d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 950d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 960d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 970d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 980d84335fSJung-uk Kim * LIMITED REMEDY. 990d84335fSJung-uk Kim * 1000d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this 1010d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any 1020d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or 1030d84335fSJung-uk Kim * any other agency or department of the United States Government. In the 1040d84335fSJung-uk Kim * event Licensee exports any such software from the United States or 1050d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall 1060d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in 1070d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the 1080d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1090d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process, 1100d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the 1110d84335fSJung-uk Kim * United States government or any agency thereof requires an export license, 1120d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining 1130d84335fSJung-uk Kim * such license, approval or letter. 1140d84335fSJung-uk Kim * 1150d84335fSJung-uk Kim ***************************************************************************** 1160d84335fSJung-uk Kim * 1170d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 1180d84335fSJung-uk Kim * following license: 1190d84335fSJung-uk Kim * 120eef1b955SJung-uk Kim * Redistribution and use in source and binary forms, with or without 121eef1b955SJung-uk Kim * modification, are permitted provided that the following conditions 122eef1b955SJung-uk Kim * are met: 123eef1b955SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 124eef1b955SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 125eef1b955SJung-uk Kim * without modification. 126eef1b955SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 127eef1b955SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 128eef1b955SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 129eef1b955SJung-uk Kim * including a substantially similar Disclaimer requirement for further 130eef1b955SJung-uk Kim * binary redistribution. 131eef1b955SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 132eef1b955SJung-uk Kim * of any contributors may be used to endorse or promote products derived 133eef1b955SJung-uk Kim * from this software without specific prior written permission. 134eef1b955SJung-uk Kim * 1350d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1360d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1370d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1380d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1390d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1400d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1410d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1420d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1430d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1440d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1450d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1460d84335fSJung-uk Kim * 1470d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 148eef1b955SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 149eef1b955SJung-uk Kim * Software Foundation. 150eef1b955SJung-uk Kim * 1510d84335fSJung-uk Kim *****************************************************************************/ 152eef1b955SJung-uk Kim 153eef1b955SJung-uk Kim /* Configuration */ 154eef1b955SJung-uk Kim 155eef1b955SJung-uk Kim #define ASL_SPACES_PER_TAB 4 156eef1b955SJung-uk Kim 157eef1b955SJung-uk Kim #define ASL_NORMAL_CHAR 0 158eef1b955SJung-uk Kim #define ASL_ESCAPE_SEQUENCE 1 159eef1b955SJung-uk Kim #define ASL_OCTAL_CONSTANT 2 160eef1b955SJung-uk Kim #define ASL_HEX_CONSTANT 3 161eef1b955SJung-uk Kim 162eef1b955SJung-uk Kim 1630d84335fSJung-uk Kim void 1640d84335fSJung-uk Kim yyerror (char const *s) 165eef1b955SJung-uk Kim { 166eef1b955SJung-uk Kim 1670d84335fSJung-uk Kim AcpiOsPrintf ("YYERROR: %s\n", s); 1680d84335fSJung-uk Kim } 169eef1b955SJung-uk Kim 170eef1b955SJung-uk Kim 1711c0e1b6dSJung-uk Kim /******************************************************************************* 1721c0e1b6dSJung-uk Kim * 1731c0e1b6dSJung-uk Kim * FUNCTION: AslParserCleanup 1741c0e1b6dSJung-uk Kim * 1751c0e1b6dSJung-uk Kim * Used to delete the current buffer 1761c0e1b6dSJung-uk Kim * 1771c0e1b6dSJung-uk Kim ******************************************************************************/ 1781c0e1b6dSJung-uk Kim 179313a0c13SJung-uk Kim void 180313a0c13SJung-uk Kim AslParserCleanup ( 181313a0c13SJung-uk Kim void) 182313a0c13SJung-uk Kim { 183313a0c13SJung-uk Kim 184313a0c13SJung-uk Kim yy_delete_buffer (YY_CURRENT_BUFFER); 185313a0c13SJung-uk Kim } 186313a0c13SJung-uk Kim 187313a0c13SJung-uk Kim 188eef1b955SJung-uk Kim /******************************************************************************* 189eef1b955SJung-uk Kim * 190eef1b955SJung-uk Kim * FUNCTION: AslDoLineDirective 191eef1b955SJung-uk Kim * 192eef1b955SJung-uk Kim * PARAMETERS: None. Uses input() to access current source code line 193eef1b955SJung-uk Kim * 194eef1b955SJung-uk Kim * RETURN: Updates global line number and filename 195eef1b955SJung-uk Kim * 196eef1b955SJung-uk Kim * DESCRIPTION: Handle #line directives emitted by the preprocessor. 197eef1b955SJung-uk Kim * 198eef1b955SJung-uk Kim * The #line directive is emitted by the preprocesser, and is used to 199eef1b955SJung-uk Kim * pass through line numbers from the original source code file to the 200eef1b955SJung-uk Kim * preprocessor output file (.i). This allows any compiler-generated 201eef1b955SJung-uk Kim * error messages to be displayed with the correct line number. 202eef1b955SJung-uk Kim * 203eef1b955SJung-uk Kim ******************************************************************************/ 204eef1b955SJung-uk Kim 205eef1b955SJung-uk Kim static void 206eef1b955SJung-uk Kim AslDoLineDirective ( 207eef1b955SJung-uk Kim void) 208eef1b955SJung-uk Kim { 209f38b0f21SJung-uk Kim int c; 210eef1b955SJung-uk Kim char *Token; 211eef1b955SJung-uk Kim UINT32 LineNumber; 212eef1b955SJung-uk Kim char *Filename; 213f38b0f21SJung-uk Kim UINT32 i; 214eef1b955SJung-uk Kim 2156f1f1a63SJung-uk Kim AslGbl_HasIncludeFiles = TRUE; 216eef1b955SJung-uk Kim 217eef1b955SJung-uk Kim /* Eat the entire line that contains the #line directive */ 218eef1b955SJung-uk Kim 2196f1f1a63SJung-uk Kim AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer; 220f38b0f21SJung-uk Kim 221f38b0f21SJung-uk Kim while ((c = input()) != '\n' && c != EOF) 222eef1b955SJung-uk Kim { 223*37d7a5bcSJung-uk Kim *AslGbl_LineBufPtr = (char) c; 2246f1f1a63SJung-uk Kim AslGbl_LineBufPtr++; 225eef1b955SJung-uk Kim } 2266f1f1a63SJung-uk Kim *AslGbl_LineBufPtr = 0; 227eef1b955SJung-uk Kim 228eef1b955SJung-uk Kim /* First argument is the actual line number */ 229eef1b955SJung-uk Kim 2306f1f1a63SJung-uk Kim Token = strtok (AslGbl_CurrentLineBuffer, " "); 231eef1b955SJung-uk Kim if (!Token) 232eef1b955SJung-uk Kim { 233eef1b955SJung-uk Kim goto ResetAndExit; 234eef1b955SJung-uk Kim } 235eef1b955SJung-uk Kim 236f38b0f21SJung-uk Kim /* First argument is the line number */ 237eef1b955SJung-uk Kim 238eef1b955SJung-uk Kim LineNumber = (UINT32) UtDoConstant (Token); 239f38b0f21SJung-uk Kim 240f38b0f21SJung-uk Kim /* Emit the appropriate number of newlines */ 241f38b0f21SJung-uk Kim 2426f1f1a63SJung-uk Kim AslGbl_CurrentColumn = 0; 2436f1f1a63SJung-uk Kim if (LineNumber > AslGbl_CurrentLineNumber) 244f38b0f21SJung-uk Kim { 2456f1f1a63SJung-uk Kim for (i = 0; i < (LineNumber - AslGbl_CurrentLineNumber); i++) 246f38b0f21SJung-uk Kim { 247f38b0f21SJung-uk Kim FlWriteFile (ASL_FILE_SOURCE_OUTPUT, "\n", 1); 2486f1f1a63SJung-uk Kim AslGbl_CurrentColumn++; 249f38b0f21SJung-uk Kim } 250f38b0f21SJung-uk Kim } 251f38b0f21SJung-uk Kim 252f38b0f21SJung-uk Kim FlSetLineNumber (LineNumber); 253eef1b955SJung-uk Kim 254eef1b955SJung-uk Kim /* Second argument is the optional filename (in double quotes) */ 255eef1b955SJung-uk Kim 256eef1b955SJung-uk Kim Token = strtok (NULL, " \""); 257eef1b955SJung-uk Kim if (Token) 258eef1b955SJung-uk Kim { 2596f1f1a63SJung-uk Kim Filename = UtLocalCacheCalloc (strlen (Token) + 1); 260eef1b955SJung-uk Kim strcpy (Filename, Token); 261eef1b955SJung-uk Kim FlSetFilename (Filename); 262eef1b955SJung-uk Kim } 263eef1b955SJung-uk Kim 264eef1b955SJung-uk Kim /* Third argument is not supported at this time */ 265eef1b955SJung-uk Kim 266eef1b955SJung-uk Kim ResetAndExit: 267f38b0f21SJung-uk Kim 268f38b0f21SJung-uk Kim /* Reset globals for a new line */ 269f38b0f21SJung-uk Kim 2706f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset += AslGbl_CurrentColumn; 2716f1f1a63SJung-uk Kim AslGbl_CurrentColumn = 0; 2726f1f1a63SJung-uk Kim AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer; 273eef1b955SJung-uk Kim } 274eef1b955SJung-uk Kim 275eef1b955SJung-uk Kim 276eef1b955SJung-uk Kim /******************************************************************************* 277eef1b955SJung-uk Kim * 278eef1b955SJung-uk Kim * FUNCTION: AslPopInputFileStack 279eef1b955SJung-uk Kim * 280eef1b955SJung-uk Kim * PARAMETERS: None 281eef1b955SJung-uk Kim * 282eef1b955SJung-uk Kim * RETURN: 0 if a node was popped, -1 otherwise 283eef1b955SJung-uk Kim * 284eef1b955SJung-uk Kim * DESCRIPTION: Pop the top of the input file stack and point the parser to 285eef1b955SJung-uk Kim * the saved parse buffer contained in the fnode. Also, set the 286eef1b955SJung-uk Kim * global line counters to the saved values. This function is 287eef1b955SJung-uk Kim * called when an include file reaches EOF. 288eef1b955SJung-uk Kim * 289eef1b955SJung-uk Kim ******************************************************************************/ 290eef1b955SJung-uk Kim 291eef1b955SJung-uk Kim int 292eef1b955SJung-uk Kim AslPopInputFileStack ( 293eef1b955SJung-uk Kim void) 294eef1b955SJung-uk Kim { 295eef1b955SJung-uk Kim ASL_FILE_NODE *Fnode; 296eef1b955SJung-uk Kim 297eef1b955SJung-uk Kim 2986f1f1a63SJung-uk Kim AslGbl_PreviousIncludeFilename = AslGbl_Files[ASL_FILE_INPUT].Filename; 2996f1f1a63SJung-uk Kim Fnode = AslGbl_IncludeFileStack; 3001c0e1b6dSJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, 301f8146b88SJung-uk Kim "\nPop InputFile Stack, Fnode %p\n", Fnode); 302f8146b88SJung-uk Kim 303f8146b88SJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, 3046f1f1a63SJung-uk Kim "Include: Closing \"%s\"\n\n", AslGbl_Files[ASL_FILE_INPUT].Filename); 305eef1b955SJung-uk Kim 306eef1b955SJung-uk Kim if (!Fnode) 307eef1b955SJung-uk Kim { 308eef1b955SJung-uk Kim return (-1); 309eef1b955SJung-uk Kim } 310eef1b955SJung-uk Kim 311eef1b955SJung-uk Kim /* Close the current include file */ 312eef1b955SJung-uk Kim 313eef1b955SJung-uk Kim fclose (yyin); 314eef1b955SJung-uk Kim 315eef1b955SJung-uk Kim /* Update the top-of-stack */ 316eef1b955SJung-uk Kim 3176f1f1a63SJung-uk Kim AslGbl_IncludeFileStack = Fnode->Next; 318eef1b955SJung-uk Kim 319eef1b955SJung-uk Kim /* Reset global line counter and filename */ 320eef1b955SJung-uk Kim 3216f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename = Fnode->Filename; 3226f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber = Fnode->CurrentLineNumber; 323eef1b955SJung-uk Kim 324eef1b955SJung-uk Kim /* Point the parser to the popped file */ 325eef1b955SJung-uk Kim 326eef1b955SJung-uk Kim yy_delete_buffer (YY_CURRENT_BUFFER); 327eef1b955SJung-uk Kim yy_switch_to_buffer (Fnode->State); 328eef1b955SJung-uk Kim 329eef1b955SJung-uk Kim /* All done with this node */ 330eef1b955SJung-uk Kim 331eef1b955SJung-uk Kim ACPI_FREE (Fnode); 332eef1b955SJung-uk Kim return (0); 333eef1b955SJung-uk Kim } 334eef1b955SJung-uk Kim 335eef1b955SJung-uk Kim 336eef1b955SJung-uk Kim /******************************************************************************* 337eef1b955SJung-uk Kim * 338eef1b955SJung-uk Kim * FUNCTION: AslPushInputFileStack 339eef1b955SJung-uk Kim * 340eef1b955SJung-uk Kim * PARAMETERS: InputFile - Open file pointer 341eef1b955SJung-uk Kim * Filename - Name of the file 342eef1b955SJung-uk Kim * 343eef1b955SJung-uk Kim * RETURN: None 344eef1b955SJung-uk Kim * 345eef1b955SJung-uk Kim * DESCRIPTION: Push the InputFile onto the file stack, and point the parser 346eef1b955SJung-uk Kim * to this file. Called when an include file is successfully 347eef1b955SJung-uk Kim * opened. 348eef1b955SJung-uk Kim * 349eef1b955SJung-uk Kim ******************************************************************************/ 350eef1b955SJung-uk Kim 351eef1b955SJung-uk Kim void 352eef1b955SJung-uk Kim AslPushInputFileStack ( 353eef1b955SJung-uk Kim FILE *InputFile, 354eef1b955SJung-uk Kim char *Filename) 355eef1b955SJung-uk Kim { 356eef1b955SJung-uk Kim ASL_FILE_NODE *Fnode; 357eef1b955SJung-uk Kim YY_BUFFER_STATE State; 358eef1b955SJung-uk Kim 359eef1b955SJung-uk Kim 360eef1b955SJung-uk Kim /* Save the current state in an Fnode */ 361eef1b955SJung-uk Kim 362eef1b955SJung-uk Kim Fnode = UtLocalCalloc (sizeof (ASL_FILE_NODE)); 363eef1b955SJung-uk Kim 364eef1b955SJung-uk Kim Fnode->File = yyin; 3656f1f1a63SJung-uk Kim Fnode->Next = AslGbl_IncludeFileStack; 366eef1b955SJung-uk Kim Fnode->State = YY_CURRENT_BUFFER; 3676f1f1a63SJung-uk Kim Fnode->Filename = AslGbl_Files[ASL_FILE_INPUT].Filename; 3686f1f1a63SJung-uk Kim Fnode->CurrentLineNumber = AslGbl_CurrentLineNumber; 369eef1b955SJung-uk Kim 370eef1b955SJung-uk Kim /* Push it on the stack */ 371eef1b955SJung-uk Kim 3726f1f1a63SJung-uk Kim AslGbl_IncludeFileStack = Fnode; 373eef1b955SJung-uk Kim 374eef1b955SJung-uk Kim /* Point the parser to this file */ 375eef1b955SJung-uk Kim 376eef1b955SJung-uk Kim State = yy_create_buffer (InputFile, YY_BUF_SIZE); 377eef1b955SJung-uk Kim yy_switch_to_buffer (State); 378eef1b955SJung-uk Kim 3791c0e1b6dSJung-uk Kim DbgPrint (ASL_PARSE_OUTPUT, 3801c0e1b6dSJung-uk Kim "\nPush InputFile Stack, returning %p\n\n", InputFile); 381eef1b955SJung-uk Kim 382eef1b955SJung-uk Kim /* Reset the global line count and filename */ 383eef1b955SJung-uk Kim 3846f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename = 38567d9aa44SJung-uk Kim UtLocalCacheCalloc (strlen (Filename) + 1); 386313a0c13SJung-uk Kim 3876f1f1a63SJung-uk Kim strcpy (AslGbl_Files[ASL_FILE_INPUT].Filename, Filename); 388313a0c13SJung-uk Kim 3896f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber = 1; 390eef1b955SJung-uk Kim yyin = InputFile; 3910d84335fSJung-uk Kim 3920d84335fSJung-uk Kim /* converter: reset the comment state to STANDARD_COMMENT */ 3930d84335fSJung-uk Kim 3946f1f1a63SJung-uk Kim AslGbl_CommentState.CommentType = STANDARD_COMMENT; 395eef1b955SJung-uk Kim } 396eef1b955SJung-uk Kim 397eef1b955SJung-uk Kim 398eef1b955SJung-uk Kim /******************************************************************************* 399eef1b955SJung-uk Kim * 400eef1b955SJung-uk Kim * FUNCTION: AslResetCurrentLineBuffer 401eef1b955SJung-uk Kim * 402eef1b955SJung-uk Kim * PARAMETERS: None 403eef1b955SJung-uk Kim * 404eef1b955SJung-uk Kim * RETURN: None 405eef1b955SJung-uk Kim * 406eef1b955SJung-uk Kim * DESCRIPTION: Reset the Line Buffer to zero, increment global line numbers. 407eef1b955SJung-uk Kim * 408eef1b955SJung-uk Kim ******************************************************************************/ 409eef1b955SJung-uk Kim 410eef1b955SJung-uk Kim void 411eef1b955SJung-uk Kim AslResetCurrentLineBuffer ( 412eef1b955SJung-uk Kim void) 413eef1b955SJung-uk Kim { 414eef1b955SJung-uk Kim 4156f1f1a63SJung-uk Kim if (AslGbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle) 416eef1b955SJung-uk Kim { 4176f1f1a63SJung-uk Kim FlWriteFile (ASL_FILE_SOURCE_OUTPUT, AslGbl_CurrentLineBuffer, 4186f1f1a63SJung-uk Kim AslGbl_LineBufPtr - AslGbl_CurrentLineBuffer); 419eef1b955SJung-uk Kim } 420eef1b955SJung-uk Kim 4216f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset += AslGbl_CurrentColumn; 4226f1f1a63SJung-uk Kim AslGbl_CurrentColumn = 0; 423eef1b955SJung-uk Kim 4246f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber++; 4256f1f1a63SJung-uk Kim AslGbl_LogicalLineNumber++; 4266f1f1a63SJung-uk Kim AslGbl_LineBufPtr = AslGbl_CurrentLineBuffer; 427eef1b955SJung-uk Kim } 428eef1b955SJung-uk Kim 429eef1b955SJung-uk Kim 430eef1b955SJung-uk Kim /******************************************************************************* 431eef1b955SJung-uk Kim * 432eef1b955SJung-uk Kim * FUNCTION: AslInsertLineBuffer 433eef1b955SJung-uk Kim * 434eef1b955SJung-uk Kim * PARAMETERS: SourceChar - One char from the input ASL source file 435eef1b955SJung-uk Kim * 436eef1b955SJung-uk Kim * RETURN: None 437eef1b955SJung-uk Kim * 438eef1b955SJung-uk Kim * DESCRIPTION: Put one character of the source file into the temp line buffer 439eef1b955SJung-uk Kim * 440eef1b955SJung-uk Kim ******************************************************************************/ 441eef1b955SJung-uk Kim 442eef1b955SJung-uk Kim void 443eef1b955SJung-uk Kim AslInsertLineBuffer ( 444eef1b955SJung-uk Kim int SourceChar) 445eef1b955SJung-uk Kim { 446eef1b955SJung-uk Kim UINT32 i; 447eef1b955SJung-uk Kim UINT32 Count = 1; 448eef1b955SJung-uk Kim 449eef1b955SJung-uk Kim 450eef1b955SJung-uk Kim if (SourceChar == EOF) 451eef1b955SJung-uk Kim { 452eef1b955SJung-uk Kim return; 453eef1b955SJung-uk Kim } 454eef1b955SJung-uk Kim 4556f1f1a63SJung-uk Kim AslGbl_InputByteCount++; 456eef1b955SJung-uk Kim 457eef1b955SJung-uk Kim /* Handle tabs. Convert to spaces */ 458eef1b955SJung-uk Kim 459eef1b955SJung-uk Kim if (SourceChar == '\t') 460eef1b955SJung-uk Kim { 461eef1b955SJung-uk Kim SourceChar = ' '; 462eef1b955SJung-uk Kim Count = ASL_SPACES_PER_TAB - 4636f1f1a63SJung-uk Kim (AslGbl_CurrentColumn & (ASL_SPACES_PER_TAB-1)); 464eef1b955SJung-uk Kim } 465eef1b955SJung-uk Kim 466eef1b955SJung-uk Kim for (i = 0; i < Count; i++) 467eef1b955SJung-uk Kim { 4686f1f1a63SJung-uk Kim AslGbl_CurrentColumn++; 469eef1b955SJung-uk Kim 470eef1b955SJung-uk Kim /* Insert the character into the line buffer */ 471eef1b955SJung-uk Kim 4726f1f1a63SJung-uk Kim *AslGbl_LineBufPtr = (UINT8) SourceChar; 4736f1f1a63SJung-uk Kim AslGbl_LineBufPtr++; 474eef1b955SJung-uk Kim 4756f1f1a63SJung-uk Kim if (AslGbl_LineBufPtr > 4766f1f1a63SJung-uk Kim (AslGbl_CurrentLineBuffer + (AslGbl_LineBufferSize - 1))) 477eef1b955SJung-uk Kim { 478eef1b955SJung-uk Kim #if 0 479eef1b955SJung-uk Kim /* 480eef1b955SJung-uk Kim * Warning if we have split a long source line. 481eef1b955SJung-uk Kim * <Probably overkill> 482eef1b955SJung-uk Kim */ 4836f1f1a63SJung-uk Kim sprintf (MsgBuffer, "Max %u", AslGbl_LineBufferSize); 484eef1b955SJung-uk Kim AslCommonError (ASL_WARNING, ASL_MSG_LONG_LINE, 4856f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber, 4866f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset, AslGbl_CurrentColumn, 4876f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, MsgBuffer); 488eef1b955SJung-uk Kim #endif 489eef1b955SJung-uk Kim 490eef1b955SJung-uk Kim AslResetCurrentLineBuffer (); 491eef1b955SJung-uk Kim } 492eef1b955SJung-uk Kim else if (SourceChar == '\n') 493eef1b955SJung-uk Kim { 494eef1b955SJung-uk Kim /* End of line */ 495eef1b955SJung-uk Kim 496eef1b955SJung-uk Kim AslResetCurrentLineBuffer (); 497eef1b955SJung-uk Kim } 4980d84335fSJung-uk Kim 499f1db5ef7SJung-uk Kim if (AcpiGbl_CaptureComments) 5000d84335fSJung-uk Kim { 501*37d7a5bcSJung-uk Kim CvProcessCommentState ((char) SourceChar); 5020d84335fSJung-uk Kim } 503eef1b955SJung-uk Kim } 504eef1b955SJung-uk Kim } 505eef1b955SJung-uk Kim 506eef1b955SJung-uk Kim 507eef1b955SJung-uk Kim /******************************************************************************* 508eef1b955SJung-uk Kim * 509eef1b955SJung-uk Kim * FUNCTION: count 510eef1b955SJung-uk Kim * 511eef1b955SJung-uk Kim * PARAMETERS: yytext - Contains the matched keyword. 512eef1b955SJung-uk Kim * Type - Keyword/Character type: 513eef1b955SJung-uk Kim * 0 = anything except a keyword 514eef1b955SJung-uk Kim * 1 = pseudo-keywords 515eef1b955SJung-uk Kim * 2 = non-executable ASL keywords 516eef1b955SJung-uk Kim * 3 = executable ASL keywords 517eef1b955SJung-uk Kim * 518eef1b955SJung-uk Kim * RETURN: None 519eef1b955SJung-uk Kim * 520eef1b955SJung-uk Kim * DESCRIPTION: Count keywords and put them into the line buffer 521eef1b955SJung-uk Kim * 522eef1b955SJung-uk Kim ******************************************************************************/ 523eef1b955SJung-uk Kim 524eef1b955SJung-uk Kim static void 525eef1b955SJung-uk Kim count ( 526eef1b955SJung-uk Kim int Type) 527eef1b955SJung-uk Kim { 528f1db5ef7SJung-uk Kim char *p; 529eef1b955SJung-uk Kim 530eef1b955SJung-uk Kim 531eef1b955SJung-uk Kim switch (Type) 532eef1b955SJung-uk Kim { 533eef1b955SJung-uk Kim case 2: 534a9d8d09cSJung-uk Kim 53544b0f624SJung-uk Kim ++AslGbl_TotalKeywords; 53644b0f624SJung-uk Kim ++AslGbl_TotalNamedObjects; 53744b0f624SJung-uk Kim ++AslGbl_FilesList->TotalKeywords; 53844b0f624SJung-uk Kim ++AslGbl_FilesList->TotalNamedObjects; 539eef1b955SJung-uk Kim break; 540eef1b955SJung-uk Kim 541eef1b955SJung-uk Kim case 3: 542a9d8d09cSJung-uk Kim 54344b0f624SJung-uk Kim ++AslGbl_TotalKeywords; 54444b0f624SJung-uk Kim ++AslGbl_TotalExecutableOpcodes; 54544b0f624SJung-uk Kim ++AslGbl_FilesList->TotalKeywords; 54644b0f624SJung-uk Kim ++AslGbl_FilesList->TotalExecutableOpcodes; 547eef1b955SJung-uk Kim break; 5489c48c75eSJung-uk Kim 5499c48c75eSJung-uk Kim default: 550a9d8d09cSJung-uk Kim 5519c48c75eSJung-uk Kim break; 552eef1b955SJung-uk Kim } 553eef1b955SJung-uk Kim 554f1db5ef7SJung-uk Kim for (p = yytext; *p != '\0'; p++) 555eef1b955SJung-uk Kim { 556f1db5ef7SJung-uk Kim AslInsertLineBuffer (*p); 5576f1f1a63SJung-uk Kim *AslGbl_LineBufPtr = 0; 558eef1b955SJung-uk Kim } 559eef1b955SJung-uk Kim } 560eef1b955SJung-uk Kim 561eef1b955SJung-uk Kim 562eef1b955SJung-uk Kim /******************************************************************************* 563eef1b955SJung-uk Kim * 564eef1b955SJung-uk Kim * FUNCTION: AslDoComment 565eef1b955SJung-uk Kim * 566eef1b955SJung-uk Kim * PARAMETERS: none 567eef1b955SJung-uk Kim * 568eef1b955SJung-uk Kim * RETURN: none 569eef1b955SJung-uk Kim * 570eef1b955SJung-uk Kim * DESCRIPTION: Process a standard comment. 571eef1b955SJung-uk Kim * 572eef1b955SJung-uk Kim ******************************************************************************/ 573eef1b955SJung-uk Kim 5740d84335fSJung-uk Kim static BOOLEAN 575eef1b955SJung-uk Kim AslDoComment ( 576eef1b955SJung-uk Kim void) 577eef1b955SJung-uk Kim { 578f38b0f21SJung-uk Kim int c; 579f38b0f21SJung-uk Kim int c1 = 0; 5806f1f1a63SJung-uk Kim char *StringBuffer = AslGbl_MsgBuffer; 5816f1f1a63SJung-uk Kim char *EndBuffer = AslGbl_MsgBuffer + ASL_MSG_BUFFER_SIZE; 5826f1f1a63SJung-uk Kim ASL_COMMENT_STATE CurrentState = AslGbl_CommentState; /* to reference later on */ 583eef1b955SJung-uk Kim 584eef1b955SJung-uk Kim 585eef1b955SJung-uk Kim AslInsertLineBuffer ('/'); 586eef1b955SJung-uk Kim AslInsertLineBuffer ('*'); 587f1db5ef7SJung-uk Kim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments) 5880d84335fSJung-uk Kim { 5890d84335fSJung-uk Kim *StringBuffer = '/'; 5900d84335fSJung-uk Kim ++StringBuffer; 5910d84335fSJung-uk Kim *StringBuffer = '*'; 5920d84335fSJung-uk Kim ++StringBuffer; 5930d84335fSJung-uk Kim } 594eef1b955SJung-uk Kim 595eef1b955SJung-uk Kim loop: 596eef1b955SJung-uk Kim 597eef1b955SJung-uk Kim /* Eat chars until end-of-comment */ 598eef1b955SJung-uk Kim 5991c0e1b6dSJung-uk Kim while (((c = input ()) != '*') && (c != EOF)) 600eef1b955SJung-uk Kim { 601eef1b955SJung-uk Kim AslInsertLineBuffer (c); 602f1db5ef7SJung-uk Kim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments) 6030d84335fSJung-uk Kim { 604*37d7a5bcSJung-uk Kim *StringBuffer = (char) c; 6050d84335fSJung-uk Kim ++StringBuffer; 6060d84335fSJung-uk Kim } 607eef1b955SJung-uk Kim c1 = c; 608eef1b955SJung-uk Kim } 609eef1b955SJung-uk Kim 610eef1b955SJung-uk Kim if (c == EOF) 611eef1b955SJung-uk Kim { 612eef1b955SJung-uk Kim goto EarlyEOF; 613eef1b955SJung-uk Kim } 614eef1b955SJung-uk Kim 615eef1b955SJung-uk Kim /* 616eef1b955SJung-uk Kim * Check for nested comment -- can help catch cases where a previous 617cd6518c7SJung-uk Kim * comment was accidentally left unterminated 618eef1b955SJung-uk Kim */ 619eef1b955SJung-uk Kim if ((c1 == '/') && (c == '*')) 620eef1b955SJung-uk Kim { 621eef1b955SJung-uk Kim AslCommonError (ASL_WARNING, ASL_MSG_NESTED_COMMENT, 6226f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber, 6236f1f1a63SJung-uk Kim AslGbl_InputByteCount, AslGbl_CurrentColumn, 6246f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, NULL); 625eef1b955SJung-uk Kim } 626eef1b955SJung-uk Kim 627eef1b955SJung-uk Kim /* Comment is closed only if the NEXT character is a slash */ 628eef1b955SJung-uk Kim 629eef1b955SJung-uk Kim AslInsertLineBuffer (c); 630f1db5ef7SJung-uk Kim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments) 6310d84335fSJung-uk Kim { 632*37d7a5bcSJung-uk Kim *StringBuffer = (char) c; 6330d84335fSJung-uk Kim ++StringBuffer; 6340d84335fSJung-uk Kim } 635eef1b955SJung-uk Kim 6361c0e1b6dSJung-uk Kim if (((c1 = input ()) != '/') && (c1 != EOF)) 637eef1b955SJung-uk Kim { 638eef1b955SJung-uk Kim unput (c1); 639eef1b955SJung-uk Kim goto loop; 640eef1b955SJung-uk Kim } 641eef1b955SJung-uk Kim 642eef1b955SJung-uk Kim if (c1 == EOF) 643eef1b955SJung-uk Kim { 644eef1b955SJung-uk Kim goto EarlyEOF; 645eef1b955SJung-uk Kim } 6460d84335fSJung-uk Kim if (StringBuffer > EndBuffer) 6470d84335fSJung-uk Kim { 6480d84335fSJung-uk Kim goto BufferOverflow; 6490d84335fSJung-uk Kim } 650eef1b955SJung-uk Kim 651eef1b955SJung-uk Kim AslInsertLineBuffer (c1); 6520d84335fSJung-uk Kim CvProcessComment (CurrentState, StringBuffer, c1); 653eef1b955SJung-uk Kim return (TRUE); 654eef1b955SJung-uk Kim 655eef1b955SJung-uk Kim 656eef1b955SJung-uk Kim EarlyEOF: 657eef1b955SJung-uk Kim /* 658eef1b955SJung-uk Kim * Premature End-Of-File 659eef1b955SJung-uk Kim */ 660eef1b955SJung-uk Kim AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF, 6616f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber, 6626f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset, AslGbl_CurrentColumn, 6636f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, NULL); 664eef1b955SJung-uk Kim return (FALSE); 6650d84335fSJung-uk Kim 6660d84335fSJung-uk Kim 6670d84335fSJung-uk Kim BufferOverflow: 6680d84335fSJung-uk Kim 6690d84335fSJung-uk Kim /* Comment was too long */ 6700d84335fSJung-uk Kim 6710d84335fSJung-uk Kim AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH, 6726f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber, 6736f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset, AslGbl_CurrentColumn, 6746f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096"); 6750d84335fSJung-uk Kim return (FALSE); 6760d84335fSJung-uk Kim 677eef1b955SJung-uk Kim } 678eef1b955SJung-uk Kim 679eef1b955SJung-uk Kim 680eef1b955SJung-uk Kim /******************************************************************************* 681eef1b955SJung-uk Kim * 682eef1b955SJung-uk Kim * FUNCTION: AslDoCommentType2 683eef1b955SJung-uk Kim * 684eef1b955SJung-uk Kim * PARAMETERS: none 685eef1b955SJung-uk Kim * 686eef1b955SJung-uk Kim * RETURN: none 687eef1b955SJung-uk Kim * 6880d84335fSJung-uk Kim * DESCRIPTION: Process a new "//" comment. Inline comments will be converted 6890d84335fSJung-uk Kim * to "/ *" standard comments. 690eef1b955SJung-uk Kim * 691eef1b955SJung-uk Kim ******************************************************************************/ 692eef1b955SJung-uk Kim 6930d84335fSJung-uk Kim static BOOLEAN 694eef1b955SJung-uk Kim AslDoCommentType2 ( 695eef1b955SJung-uk Kim void) 696eef1b955SJung-uk Kim { 697f38b0f21SJung-uk Kim int c; 6986f1f1a63SJung-uk Kim char *StringBuffer = AslGbl_MsgBuffer; 6996f1f1a63SJung-uk Kim char *EndBuffer = AslGbl_MsgBuffer + ASL_MSG_BUFFER_SIZE; 7006f1f1a63SJung-uk Kim ASL_COMMENT_STATE CurrentState = AslGbl_CommentState; 701eef1b955SJung-uk Kim 702eef1b955SJung-uk Kim 703eef1b955SJung-uk Kim AslInsertLineBuffer ('/'); 7040d84335fSJung-uk Kim 705f1db5ef7SJung-uk Kim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments) 7060d84335fSJung-uk Kim { 707af051161SJung-uk Kim AslInsertLineBuffer ('*'); 7080d84335fSJung-uk Kim *StringBuffer = '/'; 7090d84335fSJung-uk Kim ++StringBuffer; 7100d84335fSJung-uk Kim *StringBuffer = '*'; 7110d84335fSJung-uk Kim ++StringBuffer; 7120d84335fSJung-uk Kim } 713af051161SJung-uk Kim else 714af051161SJung-uk Kim { 715af051161SJung-uk Kim AslInsertLineBuffer ('/'); 716af051161SJung-uk Kim } 717eef1b955SJung-uk Kim 7181c0e1b6dSJung-uk Kim while (((c = input ()) != '\n') && (c != EOF)) 719eef1b955SJung-uk Kim { 720eef1b955SJung-uk Kim AslInsertLineBuffer (c); 721f1db5ef7SJung-uk Kim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments) 7220d84335fSJung-uk Kim { 723*37d7a5bcSJung-uk Kim *StringBuffer = (char) c; 7240d84335fSJung-uk Kim ++StringBuffer; 7250d84335fSJung-uk Kim } 726eef1b955SJung-uk Kim } 727eef1b955SJung-uk Kim 728eef1b955SJung-uk Kim if (c == EOF) 729eef1b955SJung-uk Kim { 730eef1b955SJung-uk Kim /* End of file is OK, change to newline. Let parser detect EOF later */ 731eef1b955SJung-uk Kim 732eef1b955SJung-uk Kim c = '\n'; 733eef1b955SJung-uk Kim } 734eef1b955SJung-uk Kim 7350d84335fSJung-uk Kim if (StringBuffer > EndBuffer) 7360d84335fSJung-uk Kim { 7370d84335fSJung-uk Kim goto BufferOverflow; 7380d84335fSJung-uk Kim } 739eef1b955SJung-uk Kim AslInsertLineBuffer (c); 7400d84335fSJung-uk Kim 7410d84335fSJung-uk Kim CvProcessCommentType2 (CurrentState, StringBuffer); 742eef1b955SJung-uk Kim return (TRUE); 7430d84335fSJung-uk Kim 7440d84335fSJung-uk Kim 7450d84335fSJung-uk Kim BufferOverflow: 7460d84335fSJung-uk Kim 7470d84335fSJung-uk Kim /* Comment was too long */ 7480d84335fSJung-uk Kim 7490d84335fSJung-uk Kim AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH, 7506f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber, 7516f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset, AslGbl_CurrentColumn, 7526f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096"); 7530d84335fSJung-uk Kim return (FALSE); 7540d84335fSJung-uk Kim 755eef1b955SJung-uk Kim } 756eef1b955SJung-uk Kim 757eef1b955SJung-uk Kim 758eef1b955SJung-uk Kim /******************************************************************************* 759eef1b955SJung-uk Kim * 760eef1b955SJung-uk Kim * FUNCTION: AslDoStringLiteral 761eef1b955SJung-uk Kim * 762eef1b955SJung-uk Kim * PARAMETERS: none 763eef1b955SJung-uk Kim * 764eef1b955SJung-uk Kim * RETURN: none 765eef1b955SJung-uk Kim * 766eef1b955SJung-uk Kim * DESCRIPTION: Process a string literal (surrounded by quotes) 767eef1b955SJung-uk Kim * 768eef1b955SJung-uk Kim ******************************************************************************/ 769eef1b955SJung-uk Kim 770eef1b955SJung-uk Kim static char 771eef1b955SJung-uk Kim AslDoStringLiteral ( 772eef1b955SJung-uk Kim void) 773eef1b955SJung-uk Kim { 7746f1f1a63SJung-uk Kim char *StringBuffer = AslGbl_MsgBuffer; 7756f1f1a63SJung-uk Kim char *EndBuffer = AslGbl_MsgBuffer + ASL_MSG_BUFFER_SIZE; 776eef1b955SJung-uk Kim char *CleanString; 777f38b0f21SJung-uk Kim int StringChar; 778eef1b955SJung-uk Kim UINT32 State = ASL_NORMAL_CHAR; 779eef1b955SJung-uk Kim UINT32 i = 0; 780eef1b955SJung-uk Kim UINT8 Digit; 781eef1b955SJung-uk Kim char ConvertBuffer[4]; 782eef1b955SJung-uk Kim 783eef1b955SJung-uk Kim 784eef1b955SJung-uk Kim /* 785eef1b955SJung-uk Kim * Eat chars until end-of-literal. 786eef1b955SJung-uk Kim * NOTE: Put back the original surrounding quotes into the 787eef1b955SJung-uk Kim * source line buffer. 788eef1b955SJung-uk Kim */ 789eef1b955SJung-uk Kim AslInsertLineBuffer ('\"'); 790f38b0f21SJung-uk Kim while ((StringChar = input()) != EOF) 791eef1b955SJung-uk Kim { 792eef1b955SJung-uk Kim AslInsertLineBuffer (StringChar); 793eef1b955SJung-uk Kim 794eef1b955SJung-uk Kim DoCharacter: 795eef1b955SJung-uk Kim switch (State) 796eef1b955SJung-uk Kim { 797eef1b955SJung-uk Kim case ASL_NORMAL_CHAR: 798eef1b955SJung-uk Kim 799eef1b955SJung-uk Kim switch (StringChar) 800eef1b955SJung-uk Kim { 801eef1b955SJung-uk Kim case '\\': 802eef1b955SJung-uk Kim /* 803eef1b955SJung-uk Kim * Special handling for backslash-escape sequence. We will 804eef1b955SJung-uk Kim * toss the backslash and translate the escape char(s). 805eef1b955SJung-uk Kim */ 806eef1b955SJung-uk Kim State = ASL_ESCAPE_SEQUENCE; 807eef1b955SJung-uk Kim continue; 808eef1b955SJung-uk Kim 809eef1b955SJung-uk Kim case '\"': 810eef1b955SJung-uk Kim 811eef1b955SJung-uk Kim /* String terminator */ 812eef1b955SJung-uk Kim 813eef1b955SJung-uk Kim goto CompletedString; 8149c48c75eSJung-uk Kim 8159c48c75eSJung-uk Kim default: 816a9d8d09cSJung-uk Kim 8179c48c75eSJung-uk Kim break; 818eef1b955SJung-uk Kim } 819eef1b955SJung-uk Kim break; 820eef1b955SJung-uk Kim 821eef1b955SJung-uk Kim 822eef1b955SJung-uk Kim case ASL_ESCAPE_SEQUENCE: 823eef1b955SJung-uk Kim 824eef1b955SJung-uk Kim State = ASL_NORMAL_CHAR; 825eef1b955SJung-uk Kim switch (StringChar) 826eef1b955SJung-uk Kim { 827eef1b955SJung-uk Kim case 'a': 828a9d8d09cSJung-uk Kim 829eef1b955SJung-uk Kim StringChar = 0x07; /* BELL */ 830eef1b955SJung-uk Kim break; 831eef1b955SJung-uk Kim 832eef1b955SJung-uk Kim case 'b': 833a9d8d09cSJung-uk Kim 834eef1b955SJung-uk Kim StringChar = 0x08; /* BACKSPACE */ 835eef1b955SJung-uk Kim break; 836eef1b955SJung-uk Kim 837eef1b955SJung-uk Kim case 'f': 838a9d8d09cSJung-uk Kim 839eef1b955SJung-uk Kim StringChar = 0x0C; /* FORMFEED */ 840eef1b955SJung-uk Kim break; 841eef1b955SJung-uk Kim 842eef1b955SJung-uk Kim case 'n': 843a9d8d09cSJung-uk Kim 844eef1b955SJung-uk Kim StringChar = 0x0A; /* LINEFEED */ 845eef1b955SJung-uk Kim break; 846eef1b955SJung-uk Kim 847eef1b955SJung-uk Kim case 'r': 848a9d8d09cSJung-uk Kim 849eef1b955SJung-uk Kim StringChar = 0x0D; /* CARRIAGE RETURN*/ 850eef1b955SJung-uk Kim break; 851eef1b955SJung-uk Kim 852eef1b955SJung-uk Kim case 't': 853a9d8d09cSJung-uk Kim 854eef1b955SJung-uk Kim StringChar = 0x09; /* HORIZONTAL TAB */ 855eef1b955SJung-uk Kim break; 856eef1b955SJung-uk Kim 857eef1b955SJung-uk Kim case 'v': 858a9d8d09cSJung-uk Kim 859eef1b955SJung-uk Kim StringChar = 0x0B; /* VERTICAL TAB */ 860eef1b955SJung-uk Kim break; 861eef1b955SJung-uk Kim 862eef1b955SJung-uk Kim case 'x': 863a9d8d09cSJung-uk Kim 864eef1b955SJung-uk Kim State = ASL_HEX_CONSTANT; 865eef1b955SJung-uk Kim i = 0; 866eef1b955SJung-uk Kim continue; 867eef1b955SJung-uk Kim 868eef1b955SJung-uk Kim case '\'': /* Single Quote */ 869eef1b955SJung-uk Kim case '\"': /* Double Quote */ 870eef1b955SJung-uk Kim case '\\': /* Backslash */ 871a9d8d09cSJung-uk Kim 872eef1b955SJung-uk Kim break; 873eef1b955SJung-uk Kim 874eef1b955SJung-uk Kim default: 875eef1b955SJung-uk Kim 876eef1b955SJung-uk Kim /* Check for an octal digit (0-7) */ 877eef1b955SJung-uk Kim 878eef1b955SJung-uk Kim if (ACPI_IS_OCTAL_DIGIT (StringChar)) 879eef1b955SJung-uk Kim { 880eef1b955SJung-uk Kim State = ASL_OCTAL_CONSTANT; 881*37d7a5bcSJung-uk Kim ConvertBuffer[0] = (char) StringChar; 882eef1b955SJung-uk Kim i = 1; 883eef1b955SJung-uk Kim continue; 884eef1b955SJung-uk Kim } 885eef1b955SJung-uk Kim 886eef1b955SJung-uk Kim /* Unknown escape sequence issue warning, but use the character */ 887eef1b955SJung-uk Kim 888eef1b955SJung-uk Kim AslCommonError (ASL_WARNING, ASL_MSG_INVALID_ESCAPE, 8896f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber, 8906f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset, AslGbl_CurrentColumn, 8916f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, NULL); 892eef1b955SJung-uk Kim break; 893eef1b955SJung-uk Kim } 894eef1b955SJung-uk Kim break; 895eef1b955SJung-uk Kim 896eef1b955SJung-uk Kim 897eef1b955SJung-uk Kim case ASL_OCTAL_CONSTANT: 898eef1b955SJung-uk Kim 899eef1b955SJung-uk Kim /* Up to three octal digits allowed */ 900eef1b955SJung-uk Kim 901eef1b955SJung-uk Kim if (!ACPI_IS_OCTAL_DIGIT (StringChar) || 902eef1b955SJung-uk Kim (i > 2)) 903eef1b955SJung-uk Kim { 904eef1b955SJung-uk Kim /* 905eef1b955SJung-uk Kim * Reached end of the constant. Convert the assembled ASCII 906eef1b955SJung-uk Kim * string and resume processing of the next character 907eef1b955SJung-uk Kim */ 908eef1b955SJung-uk Kim ConvertBuffer[i] = 0; 9095ef50723SJung-uk Kim Digit = (UINT8) strtoul (ConvertBuffer, NULL, 8); 910eef1b955SJung-uk Kim 911eef1b955SJung-uk Kim /* Check for NULL or non-ascii character (ignore if so) */ 912eef1b955SJung-uk Kim 913eef1b955SJung-uk Kim if ((Digit == 0) || (Digit > ACPI_ASCII_MAX)) 914eef1b955SJung-uk Kim { 915eef1b955SJung-uk Kim AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING, 9166f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber, 9176f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset, AslGbl_CurrentColumn, 9186f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, NULL); 919eef1b955SJung-uk Kim } 920eef1b955SJung-uk Kim else 921eef1b955SJung-uk Kim { 922eef1b955SJung-uk Kim *StringBuffer = (char) Digit; 923eef1b955SJung-uk Kim StringBuffer++; 924eef1b955SJung-uk Kim if (StringBuffer >= EndBuffer) 925eef1b955SJung-uk Kim { 926eef1b955SJung-uk Kim goto BufferOverflow; 927eef1b955SJung-uk Kim } 928eef1b955SJung-uk Kim } 929eef1b955SJung-uk Kim 930eef1b955SJung-uk Kim State = ASL_NORMAL_CHAR; 931eef1b955SJung-uk Kim goto DoCharacter; 932eef1b955SJung-uk Kim break; 933eef1b955SJung-uk Kim } 934eef1b955SJung-uk Kim 935eef1b955SJung-uk Kim /* Append another digit of the constant */ 936eef1b955SJung-uk Kim 937*37d7a5bcSJung-uk Kim ConvertBuffer[i] = (char) StringChar; 938eef1b955SJung-uk Kim i++; 939eef1b955SJung-uk Kim continue; 940eef1b955SJung-uk Kim 941eef1b955SJung-uk Kim case ASL_HEX_CONSTANT: 942eef1b955SJung-uk Kim 943eef1b955SJung-uk Kim /* Up to two hex digits allowed */ 944eef1b955SJung-uk Kim 9455ef50723SJung-uk Kim if (!isxdigit (StringChar) || 946eef1b955SJung-uk Kim (i > 1)) 947eef1b955SJung-uk Kim { 948eef1b955SJung-uk Kim /* 949eef1b955SJung-uk Kim * Reached end of the constant. Convert the assembled ASCII 950eef1b955SJung-uk Kim * string and resume processing of the next character 951eef1b955SJung-uk Kim */ 952eef1b955SJung-uk Kim ConvertBuffer[i] = 0; 9535ef50723SJung-uk Kim Digit = (UINT8) strtoul (ConvertBuffer, NULL, 16); 954eef1b955SJung-uk Kim 955eef1b955SJung-uk Kim /* Check for NULL or non-ascii character (ignore if so) */ 956eef1b955SJung-uk Kim 957eef1b955SJung-uk Kim if ((Digit == 0) || (Digit > ACPI_ASCII_MAX)) 958eef1b955SJung-uk Kim { 959eef1b955SJung-uk Kim AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING, 9606f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber, 9616f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset, AslGbl_CurrentColumn, 9626f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, NULL); 963eef1b955SJung-uk Kim } 964eef1b955SJung-uk Kim else 965eef1b955SJung-uk Kim { 966eef1b955SJung-uk Kim *StringBuffer = (char) Digit; 967eef1b955SJung-uk Kim StringBuffer++; 968eef1b955SJung-uk Kim if (StringBuffer >= EndBuffer) 969eef1b955SJung-uk Kim { 970eef1b955SJung-uk Kim goto BufferOverflow; 971eef1b955SJung-uk Kim } 972eef1b955SJung-uk Kim } 973eef1b955SJung-uk Kim 974eef1b955SJung-uk Kim State = ASL_NORMAL_CHAR; 975eef1b955SJung-uk Kim goto DoCharacter; 976eef1b955SJung-uk Kim break; 977eef1b955SJung-uk Kim } 978eef1b955SJung-uk Kim 979eef1b955SJung-uk Kim /* Append another digit of the constant */ 980eef1b955SJung-uk Kim 981*37d7a5bcSJung-uk Kim ConvertBuffer[i] = (char) StringChar; 982eef1b955SJung-uk Kim i++; 983eef1b955SJung-uk Kim continue; 9849c48c75eSJung-uk Kim 9859c48c75eSJung-uk Kim default: 986a9d8d09cSJung-uk Kim 9879c48c75eSJung-uk Kim break; 988eef1b955SJung-uk Kim } 989eef1b955SJung-uk Kim 990eef1b955SJung-uk Kim /* Save the finished character */ 991eef1b955SJung-uk Kim 992*37d7a5bcSJung-uk Kim *StringBuffer = (char) StringChar; 993eef1b955SJung-uk Kim StringBuffer++; 994eef1b955SJung-uk Kim if (StringBuffer >= EndBuffer) 995eef1b955SJung-uk Kim { 996eef1b955SJung-uk Kim goto BufferOverflow; 997eef1b955SJung-uk Kim } 998eef1b955SJung-uk Kim } 999eef1b955SJung-uk Kim 1000eef1b955SJung-uk Kim /* 1001eef1b955SJung-uk Kim * Premature End-Of-File 1002eef1b955SJung-uk Kim */ 1003eef1b955SJung-uk Kim AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF, 10046f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber, 10056f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset, AslGbl_CurrentColumn, 10066f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, NULL); 1007eef1b955SJung-uk Kim return (FALSE); 1008eef1b955SJung-uk Kim 1009eef1b955SJung-uk Kim 1010eef1b955SJung-uk Kim CompletedString: 1011eef1b955SJung-uk Kim /* 1012eef1b955SJung-uk Kim * Null terminate the input string and copy string to a new buffer 1013eef1b955SJung-uk Kim */ 1014eef1b955SJung-uk Kim *StringBuffer = 0; 1015eef1b955SJung-uk Kim 10166f1f1a63SJung-uk Kim CleanString = UtLocalCacheCalloc (strlen (AslGbl_MsgBuffer) + 1); 10176f1f1a63SJung-uk Kim strcpy (CleanString, AslGbl_MsgBuffer); 1018eef1b955SJung-uk Kim AslCompilerlval.s = CleanString; 1019eef1b955SJung-uk Kim return (TRUE); 1020eef1b955SJung-uk Kim 1021eef1b955SJung-uk Kim 1022eef1b955SJung-uk Kim BufferOverflow: 1023eef1b955SJung-uk Kim 1024eef1b955SJung-uk Kim /* Literal was too long */ 1025eef1b955SJung-uk Kim 1026eef1b955SJung-uk Kim AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH, 10276f1f1a63SJung-uk Kim AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber, 10286f1f1a63SJung-uk Kim AslGbl_CurrentLineOffset, AslGbl_CurrentColumn, 10296f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096"); 1030eef1b955SJung-uk Kim return (FALSE); 1031eef1b955SJung-uk Kim } 1032