Home | History | Annotate | Line # | Download | only in compiler
cvcompiler.c revision 1.1.1.5
      1 /******************************************************************************
      2  *
      3  * Module Name: cvcompiler - ASL-/ASL+ converter functions
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2018, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 #include "aslcompiler.h"
     45 #include "aslcompiler.y.h"
     46 #include "amlcode.h"
     47 #include "acapps.h"
     48 #include "acconvert.h"
     49 
     50 
     51 /*******************************************************************************
     52  *
     53  * FUNCTION:    CvProcessComment
     54  *
     55  * PARAMETERS:  CurrentState      Current comment parse state
     56  *              StringBuffer      Buffer containing the comment being processed
     57  *              c1                Current input
     58  *
     59  * RETURN:      None
     60  *
     61  * DESCRIPTION: Process a single line comment of a c Style comment. This
     62  *              function captures a line of a c style comment in a char* and
     63  *              places the comment in the approperiate global buffer.
     64  *
     65  ******************************************************************************/
     66 
     67 void
     68 CvProcessComment (
     69     ASL_COMMENT_STATE       CurrentState,
     70     char                    *StringBuffer,
     71     int                     c1)
     72 {
     73     UINT64                  i;
     74     char                    *LineToken;
     75     char                    *FinalLineToken;
     76     BOOLEAN                 CharStart;
     77     char                    *CommentString;
     78     char                    *FinalCommentString;
     79 
     80 
     81     if (AcpiGbl_CaptureComments && CurrentState.CaptureComments)
     82     {
     83         *StringBuffer = (char) c1;
     84         ++StringBuffer;
     85         *StringBuffer = 0;
     86 
     87         CvDbgPrint ("Multi-line comment\n");
     88         CommentString = UtLocalCacheCalloc (strlen (AslGbl_MsgBuffer) + 1);
     89         strcpy (CommentString, AslGbl_MsgBuffer);
     90 
     91         CvDbgPrint ("CommentString: %s\n", CommentString);
     92 
     93         /*
     94          * Determine whether if this comment spans multiple lines. If so,
     95          * break apart the comment by storing each line in a different node
     96          * within the comment list. This allows the disassembler to
     97          * properly indent a multi-line comment.
     98          */
     99         LineToken = strtok (CommentString, "\n");
    100 
    101         if (LineToken)
    102         {
    103             FinalLineToken = UtLocalCacheCalloc (strlen (LineToken) + 1);
    104             strcpy (FinalLineToken, LineToken);
    105 
    106             /* Get rid of any carriage returns */
    107 
    108             if (FinalLineToken[strlen (FinalLineToken) - 1] == 0x0D)
    109             {
    110                 FinalLineToken[strlen(FinalLineToken)-1] = 0;
    111             }
    112 
    113             CvAddToCommentList (FinalLineToken);
    114             LineToken = strtok (NULL, "\n");
    115             while (LineToken != NULL)
    116             {
    117                 /*
    118                  * It is assumed that each line has some sort of indentation.
    119                  * This means that we need to find the first character that
    120                  * is not a white space within each line.
    121                  */
    122                 CharStart = FALSE;
    123                 for (i = 0; (i < (strlen (LineToken) + 1)) && !CharStart; i++)
    124                 {
    125                     if (LineToken[i] != ' ' && LineToken[i] != '\t')
    126                     {
    127                         CharStart = TRUE;
    128                         LineToken += i-1;
    129                         LineToken [0] = ' '; /* Pad for Formatting */
    130                     }
    131                 }
    132 
    133                 FinalLineToken = UtLocalCacheCalloc (strlen (LineToken) + 1);
    134                 strcat (FinalLineToken, LineToken);
    135 
    136                 /* Get rid of any carriage returns */
    137 
    138                 if (FinalLineToken[strlen (FinalLineToken) - 1] == 0x0D)
    139                 {
    140                     FinalLineToken[strlen(FinalLineToken) - 1] = 0;
    141                 }
    142 
    143                 CvAddToCommentList (FinalLineToken);
    144                 LineToken = strtok (NULL,"\n");
    145             }
    146         }
    147 
    148         /*
    149          * If this only spans a single line, check to see whether if this
    150          * comment appears on the same line as a line of code. If does,
    151          * retain it's position for stylistic reasons. If it doesn't,
    152          * add it to the comment list so that it can be associated with
    153          * the next node that's created.
    154          */
    155         else
    156         {
    157            /*
    158             * If this is not a regular comment, pad with extra spaces that
    159             * appeared in the original source input to retain the original
    160             * spacing.
    161             */
    162             FinalCommentString =
    163                 UtLocalCacheCalloc (strlen (CommentString) +
    164                 CurrentState.SpacesBefore + 1);
    165 
    166             for (i = 0; (CurrentState.CommentType != ASL_COMMENT_STANDARD) &&
    167                 (i < CurrentState.SpacesBefore); i++)
    168             {
    169                  FinalCommentString[i] = ' ';
    170             }
    171 
    172             strcat (FinalCommentString, CommentString);
    173             CvPlaceComment (CurrentState.CommentType, FinalCommentString);
    174         }
    175     }
    176 }
    177 
    178 
    179 /*******************************************************************************
    180  *
    181  * FUNCTION:    CvProcessCommentType2
    182  *
    183  * PARAMETERS:  CurrentState      Current comment parse state
    184  *              StringBuffer      Buffer containing the comment being processed
    185  *
    186  * RETURN:      none
    187  *
    188  * DESCRIPTION: Process a single line comment. This function captures a comment
    189  *              in a char* and places the comment in the approperiate global
    190  *              buffer through CvPlaceComment
    191  *
    192  ******************************************************************************/
    193 
    194 void
    195 CvProcessCommentType2 (
    196     ASL_COMMENT_STATE       CurrentState,
    197     char                    *StringBuffer)
    198 {
    199     UINT32                  i;
    200     char                    *CommentString;
    201     char                    *FinalCommentString;
    202 
    203 
    204     if (AcpiGbl_CaptureComments && CurrentState.CaptureComments)
    205     {
    206         *StringBuffer = 0; /* null terminate */
    207         CvDbgPrint ("Single-line comment\n");
    208         CommentString = UtLocalCacheCalloc (strlen (AslGbl_MsgBuffer) + 1);
    209         strcpy (CommentString, AslGbl_MsgBuffer);
    210 
    211         /* If this comment lies on the same line as the latest parse op,
    212          * assign it to that op's CommentAfter field. Saving in this field
    213          * will allow us to support comments that come after code on the
    214          * same line as the code itself. For example,
    215          * Name(A,"") //comment
    216          *
    217          * will be retained rather than transformed into
    218          *
    219          * Name(A,"")
    220          * //comment
    221          *
    222          * For this case, we only need to add one comment since
    223          *
    224          * Name(A,"") //comment1 //comment2 ... more comments here.
    225          *
    226          * would be lexically analyzed as a single comment.
    227          *
    228          * Create a new string with the approperiate spaces. Since we need
    229          * to account for the proper spacing, the actual comment,
    230          * extra 2 spaces so that this comment can be converted to the "/ *"
    231          * style and the null terminator, the string would look something
    232          * like:
    233          *
    234          * [ (spaces) (comment)  ( * /) ('\0') ]
    235          *
    236          */
    237         FinalCommentString = UtLocalCacheCalloc (CurrentState.SpacesBefore +
    238             strlen (CommentString) + 3 + 1);
    239 
    240         for (i = 0; (CurrentState.CommentType != 1) &&
    241             (i < CurrentState.SpacesBefore); i++)
    242         {
    243             FinalCommentString[i] = ' ';
    244         }
    245 
    246         strcat (FinalCommentString, CommentString);
    247 
    248         /* convert to a "/ *" style comment  */
    249 
    250         strcat (FinalCommentString, " */");
    251         FinalCommentString [CurrentState.SpacesBefore +
    252             strlen (CommentString) + 3] = 0;
    253 
    254         /* get rid of the carriage return */
    255 
    256         if (FinalCommentString[strlen (FinalCommentString) - 1] == 0x0D)
    257         {
    258             FinalCommentString[strlen(FinalCommentString) - 1] = 0;
    259         }
    260 
    261         CvPlaceComment (CurrentState.CommentType, FinalCommentString);
    262     }
    263 }
    264 
    265 
    266 /*******************************************************************************
    267  *
    268  * FUNCTION:    CgCalculateCommentLengths
    269  *
    270  * PARAMETERS:  Op                 - Calculate all comments of this Op
    271  *
    272  * RETURN:      TotalCommentLength - Length of all comments within this op.
    273  *
    274  * DESCRIPTION: Calculate the length that the each comment takes up within Op.
    275  *              Comments look like the follwoing: [0xA9 OptionBtye comment 0x00]
    276  *              therefore, we add 1 + 1 + strlen (comment) + 1 to get the actual
    277  *              length of this comment.
    278  *
    279  ******************************************************************************/
    280 
    281 UINT32
    282 CvCalculateCommentLengths(
    283    ACPI_PARSE_OBJECT        *Op)
    284 {
    285     UINT32                  CommentLength = 0;
    286     UINT32                  TotalCommentLength = 0;
    287     ACPI_COMMENT_NODE       *Current = NULL;
    288 
    289 
    290     if (!AcpiGbl_CaptureComments)
    291     {
    292         return (0);
    293     }
    294 
    295     CvDbgPrint ("==Calculating comment lengths for %s\n",
    296         Op->Asl.ParseOpName);
    297 
    298     if (Op->Asl.FileChanged)
    299     {
    300         TotalCommentLength += strlen (Op->Asl.Filename) + 3;
    301 
    302         if (Op->Asl.ParentFilename &&
    303             AcpiUtStricmp (Op->Asl.Filename, Op->Asl.ParentFilename))
    304         {
    305             TotalCommentLength += strlen (Op->Asl.ParentFilename) + 3;
    306         }
    307     }
    308 
    309     if (Op->Asl.CommentList)
    310     {
    311         Current = Op->Asl.CommentList;
    312         while (Current)
    313         {
    314             CommentLength = strlen (Current->Comment)+3;
    315             CvDbgPrint ("Length of standard comment: %d\n", CommentLength);
    316             CvDbgPrint ("    Comment string: %s\n\n", Current->Comment);
    317             TotalCommentLength += CommentLength;
    318             Current = Current->Next;
    319         }
    320     }
    321 
    322     if (Op->Asl.EndBlkComment)
    323     {
    324         Current = Op->Asl.EndBlkComment;
    325         while (Current)
    326         {
    327             CommentLength = strlen (Current->Comment)+3;
    328             CvDbgPrint ("Length of endblkcomment: %d\n", CommentLength);
    329             CvDbgPrint ("    Comment string: %s\n\n", Current->Comment);
    330             TotalCommentLength += CommentLength;
    331             Current = Current->Next;
    332         }
    333     }
    334 
    335     if (Op->Asl.InlineComment)
    336     {
    337         CommentLength = strlen (Op->Asl.InlineComment)+3;
    338         CvDbgPrint ("Length of inline comment: %d\n", CommentLength);
    339         CvDbgPrint ("    Comment string: %s\n\n", Op->Asl.InlineComment);
    340         TotalCommentLength += CommentLength;
    341     }
    342 
    343     if (Op->Asl.EndNodeComment)
    344     {
    345         CommentLength = strlen(Op->Asl.EndNodeComment)+3;
    346         CvDbgPrint ("Length of end node comment +3: %d\n", CommentLength);
    347         CvDbgPrint ("    Comment string: %s\n\n", Op->Asl.EndNodeComment);
    348         TotalCommentLength += CommentLength;
    349     }
    350 
    351     if (Op->Asl.CloseBraceComment)
    352     {
    353         CommentLength = strlen (Op->Asl.CloseBraceComment)+3;
    354         CvDbgPrint ("Length of close brace comment: %d\n", CommentLength);
    355         CvDbgPrint ("    Comment string: %s\n\n", Op->Asl.CloseBraceComment);
    356         TotalCommentLength += CommentLength;
    357     }
    358 
    359     CvDbgPrint("\n\n");
    360     return (TotalCommentLength);
    361 }
    362 
    363 
    364 /*******************************************************************************
    365  *
    366  * FUNCTION:    CgWriteAmlDefBlockComment
    367  *
    368  * PARAMETERS:  Op              - Current parse op
    369  *
    370  * RETURN:      None
    371  *
    372  * DESCRIPTION: Write all comments for a particular definition block.
    373  *              For definition blocks, the comments need to come after the
    374  *              definition block header. The regular comments above the
    375  *              definition block would be categorized as
    376  *              STD_DEFBLK_COMMENT and comments after the closing brace
    377  *              is categorized as END_DEFBLK_COMMENT.
    378  *
    379  ******************************************************************************/
    380 
    381 void
    382 CgWriteAmlDefBlockComment(
    383     ACPI_PARSE_OBJECT       *Op)
    384 {
    385     UINT8                   CommentOption;
    386     ACPI_COMMENT_NODE       *Current;
    387     char                    *NewFilename;
    388     char                    *Position;
    389     char                    *DirectoryPosition;
    390 
    391 
    392     if (!AcpiGbl_CaptureComments ||
    393         (Op->Asl.ParseOpcode != PARSEOP_DEFINITION_BLOCK))
    394     {
    395         return;
    396     }
    397 
    398     CvDbgPrint ("Printing comments for a definition block..\n");
    399 
    400     /* First, print the file name comment after changing .asl to .dsl */
    401 
    402     NewFilename = UtLocalCacheCalloc (strlen (Op->Asl.Filename));
    403     strcpy (NewFilename, Op->Asl.Filename);
    404     DirectoryPosition = strrchr (NewFilename, '/');
    405     Position = strrchr (NewFilename, '.');
    406 
    407     if (Position && (Position > DirectoryPosition))
    408     {
    409         /* Tack on the new suffix */
    410 
    411         Position++;
    412         *Position = 0;
    413         strcat (Position, FILE_SUFFIX_DISASSEMBLY);
    414     }
    415     else
    416     {
    417         /* No dot, add one and then the suffix */
    418 
    419         strcat (NewFilename, ".");
    420         strcat (NewFilename, FILE_SUFFIX_DISASSEMBLY);
    421     }
    422 
    423     CommentOption = FILENAME_COMMENT;
    424     CgWriteOneAmlComment(Op, NewFilename, CommentOption);
    425 
    426     Current = Op->Asl.CommentList;
    427     CommentOption = STD_DEFBLK_COMMENT;
    428 
    429     while (Current)
    430     {
    431         CgWriteOneAmlComment(Op, Current->Comment, CommentOption);
    432         CvDbgPrint ("Printing comment: %s\n", Current->Comment);
    433         Current = Current->Next;
    434     }
    435 
    436     Op->Asl.CommentList = NULL;
    437 
    438     /* Print any Inline comments associated with this node */
    439 
    440     if (Op->Asl.CloseBraceComment)
    441     {
    442         CommentOption = END_DEFBLK_COMMENT;
    443         CgWriteOneAmlComment(Op, Op->Asl.CloseBraceComment, CommentOption);
    444         Op->Asl.CloseBraceComment = NULL;
    445     }
    446 }
    447 
    448 
    449 /*******************************************************************************
    450  *
    451  * FUNCTION:    CgWriteOneAmlComment
    452  *
    453  * PARAMETERS:  Op              - Current parse op
    454  *              CommentToPrint  - Comment that's printed
    455  *              InputOption     - Denotes the comment option.
    456  *
    457  * RETURN:      None
    458  *
    459  * DESCRIPTION: write a single comment.
    460  *
    461  ******************************************************************************/
    462 
    463 void
    464 CgWriteOneAmlComment(
    465     ACPI_PARSE_OBJECT       *Op,
    466     char*                   CommentToPrint,
    467     UINT8                   InputOption)
    468 {
    469     UINT8                   CommentOption = InputOption;
    470     UINT8                   CommentOpcode = (UINT8) AML_COMMENT_OP;
    471 
    472 
    473     if (!CommentToPrint)
    474     {
    475         return;
    476     }
    477 
    478     CgLocalWriteAmlData (Op, &CommentOpcode, 1);
    479     CgLocalWriteAmlData (Op, &CommentOption, 1);
    480 
    481     /* The strlen (..) + 1 is to include the null terminator */
    482 
    483     CgLocalWriteAmlData (Op, CommentToPrint, strlen (CommentToPrint) + 1);
    484 }
    485 
    486 
    487 /*******************************************************************************
    488  *
    489  * FUNCTION:    CgWriteAmlComment
    490  *
    491  * PARAMETERS:  Op              - Current parse op
    492  *
    493  * RETURN:      None
    494  *
    495  * DESCRIPTION: Write all comments pertaining to the current parse op
    496  *
    497  ******************************************************************************/
    498 
    499 void
    500 CgWriteAmlComment(
    501     ACPI_PARSE_OBJECT       *Op)
    502 {
    503     ACPI_COMMENT_NODE       *Current;
    504     UINT8                   CommentOption;
    505     char                    *NewFilename;
    506     char                    *ParentFilename;
    507 
    508 
    509     if ((Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK) ||
    510          !AcpiGbl_CaptureComments)
    511     {
    512         return;
    513     }
    514 
    515     /* Print out the filename comment if needed */
    516 
    517     if (Op->Asl.FileChanged)
    518     {
    519 
    520         /* First, print the file name comment after changing .asl to .dsl */
    521 
    522         NewFilename =
    523             FlGenerateFilename (Op->Asl.Filename, FILE_SUFFIX_DISASSEMBLY);
    524         if (NewFilename)
    525         {
    526             CvDbgPrint ("Writing file comment, \"%s\" for %s\n",
    527                 NewFilename, Op->Asl.ParseOpName);
    528         }
    529 
    530         CgWriteOneAmlComment(Op, NewFilename, FILENAME_COMMENT);
    531 
    532         if (Op->Asl.ParentFilename &&
    533             AcpiUtStricmp (Op->Asl.ParentFilename, Op->Asl.Filename))
    534         {
    535             ParentFilename = FlGenerateFilename (Op->Asl.ParentFilename,
    536                 FILE_SUFFIX_DISASSEMBLY);
    537             CgWriteOneAmlComment(Op, ParentFilename, PARENTFILENAME_COMMENT);
    538         }
    539 
    540         /* Prevent multiple writes of the same comment */
    541 
    542         Op->Asl.FileChanged = FALSE;
    543     }
    544 
    545     /*
    546      * Regular comments are stored in a list of comments within an Op.
    547      * If there is a such list in this node, print out the comment
    548      * as byte code.
    549      */
    550     Current = Op->Asl.CommentList;
    551     if (Op->Asl.ParseOpcode == PARSEOP_INCLUDE)
    552     {
    553         CommentOption = INCLUDE_COMMENT;
    554     }
    555     else
    556     {
    557         CommentOption = STANDARD_COMMENT;
    558     }
    559 
    560     while (Current)
    561     {
    562         CgWriteOneAmlComment(Op, Current->Comment, CommentOption);
    563         Current = Current->Next;
    564     }
    565 
    566     Op->Asl.CommentList = NULL;
    567 
    568     Current = Op->Asl.EndBlkComment;
    569     CommentOption = ENDBLK_COMMENT;
    570     while (Current)
    571     {
    572         CgWriteOneAmlComment(Op, Current->Comment, CommentOption);
    573         Current = Current->Next;
    574     }
    575 
    576     Op->Asl.EndBlkComment = NULL;
    577 
    578     /* Print any Inline comments associated with this node */
    579 
    580     if (Op->Asl.InlineComment)
    581     {
    582         CommentOption = INLINE_COMMENT;
    583         CgWriteOneAmlComment(Op, Op->Asl.InlineComment, CommentOption);
    584         Op->Asl.InlineComment = NULL;
    585     }
    586 
    587     if (Op->Asl.EndNodeComment)
    588     {
    589         CommentOption = ENDNODE_COMMENT;
    590         CgWriteOneAmlComment(Op, Op->Asl.EndNodeComment, CommentOption);
    591         Op->Asl.EndNodeComment = NULL;
    592     }
    593 
    594     if (Op->Asl.CloseBraceComment)
    595     {
    596         CommentOption = CLOSE_BRACE_COMMENT;
    597         CgWriteOneAmlComment(Op, Op->Asl.CloseBraceComment, CommentOption);
    598         Op->Asl.CloseBraceComment = NULL;
    599     }
    600 }
    601 
    602 
    603 /*******************************************************************************
    604  *
    605  * FUNCTION:    CvCommentNodeCalloc
    606  *
    607  * PARAMETERS:  None
    608  *
    609  * RETURN:      Pointer to the comment node. Aborts on allocation failure
    610  *
    611  * DESCRIPTION: Allocate a string node buffer.
    612  *
    613  ******************************************************************************/
    614 
    615 ACPI_COMMENT_NODE *
    616 CvCommentNodeCalloc (
    617     void)
    618 {
    619    ACPI_COMMENT_NODE        *NewCommentNode;
    620 
    621 
    622    NewCommentNode = UtLocalCalloc (sizeof (ACPI_COMMENT_NODE));
    623    NewCommentNode->Next = NULL;
    624    return (NewCommentNode);
    625 }
    626 
    627 
    628 /*******************************************************************************
    629  *
    630  * FUNCTION:    CvParseOpBlockType
    631  *
    632  * PARAMETERS:  Op              - Object to be examined
    633  *
    634  * RETURN:      BlockType - not a block, parens, braces, or even both.
    635  *
    636  * DESCRIPTION: Type of block for this ASL parseop (parens or braces)
    637  *              keep this in sync with aslprimaries.y, aslresources.y and
    638  *              aslrules.y
    639  *
    640  ******************************************************************************/
    641 
    642 UINT32
    643 CvParseOpBlockType (
    644     ACPI_PARSE_OBJECT       *Op)
    645 {
    646 
    647     if (!Op)
    648     {
    649         return (BLOCK_NONE);
    650     }
    651 
    652     switch (Op->Asl.ParseOpcode)
    653     {
    654     /* From aslprimaries.y */
    655 
    656     case PARSEOP_VAR_PACKAGE:
    657     case PARSEOP_BANKFIELD:
    658     case PARSEOP_BUFFER:
    659     case PARSEOP_CASE:
    660     case PARSEOP_DEVICE:
    661     case PARSEOP_FIELD:
    662     case PARSEOP_FOR:
    663     case PARSEOP_FUNCTION:
    664     case PARSEOP_IF:
    665     case PARSEOP_ELSEIF:
    666     case PARSEOP_INDEXFIELD:
    667     case PARSEOP_METHOD:
    668     case PARSEOP_POWERRESOURCE:
    669     case PARSEOP_PROCESSOR:
    670     case PARSEOP_DATABUFFER:
    671     case PARSEOP_SCOPE:
    672     case PARSEOP_SWITCH:
    673     case PARSEOP_THERMALZONE:
    674     case PARSEOP_WHILE:
    675 
    676     /* From aslresources.y */
    677 
    678     case PARSEOP_RESOURCETEMPLATE: /* optional parens */
    679     case PARSEOP_VENDORLONG:
    680     case PARSEOP_VENDORSHORT:
    681     case PARSEOP_INTERRUPT:
    682     case PARSEOP_IRQNOFLAGS:
    683     case PARSEOP_IRQ:
    684     case PARSEOP_GPIO_INT:
    685     case PARSEOP_GPIO_IO:
    686     case PARSEOP_DMA:
    687 
    688     /* From aslrules.y */
    689 
    690     case PARSEOP_DEFINITION_BLOCK:
    691         return (BLOCK_PAREN | BLOCK_BRACE);
    692 
    693     default:
    694         return (BLOCK_NONE);
    695     }
    696 }
    697 
    698 
    699 /*******************************************************************************
    700  *
    701  * FUNCTION:    CvProcessCommentState
    702  *
    703  * PARAMETERS:  Input           - Input character
    704  *
    705  * RETURN:      None
    706  *
    707  * DESCRIPTION: Take the given input. If this character is
    708  *              defined as a comment table entry, then update the state
    709  *              accordingly.
    710  *
    711  ******************************************************************************/
    712 
    713 void
    714 CvProcessCommentState (
    715     char                    Input)
    716 {
    717 
    718     if (Input != ' ')
    719     {
    720         AslGbl_CommentState.SpacesBefore = 0;
    721     }
    722 
    723     switch (Input)
    724     {
    725     case '\n':
    726 
    727         AslGbl_CommentState.CommentType = ASL_COMMENT_STANDARD;
    728         break;
    729 
    730     case ' ':
    731 
    732         /* Keep the CommentType the same */
    733 
    734         AslGbl_CommentState.SpacesBefore++;
    735         break;
    736 
    737     case '(':
    738 
    739         AslGbl_CommentState.CommentType = ASL_COMMENT_OPEN_PAREN;
    740         break;
    741 
    742     case ')':
    743 
    744         AslGbl_CommentState.CommentType = ASL_COMMENT_CLOSE_PAREN;
    745         break;
    746 
    747     case '{':
    748 
    749         AslGbl_CommentState.CommentType = ASL_COMMENT_STANDARD;
    750         AslGbl_CommentState.ParsingParenBraceNode = NULL;
    751         CvDbgPrint ("End Parsing paren/Brace node!\n");
    752         break;
    753 
    754     case '}':
    755 
    756         AslGbl_CommentState.CommentType = ASL_COMMENT_CLOSE_BRACE;
    757         break;
    758 
    759     case ',':
    760 
    761         AslGbl_CommentState.CommentType = ASLCOMMENT_INLINE;
    762         break;
    763 
    764     default:
    765 
    766         AslGbl_CommentState.CommentType = ASLCOMMENT_INLINE;
    767         break;
    768     }
    769 }
    770 
    771 
    772 /*******************************************************************************
    773  *
    774  * FUNCTION:    CvAddToCommentList
    775  *
    776  * PARAMETERS:  ToAdd              - Contains the comment to be inserted
    777  *
    778  * RETURN:      None
    779  *
    780  * DESCRIPTION: Add the given char* to a list of comments in the global list
    781  *              of comments.
    782  *
    783  ******************************************************************************/
    784 
    785 void
    786 CvAddToCommentList (
    787     char                    *ToAdd)
    788 {
    789 
    790    if (AslGbl_CommentListHead)
    791    {
    792        AslGbl_CommentListTail->Next = CvCommentNodeCalloc ();
    793        AslGbl_CommentListTail = AslGbl_CommentListTail->Next;
    794    }
    795    else
    796    {
    797        AslGbl_CommentListHead = CvCommentNodeCalloc ();
    798        AslGbl_CommentListTail = AslGbl_CommentListHead;
    799    }
    800 
    801    AslGbl_CommentListTail->Comment = ToAdd;
    802 }
    803 
    804 
    805 /*******************************************************************************
    806  *
    807  * FUNCTION:    CvAppendInlineComment
    808  *
    809  * PARAMETERS:  InlineComment      - Append to the end of this string.
    810  *              toAdd              - Contains the comment to be inserted
    811  *
    812  * RETURN:      Str                - toAdd appended to InlineComment
    813  *
    814  * DESCRIPTION: Concatenate ToAdd to InlineComment
    815  *
    816  ******************************************************************************/
    817 
    818 char *
    819 CvAppendInlineComment (
    820     char                    *InlineComment,
    821     char                    *ToAdd)
    822 {
    823     char*                   Str;
    824     UINT32                  Size = 0;
    825 
    826 
    827     if (!InlineComment)
    828     {
    829         return (ToAdd);
    830     }
    831 
    832     if (!ToAdd)
    833     {
    834         return (InlineComment);
    835     }
    836 
    837     Size = strlen (ToAdd);
    838     Size += strlen (InlineComment);
    839     Str = UtLocalCacheCalloc (Size + 1);
    840 
    841     strcpy (Str, InlineComment);
    842     strcat (Str, ToAdd);
    843     Str[Size +1] = 0;
    844     return (Str);
    845 }
    846 
    847 
    848 /*******************************************************************************
    849  *
    850  * FUNCTION:    CvPlaceComment
    851  *
    852  * PARAMETERS:  UINT8               - Type
    853  *              char *              - CommentString
    854  *
    855  * RETURN:      None
    856  *
    857  * DESCRIPTION: Given type and CommentString, this function places the
    858  *              CommentString in the approperiate global comment list or char*
    859  *
    860  ******************************************************************************/
    861 
    862 void
    863 CvPlaceComment(
    864     UINT8                   Type,
    865     char                    *CommentString)
    866 {
    867     ACPI_PARSE_OBJECT       *LatestParseNode;
    868     ACPI_PARSE_OBJECT       *ParenBraceNode;
    869 
    870 
    871     LatestParseNode = AslGbl_CommentState.LatestParseOp;
    872     ParenBraceNode  = AslGbl_CommentState.ParsingParenBraceNode;
    873     CvDbgPrint ("Placing comment %s for type %d\n", CommentString, Type);
    874 
    875     switch (Type)
    876     {
    877     case ASL_COMMENT_STANDARD:
    878 
    879         CvAddToCommentList (CommentString);
    880         break;
    881 
    882     case ASLCOMMENT_INLINE:
    883 
    884         LatestParseNode->Asl.InlineComment =
    885             CvAppendInlineComment (LatestParseNode->Asl.InlineComment,
    886             CommentString);
    887         break;
    888 
    889     case ASL_COMMENT_OPEN_PAREN:
    890 
    891         AslGbl_InlineCommentBuffer =
    892             CvAppendInlineComment(AslGbl_InlineCommentBuffer,
    893             CommentString);
    894         break;
    895 
    896     case ASL_COMMENT_CLOSE_PAREN:
    897 
    898         if (ParenBraceNode)
    899         {
    900             ParenBraceNode->Asl.EndNodeComment =
    901                 CvAppendInlineComment (ParenBraceNode->Asl.EndNodeComment,
    902                 CommentString);
    903         }
    904         else
    905         {
    906             LatestParseNode->Asl.EndNodeComment =
    907                 CvAppendInlineComment (LatestParseNode->Asl.EndNodeComment,
    908                 CommentString);
    909         }
    910         break;
    911 
    912     case ASL_COMMENT_CLOSE_BRACE:
    913 
    914         LatestParseNode->Asl.CloseBraceComment = CommentString;
    915         break;
    916 
    917     default:
    918 
    919         break;
    920     }
    921 }
    922