def isMacroCall(self,callsite,filename,callinfo): if self.macro_inspector is None: return False if self.macro_inspector.project_dir is None: return False for m in re.finditer(Syntax.lt+Syntax.identifier+Syntax.water+r"\(",callsite.codestr): funcname=m.group().rstrip("(").strip() if Syntax.isKeyWord(funcname): continue #Note that the second argument of getExpanded is the line_num of the call site code. #So should be callsite_index+1 #filename=callsite.get_func_call_info().get_file_name() linenum=callsite.get_linenum() expanded_str=self.macro_inspector.getExpanded(filename,linenum) if expanded_str is None: return False call_patttern=Syntax.lt+Syntax.identifier+Syntax.water+r"[\)\]]*"+Syntax.water+r"\(" for m in re.finditer(call_patttern,expanded_str): if ']' in m.group(): return True cleaner=''.join(m.group().split()) clean=cleaner.rstrip('(').rstrip(')') if not Syntax.isKeyWord(clean) and not Syntax.isLibFuncName(m.group(1)): return True return False
def isMacroCall(self,callsite_index): if self.macro_inspector is None: return False if self.macro_inspector.project_dir is None: return False print "Checking Macro Call..." print "UPPER:",self.l[callsite_index] print "CALLINFO:",self.l[callsite_index+1] for m in re.finditer(Syntax.lt+Syntax.identifier+Syntax.water+r"\(",self.l[callsite_index].codestr): funcname=m.group().rstrip("(").strip() if Syntax.isKeyWord(funcname): continue #Note that the second argument of getExpanded is the line_num of the call site code. #So should be callsite_index+1 print "Find Macro Call:",self.l[callsite_index] filename=self.l[callsite_index].get_func_call_info().get_file_name() linenum=self.l[callsite_index].get_linenum() print filename,linenum expanded_str=self.macro_inspector.getExpanded(filename,linenum) if expanded_str is None: return False print "expanded str:",expanded_str if "temp = (((abfd)->xvec->_bfd_check_format[(int) ((abfd)->format)]) (abfd));" in expanded_str: print "Find IT!" call_patttern=Syntax.lt+Syntax.identifier+Syntax.water+r"[\)\]]*"+Syntax.water+r"\(" for m in re.finditer(call_patttern,expanded_str): if ']' in m.group(): return True cleaner=''.join(m.group().split()) clean=cleaner.rstrip('(').rstrip(')') if not Syntax.isKeyWord(clean) and not Syntax.isLibFuncName(m.group(1)): return True return False
def macro_call_right_str(self,upperIndex): filename=self.l[upperIndex].get_func_call_info().get_file_name() linenum=self.l[upperIndex].get_linenum() print filename,linenum expanded_str=self.macro_inspector.getExpanded(filename,linenum) print "expanded str:",expanded_str if "temp = (((abfd)->xvec->_bfd_check_format[(int) ((abfd)->format)]) (abfd));" in expanded_str: print "Find It!" call_patttern=Syntax.lt+Syntax.identifier+Syntax.water+r"[\)\]]*"+Syntax.water+r"\(" for m in re.finditer(call_patttern,expanded_str): print "matched candidate function name:",m.group(1) if not Syntax.isKeyWord(m.group(1)) and not Syntax.isLibFuncName(m.group(1)): span=m.span() #FIX ME this is wrong when handling cases like: MAZE(a,b)-->'call1(a)+call2(b)". #Then when handling the second call site, it returns 'a' as the detected argument. return expanded_str[span[1]:] print "Fatal Error treat 'sizeof' as a function call or other ERROR!! Please check the macro_call_right_str()" x=1/0