解决不能识别多行函数声明的问题
This commit is contained in:
@@ -56,6 +56,7 @@ def find_func_decl(file:str):
|
||||
list_str=f.readlines()
|
||||
text=""
|
||||
ignore=False
|
||||
go_on=False
|
||||
for i in list_str:
|
||||
line=i.strip()
|
||||
if(len(line)==0):
|
||||
@@ -71,13 +72,23 @@ def find_func_decl(file:str):
|
||||
if(ignore):
|
||||
ignore=False
|
||||
continue
|
||||
if(line[-1]==';'):
|
||||
text+=line[:-1]
|
||||
if(line.find('(')>0):
|
||||
text=line
|
||||
if(line.find(');')<0):
|
||||
go_on=True
|
||||
continue
|
||||
if go_on:
|
||||
text+=line
|
||||
if(line.find(');')>0):
|
||||
go_on=False
|
||||
if not go_on:
|
||||
par_start=text.find('(')
|
||||
par_end=text.find(')')
|
||||
par_end=text.find(');')
|
||||
if(text.count('(')!=1 or text.count(')')!=1):
|
||||
continue
|
||||
if(par_start>0 and par_end>0 and par_start<par_end):
|
||||
list_func.append(text)
|
||||
text=''
|
||||
text=''
|
||||
return list_func
|
||||
|
||||
# 截取参数列表中的变量名
|
||||
@@ -97,7 +108,7 @@ def def_empty_fun(line:str):
|
||||
# print(line)
|
||||
list_str=line.split('(')
|
||||
ret_type=list_str[0].split(' ')[0]
|
||||
fun_name=list_str[0].split(' ')[1]
|
||||
fun_name=list_str[0].split(' ')[-1]
|
||||
param_str=list_str[1].split(')')[0]
|
||||
params=[]
|
||||
# 有","则至少有两个参数否则可能有一个参数,可能没有
|
||||
@@ -112,7 +123,7 @@ def def_empty_fun(line:str):
|
||||
# print(fun_name,params)
|
||||
params_num=len(params)
|
||||
fun_str=""
|
||||
fun_str+=f"{ret_type} {fun_name}("
|
||||
fun_str+=f"{list_str[0]}("
|
||||
for i in range(params_num):
|
||||
fun_str+=params[i]
|
||||
if(i<len(params)-1):
|
||||
@@ -153,7 +164,7 @@ def create_empty_fun(file:str):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
file_list=['driver/src/hw3/inc/ada_hw.h','driver/src/hw3/inc/mailbox_hw.h']
|
||||
file_list=sys.argv[1:]
|
||||
for item in file_list:
|
||||
# find_func_decl(item)
|
||||
text=create_empty_fun(item)
|
||||
|
Reference in New Issue
Block a user