refactor: rename some vars.
This commit is contained in:
@@ -43,7 +43,7 @@ class ProcessorOptions:
|
||||
self.set_variable(opt)
|
||||
|
||||
|
||||
def remove_thunks(path_to_file: str, args: ProcessorOptions):
|
||||
def process_headers(path_to_file: str, args: ProcessorOptions):
|
||||
assert os.path.isfile(path_to_file)
|
||||
|
||||
RECORDED_THUNKS = []
|
||||
@@ -79,35 +79,35 @@ def remove_thunks(path_to_file: str, args: ProcessorOptions):
|
||||
in_static_variable = True
|
||||
is_modified = True
|
||||
if in_static_variable:
|
||||
tmpline = line.strip()
|
||||
if tmpline.endswith(';'):
|
||||
if not tmpline.startswith('MCAPI'): # declaration may not be on one line
|
||||
this_line = line.strip()
|
||||
if this_line.endswith(';'):
|
||||
if not this_line.startswith('MCAPI'): # declaration may not be on one line
|
||||
begin_pos = content.rfind('MCAPI')
|
||||
tmpline = content[begin_pos:] + tmpline
|
||||
this_line = content[begin_pos:] + this_line
|
||||
content = content[:begin_pos]
|
||||
tmpline = tmpline.strip()
|
||||
this_line = this_line.strip()
|
||||
|
||||
# remove parameter list (convert to static variable)
|
||||
call_spec_pos = tmpline.rfind('()')
|
||||
call_spec_pos = this_line.rfind('()')
|
||||
assert call_spec_pos != -1
|
||||
|
||||
tmpline = tmpline[:call_spec_pos] + tmpline[call_spec_pos + 2 :]
|
||||
this_line = this_line[:call_spec_pos] + this_line[call_spec_pos + 2 :]
|
||||
|
||||
# remove reference
|
||||
refsym_pos = tmpline.rfind('&') # T&
|
||||
tlpsym_pos = tmpline.rfind('>') # ::std::add_lvalue_reference_t<T>
|
||||
refsym_pos = this_line.rfind('&') # T&
|
||||
tlpsym_pos = this_line.rfind('>') # ::std::add_lvalue_reference_t<T>
|
||||
assert refsym_pos != -1 or tlpsym_pos != -1, f'in {path_to_file}'
|
||||
if tlpsym_pos == -1 or refsym_pos > tlpsym_pos:
|
||||
tmpline = tmpline[:refsym_pos] + tmpline[refsym_pos + 1 :]
|
||||
this_line = this_line[:refsym_pos] + this_line[refsym_pos + 1 :]
|
||||
elif refsym_pos == -1 or tlpsym_pos > refsym_pos:
|
||||
# C-style arrays must have '[]' written after the variable name
|
||||
tmpline = tmpline[:tlpsym_pos] + '>' + tmpline[tlpsym_pos:]
|
||||
tmpline = tmpline.replace(
|
||||
this_line = this_line[:tlpsym_pos] + '>' + this_line[tlpsym_pos:]
|
||||
this_line = this_line.replace(
|
||||
'::std::add_lvalue_reference_t<',
|
||||
'::std::remove_reference_t<::std::add_lvalue_reference_t<',
|
||||
)
|
||||
|
||||
content += f'\t{tmpline}\n'
|
||||
content += f'\t{this_line}\n'
|
||||
continue
|
||||
|
||||
if args.restore_member_variable and '::ll::' in line: # union { ... };
|
||||
@@ -117,39 +117,39 @@ def remove_thunks(path_to_file: str, args: ProcessorOptions):
|
||||
# ::ll::TypedStorage<Alignment, Size, T> mVar;
|
||||
# ::ll::UntypedStorage<Alignment, Size> mVar;
|
||||
|
||||
tmpline = line.strip()
|
||||
if tmpline.endswith(';'):
|
||||
if not tmpline.startswith('::ll::'):
|
||||
this_line = line.strip()
|
||||
if this_line.endswith(';'):
|
||||
if not this_line.startswith('::ll::'):
|
||||
begin_pos = content.rfind('::ll::')
|
||||
tmpline = content[begin_pos:] + tmpline
|
||||
this_line = content[begin_pos:] + this_line
|
||||
content = content[:begin_pos]
|
||||
tmpline = tmpline.strip()
|
||||
this_line = this_line.strip()
|
||||
|
||||
if 'TypedStorage' in tmpline:
|
||||
match = ll_typed_regex.search(regex_preprocess_name(tmpline))
|
||||
assert match and match.lastindex == 4, (
|
||||
f'in {path_to_file}, line="{tmpline}"'
|
||||
if 'TypedStorage' in this_line:
|
||||
matched = ll_typed_regex.search(regex_preprocess_name(this_line))
|
||||
assert matched and matched.lastindex == 4, (
|
||||
f'in {path_to_file}, line="{this_line}"'
|
||||
)
|
||||
|
||||
align = match[1] # unused.
|
||||
size = match[2] # unused.
|
||||
type_name = match[3]
|
||||
var_name = match[4]
|
||||
align = matched[1] # unused.
|
||||
size = matched[2] # unused.
|
||||
type_name = matched[3]
|
||||
var_name = matched[4]
|
||||
|
||||
content += f'\t{type_name} {var_name};\n'
|
||||
|
||||
in_member_variable = False
|
||||
continue
|
||||
|
||||
if 'UntypedStorage' in tmpline:
|
||||
match = ll_untyped_regex.search(regex_preprocess_name(tmpline))
|
||||
assert match and match.lastindex == 3, (
|
||||
f'in {path_to_file}, line="{tmpline}"'
|
||||
if 'UntypedStorage' in this_line:
|
||||
matched = ll_untyped_regex.search(regex_preprocess_name(this_line))
|
||||
assert matched and matched.lastindex == 3, (
|
||||
f'in {path_to_file}, line="{this_line}"'
|
||||
)
|
||||
|
||||
align = match[1]
|
||||
size = match[2]
|
||||
var_name = match[3]
|
||||
align = matched[1]
|
||||
size = matched[2]
|
||||
var_name = matched[3]
|
||||
|
||||
content += f'\talignas({align}) std::byte {var_name}[{size}];\n'
|
||||
|
||||
@@ -187,7 +187,7 @@ def iterate_headers(args: ProcessorOptions):
|
||||
for root, dirs, files in os.walk(args.base_dir):
|
||||
for file in files:
|
||||
if is_cxx_header(file):
|
||||
remove_thunks(os.path.join(root, file), args)
|
||||
process_headers(os.path.join(root, file), args)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user