## @file\r
# This file is used to define comment generating interface\r
#\r
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
#\r
-# This program and the accompanying materials are licensed and made available \r
-# under the terms and conditions of the BSD License which accompanies this \r
-# distribution. The full text of the license may be found at \r
+# This program and the accompanying materials are licensed and made available\r
+# under the terms and conditions of the BSD License which accompanies this\r
+# distribution. The full text of the license may be found at\r
# http://opensource.org/licenses/bsd-license.php\r
#\r
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
##\r
# Import Modules\r
#\r
-from Library.String import GetSplitValueList\r
+from Library.StringUtils import GetSplitValueList\r
from Library.DataType import TAB_SPACE_SPLIT\r
from Library.DataType import TAB_INF_GUIDTYPE_VAR\r
from Library.DataType import USAGE_ITEM_NOTIFY\r
from Library.DataType import ITEM_UNDEFINED\r
-from Library.DataType import LANGUAGE_EN_US\r
-\r
+from Library.DataType import TAB_HEADER_COMMENT\r
+from Library.DataType import TAB_BINARY_HEADER_COMMENT\r
+from Library.DataType import TAB_COMMENT_SPLIT\r
+from Library.DataType import TAB_SPECIAL_COMMENT\r
+from Library.DataType import END_OF_LINE\r
+from Library.DataType import TAB_COMMENT_EDK1_SPLIT\r
+from Library.DataType import TAB_COMMENT_EDK1_START\r
+from Library.DataType import TAB_COMMENT_EDK1_END\r
+from Library.DataType import TAB_STAR\r
+from Library.DataType import TAB_PCD_PROMPT\r
+from Library.UniClassObject import ConvertSpecialUnicodes\r
+from Library.Misc import GetLocalValue\r
## GenTailCommentLines\r
#\r
# @param TailCommentLines: the tail comment lines that need to be generated\r
-# @param LeadingSpaceNum: the number of leading space needed for non-first \r
+# @param LeadingSpaceNum: the number of leading space needed for non-first\r
# line tail comment\r
-# \r
+#\r
def GenTailCommentLines (TailCommentLines, LeadingSpaceNum = 0):\r
- EndOfLine = "\n"\r
- TailCommentLines = TailCommentLines.rstrip(EndOfLine)\r
- CommentStr = " ## " + (EndOfLine + LeadingSpaceNum * TAB_SPACE_SPLIT + \\r
- " ## ").join(GetSplitValueList(TailCommentLines, \\r
- EndOfLine))\r
+ TailCommentLines = TailCommentLines.rstrip(END_OF_LINE)\r
+ CommentStr = TAB_SPACE_SPLIT*2 + TAB_SPECIAL_COMMENT + TAB_SPACE_SPLIT + \\r
+ (END_OF_LINE + LeadingSpaceNum * TAB_SPACE_SPLIT + TAB_SPACE_SPLIT*2 + TAB_SPECIAL_COMMENT + \\r
+ TAB_SPACE_SPLIT).join(GetSplitValueList(TailCommentLines, END_OF_LINE))\r
+\r
return CommentStr\r
\r
## GenGenericComment\r
#\r
# @param CommentLines: Generic comment Text, maybe Multiple Lines\r
-# \r
+#\r
def GenGenericComment (CommentLines):\r
if not CommentLines:\r
return ''\r
- EndOfLine = "\n"\r
- CommentLines = CommentLines.rstrip(EndOfLine)\r
- CommentStr = '## ' + (EndOfLine + '# ').join\\r
- (GetSplitValueList(CommentLines, EndOfLine)) + EndOfLine\r
+ CommentLines = CommentLines.rstrip(END_OF_LINE)\r
+ CommentStr = TAB_SPECIAL_COMMENT + TAB_SPACE_SPLIT + (END_OF_LINE + TAB_COMMENT_SPLIT + TAB_SPACE_SPLIT).join\\r
+ (GetSplitValueList(CommentLines, END_OF_LINE)) + END_OF_LINE\r
return CommentStr\r
\r
## GenGenericCommentF\r
# and for line with only <EOL>, '#\n' will be generated instead of '# \n'\r
#\r
# @param CommentLines: Generic comment Text, maybe Multiple Lines\r
-# @return CommentStr: Generated comment line \r
-# \r
-def GenGenericCommentF (CommentLines, NumOfPound=1):\r
+# @return CommentStr: Generated comment line\r
+#\r
+def GenGenericCommentF (CommentLines, NumOfPound=1, IsPrompt=False, IsInfLibraryClass=False):\r
if not CommentLines:\r
return ''\r
- EndOfLine = "\n"\r
#\r
# if comment end with '\n', then remove it to prevent one extra line\r
# generate later on\r
#\r
- if CommentLines.endswith(EndOfLine):\r
+ if CommentLines.endswith(END_OF_LINE):\r
CommentLines = CommentLines[:-1]\r
- CommentLineList = GetSplitValueList(CommentLines, EndOfLine)\r
CommentStr = ''\r
- for Line in CommentLineList:\r
- if Line == '':\r
- CommentStr += '#' * NumOfPound + '\n'\r
- else:\r
- CommentStr += '#' * NumOfPound + ' ' + Line + '\n'\r
- \r
+ if IsPrompt:\r
+ CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT + TAB_PCD_PROMPT + TAB_SPACE_SPLIT + \\r
+ CommentLines.replace(END_OF_LINE, '') + END_OF_LINE\r
+ else:\r
+ CommentLineList = GetSplitValueList(CommentLines, END_OF_LINE)\r
+ FindLibraryClass = False\r
+ for Line in CommentLineList:\r
+ # If this comment is for @libraryclass and it has multiple lines\r
+ # make sure the second lines align to the first line after @libraryclass as below\r
+ #\r
+ # ## @libraryclass XYZ FIRST_LINE\r
+ # ## ABC SECOND_LINE\r
+ #\r
+ if IsInfLibraryClass and Line.find(u'@libraryclass ') > -1:\r
+ FindLibraryClass = True\r
+ if Line == '':\r
+ CommentStr += TAB_COMMENT_SPLIT * NumOfPound + END_OF_LINE\r
+ else:\r
+ if FindLibraryClass and Line.find(u'@libraryclass ') > -1:\r
+ CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT + Line + END_OF_LINE\r
+ elif FindLibraryClass:\r
+ CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT * 16 + Line + END_OF_LINE\r
+ else:\r
+ CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT + Line + END_OF_LINE\r
+\r
return CommentStr\r
\r
\r
#\r
# Generate Header comment sections\r
#\r
-# @param Abstract One line of abstract \r
+# @param Abstract One line of abstract\r
# @param Description multiple lines of Description\r
# @param Copyright possible multiple copyright lines\r
# @param License possible multiple license lines\r
#\r
-def GenHeaderCommentSection(Abstract, Description, Copyright, License):\r
- EndOfLine = '\n'\r
+def GenHeaderCommentSection(Abstract, Description, Copyright, License, IsBinaryHeader=False, \\r
+ CommChar=TAB_COMMENT_SPLIT):\r
Content = ''\r
- \r
- Content += '## @file' + EndOfLine\r
+\r
+ #\r
+ # Convert special character to (c), (r) and (tm).\r
+ #\r
+ Abstract = ConvertSpecialUnicodes(Abstract)\r
+ Description = ConvertSpecialUnicodes(Description)\r
+ if IsBinaryHeader:\r
+ Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_BINARY_HEADER_COMMENT + '\r\n'\r
+ elif CommChar == TAB_COMMENT_EDK1_SPLIT:\r
+ Content += CommChar + TAB_SPACE_SPLIT + TAB_COMMENT_EDK1_START + TAB_STAR + TAB_SPACE_SPLIT +\\r
+ TAB_HEADER_COMMENT + '\r\n'\r
+ else:\r
+ Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_HEADER_COMMENT + '\r\n'\r
if Abstract:\r
- Abstract = Abstract.rstrip(EndOfLine)\r
- Content += '# ' + Abstract + EndOfLine\r
- Content += '#' + EndOfLine\r
+ Abstract = Abstract.rstrip('\r\n')\r
+ Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\\r
+ (Abstract, '\n'))\r
+ Content += '\r\n' + CommChar + '\r\n'\r
else:\r
- Content += '#' + EndOfLine\r
+ Content += CommChar + '\r\n'\r
\r
if Description:\r
- Description = Description.rstrip(EndOfLine)\r
- Content += '# ' + (EndOfLine + '# ').join(GetSplitValueList\\r
+ Description = Description.rstrip('\r\n')\r
+ Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\\r
(Description, '\n'))\r
- Content += EndOfLine + '#' + EndOfLine \r
- \r
+ Content += '\r\n' + CommChar + '\r\n'\r
+\r
#\r
- # There is no '#\n' line to separate multiple copyright lines in code base \r
+ # There is no '#\n' line to separate multiple copyright lines in code base\r
#\r
if Copyright:\r
- Copyright = Copyright.rstrip(EndOfLine)\r
- Content += '# ' + (EndOfLine + '# ').join\\r
+ Copyright = Copyright.rstrip('\r\n')\r
+ Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join\\r
(GetSplitValueList(Copyright, '\n'))\r
- Content += EndOfLine + '#' + EndOfLine\r
+ Content += '\r\n' + CommChar + '\r\n'\r
\r
if License:\r
- License = License.rstrip(EndOfLine)\r
- Content += '# ' + (EndOfLine + '# ').join(GetSplitValueList\\r
+ License = License.rstrip('\r\n')\r
+ Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\\r
(License, '\n'))\r
- Content += EndOfLine + '#' + EndOfLine\r
+ Content += '\r\n' + CommChar + '\r\n'\r
+\r
+ if CommChar == TAB_COMMENT_EDK1_SPLIT:\r
+ Content += CommChar + TAB_SPACE_SPLIT + TAB_STAR + TAB_COMMENT_EDK1_END + '\r\n'\r
+ else:\r
+ Content += CommChar * 2 + '\r\n'\r
\r
- Content += '##' + EndOfLine\r
- \r
return Content\r
\r
\r
#\r
# @param Usage: Usage type\r
# @param TailCommentText: Comment text for tail comment\r
-# \r
+#\r
def GenInfPcdTailComment (Usage, TailCommentText):\r
if (Usage == ITEM_UNDEFINED) and (not TailCommentText):\r
return ''\r
- \r
+\r
CommentLine = TAB_SPACE_SPLIT.join([Usage, TailCommentText])\r
return GenTailCommentLines(CommentLine)\r
\r
#\r
# @param Usage: Usage type\r
# @param TailCommentText: Comment text for tail comment\r
-# \r
+#\r
def GenInfProtocolPPITailComment (Usage, Notify, TailCommentText):\r
if (not Notify) and (Usage == ITEM_UNDEFINED) and (not TailCommentText):\r
return ''\r
- \r
+\r
if Notify:\r
CommentLine = USAGE_ITEM_NOTIFY + " ## "\r
else:\r
CommentLine = ''\r
- \r
+\r
CommentLine += TAB_SPACE_SPLIT.join([Usage, TailCommentText])\r
return GenTailCommentLines(CommentLine)\r
\r
#\r
# @param Usage: Usage type\r
# @param TailCommentText: Comment text for tail comment\r
-# \r
+#\r
def GenInfGuidTailComment (Usage, GuidTypeList, VariableName, TailCommentText):\r
GuidType = GuidTypeList[0]\r
if (Usage == ITEM_UNDEFINED) and (GuidType == ITEM_UNDEFINED) and \\r
(not TailCommentText):\r
return ''\r
- \r
- FirstLine = Usage + " ## " + GuidType \r
+\r
+ FirstLine = Usage + " ## " + GuidType\r
if GuidType == TAB_INF_GUIDTYPE_VAR:\r
FirstLine += ":" + VariableName\r
- \r
+\r
CommentLine = TAB_SPACE_SPLIT.join([FirstLine, TailCommentText])\r
return GenTailCommentLines(CommentLine)\r
\r
## GenDecGuidTailComment\r
#\r
# @param SupModuleList: Supported module type list\r
-# \r
-def GenDecTailComment (SupModuleList): \r
+#\r
+def GenDecTailComment (SupModuleList):\r
CommentLine = TAB_SPACE_SPLIT.join(SupModuleList)\r
return GenTailCommentLines(CommentLine)\r
\r
\r
## _GetHelpStr\r
-# get HelpString from a list of HelpTextObject, the priority refer to \r
+# get HelpString from a list of HelpTextObject, the priority refer to\r
# related HLD\r
#\r
# @param HelpTextObjList: List of HelpTextObject\r
-# \r
+#\r
# @return HelpStr: the help text string found, '' means no help text found\r
#\r
def _GetHelpStr(HelpTextObjList):\r
- HelpStr = ''\r
-\r
- for HelpObj in HelpTextObjList:\r
- if HelpObj and HelpObj.GetLang() == LANGUAGE_EN_US:\r
- HelpStr = HelpObj.GetString()\r
- return HelpStr\r
- \r
- for HelpObj in HelpTextObjList:\r
- if HelpObj and HelpObj.GetLang().startswith('en'):\r
- HelpStr = HelpObj.GetString()\r
- return HelpStr\r
-\r
+ ValueList = []\r
for HelpObj in HelpTextObjList:\r
- if HelpObj and not HelpObj.GetLang():\r
- HelpStr = HelpObj.GetString()\r
- return HelpStr\r
- \r
- return HelpStr
\ No newline at end of file
+ ValueList.append((HelpObj.GetLang(), HelpObj.GetString()))\r
+ return GetLocalValue(ValueList, True)\r