]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Parser/InfDefineSectionParser.py
BaseTools: Remove equality operator with None
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfDefineSectionParser.py
CommitLineData
4234283c
LG
1## @file\r
2# This file contained the parser for define sections in INF file \r
3#\r
4# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
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
15'''\r
16InfDefineSectionParser\r
17'''\r
18##\r
19# Import Modules\r
20#\r
21import re\r
22\r
23from Library import DataType as DT\r
24from Library import GlobalData\r
25from Library.Parsing import MacroParser\r
26from Library.Misc import GetSplitValueList\r
27from Library.ParserValidate import IsValidArch\r
28from Object.Parser.InfCommonObject import InfLineCommentObject\r
29from Object.Parser.InfDefineObject import InfDefMember\r
30from Parser.InfParserMisc import InfExpandMacro\r
31from Object.Parser.InfMisc import ErrorInInf\r
32from Logger import StringTable as ST\r
33from Parser.InfParserMisc import InfParserSectionRoot\r
34\r
35## __GetValidateArchList\r
36# \r
37#\r
38def GetValidateArchList(LineContent):\r
39 \r
40 TempArch = ''\r
41 ArchList = []\r
42 ValidateAcrhPatten = re.compile(r"^\s*#\s*VALID_ARCHITECTURES\s*=\s*.*$", re.DOTALL)\r
43 \r
44 if ValidateAcrhPatten.match(LineContent):\r
45 TempArch = GetSplitValueList(LineContent, DT.TAB_EQUAL_SPLIT, 1)[1]\r
46 \r
47 TempArch = GetSplitValueList(TempArch, '(', 1)[0]\r
48 \r
49 ArchList = re.split('\s+', TempArch)\r
50 NewArchList = []\r
51 for Arch in ArchList:\r
52 if IsValidArch(Arch):\r
53 NewArchList.append(Arch)\r
54 \r
55 ArchList = NewArchList\r
56 \r
57 return ArchList \r
58\r
59class InfDefinSectionParser(InfParserSectionRoot):\r
60 def InfDefineParser(self, SectionString, InfSectionObject, FileName, SectionComment):\r
61 \r
62 if SectionComment:\r
63 pass\r
64 #\r
65 # Parser Defines section content and fill self._ContentList dict.\r
66 #\r
67 StillCommentFalg = False\r
68 HeaderComments = []\r
69 SectionContent = ''\r
70 ArchList = []\r
71 _ContentList = []\r
72 _ValueList = []\r
73 #\r
74 # Add WORKSPACE to global Marco dict.\r
75 #\r
76 self.FileLocalMacros['WORKSPACE'] = GlobalData.gWORKSPACE\r
77 \r
78 for Line in SectionString:\r
79 LineContent = Line[0]\r
80 LineNo = Line[1]\r
81 TailComments = ''\r
82 LineComment = None\r
83 \r
84 LineInfo = ['', -1, '']\r
85 LineInfo[0] = FileName\r
86 LineInfo[1] = LineNo\r
87 LineInfo[2] = LineContent\r
88 \r
89 if LineContent.strip() == '':\r
90 continue\r
91 #\r
92 # The first time encountered VALIDATE_ARCHITECHERS will be considered as support arch list.\r
93 #\r
94 if not ArchList:\r
95 ArchList = GetValidateArchList(LineContent)\r
96\r
97 #\r
98 # Parser Comment\r
99 #\r
100 if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r
101 #\r
102 # Last line is comments, and this line go on.\r
103 #\r
104 if StillCommentFalg:\r
105 HeaderComments.append(Line)\r
106 SectionContent += LineContent + DT.END_OF_LINE\r
107 continue\r
108 #\r
109 # First time encounter comment \r
110 #\r
111 else:\r
112 #\r
113 # Clear original data\r
114 #\r
115 HeaderComments = []\r
116 HeaderComments.append(Line)\r
117 StillCommentFalg = True\r
118 SectionContent += LineContent + DT.END_OF_LINE\r
119 continue\r
120 else:\r
121 StillCommentFalg = False\r
122 \r
123 if len(HeaderComments) >= 1:\r
124 LineComment = InfLineCommentObject()\r
125 LineCommentContent = ''\r
126 for Item in HeaderComments:\r
127 LineCommentContent += Item[0] + DT.END_OF_LINE\r
128 LineComment.SetHeaderComments(LineCommentContent)\r
129 \r
130 #\r
131 # Find Tail comment.\r
132 #\r
133 if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r
134 TailComments = LineContent[LineContent.find(DT.TAB_COMMENT_SPLIT):]\r
135 LineContent = LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)]\r
4231a819 136 if LineComment is None:\r
4234283c
LG
137 LineComment = InfLineCommentObject()\r
138 LineComment.SetTailComments(TailComments)\r
139 \r
140 #\r
141 # Find Macro\r
142 #\r
143 Name, Value = MacroParser((LineContent, LineNo), \r
144 FileName, \r
145 DT.MODEL_META_DATA_HEADER, \r
146 self.FileLocalMacros)\r
4231a819 147 if Name is not None:\r
4234283c
LG
148 self.FileLocalMacros[Name] = Value\r
149 continue \r
150\r
151 #\r
152 # Replace with [Defines] section Macro\r
153 #\r
154 LineContent = InfExpandMacro(LineContent, \r
155 (FileName, LineContent, LineNo), \r
156 self.FileLocalMacros, \r
157 None, True)\r
158 \r
159 SectionContent += LineContent + DT.END_OF_LINE\r
160 \r
161 TokenList = GetSplitValueList(LineContent, DT.TAB_EQUAL_SPLIT, 1)\r
162 if len(TokenList) < 2:\r
163 ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE,\r
164 LineInfo=LineInfo) \r
165 _ValueList[0:len(TokenList)] = TokenList\r
166 if not _ValueList[0]:\r
167 ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_NO_NAME,\r
168 LineInfo=LineInfo)\r
169 if not _ValueList[1]:\r
170 ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE,\r
171 LineInfo=LineInfo) \r
172 \r
173 Name, Value = _ValueList[0], _ValueList[1] \r
174 \r
175 InfDefMemberObj = InfDefMember(Name, Value)\r
4231a819 176 if (LineComment is not None):\r
4234283c
LG
177 InfDefMemberObj.Comments.SetHeaderComments(LineComment.GetHeaderComments())\r
178 InfDefMemberObj.Comments.SetTailComments(LineComment.GetTailComments())\r
179 \r
180 InfDefMemberObj.CurrentLine.SetFileName(self.FullPath)\r
181 InfDefMemberObj.CurrentLine.SetLineString(LineContent)\r
182 InfDefMemberObj.CurrentLine.SetLineNo(LineNo)\r
183 \r
184 _ContentList.append(InfDefMemberObj)\r
185 HeaderComments = []\r
186 TailComments = ''\r
187 \r
188 #\r
189 # Current Define section archs\r
190 #\r
191 if not ArchList:\r
192 ArchList = ['COMMON']\r
193 \r
194 InfSectionObject.SetAllContent(SectionContent) \r
195 \r
196 InfSectionObject.SetDefines(_ContentList, Arch=ArchList)\r
197