Fixed several GenDepex bugs
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 18 Feb 2008 05:47:53 +0000 (05:47 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 18 Feb 2008 05:47:53 +0000 (05:47 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1005 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/AutoGen/GenDepex.py
Source/Python/Common/Misc.py

index 14091d3..1daab6b 100644 (file)
@@ -48,9 +48,9 @@ class DependencyExpression:
         "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
@@ -81,11 +81,11 @@ class DependencyExpression:
     # 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
@@ -139,8 +139,11 @@ class DependencyExpression:
                         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
@@ -151,13 +154,17 @@ class DependencyExpression:
                     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
@@ -168,17 +175,35 @@ class DependencyExpression:
         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
@@ -255,6 +280,7 @@ def GetOptions():
 # @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
index 83c713f..171e876 100755 (executable)
@@ -133,6 +133,8 @@ def GuidStructureStringToGuidValueName(GuidValue):
 #   @param      Directory   The directory name\r
 #\r
 def CreateDirectory(Directory):\r
+    if Directory == None or Directory.strip() == "":\r
+        return\r
     if not os.access(Directory, os.F_OK):\r
         os.makedirs(Directory)\r
 \r