v2 / vlib / v / fmt / tests / symbol_registration_keep.vv
38 lines · 34 sloc · 1.09 KB · c51d30bf5309653c6b573ec815268e69a78ea8cc
Raw
1module analyzer
2
3import os
4
5const mut_struct_keyword = 'mut:'
6const pub_struct_keyword = 'pub:'
7const pub_mut_struct_keyword = 'pub mut:'
8const global_struct_keyword = '__global:'
9
10struct SymbolRegistration {
11mut:
12 store &Store = &Store(0)
13 cursor TreeCursor
14 module_name string
15 src_text []u8
16 // skips the local scopes and registers only
17 // the top-level ones regardless of its
18 // visibility
19 is_import bool
20 is_script bool
21 first_var_decl_pos C.TSRange
22}
23
24fn (mut sr SymbolRegistration) struct_field_decl(field_access SymbolAccess, field_decl_node C.TSNode) &Symbol {
25 field_type_node := field_decl_node.child_by_field_name('type')
26 field_name_node := field_decl_node.child_by_field_name('name')
27 field_typ := sr.store.find_symbol_by_type_node(field_type_node, sr.src_text) or { void_type }
28 return &Symbol{
29 name: field_name_node.get_text(sr.src_text)
30 kind: .field
31 range: field_name_node.range()
32 access: field_access
33 return_type: field_typ
34 is_top_level: true
35 file_path: sr.store.cur_file_path
36 file_version: sr.store.cur_version
37 }
38}
39