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