Adding alias this to symbol and match algorithm
This commit is contained in:
parent
86cb518b27
commit
de001983c2
|
@ -362,6 +362,9 @@ void resolveAliasThis(DSymbol* symbol,
|
||||||
auto parts = symbol.getPartsByName(aliasThis.breadcrumbs.front);
|
auto parts = symbol.getPartsByName(aliasThis.breadcrumbs.front);
|
||||||
if (parts.length == 0 || parts[0].type is null)
|
if (parts.length == 0 || parts[0].type is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
symbol.aliasThisSymbol = parts[0];
|
||||||
|
|
||||||
DSymbol* s = GCAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME,
|
DSymbol* s = GCAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME,
|
||||||
CompletionKind.importSymbol, parts[0].type);
|
CompletionKind.importSymbol, parts[0].type);
|
||||||
symbol.addChild(s, true);
|
symbol.addChild(s, true);
|
||||||
|
|
|
@ -375,6 +375,8 @@ struct DSymbol
|
||||||
// TODO: assert that the type is not a function
|
// TODO: assert that the type is not a function
|
||||||
DSymbol* type;
|
DSymbol* type;
|
||||||
|
|
||||||
|
// Is using alias this
|
||||||
|
DSymbol* aliasThisSymbol;
|
||||||
/**
|
/**
|
||||||
* Names of function arguments
|
* Names of function arguments
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -13,7 +13,6 @@ import std.string;
|
||||||
import dparse.lexer : tok;
|
import dparse.lexer : tok;
|
||||||
import std.regex;
|
import std.regex;
|
||||||
import containers.hashset : HashSet;
|
import containers.hashset : HashSet;
|
||||||
import dparse.ast;
|
|
||||||
|
|
||||||
// https://dlang.org/spec/type.html#implicit-conversions
|
// https://dlang.org/spec/type.html#implicit-conversions
|
||||||
enum string[string] INTEGER_PROMOTIONS = [
|
enum string[string] INTEGER_PROMOTIONS = [
|
||||||
|
@ -121,8 +120,6 @@ DSymbol*[] getSymbolsForUFCS(Scope* completionScope, const(DSymbol)* beforeDotSy
|
||||||
|
|
||||||
bool willImplicitBeUpcasted(string from, string to)
|
bool willImplicitBeUpcasted(string from, string to)
|
||||||
{
|
{
|
||||||
import std.stdio;
|
|
||||||
|
|
||||||
string* found = from in INTEGER_PROMOTIONS;
|
string* found = from in INTEGER_PROMOTIONS;
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
|
@ -132,6 +129,14 @@ bool willImplicitBeUpcasted(string from, string to)
|
||||||
return INTEGER_PROMOTIONS[from] == to;
|
return INTEGER_PROMOTIONS[from] == to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool matchAliasThis(const(DSymbol)* aliasThisSymbol, const(DSymbol)* incomingSymbol)
|
||||||
|
{
|
||||||
|
if(aliasThisSymbol) {
|
||||||
|
return isCallableWithArg(incomingSymbol, aliasThisSymbol.type);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Params:
|
* Params:
|
||||||
* incomingSymbol = the function symbol to check if it is valid for UFCS with `beforeDotType`.
|
* incomingSymbol = the function symbol to check if it is valid for UFCS with `beforeDotType`.
|
||||||
|
@ -152,8 +157,10 @@ bool isCallableWithArg(const(DSymbol)* incomingSymbol, const(DSymbol)* beforeDot
|
||||||
if (incomingSymbol.kind == CompletionKind.functionName && !incomingSymbol
|
if (incomingSymbol.kind == CompletionKind.functionName && !incomingSymbol
|
||||||
.functionParameters.empty)
|
.functionParameters.empty)
|
||||||
{
|
{
|
||||||
return beforeDotType is incomingSymbol.functionParameters.front.type ||
|
return beforeDotType is incomingSymbol.functionParameters.front.type
|
||||||
willImplicitBeUpcasted(beforeDotType.name, incomingSymbol.functionParameters.front.type.name);
|
|| willImplicitBeUpcasted(beforeDotType.name, incomingSymbol.functionParameters.front.type.name)
|
||||||
|
|| matchAliasThis(beforeDotType.aliasThisSymbol, incomingSymbol);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
identifiers
|
||||||
|
alignof k
|
||||||
|
init k
|
||||||
|
mangleof k
|
||||||
|
max k
|
||||||
|
min k
|
||||||
|
sizeof k
|
||||||
|
stringof k
|
||||||
|
tupleof k
|
||||||
|
ufcsSomeInt F
|
||||||
|
ufcsSomeShort F
|
||||||
|
x v
|
|
@ -5,7 +5,7 @@ struct Foo {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IntAliased {
|
struct IntAliased {
|
||||||
int x;
|
short x;
|
||||||
alias x this;
|
alias x this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,4 +19,5 @@ void ufcsBarRefImmuttableWrapped(ref immutable(Foo) foo, string mama) {}
|
||||||
void ufcsBarScope(ref scope Foo foo, string mama) {}
|
void ufcsBarScope(ref scope Foo foo, string mama) {}
|
||||||
void ufcsBarReturnScope(return scope Foo foo, string mama) {}
|
void ufcsBarReturnScope(return scope Foo foo, string mama) {}
|
||||||
void ufcsSomeInt(int x) {}
|
void ufcsSomeInt(int x) {}
|
||||||
|
void ufcsSomeShort(short x) {}
|
||||||
private void ufcsBarPrivate(Foo foo, string message) {}
|
private void ufcsBarPrivate(Foo foo, string message) {}
|
Loading…
Reference in New Issue