1234518Sjkim/****************************************************************************** 2234518Sjkim * 3234518Sjkim * Module Name: aslsupport.l - Flex/lex scanner C support routines. 4234518Sjkim * NOTE: Included into aslcompile.l, not compiled by itself. 5234518Sjkim * 6234518Sjkim *****************************************************************************/ 7234518Sjkim 8316303Sjkim/****************************************************************************** 9316303Sjkim * 10316303Sjkim * 1. Copyright Notice 11316303Sjkim * 12316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 13234518Sjkim * All rights reserved. 14234518Sjkim * 15316303Sjkim * 2. License 16316303Sjkim * 17316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 18316303Sjkim * rights. You may have additional license terms from the party that provided 19316303Sjkim * you this software, covering your right to use that party's intellectual 20316303Sjkim * property rights. 21316303Sjkim * 22316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23316303Sjkim * copy of the source code appearing in this file ("Covered Code") an 24316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 26316303Sjkim * make derivatives, distribute, use and display any portion of the Covered 27316303Sjkim * Code in any form, with the right to sublicense such rights; and 28316303Sjkim * 29316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30316303Sjkim * license (with the right to sublicense), under only those claims of Intel 31316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 32316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof 33316303Sjkim * solely to the minimum extent necessary to exercise the above copyright 34316303Sjkim * license, and in no event shall the patent license extend to any additions 35316303Sjkim * to or modifications of the Original Intel Code. No other license or right 36316303Sjkim * is granted directly or by implication, estoppel or otherwise; 37316303Sjkim * 38316303Sjkim * The above copyright and patent license is granted only if the following 39316303Sjkim * conditions are met: 40316303Sjkim * 41316303Sjkim * 3. Conditions 42316303Sjkim * 43316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44316303Sjkim * Redistribution of source code of any substantial portion of the Covered 45316303Sjkim * Code or modification with rights to further distribute source must include 46316303Sjkim * the above Copyright Notice, the above License, this list of Conditions, 47316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 48316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 49316303Sjkim * contain a file documenting the changes Licensee made to create that Covered 50316303Sjkim * Code and the date of any change. Licensee must include in that file the 51316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 52316303Sjkim * must include a prominent statement that the modification is derived, 53316303Sjkim * directly or indirectly, from Original Intel Code. 54316303Sjkim * 55316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56316303Sjkim * Redistribution of source code of any substantial portion of the Covered 57316303Sjkim * Code or modification without rights to further distribute source must 58316303Sjkim * include the following Disclaimer and Export Compliance provision in the 59316303Sjkim * documentation and/or other materials provided with distribution. In 60316303Sjkim * addition, Licensee may not authorize further sublicense of source of any 61316303Sjkim * portion of the Covered Code, and must include terms to the effect that the 62316303Sjkim * license from Licensee to its licensee is limited to the intellectual 63316303Sjkim * property embodied in the software Licensee provides to its licensee, and 64316303Sjkim * not to intellectual property embodied in modifications its licensee may 65316303Sjkim * make. 66316303Sjkim * 67316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 68316303Sjkim * substantial portion of the Covered Code or modification must reproduce the 69316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 70316303Sjkim * provision in the documentation and/or other materials provided with the 71316303Sjkim * distribution. 72316303Sjkim * 73316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 74316303Sjkim * Intel Code. 75316303Sjkim * 76316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 78316303Sjkim * other dealings in products derived from or relating to the Covered Code 79316303Sjkim * without prior written authorization from Intel. 80316303Sjkim * 81316303Sjkim * 4. Disclaimer and Export Compliance 82316303Sjkim * 83316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89316303Sjkim * PARTICULAR PURPOSE. 90316303Sjkim * 91316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98316303Sjkim * LIMITED REMEDY. 99316303Sjkim * 100316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 101316303Sjkim * software or system incorporating such software without first obtaining any 102316303Sjkim * required license or other approval from the U. S. Department of Commerce or 103316303Sjkim * any other agency or department of the United States Government. In the 104316303Sjkim * event Licensee exports any such software from the United States or 105316303Sjkim * re-exports any such software from a foreign destination, Licensee shall 106316303Sjkim * ensure that the distribution and export/re-export of the software is in 107316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 108316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109316303Sjkim * any of its subsidiaries will export/re-export any technical data, process, 110316303Sjkim * software, or service, directly or indirectly, to any country for which the 111316303Sjkim * United States government or any agency thereof requires an export license, 112316303Sjkim * other governmental approval, or letter of assurance, without first obtaining 113316303Sjkim * such license, approval or letter. 114316303Sjkim * 115316303Sjkim ***************************************************************************** 116316303Sjkim * 117316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 118316303Sjkim * following license: 119316303Sjkim * 120234518Sjkim * Redistribution and use in source and binary forms, with or without 121234518Sjkim * modification, are permitted provided that the following conditions 122234518Sjkim * are met: 123234518Sjkim * 1. Redistributions of source code must retain the above copyright 124234518Sjkim * notice, this list of conditions, and the following disclaimer, 125234518Sjkim * without modification. 126234518Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 127234518Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 128234518Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 129234518Sjkim * including a substantially similar Disclaimer requirement for further 130234518Sjkim * binary redistribution. 131234518Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 132234518Sjkim * of any contributors may be used to endorse or promote products derived 133234518Sjkim * from this software without specific prior written permission. 134234518Sjkim * 135316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 136316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 137316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 138316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 139316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 140316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 141316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 142316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 143316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 144316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 145316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 146316303Sjkim * 147316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 148234518Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 149234518Sjkim * Software Foundation. 150234518Sjkim * 151316303Sjkim *****************************************************************************/ 152234518Sjkim 153234518Sjkim/* Configuration */ 154234518Sjkim 155234518Sjkim#define ASL_SPACES_PER_TAB 4 156234518Sjkim 157234518Sjkim#define ASL_NORMAL_CHAR 0 158234518Sjkim#define ASL_ESCAPE_SEQUENCE 1 159234518Sjkim#define ASL_OCTAL_CONSTANT 2 160234518Sjkim#define ASL_HEX_CONSTANT 3 161234518Sjkim 162234518Sjkim 163316303Sjkimvoid 164316303Sjkimyyerror (char const *s) 165234518Sjkim{ 166234518Sjkim 167316303Sjkim AcpiOsPrintf ("YYERROR: %s\n", s); 168316303Sjkim} 169234518Sjkim 170234518Sjkim 171278970Sjkim/******************************************************************************* 172278970Sjkim * 173278970Sjkim * FUNCTION: AslParserCleanup 174278970Sjkim * 175278970Sjkim * Used to delete the current buffer 176278970Sjkim * 177278970Sjkim ******************************************************************************/ 178278970Sjkim 179272444Sjkimvoid 180272444SjkimAslParserCleanup ( 181272444Sjkim void) 182272444Sjkim{ 183272444Sjkim 184272444Sjkim yy_delete_buffer (YY_CURRENT_BUFFER); 185272444Sjkim} 186272444Sjkim 187272444Sjkim 188234518Sjkim/******************************************************************************* 189234518Sjkim * 190234518Sjkim * FUNCTION: AslDoLineDirective 191234518Sjkim * 192234518Sjkim * PARAMETERS: None. Uses input() to access current source code line 193234518Sjkim * 194234518Sjkim * RETURN: Updates global line number and filename 195234518Sjkim * 196234518Sjkim * DESCRIPTION: Handle #line directives emitted by the preprocessor. 197234518Sjkim * 198234518Sjkim * The #line directive is emitted by the preprocesser, and is used to 199234518Sjkim * pass through line numbers from the original source code file to the 200234518Sjkim * preprocessor output file (.i). This allows any compiler-generated 201234518Sjkim * error messages to be displayed with the correct line number. 202234518Sjkim * 203234518Sjkim ******************************************************************************/ 204234518Sjkim 205234518Sjkimstatic void 206234518SjkimAslDoLineDirective ( 207234518Sjkim void) 208234518Sjkim{ 209237412Sjkim int c; 210234518Sjkim char *Token; 211234518Sjkim UINT32 LineNumber; 212234518Sjkim char *Filename; 213237412Sjkim UINT32 i; 214234518Sjkim 215284583Sjkim Gbl_HasIncludeFiles = TRUE; 216234518Sjkim 217234518Sjkim /* Eat the entire line that contains the #line directive */ 218234518Sjkim 219237412Sjkim Gbl_LineBufPtr = Gbl_CurrentLineBuffer; 220237412Sjkim 221237412Sjkim while ((c = input()) != '\n' && c != EOF) 222234518Sjkim { 223237412Sjkim *Gbl_LineBufPtr = c; 224237412Sjkim Gbl_LineBufPtr++; 225234518Sjkim } 226237412Sjkim *Gbl_LineBufPtr = 0; 227234518Sjkim 228234518Sjkim /* First argument is the actual line number */ 229234518Sjkim 230234518Sjkim Token = strtok (Gbl_CurrentLineBuffer, " "); 231234518Sjkim if (!Token) 232234518Sjkim { 233234518Sjkim goto ResetAndExit; 234234518Sjkim } 235234518Sjkim 236237412Sjkim /* First argument is the line number */ 237234518Sjkim 238234518Sjkim LineNumber = (UINT32) UtDoConstant (Token); 239234518Sjkim 240237412Sjkim /* Emit the appropriate number of newlines */ 241237412Sjkim 242237412Sjkim Gbl_CurrentColumn = 0; 243237412Sjkim if (LineNumber > Gbl_CurrentLineNumber) 244237412Sjkim { 245237412Sjkim for (i = 0; i < (LineNumber - Gbl_CurrentLineNumber); i++) 246237412Sjkim { 247237412Sjkim FlWriteFile (ASL_FILE_SOURCE_OUTPUT, "\n", 1); 248237412Sjkim Gbl_CurrentColumn++; 249237412Sjkim } 250237412Sjkim } 251237412Sjkim 252237412Sjkim FlSetLineNumber (LineNumber); 253237412Sjkim 254234518Sjkim /* Second argument is the optional filename (in double quotes) */ 255234518Sjkim 256234518Sjkim Token = strtok (NULL, " \""); 257234518Sjkim if (Token) 258234518Sjkim { 259234518Sjkim Filename = ACPI_ALLOCATE_ZEROED (strlen (Token) + 1); 260234518Sjkim strcpy (Filename, Token); 261234518Sjkim FlSetFilename (Filename); 262234518Sjkim } 263234518Sjkim 264234518Sjkim /* Third argument is not supported at this time */ 265234518Sjkim 266234518SjkimResetAndExit: 267237412Sjkim 268237412Sjkim /* Reset globals for a new line */ 269237412Sjkim 270237412Sjkim Gbl_CurrentLineOffset += Gbl_CurrentColumn; 271237412Sjkim Gbl_CurrentColumn = 0; 272237412Sjkim Gbl_LineBufPtr = Gbl_CurrentLineBuffer; 273234518Sjkim} 274234518Sjkim 275234518Sjkim 276234518Sjkim/******************************************************************************* 277234518Sjkim * 278234518Sjkim * FUNCTION: AslPopInputFileStack 279234518Sjkim * 280234518Sjkim * PARAMETERS: None 281234518Sjkim * 282234518Sjkim * RETURN: 0 if a node was popped, -1 otherwise 283234518Sjkim * 284234518Sjkim * DESCRIPTION: Pop the top of the input file stack and point the parser to 285241973Sjkim * the saved parse buffer contained in the fnode. Also, set the 286241973Sjkim * global line counters to the saved values. This function is 287234518Sjkim * called when an include file reaches EOF. 288234518Sjkim * 289234518Sjkim ******************************************************************************/ 290234518Sjkim 291234518Sjkimint 292234518SjkimAslPopInputFileStack ( 293234518Sjkim void) 294234518Sjkim{ 295234518Sjkim ASL_FILE_NODE *Fnode; 296234518Sjkim 297234518Sjkim 298298714Sjkim Gbl_PreviousIncludeFilename = Gbl_Files[ASL_FILE_INPUT].Filename; 299234518Sjkim Fnode = Gbl_IncludeFileStack; 300278970Sjkim DbgPrint (ASL_PARSE_OUTPUT, 301298714Sjkim "\nPop InputFile Stack, Fnode %p\n", Fnode); 302234518Sjkim 303298714Sjkim DbgPrint (ASL_PARSE_OUTPUT, 304298714Sjkim "Include: Closing \"%s\"\n\n", Gbl_Files[ASL_FILE_INPUT].Filename); 305298714Sjkim 306234518Sjkim if (!Fnode) 307234518Sjkim { 308234518Sjkim return (-1); 309234518Sjkim } 310234518Sjkim 311234518Sjkim /* Close the current include file */ 312234518Sjkim 313234518Sjkim fclose (yyin); 314234518Sjkim 315234518Sjkim /* Update the top-of-stack */ 316234518Sjkim 317234518Sjkim Gbl_IncludeFileStack = Fnode->Next; 318234518Sjkim 319234518Sjkim /* Reset global line counter and filename */ 320234518Sjkim 321234518Sjkim Gbl_Files[ASL_FILE_INPUT].Filename = Fnode->Filename; 322234518Sjkim Gbl_CurrentLineNumber = Fnode->CurrentLineNumber; 323234518Sjkim 324234518Sjkim /* Point the parser to the popped file */ 325234518Sjkim 326234518Sjkim yy_delete_buffer (YY_CURRENT_BUFFER); 327234518Sjkim yy_switch_to_buffer (Fnode->State); 328234518Sjkim 329234518Sjkim /* All done with this node */ 330234518Sjkim 331234518Sjkim ACPI_FREE (Fnode); 332234518Sjkim return (0); 333234518Sjkim} 334234518Sjkim 335234518Sjkim 336234518Sjkim/******************************************************************************* 337234518Sjkim * 338234518Sjkim * FUNCTION: AslPushInputFileStack 339234518Sjkim * 340234518Sjkim * PARAMETERS: InputFile - Open file pointer 341234518Sjkim * Filename - Name of the file 342234518Sjkim * 343234518Sjkim * RETURN: None 344234518Sjkim * 345234518Sjkim * DESCRIPTION: Push the InputFile onto the file stack, and point the parser 346241973Sjkim * to this file. Called when an include file is successfully 347234518Sjkim * opened. 348234518Sjkim * 349234518Sjkim ******************************************************************************/ 350234518Sjkim 351234518Sjkimvoid 352234518SjkimAslPushInputFileStack ( 353234518Sjkim FILE *InputFile, 354234518Sjkim char *Filename) 355234518Sjkim{ 356234518Sjkim ASL_FILE_NODE *Fnode; 357234518Sjkim YY_BUFFER_STATE State; 358234518Sjkim 359234518Sjkim 360234518Sjkim /* Save the current state in an Fnode */ 361234518Sjkim 362234518Sjkim Fnode = UtLocalCalloc (sizeof (ASL_FILE_NODE)); 363234518Sjkim 364278970Sjkim Fnode->File = yyin; 365278970Sjkim Fnode->Next = Gbl_IncludeFileStack; 366278970Sjkim Fnode->State = YY_CURRENT_BUFFER; 367278970Sjkim Fnode->Filename = Gbl_Files[ASL_FILE_INPUT].Filename; 368278970Sjkim Fnode->CurrentLineNumber = Gbl_CurrentLineNumber; 369234518Sjkim 370234518Sjkim /* Push it on the stack */ 371234518Sjkim 372234518Sjkim Gbl_IncludeFileStack = Fnode; 373234518Sjkim 374234518Sjkim /* Point the parser to this file */ 375234518Sjkim 376234518Sjkim State = yy_create_buffer (InputFile, YY_BUF_SIZE); 377234518Sjkim yy_switch_to_buffer (State); 378234518Sjkim 379278970Sjkim DbgPrint (ASL_PARSE_OUTPUT, 380278970Sjkim "\nPush InputFile Stack, returning %p\n\n", InputFile); 381234518Sjkim 382234518Sjkim /* Reset the global line count and filename */ 383234518Sjkim 384272444Sjkim Gbl_Files[ASL_FILE_INPUT].Filename = 385327557Sjkim UtLocalCacheCalloc (strlen (Filename) + 1); 386272444Sjkim 387272444Sjkim strcpy (Gbl_Files[ASL_FILE_INPUT].Filename, Filename); 388272444Sjkim 389234518Sjkim Gbl_CurrentLineNumber = 1; 390234518Sjkim yyin = InputFile; 391316303Sjkim 392316303Sjkim /* converter: reset the comment state to STANDARD_COMMENT */ 393316303Sjkim 394316303Sjkim Gbl_CommentState.CommentType = STANDARD_COMMENT; 395234518Sjkim} 396234518Sjkim 397234518Sjkim 398234518Sjkim/******************************************************************************* 399234518Sjkim * 400234518Sjkim * FUNCTION: AslResetCurrentLineBuffer 401234518Sjkim * 402234518Sjkim * PARAMETERS: None 403234518Sjkim * 404234518Sjkim * RETURN: None 405234518Sjkim * 406234518Sjkim * DESCRIPTION: Reset the Line Buffer to zero, increment global line numbers. 407234518Sjkim * 408234518Sjkim ******************************************************************************/ 409234518Sjkim 410234518Sjkimvoid 411234518SjkimAslResetCurrentLineBuffer ( 412234518Sjkim void) 413234518Sjkim{ 414234518Sjkim 415234518Sjkim if (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle) 416234518Sjkim { 417234518Sjkim FlWriteFile (ASL_FILE_SOURCE_OUTPUT, Gbl_CurrentLineBuffer, 418234518Sjkim Gbl_LineBufPtr - Gbl_CurrentLineBuffer); 419234518Sjkim } 420234518Sjkim 421234518Sjkim Gbl_CurrentLineOffset += Gbl_CurrentColumn; 422234518Sjkim Gbl_CurrentColumn = 0; 423234518Sjkim 424234518Sjkim Gbl_CurrentLineNumber++; 425234518Sjkim Gbl_LogicalLineNumber++; 426234518Sjkim Gbl_LineBufPtr = Gbl_CurrentLineBuffer; 427234518Sjkim} 428234518Sjkim 429234518Sjkim 430234518Sjkim/******************************************************************************* 431234518Sjkim * 432234518Sjkim * FUNCTION: AslInsertLineBuffer 433234518Sjkim * 434278970Sjkim * PARAMETERS: SourceChar - One char from the input ASL source file 435234518Sjkim * 436234518Sjkim * RETURN: None 437234518Sjkim * 438234518Sjkim * DESCRIPTION: Put one character of the source file into the temp line buffer 439234518Sjkim * 440234518Sjkim ******************************************************************************/ 441234518Sjkim 442234518Sjkimvoid 443234518SjkimAslInsertLineBuffer ( 444234518Sjkim int SourceChar) 445234518Sjkim{ 446234518Sjkim UINT32 i; 447234518Sjkim UINT32 Count = 1; 448234518Sjkim 449234518Sjkim 450234518Sjkim if (SourceChar == EOF) 451234518Sjkim { 452234518Sjkim return; 453234518Sjkim } 454234518Sjkim 455234518Sjkim Gbl_InputByteCount++; 456234518Sjkim 457241973Sjkim /* Handle tabs. Convert to spaces */ 458234518Sjkim 459234518Sjkim if (SourceChar == '\t') 460234518Sjkim { 461234518Sjkim SourceChar = ' '; 462234518Sjkim Count = ASL_SPACES_PER_TAB - 463234518Sjkim (Gbl_CurrentColumn & (ASL_SPACES_PER_TAB-1)); 464234518Sjkim } 465234518Sjkim 466234518Sjkim for (i = 0; i < Count; i++) 467234518Sjkim { 468234518Sjkim Gbl_CurrentColumn++; 469234518Sjkim 470234518Sjkim /* Insert the character into the line buffer */ 471234518Sjkim 472234518Sjkim *Gbl_LineBufPtr = (UINT8) SourceChar; 473234518Sjkim Gbl_LineBufPtr++; 474234518Sjkim 475278970Sjkim if (Gbl_LineBufPtr > 476278970Sjkim (Gbl_CurrentLineBuffer + (Gbl_LineBufferSize - 1))) 477234518Sjkim { 478234518Sjkim#if 0 479234518Sjkim /* 480234518Sjkim * Warning if we have split a long source line. 481234518Sjkim * <Probably overkill> 482234518Sjkim */ 483240716Sjkim sprintf (MsgBuffer, "Max %u", Gbl_LineBufferSize); 484234518Sjkim AslCommonError (ASL_WARNING, ASL_MSG_LONG_LINE, 485278970Sjkim Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 486278970Sjkim Gbl_CurrentLineOffset, Gbl_CurrentColumn, 487278970Sjkim Gbl_Files[ASL_FILE_INPUT].Filename, MsgBuffer); 488234518Sjkim#endif 489234518Sjkim 490234518Sjkim AslResetCurrentLineBuffer (); 491234518Sjkim } 492234518Sjkim else if (SourceChar == '\n') 493234518Sjkim { 494234518Sjkim /* End of line */ 495234518Sjkim 496234518Sjkim AslResetCurrentLineBuffer (); 497234518Sjkim } 498316303Sjkim 499327557Sjkim if (AcpiGbl_CaptureComments) 500316303Sjkim { 501316303Sjkim CvProcessCommentState (SourceChar); 502316303Sjkim } 503234518Sjkim } 504234518Sjkim} 505234518Sjkim 506234518Sjkim 507234518Sjkim/******************************************************************************* 508234518Sjkim * 509234518Sjkim * FUNCTION: count 510234518Sjkim * 511278970Sjkim * PARAMETERS: yytext - Contains the matched keyword. 512278970Sjkim * Type - Keyword/Character type: 513278970Sjkim * 0 = anything except a keyword 514278970Sjkim * 1 = pseudo-keywords 515278970Sjkim * 2 = non-executable ASL keywords 516278970Sjkim * 3 = executable ASL keywords 517234518Sjkim * 518234518Sjkim * RETURN: None 519234518Sjkim * 520234518Sjkim * DESCRIPTION: Count keywords and put them into the line buffer 521234518Sjkim * 522234518Sjkim ******************************************************************************/ 523234518Sjkim 524234518Sjkimstatic void 525234518Sjkimcount ( 526234518Sjkim int Type) 527234518Sjkim{ 528327557Sjkim char *p; 529234518Sjkim 530234518Sjkim 531234518Sjkim switch (Type) 532234518Sjkim { 533234518Sjkim case 2: 534250838Sjkim 535234518Sjkim TotalKeywords++; 536234518Sjkim TotalNamedObjects++; 537234518Sjkim break; 538234518Sjkim 539234518Sjkim case 3: 540250838Sjkim 541234518Sjkim TotalKeywords++; 542234518Sjkim TotalExecutableOpcodes++; 543234518Sjkim break; 544246849Sjkim 545246849Sjkim default: 546250838Sjkim 547246849Sjkim break; 548234518Sjkim } 549234518Sjkim 550327557Sjkim for (p = yytext; *p != '\0'; p++) 551234518Sjkim { 552327557Sjkim AslInsertLineBuffer (*p); 553234518Sjkim *Gbl_LineBufPtr = 0; 554234518Sjkim } 555234518Sjkim} 556234518Sjkim 557234518Sjkim 558234518Sjkim/******************************************************************************* 559234518Sjkim * 560234518Sjkim * FUNCTION: AslDoComment 561234518Sjkim * 562234518Sjkim * PARAMETERS: none 563234518Sjkim * 564234518Sjkim * RETURN: none 565234518Sjkim * 566234518Sjkim * DESCRIPTION: Process a standard comment. 567234518Sjkim * 568234518Sjkim ******************************************************************************/ 569234518Sjkim 570316303Sjkimstatic BOOLEAN 571234518SjkimAslDoComment ( 572234518Sjkim void) 573234518Sjkim{ 574316303Sjkim int c; 575316303Sjkim int c1 = 0; 576316303Sjkim char *StringBuffer = MsgBuffer; 577316303Sjkim char *EndBuffer = MsgBuffer + ASL_MSG_BUFFER_SIZE; 578316303Sjkim ASL_COMMENT_STATE CurrentState = Gbl_CommentState; /* to reference later on */ 579234518Sjkim 580234518Sjkim 581234518Sjkim AslInsertLineBuffer ('/'); 582234518Sjkim AslInsertLineBuffer ('*'); 583327557Sjkim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments) 584316303Sjkim { 585316303Sjkim *StringBuffer = '/'; 586316303Sjkim ++StringBuffer; 587316303Sjkim *StringBuffer = '*'; 588316303Sjkim ++StringBuffer; 589316303Sjkim } 590234518Sjkim 591234518Sjkimloop: 592234518Sjkim 593234518Sjkim /* Eat chars until end-of-comment */ 594234518Sjkim 595278970Sjkim while (((c = input ()) != '*') && (c != EOF)) 596234518Sjkim { 597234518Sjkim AslInsertLineBuffer (c); 598327557Sjkim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments) 599316303Sjkim { 600316303Sjkim *StringBuffer = c; 601316303Sjkim ++StringBuffer; 602316303Sjkim } 603234518Sjkim c1 = c; 604234518Sjkim } 605234518Sjkim 606234518Sjkim if (c == EOF) 607234518Sjkim { 608234518Sjkim goto EarlyEOF; 609234518Sjkim } 610234518Sjkim 611234518Sjkim /* 612234518Sjkim * Check for nested comment -- can help catch cases where a previous 613234518Sjkim * comment was accidently left unterminated 614234518Sjkim */ 615234518Sjkim if ((c1 == '/') && (c == '*')) 616234518Sjkim { 617234518Sjkim AslCommonError (ASL_WARNING, ASL_MSG_NESTED_COMMENT, 618278970Sjkim Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 619278970Sjkim Gbl_InputByteCount, Gbl_CurrentColumn, 620278970Sjkim Gbl_Files[ASL_FILE_INPUT].Filename, NULL); 621234518Sjkim } 622234518Sjkim 623234518Sjkim /* Comment is closed only if the NEXT character is a slash */ 624234518Sjkim 625234518Sjkim AslInsertLineBuffer (c); 626327557Sjkim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments) 627316303Sjkim { 628316303Sjkim *StringBuffer = c; 629316303Sjkim ++StringBuffer; 630316303Sjkim } 631234518Sjkim 632278970Sjkim if (((c1 = input ()) != '/') && (c1 != EOF)) 633234518Sjkim { 634316303Sjkim unput (c1); 635234518Sjkim goto loop; 636234518Sjkim } 637234518Sjkim 638234518Sjkim if (c1 == EOF) 639234518Sjkim { 640234518Sjkim goto EarlyEOF; 641234518Sjkim } 642316303Sjkim if (StringBuffer > EndBuffer) 643316303Sjkim { 644316303Sjkim goto BufferOverflow; 645316303Sjkim } 646234518Sjkim 647234518Sjkim AslInsertLineBuffer (c1); 648316303Sjkim CvProcessComment (CurrentState, StringBuffer, c1); 649234518Sjkim return (TRUE); 650234518Sjkim 651234518Sjkim 652234518SjkimEarlyEOF: 653234518Sjkim /* 654234518Sjkim * Premature End-Of-File 655234518Sjkim */ 656234518Sjkim AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF, 657278970Sjkim Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 658278970Sjkim Gbl_CurrentLineOffset, Gbl_CurrentColumn, 659278970Sjkim Gbl_Files[ASL_FILE_INPUT].Filename, NULL); 660234518Sjkim return (FALSE); 661316303Sjkim 662316303Sjkim 663316303SjkimBufferOverflow: 664316303Sjkim 665316303Sjkim /* Comment was too long */ 666316303Sjkim 667316303Sjkim AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH, 668316303Sjkim Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 669316303Sjkim Gbl_CurrentLineOffset, Gbl_CurrentColumn, 670316303Sjkim Gbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096"); 671316303Sjkim return (FALSE); 672316303Sjkim 673234518Sjkim} 674234518Sjkim 675234518Sjkim 676234518Sjkim/******************************************************************************* 677234518Sjkim * 678234518Sjkim * FUNCTION: AslDoCommentType2 679234518Sjkim * 680234518Sjkim * PARAMETERS: none 681234518Sjkim * 682234518Sjkim * RETURN: none 683234518Sjkim * 684316303Sjkim * DESCRIPTION: Process a new "//" comment. Inline comments will be converted 685316303Sjkim * to "/ *" standard comments. 686234518Sjkim * 687234518Sjkim ******************************************************************************/ 688234518Sjkim 689316303Sjkimstatic BOOLEAN 690234518SjkimAslDoCommentType2 ( 691234518Sjkim void) 692234518Sjkim{ 693316303Sjkim int c; 694316303Sjkim char *StringBuffer = MsgBuffer; 695316303Sjkim char *EndBuffer = MsgBuffer + ASL_MSG_BUFFER_SIZE; 696316303Sjkim ASL_COMMENT_STATE CurrentState = Gbl_CommentState; 697234518Sjkim 698234518Sjkim 699234518Sjkim AslInsertLineBuffer ('/'); 700234518Sjkim 701327557Sjkim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments) 702316303Sjkim { 703322877Sjkim AslInsertLineBuffer ('*'); 704316303Sjkim *StringBuffer = '/'; 705316303Sjkim ++StringBuffer; 706316303Sjkim *StringBuffer = '*'; 707316303Sjkim ++StringBuffer; 708316303Sjkim } 709322877Sjkim else 710322877Sjkim { 711322877Sjkim AslInsertLineBuffer ('/'); 712322877Sjkim } 713316303Sjkim 714278970Sjkim while (((c = input ()) != '\n') && (c != EOF)) 715234518Sjkim { 716234518Sjkim AslInsertLineBuffer (c); 717327557Sjkim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments) 718316303Sjkim { 719316303Sjkim *StringBuffer = c; 720316303Sjkim ++StringBuffer; 721316303Sjkim } 722234518Sjkim } 723234518Sjkim 724234518Sjkim if (c == EOF) 725234518Sjkim { 726234518Sjkim /* End of file is OK, change to newline. Let parser detect EOF later */ 727234518Sjkim 728234518Sjkim c = '\n'; 729234518Sjkim } 730234518Sjkim 731316303Sjkim if (StringBuffer > EndBuffer) 732316303Sjkim { 733316303Sjkim goto BufferOverflow; 734316303Sjkim } 735234518Sjkim AslInsertLineBuffer (c); 736316303Sjkim 737316303Sjkim CvProcessCommentType2 (CurrentState, StringBuffer); 738234518Sjkim return (TRUE); 739316303Sjkim 740316303Sjkim 741316303SjkimBufferOverflow: 742316303Sjkim 743316303Sjkim /* Comment was too long */ 744316303Sjkim 745316303Sjkim AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH, 746316303Sjkim Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 747316303Sjkim Gbl_CurrentLineOffset, Gbl_CurrentColumn, 748316303Sjkim Gbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096"); 749316303Sjkim return (FALSE); 750316303Sjkim 751234518Sjkim} 752234518Sjkim 753234518Sjkim 754234518Sjkim/******************************************************************************* 755234518Sjkim * 756234518Sjkim * FUNCTION: AslDoStringLiteral 757234518Sjkim * 758234518Sjkim * PARAMETERS: none 759234518Sjkim * 760234518Sjkim * RETURN: none 761234518Sjkim * 762234518Sjkim * DESCRIPTION: Process a string literal (surrounded by quotes) 763234518Sjkim * 764234518Sjkim ******************************************************************************/ 765234518Sjkim 766234518Sjkimstatic char 767234518SjkimAslDoStringLiteral ( 768234518Sjkim void) 769234518Sjkim{ 770234518Sjkim char *StringBuffer = MsgBuffer; 771234518Sjkim char *EndBuffer = MsgBuffer + ASL_MSG_BUFFER_SIZE; 772234518Sjkim char *CleanString; 773237412Sjkim int StringChar; 774234518Sjkim UINT32 State = ASL_NORMAL_CHAR; 775234518Sjkim UINT32 i = 0; 776234518Sjkim UINT8 Digit; 777234518Sjkim char ConvertBuffer[4]; 778234518Sjkim 779234518Sjkim 780234518Sjkim /* 781234518Sjkim * Eat chars until end-of-literal. 782234518Sjkim * NOTE: Put back the original surrounding quotes into the 783234518Sjkim * source line buffer. 784234518Sjkim */ 785234518Sjkim AslInsertLineBuffer ('\"'); 786237412Sjkim while ((StringChar = input()) != EOF) 787234518Sjkim { 788234518Sjkim AslInsertLineBuffer (StringChar); 789234518Sjkim 790234518SjkimDoCharacter: 791234518Sjkim switch (State) 792234518Sjkim { 793234518Sjkim case ASL_NORMAL_CHAR: 794234518Sjkim 795234518Sjkim switch (StringChar) 796234518Sjkim { 797234518Sjkim case '\\': 798234518Sjkim /* 799241973Sjkim * Special handling for backslash-escape sequence. We will 800234518Sjkim * toss the backslash and translate the escape char(s). 801234518Sjkim */ 802234518Sjkim State = ASL_ESCAPE_SEQUENCE; 803234518Sjkim continue; 804234518Sjkim 805234518Sjkim case '\"': 806234518Sjkim 807234518Sjkim /* String terminator */ 808234518Sjkim 809234518Sjkim goto CompletedString; 810246849Sjkim 811246849Sjkim default: 812250838Sjkim 813246849Sjkim break; 814234518Sjkim } 815234518Sjkim break; 816234518Sjkim 817234518Sjkim 818234518Sjkim case ASL_ESCAPE_SEQUENCE: 819234518Sjkim 820234518Sjkim State = ASL_NORMAL_CHAR; 821234518Sjkim switch (StringChar) 822234518Sjkim { 823234518Sjkim case 'a': 824250838Sjkim 825234518Sjkim StringChar = 0x07; /* BELL */ 826234518Sjkim break; 827234518Sjkim 828234518Sjkim case 'b': 829250838Sjkim 830234518Sjkim StringChar = 0x08; /* BACKSPACE */ 831234518Sjkim break; 832234518Sjkim 833234518Sjkim case 'f': 834250838Sjkim 835234518Sjkim StringChar = 0x0C; /* FORMFEED */ 836234518Sjkim break; 837234518Sjkim 838234518Sjkim case 'n': 839250838Sjkim 840234518Sjkim StringChar = 0x0A; /* LINEFEED */ 841234518Sjkim break; 842234518Sjkim 843234518Sjkim case 'r': 844250838Sjkim 845234518Sjkim StringChar = 0x0D; /* CARRIAGE RETURN*/ 846234518Sjkim break; 847234518Sjkim 848234518Sjkim case 't': 849250838Sjkim 850234518Sjkim StringChar = 0x09; /* HORIZONTAL TAB */ 851234518Sjkim break; 852234518Sjkim 853234518Sjkim case 'v': 854250838Sjkim 855234518Sjkim StringChar = 0x0B; /* VERTICAL TAB */ 856234518Sjkim break; 857234518Sjkim 858234518Sjkim case 'x': 859250838Sjkim 860234518Sjkim State = ASL_HEX_CONSTANT; 861234518Sjkim i = 0; 862234518Sjkim continue; 863234518Sjkim 864234518Sjkim case '\'': /* Single Quote */ 865234518Sjkim case '\"': /* Double Quote */ 866234518Sjkim case '\\': /* Backslash */ 867250838Sjkim 868234518Sjkim break; 869234518Sjkim 870234518Sjkim default: 871234518Sjkim 872234518Sjkim /* Check for an octal digit (0-7) */ 873234518Sjkim 874234518Sjkim if (ACPI_IS_OCTAL_DIGIT (StringChar)) 875234518Sjkim { 876234518Sjkim State = ASL_OCTAL_CONSTANT; 877234518Sjkim ConvertBuffer[0] = StringChar; 878234518Sjkim i = 1; 879234518Sjkim continue; 880234518Sjkim } 881234518Sjkim 882234518Sjkim /* Unknown escape sequence issue warning, but use the character */ 883234518Sjkim 884234518Sjkim AslCommonError (ASL_WARNING, ASL_MSG_INVALID_ESCAPE, 885278970Sjkim Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 886278970Sjkim Gbl_CurrentLineOffset, Gbl_CurrentColumn, 887278970Sjkim Gbl_Files[ASL_FILE_INPUT].Filename, NULL); 888234518Sjkim break; 889234518Sjkim } 890234518Sjkim break; 891234518Sjkim 892234518Sjkim 893234518Sjkim case ASL_OCTAL_CONSTANT: 894234518Sjkim 895234518Sjkim /* Up to three octal digits allowed */ 896234518Sjkim 897234518Sjkim if (!ACPI_IS_OCTAL_DIGIT (StringChar) || 898234518Sjkim (i > 2)) 899234518Sjkim { 900234518Sjkim /* 901241973Sjkim * Reached end of the constant. Convert the assembled ASCII 902234518Sjkim * string and resume processing of the next character 903234518Sjkim */ 904234518Sjkim ConvertBuffer[i] = 0; 905284583Sjkim Digit = (UINT8) strtoul (ConvertBuffer, NULL, 8); 906234518Sjkim 907234518Sjkim /* Check for NULL or non-ascii character (ignore if so) */ 908234518Sjkim 909234518Sjkim if ((Digit == 0) || (Digit > ACPI_ASCII_MAX)) 910234518Sjkim { 911234518Sjkim AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING, 912278970Sjkim Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 913278970Sjkim Gbl_CurrentLineOffset, Gbl_CurrentColumn, 914278970Sjkim Gbl_Files[ASL_FILE_INPUT].Filename, NULL); 915234518Sjkim } 916234518Sjkim else 917234518Sjkim { 918234518Sjkim *StringBuffer = (char) Digit; 919234518Sjkim StringBuffer++; 920234518Sjkim if (StringBuffer >= EndBuffer) 921234518Sjkim { 922234518Sjkim goto BufferOverflow; 923234518Sjkim } 924234518Sjkim } 925234518Sjkim 926234518Sjkim State = ASL_NORMAL_CHAR; 927234518Sjkim goto DoCharacter; 928234518Sjkim break; 929234518Sjkim } 930234518Sjkim 931234518Sjkim /* Append another digit of the constant */ 932234518Sjkim 933234518Sjkim ConvertBuffer[i] = StringChar; 934234518Sjkim i++; 935234518Sjkim continue; 936234518Sjkim 937234518Sjkim case ASL_HEX_CONSTANT: 938234518Sjkim 939234518Sjkim /* Up to two hex digits allowed */ 940234518Sjkim 941284583Sjkim if (!isxdigit (StringChar) || 942234518Sjkim (i > 1)) 943234518Sjkim { 944234518Sjkim /* 945241973Sjkim * Reached end of the constant. Convert the assembled ASCII 946234518Sjkim * string and resume processing of the next character 947234518Sjkim */ 948234518Sjkim ConvertBuffer[i] = 0; 949284583Sjkim Digit = (UINT8) strtoul (ConvertBuffer, NULL, 16); 950234518Sjkim 951234518Sjkim /* Check for NULL or non-ascii character (ignore if so) */ 952234518Sjkim 953234518Sjkim if ((Digit == 0) || (Digit > ACPI_ASCII_MAX)) 954234518Sjkim { 955234518Sjkim AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING, 956278970Sjkim Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 957278970Sjkim Gbl_CurrentLineOffset, Gbl_CurrentColumn, 958278970Sjkim Gbl_Files[ASL_FILE_INPUT].Filename, NULL); 959234518Sjkim } 960234518Sjkim else 961234518Sjkim { 962234518Sjkim *StringBuffer = (char) Digit; 963234518Sjkim StringBuffer++; 964234518Sjkim if (StringBuffer >= EndBuffer) 965234518Sjkim { 966234518Sjkim goto BufferOverflow; 967234518Sjkim } 968234518Sjkim } 969234518Sjkim 970234518Sjkim State = ASL_NORMAL_CHAR; 971234518Sjkim goto DoCharacter; 972234518Sjkim break; 973234518Sjkim } 974234518Sjkim 975234518Sjkim /* Append another digit of the constant */ 976234518Sjkim 977234518Sjkim ConvertBuffer[i] = StringChar; 978234518Sjkim i++; 979234518Sjkim continue; 980246849Sjkim 981246849Sjkim default: 982250838Sjkim 983246849Sjkim break; 984234518Sjkim } 985234518Sjkim 986234518Sjkim /* Save the finished character */ 987234518Sjkim 988234518Sjkim *StringBuffer = StringChar; 989234518Sjkim StringBuffer++; 990234518Sjkim if (StringBuffer >= EndBuffer) 991234518Sjkim { 992234518Sjkim goto BufferOverflow; 993234518Sjkim } 994234518Sjkim } 995234518Sjkim 996234518Sjkim /* 997234518Sjkim * Premature End-Of-File 998234518Sjkim */ 999234518Sjkim AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF, 1000278970Sjkim Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 1001278970Sjkim Gbl_CurrentLineOffset, Gbl_CurrentColumn, 1002278970Sjkim Gbl_Files[ASL_FILE_INPUT].Filename, NULL); 1003234518Sjkim return (FALSE); 1004234518Sjkim 1005234518Sjkim 1006234518SjkimCompletedString: 1007234518Sjkim /* 1008234518Sjkim * Null terminate the input string and copy string to a new buffer 1009234518Sjkim */ 1010234518Sjkim *StringBuffer = 0; 1011234518Sjkim 1012327557Sjkim CleanString = UtLocalCacheCalloc (strlen (MsgBuffer) + 1); 1013284583Sjkim strcpy (CleanString, MsgBuffer); 1014234518Sjkim AslCompilerlval.s = CleanString; 1015234518Sjkim return (TRUE); 1016234518Sjkim 1017234518Sjkim 1018234518SjkimBufferOverflow: 1019234518Sjkim 1020234518Sjkim /* Literal was too long */ 1021234518Sjkim 1022234518Sjkim AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH, 1023278970Sjkim Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 1024278970Sjkim Gbl_CurrentLineOffset, Gbl_CurrentColumn, 1025278970Sjkim Gbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096"); 1026234518Sjkim return (FALSE); 1027234518Sjkim} 1028