BaseTools: use new shared GUID regular expressions

remove local variables that are GUID matching and replace with shared
expression.

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>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Carsey, Jaben 2018-03-17 07:27:41 +08:00 committed by Yonghong Zhu
parent 709c9fd56b
commit b1a9e404d4
4 changed files with 9 additions and 11 deletions

View File

@ -214,7 +214,6 @@ class ValueExpression(object):
PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$') PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$') HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')
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}')
SymbolPattern = re.compile("(" SymbolPattern = re.compile("("
"\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|" "\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
@ -725,7 +724,7 @@ class ValueExpression(object):
self._Token = '' self._Token = ''
if Expr: if Expr:
Ch = Expr[0] Ch = Expr[0]
Match = self.RegGuidPattern.match(Expr) Match = gGuidPattern.match(Expr)
if Match and not Expr[Match.end():Match.end()+1].isalnum() \ if Match and not Expr[Match.end():Match.end()+1].isalnum() \
and Expr[Match.end():Match.end()+1] != '_': and Expr[Match.end():Match.end()+1] != '_':
self._Idx += Match.end() self._Idx += Match.end()

View File

@ -22,6 +22,7 @@ import CommonDataClass.FdfClass
from Common.LongFilePathSupport import OpenLongFilePath as open from Common.LongFilePathSupport import OpenLongFilePath as open
from Common.MultipleWorkspace import MultipleWorkspace as mws from Common.MultipleWorkspace import MultipleWorkspace as mws
from Common.RangeExpression import RangeExpression from Common.RangeExpression import RangeExpression
from Common.GlobalData import *
##define T_CHAR_SPACE ' ' ##define T_CHAR_SPACE ' '
##define T_CHAR_NULL '\0' ##define T_CHAR_NULL '\0'
@ -934,7 +935,7 @@ class FdfParser(object):
if not self.__GetNextToken(): if not self.__GetNextToken():
return False return False
if RangeExpression.RegGuidPattern.match(self.__Token) != None: if gGuidPattern.match(self.__Token) != None:
return True return True
else: else:
self.__UndoToken() self.__UndoToken()

View File

@ -211,8 +211,6 @@ class RangeExpression(object):
PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$') PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
HexPattern = re.compile(r'0[xX][0-9a-fA-F]+') HexPattern = re.compile(r'0[xX][0-9a-fA-F]+')
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}$')
RangePattern = re.compile(r'[0-9]+ - [0-9]+') RangePattern = re.compile(r'[0-9]+ - [0-9]+')
@ -341,18 +339,18 @@ class RangeExpression(object):
def Eval(self, Operator, Oprand1, Oprand2 = None): def Eval(self, Operator, Oprand1, Oprand2 = None):
if Operator in ["!", "NOT", "not"]: if Operator in ["!", "NOT", "not"]:
if not self.RegGuidPattern.match(Oprand1.strip()): if not gGuidPattern.match(Oprand1.strip()):
raise BadExpression(ERR_STRING_EXPR % Operator) raise BadExpression(ERR_STRING_EXPR % Operator)
return self.NegtiveRange(Oprand1) return self.NegtiveRange(Oprand1)
else: else:
if Operator in ["==", ">=", "<=", ">", "<", '^']: if Operator in ["==", ">=", "<=", ">", "<", '^']:
return self.EvalRange(Operator, Oprand1) return self.EvalRange(Operator, Oprand1)
elif Operator == 'and' : elif Operator == 'and' :
if not self.ExRegGuidPattern.match(Oprand1.strip()) or not self.ExRegGuidPattern.match(Oprand2.strip()): if not gGuidPatternEnd.match(Oprand1.strip()) or not gGuidPatternEnd.match(Oprand2.strip()):
raise BadExpression(ERR_STRING_EXPR % Operator) raise BadExpression(ERR_STRING_EXPR % Operator)
return self.Rangeintersection(Oprand1, Oprand2) return self.Rangeintersection(Oprand1, Oprand2)
elif Operator == 'or': elif Operator == 'or':
if not self.ExRegGuidPattern.match(Oprand1.strip()) or not self.ExRegGuidPattern.match(Oprand2.strip()): if not gGuidPatternEnd.match(Oprand1.strip()) or not gGuidPatternEnd.match(Oprand2.strip()):
raise BadExpression(ERR_STRING_EXPR % Operator) raise BadExpression(ERR_STRING_EXPR % Operator)
return self.Rangecollections(Oprand1, Oprand2) return self.Rangecollections(Oprand1, Oprand2)
else: else:
@ -410,7 +408,7 @@ class RangeExpression(object):
# check if the expression does not need to evaluate # check if the expression does not need to evaluate
if RealValue and Depth == 0: if RealValue and Depth == 0:
self._Token = self._Expr self._Token = self._Expr
if self.ExRegGuidPattern.match(self._Expr): if gGuidPatternEnd.match(self._Expr):
return [self.operanddict[self._Expr] ] return [self.operanddict[self._Expr] ]
self._Idx = 0 self._Idx = 0
@ -657,7 +655,7 @@ class RangeExpression(object):
self._Token = '' self._Token = ''
if Expr: if Expr:
Ch = Expr[0] Ch = Expr[0]
Match = self.RegGuidPattern.match(Expr) Match = gGuidPattern.match(Expr)
if Match and not Expr[Match.end():Match.end() + 1].isalnum() \ if Match and not Expr[Match.end():Match.end() + 1].isalnum() \
and Expr[Match.end():Match.end() + 1] != '_': and Expr[Match.end():Match.end() + 1] != '_':
self._Idx += Match.end() self._Idx += Match.end()

View File

@ -1136,7 +1136,7 @@ class FdfParser:
if not self.__GetNextToken(): if not self.__GetNextToken():
return False return False
if RangeExpression.RegGuidPattern.match(self.__Token) != None: if gGuidPattern.match(self.__Token) != None:
return True return True
else: else:
self.__UndoToken() self.__UndoToken()