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