diff options
author | Araq <rumpf_a@web.de> | 2012-08-03 22:57:26 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-08-03 22:57:26 +0200 |
commit | a7a2f464a2cdc66b6c7e77545a13913cbe21bf5c (patch) | |
tree | a77de6bcb82fd5da17ead0109de46fbb268e27b3 | |
parent | 344438ce6a71688b178b051a30b1514b2dcadf17 (diff) | |
download | Nim-a7a2f464a2cdc66b6c7e77545a13913cbe21bf5c.tar.gz |
idetools: don't suggest module names or not visible object fields
-rwxr-xr-x | compiler/semexprs.nim | 6 | ||||
-rwxr-xr-x | compiler/suggest.nim | 33 |
2 files changed, 21 insertions, 18 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 4411385b4..21d8ed617 100755 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -866,10 +866,8 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode = if f != nil: break if ty.sons[0] == nil: break ty = skipTypes(ty.sons[0], {tyGenericInst}) - if f != nil: - var fmoduleId = getModule(f).id - if sfExported in f.flags or fmoduleId == c.module.id or - fmoduleId == c.friendModule.id: + if f != nil: + if fieldVisible(c, f): # is the access to a public field or in the same module or in a friend? n.sons[0] = makeDeref(n.sons[0]) n.sons[1] = newSymNode(f) # we now have the correct field diff --git a/compiler/suggest.nim b/compiler/suggest.nim index fb8a74ef5..320548457 100755 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -42,11 +42,16 @@ proc SymToStr(s: PSym, isLocal: bool, section: string, li: TLineInfo): string = proc SymToStr(s: PSym, isLocal: bool, section: string): string = result = SymToStr(s, isLocal, section, s.info) -proc filterSym(s: PSym): bool {.inline.} = - result = s.name.s[0] in lexer.SymChars +proc filterSym(s: PSym): bool {.inline.} = + result = s.name.s[0] in lexer.SymChars and s.kind != skModule -proc suggestField(s: PSym, outputs: var int) = - if filterSym(s): +proc fieldVisible*(c: PContext, f: PSym): bool {.inline.} = + let fmoduleId = getModule(f).id + result = sfExported in f.flags or fmoduleId == c.module.id or + fmoduleId == c.friendModule.id + +proc suggestField(c: PContext, s: PSym, outputs: var int) = + if filterSym(s) and fieldVisible(c, s): OutWriteln(SymToStr(s, isLocal=true, sectionSuggest)) inc outputs @@ -57,22 +62,22 @@ template wholeSymTab(cond, section: expr) {.immediate.} = OutWriteln(SymToStr(it, isLocal = i > ModuleTablePos, section)) inc outputs -proc suggestSymList(list: PNode, outputs: var int) = +proc suggestSymList(c: PContext, list: PNode, outputs: var int) = for i in countup(0, sonsLen(list) - 1): if list.sons[i].kind == nkSym: - suggestField(list.sons[i].sym, outputs) + suggestField(c, list.sons[i].sym, outputs) #else: InternalError(list.info, "getSymFromList") -proc suggestObject(n: PNode, outputs: var int) = +proc suggestObject(c: PContext, n: PNode, outputs: var int) = case n.kind of nkRecList: - for i in countup(0, sonsLen(n)-1): suggestObject(n.sons[i], outputs) + for i in countup(0, sonsLen(n)-1): suggestObject(c, n.sons[i], outputs) of nkRecCase: var L = sonsLen(n) if L > 0: - suggestObject(n.sons[0], outputs) - for i in countup(1, L-1): suggestObject(lastSon(n.sons[i]), outputs) - of nkSym: suggestField(n.sym, outputs) + suggestObject(c, n.sons[0], outputs) + for i in countup(1, L-1): suggestObject(c, lastSon(n.sons[i]), outputs) + of nkSym: suggestField(c, n.sym, outputs) else: nil proc nameFits(c: PContext, s: PSym, n: PNode): bool = @@ -140,7 +145,7 @@ proc suggestFieldAccess(c: PContext, n: PNode, outputs: var int) = # look up if the identifier belongs to the enum: var t = typ while t != nil: - suggestSymList(t.n, outputs) + suggestSymList(c, t.n, outputs) t = t.sons[0] suggestOperations(c, n, typ, outputs) else: @@ -148,12 +153,12 @@ proc suggestFieldAccess(c: PContext, n: PNode, outputs: var int) = if typ.kind == tyObject: var t = typ while true: - suggestObject(t.n, outputs) + suggestObject(c, t.n, outputs) if t.sons[0] == nil: break t = skipTypes(t.sons[0], {tyGenericInst}) suggestOperations(c, n, typ, outputs) elif typ.kind == tyTuple and typ.n != nil: - suggestSymList(typ.n, outputs) + suggestSymList(c, typ.n, outputs) suggestOperations(c, n, typ, outputs) else: suggestOperations(c, n, typ, outputs) |