Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
find-null-checks Namespace Reference

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 = {}
 

Function Documentation

◆ _collect_ast_walk()

find-null-checks._collect_ast_walk (   n,
  parent,
  tu,
  src_bytes,
  edits 
)
protected

◆ _pos_in_string()

bool find-null-checks._pos_in_string ( str  s,
int  pos 
)
protected
Return True if position `pos` is inside a single- or double-quoted literal in s.

Referenced by process_if(), and transform_condition().

◆ _rewrite_token_repl()

find-null-checks._rewrite_token_repl (   m)
protected

◆ collect_ast_replacements()

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().

◆ collect_call_args()

find-null-checks.collect_call_args (   n,
  call_args_names 
)

◆ collect_call_args_tokens()

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().

◆ collect_call_extents()

find-null-checks.collect_call_extents (   n,
  call_extents 
)

References collect_call_extents().

Referenced by collect_call_extents().

◆ collect_calls()

find-null-checks.collect_calls (   n,
  call_refs 
)

References collect_calls(), and collect_decl_refs().

Referenced by collect_calls().

◆ collect_decl_refs()

find-null-checks.collect_decl_refs (   n,
  call_refs 
)

◆ collect_decls()

find-null-checks.collect_decls (   root)
Collect PARAM_DECL and VAR_DECL under root into a name->cursor dict.

Referenced by process_if().

◆ find_call_arg_ranges()

find-null-checks.find_call_arg_ranges ( str  text,
  lit_ranges 
)

References is_pos_in_literal().

Referenced by transform_condition().

◆ find_decl_in_cursor()

find-null-checks.find_decl_in_cursor (   cursor,
  name,
  visited = None 
)

References find_decl_in_cursor().

Referenced by find_decl_in_cursor().

◆ find_literal_ranges()

find-null-checks.find_literal_ranges ( str  text)

Referenced by transform_condition().

◆ get_text()

find-null-checks.get_text (   src,
  extent 
)

Referenced by process_if().

◆ is_pointer_decl()

find-null-checks.is_pointer_decl (   decl)

Referenced by _collect_ast_walk(), and process_if().

◆ is_pos_in_call_args()

◆ is_pos_in_literal()

◆ node_text()

find-null-checks.node_text (   src_bytes,
  node 
)

References max.

Referenced by _collect_ast_walk(), and process_if().

◆ process_file()

find-null-checks.process_file (   path)

References visit().

Referenced by process_folder().

◆ process_folder()

find-null-checks.process_folder (   folder)

References process_file(), and process_folder().

Referenced by process_folder().

◆ process_if()

find-null-checks.process_if (   node,
  src_bytes,
  path,
  edits 
)

◆ rewrite_condition()

str find-null-checks.rewrite_condition ( str  cond)
Conservative rule:
- if token is pointer-like: convert
- if already negated: flip logic

◆ transform_condition()

str find-null-checks.transform_condition ( str  cond_text,
list  pointer_vars 
)

◆ visit()

find-null-checks.visit (   node,
  src_bytes,
  path,
  edits 
)

References process_if(), and visit().

Referenced by process_file(), and visit().

Variable Documentation

◆ _global_decls_cache

dict find-null-checks._global_decls_cache = {}
protected

◆ EXTS

dict find-null-checks.EXTS = {".c", ".h", ".cpp", ".hpp"}

◆ NULL_NAME

str find-null-checks.NULL_NAME = "NULL"