/
struct.v
755 lines (749 loc) · 20.5 KB
/
struct.v
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module parser
import v.ast
import v.token
import v.util
fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
p.top_level_statement_start()
// save attributes, they will be changed later in fields
attrs := p.attrs
start_pos := p.tok.pos()
mut is_pub := p.tok.kind == .key_pub
if is_pub {
p.next()
}
if is_anon {
is_pub = true
}
is_union := p.tok.kind == .key_union
if p.tok.kind == .key_struct {
p.next()
} else {
p.check(.key_union)
}
language := if p.tok.lit == 'C' && p.peek_tok.kind == .dot {
ast.Language.c
} else if p.tok.lit == 'JS' && p.peek_tok.kind == .dot {
ast.Language.js
} else if p.tok.lit == 'WASM' && p.peek_tok.kind == .dot {
ast.Language.wasm
} else {
ast.Language.v
}
if language != .v {
p.next() // C || JS
p.next() // .
}
name_pos := p.tok.pos()
p.check_for_impure_v(language, name_pos)
if p.disallow_declarations_in_script_mode() {
return ast.StructDecl{}
}
mut name := if is_anon {
p.table.anon_struct_counter++
'_VAnonStruct${p.table.anon_struct_counter}'
} else {
p.check_name()
}
if name.len == 1 && name[0].is_capital() {
p.error_with_pos('single letter capital names are reserved for generic template types.',
name_pos)
return ast.StructDecl{}
}
if name == 'IError' && p.mod != 'builtin' {
p.error_with_pos('cannot register struct `IError`, it is builtin interface type',
name_pos)
}
// append module name before any type of parsing to enable recursion parsing
p.table.start_parsing_type(p.prepend_mod(name))
defer {
p.table.reset_parsing_type()
}
generic_types, _ := p.parse_generic_types()
no_body := p.tok.kind != .lcbr
if language == .v && no_body {
p.error('`${p.tok.lit}` lacks body')
return ast.StructDecl{}
}
if name.len == 1 {
p.error_with_pos('struct names must have more than one character', name_pos)
return ast.StructDecl{}
}
if name in p.imported_symbols {
p.error_with_pos('cannot register struct `${name}`, this type was already imported',
name_pos)
return ast.StructDecl{}
}
mut orig_name := name
if language == .c {
name = 'C.${name}'
orig_name = name
} else if language == .js {
name = 'JS.${name}'
orig_name = name
} else if language == .wasm {
name = 'WASM.${name}'
orig_name = name
} else {
name = p.prepend_mod(name)
}
mut ast_fields := []ast.StructField{}
mut fields := []ast.StructField{}
mut embed_types := []ast.Type{}
mut embeds := []ast.Embed{}
mut embed_field_names := []string{}
mut mut_pos := -1
mut pub_pos := -1
mut pub_mut_pos := -1
mut global_pos := -1
mut module_pos := -1
mut is_field_mut := false
mut is_field_pub := false
mut is_field_global := false
mut last_line := p.prev_tok.pos().line_nr + 1
mut pre_comments := []ast.Comment{}
mut end_comments := []ast.Comment{}
if !no_body {
p.check(.lcbr)
pre_comments = p.eat_comments()
mut i := 0
for p.tok.kind != .rcbr {
mut comments := []ast.Comment{}
for p.tok.kind == .comment {
comments << p.comment()
if p.tok.kind == .rcbr {
break
}
}
if p.tok.kind == .rcbr {
end_comments = p.eat_comments(same_line: true)
break
}
if p.tok.kind == .key_pub {
p.next()
if p.tok.kind == .key_mut {
if pub_mut_pos != -1 {
p.error('redefinition of `pub mut` section')
return ast.StructDecl{}
}
p.next()
pub_mut_pos = ast_fields.len
is_field_pub = true
is_field_mut = true
is_field_global = false
} else {
if pub_pos != -1 {
p.error('redefinition of `pub` section')
return ast.StructDecl{}
}
pub_pos = ast_fields.len
is_field_pub = true
is_field_mut = false
is_field_global = false
}
p.check(.colon)
} else if p.tok.kind == .key_mut {
if mut_pos != -1 {
p.error('redefinition of `mut` section')
return ast.StructDecl{}
}
p.next()
p.check(.colon)
mut_pos = ast_fields.len
is_field_pub = false
is_field_mut = true
is_field_global = false
} else if p.tok.kind == .key_global {
if global_pos != -1 {
p.error('redefinition of `global` section')
return ast.StructDecl{}
}
p.next()
p.check(.colon)
global_pos = ast_fields.len
is_field_pub = true
is_field_mut = true
is_field_global = true
} else if p.tok.kind == .key_module {
if module_pos != -1 {
p.error('redefinition of `module` section')
return ast.StructDecl{}
}
p.next()
p.check(.colon)
module_pos = ast_fields.len
is_field_pub = false
is_field_mut = false
is_field_global = false
}
for p.tok.kind == .comment {
comments << p.comment()
if p.tok.kind == .rcbr {
break
}
}
field_start_pos := p.tok.pos()
mut is_field_volatile := false
mut is_field_deprecated := false
if p.tok.kind == .key_volatile {
p.next()
is_field_volatile = true
}
is_embed := ((p.tok.lit.len > 1 && p.tok.lit[0].is_capital()
&& (p.peek_tok.line_nr != p.tok.line_nr || p.peek_tok.kind !in [.name, .amp])
&& (p.peek_tok.kind != .lsbr || p.peek_token(2).kind != .rsbr))
|| p.peek_tok.kind == .dot) && language == .v && p.peek_tok.kind != .key_fn
is_on_top := ast_fields.len == 0 && !(is_field_pub || is_field_mut || is_field_global)
mut field_name := ''
mut typ := ast.Type(0)
mut type_pos := token.Pos{}
mut field_pos := token.Pos{}
mut option_pos := token.Pos{}
if is_embed {
// struct embedding
type_pos = p.tok.pos()
typ = p.parse_type()
comments << p.eat_comments()
type_pos = type_pos.extend(p.prev_tok.pos())
if !is_on_top {
p.error_with_pos('struct embedding must be declared at the beginning of the struct body',
type_pos)
return ast.StructDecl{}
}
sym := p.table.sym(typ)
if typ in embed_types {
p.error_with_pos('cannot embed `${sym.name}` more than once', type_pos)
return ast.StructDecl{}
}
field_name = sym.embed_name()
if field_name in embed_field_names {
p.error_with_pos('duplicate field `${field_name}`', type_pos)
return ast.StructDecl{}
}
if p.tok.kind == .lsbr {
p.error('cannot use attributes on embedded structs')
}
embed_field_names << field_name
embed_types << typ
embeds << ast.Embed{
typ: typ
pos: type_pos
comments: comments
}
} else {
// struct field
field_name = p.check_name()
for p.tok.kind == .comment {
comments << p.comment()
if p.tok.kind == .rcbr {
break
}
}
p.inside_struct_field_decl = true
if p.tok.kind == .key_struct {
// Anon structs
if p.tok.kind == .key_struct {
p.anon_struct_decl = p.struct_decl(true)
// Find the registered anon struct type, it was registered above in `p.struct_decl()`
typ = p.table.find_type_idx(p.anon_struct_decl.name)
}
} else {
start_type_pos := p.tok.pos()
typ = p.parse_type()
type_pos = start_type_pos.extend(p.prev_tok.pos())
}
p.inside_struct_field_decl = false
if typ.idx() == 0 {
// error is set in parse_type
return ast.StructDecl{}
}
field_pos = field_start_pos.extend(p.prev_tok.pos())
if typ.has_flag(.option) || typ.has_flag(.result) {
option_pos = p.peek_token(-2).pos()
}
}
// Comments after type (same line)
prev_attrs := p.attrs
p.attrs = []
if p.tok.kind == .lsbr || p.tok.kind == .at {
p.inside_struct_attr_decl = true
// attrs are stored in `p.attrs`
p.attributes()
for fa in p.attrs {
if fa.name == 'deprecated' {
is_field_deprecated = true
}
}
p.inside_struct_attr_decl = false
}
comments << p.eat_comments()
mut default_expr := ast.empty_expr
mut has_default_expr := false
if !is_embed {
if p.tok.kind == .assign {
// Default value
p.next()
default_expr = p.expr(0)
match mut default_expr {
ast.EnumVal { default_expr.typ = typ }
// TODO: implement all types??
else {}
}
has_default_expr = true
comments << p.eat_comments()
}
ast_fields << ast.StructField{
name: field_name
typ: typ
pos: field_pos
type_pos: type_pos
option_pos: option_pos
comments: comments
i: i
default_expr: default_expr
has_default_expr: has_default_expr
attrs: p.attrs
is_pub: is_embed || is_field_pub
is_mut: is_embed || is_field_mut
is_global: is_field_global
is_volatile: is_field_volatile
is_deprecated: is_field_deprecated
anon_struct_decl: p.anon_struct_decl
}
}
// save embeds as table fields too, it will be used in generation phase
fields << ast.StructField{
name: field_name
typ: typ
pos: field_pos
type_pos: type_pos
option_pos: option_pos
comments: comments
i: i
default_expr: default_expr
has_default_expr: has_default_expr
attrs: p.attrs
is_pub: is_embed || is_field_pub
is_mut: is_embed || is_field_mut
is_global: is_field_global
is_volatile: is_field_volatile
is_deprecated: is_field_deprecated
anon_struct_decl: p.anon_struct_decl
}
p.anon_struct_decl = ast.StructDecl{}
p.attrs = prev_attrs
i++
}
p.top_level_statement_end()
last_line = p.tok.line_nr
p.check(.rcbr)
end_comments = p.eat_comments(same_line: true)
}
is_minify := attrs.contains('minify')
mut sym := ast.TypeSymbol{
kind: .struct_
language: language
name: name
cname: util.no_dots(name)
mod: p.mod
info: ast.Struct{
embeds: embed_types
fields: fields
is_typedef: attrs.contains('typedef')
is_union: is_union
is_heap: attrs.contains('heap')
is_minify: is_minify
is_generic: generic_types.len > 0
generic_types: generic_types
attrs: attrs
is_anon: is_anon
}
is_pub: is_pub
}
if p.table.has_deep_child_no_ref(&sym, name) {
p.error_with_pos('invalid recursive struct `${orig_name}`', name_pos)
return ast.StructDecl{}
}
mut ret := p.table.register_sym(sym)
if is_anon {
p.table.register_anon_struct(name, ret)
}
// allow duplicate c struct declarations
if ret == -1 && language != .c {
p.error_with_pos('cannot register struct `${name}`, another type with this name exists',
name_pos)
return ast.StructDecl{}
}
p.expr_mod = ''
return ast.StructDecl{
name: name
is_pub: is_pub
fields: ast_fields
pos: start_pos.extend_with_last_line(name_pos, last_line)
mut_pos: mut_pos
pub_pos: pub_pos
pub_mut_pos: pub_mut_pos
global_pos: global_pos
module_pos: module_pos
language: language
is_union: is_union
attrs: if is_anon { []ast.Attr{} } else { attrs } // anon structs can't have attributes
pre_comments: pre_comments
end_comments: end_comments
generic_types: generic_types
embeds: embeds
}
}
fn (mut p Parser) struct_init(typ_str string, kind ast.StructInitKind, is_option bool) ast.StructInit {
first_pos := (if kind == .short_syntax && p.prev_tok.kind == .lcbr { p.prev_tok } else { p.tok }).pos()
p.struct_init_generic_types = []ast.Type{}
mut typ := if kind == .short_syntax { ast.void_type } else { p.parse_type() }
struct_init_generic_types := p.struct_init_generic_types.clone()
if is_option {
typ = typ.set_flag(.option)
}
p.expr_mod = ''
if kind != .short_syntax {
p.check(.lcbr)
}
pre_comments := p.eat_comments()
mut init_fields := []ast.StructInitField{}
mut i := 0
no_keys := p.peek_tok.kind != .colon && p.tok.kind != .rcbr && p.tok.kind != .ellipsis // `Vec{a,b,c}
saved_is_amp := p.is_amp
p.is_amp = false
mut update_expr := ast.empty_expr
mut update_expr_comments := []ast.Comment{}
mut has_update_expr := false
mut update_expr_pos := token.Pos{}
for p.tok.kind !in [.rcbr, .rpar, .eof] {
mut field_name := ''
mut expr := ast.empty_expr
mut field_pos := token.Pos{}
mut first_field_pos := token.Pos{}
mut comments := []ast.Comment{}
mut nline_comments := []ast.Comment{}
is_update_expr := init_fields.len == 0 && p.tok.kind == .ellipsis
if no_keys {
// name will be set later in checker
expr = p.expr(0)
field_pos = expr.pos()
first_field_pos = field_pos
comments = p.eat_comments(same_line: true)
} else if is_update_expr {
// struct updating syntax; f2 := Foo{ ...f, name: 'f2' }
update_expr_pos = p.tok.pos()
p.check(.ellipsis)
update_expr = p.expr(0)
update_expr_comments << p.eat_comments(same_line: true)
has_update_expr = true
} else {
first_field_pos = p.tok.pos()
field_name = p.check_name()
p.check(.colon)
expr = p.expr(0)
comments = p.eat_comments(same_line: true)
last_field_pos := expr.pos()
field_len := if last_field_pos.len > 0 {
last_field_pos.pos - first_field_pos.pos + last_field_pos.len
} else {
first_field_pos.len + 1
}
field_pos = token.Pos{
line_nr: first_field_pos.line_nr
pos: first_field_pos.pos
len: field_len
col: first_field_pos.col
}
}
i++
if p.tok.kind == .comma {
p.next()
}
comments << p.eat_comments(same_line: true)
nline_comments << p.eat_comments()
if !is_update_expr {
init_fields << ast.StructInitField{
name: field_name
expr: expr
pos: field_pos
name_pos: first_field_pos
comments: comments
next_comments: nline_comments
parent_type: typ
}
}
}
if kind != .short_syntax {
p.check(.rcbr)
}
p.is_amp = saved_is_amp
return ast.StructInit{
unresolved: typ.has_flag(.generic)
typ_str: typ_str
typ: typ
init_fields: init_fields
update_expr: update_expr
update_expr_pos: update_expr_pos
update_expr_comments: update_expr_comments
has_update_expr: has_update_expr
name_pos: first_pos
pos: first_pos.extend(if kind == .short_syntax { p.tok.pos() } else { p.prev_tok.pos() })
no_keys: no_keys
is_short_syntax: kind == .short_syntax
is_anon: kind == .anon
pre_comments: pre_comments
generic_types: struct_init_generic_types
}
}
fn (mut p Parser) interface_decl() ast.InterfaceDecl {
p.top_level_statement_start()
mut pos := p.tok.pos()
attrs := p.attrs
is_pub := p.tok.kind == .key_pub
if is_pub {
p.next()
}
p.next() // `interface`
language := if p.tok.lit == 'C' && p.peek_tok.kind == .dot {
ast.Language.c
} else if p.tok.lit == 'JS' && p.peek_tok.kind == .dot {
ast.Language.js
} else {
ast.Language.v
}
if language != .v {
p.next() // C || JS | WASM
p.next() // .
}
name_pos := p.tok.pos()
p.check_for_impure_v(language, name_pos)
if p.disallow_declarations_in_script_mode() {
return ast.InterfaceDecl{}
}
modless_name := p.check_name()
if modless_name.len == 1 && modless_name[0].is_capital() {
p.error_with_pos('single letter capital names are reserved for generic template types.',
name_pos)
return ast.InterfaceDecl{}
}
if modless_name == 'IError' && p.mod != 'builtin' {
p.error_with_pos('cannot register interface `IError`, it is builtin interface type',
name_pos)
}
mut interface_name := ''
if language == .js {
interface_name = 'JS.' + modless_name
} else {
interface_name = p.prepend_mod(modless_name)
}
generic_types, _ := p.parse_generic_types()
// println('interface decl $interface_name')
p.check(.lcbr)
pre_comments := p.eat_comments()
if modless_name in p.imported_symbols {
p.error_with_pos('cannot register interface `${interface_name}`, this type was already imported',
name_pos)
return ast.InterfaceDecl{}
}
// Declare the type
reg_idx := p.table.register_sym(
is_pub: is_pub
kind: .interface_
name: interface_name
cname: util.no_dots(interface_name)
mod: p.mod
info: ast.Interface{
types: []
is_generic: generic_types.len > 0
generic_types: generic_types
}
language: language
)
if reg_idx == -1 {
p.error_with_pos('cannot register interface `${interface_name}`, another type with this name exists',
name_pos)
return ast.InterfaceDecl{}
}
typ := ast.new_type(reg_idx)
mut ts := p.table.sym(typ)
mut info := ts.info as ast.Interface
// if methods were declared before, it's an error, ignore them
ts.methods = []ast.Fn{cap: 20}
// Parse fields or methods
mut fields := []ast.StructField{cap: 20}
mut methods := []ast.FnDecl{cap: 20}
mut embeds := []ast.InterfaceEmbedding{}
mut is_mut := false
mut mut_pos := -1
for p.tok.kind != .rcbr && p.tok.kind != .eof {
// check embedded interface from internal module
if p.tok.kind == .name && p.tok.lit.len > 0 && p.tok.lit[0].is_capital()
&& (p.peek_tok.line_nr != p.tok.line_nr
|| p.peek_tok.kind !in [.name, .amp, .lsbr, .lpar]
|| (p.peek_tok.kind == .lsbr && p.peek_tok.is_next_to(p.tok))) {
iface_pos := p.tok.pos()
mut iface_name := p.tok.lit
iface_type := p.parse_type()
if iface_name == 'JS' {
iface_name = p.table.sym(iface_type).name
}
comments := p.eat_comments()
embeds << ast.InterfaceEmbedding{
name: iface_name
typ: iface_type
pos: iface_pos
comments: comments
}
if p.tok.kind == .rcbr {
break
}
continue
}
// check embedded interface from external module
if p.tok.kind == .name && p.peek_tok.kind == .dot {
if p.tok.lit !in p.imports {
p.error_with_pos('mod `${p.tok.lit}` not imported', p.tok.pos())
break
}
mod_name := p.tok.lit
from_mod_typ := p.parse_type()
from_mod_name := '${mod_name}.${p.prev_tok.lit}'
if from_mod_name.is_lower() {
p.error_with_pos('the interface name need to have the pascal case', p.prev_tok.pos())
break
}
comments := p.eat_comments()
embeds << ast.InterfaceEmbedding{
name: from_mod_name
typ: from_mod_typ
pos: p.prev_tok.pos()
comments: comments
}
if p.tok.kind == .rcbr {
break
}
continue
}
if p.tok.kind == .key_mut {
if is_mut {
p.error_with_pos('redefinition of `mut` section', p.tok.pos())
return ast.InterfaceDecl{}
}
p.next()
p.check(.colon)
is_mut = true
mut_pos = fields.len
}
if p.peek_tok.kind in [.lt, .lsbr] && p.peek_tok.is_next_to(p.tok) {
p.error_with_pos("no need to add generic type names in generic interface's method",
p.peek_tok.pos())
return ast.InterfaceDecl{}
}
mut comments := p.eat_comments()
if p.peek_tok.kind == .lpar {
method_start_pos := p.tok.pos()
line_nr := p.tok.line_nr
name := p.check_name()
if name in ['type_name', 'type_idx'] {
p.error_with_pos('cannot override built-in method `${name}`', method_start_pos)
return ast.InterfaceDecl{}
}
if ts.has_method(name) {
p.error_with_pos('duplicate method `${name}`', method_start_pos)
return ast.InterfaceDecl{}
}
params_t, _, is_variadic := p.fn_params() // TODO merge ast.Param and ast.Arg to avoid this
mut params := [
ast.Param{
name: 'x'
is_mut: is_mut
typ: typ
is_hidden: true
},
]
params << params_t
mut method := ast.FnDecl{
name: name
short_name: name
mod: p.mod
params: params
file: p.file_name
return_type: ast.void_type
is_variadic: is_variadic
is_pub: true
pos: method_start_pos.extend(p.prev_tok.pos())
scope: p.scope
}
if p.tok.kind.is_start_of_type() && p.tok.line_nr == line_nr {
method.return_type_pos = p.tok.pos()
method.return_type = p.parse_type()
method.return_type_pos = method.return_type_pos.extend(p.tok.pos())
method.pos = method.pos.extend(method.return_type_pos)
}
comments << p.eat_comments(same_line: true)
mnext_comments := p.eat_comments()
method.comments = comments
method.next_comments = mnext_comments
methods << method
tmethod := ast.Fn{
name: name
params: params
pos: method.pos
return_type: method.return_type
is_variadic: is_variadic
is_pub: true
is_method: true
receiver_type: typ
}
ts.register_method(tmethod)
info.methods << tmethod
} else {
// interface fields
field_pos := p.tok.pos()
field_name := p.check_name()
mut type_pos := p.tok.pos()
field_typ := p.parse_type()
type_pos = type_pos.extend(p.prev_tok.pos())
comments << p.eat_comments(same_line: true)
fields << ast.StructField{
name: field_name
pos: field_pos
type_pos: type_pos
typ: field_typ
comments: comments
is_pub: true
}
info.fields << ast.StructField{
name: field_name
typ: field_typ
is_pub: true
is_mut: is_mut
}
}
}
info.embeds = embeds.map(it.typ)
ts.info = info
p.top_level_statement_end()
p.check(.rcbr)
pos = pos.extend_with_last_line(p.prev_tok.pos(), p.prev_tok.line_nr)
res := ast.InterfaceDecl{
name: interface_name
language: language
typ: typ
fields: fields
methods: methods
embeds: embeds
is_pub: is_pub
attrs: attrs
pos: pos
pre_comments: pre_comments
generic_types: generic_types
mut_pos: mut_pos
name_pos: name_pos
}
p.table.register_interface(res)
return res
}