ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
tree.h
Go to the documentation of this file.
1 
17 #ifndef _CEPTR_TREE_H
18 #define _CEPTR_TREE_H
19 
20 #include <string.h>
21 #include <stdlib.h>
22 #include "ceptr_error.h"
23 #include "sys_defs.h"
24 #include "base_defs.h"
25 #include "ceptr_types.h"
26 #include "stream.h"
27 
28 #define TREE_CHILDREN_BLOCK 5
29 #define TREE_PATH_TERMINATOR 0xFFFFFFFF
30 
31 enum TreeSurfaceFlags {TFLAG_ALLOCATED=0x0001,TFLAG_SURFACE_IS_TREE=0x0002,TFLAG_SURFACE_IS_RECEPTOR = 0x0004,TFLAG_SURFACE_IS_SCAPE=0x0008,TFLAG_SURFACE_IS_CPTR=0x0010,TFLAG_DELETED=0x0020,TFLAG_RUN_NODE=0x0040,TFLAG_REFERENCE=0x8000};
32 
33 /***************** Node creation and deletion*/
34 T *__t_new(T *t,Symbol symbol, void *surface, size_t size,bool is_run_node);
35 #define _t_new(p,sy,su,s) __t_new(p,sy,su,s,0)
36 T *__t_newc(T *t,Symbol symbol, char c,bool is_run_node);
37 #define _t_newc(parent,symbol,c) __t_newc(parent,symbol,c,0)
38 T *__t_newi(T *parent,Symbol symbol,int surface,bool is_run_node);
39 #define _t_newi(p,sy,su) __t_newi(p,sy,su,0)
40 T *__t_newi64(T *parent,Symbol symbol,long surface,bool is_run_node);
41 #define _t_newi64(p,sy,su) __t_newi64(p,sy,su,0)
42 T *__t_news(T *parent,Symbol symbol,SemanticID surface,bool is_run_node);
43 #define _t_news(parent,symbol,surface) __t_news(parent,symbol,surface,0)
44 T *_t_newt(T *parent,Symbol symbol,T *t);
45 #define _t_new_str(parent,symbol,str) __t_new_str(parent,symbol,str,0)
46 T *__t_new_str(T *parent,Symbol symbol,char *str,bool is_run_node);
47 T *_t_new_root(Symbol symbol);
48 #define _t_newr(p,s) __t_newr(p,s,0)
49 T *__t_newr(T *parent,Symbol symbol,bool is_run_node);
50 T *_t_new_receptor(T *parent,Symbol symbol,Receptor *r);
51 T *_t_new_scape(T *parent,Symbol symbol,Scape *s);
52 T *_t_new_cptr(T *parent,Symbol symbol,void *s);
53 T *_t_newp(T *parent,Symbol symbol,Process surface);
54 
55 void _t_add(T *t,T *c);
56 void _t_detach_by_ptr(T *t,T *c);
57 T *_t_detach_by_idx(T *t,int i);
58 void _t_replace(T *t,int i,T *r);
59 void _t_replace_node(T *t,T *r);
60 T *_t_swap(T *t,int i,T *r);
61 void _t_insert_at(T *t, int *path, T *i);
62 void _t_morph(T *dst,T *src);
63 void __t_morph(T *t,Symbol s,void *surface,size_t length,int allocate);
64 void __t_free_children(T *t);
65 void __t_free(T *t);
66 void _t_free(T *t);
67 T *_t_clone(T *t);
68 T *_t_rclone(T *t);
69 
70 T *_t_build(SemTable *sem,T *t,...);
71 T *_t_build2(SemTable *sem,T *t,...);
72 T *__t_tokenize(char *s);
73 T *_t_parse(SemTable *sem,T *parent,char *s,...);
74 
75 #define _t_fill_template(t,i) __t_fill_template(t,i,false)
76 bool __t_fill_template(T *template, T *items,bool as_run_node);
77 
78 /******************** Node data accessors */
79 int _t_children(T *t);
80 void * _t_surface(T *t);
81 Symbol _t_symbol(T *t);
82 size_t _t_size(T *t);
83 
84 /***************** Tree navigation */
85 T * _t_parent(T *t);
86 T *_t_child(T *t,int i);
87 T * _t_root(T *t);
88 T * _t_next_sibling(T *t);
89 int _t_node_index(T *t);
90 #define _t_find(t,sym) __t_find(t,sym,1)
91 T *__t_find(T *t,Symbol sym,int start_child);
92 
93 /***************** Tree path based accesses */
94 int _t_path_equal(int *p1,int *p2);
95 int _t_path_depth(int *p);
96 void _t_pathcpy(int *dst_p,int *src_p);
97 T * _t_get(T *t,int *p);
98 T * _t_getv(T *t,...);
99 int *_t_get_path(T *t);
100 void * _t_get_surface(T *t,int *p);
101 char * _t_sprint_path(int *fp,char *buf);
102 T * _t_path_walk(T *t,int **pathP,int *lenP );
103 
104 /***************** Tree hashing utilities */
105 TreeHash _t_hash(SemTable *sem,T *t);
106 int _t_hash_equal(TreeHash h1,TreeHash h2);
107 
108 /***************** UUID utilities */
109 UUIDt __uuid_gen();
110 int __uuid_equal(UUIDt *u1,UUIDt *u2);
111 
112 /***************** Tree serialization */
113 size_t __t_serialize(SemTable *sem,T *t,void **bufferP,size_t offset,size_t current_size,int compact);
114 void _t_serialize(SemTable *sem,T *t,void **surfaceP,size_t *sizeP);
115 T * _t_unserialize(SemTable *sem,void **surfaceP,size_t *lengthP,T *t);
116 
117 char * _t2rawjson(SemTable *sem,T *t,int level,char *buf);
118 char * _t2json(SemTable *sem,T *t,int level,char *buf);
119 
120 /***************** Misc... */
121 
122 int _t_write(SemTable *sem,T *t,Stream *stream);
123 
124 #define DO_KIDS(t,x) {int i,_c=_t_children(t);for(i=1;i<=_c;i++){x;}}
125 
126 #define root_check(c) if (c->structure.parent != 0) {raise_error("can't add a node that isn't a root!");}
127 
128 #endif
129 
T * _t_new_root(Symbol symbol)
Definition: tree.c:160
Definition: ceptr_types.h:114
T * _t_next_sibling(T *t)
Definition: tree.c:1306
T * _t_new_scape(T *parent, Symbol symbol, Scape *s)
Definition: tree.c:222
void _t_morph(T *dst, T *src)
Definition: tree.c:357
T * _t_build2(SemTable *sem, T *t,...)
Definition: tree.c:771
Definition: stream.h:30
T * __t_newi(T *parent, Symbol symbol, int surface, bool is_run_node)
Definition: tree.c:97
T * _t_get(T *t, int *p)
Definition: tree.c:1441
int _t_write(SemTable *sem, T *t, Stream *stream)
Definition: tree.c:2066
T * _t_path_walk(T *t, int **pathP, int *lenP)
Definition: tree.c:1543
bool __t_fill_template(T *template, T *items, bool as_run_node)
Definition: tree.c:1049
int _t_hash_equal(TreeHash h1, TreeHash h2)
Definition: tree.c:1649
T * _t_detach_by_idx(T *t, int i)
Definition: tree.c:278
int _t_path_depth(int *p)
Definition: tree.c:1365
int _t_node_index(T *t)
Definition: tree.c:1284
T * _t_new_receptor(T *parent, Symbol symbol, Receptor *r)
Definition: tree.c:204
TreeHash _t_hash(SemTable *sem, T *t)
Definition: tree.c:1614
int * _t_get_path(T *t)
Definition: tree.c:1384
T * _t_clone(T *t)
Definition: tree.c:589
T * __t_newr(T *parent, Symbol symbol, bool is_run_node)
Definition: tree.c:171
T * _t_root(T *t)
Definition: tree.c:1272
void _t_serialize(SemTable *sem, T *t, void **surfaceP, size_t *sizeP)
Definition: tree.c:1723
T * __t_new(T *t, Symbol symbol, void *surface, size_t size, bool is_run_node)
Definition: tree.c:59
Symbol _t_symbol(T *t)
Definition: tree.c:1228
T * _t_child(T *t, int i)
Definition: tree.c:1251
T * _t_newp(T *parent, Symbol symbol, Process surface)
Definition: tree.c:251
T * _t_swap(T *t, int i, T *r)
Definition: tree.c:418
void _t_pathcpy(int *dst_p, int *src_p)
Definition: tree.c:1424
streams abstraction header file
void _t_insert_at(T *t, int *path, T *i)
Definition: tree.c:438
size_t __t_serialize(SemTable *sem, T *t, void **bufferP, size_t offset, size_t current_size, int compact)
Definition: tree.c:1686
void * _t_surface(T *t)
Definition: tree.c:1215
T * __t_new_str(T *parent, Symbol symbol, char *str, bool is_run_node)
Definition: tree.c:150
T * _t_newt(T *parent, Symbol symbol, T *t)
Definition: tree.c:133
void _t_replace_node(T *t, T *r)
Definition: tree.c:391
T * _t_parent(T *t)
Definition: tree.c:1262
char * _t2rawjson(SemTable *sem, T *t, int level, char *buf)
Definition: tree.c:1785
Defines types and vars for system defined semantics.
void * _t_get_surface(T *t, int *p)
Definition: tree.c:1492
T * __t_find(T *t, Symbol sym, int start_child)
Definition: tree.c:1328
T * __t_newi64(T *parent, Symbol symbol, long surface, bool is_run_node)
Definition: tree.c:109
T * _t_parse(SemTable *sem, T *parent, char *s,...)
Definition: tree.c:919
int _t_path_equal(int *p1, int *p2)
Definition: tree.c:1350
void _t_add(T *t, T *c)
Definition: tree.c:261
auto-generated system definitions
char * _t2json(SemTable *sem, T *t, int level, char *buf)
Definition: tree.c:1912
void __t_morph(T *t, Symbol s, void *surface, size_t length, int allocate)
Definition: tree.c:325
int _t_children(T *t)
Definition: tree.c:1205
void _t_replace(T *t, int i, T *r)
Definition: tree.c:372
void _t_detach_by_ptr(T *t, T *c)
Definition: tree.c:291
void _t_free(T *t)
Definition: tree.c:526
T * __t_news(T *parent, Symbol symbol, SemanticID surface, bool is_run_node)
Definition: tree.c:121
T * _t_build(SemTable *sem, T *t,...)
Definition: tree.c:635
T * _t_getv(T *t,...)
Definition: tree.c:1470
size_t _t_size(T *t)
Definition: tree.c:1238
T * __t_newc(T *t, Symbol symbol, char c, bool is_run_node)
Definition: tree.c:85
T * _t_new_cptr(T *parent, Symbol symbol, void *s)
Definition: tree.c:239
char * _t_sprint_path(int *fp, char *buf)
Definition: tree.c:1508