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