|
From: <qh...@us...> - 2010-03-04 02:45:26
|
Revision: 1910
http://edk2-buildtools.svn.sourceforge.net/edk2-buildtools/?rev=1910&view=rev
Author: qhuang8
Date: 2010-03-04 02:45:19 +0000 (Thu, 04 Mar 2010)
Log Message:
-----------
Update Conditional statement(!if..) in DSC/FDF statement to require the mandatory $() for macro name.
This is a non-backward compatible change that might require the manual update of current DSC/FDF file. (The error message printed out by the tool will help user to solve the incompatible issue)
Modified Paths:
--------------
trunk/BaseTools/Source/Python/Common/FdfParserLite.py
trunk/BaseTools/Source/Python/GenFds/FdfParser.py
trunk/BaseTools/Source/Python/Workspace/MetaFileParser.py
Modified: trunk/BaseTools/Source/Python/Common/FdfParserLite.py
===================================================================
--- trunk/BaseTools/Source/Python/Common/FdfParserLite.py 2010-03-03 02:48:39 UTC (rev 1909)
+++ trunk/BaseTools/Source/Python/Common/FdfParserLite.py 2010-03-04 02:45:19 UTC (rev 1910)
@@ -1,7 +1,7 @@
## @file
# parse FDF file
#
-# Copyright (c) 2007, Intel Corporation
+# Copyright (c) 2007 - 2010, Intel Corporation
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -383,7 +383,22 @@
while Offset <= EndPos[1]:
self.Profile.FileLinesList[EndPos[0]][Offset] = Value
Offset += 1
-
+
+
+ def __GetMacroName(self):
+ if not self.__GetNextToken():
+ raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber)
+ MacroName = self.__Token
+ NotFlag = False
+ if MacroName.startswith('!'):
+ NotFlag = True
+ MacroName = MacroName[1:].strip()
+
+ if not MacroName.startswith('$(') or not MacroName.endswith(')'):
+ raise Warning("Macro name expected(Please use '$(%(Token)s)' if '%(Token)s' is a macro.)" % {"Token" : MacroName},
+ self.FileName, self.CurrentLineNumber)
+ MacroName = MacroName[2:-1]
+ return MacroName, NotFlag
## PreprocessFile() method
#
@@ -554,14 +569,7 @@
IfList.append([IfStartPos, None, None])
CondLabel = self.__Token
- if not self.__GetNextToken():
- raise Warning("expected Macro name At Line ", self.FileName, self.CurrentLineNumber)
- MacroName = self.__Token
- NotFlag = False
- if MacroName.startswith('!'):
- NotFlag = True
- MacroName = MacroName[1:]
-
+ MacroName, NotFlag = self.__GetMacroName()
NotDefineFlag = False
if CondLabel == '!ifndef':
NotDefineFlag = True
@@ -615,14 +623,7 @@
self.__WipeOffArea.append((IfList[-1][0], ElseStartPos))
IfList[-1] = [ElseStartPos, True, IfList[-1][2]]
if self.__Token == '!elseif':
- if not self.__GetNextToken():
- raise Warning("expected Macro name At Line ", self.FileName, self.CurrentLineNumber)
- MacroName = self.__Token
- NotFlag = False
- if MacroName.startswith('!'):
- NotFlag = True
- MacroName = MacroName[1:]
-
+ MacroName, NotFlag = self.__GetMacroName()
if not self.__GetNextOp():
raise Warning("expected !endif At Line ", self.FileName, self.CurrentLineNumber)
Modified: trunk/BaseTools/Source/Python/GenFds/FdfParser.py
===================================================================
--- trunk/BaseTools/Source/Python/GenFds/FdfParser.py 2010-03-03 02:48:39 UTC (rev 1909)
+++ trunk/BaseTools/Source/Python/GenFds/FdfParser.py 2010-03-04 02:45:19 UTC (rev 1910)
@@ -1,7 +1,7 @@
## @file
# parse FDF file
#
-# Copyright (c) 2007, Intel Corporation
+# Copyright (c) 2007 - 2010, Intel Corporation
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -415,6 +415,21 @@
Offset += 1
+ def __GetMacroName(self):
+ if not self.__GetNextToken():
+ raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber)
+ MacroName = self.__Token
+ NotFlag = False
+ if MacroName.startswith('!'):
+ NotFlag = True
+ MacroName = MacroName[1:].strip()
+
+ if not MacroName.startswith('$(') or not MacroName.endswith(')'):
+ raise Warning("Macro name expected(Please use '$(%(Token)s)' if '%(Token)s' is a macro.)" % {"Token" : MacroName},
+ self.FileName, self.CurrentLineNumber)
+ MacroName = MacroName[2:-1]
+ return MacroName, NotFlag
+
## PreprocessFile() method
#
# Preprocess file contents, replace comments with spaces.
@@ -545,6 +560,7 @@
self.Rewind()
+
## PreprocessIncludeFile() method
#
# Preprocess file contents, replace !include statements with file contents.
@@ -583,15 +599,8 @@
IfStartPos = (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len(self.__Token))
IfList.append([IfStartPos, None, None])
CondLabel = self.__Token
-
- if not self.__GetNextToken():
- raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber)
- MacroName = self.__Token
- NotFlag = False
- if MacroName.startswith('!'):
- NotFlag = True
- MacroName = MacroName[1:]
-
+
+ MacroName, NotFlag = self.__GetMacroName()
NotDefineFlag = False
if CondLabel == '!ifndef':
NotDefineFlag = True
@@ -645,14 +654,7 @@
self.__WipeOffArea.append((IfList[-1][0], ElseStartPos))
IfList[-1] = [ElseStartPos, True, IfList[-1][2]]
if self.__Token == '!elseif':
- if not self.__GetNextToken():
- raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber)
- MacroName = self.__Token
- NotFlag = False
- if MacroName.startswith('!'):
- NotFlag = True
- MacroName = MacroName[1:]
-
+ MacroName, NotFlag = self.__GetMacroName()
if not self.__GetNextOp():
raise Warning("expected !endif", self.FileName, self.CurrentLineNumber)
Modified: trunk/BaseTools/Source/Python/Workspace/MetaFileParser.py
===================================================================
--- trunk/BaseTools/Source/Python/Workspace/MetaFileParser.py 2010-03-03 02:48:39 UTC (rev 1909)
+++ trunk/BaseTools/Source/Python/Workspace/MetaFileParser.py 2010-03-04 02:45:19 UTC (rev 1910)
@@ -799,13 +799,24 @@
else:
self._Enabled = len(self._Eval)
- ## Evaludate the value of expression in "if/ifdef/ifndef" directives
+ ## Evaluate the Token for its value; for now only macros are supported.
+ def _EvaluateToken(self, TokenName, Expression):
+ if TokenName.startswith("$(") and TokenName.endswith(")"):
+ Name = TokenName[2:-1]
+ return self._Macros.get(Name)
+ else:
+ EdkLogger.error('Parser', FORMAT_INVALID, "Unknown operand '%(Token)s', "
+ "please use '$(%(Token)s)' if '%(Token)s' is a macro" % {"Token" : TokenName},
+ File=self.MetaFile, Line=self._LineIndex+1, ExtraData=Expression)
+
+ ## Evaluate the value of expression in "if/ifdef/ifndef" directives
def _Evaluate(self, Expression):
TokenList = Expression.split()
TokenNumber = len(TokenList)
# one operand, guess it's just a macro name
if TokenNumber == 1:
- return TokenList[0] in self._Macros
+ TokenValue = self._EvaluateToken(TokenList[0], Expression)
+ return TokenValue != None
# two operands, suppose it's "!xxx" format
elif TokenNumber == 2:
Op = TokenList[0]
@@ -819,8 +830,8 @@
return self._OP_[Op](Value)
# three operands
elif TokenNumber == 3:
- Name = TokenList[0]
- if Name not in self._Macros:
+ TokenValue = self._EvaluateToken(TokenList[0], Expression)
+ if TokenValue == None:
return False
Value = TokenList[2]
if Value[0] in ["'", '"'] and Value[-1] in ["'", '"']:
@@ -829,7 +840,7 @@
if Op not in self._OP_:
EdkLogger.error('Parser', FORMAT_INVALID, "Unsupported operator [%s]" % Op, File=self.MetaFile,
Line=self._LineIndex+1, ExtraData=Expression)
- return self._OP_[Op](self._Macros[Name], Value)
+ return self._OP_[Op](TokenValue, Value)
else:
EdkLogger.error('Parser', FORMAT_INVALID, File=self.MetaFile, Line=self._LineIndex+1,
ExtraData=Expression)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|