"AND" : 1,\r
"OR" : 1,\r
"NOT" : 2,\r
- "SOR" : 9,\r
- "BEFORE": 9,\r
- "AFTER" : 9,\r
+ # "SOR" : 9,\r
+ # "BEFORE": 9,\r
+ # "AFTER" : 9,\r
}\r
\r
Opcode = {\r
# all supported op code\r
SupportedOpcode = ["BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT", "TRUE", "FALSE", "END", "SOR"]\r
# op code that should not be the last one\r
- NonEndingOpcode = ["AND", "OR"]\r
+ NonEndingOpcode = ["AND", "OR", "NOT"]\r
# op code must not present at the same time\r
- ExclusiveOpcode = ["SOR", "BEFORE", "AFTER"]\r
+ ExclusiveOpcode = ["BEFORE", "AFTER"]\r
# op code that should be the first one if it presents\r
- AboveAllOpcode = ["SOR"]\r
+ AboveAllOpcode = ["SOR", "BEFORE", "AFTER"]\r
\r
#\r
# open and close brace must be taken as individual tokens\r
break\r
self.PostfixNotation.append(Stack.pop())\r
elif Token in self.OpcodePriority:\r
+ if Token == "NOT" and LastToken not in self.SupportedOpcode:\r
+ EdkLogger.error("GenDepex", PARSER_ERROR, "Invalid dependency expression: missing operator before NOT",\r
+ ExtraData=str(self))\r
while len(Stack) > 0:\r
- if Stack[-1] == "(" or self.OpcodePriority[Token] > self.OpcodePriority[Stack[-1]]:\r
+ if Stack[-1] == "(" or self.OpcodePriority[Token] >= self.OpcodePriority[Stack[-1]]:\r
break\r
self.PostfixNotation.append(Stack.pop())\r
Stack.append(Token)\r
if LastToken not in self.SupportedOpcode + ['(', ')']:\r
EdkLogger.error("GenDepex", PARSER_ERROR, "Invalid dependency expression: missing operator",\r
ExtraData=str(self))\r
- self.PostfixNotation.append("PUSH")\r
+ if len(self.OpcodeList) == 0 or self.OpcodeList[-1] not in self.ExclusiveOpcode:\r
+ self.PostfixNotation.append("PUSH")\r
# check if OP is valid in this phase\r
elif Token in self.Opcode[self.Phase]:\r
+ if Token == "END":\r
+ break\r
self.OpcodeList.append(Token)\r
else:\r
EdkLogger.error("GenDepex", PARSER_ERROR, \r
- "Opcode=%s doesn't supported in %s stage " % (Op, self.Phase))\r
+ "Opcode=%s doesn't supported in %s stage " % (Op, self.Phase),\r
+ ExtraData=str(self))\r
self.PostfixNotation.append(Token)\r
LastToken = Token\r
\r
while len(Stack) > 0:\r
self.PostfixNotation.append(Stack.pop())\r
self.PostfixNotation.append("END")\r
+ print self.PostfixNotation\r
\r
## Validate the dependency expression\r
def ValidateOpcode(self):\r
for Op in self.AboveAllOpcode:\r
- if Op in self.OpcodeList and Op != self.OpcodeList[0]:\r
- EdkLogger.error("GenDepex", PARSER_ERROR, "Opcode=%s should be the first one in the expression" % Op)\r
+ if Op in self.PostfixNotation:\r
+ if Op != self.PostfixNotation[0]:\r
+ EdkLogger.error("GenDepex", PARSER_ERROR, "Opcode=%s should be the first opcode in the expression" % Op,\r
+ ExtraData=str(self))\r
+ if len(self.PostfixNotation) < 3:\r
+ EdkLogger.error("GenDepex", PARSER_ERROR, "Missing operand for %s" % Op,\r
+ ExtraData=str(self))\r
for Op in self.ExclusiveOpcode:\r
- if Op in self.OpcodeList and len(self.OpcodeList) > 1:\r
- EdkLogger.error("GenDepex", PARSER_ERROR, "Opcode=%s should be the only opcode in the expression" % Op)\r
- if self.TokenList[-1] in self.NonEndingOpcode:\r
- EdkLogger.error("GenDepex", PARSER_ERROR, "Extra %s at the end of the dependency expression" % self.TokenList[-1])\r
+ if Op in self.OpcodeList:\r
+ if len(self.OpcodeList) > 1:\r
+ EdkLogger.error("GenDepex", PARSER_ERROR, "Opcode=%s should be the only opcode in the expression" % Op,\r
+ ExtraData=str(self))\r
+ if len(self.PostfixNotation) < 3:\r
+ EdkLogger.error("GenDepex", PARSER_ERROR, "Missing operand for %s" % Op,\r
+ ExtraData=str(self))\r
+ if self.TokenList[-1] != 'END' and self.TokenList[-1] in self.NonEndingOpcode:\r
+ EdkLogger.error("GenDepex", PARSER_ERROR, "Extra %s at the end of the dependency expression" % self.TokenList[-1],\r
+ ExtraData=str(self))\r
+ if self.TokenList[-1] == 'END' and self.TokenList[-2] in self.NonEndingOpcode:\r
+ EdkLogger.error("GenDepex", PARSER_ERROR, "Extra %s at the end of the dependency expression" % self.TokenList[-2],\r
+ ExtraData=str(self))\r
+ if "END" in self.TokenList and "END" != self.TokenList[-1]:\r
+ EdkLogger.error("GenDepex", PARSER_ERROR, "Extra expressions after END", \r
+ ExtraData=str(self))\r
\r
## Convert a GUID value in C structure format into its binary form\r
#\r
# @retval 1 Tool failed\r
#\r
def Main():\r
+ EdkLogger.Initialize()\r
Option, Input = GetOptions()\r
if Option.ModuleType == None or Option.ModuleType not in gType2Phase:\r
print "Module type is not specified or supported"\r