summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/Eot/CodeFragmentCollector.py
diff options
context:
space:
mode:
authorFeng, Bob C <bob.c.feng@intel.com>2019-01-14 16:41:22 +0800
committerFeng, Bob C <bob.c.feng@intel.com>2019-02-01 11:09:25 +0800
commit8189be6fd7d7bdd15323b40d5f2f8d0ff822e2d5 (patch)
tree34ad4fd6783f24c4a5568b0a259a379950b91ae8 /BaseTools/Source/Python/Eot/CodeFragmentCollector.py
parentc60377d7f9ec80ecc7fe76c38b81ffd98b7ef2e4 (diff)
downloadedk2-8189be6fd7d7bdd15323b40d5f2f8d0ff822e2d5.tar.gz
edk2-8189be6fd7d7bdd15323b40d5f2f8d0ff822e2d5.tar.bz2
edk2-8189be6fd7d7bdd15323b40d5f2f8d0ff822e2d5.zip
BaseTools: Eot tool Python3 adaption
v2: The python files under CParser4 are generated by antlr4 and for python3 usage. They have python3 specific syntax, for example the data type declaration for the arguments of a function. That is not compitable with python2. this patch is to remove these syntax. Eot tool Python3 adaption. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bob Feng <bob.c.feng@intel.com> Cc: Liming Gao <liming.gao@intel.com> Tested-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/Eot/CodeFragmentCollector.py')
-rw-r--r--BaseTools/Source/Python/Eot/CodeFragmentCollector.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/BaseTools/Source/Python/Eot/CodeFragmentCollector.py b/BaseTools/Source/Python/Eot/CodeFragmentCollector.py
index 8a5e5df17e..b1e77a690a 100644
--- a/BaseTools/Source/Python/Eot/CodeFragmentCollector.py
+++ b/BaseTools/Source/Python/Eot/CodeFragmentCollector.py
@@ -21,13 +21,19 @@ import re
import Common.LongFilePathOs as os
import sys
-import antlr3
-from .CLexer import CLexer
-from .CParser import CParser
+if sys.version_info.major == 3:
+ import antlr4 as antlr
+ from Eot.CParser4.CLexer import CLexer
+ from Eot.CParser4.CParser import CParser
+else:
+ import antlr3 as antlr
+ antlr.InputStream = antlr.StringStream
+ from Eot.CParser3.CLexer import CLexer
+ from Eot.CParser3.CParser import CParser
-from . import FileProfile
-from .CodeFragment import PP_Directive
-from .ParserWarning import Warning
+from Eot import FileProfile
+from Eot.CodeFragment import PP_Directive
+from Eot.ParserWarning import Warning
##define T_CHAR_SPACE ' '
@@ -354,9 +360,9 @@ class CodeFragmentCollector:
FileStringContents = ''
for fileLine in self.Profile.FileLinesList:
FileStringContents += fileLine
- cStream = antlr3.StringStream(FileStringContents)
+ cStream = antlr.InputStream(FileStringContents)
lexer = CLexer(cStream)
- tStream = antlr3.CommonTokenStream(lexer)
+ tStream = antlr.CommonTokenStream(lexer)
parser = CParser(tStream)
parser.translation_unit()