Skip to content

Commit

Permalink
make function symbols store function parameters, needed for UFCS. (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
vushu authored Oct 10, 2022
1 parent 3925b12 commit 8a24727
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
17 changes: 7 additions & 10 deletions src/dsymbol/conversion/first.d
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ final class FirstPass : ASTVisitor
* symbolFile = path to the file being converted
* symbolAllocator = allocator used for the auto-complete symbols
* semanticAllocator = allocator used for semantic symbols
* includeParameterSymbols = include parameter symbols as children of
* function decalarations and constructors
*/
this(const Module mod, istring symbolFile, RCIAllocator symbolAllocator,
RCIAllocator semanticAllocator, bool includeParameterSymbols,
RCIAllocator semanticAllocator,
ModuleCache* cache, CacheEntry* entry = null)
in
{
Expand All @@ -81,7 +79,6 @@ final class FirstPass : ASTVisitor
this.symbolFile = symbolFile;
this.symbolAllocator = symbolAllocator;
this.semanticAllocator = semanticAllocator;
this.includeParameterSymbols = includeParameterSymbols;
this.entry = entry;
this.cache = cache;
}
Expand Down Expand Up @@ -158,11 +155,8 @@ final class FirstPass : ASTVisitor
}
else
{
immutable ips = includeParameterSymbols;
includeParameterSymbols = false;
processParameters(currentSymbol, dec.returnType,
currentSymbol.acSymbol.name, dec.parameters, dec.templateParameters);
includeParameterSymbols = ips;
}
}

Expand Down Expand Up @@ -970,8 +964,9 @@ private:
const TemplateParameters templateParameters)
{
processTemplateParameters(symbol, templateParameters);
if (includeParameterSymbols && parameters !is null)
if (parameters !is null)
{
currentSymbol.acSymbol.functionParameters.reserve(parameters.parameters.length);
foreach (const Parameter p; parameters.parameters)
{
SemanticSymbol* parameter = allocateSemanticSymbol(
Expand All @@ -981,6 +976,9 @@ private:
addTypeToLookups(parameter.typeLookups, p.type);
parameter.parent = currentSymbol;
currentSymbol.acSymbol.argNames.insert(parameter.acSymbol.name);

currentSymbol.acSymbol.functionParameters ~= parameter.acSymbol;

currentSymbol.addChild(parameter, true);
currentScope.addSymbol(parameter.acSymbol, false);
}
Expand Down Expand Up @@ -1008,7 +1006,7 @@ private:

void processTemplateParameters(SemanticSymbol* symbol, const TemplateParameters templateParameters)
{
if (includeParameterSymbols && templateParameters !is null
if (templateParameters !is null
&& templateParameters.templateParameterList !is null)
{
foreach (const TemplateParameter p; templateParameters.templateParameterList.items)
Expand Down Expand Up @@ -1217,7 +1215,6 @@ private:

ModuleCache* cache;

bool includeParameterSymbols;
bool skipBaseClassesOfNewAnon;

ubyte foreachTypeIndexOfInterest;
Expand Down
2 changes: 1 addition & 1 deletion src/dsymbol/conversion/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ScopeSymbolPair generateAutocompleteTrees(const(Token)[] tokens,
parseAllocator, cursorPosition);

scope first = new FirstPass(m, internString("stdin"), symbolAllocator,
symbolAllocator, true, &cache);
symbolAllocator, &cache);
first.run();

secondPass(first.rootSymbol, first.moduleScope, cache);
Expand Down
2 changes: 1 addition & 1 deletion src/dsymbol/modulecache.d
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct ModuleCache

assert (!symbolAllocator.isNull);
scope first = new FirstPass(m, cachedLocation, symbolAllocator,
semanticAllocator.allocatorObject, false, &this, newEntry);
semanticAllocator.allocatorObject, &this, newEntry);
first.run();

secondPass(first.rootSymbol, first.moduleScope, this);
Expand Down
6 changes: 6 additions & 0 deletions src/dsymbol/symbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,16 @@ struct DSymbol
/**
* Names of function arguments
*/
// TODO: remove since we have function arguments
UnrolledList!(istring) argNames;

private uint _location;

/**
* Function parameter symbols
*/
DSymbol*[] functionParameters;

/**
* DSymbol location
*/
Expand Down
2 changes: 1 addition & 1 deletion src/dsymbol/tests.d
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ ScopeSymbolPair generateAutocompleteTrees(string source, string filename, ref Mo
Module m = parseModule(tokens, filename, &rba);

scope first = new FirstPass(m, internString(filename),
theAllocator, theAllocator, true, &cache);
theAllocator, theAllocator, &cache);
first.run();

secondPass(first.rootSymbol, first.moduleScope, cache);
Expand Down

0 comments on commit 8a24727

Please sign in to comment.