* [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools
@ 2018-03-13 23:11 Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 1/5] BaseTools: Expression - remove redundant variable Jaben Carsey
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-13 23:11 UTC (permalink / raw)
To: edk2-devel
cleanup up some BaseTools code for simplicity.
Jaben Carsey (5):
BaseTools: Expression - remove redundant variable
BaseTools: Expression refactor function
BaseTools: Expression - change from series of if to elif
BaseTools: Expression - remove variable
BaseTools: RangeExpression - remove unused variable
BaseTools/Source/Python/Common/Expression.py | 32 ++++++++------------
BaseTools/Source/Python/Common/RangeExpression.py | 9 +-----
2 files changed, 14 insertions(+), 27 deletions(-)
--
2.16.2.windows.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 1/5] BaseTools: Expression - remove redundant variable
2018-03-13 23:11 [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools Jaben Carsey
@ 2018-03-13 23:11 ` Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 2/5] BaseTools: Expression refactor function Jaben Carsey
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-13 23:11 UTC (permalink / raw)
To: edk2-devel; +Cc: Yonghong Zhu, Liming Gao
Str is created and not needed.
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/Expression.py | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index e76f09c367c1..bcb27ec11fd5 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -46,14 +46,13 @@ ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARC
#
def SplitString(String):
# There might be escaped quote: "abc\"def\\\"ghi", 'abc\'def\\\'ghi'
- Str = String
RetList = []
InSingleQuote = False
InDoubleQuote = False
Item = ''
- for i, ch in enumerate(Str):
+ for i, ch in enumerate(String):
if ch == '"' and not InSingleQuote:
- if Str[i - 1] != '\\':
+ if String[i - 1] != '\\':
InDoubleQuote = not InDoubleQuote
if not InDoubleQuote:
Item += String[i]
@@ -64,7 +63,7 @@ def SplitString(String):
RetList.append(Item)
Item = ''
elif ch == "'" and not InDoubleQuote:
- if Str[i - 1] != '\\':
+ if String[i - 1] != '\\':
InSingleQuote = not InSingleQuote
if not InSingleQuote:
Item += String[i]
@@ -84,13 +83,12 @@ def SplitString(String):
def SplitPcdValueString(String):
# There might be escaped comma in GUID() or DEVICE_PATH() or " "
# or ' ' or L' ' or L" "
- Str = String
RetList = []
InParenthesis = 0
InSingleQuote = False
InDoubleQuote = False
Item = ''
- for i, ch in enumerate(Str):
+ for i, ch in enumerate(String):
if ch == '(':
InParenthesis += 1
if ch == ')':
--
2.16.2.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 2/5] BaseTools: Expression refactor function
2018-03-13 23:11 [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 1/5] BaseTools: Expression - remove redundant variable Jaben Carsey
@ 2018-03-13 23:11 ` Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 3/5] BaseTools: Expression - change from series of if to elif Jaben Carsey
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-13 23:11 UTC (permalink / raw)
To: edk2-devel; +Cc: Yonghong Zhu, Liming Gao
The function is about C Names, not C Strings.
Move the re.compile outside the function call
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/Expression.py | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index bcb27ec11fd5..c7037dd0d00b 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -40,6 +40,8 @@ ERR_ARRAY_ELE = 'This must be HEX value for NList or Array: [%s].'
ERR_EMPTY_EXPR = 'Empty expression is not allowed.'
ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).'
+__ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
+
## SplitString
# Split string to list according double quote
# For example: abc"de\"f"ghi"jkl"mn will be: ['abc', '"de\"f"', 'ghi', '"jkl"', 'mn']
@@ -117,11 +119,8 @@ def SplitPcdValueString(String):
RetList.append(Item)
return RetList
-def IsValidCString(Str):
- ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
- if not ValidString.match(Str):
- return False
- return True
+def IsValidCName(Str):
+ return True if __ValidString.match(Str) else False
def BuildOptionValue(PcdValue, GuidDict):
IsArray = False
@@ -912,7 +911,7 @@ class ValueExpressionEx(ValueExpression):
Item = Item.strip()
if LabelList:
for Label in LabelList:
- if not IsValidCString(Label):
+ if not IsValidCName(Label):
raise BadExpression('%s is not a valid c variable name' % Label)
if Label not in LabelDict.keys():
LabelDict[Label] = str(LabelOffset)
--
2.16.2.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 3/5] BaseTools: Expression - change from series of if to elif
2018-03-13 23:11 [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 1/5] BaseTools: Expression - remove redundant variable Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 2/5] BaseTools: Expression refactor function Jaben Carsey
@ 2018-03-13 23:11 ` Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 4/5] BaseTools: Expression - remove variable Jaben Carsey
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-13 23:11 UTC (permalink / raw)
To: edk2-devel; +Cc: Yonghong Zhu, Liming Gao
since the first character of the string cannot be found by multiple if
statements, use elif to optomize the behavior.
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/Expression.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index c7037dd0d00b..85c1ce9bbc09 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -93,18 +93,18 @@ def SplitPcdValueString(String):
for i, ch in enumerate(String):
if ch == '(':
InParenthesis += 1
- if ch == ')':
+ elif ch == ')':
if InParenthesis:
InParenthesis -= 1
else:
raise BadExpression(ERR_STRING_TOKEN % Item)
- if ch == '"' and not InSingleQuote:
+ elif ch == '"' and not InSingleQuote:
if String[i-1] != '\\':
InDoubleQuote = not InDoubleQuote
- if ch == "'" and not InDoubleQuote:
+ elif ch == "'" and not InDoubleQuote:
if String[i-1] != '\\':
InSingleQuote = not InSingleQuote
- if ch == ',':
+ elif ch == ',':
if InParenthesis or InSingleQuote or InDoubleQuote:
Item += String[i]
continue
--
2.16.2.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 4/5] BaseTools: Expression - remove variable
2018-03-13 23:11 [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools Jaben Carsey
` (2 preceding siblings ...)
2018-03-13 23:11 ` [PATCH v1 3/5] BaseTools: Expression - change from series of if to elif Jaben Carsey
@ 2018-03-13 23:11 ` Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 5/5] BaseTools: RangeExpression - remove unused variable Jaben Carsey
2018-03-16 6:52 ` [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools Zhu, Yonghong
5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-13 23:11 UTC (permalink / raw)
To: edk2-devel; +Cc: Yonghong Zhu, Liming Gao
The InArary variable serves no purpose. just do the work immediately.
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/Expression.py | 3 ---
1 file changed, 3 deletions(-)
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index 85c1ce9bbc09..4f0f377f3788 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -123,7 +123,6 @@ def IsValidCName(Str):
return True if __ValidString.match(Str) else False
def BuildOptionValue(PcdValue, GuidDict):
- IsArray = False
if PcdValue.startswith('H'):
InputValue = PcdValue[1:]
elif PcdValue.startswith("L'") or PcdValue.startswith("'"):
@@ -133,8 +132,6 @@ def BuildOptionValue(PcdValue, GuidDict):
else:
InputValue = PcdValue
if IsFieldValueAnArray(InputValue):
- IsArray = True
- if IsArray:
try:
PcdValue = ValueExpressionEx(InputValue, 'VOID*', GuidDict)(True)
except:
--
2.16.2.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 5/5] BaseTools: RangeExpression - remove unused variable
2018-03-13 23:11 [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools Jaben Carsey
` (3 preceding siblings ...)
2018-03-13 23:11 ` [PATCH v1 4/5] BaseTools: Expression - remove variable Jaben Carsey
@ 2018-03-13 23:11 ` Jaben Carsey
2018-03-16 6:52 ` [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools Zhu, Yonghong
5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-03-13 23:11 UTC (permalink / raw)
To: edk2-devel; +Cc: Yonghong Zhu, Liming Gao
remove a never used variable.
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/RangeExpression.py | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/BaseTools/Source/Python/Common/RangeExpression.py b/BaseTools/Source/Python/Common/RangeExpression.py
index b6c929fd885b..3449711dcc08 100644
--- a/BaseTools/Source/Python/Common/RangeExpression.py
+++ b/BaseTools/Source/Python/Common/RangeExpression.py
@@ -1,7 +1,7 @@
# # @file
# This file is used to parse and evaluate range expression in Pcd declaration.
#
-# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2015 - 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
@@ -214,13 +214,6 @@ class RangeExpression(object):
RegGuidPattern = re.compile(r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}')
ExRegGuidPattern = re.compile(r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$')
- SymbolPattern = re.compile("("
- "\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
- "&&|\|\||!(?!=)|"
- "(?<=\W)AND(?=\W)|(?<=\W)OR(?=\W)|(?<=\W)NOT(?=\W)|(?<=\W)XOR(?=\W)|"
- "(?<=\W)EQ(?=\W)|(?<=\W)NE(?=\W)|(?<=\W)GT(?=\W)|(?<=\W)LT(?=\W)|(?<=\W)GE(?=\W)|(?<=\W)LE(?=\W)"
- ")")
-
RangePattern = re.compile(r'[0-9]+ - [0-9]+')
def preProcessRangeExpr(self, expr):
--
2.16.2.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools
2018-03-13 23:11 [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools Jaben Carsey
` (4 preceding siblings ...)
2018-03-13 23:11 ` [PATCH v1 5/5] BaseTools: RangeExpression - remove unused variable Jaben Carsey
@ 2018-03-16 6:52 ` Zhu, Yonghong
5 siblings, 0 replies; 7+ messages in thread
From: Zhu, Yonghong @ 2018-03-16 6:52 UTC (permalink / raw)
To: Carsey, Jaben, edk2-devel@lists.01.org
Reviewd this series patch. Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Best Regards,
Zhu Yonghong
-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jaben Carsey
Sent: Wednesday, March 14, 2018 7:12 AM
To: edk2-devel@lists.01.org
Subject: [edk2] [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools
cleanup up some BaseTools code for simplicity.
Jaben Carsey (5):
BaseTools: Expression - remove redundant variable
BaseTools: Expression refactor function
BaseTools: Expression - change from series of if to elif
BaseTools: Expression - remove variable
BaseTools: RangeExpression - remove unused variable
BaseTools/Source/Python/Common/Expression.py | 32 ++++++++------------
BaseTools/Source/Python/Common/RangeExpression.py | 9 +-----
2 files changed, 14 insertions(+), 27 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-16 6:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-13 23:11 [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 1/5] BaseTools: Expression - remove redundant variable Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 2/5] BaseTools: Expression refactor function Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 3/5] BaseTools: Expression - change from series of if to elif Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 4/5] BaseTools: Expression - remove variable Jaben Carsey
2018-03-13 23:11 ` [PATCH v1 5/5] BaseTools: RangeExpression - remove unused variable Jaben Carsey
2018-03-16 6:52 ` [PATCH v1 0/5] BaseTools - some simple cleanups for BaseTools Zhu, Yonghong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox