Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle remove_bad_names=False from DAILA #10

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions varbert/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def predict_variable_names(

orig_name_2_popular_name, renamed_code = preprocessor.generate_popular_names(
processed_code, func_args, scores, score_origins,
predict_for_decompiler_generated_vars=False
predict_for_decompiler_generated_vars=not remove_bad_names
)
if not orig_name_2_popular_name:
self.warning(f"Unable to predict any names for function {function}")
Expand All @@ -92,17 +92,22 @@ def predict_variable_names(
orig_name_2_popular_name = {
k: v for k, v in name_pairs if "/*decompiler*/" not in v
}
else:
# rewrite decompiled based names
orig_name_2_popular_name = {
k: v.replace(" /*decompiler*/", "_dec") for k, v in orig_name_2_popular_name.items()
}

# check after filtering
self.info(f"Predicted {len(orig_name_2_popular_name)} new names for function {function}")
return orig_name_2_popular_name, renamed_code

@AIAPI.requires_function
def query_model(self, *args, function=None, dec_text=None, use_dec=True, **kwargs) -> Tuple[Dict[str, str], str]:
def query_model(self, function=None, dec_text=None, use_dec=True, *args, **kwargs) -> Tuple[Dict[str, str], str]:
"""
Standardized function for querying the model in DAILA interfaces.
"""
old_to_new_vars, renamed_code = self.predict_variable_names(function=function, decompilation_text=dec_text, use_decompiler=use_dec)
old_to_new_vars, renamed_code = self.predict_variable_names(function=function, decompilation_text=dec_text, use_decompiler=use_dec, *args, **kwargs)
if use_dec and old_to_new_vars:
self._dec_interface.rename_local_variables_by_names(function, old_to_new_vars)

Expand Down
Loading