]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Eot/CodeFragmentCollector.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / Eot / CodeFragmentCollector.py
index 87f179206d846b575b836a05876cfe837ed6052d..a5c1ceeaea3218800ad37b21826cfacd9264e28e 100644 (file)
@@ -3,29 +3,31 @@
 #\r
 #  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 #\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
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 ##\r
 # Import Modules\r
 #\r
+from __future__ import print_function\r
+from __future__ import absolute_import\r
 import re\r
 import Common.LongFilePathOs as os\r
 import sys\r
 \r
-import antlr3\r
-from CLexer import CLexer\r
-from CParser import CParser\r
+if sys.version_info.major == 3:\r
+    import antlr4 as antlr\r
+    from Eot.CParser4.CLexer import CLexer\r
+    from Eot.CParser4.CParser import CParser\r
+else:\r
+    import antlr3 as antlr\r
+    antlr.InputStream = antlr.StringStream\r
+    from Eot.CParser3.CLexer import CLexer\r
+    from Eot.CParser3.CParser import CParser\r
 \r
-import FileProfile\r
-from CodeFragment import PP_Directive\r
-from ParserWarning import Warning\r
+from Eot import FileProfile\r
+from Eot.CodeFragment import PP_Directive\r
+from Eot.ParserWarning import Warning\r
 \r
 \r
 ##define T_CHAR_SPACE                ' '\r
@@ -352,9 +354,9 @@ class CodeFragmentCollector:
         FileStringContents = ''\r
         for fileLine in self.Profile.FileLinesList:\r
             FileStringContents += fileLine\r
-        cStream = antlr3.StringStream(FileStringContents)\r
+        cStream = antlr.InputStream(FileStringContents)\r
         lexer = CLexer(cStream)\r
-        tStream = antlr3.CommonTokenStream(lexer)\r
+        tStream = antlr.CommonTokenStream(lexer)\r
         parser = CParser(tStream)\r
         parser.translation_unit()\r
 \r
@@ -379,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
-        for asign in FileProfile.AssignmentExpressionList:\r
-            print str(asign.StartPos) + asign.Name + asign.Operator + asign.Value\r
+        print('/****************************************/')\r
+        print('/************** ASSIGNMENTS *************/')\r
+        print('/****************************************/')\r
+        for assign in FileProfile.AssignmentExpressionList:\r
+            print(str(assign.StartPos) + assign.Name + assign.Operator + assign.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
@@ -430,4 +432,4 @@ class CodeFragmentCollector:
 #\r
 if __name__ == "__main__":\r
 \r
-    print "For Test."\r
+    print("For Test.")\r