Commit 9091be33 by sikang

update script

parent 18778624
......@@ -40,12 +40,12 @@ def get_rand_code(isInFunc):
elif num == 4:
code += indentasiStr + "long " + filedName + "=" + str(random.randint(0, 100000)) + ";\n"
# if isInFunc:
# if num == 0:
# code += "if(\"" + filedName + "\".equals(\"" + gen_rand_str() + "\")){}//interference code\n"
# else:
# index = gen_rand_str()
# code += "for(int " + index + "="+str(random.randint(0,10))+";"+index+"<"+filedName+";"+index+"++){}//interference code\n"
if isInFunc:
if num == 0:
code += "if(\"" + filedName + "\".equals(\"" + gen_rand_str() + "\")){}//interference code\n"
else:
index = gen_rand_str()
code += "for(int " + index + "="+str(random.randint(0,10))+";"+index+"<"+filedName+";"+index+"++){}//interference code\n"
return code
......@@ -60,32 +60,33 @@ def process_file_content(path, file_name):
with open(path, "w", encoding="utf-8") as f_w:
isReturn = False
isErrorIf = False
= 0
func_level = 0
for line in lines:
#没加{}的if else
if ("if(" in line or "if (" in line) and "{" not in line:
isErrorIf = True
#return后有多行代码
if "return" in line or "throw" in line:
if "return" in line or "throw" in line and not isReturn:
isReturn = True
func_level = 0
= 0
if isReturn:
if "{" in line:
func_level += 1
+= 1
elif "}" in line:
func_level -= 1
if func_level < 0:
func_level = 0
-= 1
if < 0:
= 0
# if "//interference code" not in line and ")" in line and "{\n" in line and func_level == 0:
# func_level = 1
# elif "//interference code" not in line and "{\n" in line:
# 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 or ") {\n" in line) and func_level == 0:
func_level = 1
if func_level > 0:
if "//interference code" not in line and "{\n" in line:
func_level +=1
if "//interference code" not in line and "}\n" in line:
func_level -=1
#需要忽略的行
if not isReturn and not isErrorIf and \
......@@ -106,7 +107,7 @@ def process_file_content(path, file_name):
if ";" in line :
isErrorIf = False
if ";\n" in line and func_level == 0:
if ";\n" in line and return_level == 0:
isReturn = False
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