]>
Commit | Line | Data |
---|---|---|
1 | ## @file\r | |
2 | # This file is used to define comment generating interface\r | |
3 | #\r | |
4 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
5 | #\r | |
6 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | #\r | |
8 | \r | |
9 | '''\r | |
10 | CommentGenerating\r | |
11 | '''\r | |
12 | \r | |
13 | ##\r | |
14 | # Import Modules\r | |
15 | #\r | |
16 | from Library.StringUtils import GetSplitValueList\r | |
17 | from Library.DataType import TAB_SPACE_SPLIT\r | |
18 | from Library.DataType import TAB_INF_GUIDTYPE_VAR\r | |
19 | from Library.DataType import USAGE_ITEM_NOTIFY\r | |
20 | from Library.DataType import ITEM_UNDEFINED\r | |
21 | from Library.DataType import TAB_HEADER_COMMENT\r | |
22 | from Library.DataType import TAB_BINARY_HEADER_COMMENT\r | |
23 | from Library.DataType import TAB_COMMENT_SPLIT\r | |
24 | from Library.DataType import TAB_SPECIAL_COMMENT\r | |
25 | from Library.DataType import END_OF_LINE\r | |
26 | from Library.DataType import TAB_COMMENT_EDK1_SPLIT\r | |
27 | from Library.DataType import TAB_COMMENT_EDK1_START\r | |
28 | from Library.DataType import TAB_COMMENT_EDK1_END\r | |
29 | from Library.DataType import TAB_STAR\r | |
30 | from Library.DataType import TAB_PCD_PROMPT\r | |
31 | from Library.UniClassObject import ConvertSpecialUnicodes\r | |
32 | from Library.Misc import GetLocalValue\r | |
33 | ## GenTailCommentLines\r | |
34 | #\r | |
35 | # @param TailCommentLines: the tail comment lines that need to be generated\r | |
36 | # @param LeadingSpaceNum: the number of leading space needed for non-first\r | |
37 | # line tail comment\r | |
38 | #\r | |
39 | def GenTailCommentLines (TailCommentLines, LeadingSpaceNum = 0):\r | |
40 | TailCommentLines = TailCommentLines.rstrip(END_OF_LINE)\r | |
41 | CommentStr = TAB_SPACE_SPLIT*2 + TAB_SPECIAL_COMMENT + TAB_SPACE_SPLIT + \\r | |
42 | (END_OF_LINE + LeadingSpaceNum * TAB_SPACE_SPLIT + TAB_SPACE_SPLIT*2 + TAB_SPECIAL_COMMENT + \\r | |
43 | TAB_SPACE_SPLIT).join(GetSplitValueList(TailCommentLines, END_OF_LINE))\r | |
44 | \r | |
45 | return CommentStr\r | |
46 | \r | |
47 | ## GenGenericComment\r | |
48 | #\r | |
49 | # @param CommentLines: Generic comment Text, maybe Multiple Lines\r | |
50 | #\r | |
51 | def GenGenericComment (CommentLines):\r | |
52 | if not CommentLines:\r | |
53 | return ''\r | |
54 | CommentLines = CommentLines.rstrip(END_OF_LINE)\r | |
55 | CommentStr = TAB_SPECIAL_COMMENT + TAB_SPACE_SPLIT + (END_OF_LINE + TAB_COMMENT_SPLIT + TAB_SPACE_SPLIT).join\\r | |
56 | (GetSplitValueList(CommentLines, END_OF_LINE)) + END_OF_LINE\r | |
57 | return CommentStr\r | |
58 | \r | |
59 | ## GenGenericCommentF\r | |
60 | #\r | |
61 | # similar to GenGenericComment but will remove <EOL> at end of comment once,\r | |
62 | # and for line with only <EOL>, '#\n' will be generated instead of '# \n'\r | |
63 | #\r | |
64 | # @param CommentLines: Generic comment Text, maybe Multiple Lines\r | |
65 | # @return CommentStr: Generated comment line\r | |
66 | #\r | |
67 | def GenGenericCommentF (CommentLines, NumOfPound=1, IsPrompt=False, IsInfLibraryClass=False):\r | |
68 | if not CommentLines:\r | |
69 | return ''\r | |
70 | #\r | |
71 | # if comment end with '\n', then remove it to prevent one extra line\r | |
72 | # generate later on\r | |
73 | #\r | |
74 | if CommentLines.endswith(END_OF_LINE):\r | |
75 | CommentLines = CommentLines[:-1]\r | |
76 | CommentStr = ''\r | |
77 | if IsPrompt:\r | |
78 | CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT + TAB_PCD_PROMPT + TAB_SPACE_SPLIT + \\r | |
79 | CommentLines.replace(END_OF_LINE, '') + END_OF_LINE\r | |
80 | else:\r | |
81 | CommentLineList = GetSplitValueList(CommentLines, END_OF_LINE)\r | |
82 | FindLibraryClass = False\r | |
83 | for Line in CommentLineList:\r | |
84 | # If this comment is for @libraryclass and it has multiple lines\r | |
85 | # make sure the second lines align to the first line after @libraryclass as below\r | |
86 | #\r | |
87 | # ## @libraryclass XYZ FIRST_LINE\r | |
88 | # ## ABC SECOND_LINE\r | |
89 | #\r | |
90 | if IsInfLibraryClass and Line.find(u'@libraryclass ') > -1:\r | |
91 | FindLibraryClass = True\r | |
92 | if Line == '':\r | |
93 | CommentStr += TAB_COMMENT_SPLIT * NumOfPound + END_OF_LINE\r | |
94 | else:\r | |
95 | if FindLibraryClass and Line.find(u'@libraryclass ') > -1:\r | |
96 | CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT + Line + END_OF_LINE\r | |
97 | elif FindLibraryClass:\r | |
98 | CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT * 16 + Line + END_OF_LINE\r | |
99 | else:\r | |
100 | CommentStr += TAB_COMMENT_SPLIT * NumOfPound + TAB_SPACE_SPLIT + Line + END_OF_LINE\r | |
101 | \r | |
102 | return CommentStr\r | |
103 | \r | |
104 | \r | |
105 | ## GenHeaderCommentSection\r | |
106 | #\r | |
107 | # Generate Header comment sections\r | |
108 | #\r | |
109 | # @param Abstract One line of abstract\r | |
110 | # @param Description multiple lines of Description\r | |
111 | # @param Copyright possible multiple copyright lines\r | |
112 | # @param License possible multiple license lines\r | |
113 | #\r | |
114 | def GenHeaderCommentSection(Abstract, Description, Copyright, License, IsBinaryHeader=False, \\r | |
115 | CommChar=TAB_COMMENT_SPLIT):\r | |
116 | Content = ''\r | |
117 | \r | |
118 | #\r | |
119 | # Convert special character to (c), (r) and (tm).\r | |
120 | #\r | |
121 | Abstract = ConvertSpecialUnicodes(Abstract)\r | |
122 | Description = ConvertSpecialUnicodes(Description)\r | |
123 | if IsBinaryHeader:\r | |
124 | Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_BINARY_HEADER_COMMENT + '\r\n'\r | |
125 | elif CommChar == TAB_COMMENT_EDK1_SPLIT:\r | |
126 | Content += CommChar + TAB_SPACE_SPLIT + TAB_COMMENT_EDK1_START + TAB_STAR + TAB_SPACE_SPLIT +\\r | |
127 | TAB_HEADER_COMMENT + '\r\n'\r | |
128 | else:\r | |
129 | Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_HEADER_COMMENT + '\r\n'\r | |
130 | if Abstract:\r | |
131 | Abstract = Abstract.rstrip('\r\n')\r | |
132 | Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\\r | |
133 | (Abstract, '\n'))\r | |
134 | Content += '\r\n' + CommChar + '\r\n'\r | |
135 | else:\r | |
136 | Content += CommChar + '\r\n'\r | |
137 | \r | |
138 | if Description:\r | |
139 | Description = Description.rstrip('\r\n')\r | |
140 | Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\\r | |
141 | (Description, '\n'))\r | |
142 | Content += '\r\n' + CommChar + '\r\n'\r | |
143 | \r | |
144 | #\r | |
145 | # There is no '#\n' line to separate multiple copyright lines in code base\r | |
146 | #\r | |
147 | if Copyright:\r | |
148 | Copyright = Copyright.rstrip('\r\n')\r | |
149 | Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join\\r | |
150 | (GetSplitValueList(Copyright, '\n'))\r | |
151 | Content += '\r\n' + CommChar + '\r\n'\r | |
152 | \r | |
153 | if License:\r | |
154 | License = License.rstrip('\r\n')\r | |
155 | Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\\r | |
156 | (License, '\n'))\r | |
157 | Content += '\r\n' + CommChar + '\r\n'\r | |
158 | \r | |
159 | if CommChar == TAB_COMMENT_EDK1_SPLIT:\r | |
160 | Content += CommChar + TAB_SPACE_SPLIT + TAB_STAR + TAB_COMMENT_EDK1_END + '\r\n'\r | |
161 | else:\r | |
162 | Content += CommChar * 2 + '\r\n'\r | |
163 | \r | |
164 | return Content\r | |
165 | \r | |
166 | \r | |
167 | ## GenInfPcdTailComment\r | |
168 | # Generate Pcd tail comment for Inf, this would be one line comment\r | |
169 | #\r | |
170 | # @param Usage: Usage type\r | |
171 | # @param TailCommentText: Comment text for tail comment\r | |
172 | #\r | |
173 | def GenInfPcdTailComment (Usage, TailCommentText):\r | |
174 | if (Usage == ITEM_UNDEFINED) and (not TailCommentText):\r | |
175 | return ''\r | |
176 | \r | |
177 | CommentLine = TAB_SPACE_SPLIT.join([Usage, TailCommentText])\r | |
178 | return GenTailCommentLines(CommentLine)\r | |
179 | \r | |
180 | ## GenInfProtocolPPITailComment\r | |
181 | # Generate Protocol/PPI tail comment for Inf\r | |
182 | #\r | |
183 | # @param Usage: Usage type\r | |
184 | # @param TailCommentText: Comment text for tail comment\r | |
185 | #\r | |
186 | def GenInfProtocolPPITailComment (Usage, Notify, TailCommentText):\r | |
187 | if (not Notify) and (Usage == ITEM_UNDEFINED) and (not TailCommentText):\r | |
188 | return ''\r | |
189 | \r | |
190 | if Notify:\r | |
191 | CommentLine = USAGE_ITEM_NOTIFY + " ## "\r | |
192 | else:\r | |
193 | CommentLine = ''\r | |
194 | \r | |
195 | CommentLine += TAB_SPACE_SPLIT.join([Usage, TailCommentText])\r | |
196 | return GenTailCommentLines(CommentLine)\r | |
197 | \r | |
198 | ## GenInfGuidTailComment\r | |
199 | # Generate Guid tail comment for Inf\r | |
200 | #\r | |
201 | # @param Usage: Usage type\r | |
202 | # @param TailCommentText: Comment text for tail comment\r | |
203 | #\r | |
204 | def GenInfGuidTailComment (Usage, GuidTypeList, VariableName, TailCommentText):\r | |
205 | GuidType = GuidTypeList[0]\r | |
206 | if (Usage == ITEM_UNDEFINED) and (GuidType == ITEM_UNDEFINED) and \\r | |
207 | (not TailCommentText):\r | |
208 | return ''\r | |
209 | \r | |
210 | FirstLine = Usage + " ## " + GuidType\r | |
211 | if GuidType == TAB_INF_GUIDTYPE_VAR:\r | |
212 | FirstLine += ":" + VariableName\r | |
213 | \r | |
214 | CommentLine = TAB_SPACE_SPLIT.join([FirstLine, TailCommentText])\r | |
215 | return GenTailCommentLines(CommentLine)\r | |
216 | \r | |
217 | ## GenDecGuidTailComment\r | |
218 | #\r | |
219 | # @param SupModuleList: Supported module type list\r | |
220 | #\r | |
221 | def GenDecTailComment (SupModuleList):\r | |
222 | CommentLine = TAB_SPACE_SPLIT.join(SupModuleList)\r | |
223 | return GenTailCommentLines(CommentLine)\r | |
224 | \r | |
225 | \r | |
226 | ## _GetHelpStr\r | |
227 | # get HelpString from a list of HelpTextObject, the priority refer to\r | |
228 | # related HLD\r | |
229 | #\r | |
230 | # @param HelpTextObjList: List of HelpTextObject\r | |
231 | #\r | |
232 | # @return HelpStr: the help text string found, '' means no help text found\r | |
233 | #\r | |
234 | def _GetHelpStr(HelpTextObjList):\r | |
235 | ValueList = []\r | |
236 | for HelpObj in HelpTextObjList:\r | |
237 | ValueList.append((HelpObj.GetLang(), HelpObj.GetString()))\r | |
238 | return GetLocalValue(ValueList, True)\r |