@@ -125,9 +125,8 @@ final class FirstPass : ASTVisitor
125125 {
126126 assert (dec);
127127 pushSymbol(dec.name.text, CompletionKind.functionName, symbolFile,
128- dec.name.index, dec.returnType);
128+ dec.name.index, dec.returnType, protection.current );
129129 scope (exit) popSymbol();
130- currentSymbol.acSymbol.protection = protection.current;
131130 currentSymbol.acSymbol.doc = makeDocumentation(dec.comment);
132131
133132 istring lastComment = this .lastComment;
@@ -374,6 +373,7 @@ final class FirstPass : ASTVisitor
374373 auto objectImport = allocateSemanticSymbol(IMPORT_SYMBOL_NAME ,
375374 CompletionKind.importSymbol, objectLocation);
376375 objectImport.acSymbol.skipOver = true ;
376+ objectImport.acSymbol.protection = protection.currentForImport;
377377 currentSymbol.addChild(objectImport, true );
378378 currentScope.addSymbol(objectImport.acSymbol, false );
379379 }
@@ -440,6 +440,7 @@ final class FirstPass : ASTVisitor
440440 thisSymbol.symbolFile = symbolFile;
441441 thisSymbol.type = currentSymbol.acSymbol;
442442 thisSymbol.ownType = false ;
443+ thisSymbol.protection = tok! " private" ;
443444 currentScope.addSymbol(thisSymbol, false );
444445
445446 foreach (dec; structBody.declarations)
@@ -471,6 +472,7 @@ final class FirstPass : ASTVisitor
471472 SemanticSymbol* importSymbol = allocateSemanticSymbol(IMPORT_SYMBOL_NAME ,
472473 CompletionKind.importSymbol, modulePath);
473474 importSymbol.acSymbol.skipOver = protection.currentForImport != tok! " public" ;
475+ importSymbol.acSymbol.protection = protection.currentForImport;
474476 if (single.rename == tok! " " )
475477 {
476478 size_t i = 0 ;
@@ -488,6 +490,8 @@ final class FirstPass : ASTVisitor
488490 if (s.length == 0 )
489491 {
490492 currentImportSymbol = GCAllocator.instance.make! DSymbol(ip, kind);
493+ currentImportSymbol.protection = protection.currentForImport;
494+ currentImportSymbol.skipOver = protection.currentForImport != tok! " public" ;
491495 currentScope.addSymbol(currentImportSymbol, true );
492496 if (last)
493497 {
@@ -505,6 +509,8 @@ final class FirstPass : ASTVisitor
505509 if (s.length == 0 )
506510 {
507511 auto sym = GCAllocator.instance.make! DSymbol(ip, kind);
512+ sym.protection = protection.currentForImport;
513+ sym.skipOver = protection.currentForImport != tok! " public" ;
508514 currentImportSymbol.addChild(sym, true );
509515 currentImportSymbol = sym;
510516 if (last)
@@ -527,6 +533,7 @@ final class FirstPass : ASTVisitor
527533 SemanticSymbol* renameSymbol = allocateSemanticSymbol(
528534 internString(single.rename.text), CompletionKind.aliasName,
529535 modulePath);
536+ renameSymbol.acSymbol.protection = protection.currentForImport;
530537 renameSymbol.acSymbol.skipOver = protection.currentForImport != tok! " public" ;
531538 renameSymbol.acSymbol.type = importSymbol.acSymbol;
532539 renameSymbol.acSymbol.ownType = true ;
@@ -544,7 +551,7 @@ final class FirstPass : ASTVisitor
544551 istring modulePath = cache.resolveImportLocation(chain);
545552 if (modulePath is null )
546553 {
547- warning(" Could not resolve location of module '" , chain, " '" );
554+ warning(" Could not resolve location of module '" , chain.data , " '" );
548555 return ;
549556 }
550557
@@ -572,6 +579,7 @@ final class FirstPass : ASTVisitor
572579 importSymbol.acSymbol.qualifier = SymbolQualifier.selectiveImport;
573580 importSymbol.typeLookups.insert(lookup);
574581 importSymbol.acSymbol.skipOver = protection.currentForImport != tok! " public" ;
582+ importSymbol.acSymbol.protection = protection.currentForImport;
575583 currentSymbol.addChild(importSymbol, true );
576584 currentScope.addSymbol(importSymbol.acSymbol, false );
577585 }
@@ -831,10 +839,11 @@ private:
831839 }
832840
833841 void pushSymbol (string name, CompletionKind kind, istring symbolFile,
834- size_t location = 0 , const Type type = null )
842+ size_t location = 0 , const Type type = null ,
843+ const IdType protection = tok! " public" )
835844 {
836845 SemanticSymbol* symbol = allocateSemanticSymbol(name, kind, symbolFile,
837- location);
846+ location, protection );
838847 if (type ! is null )
839848 addTypeToLookups(symbol.typeLookups, type);
840849 symbol.parent = currentSymbol;
@@ -867,14 +876,13 @@ private:
867876 dec.accept(this );
868877 return ;
869878 }
870- pushSymbol(dec.name.text, kind, symbolFile, dec.name.index);
879+ pushSymbol(dec.name.text, kind, symbolFile, dec.name.index, null , protection.current );
871880 scope (exit) popSymbol ();
872881
873882 if (kind == CompletionKind.className)
874883 currentSymbol.acSymbol.addChildren(classSymbols[], false );
875884 else
876885 currentSymbol.acSymbol.addChildren(aggregateSymbols[], false );
877- currentSymbol.acSymbol.protection = protection.current;
878886 currentSymbol.acSymbol.doc = makeDocumentation(dec.comment);
879887
880888 istring lastComment = this .lastComment;
@@ -1092,11 +1100,12 @@ private:
10921100 }
10931101
10941102 SemanticSymbol* allocateSemanticSymbol (string name, CompletionKind kind,
1095- istring symbolFile, size_t location = 0 )
1103+ istring symbolFile, size_t location = 0 , IdType protection = tok ! " public " )
10961104 {
10971105 DSymbol* acSymbol = GCAllocator.instance.make! DSymbol(istring(name), kind);
10981106 acSymbol.location = location;
10991107 acSymbol.symbolFile = symbolFile;
1108+ acSymbol.protection = protection;
11001109 symbolsAllocated++ ;
11011110 return GCAllocator.instance.make! SemanticSymbol(acSymbol);
11021111 }
@@ -1213,17 +1222,19 @@ struct ProtectionStack
12131222
12141223 IdType currentForImport () const
12151224 {
1216- return stack.empty ? tok! " default" : current();
1225+ // Imports are private unless specified otherwise.
1226+ return stack.empty ? tok! " private" : current();
12171227 }
12181228
12191229 IdType current () const
1230+ out (t; isProtection (t), str(t))
1231+ do
12201232 {
12211233 import std.algorithm.iteration : filter;
12221234 import std.range : choose, only;
12231235
1224- IdType retVal;
1225- foreach (t; choose(stack.empty, only (tok! " public" ), stack[]).filter! (
1226- a => a != tok! " {" && a != tok! " :" ))
1236+ IdType retVal = tok! " public" ;
1237+ foreach (t; stack[].filter! (a => a != tok! " {" && a != tok! " :" ))
12271238 retVal = cast (IdType) t;
12281239 return retVal;
12291240 }
@@ -1252,7 +1263,7 @@ struct ProtectionStack
12521263
12531264 void beginLocal (const IdType t)
12541265 {
1255- assert (t != tok ! " " , " DERP! " );
1266+ assert (isProtection(t), str(t) );
12561267 stack.insertBack(t);
12571268 }
12581269
0 commit comments