![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
Data Structures | |
| class | ReplEq |
| class | ReplNeq |
| class | ReplNot |
| class | ReplNotVar |
Functions | |
| str | rewrite_condition (str cond) |
| get_text (src, extent) | |
| find_decl_in_cursor (cursor, name, visited=None) | |
| is_pointer_decl (decl) | |
| collect_decls (root) | |
| collect_decl_refs (n, call_refs) | |
| collect_calls (n, call_refs) | |
| collect_call_extents (n, call_extents) | |
| collect_call_args (n, call_args_names) | |
| node_text (src_bytes, node) | |
| bool | _pos_in_string (str s, int pos) |
| find_literal_ranges (str text) | |
| bool | is_pos_in_literal (int pos, lit_ranges) |
| find_call_arg_ranges (str text, lit_ranges) | |
| bool | is_pos_in_call_args (int pos, call_ranges) |
| str | transform_condition (str cond_text, list pointer_vars) |
| collect_ast_replacements (cond_node, src_bytes) | |
| collect_call_args_tokens (cond_node) | |
| _rewrite_token_repl (m) | |
| _collect_ast_walk (n, parent, tu, src_bytes, edits) | |
| process_if (node, src_bytes, path, edits) | |
| process_file (path) | |
| visit (node, src_bytes, path, edits) | |
| process_folder (folder) | |
Variables | |
| dict | EXTS = {".c", ".h", ".cpp", ".hpp"} |
| str | NULL_NAME = "NULL" |
| dict | _global_decls_cache = {} |
|
protected |
References _collect_ast_walk(), is_pointer_decl(), and node_text().
Referenced by _collect_ast_walk(), and collect_ast_replacements().
|
protected |
Return True if position `pos` is inside a single- or double-quoted literal in s.
Referenced by process_if(), and transform_condition().
|
protected |
| find-null-checks.collect_ast_replacements | ( | cond_node, | |
| src_bytes | |||
| ) |
Walk condition AST and produce precise replacements as (start,end,bytes,old,new). Replacements handled: - `var == NULL` and `NULL == var` -> `IS_NULL_PTR(var)` - `var != NULL` and `NULL != var` -> `!IS_NULL_PTR(var)` - `!var` where var is a bare DeclRefExpr (not member access) -> `IS_NULL_PTR(var)` - bare `var` (DeclRefExpr) used as boolean -> `!IS_NULL_PTR(var)` The function avoids touching identifiers that are part of CALL_EXPR, MEMBER_REF_EXPR, ARRAY_SUBSCRIPT_EXPR, or binary comparisons not involving NULL.
References _collect_ast_walk().
| find-null-checks.collect_call_args | ( | n, | |
| call_args_names | |||
| ) |
References collect_call_args(), and collect_decl_refs().
Referenced by collect_call_args(), and process_if().
| find-null-checks.collect_call_args_tokens | ( | cond_node | ) |
Collect identifier names that appear as arguments of any call-like token sequence inside cond_node by tokenizing the source via libclang. This handles macros and other call-like constructs that do not appear as CALL_EXPR in the AST.
Referenced by process_if().
| find-null-checks.collect_call_extents | ( | n, | |
| call_extents | |||
| ) |
References collect_call_extents().
Referenced by collect_call_extents().
| find-null-checks.collect_calls | ( | n, | |
| call_refs | |||
| ) |
References collect_calls(), and collect_decl_refs().
Referenced by collect_calls().
| find-null-checks.collect_decl_refs | ( | n, | |
| call_refs | |||
| ) |
References collect_decl_refs().
Referenced by collect_call_args(), collect_calls(), and collect_decl_refs().
| find-null-checks.collect_decls | ( | root | ) |
Collect PARAM_DECL and VAR_DECL under root into a name->cursor dict.
Referenced by process_if().
| find-null-checks.find_call_arg_ranges | ( | str | text, |
| lit_ranges | |||
| ) |
References is_pos_in_literal().
Referenced by transform_condition().
| find-null-checks.find_decl_in_cursor | ( | cursor, | |
| name, | |||
visited = None |
|||
| ) |
References find_decl_in_cursor().
Referenced by find_decl_in_cursor().
| find-null-checks.find_literal_ranges | ( | str | text | ) |
Referenced by transform_condition().
| find-null-checks.get_text | ( | src, | |
| extent | |||
| ) |
Referenced by process_if().
| find-null-checks.is_pointer_decl | ( | decl | ) |
Referenced by _collect_ast_walk(), and process_if().
| bool find-null-checks.is_pos_in_call_args | ( | int | pos, |
| call_ranges | |||
| ) |
| bool find-null-checks.is_pos_in_literal | ( | int | pos, |
| lit_ranges | |||
| ) |
| find-null-checks.node_text | ( | src_bytes, | |
| node | |||
| ) |
References max.
Referenced by _collect_ast_walk(), and process_if().
| find-null-checks.process_file | ( | path | ) |
References visit().
Referenced by process_folder().
| find-null-checks.process_folder | ( | folder | ) |
References process_file(), and process_folder().
Referenced by process_folder().
| find-null-checks.process_if | ( | node, | |
| src_bytes, | |||
| path, | |||
| edits | |||
| ) |
References _pos_in_string(), collect_call_args(), collect_call_args_tokens(), collect_decls(), get_text(), if(), is_pointer_decl(), max, min, node_text(), and transform_condition().
Referenced by visit().
| str find-null-checks.rewrite_condition | ( | str | cond | ) |
Conservative rule: - if token is pointer-like: convert - if already negated: flip logic
| str find-null-checks.transform_condition | ( | str | cond_text, |
| list | pointer_vars | ||
| ) |
References _pos_in_string(), find_call_arg_ranges(), find_literal_ranges(), is_pos_in_call_args(), is_pos_in_literal(), and max.
Referenced by process_if().
| find-null-checks.visit | ( | node, | |
| src_bytes, | |||
| path, | |||
| edits | |||
| ) |
References process_if(), and visit().
Referenced by process_file(), and visit().
|
protected |
| dict find-null-checks.EXTS = {".c", ".h", ".cpp", ".hpp"} |
| str find-null-checks.NULL_NAME = "NULL" |