Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed an issue in Optimize() when encounter expression like "TRUE AND…
… TRUE"

git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1233 7335b38e-4728-0410-8992-fb3ffe349368
  • Loading branch information
jwang36 committed May 16, 2008
1 parent 917e749 commit e9405d8
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions Source/Python/AutoGen/GenDepex.py
Expand Up @@ -43,10 +43,10 @@
}

## Convert dependency expression string into EFI internal representation
#
#
# DependencyExpression class is used to parse dependency expression string and
# convert it into its binary form.
#
#
class DependencyExpression:

OpcodePriority = {
Expand Down Expand Up @@ -87,10 +87,10 @@ class DependencyExpression:
SupportedOpcode = ["BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT", "END", "SOR"]
SupportedOperand = ["TRUE", "FALSE"]
## Constructor
#
#
# @param Expression The list or string of dependency expression
# @param ModuleType The type of the module using the dependency expression
#
#
def __init__(self, Expression, ModuleType, Optimize=False, File=''):
self.Phase = gType2Phase[ModuleType]
if type(Expression) == type([]):
Expand Down Expand Up @@ -130,9 +130,11 @@ def Optimize(self):
return
Op = ValidOpcode[0]
NewOperand = []
AllOperand = set()
for Token in self.PostfixNotation:
if Token in self.SupportedOpcode or Token in NewOperand:
continue
AllOperand.add(Token)
if Token == 'TRUE':
if Op == 'AND':
continue
Expand All @@ -147,22 +149,25 @@ def Optimize(self):
break
NewOperand.append(Token)

self.TokenList = []
while True:
self.TokenList.append(NewOperand.pop(0))
if NewOperand == []:
break
self.TokenList.append(Op)
if len(NewOperand) == 0:
self.TokenList = list(AllOperand)
else:
self.TokenList = []
while True:
self.TokenList.append(NewOperand.pop(0))
if NewOperand == []:
break
self.TokenList.append(Op)
self.PostfixNotation = []
self.ExpressionString = ' '.join(self.TokenList)
self.Parse()

## Convert a GUID value in C structure format into its binary form
#
# @param Guid The GUID value in C structure format
#
#
# @retval array The byte array representing the GUID value
#
#
def GetGuidValue(self, Guid):
GuidValueString = Guid.replace("{", "").replace("}", "").replace(" ", "")
GuidValueList = GuidValueString.split(",")
Expand All @@ -173,17 +178,17 @@ def GetGuidValue(self, Guid):
## Save the binary form of dependency expression in file
#
# @param File The path of file. If None is given, put the data on console
#
#
# @retval True If the file doesn't exist or file is changed
# @retval False If file exists and is not changed.
#
#
def Generate(self, File=None):
Buffer = StringIO()
for Item in self.PostfixNotation:
if Item in self.Opcode[self.Phase]:
Buffer.write(pack("B", self.Opcode[self.Phase][Item]))
elif Item in self.SupportedOpcode:
EdkLogger.error("GenDepex", FORMAT_INVALID,
EdkLogger.error("GenDepex", FORMAT_INVALID,
"Opcode [%s] is not expected in %s phase" % (Item, self.Phase),
ExtraData=self.ExpressionString)
else:
Expand All @@ -208,7 +213,7 @@ def Generate(self, File=None):
## Parse command line options
#
# @retval OptionParser
#
#
def GetOptions():
from optparse import OptionParser

Expand Down

0 comments on commit e9405d8

Please sign in to comment.