Commit 9091be33 by sikang

update script

parent 18778624
...@@ -40,12 +40,12 @@ def get_rand_code(isInFunc): ...@@ -40,12 +40,12 @@ def get_rand_code(isInFunc):
elif num == 4: elif num == 4:
code += indentasiStr + "long " + filedName + "=" + str(random.randint(0, 100000)) + ";\n" code += indentasiStr + "long " + filedName + "=" + str(random.randint(0, 100000)) + ";\n"
# if isInFunc: if isInFunc:
# if num == 0: if num == 0:
# code += "if(\"" + filedName + "\".equals(\"" + gen_rand_str() + "\")){}//interference code\n" code += "if(\"" + filedName + "\".equals(\"" + gen_rand_str() + "\")){}//interference code\n"
# else: else:
# index = gen_rand_str() index = gen_rand_str()
# code += "for(int " + index + "="+str(random.randint(0,10))+";"+index+"<"+filedName+";"+index+"++){}//interference code\n" code += "for(int " + index + "="+str(random.randint(0,10))+";"+index+"<"+filedName+";"+index+"++){}//interference code\n"
return code return code
...@@ -60,32 +60,33 @@ def process_file_content(path, file_name): ...@@ -60,32 +60,33 @@ def process_file_content(path, file_name):
with open(path, "w", encoding="utf-8") as f_w: with open(path, "w", encoding="utf-8") as f_w:
isReturn = False isReturn = False
isErrorIf = False isErrorIf = False
= 0
func_level = 0 func_level = 0
for line in lines: for line in lines:
#没加{}的if else #没加{}的if else
if ("if(" in line or "if (" in line) and "{" not in line: if ("if(" in line or "if (" in line) and "{" not in line:
isErrorIf = True isErrorIf = True
#return后有多行代码 #return后有多行代码
if "return" in line or "throw" in line: if "return" in line or "throw" in line and not isReturn:
isReturn = True isReturn = True
func_level = 0 = 0
if isReturn: if isReturn:
if "{" in line: if "{" in line:
func_level += 1 += 1
elif "}" in line: elif "}" in line:
func_level -= 1 -= 1
if func_level < 0: if < 0:
func_level = 0 = 0
# if "//interference code" not in line and ")" in line and "{\n" in line and func_level == 0: if "//interference code" not in line and ("){\n" in line or ") {\n" in line) and func_level == 0:
# func_level = 1 func_level = 1
# elif "//interference code" not in line and "{\n" in line: if func_level > 0:
# func_level +=1 if "//interference code" not in line and "{\n" in line:
# func_level +=1
# if "//interference code" not in line and "}\n" in line: if "//interference code" not in line and "}\n" in line:
# func_level -=1 func_level -=1
#需要忽略的行 #需要忽略的行
if not isReturn and not isErrorIf and \ if not isReturn and not isErrorIf and \
...@@ -106,7 +107,7 @@ def process_file_content(path, file_name): ...@@ -106,7 +107,7 @@ def process_file_content(path, file_name):
if ";" in line : if ";" in line :
isErrorIf = False isErrorIf = False
if ";\n" in line and func_level == 0: if ";\n" in line and return_level == 0:
isReturn = False isReturn = False
f_w.write(line) f_w.write(line)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment