Skip to content
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

make function symbols store function parameters, needed for UFCS. #182

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/dsymbol/conversion/first.d
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ final class FirstPass : ASTVisitor
pushFunctionScope(dec.functionBody, semanticAllocator,
dec.name.index + dec.name.text.length);
scope (exit) popScope();
includeParameterSymbols = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be here (it effectively now makes the constructor parameter useless, as parameters would always be included)

If it's never a problem, consider instead removing the symbol completely, deprecating the ctor and stripping all the ifs that checked on it

processParameters(currentSymbol, dec.returnType,
currentSymbol.acSymbol.name, dec.parameters, dec.templateParameters);
dec.functionBody.accept(this);
Expand Down Expand Up @@ -972,6 +973,7 @@ private:
processTemplateParameters(symbol, templateParameters);
if (includeParameterSymbols && parameters !is null)
{
currentSymbol.acSymbol.functionArguments.reserve(parameters.parameters.length);
foreach (const Parameter p; parameters.parameters)
{
SemanticSymbol* parameter = allocateSemanticSymbol(
Expand All @@ -981,6 +983,9 @@ private:
addTypeToLookups(parameter.typeLookups, p.type);
parameter.parent = currentSymbol;
currentSymbol.acSymbol.argNames.insert(parameter.acSymbol.name);

currentSymbol.acSymbol.functionArguments ~= parameter.acSymbol;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixed tabs and spaces


currentSymbol.addChild(parameter, true);
currentScope.addSymbol(parameter.acSymbol, false);
}
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 argument symbols
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixed tabs and spaces

*/
DSymbol*[] functionArguments;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be an array of pointers?

Copy link
Contributor Author

@vushu vushu Oct 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so since DSymbol isn't copyable unless we change that.

struct DSymbol
{
	// Copying is disabled
	@disable this();
	@disable this(this);
,,,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually all the DSymbol references are done by pointers, but it might be effective to use them inline in arrays (e.g. move them into the array)

We already know the count of items that get put into array before putting them there anyway, so we can already preallocate all the space and directly construct them in-place.


/**
* DSymbol location
*/
Expand Down