]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Parser/InfPcdSectionParser.py
edk2: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfPcdSectionParser.py
CommitLineData
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
f7496d71
LG
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
4234283c
LG
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
64285f15 29from Library.StringUtils import SplitPcdEntry\r
4234283c
LG
30from Parser.InfParserMisc import InfParserSectionRoot\r
31\r
32class InfPcdSectionParser(InfParserSectionRoot):\r
33 ## Section PCD related parser\r
f7496d71 34 #\r
4234283c
LG
35 # For 5 types of PCD list below, all use this function.\r
36 # 'FixedPcd', 'FeaturePcd', 'PatchPcd', 'Pcd', 'PcdEx'\r
37 #\r
f7496d71 38 # This is a INF independent parser, the validation in this parser only\r
4234283c
LG
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
f7496d71
LG
45 CommentsList = []\r
46 ValueList = []\r
4234283c
LG
47 #\r
48 # Current section archs\r
f7496d71 49 #\r
4234283c
LG
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
f7496d71 55\r
4234283c
LG
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
f7496d71
LG
60 File=FileName, Line=LineIndex)\r
61\r
4234283c
LG
62 #\r
63 # For Common INF file\r
64 #\r
f7496d71 65 if not GlobalData.gIS_BINARY_INF:\r
4234283c 66 #\r
f7496d71 67 # Macro defined in this section\r
4234283c 68 #\r
f7496d71 69 SectionMacros = {}\r
4234283c
LG
70 for Line in SectionString:\r
71 PcdLineContent = Line[0]\r
72 PcdLineNo = Line[1]\r
73 if PcdLineContent.strip() == '':\r
74 CommentsList = []\r
f7496d71
LG
75 continue\r
76\r
4234283c
LG
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
f7496d71 86 PcdLineContent[PcdLineContent.find(DT.TAB_COMMENT_SPLIT):],\r
4234283c 87 PcdLineNo))\r
f7496d71
LG
88 PcdLineContent = PcdLineContent[:PcdLineContent.find(DT.TAB_COMMENT_SPLIT)]\r
89\r
4234283c
LG
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
f7496d71 103\r
4234283c 104 PcdEntryReturn = SplitPcdEntry(PcdLineContent)\r
f7496d71 105\r
4234283c 106 if not PcdEntryReturn[1]:\r
f7496d71 107 TokenList = ['']\r
4234283c
LG
108 else:\r
109 TokenList = PcdEntryReturn[0]\r
f7496d71 110\r
4234283c 111 ValueList[0:len(TokenList)] = TokenList\r
f7496d71 112\r
4234283c
LG
113 #\r
114 # Replace with Local section Macro and [Defines] section Macro.\r
f7496d71
LG
115 #\r
116 ValueList = [InfExpandMacro(Value, (FileName, PcdLineContent, PcdLineNo),\r
4234283c
LG
117 self.FileLocalMacros, SectionMacros, True)\r
118 for Value in ValueList]\r
f7496d71 119\r
4234283c
LG
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
f7496d71 132\r
4234283c
LG
133 if LineContent == '':\r
134 CommentsList = []\r
135 continue\r
f7496d71 136\r
4234283c
LG
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
f7496d71 147\r
4234283c
LG
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
f7496d71
LG
155 Logger.Error('InfParser',\r
156 FORMAT_INVALID,\r
4234283c
LG
157 ST.ERR_ASBUILD_PATCHPCD_FORMAT_INVALID,\r
158 File=FileName,\r
159 Line=LineNo,\r
160 ExtraData=LineContent)\r
f7496d71 161 #\r
4234283c 162 elif KeysList[0][0].upper() == DT.TAB_INF_PCD_EX.upper():\r
421ccda3 163 if len(TokenList) != 1:\r
f7496d71
LG
164 Logger.Error('InfParser',\r
165 FORMAT_INVALID,\r
4234283c
LG
166 ST.ERR_ASBUILD_PCDEX_FORMAT_INVALID,\r
167 File=FileName,\r
168 Line=LineNo,\r
421ccda3 169 ExtraData=LineContent)\r
4234283c 170 ValueList[0:len(TokenList)] = TokenList\r
f7496d71
LG
171 if len(ValueList) >= 1:\r
172 PcdList.append((ValueList, CommentsList, (LineContent, LineNo, FileName)))\r
4234283c
LG
173 ValueList = []\r
174 CommentsList = []\r
f7496d71
LG
175 continue\r
176\r
177 if not InfSectionObject.SetPcds(PcdList, KeysList = KeysList,\r
4234283c 178 PackageInfo = self.InfPackageSection.GetPackages()):\r
f7496d71
LG
179 Logger.Error('InfParser',\r
180 FORMAT_INVALID,\r
4234283c
LG
181 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[PCD]"),\r
182 File=FileName,\r
f7496d71
LG
183 Line=LineIndex)\r
184\r