@@ -125,9 +125,8 @@ final class FirstPass : ASTVisitor
125
125
{
126
126
assert (dec);
127
127
pushSymbol(dec.name.text, CompletionKind.functionName, symbolFile,
128
- dec.name.index, dec.returnType);
128
+ dec.name.index, dec.returnType, protection.current );
129
129
scope (exit) popSymbol();
130
- currentSymbol.acSymbol.protection = protection.current;
131
130
currentSymbol.acSymbol.doc = makeDocumentation(dec.comment);
132
131
133
132
istring lastComment = this .lastComment;
@@ -374,6 +373,7 @@ final class FirstPass : ASTVisitor
374
373
auto objectImport = allocateSemanticSymbol(IMPORT_SYMBOL_NAME ,
375
374
CompletionKind.importSymbol, objectLocation);
376
375
objectImport.acSymbol.skipOver = true ;
376
+ objectImport.acSymbol.protection = protection.currentForImport;
377
377
currentSymbol.addChild(objectImport, true );
378
378
currentScope.addSymbol(objectImport.acSymbol, false );
379
379
}
@@ -440,6 +440,7 @@ final class FirstPass : ASTVisitor
440
440
thisSymbol.symbolFile = symbolFile;
441
441
thisSymbol.type = currentSymbol.acSymbol;
442
442
thisSymbol.ownType = false ;
443
+ thisSymbol.protection = tok! " private" ;
443
444
currentScope.addSymbol(thisSymbol, false );
444
445
445
446
foreach (dec; structBody.declarations)
@@ -471,6 +472,7 @@ final class FirstPass : ASTVisitor
471
472
SemanticSymbol* importSymbol = allocateSemanticSymbol(IMPORT_SYMBOL_NAME ,
472
473
CompletionKind.importSymbol, modulePath);
473
474
importSymbol.acSymbol.skipOver = protection.currentForImport != tok! " public" ;
475
+ importSymbol.acSymbol.protection = protection.currentForImport;
474
476
if (single.rename == tok! " " )
475
477
{
476
478
size_t i = 0 ;
@@ -488,6 +490,8 @@ final class FirstPass : ASTVisitor
488
490
if (s.length == 0 )
489
491
{
490
492
currentImportSymbol = GCAllocator.instance.make! DSymbol(ip, kind);
493
+ currentImportSymbol.protection = protection.currentForImport;
494
+ currentImportSymbol.skipOver = protection.currentForImport != tok! " public" ;
491
495
currentScope.addSymbol(currentImportSymbol, true );
492
496
if (last)
493
497
{
@@ -505,6 +509,8 @@ final class FirstPass : ASTVisitor
505
509
if (s.length == 0 )
506
510
{
507
511
auto sym = GCAllocator.instance.make! DSymbol(ip, kind);
512
+ sym.protection = protection.currentForImport;
513
+ sym.skipOver = protection.currentForImport != tok! " public" ;
508
514
currentImportSymbol.addChild(sym, true );
509
515
currentImportSymbol = sym;
510
516
if (last)
@@ -527,6 +533,7 @@ final class FirstPass : ASTVisitor
527
533
SemanticSymbol* renameSymbol = allocateSemanticSymbol(
528
534
internString(single.rename.text), CompletionKind.aliasName,
529
535
modulePath);
536
+ renameSymbol.acSymbol.protection = protection.currentForImport;
530
537
renameSymbol.acSymbol.skipOver = protection.currentForImport != tok! " public" ;
531
538
renameSymbol.acSymbol.type = importSymbol.acSymbol;
532
539
renameSymbol.acSymbol.ownType = true ;
@@ -544,7 +551,7 @@ final class FirstPass : ASTVisitor
544
551
istring modulePath = cache.resolveImportLocation(chain);
545
552
if (modulePath is null )
546
553
{
547
- warning(" Could not resolve location of module '" , chain, " '" );
554
+ warning(" Could not resolve location of module '" , chain.data , " '" );
548
555
return ;
549
556
}
550
557
@@ -572,6 +579,7 @@ final class FirstPass : ASTVisitor
572
579
importSymbol.acSymbol.qualifier = SymbolQualifier.selectiveImport;
573
580
importSymbol.typeLookups.insert(lookup);
574
581
importSymbol.acSymbol.skipOver = protection.currentForImport != tok! " public" ;
582
+ importSymbol.acSymbol.protection = protection.currentForImport;
575
583
currentSymbol.addChild(importSymbol, true );
576
584
currentScope.addSymbol(importSymbol.acSymbol, false );
577
585
}
@@ -831,10 +839,11 @@ private:
831
839
}
832
840
833
841
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" )
835
844
{
836
845
SemanticSymbol* symbol = allocateSemanticSymbol(name, kind, symbolFile,
837
- location);
846
+ location, protection );
838
847
if (type ! is null )
839
848
addTypeToLookups(symbol.typeLookups, type);
840
849
symbol.parent = currentSymbol;
@@ -867,14 +876,13 @@ private:
867
876
dec.accept(this );
868
877
return ;
869
878
}
870
- pushSymbol(dec.name.text, kind, symbolFile, dec.name.index);
879
+ pushSymbol(dec.name.text, kind, symbolFile, dec.name.index, null , protection.current );
871
880
scope (exit) popSymbol ();
872
881
873
882
if (kind == CompletionKind.className)
874
883
currentSymbol.acSymbol.addChildren(classSymbols[], false );
875
884
else
876
885
currentSymbol.acSymbol.addChildren(aggregateSymbols[], false );
877
- currentSymbol.acSymbol.protection = protection.current;
878
886
currentSymbol.acSymbol.doc = makeDocumentation(dec.comment);
879
887
880
888
istring lastComment = this .lastComment;
@@ -1092,11 +1100,12 @@ private:
1092
1100
}
1093
1101
1094
1102
SemanticSymbol* allocateSemanticSymbol (string name, CompletionKind kind,
1095
- istring symbolFile, size_t location = 0 )
1103
+ istring symbolFile, size_t location = 0 , IdType protection = tok ! " public " )
1096
1104
{
1097
1105
DSymbol* acSymbol = GCAllocator.instance.make! DSymbol(istring(name), kind);
1098
1106
acSymbol.location = location;
1099
1107
acSymbol.symbolFile = symbolFile;
1108
+ acSymbol.protection = protection;
1100
1109
symbolsAllocated++ ;
1101
1110
return GCAllocator.instance.make! SemanticSymbol(acSymbol);
1102
1111
}
@@ -1213,17 +1222,19 @@ struct ProtectionStack
1213
1222
1214
1223
IdType currentForImport () const
1215
1224
{
1216
- return stack.empty ? tok! " default" : current();
1225
+ // Imports are private unless specified otherwise.
1226
+ return stack.empty ? tok! " private" : current();
1217
1227
}
1218
1228
1219
1229
IdType current () const
1230
+ out (t; isProtection (t), str(t))
1231
+ do
1220
1232
{
1221
1233
import std.algorithm.iteration : filter;
1222
1234
import std.range : choose, only;
1223
1235
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! " :" ))
1227
1238
retVal = cast (IdType) t;
1228
1239
return retVal;
1229
1240
}
@@ -1252,7 +1263,7 @@ struct ProtectionStack
1252
1263
1253
1264
void beginLocal (const IdType t)
1254
1265
{
1255
- assert (t != tok ! " " , " DERP! " );
1266
+ assert (isProtection(t), str(t) );
1256
1267
stack.insertBack(t);
1257
1268
}
1258
1269
0 commit comments