Skip to content
Snippets Groups Projects
Commit 56da52d7 authored by Elizabeth's avatar Elizabeth
Browse files

Added code to handle case where 1 line of code is split into 2 lines

parent 6a6fe00e
No related branches found
No related tags found
No related merge requests found
......@@ -37,8 +37,16 @@ def generate_source_code(table, filename, dir_name, source_name):
new_file_contents = []
curr_line = ""
for line in source_file:
orig_func_ind = line.find(knob_config.orig_func_name)
# Handles case where 1 actual line of code is split into 2 lines
if len(line) >= 2 and not line.startswith("#") and \
line.find(";") == -1: # Last char is always \n
curr_line += line
continue
curr_line += line
orig_func_ind = curr_line.find(knob_config.orig_func_name)
if orig_func_ind != -1:
# Replace from an instance of origOp to first instance of ) after origOp
......@@ -46,16 +54,15 @@ def generate_source_code(table, filename, dir_name, source_name):
line_start_ind = 0
last_ind = 0
while orig_func_ind != -1:
new_line.append(line[line_start_ind : orig_func_ind])
new_line.append(curr_line[line_start_ind : orig_func_ind])
new_line.append(knob_config.new_func_call)
line_start_ind = line.find(")", orig_func_ind) + 1
orig_func_ind = line.find(knob_config.orig_func_name, line_start_ind)
new_line.append(line[line_start_ind : ])
line_start_ind = curr_line.find(")", orig_func_ind) + 1
orig_func_ind = curr_line.find(knob_config.orig_func_name, line_start_ind)
new_line.append(curr_line[line_start_ind : ])
new_file_contents.append(''.join(new_line))
else:
new_file_contents.append(line)
new_file_contents.append(curr_line)
curr_line = ""
new_filename = os.path.join(dir_name, "%s_%s.cc" % (source_name, knob_config.id))
new_file = open(new_filename, "w")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment