summary refs log tree commit diff stats
path: root/compiler/importer.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/importer.nim')
-rw-r--r--compiler/importer.nim38
1 files changed, 25 insertions, 13 deletions
diff --git a/compiler/importer.nim b/compiler/importer.nim
index f5eb5329d..ffb7e0305 100644
--- a/compiler/importer.nim
+++ b/compiler/importer.nim
@@ -10,10 +10,12 @@
 ## This module implements the symbol importing mechanism.
 
 import
-  intsets, ast, astalgo, msgs, options, idents, lookups,
-  semdata, modulepaths, sigmatch, lineinfos, sets,
-  modulegraphs, wordrecg, tables
-from strutils import `%`
+  ast, astalgo, msgs, options, idents, lookups,
+  semdata, modulepaths, sigmatch, lineinfos,
+  modulegraphs, wordrecg
+from std/strutils import `%`, startsWith
+from std/sequtils import addUnique
+import std/[sets, tables, intsets]
 
 when defined(nimPreviewSlimSystem):
   import std/assertions
@@ -142,7 +144,7 @@ proc importSymbol(c: PContext, n: PNode, fromMod: PSym; importSet: var IntSet) =
     # for an enumeration we have to add all identifiers
     if multiImport:
       # for a overloadable syms add all overloaded routines
-      var it: ModuleIter
+      var it: ModuleIter = default(ModuleIter)
       var e = initModuleIter(it, c.graph, fromMod, s.name)
       while e != nil:
         if e.name.id != s.name.id: internalError(c.config, n.info, "importSymbol: 3")
@@ -229,11 +231,6 @@ proc importForwarded(c: PContext, n: PNode, exceptSet: IntSet; fromMod: PSym; im
     for i in 0..n.safeLen-1:
       importForwarded(c, n[i], exceptSet, fromMod, importSet)
 
-proc addUnique[T](x: var seq[T], y: sink T) {.noSideEffect.} =
-  for i in 0..high(x):
-    if x[i] == y: return
-  x.add y
-    
 proc importModuleAs(c: PContext; n: PNode, realModule: PSym, importHidden: bool): PSym =
   result = realModule
   template createModuleAliasImpl(ident): untyped =
@@ -249,12 +246,14 @@ proc importModuleAs(c: PContext; n: PNode, realModule: PSym, importHidden: bool)
     result = createModuleAliasImpl(realModule.name)
   if importHidden:
     result.options.incl optImportHidden
-  c.unusedImports.add((result, n.info))
+  let moduleIdent = if n.kind == nkInfix: n[^1] else: n
+  c.unusedImports.add((result, moduleIdent.info))
   c.importModuleMap[result.id] = realModule.id
   c.importModuleLookup.mgetOrPut(result.name.id, @[]).addUnique realModule.id
 
 proc transformImportAs(c: PContext; n: PNode): tuple[node: PNode, importHidden: bool] =
-  var ret: typeof(result)
+  result = (nil, false)
+  var ret = default(typeof(result))
   proc processPragma(n2: PNode): PNode =
     let (result2, kws) = splitPragmas(c, n2)
     result = result2
@@ -305,13 +304,26 @@ proc myImportModule(c: PContext, n: var PNode, importStmtResult: PNode): PSym =
       var prefix = ""
       if realModule.constraint != nil: prefix = realModule.constraint.strVal & "; "
       message(c.config, n.info, warnDeprecated, prefix & realModule.name.s & " is deprecated")
-    suggestSym(c.graph, n.info, result, c.graph.usageSym, false)
+    let moduleName = getModuleName(c.config, n)
+    if belongsToStdlib(c.graph, result) and not startsWith(moduleName, stdPrefix) and
+        not startsWith(moduleName, "system/") and not startsWith(moduleName, "packages/"):
+      message(c.config, n.info, warnStdPrefix, realModule.name.s)
+
+    proc suggestMod(n: PNode; s: PSym) =
+      if n.kind == nkImportAs:
+        suggestMod(n[0], realModule)
+      elif n.kind == nkInfix:
+        suggestMod(n[2], s)
+      else:
+        suggestSym(c.graph, n.info, s, c.graph.usageSym, false)
+    suggestMod(n, result)
     importStmtResult.add newSymNode(result, n.info)
     #newStrNode(toFullPath(c.config, f), n.info)
   else:
     result = nil
 
 proc afterImport(c: PContext, m: PSym) =
+  if isCachedModule(c.graph, m): return
   # fixes bug #17510, for re-exported symbols
   let realModuleId = c.importModuleMap[m.id]
   for s in allSyms(c.graph, m):
itter Kartik K. Agaram <vc@akkartik.com> 2015-03-12 22:24:18 -0700 896 - c++: routine' href='/akkartik/mu/commit/cpp/012run?h=hlt&id=1228ec731ead0abec824f469cfc81f59209a2dcb'>1228ec73 ^
7da71d03 ^


9fc64bbc ^
10e449b5 ^
ec926027 ^
9fc64bbc ^

1228ec73 ^
7da71d03 ^
ec926027 ^



decaddb4 ^
ec926027 ^
3ba63579 ^
c7c822b2 ^
d241c9c4 ^








eb7afe5d ^
d241c9c4 ^
9cf71627 ^
6f5d7864 ^
9fc64bbc ^


3c435756 ^


ec926027 ^















e7f76736 ^













3c435756 ^


37e4573b ^
3c435756 ^





b1bbe92d ^
3c435756 ^









e7f76736 ^
fc55fea0 ^
cae5461b ^
916ae8f5 ^
cae5461b ^
c82d0176 ^
a4ef18b1 ^
a26cc359 ^

a4ef18b1 ^
fae70331 ^

b291f85b ^



cae5461b ^


fc55fea0 ^
cae5461b ^
6b6dfb0c ^
3ba63579 ^
fae70331 ^


57699011 ^
b291f85b ^

cae5461b ^

c1a50c82 ^
6b6dfb0c ^
fe67d47a ^
5f0e4762 ^

eaa75c87 ^
decaddb4 ^
6b6dfb0c ^



c82d0176 ^



decaddb4 ^







fc55fea0 ^






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