## 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
-from Misc import GuidStringToGuidStructureString, ParseFieldValue, IsFieldValueAnArray\r
+from .Misc import GuidStringToGuidStructureString, ParseFieldValue\r
import Common.EdkLogger as EdkLogger\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
ERR_STRING_TOKEN = 'Bad string token: [%s].'\r
ERR_MACRO_TOKEN = 'Bad macro token: [%s].'\r
ERR_EMPTY_TOKEN = 'Empty token is not allowed.'\r
-ERR_PCD_RESOLVE = 'PCD token cannot be resolved: [%s].'\r
+ERR_PCD_RESOLVE = 'The PCD should be FeatureFlag type or FixedAtBuild type: [%s].'\r
ERR_VALID_TOKEN = 'No more valid token found from rest of string: [%s].'\r
ERR_EXPR_TYPE = 'Different types found in expression.'\r
ERR_OPERATOR_UNSUPPORT = 'Unsupported operator: [%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
InputValue = 'L"' + PcdValue[1:] + '"'\r
else:\r
InputValue = PcdValue\r
- if IsFieldValueAnArray(InputValue):\r
- try:\r
- PcdValue = ValueExpressionEx(InputValue, TAB_VOID, GuidDict)(True)\r
- except:\r
- pass\r
+ try:\r
+ PcdValue = ValueExpressionEx(InputValue, TAB_VOID, GuidDict)(True)\r
+ except:\r
+ pass\r
+\r
return PcdValue\r
\r
## ReplaceExprMacro\r
Oprand2 = IntToStr(Oprand2)\r
TypeDict = {\r
type(0) : 0,\r
- type(0L) : 0,\r
+ # For python2 long type\r
+ type(sys.maxsize + 1) : 0,\r
type('') : 1,\r
type(True) : 2\r
}\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
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
OpToken = ''\r
for Ch in Expr:\r
if Ch in self.NonLetterOpLst:\r
- if '!' == Ch and OpToken:\r
+ if Ch in ['!', '~'] and OpToken:\r
break\r
self._Idx += 1\r
OpToken += Ch\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
raise BadExpression('Type %s PCD Value Size is Larger than 8 byte' % self.PcdType)\r
else:\r
try:\r
- TmpValue = long(PcdValue)\r
+ TmpValue = int(PcdValue)\r
TmpList = []\r
if TmpValue.bit_length() == 0:\r
PcdValue = '{0x00}'\r