1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
#pike __REAL_VERSION__ 
#pragma strict_types 
 
constant inherit_list = __builtin.inherit_list; 
constant inherits = __builtin.program_inherits; 
constant implements = __builtin.program_implements; 
 
// documented in the C-code. 
string defined(program x,string|void y) 
{ 
    if( !y ) 
        return __builtin.program_defined(x); 
    return __builtin.program_identifier_defined(x,y); 
} 
 
 
//! Enumerate all programs this program inherits, directly or indirectly. 
//! Similar to inherit_tree() but returns a flat array. 
//! 
//! @example 
//!  > class a{} 
//!  > class b{} 
//!  > class c{ inherit a; } 
//!  > class d{ inherit b; inherit c; } 
//!  > Program.inherit_tree(d); 
//!  Result: ({ /* 3 elements */ 
//!              b, 
//!              c, 
//!              a 
//!          }) 
array(program) all_inherits(program p) 
{ 
  array(program) ret = inherit_list(p); 
  // Iterate over a mutated array to catch all inherits to infinite depth 
  for(int e=0;e<sizeof(ret);e++) ret+=inherit_list(ret[e]); 
  return ret; 
} 
 
//! Recursively builds a inheritance tree by 
//! fetching programs inheritance lists. 
//! 
//! @returns 
//!  Returns an array with programs or arrays 
//!  as elements. 
//! 
//! @example 
//!  > class a{} 
//!  > class b{} 
//!  > class c{ inherit a; } 
//!  > class d{ inherit b; inherit c; } 
//!  > Program.inherit_tree(d); 
//!  Result: ({ /* 3 elements */ 
//!              d, 
//!              ({ /* 1 element */ 
//!                  program 
//!              }), 
//!              ({ /* 2 elements */ 
//!                  c, 
//!                  ({ /* 1 element */ 
//!                      program 
//!                  }) 
//!              }) 
//!          }) 
array inherit_tree(program p) 
{ 
  return ({ p })+ 
    Array.map(inherit_list(p),inherit_tree); 
}