This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathimports_misc.v
155 lines (137 loc) · 2.88 KB
/
imports_misc.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
module analyzer
import os
const (
v_ext = '.v'
user_os = os.user_os()
c_file_suffixes = [
'_windows',
'_linux',
'_macos',
'_darwin',
'_ios',
'_android',
'_freebsd',
'_openbsd',
'_netbsd',
'_dragonfly',
'_solaris',
'_nix',
'_native',
// '.freestanding'
]
os_file_specific_suffix_indices = {
'windows': [0]
'linux': [1, 11]
'macos': [2, 3, 11]
'ios': [4, 11]
'android': [5, 11]
'freebsd': [6, 11]
'openbsd': [7, 11]
'netbsd': [8, 11]
'dragonfly': [9, 11]
'solaris': [10, 11]
}
)
fn should_analyze_file_c(file_name string) bool {
if file_name.ends_with('.js.v') {
return false
}
for os, file_suffix_indices in analyzer.os_file_specific_suffix_indices {
for i in file_suffix_indices {
suffix := analyzer.c_file_suffixes[i]
if file_name.ends_with(suffix + '.v') || file_name.ends_with(suffix + '.c.v') {
if os != analyzer.user_os {
return false
}
return true
}
}
}
return true
}
pub fn should_analyze_file(file_name string) bool {
if !file_name.ends_with('.v') {
return false
}
// TODO: support for JS and ASM
if file_name.ends_with('.js.v') {
return false
}
if file_name.ends_with('_test.v')
|| file_name.all_before_last('.v').all_before_last('.').ends_with('_test') {
return false
}
if !should_analyze_file_c(file_name) {
return false
}
// if file.starts_with('.#') {
// continue
// }
// if file.contains('_d_') {
// if prefs.compile_defines_all.len == 0 {
// continue
// }
// mut allowed := false
// for cdefine in prefs.compile_defines {
// file_postfix := '_d_${cdefine}.v'
// if file.ends_with(file_postfix) {
// allowed = true
// break
// }
// }
// if !allowed {
// continue
// }
// }
// if file.contains('_notd_') {
// mut allowed := true
// for cdefine in prefs.compile_defines {
// file_postfix := '_notd_${cdefine}.v'
// if file.ends_with(file_postfix) {
// allowed = false
// break
// }
// }
// if !allowed {
// continue
// }
// }
return true
}
struct ImportPathIterator {
start_path string
lookup_paths []string
fallback_lookup_paths []string
mut:
idx int
in_start bool = true
in_fallback bool
}
fn (mut iter ImportPathIterator) next() ?string {
if iter.in_start {
defer {
iter.in_start = false
}
return iter.start_path
}
if !iter.in_fallback && iter.idx >= iter.lookup_paths.len {
iter.in_fallback = true
iter.idx = 0
}
if iter.in_fallback && iter.idx >= iter.fallback_lookup_paths.len {
return none
}
defer {
iter.idx++
}
return if !iter.in_fallback {
iter.lookup_paths[iter.idx]
} else {
iter.fallback_lookup_paths[iter.idx]
}
}
fn (mut iter ImportPathIterator) reset() {
iter.idx = 0
iter.in_fallback = false
iter.in_start = true
}