public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 0/5] BaseTools: improve reuse and remove dead code
@ 2018-03-15 21:39 Jaben Carsey
  2018-03-15 21:39 ` [PATCH v1 1/5] BaseTools: StrGather has redundant declaration Jaben Carsey
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-15 21:39 UTC (permalink / raw)
  To: edk2-devel

remove class and function definitions that are never used
re-use existing regular expressions instead of compiling
use string format instead of eval()

Jaben Carsey (5):
  BaseTools: StrGather has redundant declaration
  BaseTools: StrGather simplify string/int conversion functions
  BaseTools: StrGather remove functions no one calls
  BaseTools: FdfParser & FdfParserLite refactor regular expression for
    GUIDs
  BaseTools: FdfParser remove class never used.

 BaseTools/Source/Python/AutoGen/StrGather.py    | 57 +++-----------------
 BaseTools/Source/Python/Common/FdfParserLite.py |  4 +-
 BaseTools/Source/Python/GenFds/FdfParser.py     | 19 +------
 3 files changed, 10 insertions(+), 70 deletions(-)

-- 
2.16.2.windows.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v1 1/5] BaseTools: StrGather has redundant declaration
  2018-03-15 21:39 [PATCH v1 0/5] BaseTools: improve reuse and remove dead code Jaben Carsey
@ 2018-03-15 21:39 ` Jaben Carsey
  2018-03-15 21:39 ` [PATCH v1 2/5] BaseTools: StrGather simplify string/int conversion functions Jaben Carsey
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-15 21:39 UTC (permalink / raw)
  To: edk2-devel; +Cc: Yonghong Zhu, Liming Gao

remove COMPATIBLE_STRING_TOKEN as it is the same as STRING_TOKEN
remove if statement that used one or the other (identical) re

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
 BaseTools/Source/Python/AutoGen/StrGather.py | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Source/Python/AutoGen/StrGather.py
index ed33554cd7d2..0e0e9bd74d9d 100644
--- a/BaseTools/Source/Python/AutoGen/StrGather.py
+++ b/BaseTools/Source/Python/AutoGen/StrGather.py
@@ -2,7 +2,7 @@
 # This file is used to parse a strings file and create or add to a string database 
 # file.
 #
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
 # This program and the accompanying materials
 # are licensed and made available under the terms and conditions of the BSD License
 # which accompanies this distribution.  The full text of the license may be found at
@@ -63,7 +63,6 @@ OFFSET = 'offset'
 STRING = 'string'
 TO = 'to'
 STRING_TOKEN = re.compile('STRING_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)
-COMPATIBLE_STRING_TOKEN = re.compile('STRING_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)
 
 EFI_HII_ARRAY_SIZE_LENGTH = 4
 EFI_HII_PACKAGE_HEADER_LENGTH = 4
@@ -572,11 +571,7 @@ def SearchString(UniObjectClass, FileList, IsCompatibleMode):
         if os.path.isfile(File):
             Lines = open(File, 'r')
             for Line in Lines:
-                if not IsCompatibleMode:
-                    StringTokenList = STRING_TOKEN.findall(Line)
-                else:
-                    StringTokenList = COMPATIBLE_STRING_TOKEN.findall(Line)
-                for StrName in StringTokenList:
+                for StrName in STRING_TOKEN.findall(Line):
                     EdkLogger.debug(EdkLogger.DEBUG_5, "Found string identifier: " + StrName)
                     UniObjectClass.SetStringReferenced(StrName)
 
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 2/5] BaseTools: StrGather simplify string/int conversion functions
  2018-03-15 21:39 [PATCH v1 0/5] BaseTools: improve reuse and remove dead code Jaben Carsey
  2018-03-15 21:39 ` [PATCH v1 1/5] BaseTools: StrGather has redundant declaration Jaben Carsey
@ 2018-03-15 21:39 ` Jaben Carsey
  2018-03-15 21:39 ` [PATCH v1 3/5] BaseTools: StrGather remove functions no one calls Jaben Carsey
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-15 21:39 UTC (permalink / raw)
  To: edk2-devel; +Cc: Yonghong Zhu, Liming Gao

use ''.format instead of eval() and use some list comprehension for making list
delete some unused variables

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
 BaseTools/Source/Python/AutoGen/StrGather.py | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Source/Python/AutoGen/StrGather.py
index 0e0e9bd74d9d..e6f10142cb66 100644
--- a/BaseTools/Source/Python/AutoGen/StrGather.py
+++ b/BaseTools/Source/Python/AutoGen/StrGather.py
@@ -59,9 +59,6 @@ NOT_REFERENCED = 'not referenced'
 COMMENT_NOT_REFERENCED = ' ' + COMMENT + NOT_REFERENCED
 CHAR_ARRAY_DEFIN = 'unsigned char'
 COMMON_FILE_NAME = 'Strings'
-OFFSET = 'offset'
-STRING = 'string'
-TO = 'to'
 STRING_TOKEN = re.compile('STRING_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)
 
 EFI_HII_ARRAY_SIZE_LENGTH = 4
@@ -97,7 +94,7 @@ PRINTABLE_LANGUAGE_NAME_STRING_NAME = '$PRINTABLE_LANGUAGE_NAME'
 # @retval:       The formatted hex string
 #
 def DecToHexStr(Dec, Digit = 8):
-    return eval("'0x%0" + str(Digit) + "X' % int(Dec)")
+    return '0x{0:0{1}X}'.format(Dec,Digit)
 
 ## Convert a dec number to a hex list
 #
@@ -112,11 +109,8 @@ def DecToHexStr(Dec, Digit = 8):
 # @retval:       A list for formatted hex string
 #
 def DecToHexList(Dec, Digit = 8):
-    Hex = eval("'%0" + str(Digit) + "X' % int(Dec)")
-    List = []
-    for Bit in range(Digit - 2, -1, -2):
-        List.append(HexHeader + Hex[Bit:Bit + 2])
-    return List
+    Hex = '{0:0{1}X}'.format(Dec,Digit)
+    return ["0x" + Hex[Bit:Bit + 2] for Bit in range(Digit - 2, -1, -2)]
 
 ## Convert a acsii string to a hex list
 #
@@ -128,11 +122,7 @@ def DecToHexList(Dec, Digit = 8):
 # @retval:       A list for formatted hex string
 #
 def AscToHexList(Ascii):
-    List = []
-    for Item in Ascii:
-        List.append('0x%02X' % ord(Item))
-
-    return List
+    return ['0x{0:02X}'.format(ord(Item)) for Item in Ascii]
 
 ## Create header of .h file
 #
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 3/5] BaseTools: StrGather remove functions no one calls
  2018-03-15 21:39 [PATCH v1 0/5] BaseTools: improve reuse and remove dead code Jaben Carsey
  2018-03-15 21:39 ` [PATCH v1 1/5] BaseTools: StrGather has redundant declaration Jaben Carsey
  2018-03-15 21:39 ` [PATCH v1 2/5] BaseTools: StrGather simplify string/int conversion functions Jaben Carsey
@ 2018-03-15 21:39 ` Jaben Carsey
  2018-03-15 21:39 ` [PATCH v1 4/5] BaseTools: FdfParser & FdfParserLite refactor regular expression for GUIDs Jaben Carsey
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-15 21:39 UTC (permalink / raw)
  To: edk2-devel; +Cc: Yonghong Zhu, Liming Gao

simplify the code and remove functions not called anymore

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
 BaseTools/Source/Python/AutoGen/StrGather.py | 30 --------------------
 1 file changed, 30 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Source/Python/AutoGen/StrGather.py
index e6f10142cb66..9c7dd1e40374 100644
--- a/BaseTools/Source/Python/AutoGen/StrGather.py
+++ b/BaseTools/Source/Python/AutoGen/StrGather.py
@@ -124,22 +124,6 @@ def DecToHexList(Dec, Digit = 8):
 def AscToHexList(Ascii):
     return ['0x{0:02X}'.format(ord(Item)) for Item in Ascii]
 
-## Create header of .h file
-#
-# Create a header of .h file
-#
-# @param BaseName: The basename of strings
-#
-# @retval Str:     A string for .h file header
-#
-def CreateHFileHeader(BaseName):
-    Str = ''
-    for Item in H_C_FILE_HEADER:
-        Str = WriteLine(Str, Item)
-    Str = WriteLine(Str, '#ifndef _' + BaseName.upper() + '_STRINGS_DEFINE_H_')
-    Str = WriteLine(Str, '#define _' + BaseName.upper() + '_STRINGS_DEFINE_H_')
-    return Str
-
 ## Create content of .h file
 #
 # Create content of .h file
@@ -204,19 +188,6 @@ def CreateHFile(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag):
 
     return HFile
 
-## Create header of .c file
-#
-# Create a header of .c file
-#
-# @retval Str:     A string for .c file header
-#
-def CreateCFileHeader():
-    Str = ''
-    for Item in H_C_FILE_HEADER:
-        Str = WriteLine(Str, Item)
-
-    return Str
-
 ## Create a buffer to store all items in an array
 #
 # @param BinBuffer   Buffer to contain Binary data.
@@ -493,7 +464,6 @@ def CreateCFileEnd():
 #
 def CreateCFile(BaseName, UniObjectClass, IsCompatibleMode, FilterInfo):
     CFile = ''
-    #CFile = WriteLine(CFile, CreateCFileHeader())
     CFile = WriteLine(CFile, CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, None, FilterInfo))
     CFile = WriteLine(CFile, CreateCFileEnd())
     return CFile
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 4/5] BaseTools: FdfParser & FdfParserLite refactor regular expression for GUIDs
  2018-03-15 21:39 [PATCH v1 0/5] BaseTools: improve reuse and remove dead code Jaben Carsey
                   ` (2 preceding siblings ...)
  2018-03-15 21:39 ` [PATCH v1 3/5] BaseTools: StrGather remove functions no one calls Jaben Carsey
@ 2018-03-15 21:39 ` Jaben Carsey
  2018-03-15 21:39 ` [PATCH v1 5/5] BaseTools: FdfParser remove class never used Jaben Carsey
  2018-03-20  8:26 ` [PATCH v1 0/5] BaseTools: improve reuse and remove dead code Zhu, Yonghong
  5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-15 21:39 UTC (permalink / raw)
  To: edk2-devel; +Cc: Yonghong Zhu, Liming Gao

Instead of recompiling it each time the API is called, just use
the global one that exists.

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
 BaseTools/Source/Python/Common/FdfParserLite.py | 4 ++--
 BaseTools/Source/Python/GenFds/FdfParser.py     | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/Python/Common/FdfParserLite.py b/BaseTools/Source/Python/Common/FdfParserLite.py
index 7d129bfcab59..592959cdd477 100644
--- a/BaseTools/Source/Python/Common/FdfParserLite.py
+++ b/BaseTools/Source/Python/Common/FdfParserLite.py
@@ -21,6 +21,7 @@ import Common.LongFilePathOs as os
 import CommonDataClass.FdfClass
 from Common.LongFilePathSupport import OpenLongFilePath as open
 from Common.MultipleWorkspace import MultipleWorkspace as mws
+from Common.RangeExpression import RangeExpression
 
 ##define T_CHAR_SPACE                ' '
 ##define T_CHAR_NULL                 '\0'
@@ -931,8 +932,7 @@ class FdfParser(object):
         
         if not self.__GetNextToken():
             return False
-        p = re.compile('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')
-        if p.match(self.__Token) != None:
+        if RangeExpression.RegGuidPattern.match(self.__Token) != None:
             return True
         else:
             self.__UndoToken()
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index dda7ed4ce798..19c1ad372c4c 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -59,6 +59,7 @@ import Common.LongFilePathOs as os
 from Common.LongFilePathSupport import OpenLongFilePath as open
 from Capsule import EFI_CERT_TYPE_PKCS7_GUID
 from Capsule import EFI_CERT_TYPE_RSA2048_SHA256_GUID
+from Common.RangeExpression import RangeExpression
 
 ##define T_CHAR_SPACE                ' '
 ##define T_CHAR_NULL                 '\0'
@@ -1149,8 +1150,7 @@ class FdfParser:
 
         if not self.__GetNextToken():
             return False
-        p = re.compile('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')
-        if p.match(self.__Token) != None:
+        if RangeExpression.RegGuidPattern.match(self.__Token) != None:
             return True
         else:
             self.__UndoToken()
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 5/5] BaseTools: FdfParser remove class never used.
  2018-03-15 21:39 [PATCH v1 0/5] BaseTools: improve reuse and remove dead code Jaben Carsey
                   ` (3 preceding siblings ...)
  2018-03-15 21:39 ` [PATCH v1 4/5] BaseTools: FdfParser & FdfParserLite refactor regular expression for GUIDs Jaben Carsey
@ 2018-03-15 21:39 ` Jaben Carsey
  2018-03-20  8:26 ` [PATCH v1 0/5] BaseTools: improve reuse and remove dead code Zhu, Yonghong
  5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-15 21:39 UTC (permalink / raw)
  To: edk2-devel; +Cc: Yonghong Zhu, Liming Gao

the MacroProfile class is never instantiated nor referenced.

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
 BaseTools/Source/Python/GenFds/FdfParser.py | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index 19c1ad372c4c..e35057931f03 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -136,21 +136,6 @@ class Warning (Exception):
     def __str__(self):
         return self.Message
 
-## The MACRO class that used to record macro value data when parsing include file
-#
-#
-class MacroProfile :
-    ## The constructor
-    #
-    #   @param  self        The object pointer
-    #   @param  FileName    The file that to be parsed
-    #
-    def __init__(self, FileName, Line):
-        self.FileName = FileName
-        self.DefinedAtLine  = Line
-        self.MacroName = None
-        self.MacroValue = None
-
 ## The Include file content class that used to record file data when parsing include file
 #
 # May raise Exception when opening file.
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 0/5] BaseTools: improve reuse and remove dead code
  2018-03-15 21:39 [PATCH v1 0/5] BaseTools: improve reuse and remove dead code Jaben Carsey
                   ` (4 preceding siblings ...)
  2018-03-15 21:39 ` [PATCH v1 5/5] BaseTools: FdfParser remove class never used Jaben Carsey
@ 2018-03-20  8:26 ` Zhu, Yonghong
  5 siblings, 0 replies; 7+ messages in thread
From: Zhu, Yonghong @ 2018-03-20  8:26 UTC (permalink / raw)
  To: Carsey, Jaben, edk2-devel@lists.01.org

Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
I will push this series patch.

Best Regards,
Zhu Yonghong


-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jaben Carsey
Sent: Friday, March 16, 2018 5:39 AM
To: edk2-devel@lists.01.org
Subject: [edk2] [PATCH v1 0/5] BaseTools: improve reuse and remove dead code

remove class and function definitions that are never used re-use existing regular expressions instead of compiling use string format instead of eval()

Jaben Carsey (5):
  BaseTools: StrGather has redundant declaration
  BaseTools: StrGather simplify string/int conversion functions
  BaseTools: StrGather remove functions no one calls
  BaseTools: FdfParser & FdfParserLite refactor regular expression for
    GUIDs
  BaseTools: FdfParser remove class never used.

 BaseTools/Source/Python/AutoGen/StrGather.py    | 57 +++-----------------
 BaseTools/Source/Python/Common/FdfParserLite.py |  4 +-
 BaseTools/Source/Python/GenFds/FdfParser.py     | 19 +------
 3 files changed, 10 insertions(+), 70 deletions(-)

--
2.16.2.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-03-20  8:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-15 21:39 [PATCH v1 0/5] BaseTools: improve reuse and remove dead code Jaben Carsey
2018-03-15 21:39 ` [PATCH v1 1/5] BaseTools: StrGather has redundant declaration Jaben Carsey
2018-03-15 21:39 ` [PATCH v1 2/5] BaseTools: StrGather simplify string/int conversion functions Jaben Carsey
2018-03-15 21:39 ` [PATCH v1 3/5] BaseTools: StrGather remove functions no one calls Jaben Carsey
2018-03-15 21:39 ` [PATCH v1 4/5] BaseTools: FdfParser & FdfParserLite refactor regular expression for GUIDs Jaben Carsey
2018-03-15 21:39 ` [PATCH v1 5/5] BaseTools: FdfParser remove class never used Jaben Carsey
2018-03-20  8:26 ` [PATCH v1 0/5] BaseTools: improve reuse and remove dead code Zhu, Yonghong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox