[refractor] moved classes into ozulis namespace and created a folder plugins
[ozulis.git] / src / ozulis / ast / clone.cc
blob771608af462b6f4aac5e6c5c545e721d09dbdefe
1 #include <ozulis/core/assert.hh>
2 #include <ozulis/ast/ast.hh>
3 #include "clone.hh"
5 namespace ozulis
7 namespace ast
9 #define NB_ENTRIES 100
11 typedef Node * (*clone_f)(const Node * node);
12 static clone_f cloneTable_g[NB_ENTRIES] = { 0 };
13 static bool init_g = true;
15 static Node * cloneRegisterAddress(const RegisterAddress * node)
17 RegisterAddress * r = new RegisterAddress;
19 r->name = node->name;
20 return r;
23 static Node * cloneSymbol(const Symbol * node)
25 Symbol * s = new Symbol;
27 s->name = node->name;
28 s->address = clone(node->address);
29 s->type = node->type; /* type will not change */
30 return s;
33 static void cloneInit()
35 init_g = false;
37 #define ADD_ENTRY(Type) \
38 do \
39 cloneTable_g[Type::nodeTypeId()] = (clone_f)clone##Type; \
40 while (0)
42 ADD_ENTRY(RegisterAddress);
43 ADD_ENTRY(Symbol);
46 Node * clone(const Node * node)
48 if (init_g)
49 cloneInit();
51 return (cloneTable_g[node->nodeType])(node);