-
Notifications
You must be signed in to change notification settings - Fork 19
Fix several problems with symbol protection. #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,9 +135,8 @@ final class FirstPass : ASTVisitor | |
| { | ||
| assert(dec); | ||
| pushSymbol(dec.name.text, CompletionKind.functionName, symbolFile, | ||
| dec.name.index, dec.returnType); | ||
| dec.name.index, dec.returnType, protection.current); | ||
| scope (exit) popSymbol(); | ||
| currentSymbol.acSymbol.protection = protection.current; | ||
| currentSymbol.acSymbol.doc = makeDocumentation(dec.comment); | ||
|
|
||
| istring lastComment = this.lastComment; | ||
|
|
@@ -387,6 +386,7 @@ final class FirstPass : ASTVisitor | |
| auto objectImport = allocateSemanticSymbol(IMPORT_SYMBOL_NAME, | ||
| CompletionKind.importSymbol, objectLocation); | ||
| objectImport.acSymbol.skipOver = true; | ||
| objectImport.acSymbol.protection = protection.currentForImport; | ||
| currentSymbol.addChild(objectImport, true); | ||
| currentScope.addSymbol(objectImport.acSymbol, false); | ||
| } | ||
|
|
@@ -453,6 +453,7 @@ final class FirstPass : ASTVisitor | |
| thisSymbol.symbolFile = symbolFile; | ||
| thisSymbol.type = currentSymbol.acSymbol; | ||
| thisSymbol.ownType = false; | ||
| thisSymbol.protection = tok!"private"; | ||
| currentScope.addSymbol(thisSymbol, false); | ||
|
|
||
| foreach (dec; structBody.declarations) | ||
|
|
@@ -484,6 +485,7 @@ final class FirstPass : ASTVisitor | |
| SemanticSymbol* importSymbol = allocateSemanticSymbol(IMPORT_SYMBOL_NAME, | ||
| CompletionKind.importSymbol, modulePath); | ||
| importSymbol.acSymbol.skipOver = protection.currentForImport != tok!"public"; | ||
| importSymbol.acSymbol.protection = protection.currentForImport; | ||
| if (single.rename == tok!"") | ||
| { | ||
| size_t i = 0; | ||
|
|
@@ -501,6 +503,8 @@ final class FirstPass : ASTVisitor | |
| if (s.length == 0) | ||
| { | ||
| currentImportSymbol = symbolAllocator.make!DSymbol(ip, kind); | ||
| currentImportSymbol.protection = protection.currentForImport; | ||
| currentImportSymbol.skipOver = protection.currentForImport != tok!"public"; | ||
| currentScope.addSymbol(currentImportSymbol, true); | ||
| if (last) | ||
| { | ||
|
|
@@ -518,6 +522,8 @@ final class FirstPass : ASTVisitor | |
| if (s.length == 0) | ||
| { | ||
| auto sym = symbolAllocator.make!DSymbol(ip, kind); | ||
| sym.protection = protection.currentForImport; | ||
| sym.skipOver = protection.currentForImport != tok!"public"; | ||
| currentImportSymbol.addChild(sym, true); | ||
| currentImportSymbol = sym; | ||
| if (last) | ||
|
|
@@ -540,6 +546,7 @@ final class FirstPass : ASTVisitor | |
| SemanticSymbol* renameSymbol = allocateSemanticSymbol( | ||
| internString(single.rename.text), CompletionKind.aliasName, | ||
| modulePath); | ||
| renameSymbol.acSymbol.protection = protection.currentForImport; | ||
| renameSymbol.acSymbol.skipOver = protection.currentForImport != tok!"public"; | ||
| renameSymbol.acSymbol.type = importSymbol.acSymbol; | ||
| renameSymbol.acSymbol.ownType = true; | ||
|
|
@@ -557,7 +564,7 @@ final class FirstPass : ASTVisitor | |
| istring modulePath = cache.resolveImportLocation(chain); | ||
| if (modulePath is null) | ||
| { | ||
| warning("Could not resolve location of module '", chain, "'"); | ||
| warning("Could not resolve location of module '", chain.data, "'"); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -585,6 +592,7 @@ final class FirstPass : ASTVisitor | |
| importSymbol.acSymbol.qualifier = SymbolQualifier.selectiveImport; | ||
| importSymbol.typeLookups.insert(lookup); | ||
| importSymbol.acSymbol.skipOver = protection.currentForImport != tok!"public"; | ||
| importSymbol.acSymbol.protection = protection.currentForImport; | ||
| currentSymbol.addChild(importSymbol, true); | ||
| currentScope.addSymbol(importSymbol.acSymbol, false); | ||
| } | ||
|
|
@@ -848,7 +856,7 @@ private: | |
| } | ||
|
|
||
| void pushSymbol(string name, CompletionKind kind, istring symbolFile, | ||
| size_t location = 0, const Type type = null) | ||
| size_t location = 0, const Type type = null, const IdType protection = tok!"public") | ||
| { | ||
| SemanticSymbol* symbol = allocateSemanticSymbol(name, kind, symbolFile, | ||
| location); | ||
|
|
@@ -884,14 +892,13 @@ private: | |
| dec.accept(this); | ||
| return; | ||
| } | ||
| pushSymbol(dec.name.text, kind, symbolFile, dec.name.index); | ||
| pushSymbol(dec.name.text, kind, symbolFile, dec.name.index, null, protection.current); | ||
| scope(exit) popSymbol(); | ||
|
|
||
| if (kind == CompletionKind.className) | ||
| currentSymbol.acSymbol.addChildren(classSymbols[], false); | ||
| else | ||
| currentSymbol.acSymbol.addChildren(aggregateSymbols[], false); | ||
| currentSymbol.acSymbol.protection = protection.current; | ||
| currentSymbol.acSymbol.doc = makeDocumentation(dec.comment); | ||
|
|
||
| istring lastComment = this.lastComment; | ||
|
|
@@ -1106,7 +1113,7 @@ private: | |
| } | ||
|
|
||
| SemanticSymbol* allocateSemanticSymbol(string name, CompletionKind kind, | ||
| istring symbolFile, size_t location = 0) | ||
| istring symbolFile, size_t location = 0, IdType protection = tok!"public") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a default value is a bad idea. I would revert this definition, make it deprecated and add another overload with non-optional protection argument. This way we don't get issues with people assuming no protection and also simplify a lot of caller code which currently manually sets acSymbol.protection which isn't covered by the PR yet.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few points to keep in mind:
I do plan on doing another pass over this code to make more use of this extra argument. In general this module needs a lot of cleanup and documentation. |
||
| in | ||
| { | ||
| assert (symbolAllocator !is null); | ||
|
|
@@ -1116,6 +1123,7 @@ private: | |
| DSymbol* acSymbol = make!DSymbol(symbolAllocator, istring(name), kind); | ||
| acSymbol.location = location; | ||
| acSymbol.symbolFile = symbolFile; | ||
| acSymbol.protection = protection; | ||
| symbolsAllocated++; | ||
| return semanticAllocator.make!SemanticSymbol(acSymbol); | ||
| } | ||
|
|
@@ -1235,17 +1243,19 @@ struct ProtectionStack | |
|
|
||
| IdType currentForImport() const | ||
| { | ||
| return stack.empty ? tok!"default" : current(); | ||
| // Imports are private unless specified otherwise. | ||
| return stack.empty ? tok!"private" : current(); | ||
| } | ||
|
|
||
| IdType current() const | ||
| out(t) { assert(isProtection(t), str(t)); } | ||
| do | ||
| { | ||
| import std.algorithm.iteration : filter; | ||
| import std.range : choose, only; | ||
|
|
||
| IdType retVal; | ||
| foreach (t; choose(stack.empty, only(tok!"public"), stack[]).filter!( | ||
| a => a != tok!"{" && a != tok!":")) | ||
| IdType retVal = tok!"public"; | ||
| foreach (t; stack[].filter!(a => a != tok!"{" && a != tok!":")) | ||
| retVal = cast(IdType) t; | ||
| return retVal; | ||
| } | ||
|
|
@@ -1274,7 +1284,7 @@ struct ProtectionStack | |
|
|
||
| void beginLocal(const IdType t) | ||
| { | ||
| assert (t != tok!"", "DERP!"); | ||
| assert(isProtection(t), str(t)); | ||
| stack.insertBack(t); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this protection argument isn't used
also ditto from previous comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix.