BaseTools: FdfParser remove class never used.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FdfParser.py
CommitLineData
30fdf114
LG
1## @file\r
2# parse FDF file\r
3#\r
a87e79d9 4# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
118bf096 5# Copyright (c) 2015, Hewlett Packard Enterprise Development, L.P.<BR>\r
30fdf114 6#\r
40d841f6 7# This program and the accompanying materials\r
30fdf114
LG
8# are licensed and made available under the terms and conditions of the BSD License\r
9# which accompanies this distribution. The full text of the license may be found at\r
10# http://opensource.org/licenses/bsd-license.php\r
11#\r
12# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14#\r
15\r
16##\r
17# Import Modules\r
18#\r
0d2711a6
LG
19import re\r
20\r
30fdf114
LG
21import Fd\r
22import Region\r
23import Fv\r
24import AprioriSection\r
25import FfsInfStatement\r
26import FfsFileStatement\r
27import VerSection\r
28import UiSection\r
29import FvImageSection\r
30import DataSection\r
31import DepexSection\r
32import CompressSection\r
33import GuidSection\r
34import Capsule\r
35import CapsuleData\r
36import Rule\r
37import RuleComplexFile\r
38import RuleSimpleFile\r
39import EfiSection\r
40import Vtf\r
41import ComponentStatement\r
42import OptionRom\r
43import OptRomInfStatement\r
44import OptRomFileStatement\r
45\r
52302d4d 46from GenFdsGlobalVariable import GenFdsGlobalVariable\r
30fdf114
LG
47from Common.BuildToolError import *\r
48from Common import EdkLogger\r
14c48571 49from Common.Misc import PathClass\r
50from Common.String import NormPath\r
0d2711a6
LG
51import Common.GlobalData as GlobalData\r
52from Common.Expression import *\r
df692f02 53from Common import GlobalData\r
2bcc713e 54from Common.String import ReplaceMacro\r
91ae2988 55import uuid\r
d0acc87a 56from Common.Misc import tdict\r
94e4bcbb 57from Common.MultipleWorkspace import MultipleWorkspace as mws\r
1be2ed90
HC
58import Common.LongFilePathOs as os\r
59from Common.LongFilePathSupport import OpenLongFilePath as open\r
91ae2988
YZ
60from Capsule import EFI_CERT_TYPE_PKCS7_GUID\r
61from Capsule import EFI_CERT_TYPE_RSA2048_SHA256_GUID\r
2eb370ff 62from Common.RangeExpression import RangeExpression\r
30fdf114
LG
63\r
64##define T_CHAR_SPACE ' '\r
65##define T_CHAR_NULL '\0'\r
66##define T_CHAR_CR '\r'\r
67##define T_CHAR_TAB '\t'\r
68##define T_CHAR_LF '\n'\r
69##define T_CHAR_SLASH '/'\r
70##define T_CHAR_BACKSLASH '\\'\r
71##define T_CHAR_DOUBLE_QUOTE '\"'\r
72##define T_CHAR_SINGLE_QUOTE '\''\r
73##define T_CHAR_STAR '*'\r
74##define T_CHAR_HASH '#'\r
75\r
76(T_CHAR_SPACE, T_CHAR_NULL, T_CHAR_CR, T_CHAR_TAB, T_CHAR_LF, T_CHAR_SLASH, \\r
77T_CHAR_BACKSLASH, T_CHAR_DOUBLE_QUOTE, T_CHAR_SINGLE_QUOTE, T_CHAR_STAR, T_CHAR_HASH) = \\r
78(' ', '\0', '\r', '\t', '\n', '/', '\\', '\"', '\'', '*', '#')\r
79\r
80SEPERATOR_TUPLE = ('=', '|', ',', '{', '}')\r
81\r
0d2711a6
LG
82RegionSizePattern = re.compile("\s*(?P<base>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<size>(?:0x|0X)?[a-fA-F0-9]+)\s*")\r
83RegionSizeGuidPattern = re.compile("\s*(?P<base>\w+\.\w+)\s*\|\s*(?P<size>\w+\.\w+)\s*")\r
2bc3256c 84RegionOffsetPcdPattern = re.compile("\s*(?P<base>\w+\.\w+)\s*$")\r
64b2609f 85ShortcutPcdPattern = re.compile("\s*\w+\s*=\s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<name>\w+\.\w+)\s*")\r
0d2711a6 86\r
118bf096
CS
87AllIncludeFileList = []\r
88\r
89# Get the closest parent\r
90def GetParentAtLine (Line):\r
91 for Profile in AllIncludeFileList:\r
92 if Profile.IsLineInFile(Line):\r
93 return Profile\r
94 return None\r
95\r
96# Check include loop\r
97def IsValidInclude (File, Line):\r
98 for Profile in AllIncludeFileList:\r
99 if Profile.IsLineInFile(Line) and Profile.FileName == File:\r
100 return False\r
101\r
102 return True\r
30fdf114
LG
103\r
104def GetRealFileLine (File, Line):\r
105\r
106 InsertedLines = 0\r
118bf096
CS
107 for Profile in AllIncludeFileList:\r
108 if Profile.IsLineInFile(Line):\r
109 return Profile.GetLineInFile(Line)\r
110 elif Line >= Profile.InsertStartLineNumber and Profile.Level == 1:\r
df81077f 111 InsertedLines += Profile.GetTotalLines()\r
30fdf114
LG
112\r
113 return (File, Line - InsertedLines)\r
114\r
115## The exception class that used to report error messages when parsing FDF\r
116#\r
117# Currently the "ToolName" is set to be "FDF Parser".\r
118#\r
119class Warning (Exception):\r
120 ## The constructor\r
121 #\r
122 # @param self The object pointer\r
123 # @param Str The message to record\r
124 # @param File The FDF name\r
125 # @param Line The Line number that error occurs\r
126 #\r
127 def __init__(self, Str, File = None, Line = None):\r
128\r
129 FileLineTuple = GetRealFileLine(File, Line)\r
130 self.FileName = FileLineTuple[0]\r
131 self.LineNumber = FileLineTuple[1]\r
118bf096 132 self.OriginalLineNumber = Line\r
30fdf114
LG
133 self.Message = Str\r
134 self.ToolName = 'FdfParser'\r
135\r
136 def __str__(self):\r
137 return self.Message\r
138\r
30fdf114
LG
139## The Include file content class that used to record file data when parsing include file\r
140#\r
141# May raise Exception when opening file.\r
142#\r
143class IncludeFileProfile :\r
144 ## The constructor\r
145 #\r
146 # @param self The object pointer\r
147 # @param FileName The file that to be parsed\r
148 #\r
149 def __init__(self, FileName):\r
150 self.FileName = FileName\r
151 self.FileLinesList = []\r
152 try:\r
153 fsock = open(FileName, "rb", 0)\r
154 try:\r
155 self.FileLinesList = fsock.readlines()\r
47a29bc7
YF
156 for index, line in enumerate(self.FileLinesList):\r
157 if not line.endswith('\n'):\r
158 self.FileLinesList[index] += '\n'\r
159\r
30fdf114
LG
160 finally:\r
161 fsock.close()\r
162\r
163 except:\r
164 EdkLogger.error("FdfParser", FILE_OPEN_FAILURE, ExtraData=FileName)\r
165\r
166 self.InsertStartLineNumber = None\r
167 self.InsertAdjust = 0\r
118bf096
CS
168 self.IncludeFileList = []\r
169 self.Level = 1 # first level include file\r
170 \r
171 def GetTotalLines(self):\r
172 TotalLines = self.InsertAdjust + len(self.FileLinesList)\r
173\r
174 for Profile in self.IncludeFileList:\r
df81077f 175 TotalLines += Profile.GetTotalLines()\r
118bf096
CS
176\r
177 return TotalLines\r
178\r
179 def IsLineInFile(self, Line):\r
180 if Line >= self.InsertStartLineNumber and Line < self.InsertStartLineNumber + self.GetTotalLines():\r
181 return True\r
182\r
183 return False\r
184\r
185 def GetLineInFile(self, Line):\r
186 if not self.IsLineInFile (Line):\r
187 return (self.FileName, -1)\r
188 \r
189 InsertedLines = self.InsertStartLineNumber\r
190\r
191 for Profile in self.IncludeFileList:\r
192 if Profile.IsLineInFile(Line):\r
193 return Profile.GetLineInFile(Line)\r
194 elif Line >= Profile.InsertStartLineNumber:\r
195 InsertedLines += Profile.GetTotalLines()\r
196\r
197 return (self.FileName, Line - InsertedLines + 1)\r
198\r
199\r
30fdf114
LG
200\r
201## The FDF content class that used to record file data when parsing FDF\r
202#\r
203# May raise Exception when opening file.\r
204#\r
205class FileProfile :\r
206 ## The constructor\r
207 #\r
208 # @param self The object pointer\r
209 # @param FileName The file that to be parsed\r
210 #\r
211 def __init__(self, FileName):\r
212 self.FileLinesList = []\r
213 try:\r
214 fsock = open(FileName, "rb", 0)\r
215 try:\r
216 self.FileLinesList = fsock.readlines()\r
217 finally:\r
218 fsock.close()\r
219\r
220 except:\r
221 EdkLogger.error("FdfParser", FILE_OPEN_FAILURE, ExtraData=FileName)\r
222\r
223\r
224 self.PcdDict = {}\r
225 self.InfList = []\r
2502b735 226 self.InfDict = {'ArchTBD':[]}\r
d0acc87a
LG
227 # ECC will use this Dict and List information\r
228 self.PcdFileLineDict = {}\r
229 self.InfFileLineList = []\r
230 \r
30fdf114 231 self.FdDict = {}\r
52302d4d 232 self.FdNameNotSet = False\r
30fdf114 233 self.FvDict = {}\r
fd171542 234 self.CapsuleDict = {}\r
30fdf114
LG
235 self.VtfList = []\r
236 self.RuleDict = {}\r
237 self.OptRomDict = {}\r
a3251d84 238 self.FmpPayloadDict = {}\r
30fdf114
LG
239\r
240## The syntax parser for FDF\r
241#\r
242# PreprocessFile method should be called prior to ParseFile\r
243# CycleReferenceCheck method can detect cycles in FDF contents\r
244#\r
245# GetNext*** procedures mean these procedures will get next token first, then make judgement.\r
246# Get*** procedures mean these procedures will make judgement on current token only.\r
247#\r
248class FdfParser:\r
249 ## The constructor\r
250 #\r
251 # @param self The object pointer\r
252 # @param FileName The file that to be parsed\r
253 #\r
254 def __init__(self, FileName):\r
255 self.Profile = FileProfile(FileName)\r
256 self.FileName = FileName\r
257 self.CurrentLineNumber = 1\r
258 self.CurrentOffsetWithinLine = 0\r
259 self.CurrentFdName = None\r
260 self.CurrentFvName = None\r
261 self.__Token = ""\r
262 self.__SkippedChars = ""\r
97fa0ee9 263 GlobalData.gFdfParser = self\r
30fdf114 264\r
d0acc87a
LG
265 # Used to section info\r
266 self.__CurSection = []\r
267 # Key: [section name, UI name, arch]\r
268 # Value: {MACRO_NAME : MACRO_VALUE}\r
269 self.__MacroDict = tdict(True, 3)\r
270 self.__PcdDict = {}\r
271\r
30fdf114 272 self.__WipeOffArea = []\r
14c48571 273 if GenFdsGlobalVariable.WorkSpaceDir == '':\r
274 GenFdsGlobalVariable.WorkSpaceDir = os.getenv("WORKSPACE")\r
30fdf114
LG
275\r
276 ## __IsWhiteSpace() method\r
277 #\r
278 # Whether char at current FileBufferPos is whitespace\r
279 #\r
280 # @param self The object pointer\r
281 # @param Char The char to test\r
282 # @retval True The char is a kind of white space\r
283 # @retval False The char is NOT a kind of white space\r
284 #\r
285 def __IsWhiteSpace(self, Char):\r
286 if Char in (T_CHAR_NULL, T_CHAR_CR, T_CHAR_SPACE, T_CHAR_TAB, T_CHAR_LF):\r
287 return True\r
288 else:\r
289 return False\r
290\r
291 ## __SkipWhiteSpace() method\r
292 #\r
293 # Skip white spaces from current char, return number of chars skipped\r
294 #\r
295 # @param self The object pointer\r
296 # @retval Count The number of chars skipped\r
297 #\r
298 def __SkipWhiteSpace(self):\r
299 Count = 0\r
300 while not self.__EndOfFile():\r
301 Count += 1\r
302 if self.__CurrentChar() in (T_CHAR_NULL, T_CHAR_CR, T_CHAR_LF, T_CHAR_SPACE, T_CHAR_TAB):\r
303 self.__SkippedChars += str(self.__CurrentChar())\r
304 self.__GetOneChar()\r
305\r
306 else:\r
307 Count = Count - 1\r
308 return Count\r
309\r
310 ## __EndOfFile() method\r
311 #\r
312 # Judge current buffer pos is at file end\r
313 #\r
314 # @param self The object pointer\r
315 # @retval True Current File buffer position is at file end\r
316 # @retval False Current File buffer position is NOT at file end\r
317 #\r
318 def __EndOfFile(self):\r
319 NumberOfLines = len(self.Profile.FileLinesList)\r
320 SizeOfLastLine = len(self.Profile.FileLinesList[-1])\r
321 if self.CurrentLineNumber == NumberOfLines and self.CurrentOffsetWithinLine >= SizeOfLastLine - 1:\r
322 return True\r
323 elif self.CurrentLineNumber > NumberOfLines:\r
324 return True\r
325 else:\r
326 return False\r
327\r
328 ## __EndOfLine() method\r
329 #\r
330 # Judge current buffer pos is at line end\r
331 #\r
332 # @param self The object pointer\r
333 # @retval True Current File buffer position is at line end\r
334 # @retval False Current File buffer position is NOT at line end\r
335 #\r
336 def __EndOfLine(self):\r
337 if self.CurrentLineNumber > len(self.Profile.FileLinesList):\r
338 return True\r
339 SizeOfCurrentLine = len(self.Profile.FileLinesList[self.CurrentLineNumber - 1])\r
340 if self.CurrentOffsetWithinLine >= SizeOfCurrentLine:\r
341 return True\r
342 else:\r
343 return False\r
344\r
345 ## Rewind() method\r
346 #\r
347 # Reset file data buffer to the initial state\r
348 #\r
349 # @param self The object pointer\r
118bf096
CS
350 # @param DestLine Optional new destination line number.\r
351 # @param DestOffset Optional new destination offset. \r
30fdf114 352 #\r
118bf096
CS
353 def Rewind(self, DestLine = 1, DestOffset = 0): \r
354 self.CurrentLineNumber = DestLine \r
355 self.CurrentOffsetWithinLine = DestOffset \r
30fdf114
LG
356\r
357 ## __UndoOneChar() method\r
358 #\r
359 # Go back one char in the file buffer\r
360 #\r
361 # @param self The object pointer\r
362 # @retval True Successfully go back one char\r
363 # @retval False Not able to go back one char as file beginning reached\r
364 #\r
365 def __UndoOneChar(self):\r
366\r
367 if self.CurrentLineNumber == 1 and self.CurrentOffsetWithinLine == 0:\r
368 return False\r
369 elif self.CurrentOffsetWithinLine == 0:\r
370 self.CurrentLineNumber -= 1\r
371 self.CurrentOffsetWithinLine = len(self.__CurrentLine()) - 1\r
372 else:\r
373 self.CurrentOffsetWithinLine -= 1\r
374 return True\r
375\r
376 ## __GetOneChar() method\r
377 #\r
378 # Move forward one char in the file buffer\r
379 #\r
380 # @param self The object pointer\r
381 #\r
382 def __GetOneChar(self):\r
383 if self.CurrentOffsetWithinLine == len(self.Profile.FileLinesList[self.CurrentLineNumber - 1]) - 1:\r
0d2711a6
LG
384 self.CurrentLineNumber += 1\r
385 self.CurrentOffsetWithinLine = 0\r
30fdf114 386 else:\r
0d2711a6 387 self.CurrentOffsetWithinLine += 1\r
30fdf114
LG
388\r
389 ## __CurrentChar() method\r
390 #\r
391 # Get the char pointed to by the file buffer pointer\r
392 #\r
393 # @param self The object pointer\r
394 # @retval Char Current char\r
395 #\r
396 def __CurrentChar(self):\r
397 return self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine]\r
398\r
399 ## __NextChar() method\r
400 #\r
401 # Get the one char pass the char pointed to by the file buffer pointer\r
402 #\r
403 # @param self The object pointer\r
404 # @retval Char Next char\r
405 #\r
406 def __NextChar(self):\r
407 if self.CurrentOffsetWithinLine == len(self.Profile.FileLinesList[self.CurrentLineNumber - 1]) - 1:\r
408 return self.Profile.FileLinesList[self.CurrentLineNumber][0]\r
409 else:\r
410 return self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine + 1]\r
411\r
412 ## __SetCurrentCharValue() method\r
413 #\r
414 # Modify the value of current char\r
415 #\r
416 # @param self The object pointer\r
417 # @param Value The new value of current char\r
418 #\r
419 def __SetCurrentCharValue(self, Value):\r
420 self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine] = Value\r
421\r
422 ## __CurrentLine() method\r
423 #\r
424 # Get the list that contains current line contents\r
425 #\r
426 # @param self The object pointer\r
427 # @retval List current line contents\r
428 #\r
429 def __CurrentLine(self):\r
430 return self.Profile.FileLinesList[self.CurrentLineNumber - 1]\r
431\r
432 def __StringToList(self):\r
433 self.Profile.FileLinesList = [list(s) for s in self.Profile.FileLinesList]\r
434 self.Profile.FileLinesList[-1].append(' ')\r
435\r
30fdf114
LG
436 def __ReplaceFragment(self, StartPos, EndPos, Value = ' '):\r
437 if StartPos[0] == EndPos[0]:\r
438 Offset = StartPos[1]\r
439 while Offset <= EndPos[1]:\r
440 self.Profile.FileLinesList[StartPos[0]][Offset] = Value\r
441 Offset += 1\r
442 return\r
443\r
444 Offset = StartPos[1]\r
445 while self.Profile.FileLinesList[StartPos[0]][Offset] not in ('\r', '\n'):\r
446 self.Profile.FileLinesList[StartPos[0]][Offset] = Value\r
447 Offset += 1\r
448\r
449 Line = StartPos[0]\r
450 while Line < EndPos[0]:\r
451 Offset = 0\r
452 while self.Profile.FileLinesList[Line][Offset] not in ('\r', '\n'):\r
453 self.Profile.FileLinesList[Line][Offset] = Value\r
454 Offset += 1\r
455 Line += 1\r
456\r
457 Offset = 0\r
458 while Offset <= EndPos[1]:\r
459 self.Profile.FileLinesList[EndPos[0]][Offset] = Value\r
460 Offset += 1\r
461\r
462\r
d5d56f1b
LG
463 def __GetMacroName(self):\r
464 if not self.__GetNextToken():\r
465 raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber)\r
466 MacroName = self.__Token\r
467 NotFlag = False\r
468 if MacroName.startswith('!'):\r
469 NotFlag = True\r
470 MacroName = MacroName[1:].strip()\r
471 \r
472 if not MacroName.startswith('$(') or not MacroName.endswith(')'):\r
473 raise Warning("Macro name expected(Please use '$(%(Token)s)' if '%(Token)s' is a macro.)" % {"Token" : MacroName},\r
474 self.FileName, self.CurrentLineNumber)\r
475 MacroName = MacroName[2:-1]\r
476 return MacroName, NotFlag\r
d0acc87a
LG
477\r
478 def __SetMacroValue(self, Macro, Value):\r
479 if not self.__CurSection:\r
480 return\r
481\r
482 MacroDict = {}\r
483 if not self.__MacroDict[self.__CurSection[0], self.__CurSection[1], self.__CurSection[2]]:\r
484 self.__MacroDict[self.__CurSection[0], self.__CurSection[1], self.__CurSection[2]] = MacroDict\r
485 else:\r
486 MacroDict = self.__MacroDict[self.__CurSection[0], self.__CurSection[1], self.__CurSection[2]]\r
487 MacroDict[Macro] = Value\r
488\r
489 def __GetMacroValue(self, Macro):\r
490 # Highest priority\r
491 if Macro in GlobalData.gCommandLineDefines:\r
492 return GlobalData.gCommandLineDefines[Macro]\r
493 if Macro in GlobalData.gGlobalDefines:\r
494 return GlobalData.gGlobalDefines[Macro]\r
495\r
496 if self.__CurSection:\r
497 MacroDict = self.__MacroDict[\r
498 self.__CurSection[0],\r
499 self.__CurSection[1],\r
500 self.__CurSection[2]\r
501 ]\r
502 if MacroDict and Macro in MacroDict:\r
503 return MacroDict[Macro]\r
504\r
505 # Lowest priority\r
506 if Macro in GlobalData.gPlatformDefines:\r
507 return GlobalData.gPlatformDefines[Macro]\r
508 return None\r
509\r
510 def __SectionHeaderParser(self, Section):\r
511 # [Defines]\r
512 # [FD.UiName]: use dummy instead if UI name is optional\r
513 # [FV.UiName]\r
514 # [Capsule.UiName]\r
515 # [Rule]: don't take rule section into account, macro is not allowed in this section\r
516 # [VTF.arch.UiName, arch]\r
517 # [OptionRom.DriverName]\r
518 self.__CurSection = []\r
519 Section = Section.strip()[1:-1].upper().replace(' ', '').strip('.')\r
520 ItemList = Section.split('.')\r
521 Item = ItemList[0]\r
522 if Item == '' or Item == 'RULE':\r
523 return\r
524\r
525 if Item == 'DEFINES':\r
526 self.__CurSection = ['COMMON', 'COMMON', 'COMMON']\r
527 elif Item == 'VTF' and len(ItemList) == 3:\r
528 UiName = ItemList[2]\r
529 Pos = UiName.find(',')\r
530 if Pos != -1:\r
531 UiName = UiName[:Pos]\r
532 self.__CurSection = ['VTF', UiName, ItemList[1]]\r
533 elif len(ItemList) > 1:\r
534 self.__CurSection = [ItemList[0], ItemList[1], 'COMMON']\r
535 elif len(ItemList) > 0:\r
536 self.__CurSection = [ItemList[0], 'DUMMY', 'COMMON']\r
537\r
30fdf114
LG
538 ## PreprocessFile() method\r
539 #\r
540 # Preprocess file contents, replace comments with spaces.\r
541 # In the end, rewind the file buffer pointer to the beginning\r
542 # BUGBUG: No !include statement processing contained in this procedure\r
543 # !include statement should be expanded at the same FileLinesList[CurrentLineNumber - 1]\r
544 #\r
545 # @param self The object pointer\r
546 #\r
547 def PreprocessFile(self):\r
548\r
549 self.Rewind()\r
550 InComment = False\r
551 DoubleSlashComment = False\r
552 HashComment = False\r
553 # HashComment in quoted string " " is ignored.\r
554 InString = False\r
555\r
556 while not self.__EndOfFile():\r
557\r
558 if self.__CurrentChar() == T_CHAR_DOUBLE_QUOTE and not InComment:\r
559 InString = not InString\r
560 # meet new line, then no longer in a comment for // and '#'\r
561 if self.__CurrentChar() == T_CHAR_LF:\r
562 self.CurrentLineNumber += 1\r
563 self.CurrentOffsetWithinLine = 0\r
564 if InComment and DoubleSlashComment:\r
565 InComment = False\r
566 DoubleSlashComment = False\r
567 if InComment and HashComment:\r
568 InComment = False\r
569 HashComment = False\r
570 # check for */ comment end\r
571 elif InComment and not DoubleSlashComment and not HashComment and self.__CurrentChar() == T_CHAR_STAR and self.__NextChar() == T_CHAR_SLASH:\r
572 self.__SetCurrentCharValue(T_CHAR_SPACE)\r
573 self.__GetOneChar()\r
574 self.__SetCurrentCharValue(T_CHAR_SPACE)\r
575 self.__GetOneChar()\r
576 InComment = False\r
577 # set comments to spaces\r
578 elif InComment:\r
579 self.__SetCurrentCharValue(T_CHAR_SPACE)\r
580 self.__GetOneChar()\r
581 # check for // comment\r
582 elif self.__CurrentChar() == T_CHAR_SLASH and self.__NextChar() == T_CHAR_SLASH and not self.__EndOfLine():\r
583 InComment = True\r
584 DoubleSlashComment = True\r
585 # check for '#' comment\r
586 elif self.__CurrentChar() == T_CHAR_HASH and not self.__EndOfLine() and not InString:\r
587 InComment = True\r
588 HashComment = True\r
589 # check for /* comment start\r
590 elif self.__CurrentChar() == T_CHAR_SLASH and self.__NextChar() == T_CHAR_STAR:\r
591 self.__SetCurrentCharValue( T_CHAR_SPACE)\r
592 self.__GetOneChar()\r
593 self.__SetCurrentCharValue( T_CHAR_SPACE)\r
594 self.__GetOneChar()\r
595 InComment = True\r
596 else:\r
597 self.__GetOneChar()\r
598\r
599 # restore from ListOfList to ListOfString\r
600 self.Profile.FileLinesList = ["".join(list) for list in self.Profile.FileLinesList]\r
601 self.Rewind()\r
602\r
603 ## PreprocessIncludeFile() method\r
604 #\r
605 # Preprocess file contents, replace !include statements with file contents.\r
606 # In the end, rewind the file buffer pointer to the beginning\r
607 #\r
608 # @param self The object pointer\r
609 #\r
610 def PreprocessIncludeFile(self):\r
118bf096
CS
611 # nested include support\r
612 Processed = False\r
0fdfe274 613 MacroDict = {}\r
30fdf114
LG
614 while self.__GetNextToken():\r
615\r
0fdfe274
YZ
616 if self.__Token == 'DEFINE':\r
617 if not self.__GetNextToken():\r
618 raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber)\r
619 Macro = self.__Token\r
620 if not self.__IsToken( "="):\r
621 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
622 Value = self.__GetExpression()\r
623 MacroDict[Macro] = Value\r
624\r
625 elif self.__Token == '!include':\r
118bf096 626 Processed = True\r
30fdf114
LG
627 IncludeLine = self.CurrentLineNumber\r
628 IncludeOffset = self.CurrentOffsetWithinLine - len('!include')\r
629 if not self.__GetNextToken():\r
630 raise Warning("expected include file name", self.FileName, self.CurrentLineNumber)\r
631 IncFileName = self.__Token\r
0fdfe274
YZ
632 PreIndex = 0\r
633 StartPos = IncFileName.find('$(', PreIndex)\r
634 EndPos = IncFileName.find(')', StartPos+2)\r
635 while StartPos != -1 and EndPos != -1:\r
636 Macro = IncFileName[StartPos+2 : EndPos]\r
d0acc87a 637 MacroVal = self.__GetMacroValue(Macro)\r
0fdfe274
YZ
638 if not MacroVal:\r
639 if Macro in MacroDict:\r
640 MacroVal = MacroDict[Macro]\r
641 if MacroVal != None:\r
642 IncFileName = IncFileName.replace('$(' + Macro + ')', MacroVal, 1)\r
643 if MacroVal.find('$(') != -1:\r
644 PreIndex = StartPos\r
645 else:\r
646 PreIndex = StartPos + len(MacroVal)\r
647 else:\r
648 raise Warning("The Macro %s is not defined" %Macro, self.FileName, self.CurrentLineNumber)\r
649 StartPos = IncFileName.find('$(', PreIndex)\r
650 EndPos = IncFileName.find(')', StartPos+2)\r
651\r
652 IncludedFile = NormPath(IncFileName)\r
2bcc713e
LG
653 #\r
654 # First search the include file under the same directory as FDF file\r
655 #\r
656 IncludedFile1 = PathClass(IncludedFile, os.path.dirname(self.FileName))\r
657 ErrorCode = IncludedFile1.Validate()[0]\r
658 if ErrorCode != 0:\r
659 #\r
660 # Then search the include file under the same directory as DSC file\r
661 #\r
d0acc87a
LG
662 PlatformDir = ''\r
663 if GenFdsGlobalVariable.ActivePlatform:\r
664 PlatformDir = GenFdsGlobalVariable.ActivePlatform.Dir\r
665 elif GlobalData.gActivePlatform:\r
666 PlatformDir = GlobalData.gActivePlatform.MetaFile.Dir\r
667 IncludedFile1 = PathClass(IncludedFile, PlatformDir)\r
2bcc713e
LG
668 ErrorCode = IncludedFile1.Validate()[0]\r
669 if ErrorCode != 0:\r
670 #\r
671 # Also search file under the WORKSPACE directory\r
672 #\r
673 IncludedFile1 = PathClass(IncludedFile, GlobalData.gWorkspace)\r
674 ErrorCode = IncludedFile1.Validate()[0]\r
675 if ErrorCode != 0:\r
d0acc87a 676 raise Warning("The include file does not exist under below directories: \n%s\n%s\n%s\n"%(os.path.dirname(self.FileName), PlatformDir, GlobalData.gWorkspace), \r
2bcc713e 677 self.FileName, self.CurrentLineNumber)\r
30fdf114 678\r
118bf096
CS
679 if not IsValidInclude (IncludedFile1.Path, self.CurrentLineNumber):\r
680 raise Warning("The include file {0} is causing a include loop.\n".format (IncludedFile1.Path), self.FileName, self.CurrentLineNumber)\r
681\r
2bcc713e 682 IncFileProfile = IncludeFileProfile(IncludedFile1.Path)\r
30fdf114
LG
683\r
684 CurrentLine = self.CurrentLineNumber\r
685 CurrentOffset = self.CurrentOffsetWithinLine\r
686 # list index of the insertion, note that line number is 'CurrentLine + 1'\r
687 InsertAtLine = CurrentLine\r
118bf096
CS
688 ParentProfile = GetParentAtLine (CurrentLine)\r
689 if ParentProfile != None:\r
690 ParentProfile.IncludeFileList.insert(0, IncFileProfile)\r
691 IncFileProfile.Level = ParentProfile.Level + 1\r
30fdf114
LG
692 IncFileProfile.InsertStartLineNumber = InsertAtLine + 1\r
693 # deal with remaining portions after "!include filename", if exists.\r
694 if self.__GetNextToken():\r
695 if self.CurrentLineNumber == CurrentLine:\r
696 RemainingLine = self.__CurrentLine()[CurrentOffset:]\r
697 self.Profile.FileLinesList.insert(self.CurrentLineNumber, RemainingLine)\r
698 IncFileProfile.InsertAdjust += 1\r
699 self.CurrentLineNumber += 1\r
700 self.CurrentOffsetWithinLine = 0\r
701\r
702 for Line in IncFileProfile.FileLinesList:\r
703 self.Profile.FileLinesList.insert(InsertAtLine, Line)\r
704 self.CurrentLineNumber += 1\r
705 InsertAtLine += 1\r
706\r
118bf096
CS
707 # reversely sorted to better determine error in file\r
708 AllIncludeFileList.insert(0, IncFileProfile)\r
30fdf114
LG
709\r
710 # comment out the processed include file statement\r
711 TempList = list(self.Profile.FileLinesList[IncludeLine - 1])\r
712 TempList.insert(IncludeOffset, '#')\r
713 self.Profile.FileLinesList[IncludeLine - 1] = ''.join(TempList)\r
118bf096
CS
714 if Processed: # Nested and back-to-back support\r
715 self.Rewind(DestLine = IncFileProfile.InsertStartLineNumber - 1)\r
716 Processed = False\r
717 # Preprocess done.\r
30fdf114 718 self.Rewind()\r
0d2711a6 719 \r
da92f276
LG
720 def __GetIfListCurrentItemStat(self, IfList):\r
721 if len(IfList) == 0:\r
722 return True\r
723 \r
724 for Item in IfList:\r
725 if Item[1] == False:\r
726 return False\r
727 \r
728 return True\r
0d2711a6 729 \r
6780eef1 730 ## PreprocessConditionalStatement() method\r
30fdf114 731 #\r
6780eef1 732 # Preprocess conditional statement.\r
30fdf114
LG
733 # In the end, rewind the file buffer pointer to the beginning\r
734 #\r
735 # @param self The object pointer\r
736 #\r
737 def PreprocessConditionalStatement(self):\r
738 # IfList is a stack of if branches with elements of list [Pos, CondSatisfied, BranchDetermined]\r
739 IfList = []\r
0d2711a6 740 RegionLayoutLine = 0\r
d0acc87a 741 ReplacedLine = -1\r
30fdf114 742 while self.__GetNextToken():\r
d0acc87a
LG
743 # Determine section name and the location dependent macro\r
744 if self.__GetIfListCurrentItemStat(IfList):\r
745 if self.__Token.startswith('['):\r
746 Header = self.__Token\r
747 if not self.__Token.endswith(']'):\r
748 self.__SkipToToken(']')\r
749 Header += self.__SkippedChars\r
750 if Header.find('$(') != -1:\r
751 raise Warning("macro cannot be used in section header", self.FileName, self.CurrentLineNumber)\r
752 self.__SectionHeaderParser(Header)\r
753 continue\r
754 # Replace macros except in RULE section or out of section\r
755 elif self.__CurSection and ReplacedLine != self.CurrentLineNumber:\r
756 ReplacedLine = self.CurrentLineNumber\r
757 self.__UndoToken()\r
758 CurLine = self.Profile.FileLinesList[ReplacedLine - 1]\r
759 PreIndex = 0\r
760 StartPos = CurLine.find('$(', PreIndex)\r
761 EndPos = CurLine.find(')', StartPos+2)\r
64b2609f 762 while StartPos != -1 and EndPos != -1 and self.__Token not in ['!ifdef', '!ifndef', '!if', '!elseif']:\r
d0acc87a
LG
763 MacroName = CurLine[StartPos+2 : EndPos]\r
764 MacorValue = self.__GetMacroValue(MacroName)\r
765 if MacorValue != None:\r
766 CurLine = CurLine.replace('$(' + MacroName + ')', MacorValue, 1)\r
767 if MacorValue.find('$(') != -1:\r
768 PreIndex = StartPos\r
769 else:\r
770 PreIndex = StartPos + len(MacorValue)\r
771 else:\r
772 PreIndex = EndPos + 1\r
773 StartPos = CurLine.find('$(', PreIndex)\r
774 EndPos = CurLine.find(')', StartPos+2)\r
775 self.Profile.FileLinesList[ReplacedLine - 1] = CurLine\r
776 continue\r
777\r
30fdf114 778 if self.__Token == 'DEFINE':\r
d0acc87a
LG
779 if self.__GetIfListCurrentItemStat(IfList):\r
780 if not self.__CurSection:\r
781 raise Warning("macro cannot be defined in Rule section or out of section", self.FileName, self.CurrentLineNumber)\r
da92f276
LG
782 DefineLine = self.CurrentLineNumber - 1\r
783 DefineOffset = self.CurrentOffsetWithinLine - len('DEFINE')\r
784 if not self.__GetNextToken():\r
785 raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber)\r
786 Macro = self.__Token\r
787 if not self.__IsToken( "="):\r
788 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
789 \r
d0acc87a
LG
790 Value = self.__GetExpression()\r
791 self.__SetMacroValue(Macro, Value)\r
da92f276 792 self.__WipeOffArea.append(((DefineLine, DefineOffset), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
0d2711a6 793 elif self.__Token == 'SET':\r
2f04e527
YL
794 if not self.__GetIfListCurrentItemStat(IfList):\r
795 continue\r
64b2609f
LG
796 SetLine = self.CurrentLineNumber - 1\r
797 SetOffset = self.CurrentOffsetWithinLine - len('SET')\r
0d2711a6
LG
798 PcdPair = self.__GetNextPcdName()\r
799 PcdName = "%s.%s" % (PcdPair[1], PcdPair[0])\r
800 if not self.__IsToken( "="):\r
801 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
802\r
d0acc87a
LG
803 Value = self.__GetExpression()\r
804 Value = self.__EvaluateConditional(Value, self.CurrentLineNumber, 'eval', True)\r
30fdf114 805\r
d0acc87a 806 self.__PcdDict[PcdName] = Value\r
64b2609f
LG
807\r
808 self.Profile.PcdDict[PcdPair] = Value\r
809 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
810 self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
811\r
812 self.__WipeOffArea.append(((SetLine, SetOffset), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
30fdf114
LG
813 elif self.__Token in ('!ifdef', '!ifndef', '!if'):\r
814 IfStartPos = (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len(self.__Token))\r
815 IfList.append([IfStartPos, None, None])\r
0d2711a6 816\r
30fdf114 817 CondLabel = self.__Token\r
0d2711a6 818 Expression = self.__GetExpression()\r
d5d56f1b 819 \r
30fdf114 820 if CondLabel == '!if':\r
0d2711a6 821 ConditionSatisfied = self.__EvaluateConditional(Expression, IfList[-1][0][0] + 1, 'eval')\r
30fdf114 822 else:\r
0d2711a6
LG
823 ConditionSatisfied = self.__EvaluateConditional(Expression, IfList[-1][0][0] + 1, 'in')\r
824 if CondLabel == '!ifndef':\r
30fdf114 825 ConditionSatisfied = not ConditionSatisfied\r
30fdf114 826\r
0d2711a6
LG
827 BranchDetermined = ConditionSatisfied\r
828 IfList[-1] = [IfList[-1][0], ConditionSatisfied, BranchDetermined]\r
829 if ConditionSatisfied:\r
830 self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1))) \r
30fdf114
LG
831 elif self.__Token in ('!elseif', '!else'):\r
832 ElseStartPos = (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len(self.__Token))\r
833 if len(IfList) <= 0:\r
834 raise Warning("Missing !if statement", self.FileName, self.CurrentLineNumber)\r
0d2711a6 835\r
30fdf114
LG
836 if IfList[-1][1]:\r
837 IfList[-1] = [ElseStartPos, False, True]\r
838 self.__WipeOffArea.append((ElseStartPos, (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
839 else:\r
840 self.__WipeOffArea.append((IfList[-1][0], ElseStartPos))\r
841 IfList[-1] = [ElseStartPos, True, IfList[-1][2]]\r
842 if self.__Token == '!elseif':\r
0d2711a6
LG
843 Expression = self.__GetExpression()\r
844 ConditionSatisfied = self.__EvaluateConditional(Expression, IfList[-1][0][0] + 1, 'eval')\r
30fdf114
LG
845 IfList[-1] = [IfList[-1][0], ConditionSatisfied, IfList[-1][2]]\r
846\r
847 if IfList[-1][1]:\r
848 if IfList[-1][2]:\r
849 IfList[-1][1] = False\r
850 else:\r
851 IfList[-1][2] = True\r
852 self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
30fdf114 853 elif self.__Token == '!endif':\r
d0acc87a
LG
854 if len(IfList) <= 0:\r
855 raise Warning("Missing !if statement", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
856 if IfList[-1][1]:\r
857 self.__WipeOffArea.append(((self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len('!endif')), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
858 else:\r
859 self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
860\r
861 IfList.pop()\r
0d2711a6
LG
862 elif not IfList: # Don't use PCDs inside conditional directive\r
863 if self.CurrentLineNumber <= RegionLayoutLine:\r
864 # Don't try the same line twice\r
865 continue\r
64b2609f
LG
866 SetPcd = ShortcutPcdPattern.match(self.Profile.FileLinesList[self.CurrentLineNumber - 1])\r
867 if SetPcd:\r
868 self.__PcdDict[SetPcd.group('name')] = SetPcd.group('value')\r
869 RegionLayoutLine = self.CurrentLineNumber\r
870 continue\r
0d2711a6
LG
871 RegionSize = RegionSizePattern.match(self.Profile.FileLinesList[self.CurrentLineNumber - 1])\r
872 if not RegionSize:\r
873 RegionLayoutLine = self.CurrentLineNumber\r
874 continue\r
875 RegionSizeGuid = RegionSizeGuidPattern.match(self.Profile.FileLinesList[self.CurrentLineNumber])\r
876 if not RegionSizeGuid:\r
877 RegionLayoutLine = self.CurrentLineNumber + 1\r
878 continue\r
d0acc87a
LG
879 self.__PcdDict[RegionSizeGuid.group('base')] = RegionSize.group('base')\r
880 self.__PcdDict[RegionSizeGuid.group('size')] = RegionSize.group('size')\r
0d2711a6
LG
881 RegionLayoutLine = self.CurrentLineNumber + 1\r
882\r
883 if IfList:\r
30fdf114
LG
884 raise Warning("Missing !endif", self.FileName, self.CurrentLineNumber)\r
885 self.Rewind()\r
886\r
d0acc87a
LG
887 def __CollectMacroPcd(self):\r
888 MacroDict = {}\r
889\r
890 # PCD macro\r
64b2609f 891 MacroDict.update(GlobalData.gPlatformPcds)\r
d0acc87a
LG
892 MacroDict.update(self.__PcdDict)\r
893\r
894 # Lowest priority\r
895 MacroDict.update(GlobalData.gPlatformDefines)\r
896\r
897 if self.__CurSection:\r
898 # Defines macro\r
899 ScopeMacro = self.__MacroDict['COMMON', 'COMMON', 'COMMON']\r
900 if ScopeMacro:\r
901 MacroDict.update(ScopeMacro)\r
902 \r
903 # Section macro\r
904 ScopeMacro = self.__MacroDict[\r
905 self.__CurSection[0],\r
906 self.__CurSection[1],\r
907 self.__CurSection[2]\r
908 ]\r
909 if ScopeMacro:\r
910 MacroDict.update(ScopeMacro)\r
911\r
912 MacroDict.update(GlobalData.gGlobalDefines)\r
913 MacroDict.update(GlobalData.gCommandLineDefines)\r
1fa7fdf6
FY
914 if GlobalData.BuildOptionPcd:\r
915 for Item in GlobalData.BuildOptionPcd:\r
705ed563
YZ
916 if type(Item) is tuple:\r
917 continue\r
1fa7fdf6 918 PcdName, TmpValue = Item.split("=")\r
8565b582 919 TmpValue = BuildOptionValue(TmpValue, {})\r
1fa7fdf6 920 MacroDict[PcdName.strip()] = TmpValue\r
d0acc87a
LG
921 # Highest priority\r
922\r
923 return MacroDict\r
924\r
0d2711a6 925 def __EvaluateConditional(self, Expression, Line, Op = None, Value = None):\r
30fdf114 926 FileLineTuple = GetRealFileLine(self.FileName, Line)\r
d0acc87a 927 MacroPcdDict = self.__CollectMacroPcd()\r
0d2711a6
LG
928 if Op == 'eval':\r
929 try:\r
d0acc87a
LG
930 if Value:\r
931 return ValueExpression(Expression, MacroPcdDict)(True)\r
932 else:\r
933 return ValueExpression(Expression, MacroPcdDict)()\r
0d2711a6
LG
934 except WrnExpression, Excpt:\r
935 # \r
936 # Catch expression evaluation warning here. We need to report\r
937 # the precise number of line and return the evaluation result\r
938 #\r
939 EdkLogger.warn('Parser', "Suspicious expression: %s" % str(Excpt),\r
940 File=self.FileName, ExtraData=self.__CurrentLine(), \r
941 Line=Line)\r
942 return Excpt.result\r
943 except Exception, Excpt:\r
64b2609f
LG
944 if hasattr(Excpt, 'Pcd'):\r
945 if Excpt.Pcd in GlobalData.gPlatformOtherPcds:\r
946 Info = GlobalData.gPlatformOtherPcds[Excpt.Pcd]\r
947 raise Warning("Cannot use this PCD (%s) in an expression as"\r
948 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"\r
949 " of the DSC file (%s), and it is currently defined in this section:"\r
950 " %s, line #: %d." % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE'], Info[0], Info[1]),\r
951 *FileLineTuple)\r
952 else:\r
953 raise Warning("PCD (%s) is not defined in DSC file (%s)" % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE']),\r
954 *FileLineTuple)\r
955 else:\r
956 raise Warning(str(Excpt), *FileLineTuple)\r
0d2711a6
LG
957 else:\r
958 if Expression.startswith('$(') and Expression[-1] == ')':\r
959 Expression = Expression[2:-1] \r
d0acc87a 960 return Expression in MacroPcdDict\r
30fdf114
LG
961\r
962 ## __IsToken() method\r
963 #\r
964 # Check whether input string is found from current char position along\r
965 # If found, the string value is put into self.__Token\r
966 #\r
967 # @param self The object pointer\r
968 # @param String The string to search\r
969 # @param IgnoreCase Indicate case sensitive/non-sensitive search, default is case sensitive\r
970 # @retval True Successfully find string, file buffer pointer moved forward\r
971 # @retval False Not able to find string, file buffer pointer not changed\r
972 #\r
973 def __IsToken(self, String, IgnoreCase = False):\r
974 self.__SkipWhiteSpace()\r
975\r
976 # Only consider the same line, no multi-line token allowed\r
977 StartPos = self.CurrentOffsetWithinLine\r
978 index = -1\r
979 if IgnoreCase:\r
980 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].upper().find(String.upper())\r
981 else:\r
982 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].find(String)\r
983 if index == 0:\r
984 self.CurrentOffsetWithinLine += len(String)\r
985 self.__Token = self.__CurrentLine()[StartPos : self.CurrentOffsetWithinLine]\r
986 return True\r
987 return False\r
988\r
989 ## __IsKeyword() method\r
990 #\r
991 # Check whether input keyword is found from current char position along, whole word only!\r
992 # If found, the string value is put into self.__Token\r
993 #\r
994 # @param self The object pointer\r
995 # @param Keyword The string to search\r
996 # @param IgnoreCase Indicate case sensitive/non-sensitive search, default is case sensitive\r
997 # @retval True Successfully find string, file buffer pointer moved forward\r
998 # @retval False Not able to find string, file buffer pointer not changed\r
999 #\r
1000 def __IsKeyword(self, KeyWord, IgnoreCase = False):\r
1001 self.__SkipWhiteSpace()\r
1002\r
1003 # Only consider the same line, no multi-line token allowed\r
1004 StartPos = self.CurrentOffsetWithinLine\r
1005 index = -1\r
1006 if IgnoreCase:\r
1007 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].upper().find(KeyWord.upper())\r
1008 else:\r
1009 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].find(KeyWord)\r
1010 if index == 0:\r
1011 followingChar = self.__CurrentLine()[self.CurrentOffsetWithinLine + len(KeyWord)]\r
1012 if not str(followingChar).isspace() and followingChar not in SEPERATOR_TUPLE:\r
1013 return False\r
1014 self.CurrentOffsetWithinLine += len(KeyWord)\r
1015 self.__Token = self.__CurrentLine()[StartPos : self.CurrentOffsetWithinLine]\r
1016 return True\r
1017 return False\r
1018\r
0d2711a6
LG
1019 def __GetExpression(self):\r
1020 Line = self.Profile.FileLinesList[self.CurrentLineNumber - 1]\r
1021 Index = len(Line) - 1\r
1022 while Line[Index] in ['\r', '\n']:\r
1023 Index -= 1\r
1024 ExpressionString = self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine:Index+1]\r
1025 self.CurrentOffsetWithinLine += len(ExpressionString)\r
1026 ExpressionString = ExpressionString.strip()\r
1027 return ExpressionString\r
1028\r
30fdf114
LG
1029 ## __GetNextWord() method\r
1030 #\r
1031 # Get next C name from file lines\r
1032 # If found, the string value is put into self.__Token\r
1033 #\r
1034 # @param self The object pointer\r
1035 # @retval True Successfully find a C name string, file buffer pointer moved forward\r
1036 # @retval False Not able to find a C name string, file buffer pointer not changed\r
1037 #\r
1038 def __GetNextWord(self):\r
1039 self.__SkipWhiteSpace()\r
1040 if self.__EndOfFile():\r
1041 return False\r
1042\r
1043 TempChar = self.__CurrentChar()\r
1044 StartPos = self.CurrentOffsetWithinLine\r
1045 if (TempChar >= 'a' and TempChar <= 'z') or (TempChar >= 'A' and TempChar <= 'Z') or TempChar == '_':\r
1046 self.__GetOneChar()\r
1047 while not self.__EndOfLine():\r
1048 TempChar = self.__CurrentChar()\r
1049 if (TempChar >= 'a' and TempChar <= 'z') or (TempChar >= 'A' and TempChar <= 'Z') \\r
1050 or (TempChar >= '0' and TempChar <= '9') or TempChar == '_' or TempChar == '-':\r
1051 self.__GetOneChar()\r
1052\r
1053 else:\r
1054 break\r
1055\r
1056 self.__Token = self.__CurrentLine()[StartPos : self.CurrentOffsetWithinLine]\r
1057 return True\r
1058\r
1059 return False\r
1060\r
1061 ## __GetNextToken() method\r
1062 #\r
1063 # Get next token unit before a seperator\r
1064 # If found, the string value is put into self.__Token\r
1065 #\r
1066 # @param self The object pointer\r
1067 # @retval True Successfully find a token unit, file buffer pointer moved forward\r
1068 # @retval False Not able to find a token unit, file buffer pointer not changed\r
1069 #\r
1070 def __GetNextToken(self):\r
1071 # Skip leading spaces, if exist.\r
1072 self.__SkipWhiteSpace()\r
1073 if self.__EndOfFile():\r
1074 return False\r
1075 # Record the token start position, the position of the first non-space char.\r
1076 StartPos = self.CurrentOffsetWithinLine\r
1077 StartLine = self.CurrentLineNumber\r
d0acc87a 1078 while StartLine == self.CurrentLineNumber:\r
30fdf114
LG
1079 TempChar = self.__CurrentChar()\r
1080 # Try to find the end char that is not a space and not in seperator tuple.\r
1081 # That is, when we got a space or any char in the tuple, we got the end of token.\r
1082 if not str(TempChar).isspace() and TempChar not in SEPERATOR_TUPLE:\r
1083 self.__GetOneChar()\r
1084 # if we happen to meet a seperator as the first char, we must proceed to get it.\r
1085 # That is, we get a token that is a seperator char. nomally it is the boundary of other tokens.\r
1086 elif StartPos == self.CurrentOffsetWithinLine and TempChar in SEPERATOR_TUPLE:\r
1087 self.__GetOneChar()\r
1088 break\r
1089 else:\r
1090 break\r
1091# else:\r
1092# return False\r
1093\r
1094 EndPos = self.CurrentOffsetWithinLine\r
1095 if self.CurrentLineNumber != StartLine:\r
1096 EndPos = len(self.Profile.FileLinesList[StartLine-1])\r
1097 self.__Token = self.Profile.FileLinesList[StartLine-1][StartPos : EndPos]\r
1098 if StartPos != self.CurrentOffsetWithinLine:\r
1099 return True\r
1100 else:\r
1101 return False\r
1102\r
1103 def __GetNextOp(self):\r
1104 # Skip leading spaces, if exist.\r
1105 self.__SkipWhiteSpace()\r
1106 if self.__EndOfFile():\r
1107 return False\r
1108 # Record the token start position, the position of the first non-space char.\r
1109 StartPos = self.CurrentOffsetWithinLine\r
1110 while not self.__EndOfLine():\r
1111 TempChar = self.__CurrentChar()\r
1112 # Try to find the end char that is not a space\r
1113 if not str(TempChar).isspace():\r
1114 self.__GetOneChar()\r
1115 else:\r
1116 break\r
1117 else:\r
1118 return False\r
1119\r
1120 if StartPos != self.CurrentOffsetWithinLine:\r
1121 self.__Token = self.__CurrentLine()[StartPos : self.CurrentOffsetWithinLine]\r
1122 return True\r
1123 else:\r
1124 return False\r
1125 ## __GetNextGuid() method\r
1126 #\r
1127 # Get next token unit before a seperator\r
1128 # If found, the GUID string is put into self.__Token\r
1129 #\r
1130 # @param self The object pointer\r
1131 # @retval True Successfully find a registry format GUID, file buffer pointer moved forward\r
1132 # @retval False Not able to find a registry format GUID, file buffer pointer not changed\r
1133 #\r
1134 def __GetNextGuid(self):\r
1135\r
1136 if not self.__GetNextToken():\r
1137 return False\r
2eb370ff 1138 if RangeExpression.RegGuidPattern.match(self.__Token) != None:\r
30fdf114
LG
1139 return True\r
1140 else:\r
1141 self.__UndoToken()\r
1142 return False\r
1143\r
91ae2988
YZ
1144 def __Verify(self, Name, Value, Scope):\r
1145 if Scope in ['UINT64', 'UINT8']:\r
1146 ValueNumber = 0\r
1147 try:\r
1148 if Value.upper().startswith('0X'):\r
1149 ValueNumber = int (Value, 16)\r
1150 else:\r
1151 ValueNumber = int (Value)\r
1152 except:\r
1153 EdkLogger.error("FdfParser", FORMAT_INVALID, "The value is not valid dec or hex number for %s." % Name)\r
1154 if ValueNumber < 0:\r
1155 EdkLogger.error("FdfParser", FORMAT_INVALID, "The value can't be set to negative value for %s." % Name)\r
1156 if Scope == 'UINT64':\r
1157 if ValueNumber >= 0x10000000000000000:\r
1158 EdkLogger.error("FdfParser", FORMAT_INVALID, "Too large value for %s." % Name)\r
1159 if Scope == 'UINT8':\r
1160 if ValueNumber >= 0x100:\r
1161 EdkLogger.error("FdfParser", FORMAT_INVALID, "Too large value for %s." % Name)\r
1162 return True\r
1163\r
30fdf114
LG
1164 ## __UndoToken() method\r
1165 #\r
1166 # Go back one token unit in file buffer\r
1167 #\r
1168 # @param self The object pointer\r
1169 #\r
1170 def __UndoToken(self):\r
1171 self.__UndoOneChar()\r
1172 while self.__CurrentChar().isspace():\r
1173 if not self.__UndoOneChar():\r
1174 self.__GetOneChar()\r
1175 return\r
1176\r
1177\r
1178 StartPos = self.CurrentOffsetWithinLine\r
1179 CurrentLine = self.CurrentLineNumber\r
1180 while CurrentLine == self.CurrentLineNumber:\r
1181\r
1182 TempChar = self.__CurrentChar()\r
1183 # Try to find the end char that is not a space and not in seperator tuple.\r
1184 # That is, when we got a space or any char in the tuple, we got the end of token.\r
1185 if not str(TempChar).isspace() and not TempChar in SEPERATOR_TUPLE:\r
1186 if not self.__UndoOneChar():\r
d0acc87a 1187 return\r
30fdf114
LG
1188 # if we happen to meet a seperator as the first char, we must proceed to get it.\r
1189 # That is, we get a token that is a seperator char. nomally it is the boundary of other tokens.\r
1190 elif StartPos == self.CurrentOffsetWithinLine and TempChar in SEPERATOR_TUPLE:\r
1191 return\r
1192 else:\r
1193 break\r
1194\r
1195 self.__GetOneChar()\r
1196\r
1197 ## __HexDigit() method\r
1198 #\r
1199 # Whether char input is a Hex data bit\r
1200 #\r
1201 # @param self The object pointer\r
1202 # @param TempChar The char to test\r
1203 # @retval True The char is a Hex data bit\r
1204 # @retval False The char is NOT a Hex data bit\r
1205 #\r
1206 def __HexDigit(self, TempChar):\r
1207 if (TempChar >= 'a' and TempChar <= 'f') or (TempChar >= 'A' and TempChar <= 'F') \\r
1208 or (TempChar >= '0' and TempChar <= '9'):\r
1209 return True\r
1210 else:\r
1211 return False\r
1212\r
1213 def __IsHex(self, HexStr):\r
1214 if not HexStr.upper().startswith("0X"):\r
1215 return False\r
1216 if len(self.__Token) <= 2:\r
1217 return False\r
1218 charList = [c for c in HexStr[2 : ] if not self.__HexDigit( c)]\r
1219 if len(charList) == 0:\r
1220 return True\r
1221 else:\r
1222 return False\r
1223 ## __GetNextHexNumber() method\r
1224 #\r
1225 # Get next HEX data before a seperator\r
1226 # If found, the HEX data is put into self.__Token\r
1227 #\r
1228 # @param self The object pointer\r
1229 # @retval True Successfully find a HEX data, file buffer pointer moved forward\r
1230 # @retval False Not able to find a HEX data, file buffer pointer not changed\r
1231 #\r
1232 def __GetNextHexNumber(self):\r
1233 if not self.__GetNextToken():\r
1234 return False\r
1235 if self.__IsHex(self.__Token):\r
1236 return True\r
1237 else:\r
1238 self.__UndoToken()\r
1239 return False\r
1240\r
1241 ## __GetNextDecimalNumber() method\r
1242 #\r
1243 # Get next decimal data before a seperator\r
1244 # If found, the decimal data is put into self.__Token\r
1245 #\r
1246 # @param self The object pointer\r
1247 # @retval True Successfully find a decimal data, file buffer pointer moved forward\r
1248 # @retval False Not able to find a decimal data, file buffer pointer not changed\r
1249 #\r
1250 def __GetNextDecimalNumber(self):\r
1251 if not self.__GetNextToken():\r
1252 return False\r
1253 if self.__Token.isdigit():\r
1254 return True\r
1255 else:\r
1256 self.__UndoToken()\r
1257 return False\r
1258\r
1259 ## __GetNextPcdName() method\r
1260 #\r
1261 # Get next PCD token space C name and PCD C name pair before a seperator\r
1262 # If found, the decimal data is put into self.__Token\r
1263 #\r
1264 # @param self The object pointer\r
1265 # @retval Tuple PCD C name and PCD token space C name pair\r
1266 #\r
1267 def __GetNextPcdName(self):\r
1268 if not self.__GetNextWord():\r
1269 raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
1270 pcdTokenSpaceCName = self.__Token\r
1271\r
1272 if not self.__IsToken( "."):\r
1273 raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
1274\r
1275 if not self.__GetNextWord():\r
1276 raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
1277 pcdCName = self.__Token\r
1278\r
1279 return (pcdCName, pcdTokenSpaceCName)\r
1280\r
1281 ## __GetStringData() method\r
1282 #\r
1283 # Get string contents quoted in ""\r
1284 # If found, the decimal data is put into self.__Token\r
1285 #\r
1286 # @param self The object pointer\r
1287 # @retval True Successfully find a string data, file buffer pointer moved forward\r
1288 # @retval False Not able to find a string data, file buffer pointer not changed\r
1289 #\r
1290 def __GetStringData(self):\r
1291 if self.__Token.startswith("\"") or self.__Token.startswith("L\""):\r
1292 self.__UndoToken()\r
1293 self.__SkipToToken("\"")\r
1294 currentLineNumber = self.CurrentLineNumber\r
1295\r
1296 if not self.__SkipToToken("\""):\r
1297 raise Warning("Missing Quote \" for String", self.FileName, self.CurrentLineNumber)\r
1298 if currentLineNumber != self.CurrentLineNumber:\r
1299 raise Warning("Missing Quote \" for String", self.FileName, self.CurrentLineNumber)\r
1300 self.__Token = self.__SkippedChars.rstrip('\"')\r
1301 return True\r
1302\r
1303 elif self.__Token.startswith("\'") or self.__Token.startswith("L\'"):\r
1304 self.__UndoToken()\r
1305 self.__SkipToToken("\'")\r
1306 currentLineNumber = self.CurrentLineNumber\r
1307\r
1308 if not self.__SkipToToken("\'"):\r
1309 raise Warning("Missing Quote \' for String", self.FileName, self.CurrentLineNumber)\r
1310 if currentLineNumber != self.CurrentLineNumber:\r
1311 raise Warning("Missing Quote \' for String", self.FileName, self.CurrentLineNumber)\r
1312 self.__Token = self.__SkippedChars.rstrip('\'')\r
1313 return True\r
1314\r
1315 else:\r
1316 return False\r
1317\r
1318 ## __SkipToToken() method\r
1319 #\r
1320 # Search forward in file buffer for the string\r
1321 # The skipped chars are put into self.__SkippedChars\r
1322 #\r
1323 # @param self The object pointer\r
1324 # @param String The string to search\r
1325 # @param IgnoreCase Indicate case sensitive/non-sensitive search, default is case sensitive\r
1326 # @retval True Successfully find the string, file buffer pointer moved forward\r
1327 # @retval False Not able to find the string, file buffer pointer not changed\r
1328 #\r
1329 def __SkipToToken(self, String, IgnoreCase = False):\r
1330 StartPos = self.GetFileBufferPos()\r
1331\r
1332 self.__SkippedChars = ""\r
1333 while not self.__EndOfFile():\r
1334 index = -1\r
1335 if IgnoreCase:\r
1336 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].upper().find(String.upper())\r
1337 else:\r
1338 index = self.__CurrentLine()[self.CurrentOffsetWithinLine : ].find(String)\r
1339 if index == 0:\r
1340 self.CurrentOffsetWithinLine += len(String)\r
1341 self.__SkippedChars += String\r
1342 return True\r
1343 self.__SkippedChars += str(self.__CurrentChar())\r
1344 self.__GetOneChar()\r
1345\r
1346 self.SetFileBufferPos( StartPos)\r
1347 self.__SkippedChars = ""\r
1348 return False\r
1349\r
1350 ## GetFileBufferPos() method\r
1351 #\r
1352 # Return the tuple of current line and offset within the line\r
1353 #\r
1354 # @param self The object pointer\r
1355 # @retval Tuple Line number and offset pair\r
1356 #\r
1357 def GetFileBufferPos(self):\r
1358 return (self.CurrentLineNumber, self.CurrentOffsetWithinLine)\r
1359\r
1360 ## SetFileBufferPos() method\r
1361 #\r
1362 # Restore the file buffer position\r
1363 #\r
1364 # @param self The object pointer\r
1365 # @param Pos The new file buffer position\r
1366 #\r
1367 def SetFileBufferPos(self, Pos):\r
1368 (self.CurrentLineNumber, self.CurrentOffsetWithinLine) = Pos\r
1369\r
d40b2ee6
LG
1370 ## Preprocess() method\r
1371 #\r
1372 # Preprocess comment, conditional directive, include directive, replace macro.\r
1373 # Exception will be raised if syntax error found\r
1374 #\r
1375 # @param self The object pointer\r
1376 #\r
1377 def Preprocess(self):\r
1378 self.__StringToList()\r
1379 self.PreprocessFile()\r
1380 self.PreprocessIncludeFile()\r
1381 self.__StringToList()\r
1382 self.PreprocessFile()\r
1383 self.PreprocessConditionalStatement()\r
1384 self.__StringToList()\r
1385 for Pos in self.__WipeOffArea:\r
1386 self.__ReplaceFragment(Pos[0], Pos[1])\r
1387 self.Profile.FileLinesList = ["".join(list) for list in self.Profile.FileLinesList]\r
1388\r
1389 while self.__GetDefines():\r
1390 pass\r
d40b2ee6 1391\r
30fdf114
LG
1392 ## ParseFile() method\r
1393 #\r
1394 # Parse the file profile buffer to extract fd, fv ... information\r
1395 # Exception will be raised if syntax error found\r
1396 #\r
1397 # @param self The object pointer\r
1398 #\r
1399 def ParseFile(self):\r
1400\r
1401 try:\r
d40b2ee6 1402 self.Preprocess()\r
dd170333
MK
1403 #\r
1404 # Keep processing sections of the FDF until no new sections or a syntax error is found\r
1405 #\r
1406 while self.__GetFd() or self.__GetFv() or self.__GetFmp() or self.__GetCapsule() or self.__GetVtf() or self.__GetRule() or self.__GetOptionRom():\r
30fdf114
LG
1407 pass\r
1408\r
1409 except Warning, X:\r
1410 self.__UndoToken()\r
30fdf114 1411 #'\n\tGot Token: \"%s\" from File %s\n' % (self.__Token, FileLineTuple[0]) + \\r
118bf096
CS
1412 # At this point, the closest parent would be the included file itself\r
1413 Profile = GetParentAtLine(X.OriginalLineNumber)\r
1414 if Profile != None:\r
1415 X.Message += ' near line %d, column %d: %s' \\r
1416 % (X.LineNumber, 0, Profile.FileLinesList[X.LineNumber-1])\r
1417 else:\r
1418 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1419 X.Message += ' near line %d, column %d: %s' \\r
30fdf114
LG
1420 % (FileLineTuple[1], self.CurrentOffsetWithinLine + 1, self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :].rstrip('\n').rstrip('\r'))\r
1421 raise\r
1422\r
df81077f
YZ
1423 ## SectionParser() method\r
1424 #\r
1425 # Parse the file section info\r
1426 # Exception will be raised if syntax error found\r
1427 #\r
1428 # @param self The object pointer\r
1429 # @param section The section string\r
1430\r
1431 def SectionParser(self, section):\r
1432 S = section.upper()\r
1433 if not S.startswith("[DEFINES") and not S.startswith("[FD.") and not S.startswith("[FV.") and not S.startswith("[CAPSULE.") \\r
1434 and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM.") and not S.startswith('[FMPPAYLOAD.'):\r
1435 raise Warning("Unknown section or section appear sequence error (The correct sequence should be [DEFINES], [FD.], [FV.], [Capsule.], [VTF.], [Rule.], [OptionRom.], [FMPPAYLOAD.])", self.FileName, self.CurrentLineNumber)\r
1436\r
30fdf114
LG
1437 ## __GetDefines() method\r
1438 #\r
1439 # Get Defines section contents and store its data into AllMacrosList\r
1440 #\r
1441 # @param self The object pointer\r
1442 # @retval True Successfully find a Defines\r
1443 # @retval False Not able to find a Defines\r
1444 #\r
1445 def __GetDefines(self):\r
1446\r
1447 if not self.__GetNextToken():\r
1448 return False\r
1449\r
1450 S = self.__Token.upper()\r
1451 if S.startswith("[") and not S.startswith("[DEFINES"):\r
df81077f 1452 self.SectionParser(S)\r
30fdf114
LG
1453 self.__UndoToken()\r
1454 return False\r
1455\r
1456 self.__UndoToken()\r
1457 if not self.__IsToken("[DEFINES", True):\r
1458 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1459 #print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \\r
1460 # % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)\r
1461 raise Warning("expected [DEFINES", self.FileName, self.CurrentLineNumber)\r
1462\r
1463 if not self.__IsToken( "]"):\r
1464 raise Warning("expected ']'", self.FileName, self.CurrentLineNumber)\r
1465\r
1466 while self.__GetNextWord():\r
6780eef1
LG
1467 # handle the SET statement\r
1468 if self.__Token == 'SET':\r
1469 self.__UndoToken()\r
1470 self.__GetSetStatement(None)\r
1471 continue\r
1472 \r
30fdf114
LG
1473 Macro = self.__Token\r
1474 \r
1475 if not self.__IsToken("="):\r
1476 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1477 if not self.__GetNextToken() or self.__Token.startswith('['):\r
1478 raise Warning("expected MACRO value", self.FileName, self.CurrentLineNumber)\r
1479 Value = self.__Token\r
30fdf114
LG
1480\r
1481 return False\r
1482\r
1483 ## __GetFd() method\r
1484 #\r
1485 # Get FD section contents and store its data into FD dictionary of self.Profile\r
1486 #\r
1487 # @param self The object pointer\r
1488 # @retval True Successfully find a FD\r
1489 # @retval False Not able to find a FD\r
1490 #\r
1491 def __GetFd(self):\r
1492\r
1493 if not self.__GetNextToken():\r
1494 return False\r
1495\r
1496 S = self.__Token.upper()\r
1497 if S.startswith("[") and not S.startswith("[FD."):\r
a3251d84 1498 if not S.startswith("[FV.") and not S.startswith('[FMPPAYLOAD.') and not S.startswith("[CAPSULE.") \\r
30fdf114
LG
1499 and not S.startswith("[VTF.") and not S.startswith("[RULE.") and not S.startswith("[OPTIONROM."):\r
1500 raise Warning("Unknown section", self.FileName, self.CurrentLineNumber)\r
1501 self.__UndoToken()\r
1502 return False\r
1503\r
1504 self.__UndoToken()\r
1505 if not self.__IsToken("[FD.", True):\r
1506 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1507 #print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \\r
1508 # % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)\r
1509 raise Warning("expected [FD.]", self.FileName, self.CurrentLineNumber)\r
1510\r
1511 FdName = self.__GetUiName()\r
52302d4d
LG
1512 if FdName == "":\r
1513 if len (self.Profile.FdDict) == 0:\r
1514 FdName = GenFdsGlobalVariable.PlatformName\r
d0acc87a
LG
1515 if FdName == "" and GlobalData.gActivePlatform:\r
1516 FdName = GlobalData.gActivePlatform.PlatformName\r
52302d4d
LG
1517 self.Profile.FdNameNotSet = True\r
1518 else:\r
1519 raise Warning("expected FdName in [FD.] section", self.FileName, self.CurrentLineNumber)\r
30fdf114 1520 self.CurrentFdName = FdName.upper()\r
52302d4d
LG
1521 \r
1522 if self.CurrentFdName in self.Profile.FdDict:\r
1523 raise Warning("Unexpected the same FD name", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
1524\r
1525 if not self.__IsToken( "]"):\r
1526 raise Warning("expected ']'", self.FileName, self.CurrentLineNumber)\r
1527\r
1528 FdObj = Fd.FD()\r
1529 FdObj.FdUiName = self.CurrentFdName\r
1530 self.Profile.FdDict[self.CurrentFdName] = FdObj\r
52302d4d
LG
1531\r
1532 if len (self.Profile.FdDict) > 1 and self.Profile.FdNameNotSet:\r
1533 raise Warning("expected all FDs have their name", self.FileName, self.CurrentLineNumber)\r
1534\r
30fdf114
LG
1535 Status = self.__GetCreateFile(FdObj)\r
1536 if not Status:\r
1537 raise Warning("FD name error", self.FileName, self.CurrentLineNumber)\r
1538\r
e8a47801
LG
1539 while self.__GetTokenStatements(FdObj):\r
1540 pass\r
1541 for Attr in ("BaseAddress", "Size", "ErasePolarity"):\r
1542 if getattr(FdObj, Attr) == None:\r
1543 self.__GetNextToken()\r
1544 raise Warning("Keyword %s missing" % Attr, self.FileName, self.CurrentLineNumber)\r
1545\r
1546 if not FdObj.BlockSizeList:\r
1547 FdObj.BlockSizeList.append((1, FdObj.Size, None))\r
30fdf114
LG
1548\r
1549 self.__GetDefineStatements(FdObj)\r
1550\r
1551 self.__GetSetStatements(FdObj)\r
1552\r
1553 if not self.__GetRegionLayout(FdObj):\r
1554 raise Warning("expected region layout", self.FileName, self.CurrentLineNumber)\r
1555\r
1556 while self.__GetRegionLayout(FdObj):\r
1557 pass\r
1558 return True\r
1559\r
1560 ## __GetUiName() method\r
1561 #\r
1562 # Return the UI name of a section\r
1563 #\r
1564 # @param self The object pointer\r
1565 # @retval FdName UI name\r
1566 #\r
1567 def __GetUiName(self):\r
1568 Name = ""\r
1569 if self.__GetNextWord():\r
1570 Name = self.__Token\r
1571\r
1572 return Name\r
1573\r
1574 ## __GetCreateFile() method\r
1575 #\r
1576 # Return the output file name of object\r
1577 #\r
1578 # @param self The object pointer\r
1579 # @param Obj object whose data will be stored in file\r
1580 # @retval FdName UI name\r
1581 #\r
1582 def __GetCreateFile(self, Obj):\r
1583\r
1584 if self.__IsKeyword( "CREATE_FILE"):\r
1585 if not self.__IsToken( "="):\r
1586 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1587\r
1588 if not self.__GetNextToken():\r
1589 raise Warning("expected file name", self.FileName, self.CurrentLineNumber)\r
1590\r
1591 FileName = self.__Token\r
1592 Obj.CreateFileName = FileName\r
1593\r
1594 return True\r
1595\r
1596 ## __GetTokenStatements() method\r
1597 #\r
1598 # Get token statements\r
1599 #\r
1600 # @param self The object pointer\r
1601 # @param Obj for whom token statement is got\r
30fdf114
LG
1602 #\r
1603 def __GetTokenStatements(self, Obj):\r
e8a47801
LG
1604 if self.__IsKeyword( "BaseAddress"):\r
1605 if not self.__IsToken( "="):\r
1606 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1607 \r
1608 if not self.__GetNextHexNumber():\r
1609 raise Warning("expected Hex base address", self.FileName, self.CurrentLineNumber)\r
1610 \r
1611 Obj.BaseAddress = self.__Token\r
1612 \r
1613 if self.__IsToken( "|"):\r
1614 pcdPair = self.__GetNextPcdName()\r
1615 Obj.BaseAddressPcd = pcdPair\r
1616 self.Profile.PcdDict[pcdPair] = Obj.BaseAddress\r
1617 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1618 self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple\r
1619 return True\r
30fdf114 1620\r
e8a47801
LG
1621 if self.__IsKeyword( "Size"):\r
1622 if not self.__IsToken( "="):\r
1623 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1624 \r
1625 if not self.__GetNextHexNumber():\r
1626 raise Warning("expected Hex size", self.FileName, self.CurrentLineNumber)\r
30fdf114 1627\r
e8a47801
LG
1628 Size = self.__Token\r
1629 if self.__IsToken( "|"):\r
1630 pcdPair = self.__GetNextPcdName()\r
1631 Obj.SizePcd = pcdPair\r
1632 self.Profile.PcdDict[pcdPair] = Size\r
1633 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1634 self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple\r
1635 Obj.Size = long(Size, 0)\r
1636 return True\r
30fdf114 1637\r
e8a47801
LG
1638 if self.__IsKeyword( "ErasePolarity"):\r
1639 if not self.__IsToken( "="):\r
1640 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1641 \r
1642 if not self.__GetNextToken():\r
1643 raise Warning("expected Erase Polarity", self.FileName, self.CurrentLineNumber)\r
1644 \r
1645 if self.__Token != "1" and self.__Token != "0":\r
1646 raise Warning("expected 1 or 0 Erase Polarity", self.FileName, self.CurrentLineNumber)\r
1647 \r
1648 Obj.ErasePolarity = self.__Token\r
1649 return True\r
30fdf114 1650\r
e8a47801 1651 return self.__GetBlockStatements(Obj)\r
30fdf114
LG
1652\r
1653 ## __GetAddressStatements() method\r
1654 #\r
1655 # Get address statements\r
1656 #\r
1657 # @param self The object pointer\r
1658 # @param Obj for whom address statement is got\r
1659 # @retval True Successfully find\r
1660 # @retval False Not able to find\r
1661 #\r
1662 def __GetAddressStatements(self, Obj):\r
1663\r
1664 if self.__IsKeyword("BsBaseAddress"):\r
1665 if not self.__IsToken( "="):\r
1666 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1667\r
1668 if not self.__GetNextDecimalNumber() and not self.__GetNextHexNumber():\r
1669 raise Warning("expected address", self.FileName, self.CurrentLineNumber)\r
1670\r
1671 BsAddress = long(self.__Token, 0)\r
1672 Obj.BsBaseAddress = BsAddress\r
1673\r
1674 if self.__IsKeyword("RtBaseAddress"):\r
1675 if not self.__IsToken( "="):\r
1676 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1677\r
1678 if not self.__GetNextDecimalNumber() and not self.__GetNextHexNumber():\r
1679 raise Warning("expected address", self.FileName, self.CurrentLineNumber)\r
1680\r
1681 RtAddress = long(self.__Token, 0)\r
1682 Obj.RtBaseAddress = RtAddress\r
1683\r
1684 ## __GetBlockStatements() method\r
1685 #\r
1686 # Get block statements\r
1687 #\r
1688 # @param self The object pointer\r
1689 # @param Obj for whom block statement is got\r
30fdf114
LG
1690 #\r
1691 def __GetBlockStatements(self, Obj):\r
e8a47801 1692 IsBlock = False\r
30fdf114 1693 while self.__GetBlockStatement(Obj):\r
e8a47801 1694 IsBlock = True\r
52302d4d 1695 \r
e8a47801 1696 Item = Obj.BlockSizeList[-1]\r
52302d4d 1697 if Item[0] == None or Item[1] == None:\r
6780eef1 1698 raise Warning("expected block statement", self.FileName, self.CurrentLineNumber)\r
e8a47801 1699 return IsBlock\r
30fdf114
LG
1700\r
1701 ## __GetBlockStatement() method\r
1702 #\r
1703 # Get block statement\r
1704 #\r
1705 # @param self The object pointer\r
1706 # @param Obj for whom block statement is got\r
1707 # @retval True Successfully find\r
1708 # @retval False Not able to find\r
1709 #\r
1710 def __GetBlockStatement(self, Obj):\r
1711 if not self.__IsKeyword( "BlockSize"):\r
1712 return False\r
1713\r
1714 if not self.__IsToken( "="):\r
1715 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1716\r
1717 if not self.__GetNextHexNumber() and not self.__GetNextDecimalNumber():\r
6780eef1 1718 raise Warning("expected Hex or Integer block size", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
1719\r
1720 BlockSize = self.__Token\r
1721 BlockSizePcd = None\r
1722 if self.__IsToken( "|"):\r
1723 PcdPair = self.__GetNextPcdName()\r
1724 BlockSizePcd = PcdPair\r
1725 self.Profile.PcdDict[PcdPair] = BlockSize\r
d0acc87a
LG
1726 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1727 self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
52302d4d 1728 BlockSize = long(BlockSize, 0)\r
30fdf114
LG
1729\r
1730 BlockNumber = None\r
1731 if self.__IsKeyword( "NumBlocks"):\r
1732 if not self.__IsToken( "="):\r
1733 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1734\r
1735 if not self.__GetNextDecimalNumber() and not self.__GetNextHexNumber():\r
1736 raise Warning("expected block numbers", self.FileName, self.CurrentLineNumber)\r
1737\r
1738 BlockNumber = long(self.__Token, 0)\r
1739\r
1740 Obj.BlockSizeList.append((BlockSize, BlockNumber, BlockSizePcd))\r
1741 return True\r
1742\r
1743 ## __GetDefineStatements() method\r
1744 #\r
1745 # Get define statements\r
1746 #\r
1747 # @param self The object pointer\r
1748 # @param Obj for whom define statement is got\r
1749 # @retval True Successfully find\r
1750 # @retval False Not able to find\r
1751 #\r
1752 def __GetDefineStatements(self, Obj):\r
1753 while self.__GetDefineStatement( Obj):\r
1754 pass\r
1755\r
1756 ## __GetDefineStatement() method\r
1757 #\r
1758 # Get define statement\r
1759 #\r
1760 # @param self The object pointer\r
1761 # @param Obj for whom define statement is got\r
1762 # @retval True Successfully find\r
1763 # @retval False Not able to find\r
1764 #\r
1765 def __GetDefineStatement(self, Obj):\r
1766 if self.__IsKeyword("DEFINE"):\r
1767 self.__GetNextToken()\r
1768 Macro = self.__Token\r
1769 if not self.__IsToken( "="):\r
1770 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1771\r
1772 if not self.__GetNextToken():\r
1773 raise Warning("expected value", self.FileName, self.CurrentLineNumber)\r
1774\r
1775 Value = self.__Token\r
1776 Macro = '$(' + Macro + ')'\r
1777 Obj.DefineVarDict[Macro] = Value\r
1778 return True\r
1779\r
1780 return False\r
1781\r
1782 ## __GetSetStatements() method\r
1783 #\r
1784 # Get set statements\r
1785 #\r
1786 # @param self The object pointer\r
1787 # @param Obj for whom set statement is got\r
1788 # @retval True Successfully find\r
1789 # @retval False Not able to find\r
1790 #\r
1791 def __GetSetStatements(self, Obj):\r
1792 while self.__GetSetStatement(Obj):\r
1793 pass\r
1794\r
1795 ## __GetSetStatement() method\r
1796 #\r
1797 # Get set statement\r
1798 #\r
1799 # @param self The object pointer\r
1800 # @param Obj for whom set statement is got\r
1801 # @retval True Successfully find\r
1802 # @retval False Not able to find\r
1803 #\r
1804 def __GetSetStatement(self, Obj):\r
1805 if self.__IsKeyword("SET"):\r
1806 PcdPair = self.__GetNextPcdName()\r
1807\r
1808 if not self.__IsToken( "="):\r
1809 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1810\r
d0acc87a
LG
1811 Value = self.__GetExpression()\r
1812 Value = self.__EvaluateConditional(Value, self.CurrentLineNumber, 'eval', True)\r
30fdf114 1813\r
6780eef1
LG
1814 if Obj:\r
1815 Obj.SetVarDict[PcdPair] = Value\r
30fdf114 1816 self.Profile.PcdDict[PcdPair] = Value\r
d0acc87a
LG
1817 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1818 self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
30fdf114
LG
1819 return True\r
1820\r
1821 return False\r
1822\r
4afd3d04
LG
1823 ## __CalcRegionExpr(self)\r
1824 #\r
1825 # Calculate expression for offset or size of a region\r
1826 #\r
1827 # @return: None if invalid expression\r
1828 # Calculated number if successfully\r
1829 #\r
1830 def __CalcRegionExpr(self):\r
1831 StartPos = self.GetFileBufferPos()\r
1832 Expr = ''\r
1833 PairCount = 0\r
1834 while not self.__EndOfFile():\r
1835 CurCh = self.__CurrentChar()\r
1836 if CurCh == '(':\r
1837 PairCount += 1\r
1838 elif CurCh == ')':\r
1839 PairCount -= 1\r
1840\r
1841 if CurCh in '|\r\n' and PairCount == 0:\r
1842 break\r
1843 Expr += CurCh\r
1844 self.__GetOneChar()\r
1845 try:\r
1846 return long(\r
1847 ValueExpression(Expr,\r
2bc3256c 1848 self.__CollectMacroPcd()\r
4afd3d04
LG
1849 )(True),0)\r
1850 except Exception:\r
1851 self.SetFileBufferPos(StartPos)\r
1852 return None\r
1853\r
30fdf114
LG
1854 ## __GetRegionLayout() method\r
1855 #\r
1856 # Get region layout for FD\r
1857 #\r
1858 # @param self The object pointer\r
1859 # @param Fd for whom region is got\r
1860 # @retval True Successfully find\r
1861 # @retval False Not able to find\r
1862 #\r
1863 def __GetRegionLayout(self, Fd):\r
4afd3d04
LG
1864 Offset = self.__CalcRegionExpr() \r
1865 if Offset == None:\r
30fdf114
LG
1866 return False\r
1867\r
1868 RegionObj = Region.Region()\r
4afd3d04 1869 RegionObj.Offset = Offset\r
30fdf114
LG
1870 Fd.RegionList.append(RegionObj)\r
1871\r
1872 if not self.__IsToken( "|"):\r
1873 raise Warning("expected '|'", self.FileName, self.CurrentLineNumber)\r
1874\r
4afd3d04
LG
1875 Size = self.__CalcRegionExpr()\r
1876 if Size == None:\r
30fdf114 1877 raise Warning("expected Region Size", self.FileName, self.CurrentLineNumber)\r
4afd3d04 1878 RegionObj.Size = Size\r
30fdf114
LG
1879\r
1880 if not self.__GetNextWord():\r
1881 return True\r
1882\r
b21a13fb 1883 if not self.__Token in ("SET", "FV", "FILE", "DATA", "CAPSULE", "INF"):\r
2bc3256c
LG
1884 #\r
1885 # If next token is a word which is not a valid FV type, it might be part of [PcdOffset[|PcdSize]]\r
1886 # Or it might be next region's offset described by an expression which starts with a PCD.\r
1887 # PcdOffset[|PcdSize] or OffsetPcdExpression|Size\r
1888 #\r
30fdf114 1889 self.__UndoToken()\r
2bc3256c
LG
1890 IsRegionPcd = (RegionSizeGuidPattern.match(self.__CurrentLine()[self.CurrentOffsetWithinLine:]) or\r
1891 RegionOffsetPcdPattern.match(self.__CurrentLine()[self.CurrentOffsetWithinLine:]))\r
1892 if IsRegionPcd:\r
1893 RegionObj.PcdOffset = self.__GetNextPcdName()\r
1894 self.Profile.PcdDict[RegionObj.PcdOffset] = "0x%08X" % (RegionObj.Offset + long(Fd.BaseAddress, 0))\r
1895 self.__PcdDict['%s.%s' % (RegionObj.PcdOffset[1], RegionObj.PcdOffset[0])] = "0x%x" % RegionObj.Offset\r
d0acc87a 1896 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
2bc3256c
LG
1897 self.Profile.PcdFileLineDict[RegionObj.PcdOffset] = FileLineTuple\r
1898 if self.__IsToken( "|"):\r
1899 RegionObj.PcdSize = self.__GetNextPcdName()\r
1900 self.Profile.PcdDict[RegionObj.PcdSize] = "0x%08X" % RegionObj.Size\r
1901 self.__PcdDict['%s.%s' % (RegionObj.PcdSize[1], RegionObj.PcdSize[0])] = "0x%x" % RegionObj.Size\r
1902 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
1903 self.Profile.PcdFileLineDict[RegionObj.PcdSize] = FileLineTuple\r
30fdf114
LG
1904\r
1905 if not self.__GetNextWord():\r
1906 return True\r
1907\r
1908 if self.__Token == "SET":\r
1909 self.__UndoToken()\r
1910 self.__GetSetStatements( RegionObj)\r
1911 if not self.__GetNextWord():\r
1912 return True\r
1913\r
fd171542 1914 elif self.__Token == "FV":\r
30fdf114
LG
1915 self.__UndoToken()\r
1916 self.__GetRegionFvType( RegionObj)\r
1917\r
fd171542 1918 elif self.__Token == "CAPSULE":\r
1919 self.__UndoToken()\r
1920 self.__GetRegionCapType( RegionObj)\r
1921\r
30fdf114
LG
1922 elif self.__Token == "FILE":\r
1923 self.__UndoToken()\r
b21a13fb
YZ
1924 self.__GetRegionFileType(RegionObj)\r
1925\r
1926 elif self.__Token == "INF":\r
1927 self.__UndoToken()\r
1928 RegionObj.RegionType = "INF"\r
1929 while self.__IsKeyword("INF"):\r
1930 self.__UndoToken()\r
1931 ffsInf = self.__ParseInfStatement()\r
1932 if not ffsInf:\r
1933 break\r
1934 RegionObj.RegionDataList.append(ffsInf)\r
30fdf114 1935\r
79b74a03 1936 elif self.__Token == "DATA":\r
30fdf114 1937 self.__UndoToken()\r
b21a13fb 1938 self.__GetRegionDataType(RegionObj)\r
79b74a03 1939 else:\r
2bc3256c
LG
1940 self.__UndoToken()\r
1941 if self.__GetRegionLayout(Fd):\r
1942 return True\r
79b74a03 1943 raise Warning("A valid region type was not found. "\r
b21a13fb 1944 "Valid types are [SET, FV, CAPSULE, FILE, DATA, INF]. This error occurred",\r
79b74a03 1945 self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
1946\r
1947 return True\r
1948\r
1949 ## __GetRegionFvType() method\r
1950 #\r
1951 # Get region fv data for region\r
1952 #\r
1953 # @param self The object pointer\r
1954 # @param RegionObj for whom region data is got\r
1955 #\r
1956 def __GetRegionFvType(self, RegionObj):\r
1957\r
1958 if not self.__IsKeyword( "FV"):\r
1959 raise Warning("expected Keyword 'FV'", self.FileName, self.CurrentLineNumber)\r
1960\r
1961 if not self.__IsToken( "="):\r
1962 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1963\r
1964 if not self.__GetNextToken():\r
1965 raise Warning("expected FV name", self.FileName, self.CurrentLineNumber)\r
1966\r
1967 RegionObj.RegionType = "FV"\r
0199377c 1968 RegionObj.RegionDataList.append((self.__Token).upper())\r
30fdf114
LG
1969\r
1970 while self.__IsKeyword( "FV"):\r
1971\r
1972 if not self.__IsToken( "="):\r
1973 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1974\r
1975 if not self.__GetNextToken():\r
1976 raise Warning("expected FV name", self.FileName, self.CurrentLineNumber)\r
1977\r
0199377c 1978 RegionObj.RegionDataList.append((self.__Token).upper())\r
30fdf114 1979\r
fd171542 1980 ## __GetRegionCapType() method\r
1981 #\r
1982 # Get region capsule data for region\r
1983 #\r
1984 # @param self The object pointer\r
1985 # @param RegionObj for whom region data is got\r
1986 #\r
1987 def __GetRegionCapType(self, RegionObj):\r
1988\r
1989 if not self.__IsKeyword("CAPSULE"):\r
1990 raise Warning("expected Keyword 'CAPSULE'", self.FileName, self.CurrentLineNumber)\r
1991\r
1992 if not self.__IsToken("="):\r
1993 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
1994\r
1995 if not self.__GetNextToken():\r
1996 raise Warning("expected CAPSULE name", self.FileName, self.CurrentLineNumber)\r
1997\r
1998 RegionObj.RegionType = "CAPSULE"\r
1999 RegionObj.RegionDataList.append(self.__Token)\r
2000\r
2001 while self.__IsKeyword("CAPSULE"):\r
2002\r
2003 if not self.__IsToken("="):\r
2004 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2005\r
2006 if not self.__GetNextToken():\r
2007 raise Warning("expected CAPSULE name", self.FileName, self.CurrentLineNumber)\r
2008\r
2009 RegionObj.RegionDataList.append(self.__Token)\r
2010\r
30fdf114
LG
2011 ## __GetRegionFileType() method\r
2012 #\r
2013 # Get region file data for region\r
2014 #\r
2015 # @param self The object pointer\r
2016 # @param RegionObj for whom region data is got\r
2017 #\r
2018 def __GetRegionFileType(self, RegionObj):\r
2019\r
2020 if not self.__IsKeyword( "FILE"):\r
2021 raise Warning("expected Keyword 'FILE'", self.FileName, self.CurrentLineNumber)\r
2022\r
2023 if not self.__IsToken( "="):\r
2024 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2025\r
2026 if not self.__GetNextToken():\r
2027 raise Warning("expected File name", self.FileName, self.CurrentLineNumber)\r
2028\r
2029 RegionObj.RegionType = "FILE"\r
2030 RegionObj.RegionDataList.append( self.__Token)\r
2031\r
2032 while self.__IsKeyword( "FILE"):\r
2033\r
2034 if not self.__IsToken( "="):\r
2035 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2036\r
2037 if not self.__GetNextToken():\r
2038 raise Warning("expected FILE name", self.FileName, self.CurrentLineNumber)\r
2039\r
2040 RegionObj.RegionDataList.append(self.__Token)\r
2041\r
2042 ## __GetRegionDataType() method\r
2043 #\r
2044 # Get region array data for region\r
2045 #\r
2046 # @param self The object pointer\r
2047 # @param RegionObj for whom region data is got\r
2048 #\r
2049 def __GetRegionDataType(self, RegionObj):\r
2050\r
2051 if not self.__IsKeyword( "DATA"):\r
2052 raise Warning("expected Region Data type", self.FileName, self.CurrentLineNumber)\r
2053\r
2054 if not self.__IsToken( "="):\r
2055 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2056\r
2057 if not self.__IsToken( "{"):\r
2058 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2059\r
2060 if not self.__GetNextHexNumber():\r
2061 raise Warning("expected Hex byte", self.FileName, self.CurrentLineNumber)\r
2062\r
636f2be6
LG
2063 if len(self.__Token) > 18:\r
2064 raise Warning("Hex string can't be converted to a valid UINT64 value", self.FileName, self.CurrentLineNumber)\r
2065\r
2066 # convert hex string value to byte hex string array\r
2067 AllString = self.__Token\r
2068 AllStrLen = len (AllString)\r
2069 DataString = ""\r
2070 while AllStrLen > 4:\r
2071 DataString = DataString + "0x" + AllString[AllStrLen - 2: AllStrLen] + ","\r
2072 AllStrLen = AllStrLen - 2\r
2073 DataString = DataString + AllString[:AllStrLen] + ","\r
2074\r
2075 # byte value array\r
2076 if len (self.__Token) <= 4:\r
2077 while self.__IsToken(","):\r
2078 if not self.__GetNextHexNumber():\r
2079 raise Warning("Invalid Hex number", self.FileName, self.CurrentLineNumber)\r
2080 if len(self.__Token) > 4:\r
2081 raise Warning("Hex byte(must be 2 digits) too long", self.FileName, self.CurrentLineNumber)\r
2082 DataString += self.__Token\r
2083 DataString += ","\r
30fdf114
LG
2084\r
2085 if not self.__IsToken( "}"):\r
2086 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2087\r
2088 DataString = DataString.rstrip(",")\r
2089 RegionObj.RegionType = "DATA"\r
2090 RegionObj.RegionDataList.append( DataString)\r
2091\r
2092 while self.__IsKeyword( "DATA"):\r
2093\r
2094 if not self.__IsToken( "="):\r
2095 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2096\r
2097 if not self.__IsToken( "{"):\r
2098 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2099\r
2100 if not self.__GetNextHexNumber():\r
2101 raise Warning("expected Hex byte", self.FileName, self.CurrentLineNumber)\r
2102\r
636f2be6
LG
2103 if len(self.__Token) > 18:\r
2104 raise Warning("Hex string can't be converted to a valid UINT64 value", self.FileName, self.CurrentLineNumber)\r
2105\r
2106 # convert hex string value to byte hex string array\r
2107 AllString = self.__Token\r
2108 AllStrLen = len (AllString)\r
2109 DataString = ""\r
2110 while AllStrLen > 4:\r
2111 DataString = DataString + "0x" + AllString[AllStrLen - 2: AllStrLen] + ","\r
2112 AllStrLen = AllStrLen - 2\r
2113 DataString = DataString + AllString[:AllStrLen] + ","\r
2114\r
2115 # byte value array\r
2116 if len (self.__Token) <= 4:\r
2117 while self.__IsToken(","):\r
2118 if not self.__GetNextHexNumber():\r
2119 raise Warning("Invalid Hex number", self.FileName, self.CurrentLineNumber)\r
2120 if len(self.__Token) > 4:\r
2121 raise Warning("Hex byte(must be 2 digits) too long", self.FileName, self.CurrentLineNumber)\r
2122 DataString += self.__Token\r
2123 DataString += ","\r
30fdf114
LG
2124\r
2125 if not self.__IsToken( "}"):\r
2126 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2127\r
2128 DataString = DataString.rstrip(",")\r
2129 RegionObj.RegionDataList.append( DataString)\r
2130\r
2131 ## __GetFv() method\r
2132 #\r
2133 # Get FV section contents and store its data into FV dictionary of self.Profile\r
2134 #\r
2135 # @param self The object pointer\r
2136 # @retval True Successfully find a FV\r
2137 # @retval False Not able to find a FV\r
2138 #\r
2139 def __GetFv(self):\r
2140 if not self.__GetNextToken():\r
2141 return False\r
2142\r
2143 S = self.__Token.upper()\r
2144 if S.startswith("[") and not S.startswith("[FV."):\r
df81077f 2145 self.SectionParser(S)\r
30fdf114
LG
2146 self.__UndoToken()\r
2147 return False\r
2148\r
2149 self.__UndoToken()\r
2150 if not self.__IsToken("[FV.", True):\r
2151 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
2152 #print 'Parsing String: %s in File %s, At line: %d, Offset Within Line: %d' \\r
2153 # % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :], FileLineTuple[0], FileLineTuple[1], self.CurrentOffsetWithinLine)\r
2154 raise Warning("Unknown Keyword '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
2155\r
2156 FvName = self.__GetUiName()\r
2157 self.CurrentFvName = FvName.upper()\r
2158\r
2159 if not self.__IsToken( "]"):\r
2160 raise Warning("expected ']'", self.FileName, self.CurrentLineNumber)\r
2161\r
2162 FvObj = Fv.FV()\r
2163 FvObj.UiFvName = self.CurrentFvName\r
2164 self.Profile.FvDict[self.CurrentFvName] = FvObj\r
2165\r
2166 Status = self.__GetCreateFile(FvObj)\r
2167 if not Status:\r
2168 raise Warning("FV name error", self.FileName, self.CurrentLineNumber)\r
2169\r
2170 self.__GetDefineStatements(FvObj)\r
2171\r
2172 self.__GetAddressStatements(FvObj)\r
2173\r
b303ea72
LG
2174 FvObj.FvExtEntryTypeValue = []\r
2175 FvObj.FvExtEntryType = []\r
2176 FvObj.FvExtEntryData = []\r
2177 while True:\r
e8a47801
LG
2178 self.__GetSetStatements(FvObj)\r
2179\r
2180 if not (self.__GetBlockStatement(FvObj) or self.__GetFvBaseAddress(FvObj) or \r
2181 self.__GetFvForceRebase(FvObj) or self.__GetFvAlignment(FvObj) or \r
2182 self.__GetFvAttributes(FvObj) or self.__GetFvNameGuid(FvObj) or \r
aaf8aa7b 2183 self.__GetFvExtEntryStatement(FvObj) or self.__GetFvNameString(FvObj)):\r
b303ea72
LG
2184 break\r
2185\r
aaf8aa7b
YL
2186 if FvObj.FvNameString == 'TRUE' and not FvObj.FvNameGuid:\r
2187 raise Warning("FvNameString found but FvNameGuid was not found", self.FileName, self.CurrentLineNumber)\r
2188\r
30fdf114
LG
2189 self.__GetAprioriSection(FvObj, FvObj.DefineVarDict.copy())\r
2190 self.__GetAprioriSection(FvObj, FvObj.DefineVarDict.copy())\r
2191\r
2192 while True:\r
2193 isInf = self.__GetInfStatement(FvObj, MacroDict = FvObj.DefineVarDict.copy())\r
2194 isFile = self.__GetFileStatement(FvObj, MacroDict = FvObj.DefineVarDict.copy())\r
2195 if not isInf and not isFile:\r
2196 break\r
2197\r
2198 return True\r
2199\r
2200 ## __GetFvAlignment() method\r
2201 #\r
2202 # Get alignment for FV\r
2203 #\r
2204 # @param self The object pointer\r
2205 # @param Obj for whom alignment is got\r
2206 # @retval True Successfully find a alignment statement\r
2207 # @retval False Not able to find a alignment statement\r
2208 #\r
2209 def __GetFvAlignment(self, Obj):\r
2210\r
2211 if not self.__IsKeyword( "FvAlignment"):\r
2212 return False\r
2213\r
2214 if not self.__IsToken( "="):\r
2215 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2216\r
2217 if not self.__GetNextToken():\r
2218 raise Warning("expected alignment value", self.FileName, self.CurrentLineNumber)\r
2219\r
2220 if self.__Token.upper() not in ("1", "2", "4", "8", "16", "32", "64", "128", "256", "512", \\r
2221 "1K", "2K", "4K", "8K", "16K", "32K", "64K", "128K", "256K", "512K", \\r
2222 "1M", "2M", "4M", "8M", "16M", "32M", "64M", "128M", "256M", "512M", \\r
2223 "1G", "2G"):\r
2224 raise Warning("Unknown alignment value '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
2225 Obj.FvAlignment = self.__Token\r
2226 return True\r
4234283c
LG
2227 \r
2228 ## __GetFvBaseAddress() method\r
2229 #\r
2230 # Get BaseAddress for FV\r
2231 #\r
2232 # @param self The object pointer\r
2233 # @param Obj for whom FvBaseAddress is got\r
2234 # @retval True Successfully find a FvBaseAddress statement\r
2235 # @retval False Not able to find a FvBaseAddress statement\r
2236 #\r
2237 def __GetFvBaseAddress(self, Obj):\r
2238\r
2239 if not self.__IsKeyword("FvBaseAddress"):\r
2240 return False\r
2241\r
2242 if not self.__IsToken( "="):\r
2243 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2244\r
2245 if not self.__GetNextToken():\r
2246 raise Warning("expected FV base address value", self.FileName, self.CurrentLineNumber)\r
2247\r
2248 IsValidBaseAddrValue = re.compile('^0[x|X][0-9a-fA-F]+')\r
2249\r
2250 if not IsValidBaseAddrValue.match(self.__Token.upper()):\r
79b74a03 2251 raise Warning("Unknown FV base address value '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
4234283c 2252 Obj.FvBaseAddress = self.__Token\r
0d2711a6
LG
2253 return True \r
2254 \r
79b74a03
LG
2255 ## __GetFvForceRebase() method\r
2256 #\r
2257 # Get FvForceRebase for FV\r
2258 #\r
2259 # @param self The object pointer\r
2260 # @param Obj for whom FvForceRebase is got\r
2261 # @retval True Successfully find a FvForceRebase statement\r
2262 # @retval False Not able to find a FvForceRebase statement\r
2263 #\r
2264 def __GetFvForceRebase(self, Obj):\r
2265\r
2266 if not self.__IsKeyword("FvForceRebase"):\r
2267 return False\r
2268\r
2269 if not self.__IsToken( "="):\r
2270 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2271\r
2272 if not self.__GetNextToken():\r
2273 raise Warning("expected FvForceRebase value", self.FileName, self.CurrentLineNumber)\r
30fdf114 2274\r
79b74a03
LG
2275 if self.__Token.upper() not in ["TRUE", "FALSE", "0", "0X0", "0X00", "1", "0X1", "0X01"]:\r
2276 raise Warning("Unknown FvForceRebase value '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
2277 \r
2278 if self.__Token.upper() in ["TRUE", "1", "0X1", "0X01"]:\r
2279 Obj.FvForceRebase = True\r
2280 elif self.__Token.upper() in ["FALSE", "0", "0X0", "0X00"]:\r
2281 Obj.FvForceRebase = False\r
2282 else:\r
2283 Obj.FvForceRebase = None\r
2284 \r
2285 return True\r
0d2711a6
LG
2286\r
2287\r
30fdf114
LG
2288 ## __GetFvAttributes() method\r
2289 #\r
2290 # Get attributes for FV\r
2291 #\r
2292 # @param self The object pointer\r
2293 # @param Obj for whom attribute is got\r
2294 # @retval None\r
2295 #\r
2296 def __GetFvAttributes(self, FvObj):\r
2bc3256c 2297 IsWordToken = False\r
30fdf114 2298 while self.__GetNextWord():\r
2bc3256c 2299 IsWordToken = True\r
30fdf114
LG
2300 name = self.__Token\r
2301 if name not in ("ERASE_POLARITY", "MEMORY_MAPPED", \\r
2302 "STICKY_WRITE", "LOCK_CAP", "LOCK_STATUS", "WRITE_ENABLED_CAP", \\r
2303 "WRITE_DISABLED_CAP", "WRITE_STATUS", "READ_ENABLED_CAP", \\r
2304 "READ_DISABLED_CAP", "READ_STATUS", "READ_LOCK_CAP", \\r
2305 "READ_LOCK_STATUS", "WRITE_LOCK_CAP", "WRITE_LOCK_STATUS", \\r
9425b349 2306 "WRITE_POLICY_RELIABLE", "WEAK_ALIGNMENT", "FvUsedSizeEnable"):\r
30fdf114 2307 self.__UndoToken()\r
e8a47801 2308 return False\r
30fdf114
LG
2309\r
2310 if not self.__IsToken( "="):\r
2311 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2312\r
2313 if not self.__GetNextToken() or self.__Token.upper() not in ("TRUE", "FALSE", "1", "0"):\r
2314 raise Warning("expected TRUE/FALSE (1/0)", self.FileName, self.CurrentLineNumber)\r
2315\r
2316 FvObj.FvAttributeDict[name] = self.__Token\r
2317\r
2bc3256c 2318 return IsWordToken\r
30fdf114
LG
2319 \r
2320 ## __GetFvNameGuid() method\r
2321 #\r
2322 # Get FV GUID for FV\r
2323 #\r
2324 # @param self The object pointer\r
2325 # @param Obj for whom GUID is got\r
2326 # @retval None\r
2327 #\r
2328 def __GetFvNameGuid(self, FvObj):\r
2329\r
2330 if not self.__IsKeyword( "FvNameGuid"):\r
e8a47801 2331 return False\r
30fdf114
LG
2332\r
2333 if not self.__IsToken( "="):\r
2334 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2335\r
2336 if not self.__GetNextGuid():\r
2337 raise Warning("expected FV GUID value", self.FileName, self.CurrentLineNumber)\r
2338\r
2339 FvObj.FvNameGuid = self.__Token\r
2340\r
e8a47801 2341 return True\r
30fdf114 2342\r
aaf8aa7b
YL
2343 def __GetFvNameString(self, FvObj):\r
2344\r
2345 if not self.__IsKeyword( "FvNameString"):\r
2346 return False\r
2347\r
2348 if not self.__IsToken( "="):\r
2349 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2350\r
2351 if not self.__GetNextToken() or self.__Token not in ('TRUE', 'FALSE'):\r
2352 raise Warning("expected TRUE or FALSE for FvNameString", self.FileName, self.CurrentLineNumber)\r
2353\r
2354 FvObj.FvNameString = self.__Token\r
2355\r
2356 return True\r
2357\r
b303ea72
LG
2358 def __GetFvExtEntryStatement(self, FvObj):\r
2359\r
92d07e48 2360 if not (self.__IsKeyword( "FV_EXT_ENTRY") or self.__IsKeyword( "FV_EXT_ENTRY_TYPE")):\r
b303ea72
LG
2361 return False\r
2362\r
2363 if not self.__IsKeyword ("TYPE"):\r
2364 raise Warning("expected 'TYPE'", self.FileName, self.CurrentLineNumber)\r
2365 \r
2366 if not self.__IsToken( "="):\r
2367 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2368\r
2369 if not self.__GetNextHexNumber() and not self.__GetNextDecimalNumber():\r
2370 raise Warning("expected Hex FV extension entry type value At Line ", self.FileName, self.CurrentLineNumber)\r
2371\r
2372 FvObj.FvExtEntryTypeValue += [self.__Token]\r
2373\r
2374 if not self.__IsToken( "{"):\r
2375 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2376\r
2377 if not self.__IsKeyword ("FILE") and not self.__IsKeyword ("DATA"):\r
2378 raise Warning("expected 'FILE' or 'DATA'", self.FileName, self.CurrentLineNumber)\r
2379\r
2380 FvObj.FvExtEntryType += [self.__Token]\r
2381\r
2382 if self.__Token == 'DATA':\r
2383\r
2384 if not self.__IsToken( "="):\r
2385 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2386 \r
2387 if not self.__IsToken( "{"):\r
2388 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2389\r
2390 if not self.__GetNextHexNumber():\r
2391 raise Warning("expected Hex byte", self.FileName, self.CurrentLineNumber)\r
2392\r
2393 if len(self.__Token) > 4:\r
2394 raise Warning("Hex byte(must be 2 digits) too long", self.FileName, self.CurrentLineNumber)\r
2395\r
2396 DataString = self.__Token\r
2397 DataString += ","\r
2398\r
2399 while self.__IsToken(","):\r
2400 if not self.__GetNextHexNumber():\r
2401 raise Warning("Invalid Hex number", self.FileName, self.CurrentLineNumber)\r
2402 if len(self.__Token) > 4:\r
2403 raise Warning("Hex byte(must be 2 digits) too long", self.FileName, self.CurrentLineNumber)\r
2404 DataString += self.__Token\r
2405 DataString += ","\r
2406\r
2407 if not self.__IsToken( "}"):\r
2408 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2409\r
2410 if not self.__IsToken( "}"):\r
2411 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2412\r
2413 DataString = DataString.rstrip(",")\r
2414 FvObj.FvExtEntryData += [DataString]\r
2415\r
2416 if self.__Token == 'FILE':\r
2417 \r
2418 if not self.__IsToken( "="):\r
2419 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2420 \r
2421 if not self.__GetNextToken():\r
2422 raise Warning("expected FV Extension Entry file path At Line ", self.FileName, self.CurrentLineNumber)\r
2423 \r
2424 FvObj.FvExtEntryData += [self.__Token]\r
2425\r
2426 if not self.__IsToken( "}"):\r
2427 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2428\r
2429 return True\r
2430\r
30fdf114
LG
2431 ## __GetAprioriSection() method\r
2432 #\r
2433 # Get token statements\r
2434 #\r
2435 # @param self The object pointer\r
2436 # @param FvObj for whom apriori is got\r
2437 # @param MacroDict dictionary used to replace macro\r
2438 # @retval True Successfully find apriori statement\r
2439 # @retval False Not able to find apriori statement\r
2440 #\r
2441 def __GetAprioriSection(self, FvObj, MacroDict = {}):\r
2442\r
2443 if not self.__IsKeyword( "APRIORI"):\r
2444 return False\r
2445\r
2446 if not self.__IsKeyword("PEI") and not self.__IsKeyword("DXE"):\r
2447 raise Warning("expected Apriori file type", self.FileName, self.CurrentLineNumber)\r
2448 AprType = self.__Token\r
2449\r
2450 if not self.__IsToken( "{"):\r
2451 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2452\r
2453 AprSectionObj = AprioriSection.AprioriSection()\r
2454 AprSectionObj.AprioriType = AprType\r
2455\r
2456 self.__GetDefineStatements(AprSectionObj)\r
2457 MacroDict.update(AprSectionObj.DefineVarDict)\r
2458\r
2459 while True:\r
2460 IsInf = self.__GetInfStatement( AprSectionObj, MacroDict = MacroDict)\r
2461 IsFile = self.__GetFileStatement( AprSectionObj)\r
2462 if not IsInf and not IsFile:\r
2463 break\r
2464\r
2465 if not self.__IsToken( "}"):\r
2466 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2467\r
2468 FvObj.AprioriSectionList.append(AprSectionObj)\r
2469 return True\r
2470\r
b21a13fb
YZ
2471 def __ParseInfStatement(self):\r
2472 if not self.__IsKeyword("INF"):\r
2473 return None\r
30fdf114
LG
2474\r
2475 ffsInf = FfsInfStatement.FfsInfStatement()\r
b21a13fb 2476 self.__GetInfOptions(ffsInf)\r
30fdf114
LG
2477\r
2478 if not self.__GetNextToken():\r
2479 raise Warning("expected INF file path", self.FileName, self.CurrentLineNumber)\r
2480 ffsInf.InfFileName = self.__Token\r
a87e79d9
YZ
2481 if not ffsInf.InfFileName.endswith('.inf'):\r
2482 raise Warning("expected .inf file path", self.FileName, self.CurrentLineNumber)\r
64b2609f
LG
2483\r
2484 ffsInf.CurrentLineNum = self.CurrentLineNumber\r
2485 ffsInf.CurrentLineContent = self.__CurrentLine()\r
2486\r
97fa0ee9
YL
2487 #Replace $(SAPCE) with real space\r
2488 ffsInf.InfFileName = ffsInf.InfFileName.replace('$(SPACE)', ' ')\r
2489\r
14c48571 2490 if ffsInf.InfFileName.replace('$(WORKSPACE)', '').find('$') == -1:\r
2491 #do case sensitive check for file path\r
2492 ErrorCode, ErrorInfo = PathClass(NormPath(ffsInf.InfFileName), GenFdsGlobalVariable.WorkSpaceDir).Validate()\r
2493 if ErrorCode != 0:\r
2494 EdkLogger.error("GenFds", ErrorCode, ExtraData=ErrorInfo)\r
30fdf114 2495\r
30fdf114
LG
2496 if not ffsInf.InfFileName in self.Profile.InfList:\r
2497 self.Profile.InfList.append(ffsInf.InfFileName)\r
d0acc87a
LG
2498 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
2499 self.Profile.InfFileLineList.append(FileLineTuple)\r
2502b735
YZ
2500 if ffsInf.UseArch:\r
2501 if ffsInf.UseArch not in self.Profile.InfDict:\r
2502 self.Profile.InfDict[ffsInf.UseArch] = [ffsInf.InfFileName]\r
2503 else:\r
2504 self.Profile.InfDict[ffsInf.UseArch].append(ffsInf.InfFileName)\r
2505 else:\r
2506 self.Profile.InfDict['ArchTBD'].append(ffsInf.InfFileName)\r
30fdf114
LG
2507\r
2508 if self.__IsToken('|'):\r
2509 if self.__IsKeyword('RELOCS_STRIPPED'):\r
2510 ffsInf.KeepReloc = False\r
2511 elif self.__IsKeyword('RELOCS_RETAINED'):\r
2512 ffsInf.KeepReloc = True\r
2513 else:\r
2514 raise Warning("Unknown reloc strip flag '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
b21a13fb
YZ
2515 return ffsInf\r
2516\r
2517 ## __GetInfStatement() method\r
2518 #\r
2519 # Get INF statements\r
2520 #\r
2521 # @param self The object pointer\r
2522 # @param Obj for whom inf statement is got\r
2523 # @param MacroDict dictionary used to replace macro\r
2524 # @retval True Successfully find inf statement\r
2525 # @retval False Not able to find inf statement\r
2526 #\r
2527 def __GetInfStatement(self, Obj, ForCapsule=False, MacroDict={}):\r
2528 ffsInf = self.__ParseInfStatement()\r
2529 if not ffsInf:\r
2530 return False\r
2531\r
30fdf114
LG
2532 if ForCapsule:\r
2533 capsuleFfs = CapsuleData.CapsuleFfs()\r
2534 capsuleFfs.Ffs = ffsInf\r
2535 Obj.CapsuleDataList.append(capsuleFfs)\r
2536 else:\r
2537 Obj.FfsList.append(ffsInf)\r
2538 return True\r
2539\r
2540 ## __GetInfOptions() method\r
2541 #\r
2542 # Get options for INF\r
2543 #\r
2544 # @param self The object pointer\r
2545 # @param FfsInfObj for whom option is got\r
2546 #\r
2547 def __GetInfOptions(self, FfsInfObj):\r
97fa0ee9
YL
2548 if self.__IsKeyword("FILE_GUID"):\r
2549 if not self.__IsToken("="):\r
2550 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2551 if not self.__GetNextGuid():\r
2552 raise Warning("expected GUID value", self.FileName, self.CurrentLineNumber)\r
2553 FfsInfObj.OverrideGuid = self.__Token\r
30fdf114
LG
2554\r
2555 if self.__IsKeyword( "RuleOverride"):\r
2556 if not self.__IsToken( "="):\r
2557 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2558 if not self.__GetNextToken():\r
2559 raise Warning("expected Rule name", self.FileName, self.CurrentLineNumber)\r
2560 FfsInfObj.Rule = self.__Token\r
2561\r
2562 if self.__IsKeyword( "VERSION"):\r
2563 if not self.__IsToken( "="):\r
2564 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2565 if not self.__GetNextToken():\r
2566 raise Warning("expected Version", self.FileName, self.CurrentLineNumber)\r
2567\r
2568 if self.__GetStringData():\r
2569 FfsInfObj.Version = self.__Token\r
2570\r
2571 if self.__IsKeyword( "UI"):\r
2572 if not self.__IsToken( "="):\r
2573 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2574 if not self.__GetNextToken():\r
2575 raise Warning("expected UI name", self.FileName, self.CurrentLineNumber)\r
2576\r
2577 if self.__GetStringData():\r
2578 FfsInfObj.Ui = self.__Token\r
2579\r
2580 if self.__IsKeyword( "USE"):\r
2581 if not self.__IsToken( "="):\r
2582 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2583 if not self.__GetNextToken():\r
2584 raise Warning("expected ARCH name", self.FileName, self.CurrentLineNumber)\r
2585 FfsInfObj.UseArch = self.__Token\r
2586\r
2587 \r
2588 if self.__GetNextToken():\r
97fa0ee9
YL
2589 p = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\))')\r
2590 if p.match(self.__Token) and p.match(self.__Token).span()[1] == len(self.__Token):\r
30fdf114
LG
2591 FfsInfObj.KeyStringList.append(self.__Token)\r
2592 if not self.__IsToken(","):\r
2593 return\r
2594 else:\r
2595 self.__UndoToken()\r
2596 return\r
2597\r
2598 while self.__GetNextToken():\r
2599 if not p.match(self.__Token):\r
2600 raise Warning("expected KeyString \"Target_Tag_Arch\"", self.FileName, self.CurrentLineNumber)\r
2601 FfsInfObj.KeyStringList.append(self.__Token)\r
2602\r
2603 if not self.__IsToken(","):\r
2604 break\r
2605\r
2606 ## __GetFileStatement() method\r
2607 #\r
2608 # Get FILE statements\r
2609 #\r
2610 # @param self The object pointer\r
2611 # @param Obj for whom FILE statement is got\r
2612 # @param MacroDict dictionary used to replace macro\r
2613 # @retval True Successfully find FILE statement\r
2614 # @retval False Not able to find FILE statement\r
2615 #\r
2616 def __GetFileStatement(self, Obj, ForCapsule = False, MacroDict = {}):\r
2617\r
2618 if not self.__IsKeyword( "FILE"):\r
2619 return False\r
2620\r
30fdf114
LG
2621 if not self.__GetNextWord():\r
2622 raise Warning("expected FFS type", self.FileName, self.CurrentLineNumber)\r
b36d134f
LG
2623\r
2624 if ForCapsule and self.__Token == 'DATA':\r
2625 self.__UndoToken()\r
2626 self.__UndoToken()\r
2627 return False\r
2628 \r
2629 FfsFileObj = FfsFileStatement.FileStatement()\r
30fdf114
LG
2630 FfsFileObj.FvFileType = self.__Token\r
2631\r
2632 if not self.__IsToken( "="):\r
2633 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2634\r
2635 if not self.__GetNextGuid():\r
2636 if not self.__GetNextWord():\r
2637 raise Warning("expected File GUID", self.FileName, self.CurrentLineNumber)\r
2638 if self.__Token == 'PCD':\r
2639 if not self.__IsToken( "("):\r
2640 raise Warning("expected '('", self.FileName, self.CurrentLineNumber)\r
2641 PcdPair = self.__GetNextPcdName()\r
2642 if not self.__IsToken( ")"):\r
2643 raise Warning("expected ')'", self.FileName, self.CurrentLineNumber)\r
2644 self.__Token = 'PCD('+PcdPair[1]+'.'+PcdPair[0]+')'\r
2645 \r
2646 FfsFileObj.NameGuid = self.__Token\r
79b74a03 2647 \r
30fdf114
LG
2648 self.__GetFilePart( FfsFileObj, MacroDict.copy())\r
2649\r
2650 if ForCapsule:\r
2651 capsuleFfs = CapsuleData.CapsuleFfs()\r
2652 capsuleFfs.Ffs = FfsFileObj\r
2653 Obj.CapsuleDataList.append(capsuleFfs)\r
2654 else:\r
2655 Obj.FfsList.append(FfsFileObj)\r
2656\r
2657 return True\r
2658\r
2659 ## __FileCouldHaveRelocFlag() method\r
2660 #\r
2661 # Check whether reloc strip flag can be set for a file type.\r
2662 #\r
2663 # @param self The object pointer\r
2664 # @param FileType The file type to check with\r
2665 # @retval True This type could have relocation strip flag\r
2666 # @retval False No way to have it\r
2667 #\r
2668\r
2669 def __FileCouldHaveRelocFlag (self, FileType):\r
2670 if FileType in ('SEC', 'PEI_CORE', 'PEIM', 'PEI_DXE_COMBO'):\r
2671 return True\r
2672 else:\r
2673 return False\r
2674\r
2675 ## __SectionCouldHaveRelocFlag() method\r
2676 #\r
2677 # Check whether reloc strip flag can be set for a section type.\r
2678 #\r
2679 # @param self The object pointer\r
2680 # @param SectionType The section type to check with\r
2681 # @retval True This type could have relocation strip flag\r
2682 # @retval False No way to have it\r
2683 #\r
2684\r
2685 def __SectionCouldHaveRelocFlag (self, SectionType):\r
2686 if SectionType in ('TE', 'PE32'):\r
2687 return True\r
2688 else:\r
2689 return False\r
2690\r
2691 ## __GetFilePart() method\r
2692 #\r
2693 # Get components for FILE statement\r
2694 #\r
2695 # @param self The object pointer\r
2696 # @param FfsFileObj for whom component is got\r
2697 # @param MacroDict dictionary used to replace macro\r
2698 #\r
2699 def __GetFilePart(self, FfsFileObj, MacroDict = {}):\r
2700\r
2701 self.__GetFileOpts( FfsFileObj)\r
2702\r
2703 if not self.__IsToken("{"):\r
4afd3d04
LG
2704 if self.__IsKeyword('RELOCS_STRIPPED') or self.__IsKeyword('RELOCS_RETAINED'):\r
2705 if self.__FileCouldHaveRelocFlag(FfsFileObj.FvFileType):\r
2706 if self.__Token == 'RELOCS_STRIPPED':\r
2707 FfsFileObj.KeepReloc = False\r
2708 else:\r
2709 FfsFileObj.KeepReloc = True\r
2710 else:\r
2711 raise Warning("File type %s could not have reloc strip flag%d" % (FfsFileObj.FvFileType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)\r
2712\r
2713 if not self.__IsToken("{"):\r
30fdf114
LG
2714 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2715\r
2716 if not self.__GetNextToken():\r
2717 raise Warning("expected File name or section data", self.FileName, self.CurrentLineNumber)\r
2718\r
2719 if self.__Token == "FV":\r
2720 if not self.__IsToken( "="):\r
2721 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2722 if not self.__GetNextToken():\r
2723 raise Warning("expected FV name", self.FileName, self.CurrentLineNumber)\r
2724 FfsFileObj.FvName = self.__Token\r
2725\r
2726 elif self.__Token == "FD":\r
2727 if not self.__IsToken( "="):\r
2728 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2729 if not self.__GetNextToken():\r
2730 raise Warning("expected FD name", self.FileName, self.CurrentLineNumber)\r
2731 FfsFileObj.FdName = self.__Token\r
2732\r
2733 elif self.__Token in ("DEFINE", "APRIORI", "SECTION"):\r
2734 self.__UndoToken()\r
2735 self.__GetSectionData( FfsFileObj, MacroDict)\r
860992ed
YZ
2736\r
2737 elif hasattr(FfsFileObj, 'FvFileType') and FfsFileObj.FvFileType == 'RAW':\r
2738 self.__UndoToken()\r
2739 self.__GetRAWData(FfsFileObj, MacroDict)\r
2740\r
30fdf114 2741 else:\r
64b2609f
LG
2742 FfsFileObj.CurrentLineNum = self.CurrentLineNumber\r
2743 FfsFileObj.CurrentLineContent = self.__CurrentLine()\r
97fa0ee9 2744 FfsFileObj.FileName = self.__Token.replace('$(SPACE)', ' ')\r
2bc3256c 2745 self.__VerifyFile(FfsFileObj.FileName)\r
0d2711a6 2746\r
30fdf114
LG
2747 if not self.__IsToken( "}"):\r
2748 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2749\r
860992ed
YZ
2750 ## __GetRAWData() method\r
2751 #\r
2752 # Get RAW data for FILE statement\r
2753 #\r
2754 # @param self The object pointer\r
2755 # @param FfsFileObj for whom section is got\r
2756 # @param MacroDict dictionary used to replace macro\r
2757 #\r
2758 def __GetRAWData(self, FfsFileObj, MacroDict = {}):\r
2759 FfsFileObj.FileName = []\r
cfaaf99b 2760 FfsFileObj.SubAlignment = []\r
860992ed
YZ
2761 while True:\r
2762 AlignValue = None\r
2763 if self.__GetAlignment():\r
e921f58d
YZ
2764 if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
2765 "256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
860992ed 2766 raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
f475f1e2
YZ
2767 #For FFS, Auto is default option same to ""\r
2768 if not self.__Token == "Auto":\r
2769 AlignValue = self.__Token\r
860992ed
YZ
2770 if not self.__GetNextToken():\r
2771 raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)\r
2772\r
2773 FileName = self.__Token.replace('$(SPACE)', ' ')\r
2774 if FileName == '}':\r
2775 self.__UndoToken()\r
2776 raise Warning("expected Filename value", self.FileName, self.CurrentLineNumber)\r
860992ed
YZ
2777\r
2778 self.__VerifyFile(FileName)\r
2779 File = PathClass(NormPath(FileName), GenFdsGlobalVariable.WorkSpaceDir)\r
2780 FfsFileObj.FileName.append(File.Path)\r
cfaaf99b 2781 FfsFileObj.SubAlignment.append(AlignValue)\r
860992ed
YZ
2782\r
2783 if self.__IsToken( "}"):\r
2784 self.__UndoToken()\r
2785 break\r
2786\r
cfaaf99b
YZ
2787 if len(FfsFileObj.SubAlignment) == 1:\r
2788 FfsFileObj.SubAlignment = FfsFileObj.SubAlignment[0]\r
860992ed
YZ
2789 if len(FfsFileObj.FileName) == 1:\r
2790 FfsFileObj.FileName = FfsFileObj.FileName[0]\r
2791\r
30fdf114
LG
2792 ## __GetFileOpts() method\r
2793 #\r
2794 # Get options for FILE statement\r
2795 #\r
2796 # @param self The object pointer\r
2797 # @param FfsFileObj for whom options is got\r
2798 #\r
2799 def __GetFileOpts(self, FfsFileObj):\r
2800\r
2801 if self.__GetNextToken():\r
2802 Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
2803 if Pattern.match(self.__Token):\r
2804 FfsFileObj.KeyStringList.append(self.__Token)\r
2805 if self.__IsToken(","):\r
2806 while self.__GetNextToken():\r
2807 if not Pattern.match(self.__Token):\r
2808 raise Warning("expected KeyString \"Target_Tag_Arch\"", self.FileName, self.CurrentLineNumber)\r
2809 FfsFileObj.KeyStringList.append(self.__Token)\r
2810\r
2811 if not self.__IsToken(","):\r
2812 break\r
2813\r
2814 else:\r
2815 self.__UndoToken()\r
2816\r
2817 if self.__IsKeyword( "FIXED", True):\r
2818 FfsFileObj.Fixed = True\r
2819\r
2820 if self.__IsKeyword( "CHECKSUM", True):\r
2821 FfsFileObj.CheckSum = True\r
2822\r
2823 if self.__GetAlignment():\r
e921f58d
YZ
2824 if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
2825 "256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
9053bc51 2826 raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
2827 #For FFS, Auto is default option same to ""\r
2828 if not self.__Token == "Auto":\r
2829 FfsFileObj.Alignment = self.__Token\r
30fdf114
LG
2830\r
2831 ## __GetAlignment() method\r
2832 #\r
2833 # Return the alignment value\r
2834 #\r
2835 # @param self The object pointer\r
2836 # @retval True Successfully find alignment\r
2837 # @retval False Not able to find alignment\r
2838 #\r
2839 def __GetAlignment(self):\r
2840 if self.__IsKeyword( "Align", True):\r
2841 if not self.__IsToken( "="):\r
2842 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2843\r
2844 if not self.__GetNextToken():\r
2845 raise Warning("expected alignment value", self.FileName, self.CurrentLineNumber)\r
2846 return True\r
2847\r
2848 return False\r
2849\r
2850 ## __GetFilePart() method\r
2851 #\r
2852 # Get section data for FILE statement\r
2853 #\r
2854 # @param self The object pointer\r
2855 # @param FfsFileObj for whom section is got\r
2856 # @param MacroDict dictionary used to replace macro\r
2857 #\r
2858 def __GetSectionData(self, FfsFileObj, MacroDict = {}):\r
2859 Dict = {}\r
2860 Dict.update(MacroDict)\r
2861\r
2862 self.__GetDefineStatements(FfsFileObj)\r
2863\r
2864 Dict.update(FfsFileObj.DefineVarDict)\r
2865 self.__GetAprioriSection(FfsFileObj, Dict.copy())\r
2866 self.__GetAprioriSection(FfsFileObj, Dict.copy())\r
2867\r
2868 while True:\r
2869 IsLeafSection = self.__GetLeafSection(FfsFileObj, Dict)\r
2870 IsEncapSection = self.__GetEncapsulationSec(FfsFileObj)\r
2871 if not IsLeafSection and not IsEncapSection:\r
2872 break\r
2873\r
2874 ## __GetLeafSection() method\r
2875 #\r
2876 # Get leaf section for Obj\r
2877 #\r
2878 # @param self The object pointer\r
2879 # @param Obj for whom leaf section is got\r
2880 # @param MacroDict dictionary used to replace macro\r
2881 # @retval True Successfully find section statement\r
2882 # @retval False Not able to find section statement\r
2883 #\r
2884 def __GetLeafSection(self, Obj, MacroDict = {}):\r
2885\r
2886 OldPos = self.GetFileBufferPos()\r
2887\r
2888 if not self.__IsKeyword( "SECTION"):\r
2889 if len(Obj.SectionList) == 0:\r
2890 raise Warning("expected SECTION", self.FileName, self.CurrentLineNumber)\r
2891 else:\r
2892 return False\r
2893\r
2894 AlignValue = None\r
2895 if self.__GetAlignment():\r
e921f58d
YZ
2896 if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
2897 "256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
52302d4d 2898 raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
2899 AlignValue = self.__Token\r
2900\r
2901 BuildNum = None\r
2902 if self.__IsKeyword( "BUILD_NUM"):\r
2903 if not self.__IsToken( "="):\r
2904 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2905\r
2906 if not self.__GetNextToken():\r
2907 raise Warning("expected Build number value", self.FileName, self.CurrentLineNumber)\r
2908\r
2909 BuildNum = self.__Token\r
2910\r
2911 if self.__IsKeyword( "VERSION"):\r
52302d4d
LG
2912 if AlignValue == 'Auto':\r
2913 raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
2914 if not self.__IsToken( "="):\r
2915 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2916 if not self.__GetNextToken():\r
2917 raise Warning("expected version", self.FileName, self.CurrentLineNumber)\r
2918 VerSectionObj = VerSection.VerSection()\r
2919 VerSectionObj.Alignment = AlignValue\r
2920 VerSectionObj.BuildNum = BuildNum\r
2921 if self.__GetStringData():\r
2922 VerSectionObj.StringData = self.__Token\r
2923 else:\r
2924 VerSectionObj.FileName = self.__Token\r
2925 Obj.SectionList.append(VerSectionObj)\r
52302d4d 2926 \r
30fdf114 2927 elif self.__IsKeyword( "UI"):\r
52302d4d
LG
2928 if AlignValue == 'Auto':\r
2929 raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
2930 if not self.__IsToken( "="):\r
2931 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2932 if not self.__GetNextToken():\r
2933 raise Warning("expected UI", self.FileName, self.CurrentLineNumber)\r
2934 UiSectionObj = UiSection.UiSection()\r
2935 UiSectionObj.Alignment = AlignValue\r
2936 if self.__GetStringData():\r
2937 UiSectionObj.StringData = self.__Token\r
2938 else:\r
2939 UiSectionObj.FileName = self.__Token\r
2940 Obj.SectionList.append(UiSectionObj)\r
2941\r
2942 elif self.__IsKeyword( "FV_IMAGE"):\r
52302d4d
LG
2943 if AlignValue == 'Auto':\r
2944 raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
2945 if not self.__IsToken( "="):\r
2946 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2947 if not self.__GetNextToken():\r
2948 raise Warning("expected FV name or FV file path", self.FileName, self.CurrentLineNumber)\r
2949\r
2950 FvName = self.__Token\r
2951 FvObj = None\r
2952\r
2953 if self.__IsToken( "{"):\r
2954 FvObj = Fv.FV()\r
2955 FvObj.UiFvName = FvName.upper()\r
2956 self.__GetDefineStatements(FvObj)\r
2957 MacroDict.update(FvObj.DefineVarDict)\r
2958 self.__GetBlockStatement(FvObj)\r
2959 self.__GetSetStatements(FvObj)\r
2960 self.__GetFvAlignment(FvObj)\r
2961 self.__GetFvAttributes(FvObj)\r
2962 self.__GetAprioriSection(FvObj, MacroDict.copy())\r
2963 self.__GetAprioriSection(FvObj, MacroDict.copy())\r
2964\r
2965 while True:\r
2966 IsInf = self.__GetInfStatement(FvObj, MacroDict.copy())\r
2967 IsFile = self.__GetFileStatement(FvObj, MacroDict.copy())\r
2968 if not IsInf and not IsFile:\r
2969 break\r
2970\r
2971 if not self.__IsToken( "}"):\r
2972 raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
2973\r
2974 FvImageSectionObj = FvImageSection.FvImageSection()\r
2975 FvImageSectionObj.Alignment = AlignValue\r
2976 if FvObj != None:\r
2977 FvImageSectionObj.Fv = FvObj\r
2978 FvImageSectionObj.FvName = None\r
2979 else:\r
2980 FvImageSectionObj.FvName = FvName.upper()\r
2981 FvImageSectionObj.FvFileName = FvName\r
2982\r
2983 Obj.SectionList.append(FvImageSectionObj)\r
2984\r
2985 elif self.__IsKeyword("PEI_DEPEX_EXP") or self.__IsKeyword("DXE_DEPEX_EXP") or self.__IsKeyword("SMM_DEPEX_EXP"):\r
52302d4d
LG
2986 if AlignValue == 'Auto':\r
2987 raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
30fdf114
LG
2988 DepexSectionObj = DepexSection.DepexSection()\r
2989 DepexSectionObj.Alignment = AlignValue\r
2990 DepexSectionObj.DepexType = self.__Token\r
2991\r
2992 if not self.__IsToken( "="):\r
2993 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
2994 if not self.__IsToken( "{"):\r
2995 raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
2996 if not self.__SkipToToken( "}"):\r
2997 raise Warning("expected Depex expression ending '}'", self.FileName, self.CurrentLineNumber)\r
2998\r
2999 DepexSectionObj.Expression = self.__SkippedChars.rstrip('}')\r
3000 Obj.SectionList.append(DepexSectionObj)\r
3001\r
3002 else:\r
30fdf114
LG
3003 if not self.__GetNextWord():\r
3004 raise Warning("expected section type", self.FileName, self.CurrentLineNumber)\r
3005\r
3006 # Encapsulation section appear, UndoToken and return\r
3007 if self.__Token == "COMPRESS" or self.__Token == "GUIDED":\r
3008 self.SetFileBufferPos(OldPos)\r
3009 return False\r
3010\r
3011 if self.__Token not in ("COMPAT16", "PE32", "PIC", "TE", "FV_IMAGE", "RAW", "DXE_DEPEX",\\r
3012 "UI", "VERSION", "PEI_DEPEX", "SUBTYPE_GUID", "SMM_DEPEX"):\r
3013 raise Warning("Unknown section type '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
52302d4d
LG
3014 if AlignValue == 'Auto'and (not self.__Token == 'PE32') and (not self.__Token == 'TE'):\r
3015 raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)\r
3016\r
30fdf114
LG
3017 # DataSection\r
3018 DataSectionObj = DataSection.DataSection()\r
3019 DataSectionObj.Alignment = AlignValue\r
3020 DataSectionObj.SecType = self.__Token\r
3021\r
3022 if self.__IsKeyword('RELOCS_STRIPPED') or self.__IsKeyword('RELOCS_RETAINED'):\r
3023 if self.__FileCouldHaveRelocFlag(Obj.FvFileType) and self.__SectionCouldHaveRelocFlag(DataSectionObj.SecType):\r
3024 if self.__Token == 'RELOCS_STRIPPED':\r
3025 DataSectionObj.KeepReloc = False\r
3026 else:\r
3027 DataSectionObj.KeepReloc = True\r
3028 else:\r
3029 raise Warning("File type %s, section type %s, could not have reloc strip flag%d" % (Obj.FvFileType, DataSectionObj.SecType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber)\r
3030\r
3031 if self.__IsToken("="):\r
3032 if not self.__GetNextToken():\r
3033 raise Warning("expected section file path", self.FileName, self.CurrentLineNumber)\r
3034 DataSectionObj.SectFileName = self.__Token\r
2bc3256c 3035