Skip to content

Commit

Permalink
ECC: add TPMINTERNALAPI to modifier list in config.ini; add StripComm…
Browse files Browse the repository at this point in the history
…ents procedure before searching structure for variable type.

git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1258 7335b38e-4728-0410-8992-fb3ffe349368
  • Loading branch information
jlin16 committed Jun 17, 2008
1 parent 5aa3c38 commit 976beaf
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 28 deletions.
149 changes: 122 additions & 27 deletions Source/Python/Ecc/c.py
Expand Up @@ -648,11 +648,55 @@ def GetCNameList(Lvalue):

return VarList

def SplitPredicateByOp(Str, Op):
def SplitPredicateByOp(Str, Op, IsFuncCalling = False):

Name = Str.strip()
Value = None

if IsFuncCalling:
Index = 0
LBFound = False
UnmatchedLBCount = 0
while Index < len(Str):
while not LBFound and Str[Index] != '_' and not Str[Index].isalnum():
Index += 1

while not LBFound and (Str[Index].isalnum() or Str[Index] == '_'):
Index += 1
# maybe type-cast at the begining, skip it.
RemainingStr = Str[Index:].lstrip()
if RemainingStr.startswith(')') and not LBFound:
Index += 1
continue

if RemainingStr.startswith('(') and not LBFound:
LBFound = True

if Str[Index] == '(':
UnmatchedLBCount += 1
Index += 1
continue

if Str[Index] == ')':
UnmatchedLBCount -= 1
Index += 1
if UnmatchedLBCount == 0:
break
continue

Index += 1

if UnmatchedLBCount > 0:
return [Name]

IndexInRemainingStr = Str[Index:].find(Op)
if IndexInRemainingStr == -1:
return [Name]

Name = Str[0:Index + IndexInRemainingStr].strip()
Value = Str[Index+IndexInRemainingStr+len(Op):].strip()
return [Name, Value]

TmpStr = Str.rstrip(';').rstrip(')')
while True:
Index = TmpStr.rfind(Op)
Expand All @@ -667,32 +711,33 @@ def SplitPredicateByOp(Str, Op):
TmpStr = Str[0:Index - 1]

def SplitPredicateStr(Str):
IsFuncCalling = False
p = GetFuncDeclPattern()
TmpStr = Str.replace('.', '').replace('->', '')
if p.match(TmpStr):
return [[Str, None], None]
IsFuncCalling = True

PredPartList = SplitPredicateByOp(Str, '==')
PredPartList = SplitPredicateByOp(Str, '==', IsFuncCalling)
if len(PredPartList) > 1:
return [PredPartList, '==']

PredPartList = SplitPredicateByOp(Str, '!=')
PredPartList = SplitPredicateByOp(Str, '!=', IsFuncCalling)
if len(PredPartList) > 1:
return [PredPartList, '!=']

PredPartList = SplitPredicateByOp(Str, '>=')
PredPartList = SplitPredicateByOp(Str, '>=', IsFuncCalling)
if len(PredPartList) > 1:
return [PredPartList, '>=']

PredPartList = SplitPredicateByOp(Str, '<=')
PredPartList = SplitPredicateByOp(Str, '<=', IsFuncCalling)
if len(PredPartList) > 1:
return [PredPartList, '<=']

PredPartList = SplitPredicateByOp(Str, '>')
PredPartList = SplitPredicateByOp(Str, '>', IsFuncCalling)
if len(PredPartList) > 1:
return [PredPartList, '>']

PredPartList = SplitPredicateByOp(Str, '<')
PredPartList = SplitPredicateByOp(Str, '<', IsFuncCalling)
if len(PredPartList) > 1:
return [PredPartList, '<']

Expand Down Expand Up @@ -819,6 +864,29 @@ def GetSUDict(FullFileName):
SUDict[FullFileName] = Dict
return Dict

def StripComments(Str):
StrippedStr = ''
List = Str.splitlines()
InComment = False
for StrPart in List:
if StrPart.lstrip().startswith('//'):
continue
Index = StrPart.find('/*')
if Index != -1:
InComment = True
StrippedStr += StrPart[0:Index]

Index = StrPart.find('*/')
if Index != -1:
StrippedStr += StrPart[Index+2:]
InComment = False
continue

if not InComment:
StrippedStr += StrPart

return StrippedStr

def GetFinalTypeValue(Type, FieldName, TypedefDict, SUDict):
Value = TypedefDict.get(Type)
if Value == None:
Expand All @@ -843,22 +911,23 @@ def GetFinalTypeValue(Type, FieldName, TypedefDict, SUDict):

# RBPos = Value.find('}')
Fields = Value[LBPos + 1:]
Fields = StripComments(Fields)
FieldsList = Fields.split(';')
for Field in FieldsList:
Field = Field.strip()
Index = Field.find(FieldName)
Index = Field.rfind(FieldName)
if Index < 1:
continue
if not Field[Index - 1].isalnum():
if Index + len(FieldName) == len(Field):
Type = GetDataTypeFromModifier(Field[0:Index])
return Type.split()[-1]
# else:
# if not Field[Index + len(FieldName) + 1].isalnum():
# Type = GetCNameList(Field[0:Index])
# if len(Type) == 0:
# return Field[0:Index]
# return Type[0]
else:
# For the condition that the field in struct is an array with [] sufixes...
if not Field[Index + len(FieldName)].isalnum():
Type = GetDataTypeFromModifier(Field[0:Index])
return Type.split()[-1]

return None

def GetRealType(Type, TypedefDict, TargetType = None):
Expand Down Expand Up @@ -1450,6 +1519,9 @@ def CheckPointerNullComparison(FullFileName):
if FileID < 0:
return ErrorMsgList

# cache the found function return type to accelerate later checking in this file.
FuncReturnTypeDict = {}

Db = GetDB()
FileTable = 'Identifier' + str(FileID)
SqlStatement = """ select Value, StartLine, ID
Expand Down Expand Up @@ -1481,15 +1553,37 @@ def CheckPointerNullComparison(FullFileName):
for Exp in GetPredicateListFromPredicateExpStr(Str[0]):
PredInfo = SplitPredicateStr(Exp)
if PredInfo[1] == None:
PredVarList = GetCNameList(PredInfo[0][0])
PredVarStr = PredInfo[0][0].strip()
IsFuncCall = False
SearchInCache = False
# PredVarStr may contain '.' or '->'
TmpStr = PredVarStr.replace('.', '').replace('->', '')
if p.match(TmpStr):
PredVarStr = PredVarStr[0:PredVarStr.find('(')]
SearchInCache = True
# Only direct function call using IsFuncCall branch. Multi-level ref. function call is considered a variable.
if TmpStr.startswith(PredVarStr):
IsFuncCall = True

if PredVarStr.strip() in IgnoredKeywordList:
continue
PredVarList = GetCNameList(PredVarStr)
# No variable found, maybe value first? like (0 == VarName)
if len(PredVarList) == 0:
continue
# in the form of function call
if p.match(PredInfo[0][0]):
continue
if SearchInCache:
Type = FuncReturnTypeDict.get(PredVarStr)
if Type != None:
if Type.find('*') == -1:
PrintErrorMsg(ERROR_PREDICATE_EXPRESSION_CHECK_NO_BOOLEAN_OPERATOR, 'Predicate Expression: %s' % Exp, FileTable, Str[2])
continue

if PredVarStr in FuncReturnTypeDict:
continue

Type = GetVarInfo(PredVarList, FuncRecord, FullFileName)
if SearchInCache:
FuncReturnTypeDict[PredVarStr] = Type
if Type == None:
continue
if Type.find('*') != -1:
Expand Down Expand Up @@ -1546,16 +1640,17 @@ def CheckNonBooleanValueComparison(FullFileName):
if p.match(TmpStr):
PredVarStr = PredVarStr[0:PredVarStr.find('(')]
SearchInCache = True
# Only direct function call using IsFuncCall branch. Multi-level ref. function call is considered a variable.
if TmpStr.startswith(PredVarStr):
IsFuncCall = True

if PredVarStr.strip() in IgnoredKeywordList:
continue
PredVarList = GetCNameList(PredVarStr)
# No variable found, maybe value first? like (0 == VarName)
if len(PredVarList) == 0:
continue
# Only direct function call using IsFuncCall branch. Multi-level ref. function call is considered a variable.
if len(PredVarList) == 1:
IsFuncCall = True

if SearchInCache:
Type = FuncReturnTypeDict.get(PredVarStr)
if Type != None:
Expand Down Expand Up @@ -1616,25 +1711,25 @@ def CheckBooleanValueComparison(FullFileName):
for Exp in GetPredicateListFromPredicateExpStr(Str[0]):
PredInfo = SplitPredicateStr(Exp)
if PredInfo[1] in ('==', '!=') and PredInfo[0][1] in ('TRUE', 'FALSE'):
PredVarList = GetCNameList(PredInfo[0][0])
PredVarStr = PredInfo[0][0].strip()
IsFuncCall = False
SearchInCache = False
# PredVarStr may contain '.' or '->'
TmpStr = PredVarStr.replace('.', '').replace('->', '')
if p.match(TmpStr):
PredVarStr = PredVarStr[0:PredVarStr.find('(')]
SearchInCache = True
# Only direct function call using IsFuncCall branch. Multi-level ref. function call is considered a variable.
if TmpStr.startswith(PredVarStr):
IsFuncCall = True

if PredVarStr.strip() in IgnoredKeywordList:
continue
PredVarList = GetCNameList(PredVarStr)
# No variable found, maybe value first? like (0 == VarName)
if len(PredVarList) == 0:
continue

# Only direct function call using IsFuncCall branch. Multi-level ref. function call is considered a variable.
if len(PredVarList) == 1:
IsFuncCall = True

if SearchInCache:
Type = FuncReturnTypeDict.get(PredVarStr)
if Type != None:
Expand Down
2 changes: 1 addition & 1 deletion Source/Python/Ecc/config.ini
Expand Up @@ -41,7 +41,7 @@ AutoCorrect = 1
#
# List customized Modifer here, split with ','
#
ModifierList = IN, OUT, OPTIONAL, UNALIGNED, EFI_RUNTIMESERVICE, EFI_BOOTSERVICE, EFIAPI
ModifierList = IN, OUT, OPTIONAL, UNALIGNED, EFI_RUNTIMESERVICE, EFI_BOOTSERVICE, EFIAPI, TPMINTERNALAPI

#
# General Checking
Expand Down

0 comments on commit 976beaf

Please sign in to comment.