\r
## Import Modules\r
#\r
+from __future__ import print_function\r
+from __future__ import absolute_import\r
from Common.GlobalData import *\r
from CommonDataClass.Exceptions import BadExpression\r
from CommonDataClass.Exceptions import WrnExpression\r
import copy\r
from Common.DataType import *\r
import sys\r
+from random import sample\r
+import string\r
\r
ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].'\r
ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].'\r
#\r
def SplitString(String):\r
# There might be escaped quote: "abc\"def\\\"ghi", 'abc\'def\\\'ghi'\r
+ RanStr = ''.join(sample(string.ascii_letters + string.digits, 8))\r
+ String = String.replace('\\\\', RanStr).strip()\r
RetList = []\r
InSingleQuote = False\r
InDoubleQuote = False\r
raise BadExpression(ERR_STRING_TOKEN % Item)\r
if Item:\r
RetList.append(Item)\r
+ for i, ch in enumerate(RetList):\r
+ if RanStr in ch:\r
+ RetList[i] = ch.replace(RanStr,'\\\\')\r
return RetList\r
\r
def SplitPcdValueString(String):\r
# There might be escaped comma in GUID() or DEVICE_PATH() or " "\r
# or ' ' or L' ' or L" "\r
+ RanStr = ''.join(sample(string.ascii_letters + string.digits, 8))\r
+ String = String.replace('\\\\', RanStr).strip()\r
RetList = []\r
InParenthesis = 0\r
InSingleQuote = False\r
raise BadExpression(ERR_STRING_TOKEN % Item)\r
if Item:\r
RetList.append(Item)\r
+ for i, ch in enumerate(RetList):\r
+ if RanStr in ch:\r
+ RetList[i] = ch.replace(RanStr,'\\\\')\r
return RetList\r
\r
def IsValidCName(Str):\r
\r
class BaseExpression(object):\r
def __init__(self, *args, **kwargs):\r
- super().__init__()\r
+ super(BaseExpression, self).__init__()\r
\r
# Check if current token matches the operators given from parameter\r
def _IsOperator(self, OpSet):\r
'IN' : 'in'\r
}\r
\r
- NonLetterOpLst = ['+', '-', '*', '/', '%', '&', '|', '^', '~', '<<', '>>', '!', '=', '>', '<', '?', ':']\r
+ NonLetterOpLst = ['+', '-', TAB_STAR, '/', '%', '&', '|', '^', '~', '<<', '>>', '!', '=', '>', '<', '?', ':']\r
\r
\r
SymbolPattern = re.compile("("\r
else:\r
raise BadExpression(ERR_EXPR_TYPE)\r
if isinstance(Oprand1, type('')) and isinstance(Oprand2, type('')):\r
- if (Oprand1.startswith('L"') and not Oprand2.startswith('L"')) or \\r
- (not Oprand1.startswith('L"') and Oprand2.startswith('L"')):\r
+ if ((Oprand1.startswith('L"') or Oprand1.startswith("L'")) and (not Oprand2.startswith('L"')) and (not Oprand2.startswith("L'"))) or \\r
+ (((not Oprand1.startswith('L"')) and (not Oprand1.startswith("L'"))) and (Oprand2.startswith('L"') or Oprand2.startswith("L'"))):\r
raise BadExpression(ERR_STRING_CMP % (Oprand1, Operator, Oprand2))\r
if 'in' in Operator and isinstance(Oprand2, type('')):\r
Oprand2 = Oprand2.split()\r
return Val\r
\r
def __init__(self, Expression, SymbolTable={}):\r
- super().__init__(self, Expression, SymbolTable)\r
+ super(ValueExpression, self).__init__(self, Expression, SymbolTable)\r
self._NoProcess = False\r
if not isinstance(Expression, type('')):\r
self._Expr = Expression\r
elif not Val:\r
Val = False\r
RealVal = '""'\r
- elif not Val.startswith('L"') and not Val.startswith('{') and not Val.startswith("L'"):\r
+ elif not Val.startswith('L"') and not Val.startswith('{') and not Val.startswith("L'") and not Val.startswith("'"):\r
Val = True\r
RealVal = '"' + RealVal + '"'\r
\r
\r
# A [ * B]*\r
def _MulExpr(self):\r
- return self._ExprFuncTemplate(self._UnaryExpr, {"*", "/", "%"})\r
+ return self._ExprFuncTemplate(self._UnaryExpr, {TAB_STAR, "/", "%"})\r
\r
# [!]*A\r
def _UnaryExpr(self):\r
PcdValue = PcdValue.strip()\r
if PcdValue.startswith('{') and PcdValue.endswith('}'):\r
PcdValue = SplitPcdValueString(PcdValue[1:-1])\r
+ if ERR_STRING_CMP.split(':')[0] in Value.message:\r
+ raise BadExpression("Type: %s, Value: %s, %s" % (self.PcdType, PcdValue, Value))\r
if isinstance(PcdValue, type([])):\r
TmpValue = 0\r
Size = 0\r
if __name__ == '__main__':\r
pass\r
while True:\r
- input = input('Input expr: ')\r
+ input = raw_input('Input expr: ')\r
if input in 'qQ':\r
break\r
try:\r