]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Eot/CodeFragmentCollector.py
BaseTools: Use absolute import in Eot
[mirror_edk2.git] / BaseTools / Source / Python / Eot / CodeFragmentCollector.py
index 349f934304df704e25ad4f77219ce13dafbe6f35..8a5e5df17e5aff5e34011e833becff72771e44b2 100644 (file)
@@ -1,9 +1,9 @@
 ## @file\r
 # preprocess source file\r
 #\r
-#  Copyright (c) 2007 ~ 2010, Intel Corporation\r
+#  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 #\r
-#  All rights reserved. This program and the accompanying materials\r
+#  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  which accompanies this distribution.  The full text of the license may be found at\r
 #  http://opensource.org/licenses/bsd-license.php\r
 ##\r
 # Import Modules\r
 #\r
+from __future__ import print_function\r
+from __future__ import absolute_import\r
 import re\r
-import os\r
+import Common.LongFilePathOs as os\r
 import sys\r
 \r
 import antlr3\r
-from CLexer import CLexer\r
-from CParser import CParser\r
+from .CLexer import CLexer\r
+from .CParser import CParser\r
 \r
-import FileProfile\r
-from CodeFragment import PP_Directive\r
-from ParserWarning import Warning\r
+from . import FileProfile\r
+from .CodeFragment import PP_Directive\r
+from .ParserWarning import Warning\r
 \r
 \r
 ##define T_CHAR_SPACE                ' '\r
@@ -73,40 +75,6 @@ class CodeFragmentCollector:
         self.__Token = ""\r
         self.__SkippedChars = ""\r
 \r
-    ## __IsWhiteSpace() method\r
-    #\r
-    #   Whether char at current FileBufferPos is whitespace\r
-    #\r
-    #   @param  self        The object pointer\r
-    #   @param  Char        The char to test\r
-    #   @retval True        The char is a kind of white space\r
-    #   @retval False       The char is NOT a kind of white space\r
-    #\r
-    def __IsWhiteSpace(self, Char):\r
-        if Char in (T_CHAR_NULL, T_CHAR_CR, T_CHAR_SPACE, T_CHAR_TAB, T_CHAR_LF):\r
-            return True\r
-        else:\r
-            return False\r
-\r
-    ## __SkipWhiteSpace() method\r
-    #\r
-    #   Skip white spaces from current char, return number of chars skipped\r
-    #\r
-    #   @param  self        The object pointer\r
-    #   @retval Count       The number of chars skipped\r
-    #\r
-    def __SkipWhiteSpace(self):\r
-        Count = 0\r
-        while not self.__EndOfFile():\r
-            Count += 1\r
-            if self.__CurrentChar() in (T_CHAR_NULL, T_CHAR_CR, T_CHAR_LF, T_CHAR_SPACE, T_CHAR_TAB):\r
-                self.__SkippedChars += str(self.__CurrentChar())\r
-                self.__GetOneChar()\r
-\r
-            else:\r
-                Count = Count - 1\r
-                return Count\r
-\r
     ## __EndOfFile() method\r
     #\r
     #   Judge current buffer pos is at file end\r
@@ -291,7 +259,7 @@ class CodeFragmentCollector:
                 InCharLiteral = not InCharLiteral\r
             # meet new line, then no longer in a comment for // and '#'\r
             if self.__CurrentChar() == T_CHAR_LF:\r
-                if HashComment and PPDirectiveObj != None:\r
+                if HashComment and PPDirectiveObj is not None:\r
                     if PPDirectiveObj.Content.rstrip(T_CHAR_CR).endswith(T_CHAR_BACKSLASH):\r
                         PPDirectiveObj.Content += T_CHAR_LF\r
                         PPExtend = True\r
@@ -413,49 +381,49 @@ class CodeFragmentCollector:
     #\r
     def PrintFragments(self):\r
 \r
-        print '################# ' + self.FileName + '#####################'\r
+        print('################# ' + self.FileName + '#####################')\r
 \r
-        print '/****************************************/'\r
-        print '/*************** ASSIGNMENTS ***************/'\r
-        print '/****************************************/'\r
+        print('/****************************************/')\r
+        print('/*************** ASSIGNMENTS ***************/')\r
+        print('/****************************************/')\r
         for asign in FileProfile.AssignmentExpressionList:\r
-            print str(asign.StartPos) + asign.Name + asign.Operator + asign.Value\r
+            print(str(asign.StartPos) + asign.Name + asign.Operator + asign.Value)\r
 \r
-        print '/****************************************/'\r
-        print '/********* PREPROCESS DIRECTIVES ********/'\r
-        print '/****************************************/'\r
+        print('/****************************************/')\r
+        print('/********* PREPROCESS DIRECTIVES ********/')\r
+        print('/****************************************/')\r
         for pp in FileProfile.PPDirectiveList:\r
-            print str(pp.StartPos) + pp.Content\r
+            print(str(pp.StartPos) + pp.Content)\r
 \r
-        print '/****************************************/'\r
-        print '/********* VARIABLE DECLARATIONS ********/'\r
-        print '/****************************************/'\r
+        print('/****************************************/')\r
+        print('/********* VARIABLE DECLARATIONS ********/')\r
+        print('/****************************************/')\r
         for var in FileProfile.VariableDeclarationList:\r
-            print str(var.StartPos) + var.Modifier + ' '+ var.Declarator\r
+            print(str(var.StartPos) + var.Modifier + ' '+ var.Declarator)\r
 \r
-        print '/****************************************/'\r
-        print '/********* FUNCTION DEFINITIONS *********/'\r
-        print '/****************************************/'\r
+        print('/****************************************/')\r
+        print('/********* FUNCTION DEFINITIONS *********/')\r
+        print('/****************************************/')\r
         for func in FileProfile.FunctionDefinitionList:\r
-            print str(func.StartPos) + func.Modifier + ' '+ func.Declarator + ' ' + str(func.NamePos)\r
+            print(str(func.StartPos) + func.Modifier + ' '+ func.Declarator + ' ' + str(func.NamePos))\r
 \r
-        print '/****************************************/'\r
-        print '/************ ENUMERATIONS **************/'\r
-        print '/****************************************/'\r
+        print('/****************************************/')\r
+        print('/************ ENUMERATIONS **************/')\r
+        print('/****************************************/')\r
         for enum in FileProfile.EnumerationDefinitionList:\r
-            print str(enum.StartPos) + enum.Content\r
+            print(str(enum.StartPos) + enum.Content)\r
 \r
-        print '/****************************************/'\r
-        print '/*********** STRUCTS/UNIONS *************/'\r
-        print '/****************************************/'\r
+        print('/****************************************/')\r
+        print('/*********** STRUCTS/UNIONS *************/')\r
+        print('/****************************************/')\r
         for su in FileProfile.StructUnionDefinitionList:\r
-            print str(su.StartPos) + su.Content\r
+            print(str(su.StartPos) + su.Content)\r
 \r
-        print '/****************************************/'\r
-        print '/************** TYPEDEFS ****************/'\r
-        print '/****************************************/'\r
+        print('/****************************************/')\r
+        print('/************** TYPEDEFS ****************/')\r
+        print('/****************************************/')\r
         for typedef in FileProfile.TypedefDefinitionList:\r
-            print str(typedef.StartPos) + typedef.ToType\r
+            print(str(typedef.StartPos) + typedef.ToType)\r
 \r
 ##\r
 #\r
@@ -464,4 +432,4 @@ class CodeFragmentCollector:
 #\r
 if __name__ == "__main__":\r
 \r
-    print "For Test."\r
+    print("For Test.")\r