My Project
Loading...
Searching...
No Matches
cpy_ast.h File Reference

copy ast nodes More...

Go to the source code of this file.

Functions

ANN Expcpy_exp (MemPool, const Exp *)
 
ANN Array_Sub cpy_array_sub (MemPool, const Array_Sub)
 
ANN ArgList * cpy_arg_list (MemPool, const ArgList *)
 
ANN SpecializedList * cpy_specialized_list (MemPool, const SpecializedList *)
 
ANN Type_Declcpy_type_decl (MemPool, const Type_Decl *)
 
ANN VariableList * cpy_variable_list (MemPool, const VariableList *)
 
ANN Func_Def cpy_func_def (MemPool, const Func_Def)
 
ANN struct Func_Base_cpy_func_base (MemPool, const struct Func_Base_ *)
 
ANN Class_Def cpy_class_def (MemPool, const Class_Def)
 
ANN Extend_Def cpy_extend_def (MemPool, const Extend_Def)
 
ANN Fptr_Def cpy_fptr_def (MemPool p, const Fptr_Def src)
 
ANN Union_Def cpy_union_def (MemPool, const Union_Def)
 
ANN TmplArgList * cpy_tmplarg_list (MemPool p, const TmplArgList *src)
 
ANN TagList * cpy_taglist (MemPool p, const TagList *src)
 
ANN Tmplcpy_tmpl (MemPool p, const Tmpl *src)
 
ANN Ast cpy_ast (MemPool p, const Ast src)
 
ANN Stmtcpy_stmt3 (MemPool p, const Stmt *)
 

Detailed Description

copy ast nodes

Definition in file cpy_ast.h.

Function Documentation

◆ cpy_arg_list()

ANN ArgList * cpy_arg_list ( MemPool p,
const ArgList * src )

Definition at line 106 of file ast_cpy.c.

106 {
107 ArgList *arg = new_arglist(p, src->len);
108 for(m_uint i = 0; i < src->len; i++) {
109 const Arg _src = arglist_at(src, i);
110 Arg *_arg = arglist_ptr_at(arg, i);
111 cpy_variable(p, &_arg->var, &_src.var);
112 if (_src.exp) _arg->exp = cpy_exp(p, _src.exp);
113 }
114 return arg;
115}
ANN Exp * cpy_exp(MemPool p, const Exp *src)
Definition ast_cpy.c:225
static ANN void cpy_variable(MemPool p, Variable *a, const Variable *src)
Definition ast_cpy.c:101
Definition absyn.h:310
Exp * exp
Definition absyn.h:312
Variable var
Definition absyn.h:311

◆ cpy_array_sub()

ANN Array_Sub cpy_array_sub ( MemPool p,
const Array_Sub src )

Definition at line 26 of file ast_cpy.c.

26 {
27 Array_Sub a = mp_calloc(p, Array_Sub);
28 if (src->exp) a->exp = cpy_exp(p, src->exp);
29 a->depth = src->depth;
30 return a;
31}
array_subscript.
Definition absyn.h:352
uint16_t depth
Definition absyn.h:355
Exp * exp
Definition absyn.h:353

◆ cpy_ast()

ANN Ast cpy_ast ( MemPool p,
const Ast src )

Definition at line 631 of file ast_cpy.c.

631 {
632 Ast a = new_sectionlist(p, src->len);
633 for(m_uint i = 0; i < src->len; i++) {
634 Section * asec = sectionlist_ptr_at(a, i);
635 const Section ssec = sectionlist_at(src, i);
636 cpy_section(p, asec, &ssec);
637 }
638 return a;
639}
struct SectionList * Ast
Definition absyn.h:23
static ANN void cpy_section(MemPool p, Section *const a, const Section *src)
Definition ast_cpy.c:575

◆ cpy_class_def()

ANN Class_Def cpy_class_def ( MemPool p,
const Class_Def src )

Definition at line 621 of file ast_cpy.c.

621 {
622 Class_Def a = mp_calloc(p, Class_Def);
623 cpy_type_def2(p, &a->base, &src->base);
624 if (src->body) a->body = cpy_ast(p, src->body);
625 if (src->traits) a->traits = cpy_taglist(p, src->traits);
626 a->flag = src->flag;
627 a->cflag = src->cflag;
628 return a;
629}
ANN Ast cpy_ast(MemPool p, Ast src)
Definition ast_cpy.c:631
static ANN void cpy_type_def2(MemPool p, Type_Def a, const Type_Def src)
Definition ast_cpy.c:402
ANN TagList * cpy_taglist(MemPool p, const TagList *src)
Definition ast_cpy.c:63
ae_flag flag
Definition absyn.h:884
Ast body
Definition absyn.h:881
enum cflag cflag
Definition absyn.h:883
TagList * traits
Definition absyn.h:882
struct Type_Def_ base
Definition absyn.h:880

◆ cpy_exp()

ANN Exp * cpy_exp ( MemPool p,
const Exp * src )

Definition at line 225 of file ast_cpy.c.

225 {
226 Exp* a = mp_calloc2(p, sizeof(Exp));
227 if (src->next) a->next = cpy_exp(p, src->next);
228 switch (src->exp_type) {
229 case ae_exp_post: // !! naming
230 cpy_exp_postfix(p, &a->d.exp_post, &src->d.exp_post);
231 break;
232 case ae_exp_primary:
233 cpy_prim(p, &a->d.prim, &src->d.prim);
234 break;
235 case ae_exp_decl:
236 cpy_exp_decl(p, &a->d.exp_decl, &src->d.exp_decl);
237 break;
238 case ae_exp_unary:
239 cpy_exp_unary(p, &a->d.exp_unary, &src->d.exp_unary);
240 break;
241 case ae_exp_binary:
242 cpy_exp_binary(p, &a->d.exp_binary, &src->d.exp_binary);
243 break;
244 case ae_exp_cast:
245 cpy_exp_cast(p, &a->d.exp_cast, &src->d.exp_cast);
246 break;
247 case ae_exp_call:
248 cpy_exp_call(p, &a->d.exp_call, &src->d.exp_call);
249 break;
250 case ae_exp_if:
251 cpy_exp_if(p, &a->d.exp_if, &src->d.exp_if);
252 break;
253 case ae_exp_dot:
254 cpy_exp_dot(p, &a->d.exp_dot, &src->d.exp_dot);
255 break;
256 case ae_exp_array:
257 cpy_exp_array(p, &a->d.exp_array, &src->d.exp_array);
258 break;
259 case ae_exp_slice:
260 cpy_exp_slice(p, &a->d.exp_slice, &src->d.exp_slice);
261 break;
262 case ae_exp_lambda:
263 cpy_exp_lambda(p, &a->d.exp_lambda, &src->d.exp_lambda);
264 break;
265 case ae_exp_td:
266 a->d.exp_td = cpy_type_decl(p, src->d.exp_td);
267 break;
268 case ae_exp_named:
269 a->d.exp_named.exp = cpy_exp(p, src->d.exp_named.exp);
270 }
271 a->exp_type = src->exp_type;
272 a->emit_var = src->emit_var;
273 // a->meta = src->meta;// maybe meta shoyuld be set as in constructors
274 a->loc = src->loc;
275 return a;
276}
@ ae_exp_unary
Definition absyn.h:402
@ ae_exp_binary
Definition absyn.h:401
@ ae_exp_post
Definition absyn.h:405
@ ae_exp_dot
Definition absyn.h:410
@ ae_exp_call
Definition absyn.h:406
@ ae_exp_decl
Definition absyn.h:400
@ ae_exp_primary
Definition absyn.h:403
@ ae_exp_if
Definition absyn.h:409
@ ae_exp_lambda
Definition absyn.h:411
@ ae_exp_td
Definition absyn.h:412
@ ae_exp_cast
Definition absyn.h:404
@ ae_exp_slice
Definition absyn.h:408
@ ae_exp_array
Definition absyn.h:407
@ ae_exp_named
Definition absyn.h:413
static ANN void cpy_exp_slice(MemPool p, Exp_Slice *a, const Exp_Slice *src)
Definition ast_cpy.c:45
ANN Type_Decl * cpy_type_decl(MemPool p, const Type_Decl *src)
Definition ast_cpy.c:50
static ANN void cpy_exp_if(MemPool p, Exp_If *a, const Exp_If *src)
Definition ast_cpy.c:190
static ANN void cpy_exp_call(MemPool p, Exp_Call *a, const Exp_Call *src)
Definition ast_cpy.c:166
static ANN void cpy_exp_dot(MemPool p, Exp_Dot *a, const Exp_Dot *src)
Definition ast_cpy.c:16
static ANN void cpy_exp_unary(MemPool p, Exp_Unary *a, const Exp_Unary *src)
Definition ast_cpy.c:206
static ANN void cpy_prim(MemPool p, Exp_Primary *a, const Exp_Primary *src)
Definition ast_cpy.c:122
static ANN void cpy_exp_lambda(MemPool p, Exp_Lambda *a, const Exp_Lambda *src)
Definition ast_cpy.c:21
static ANN void cpy_exp_binary(MemPool p, Exp_Binary *a, const Exp_Binary *src)
Definition ast_cpy.c:177
static ANN void cpy_exp_decl(MemPool p, Exp_Decl *a, const Exp_Decl *src)
Definition ast_cpy.c:117
static ANN void cpy_exp_postfix(MemPool p, Exp_Postfix *a, const Exp_Postfix *src)
Definition ast_cpy.c:184
static ANN void cpy_exp_cast(MemPool p, Exp_Cast *a, const Exp_Cast *src)
Definition ast_cpy.c:172
static ANN void cpy_exp_array(MemPool p, Exp_Array *a, const Exp_Array *src)
Definition ast_cpy.c:40
Exp * exp
Definition absyn.h:539
Definition absyn.h:559
int16_t emit_var
Definition absyn.h:583
ae_exp_t exp_type
Definition absyn.h:582
union Exp::exp_data d
loc_t loc
Definition absyn.h:581
Exp * next
Definition absyn.h:578
Exp_Lambda exp_lambda
Definition absyn.h:572
Exp_Named exp_named
Definition absyn.h:574
Exp_Decl exp_decl
Definition absyn.h:563
Exp_Array exp_array
Definition absyn.h:570
Exp_Unary exp_unary
Definition absyn.h:564
Exp_Cast exp_cast
Definition absyn.h:566
Exp_Postfix exp_post
Definition absyn.h:561
Exp_Primary prim
Definition absyn.h:562
Exp_Binary exp_binary
Definition absyn.h:565
Exp_Dot exp_dot
Definition absyn.h:569
Exp_Call exp_call
Definition absyn.h:567
Exp_Slice exp_slice
Definition absyn.h:571
Exp_If exp_if
Definition absyn.h:568
Type_Decl * exp_td
Definition absyn.h:573

◆ cpy_extend_def()

ANN Extend_Def cpy_extend_def ( MemPool p,
const Extend_Def src )

Definition at line 614 of file ast_cpy.c.

614 {
615 Extend_Def a = mp_calloc(p, Extend_Def);
616 a->traits = cpy_taglist(p, src->traits);
617 a->td = cpy_type_decl(p, src->td);
618 return a;
619}
Type_Decl * td
Definition absyn.h:865
TagList * traits
Definition absyn.h:866

◆ cpy_fptr_def()

ANN Fptr_Def cpy_fptr_def ( MemPool p,
const Fptr_Def src )

Definition at line 396 of file ast_cpy.c.

396 {
397 Fptr_Def a = mp_calloc(p, Fptr_Def);
398 a->base = cpy_func_base(p, src->base);
399 return a;
400}
ANN Func_Base * cpy_func_base(MemPool p, const Func_Base *src)
Definition ast_cpy.c:383
Func_Base * base
Definition absyn.h:749

◆ cpy_func_base()

ANN struct Func_Base_ * cpy_func_base ( MemPool ,
const struct Func_Base_ *  )

◆ cpy_func_def()

ANN Func_Def cpy_func_def ( MemPool p,
const Func_Def src )

Definition at line 534 of file ast_cpy.c.

534 {
535 Func_Def a = mp_calloc(p, Func_Def);
536 a->base = cpy_func_base(p, src->base);
537 if (src->d.code) {
538 if(!src->builtin && src->d.code) a->d.code = cpy_stmt_list(p, src->d.code);
539 else a->d.dl_func_ptr = src->d.dl_func_ptr;
540 }
541 if (src->captures) a->captures = cpy_captures(p, src->captures);
542 // a->trait = src->trait;
543 a->builtin = src->builtin;
544 return a;
545}
static ANN CaptureList * cpy_captures(MemPool p, const CaptureList *src)
Definition ast_cpy.c:196
static ANN StmtList * cpy_stmt_list(MemPool p, const StmtList *src)
Definition ast_cpy.c:547
bool builtin
Definition absyn.h:787
union Func_Def_::func_def_data d
Func_Base * base
Definition absyn.h:779
CaptureList * captures
Definition absyn.h:784

◆ cpy_specialized_list()

ANN SpecializedList * cpy_specialized_list ( MemPool p,
const SpecializedList * src )

Definition at line 72 of file ast_cpy.c.

72 {
73 SpecializedList *tgt = new_specializedlist(p, src->len);
74 for(uint32_t i = 0; i < src->len; i++) {
75 const Specialized _src = specializedlist_at(src, i);
76 Specialized *_tgt = specializedlist_ptr_at(tgt, i);
77 _tgt->tag = _src.tag;
78 if (_src.td) _tgt->td = cpy_type_decl(p, _src.td);
79 if (_src.traits) _tgt->traits = cpy_taglist(p, _src.traits);
80 }
81 return tgt;
82}
Tag tag
Definition absyn.h:387
Type_Decl * td
Definition absyn.h:388
TagList * traits
Definition absyn.h:389

◆ cpy_stmt3()

ANN Stmt * cpy_stmt3 ( MemPool p,
const Stmt * src )

Definition at line 440 of file ast_cpy.c.

440 {
441 Stmt* a = mp_calloc2(p, sizeof(Stmt));
442 memcpy(a, src, sizeof(Stmt));
443 return a;
444}
Definition absyn.h:187

◆ cpy_taglist()

ANN TagList * cpy_taglist ( MemPool p,
const TagList * src )

Definition at line 63 of file ast_cpy.c.

63 {
64 TagList *a = new_taglist(p, src->len);
65 for(uint32_t i = 0; i < src->len; i++) {
66 const Tag tag = taglist_at(src, i);
67 taglist_set(a, i, tag);
68 }
69 return a;
70}
Definition absyn.h:25

◆ cpy_tmpl()

ANN Tmpl * cpy_tmpl ( MemPool p,
const Tmpl * src )

Definition at line 155 of file ast_cpy.c.

155 {
156 Tmpl *a = mp_calloc(p, Tmpl);
157 if (!src->call)
158 a->list = cpy_specialized_list(p, src->list);
159 else {
160 a->list = src->list;
161 a->call = cpy_tmplarg_list(p, src->call);
162 }
163 return a;
164}
ANN TmplArgList * cpy_tmplarg_list(MemPool p, const TmplArgList *src)
Definition ast_cpy.c:91
ANN SpecializedList * cpy_specialized_list(MemPool p, const SpecializedList *src)
Definition ast_cpy.c:72
Definition absyn.h:478
SpecializedList * list
Definition absyn.h:479
TmplArgList * call
Definition absyn.h:480

◆ cpy_tmplarg_list()

ANN TmplArgList * cpy_tmplarg_list ( MemPool p,
const TmplArgList * src )

Definition at line 91 of file ast_cpy.c.

91 {
92 TmplArgList *a = new_tmplarglist(p, src->len);
93 for(uint32_t i = 0; i < src->len; i++) {
94 const TmplArg _src = tmplarglist_at(src, i);
95 TmplArg *_tgt = tmplarglist_ptr_at(a, i);
96 cpy_tmplarg(p, &_src, _tgt);
97 }
98 return a;
99}
ANN void cpy_tmplarg(MemPool p, const TmplArg *src, TmplArg *tgt)
Definition ast_cpy.c:84

◆ cpy_type_decl()

ANN Type_Decl * cpy_type_decl ( MemPool p,
const Type_Decl * src )

Definition at line 50 of file ast_cpy.c.

50 {
51 Type_Decl *a = mp_calloc(p, Type_Decl);
52 a->tag = src->tag;
53 if (src->array) a->array = cpy_array_sub(p, src->array); // 1
54 if (src->types) a->types = cpy_tmplarg_list(p, src->types); // 1
55 a->flag = src->flag; // 1
56 if (src->next) a->next = cpy_type_decl(p, src->next);
57 if (src->fptr) a->fptr = cpy_fptr_def(p, src->fptr);
58 a->option = src->option;
59 a->ref = src->ref;
60 return a;
61}
ANN Array_Sub cpy_array_sub(MemPool p, const Array_Sub src)
Definition ast_cpy.c:26
ANN Fptr_Def cpy_fptr_def(MemPool p, const Fptr_Def src)
Definition ast_cpy.c:396
Tag tag
Definition absyn.h:279
Type_Decl * next
Definition absyn.h:282
ae_flag flag
Definition absyn.h:285
TmplArgList * types
Definition absyn.h:281
Array_Sub array
Definition absyn.h:280
bool ref
Definition absyn.h:286
uint8_t option
Definition absyn.h:284
Fptr_Def fptr
Definition absyn.h:283

◆ cpy_union_def()

ANN Union_Def cpy_union_def ( MemPool p,
const Union_Def src )

Definition at line 425 of file ast_cpy.c.

425 {
426 Union_Def a = mp_calloc(p, Union_Def);
427 a->tag = src->tag;
428 a->l = cpy_variable_list(p, src->l);
429 if (src->tmpl) a->tmpl = cpy_tmpl(p, src->tmpl);
430 a->flag = src->flag;
431 return a;
432}
ANN Tmpl * cpy_tmpl(MemPool p, const Tmpl *src)
Definition ast_cpy.c:155
ANN VariableList * cpy_variable_list(MemPool p, const VariableList *src)
Definition ast_cpy.c:415
Tmpl * tmpl
Definition absyn.h:772
Tag tag
Definition absyn.h:770
ae_flag flag
Definition absyn.h:773
VariableList * l
Definition absyn.h:769

◆ cpy_variable_list()

ANN VariableList * cpy_variable_list ( MemPool p,
const VariableList * src )

Definition at line 415 of file ast_cpy.c.

415 {
416 VariableList *a = new_variablelist(p, src->len);
417 for(uint32_t i = 0; i < src->len; i++) {
418 const Variable _src = variablelist_at(src, i);
419 Variable *_tgt = variablelist_ptr_at(a, i);
420 cpy_variable(p, _tgt, &_src);
421 }
422 return a;
423}
variable declaration
Definition absyn.h:244