// $Id$
// Red nil pointers.  If enabled, show nil pointers in red.

#pragma override old_pointer_value
#pragma override old_dereferenced_pointer_value
old_pointer_value(...) -> pointer_value(...);
old_dereferenced_pointer_value(...) -> dereferenced_pointer_value(...);

#pragma override pointer_value
#pragma override dereferenced_pointer_value

// True if S1 starts in S2
starts_with(s1, s2) = 
    let s1c = chars(s1), s2c = chars(s2) in prefix(s2c, s1c);

// replacement for the old version based on suffixes, since suffix is very slow and causes VSL stack overflows for long strings
// True if null value
is_null(value) = (starts_with(value, "0x0 ") or value="0x0" or starts_with(value, "nil ") or value="nil");

// Rendering of null values
null_pointer(value) = color(value, "red");

// Ordinary pointers
pointer_value (value) -> 
    old_pointer_value(v)
    where v = (if (is_null(value)) then 
	           null_pointer(value)
	       else 
	           value
               fi);

// Dereferenced pointers
dereferenced_pointer_value (value) -> 
    old_dereferenced_pointer_value(v)
    where v = (if (is_null(value)) then 
	           null_pointer(value) 
	       else 
	           value
               fi);
