]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Expression refactor function
authorCarsey, Jaben </o=Intel/ou=Americas01/cn=Workers/cn=Carsey, Jaben>
Tue, 13 Mar 2018 23:11:32 +0000 (07:11 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Mon, 19 Mar 2018 01:25:06 +0000 (09:25 +0800)
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>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/Common/Expression.py

index bcb27ec11fd596c75f5ce5c91220b24afd7d0ab9..c7037dd0d00bcc27ed31ee2ad896d2ebbddc315d 100644 (file)
@@ -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.'\r
 ERR_IN_OPERAND          = 'Macro after IN operator can only be: $(FAMILY), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).'\r
 \r
+__ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')\r
+\r
 ## SplitString\r
 #  Split string to list according double quote\r
 #  For example: abc"de\"f"ghi"jkl"mn will be: ['abc', '"de\"f"', 'ghi', '"jkl"', 'mn']\r
@@ -117,11 +119,8 @@ def SplitPcdValueString(String):
         RetList.append(Item)\r
     return RetList\r
 \r
-def IsValidCString(Str):\r
-    ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')\r
-    if not ValidString.match(Str):\r
-        return False\r
-    return True\r
+def IsValidCName(Str):\r
+    return True if __ValidString.match(Str) else False\r
 \r
 def BuildOptionValue(PcdValue, GuidDict):\r
     IsArray = False\r
@@ -912,7 +911,7 @@ class ValueExpressionEx(ValueExpression):
                             Item = Item.strip()\r
                             if LabelList:\r
                                 for Label in LabelList:\r
-                                    if not IsValidCString(Label):\r
+                                    if not IsValidCName(Label):\r
                                         raise BadExpression('%s is not a valid c variable name' % Label)\r
                                     if Label not in LabelDict.keys():\r
                                         LabelDict[Label] = str(LabelOffset)\r