]>
Commit | Line | Data |
---|---|---|
4234283c | 1 | ## @file\r |
f7496d71 | 2 | # This file contained the parser for [Pcds] sections in INF file\r |
4234283c | 3 | #\r |
64285f15 | 4 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r |
4234283c | 5 | #\r |
2e351cbe | 6 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
4234283c LG |
7 | #\r |
8 | '''\r | |
9 | InfPcdSectionParser\r | |
10 | '''\r | |
11 | ##\r | |
12 | # Import Modules\r | |
13 | #\r | |
14 | \r | |
15 | import Logger.Log as Logger\r | |
16 | from Logger import StringTable as ST\r | |
17 | from Logger.ToolError import FORMAT_INVALID\r | |
18 | from Parser.InfParserMisc import InfExpandMacro\r | |
19 | from Library import DataType as DT\r | |
20 | from Library.Parsing import MacroParser\r | |
21 | from Library.Misc import GetSplitValueList\r | |
22 | from Library import GlobalData\r | |
64285f15 | 23 | from Library.StringUtils import SplitPcdEntry\r |
4234283c LG |
24 | from Parser.InfParserMisc import InfParserSectionRoot\r |
25 | \r | |
26 | class InfPcdSectionParser(InfParserSectionRoot):\r | |
27 | ## Section PCD related parser\r | |
f7496d71 | 28 | #\r |
4234283c LG |
29 | # For 5 types of PCD list below, all use this function.\r |
30 | # 'FixedPcd', 'FeaturePcd', 'PatchPcd', 'Pcd', 'PcdEx'\r | |
31 | #\r | |
f7496d71 | 32 | # This is a INF independent parser, the validation in this parser only\r |
4234283c LG |
33 | # cover\r |
34 | # INF spec scope, will not cross DEC/DSC to check pcd value\r | |
35 | #\r | |
36 | def InfPcdParser(self, SectionString, InfSectionObject, FileName):\r | |
37 | KeysList = []\r | |
38 | PcdList = []\r | |
f7496d71 LG |
39 | CommentsList = []\r |
40 | ValueList = []\r | |
4234283c LG |
41 | #\r |
42 | # Current section archs\r | |
f7496d71 | 43 | #\r |
4234283c LG |
44 | LineIndex = -1\r |
45 | for Item in self.LastSectionHeaderContent:\r | |
46 | if (Item[0], Item[1], Item[3]) not in KeysList:\r | |
47 | KeysList.append((Item[0], Item[1], Item[3]))\r | |
48 | LineIndex = Item[3]\r | |
f7496d71 | 49 | \r |
4234283c LG |
50 | if (Item[0].upper() == DT.TAB_INF_FIXED_PCD.upper() or \\r |
51 | Item[0].upper() == DT.TAB_INF_FEATURE_PCD.upper() or \\r | |
52 | Item[0].upper() == DT.TAB_INF_PCD.upper()) and GlobalData.gIS_BINARY_INF:\r | |
53 | Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_ASBUILD_PCD_SECTION_TYPE%("\"" + Item[0] + "\""),\r | |
f7496d71 LG |
54 | File=FileName, Line=LineIndex)\r |
55 | \r | |
4234283c LG |
56 | #\r |
57 | # For Common INF file\r | |
58 | #\r | |
f7496d71 | 59 | if not GlobalData.gIS_BINARY_INF:\r |
4234283c | 60 | #\r |
f7496d71 | 61 | # Macro defined in this section\r |
4234283c | 62 | #\r |
f7496d71 | 63 | SectionMacros = {}\r |
4234283c LG |
64 | for Line in SectionString:\r |
65 | PcdLineContent = Line[0]\r | |
66 | PcdLineNo = Line[1]\r | |
67 | if PcdLineContent.strip() == '':\r | |
68 | CommentsList = []\r | |
f7496d71 LG |
69 | continue\r |
70 | \r | |
4234283c LG |
71 | if PcdLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r |
72 | CommentsList.append(Line)\r | |
73 | continue\r | |
74 | else:\r | |
75 | #\r | |
76 | # Encounter a PCD entry\r | |
77 | #\r | |
78 | if PcdLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r | |
79 | CommentsList.append((\r | |
f7496d71 | 80 | PcdLineContent[PcdLineContent.find(DT.TAB_COMMENT_SPLIT):],\r |
4234283c | 81 | PcdLineNo))\r |
f7496d71 LG |
82 | PcdLineContent = PcdLineContent[:PcdLineContent.find(DT.TAB_COMMENT_SPLIT)]\r |
83 | \r | |
4234283c LG |
84 | if PcdLineContent != '':\r |
85 | #\r | |
86 | # Find Macro\r | |
87 | #\r | |
88 | Name, Value = MacroParser((PcdLineContent, PcdLineNo),\r | |
89 | FileName,\r | |
90 | DT.MODEL_EFI_PCD,\r | |
91 | self.FileLocalMacros)\r | |
4231a819 | 92 | if Name is not None:\r |
4234283c LG |
93 | SectionMacros[Name] = Value\r |
94 | ValueList = []\r | |
95 | CommentsList = []\r | |
96 | continue\r | |
f7496d71 | 97 | \r |
4234283c | 98 | PcdEntryReturn = SplitPcdEntry(PcdLineContent)\r |
f7496d71 | 99 | \r |
4234283c | 100 | if not PcdEntryReturn[1]:\r |
f7496d71 | 101 | TokenList = ['']\r |
4234283c LG |
102 | else:\r |
103 | TokenList = PcdEntryReturn[0]\r | |
f7496d71 | 104 | \r |
4234283c | 105 | ValueList[0:len(TokenList)] = TokenList\r |
f7496d71 | 106 | \r |
4234283c LG |
107 | #\r |
108 | # Replace with Local section Macro and [Defines] section Macro.\r | |
f7496d71 LG |
109 | #\r |
110 | ValueList = [InfExpandMacro(Value, (FileName, PcdLineContent, PcdLineNo),\r | |
4234283c LG |
111 | self.FileLocalMacros, SectionMacros, True)\r |
112 | for Value in ValueList]\r | |
f7496d71 | 113 | \r |
4234283c LG |
114 | if len(ValueList) >= 1:\r |
115 | PcdList.append((ValueList, CommentsList, (PcdLineContent, PcdLineNo, FileName)))\r | |
116 | ValueList = []\r | |
117 | CommentsList = []\r | |
118 | continue\r | |
119 | #\r | |
120 | # For Binary INF file\r | |
121 | #\r | |
122 | else:\r | |
123 | for Line in SectionString:\r | |
124 | LineContent = Line[0].strip()\r | |
125 | LineNo = Line[1]\r | |
f7496d71 | 126 | \r |
4234283c LG |
127 | if LineContent == '':\r |
128 | CommentsList = []\r | |
129 | continue\r | |
f7496d71 | 130 | \r |
4234283c LG |
131 | if LineContent.startswith(DT.TAB_COMMENT_SPLIT):\r |
132 | CommentsList.append(LineContent)\r | |
133 | continue\r | |
134 | #\r | |
135 | # Have comments at tail.\r | |
136 | #\r | |
137 | CommentIndex = LineContent.find(DT.TAB_COMMENT_SPLIT)\r | |
138 | if CommentIndex > -1:\r | |
139 | CommentsList.append(LineContent[CommentIndex+1:])\r | |
140 | LineContent = LineContent[:CommentIndex]\r | |
f7496d71 | 141 | \r |
4234283c LG |
142 | TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT)\r |
143 | #\r | |
144 | # PatchablePcd\r | |
145 | # TokenSpace.CName | Value | Offset\r | |
146 | #\r | |
147 | if KeysList[0][0].upper() == DT.TAB_INF_PATCH_PCD.upper():\r | |
148 | if len(TokenList) != 3:\r | |
f7496d71 LG |
149 | Logger.Error('InfParser',\r |
150 | FORMAT_INVALID,\r | |
4234283c LG |
151 | ST.ERR_ASBUILD_PATCHPCD_FORMAT_INVALID,\r |
152 | File=FileName,\r | |
153 | Line=LineNo,\r | |
154 | ExtraData=LineContent)\r | |
f7496d71 | 155 | #\r |
4234283c | 156 | elif KeysList[0][0].upper() == DT.TAB_INF_PCD_EX.upper():\r |
421ccda3 | 157 | if len(TokenList) != 1:\r |
f7496d71 LG |
158 | Logger.Error('InfParser',\r |
159 | FORMAT_INVALID,\r | |
4234283c LG |
160 | ST.ERR_ASBUILD_PCDEX_FORMAT_INVALID,\r |
161 | File=FileName,\r | |
162 | Line=LineNo,\r | |
421ccda3 | 163 | ExtraData=LineContent)\r |
4234283c | 164 | ValueList[0:len(TokenList)] = TokenList\r |
f7496d71 LG |
165 | if len(ValueList) >= 1:\r |
166 | PcdList.append((ValueList, CommentsList, (LineContent, LineNo, FileName)))\r | |
4234283c LG |
167 | ValueList = []\r |
168 | CommentsList = []\r | |
f7496d71 LG |
169 | continue\r |
170 | \r | |
171 | if not InfSectionObject.SetPcds(PcdList, KeysList = KeysList,\r | |
4234283c | 172 | PackageInfo = self.InfPackageSection.GetPackages()):\r |
f7496d71 LG |
173 | Logger.Error('InfParser',\r |
174 | FORMAT_INVALID,\r | |
4234283c LG |
175 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[PCD]"),\r |
176 | File=FileName,\r | |
f7496d71 LG |
177 | Line=LineIndex)\r |
178 | \r |