# # @file\r
# This file is used to parse and evaluate range expression in Pcd declaration.\r
#\r
-# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\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
NonLetterOpLst = ['+', '-', '&', '|', '^', '!', '=', '>', '<']\r
\r
PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')\r
- HexPattern = re.compile(r'0[xX][0-9a-fA-F]+')\r
- 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}')\r
- 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}$')\r
- \r
- SymbolPattern = re.compile("("\r
- "\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"\r
- "&&|\|\||!(?!=)|"\r
- "(?<=\W)AND(?=\W)|(?<=\W)OR(?=\W)|(?<=\W)NOT(?=\W)|(?<=\W)XOR(?=\W)|"\r
- "(?<=\W)EQ(?=\W)|(?<=\W)NE(?=\W)|(?<=\W)GT(?=\W)|(?<=\W)LT(?=\W)|(?<=\W)GE(?=\W)|(?<=\W)LE(?=\W)"\r
- ")")\r
\r
RangePattern = re.compile(r'[0-9]+ - [0-9]+')\r
\r
# convert interval to object index. ex. 1 - 10 to a GUID\r
expr = expr.strip()\r
NumberDict = {}\r
- for HexNumber in self.HexPattern.findall(expr):\r
+ for HexNumber in gHexPattern.findall(expr):\r
Number = str(int(HexNumber, 16))\r
NumberDict[HexNumber] = Number\r
for HexNum in NumberDict:\r
def Eval(self, Operator, Oprand1, Oprand2 = None):\r
\r
if Operator in ["!", "NOT", "not"]:\r
- if not self.RegGuidPattern.match(Oprand1.strip()):\r
+ if not gGuidPattern.match(Oprand1.strip()):\r
raise BadExpression(ERR_STRING_EXPR % Operator)\r
return self.NegtiveRange(Oprand1)\r
else:\r
if Operator in ["==", ">=", "<=", ">", "<", '^']:\r
return self.EvalRange(Operator, Oprand1)\r
elif Operator == 'and' :\r
- if not self.ExRegGuidPattern.match(Oprand1.strip()) or not self.ExRegGuidPattern.match(Oprand2.strip()):\r
+ if not gGuidPatternEnd.match(Oprand1.strip()) or not gGuidPatternEnd.match(Oprand2.strip()):\r
raise BadExpression(ERR_STRING_EXPR % Operator)\r
return self.Rangeintersection(Oprand1, Oprand2) \r
elif Operator == 'or':\r
- if not self.ExRegGuidPattern.match(Oprand1.strip()) or not self.ExRegGuidPattern.match(Oprand2.strip()):\r
+ if not gGuidPatternEnd.match(Oprand1.strip()) or not gGuidPatternEnd.match(Oprand2.strip()):\r
raise BadExpression(ERR_STRING_EXPR % Operator)\r
return self.Rangecollections(Oprand1, Oprand2)\r
else:\r
# check if the expression does not need to evaluate\r
if RealValue and Depth == 0:\r
self._Token = self._Expr\r
- if self.ExRegGuidPattern.match(self._Expr):\r
+ if gGuidPatternEnd.match(self._Expr):\r
return [self.operanddict[self._Expr] ]\r
\r
self._Idx = 0\r
self._LiteralToken.endswith('}'):\r
return True\r
\r
- if self.HexPattern.match(self._LiteralToken):\r
+ if gHexPattern.match(self._LiteralToken):\r
Token = self._LiteralToken[2:]\r
Token = Token.lstrip('0')\r
if not Token:\r
self._Token = ''\r
if Expr:\r
Ch = Expr[0]\r
- Match = self.RegGuidPattern.match(Expr)\r
+ Match = gGuidPattern.match(Expr)\r
if Match and not Expr[Match.end():Match.end() + 1].isalnum() \\r
and Expr[Match.end():Match.end() + 1] != '_':\r
self._Idx += Match.end()\r