mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 21:51:03 +03:00
parent
b2c83e9921
commit
1b9bc74edc
6 changed files with 85 additions and 16 deletions
|
@ -30,6 +30,7 @@ import dmd.func;
|
||||||
import dmd.funcsem : overloadApply, getLevelAndCheck;
|
import dmd.funcsem : overloadApply, getLevelAndCheck;
|
||||||
import dmd.globals;
|
import dmd.globals;
|
||||||
import dmd.gluelayer;
|
import dmd.gluelayer;
|
||||||
|
import dmd.hdrgen;
|
||||||
import dmd.id;
|
import dmd.id;
|
||||||
import dmd.identifier;
|
import dmd.identifier;
|
||||||
import dmd.init;
|
import dmd.init;
|
||||||
|
@ -442,8 +443,7 @@ extern (C++) final class AliasDeclaration : Declaration
|
||||||
extern (D) this(const ref Loc loc, Identifier ident, Type type) @safe
|
extern (D) this(const ref Loc loc, Identifier ident, Type type) @safe
|
||||||
{
|
{
|
||||||
super(loc, ident);
|
super(loc, ident);
|
||||||
//printf("AliasDeclaration(id = '%s', type = %p)\n", ident.toChars(), type);
|
//debug printf("AliasDeclaration(id = '%s', type = `%s`, %p)\n", ident.toChars(), dmd.hdrgen.toChars(type), type.isTypeIdentifier());
|
||||||
//printf("type = '%s'\n", type.toChars());
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
assert(type);
|
assert(type);
|
||||||
}
|
}
|
||||||
|
@ -451,7 +451,7 @@ extern (C++) final class AliasDeclaration : Declaration
|
||||||
extern (D) this(const ref Loc loc, Identifier ident, Dsymbol s) @safe
|
extern (D) this(const ref Loc loc, Identifier ident, Dsymbol s) @safe
|
||||||
{
|
{
|
||||||
super(loc, ident);
|
super(loc, ident);
|
||||||
//printf("AliasDeclaration(id = '%s', s = %p)\n", ident.toChars(), s);
|
//debug printf("AliasDeclaration(id = '%s', s = `%s`)\n", ident.toChars(), s.toChars());
|
||||||
assert(s != this);
|
assert(s != this);
|
||||||
this.aliassym = s;
|
this.aliassym = s;
|
||||||
assert(s);
|
assert(s);
|
||||||
|
@ -612,8 +612,9 @@ extern (C++) final class AliasDeclaration : Declaration
|
||||||
|
|
||||||
override Dsymbol toAlias()
|
override Dsymbol toAlias()
|
||||||
{
|
{
|
||||||
//printf("[%s] AliasDeclaration::toAlias('%s', this = %p, aliassym = %p, kind = '%s', inuse = %d)\n",
|
static if (0)
|
||||||
// loc.toChars(), toChars(), this, aliassym, aliassym ? aliassym.kind() : "", inuse);
|
printf("[%s] AliasDeclaration::toAlias('%s', this = %p, aliassym: %s, kind: '%s', inuse = %d)\n",
|
||||||
|
loc.toChars(), toChars(), this, aliassym ? aliassym.toChars() : "", aliassym ? aliassym.kind() : "", inuse);
|
||||||
assert(this != aliassym);
|
assert(this != aliassym);
|
||||||
//static int count; if (++count == 10) *(char*)0=0;
|
//static int count; if (++count == 10) *(char*)0=0;
|
||||||
|
|
||||||
|
|
|
@ -5243,7 +5243,7 @@ void aliasInstanceSemantic(TemplateInstance tempinst, Scope* sc, TemplateDeclara
|
||||||
// function used to perform semantic on AliasDeclaration
|
// function used to perform semantic on AliasDeclaration
|
||||||
void aliasSemantic(AliasDeclaration ds, Scope* sc)
|
void aliasSemantic(AliasDeclaration ds, Scope* sc)
|
||||||
{
|
{
|
||||||
//printf("AliasDeclaration::semantic() %s\n", ds.toChars());
|
//printf("AliasDeclaration::semantic() %s %p\n", ds.toChars(), ds.aliassym);
|
||||||
|
|
||||||
// as DsymbolSemanticVisitor::visit(AliasDeclaration), in case we're called first.
|
// as DsymbolSemanticVisitor::visit(AliasDeclaration), in case we're called first.
|
||||||
// see https://issues.dlang.org/show_bug.cgi?id=21001
|
// see https://issues.dlang.org/show_bug.cgi?id=21001
|
||||||
|
|
|
@ -8138,7 +8138,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
|
||||||
static if (LOGSEMANTIC)
|
static if (LOGSEMANTIC)
|
||||||
{
|
{
|
||||||
printf("DotIdExp::semantic(this = %p, '%s')\n", exp, exp.toChars());
|
printf("DotIdExp::semantic(this = %p, '%s')\n", exp, exp.toChars());
|
||||||
//printf("e1.op = %d, '%s'\n", e1.op, Token.toChars(e1.op));
|
printAST(exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sc.inCfile)
|
if (sc.inCfile)
|
||||||
|
@ -14036,7 +14036,7 @@ Expression expressionSemantic(Expression e, Scope* sc)
|
||||||
|
|
||||||
private Expression dotIdSemanticPropX(DotIdExp exp, Scope* sc)
|
private Expression dotIdSemanticPropX(DotIdExp exp, Scope* sc)
|
||||||
{
|
{
|
||||||
//printf("DotIdExp::semanticX(this = %p, '%s')\n", this, toChars());
|
//printf("dotIdSemanticPropX() %s\n", toChars(exp));
|
||||||
if (Expression ex = unaSemantic(exp, sc))
|
if (Expression ex = unaSemantic(exp, sc))
|
||||||
return ex;
|
return ex;
|
||||||
|
|
||||||
|
@ -14164,7 +14164,7 @@ private Expression dotIdSemanticPropX(DotIdExp exp, Scope* sc)
|
||||||
*/
|
*/
|
||||||
Expression dotIdSemanticProp(DotIdExp exp, Scope* sc, bool gag)
|
Expression dotIdSemanticProp(DotIdExp exp, Scope* sc, bool gag)
|
||||||
{
|
{
|
||||||
//printf("DotIdExp::semanticY(this = %p, '%s')\n", exp, exp.toChars());
|
//printf("dotIdSemanticProp('%s')\n", exp.toChars());
|
||||||
|
|
||||||
//{ static int z; fflush(stdout); if (++z == 10) *(char*)0=0; }
|
//{ static int z; fflush(stdout); if (++z == 10) *(char*)0=0; }
|
||||||
|
|
||||||
|
@ -14502,7 +14502,7 @@ Expression dotIdSemanticProp(DotIdExp exp, Scope* sc, bool gag)
|
||||||
|
|
||||||
const flag = cast(DotExpFlag) (exp.noderef * DotExpFlag.noDeref | gag * DotExpFlag.gag);
|
const flag = cast(DotExpFlag) (exp.noderef * DotExpFlag.noDeref | gag * DotExpFlag.gag);
|
||||||
|
|
||||||
Expression e = exp.e1.type.dotExp(sc, exp.e1, exp.ident, flag);
|
Expression e = dotExp(exp.e1.type, sc, exp.e1, exp.ident, flag);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
e = e.expressionSemantic(sc);
|
e = e.expressionSemantic(sc);
|
||||||
|
|
|
@ -51,6 +51,12 @@ extern (C++) final class PrintASTVisitor : Visitor
|
||||||
printf("%.*s %s\n", cast(int)s.length, s.ptr, e.type ? e.type.toChars() : "");
|
printf("%.*s %s\n", cast(int)s.length, s.ptr, e.type ? e.type.toChars() : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override void visit(IdentifierExp e)
|
||||||
|
{
|
||||||
|
printIndent(indent);
|
||||||
|
printf("Identifier `%s` %s\n", e.ident.toChars(), e.type ? e.type.toChars() : "");
|
||||||
|
}
|
||||||
|
|
||||||
override void visit(IntegerExp e)
|
override void visit(IntegerExp e)
|
||||||
{
|
{
|
||||||
printIndent(indent);
|
printIndent(indent);
|
||||||
|
|
|
@ -4462,6 +4462,10 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, out Expression pe, out Type
|
||||||
*/
|
*/
|
||||||
Expression dotExp(Type mt, Scope* sc, Expression e, Identifier ident, DotExpFlag flag)
|
Expression dotExp(Type mt, Scope* sc, Expression e, Identifier ident, DotExpFlag flag)
|
||||||
{
|
{
|
||||||
|
enum LOGDOTEXP = false;
|
||||||
|
if (LOGDOTEXP)
|
||||||
|
printf("dotExp()\n");
|
||||||
|
|
||||||
Expression visitType(Type mt)
|
Expression visitType(Type mt)
|
||||||
{
|
{
|
||||||
VarDeclaration v = null;
|
VarDeclaration v = null;
|
||||||
|
@ -5082,8 +5086,41 @@ Expression dotExp(Type mt, Scope* sc, Expression e, Identifier ident, DotExpFlag
|
||||||
return noMember(mt, sc, e, ident, flag);
|
return noMember(mt, sc, e, ident, flag);
|
||||||
}
|
}
|
||||||
// check before alias resolution; the alias itself might be deprecated!
|
// check before alias resolution; the alias itself might be deprecated!
|
||||||
if (s.isAliasDeclaration)
|
if (auto ad = s.isAliasDeclaration)
|
||||||
|
{
|
||||||
s.checkDeprecated(e.loc, sc);
|
s.checkDeprecated(e.loc, sc);
|
||||||
|
|
||||||
|
// Fix for https://github.com/dlang/dmd/issues/20610
|
||||||
|
if (ad.originalType)
|
||||||
|
{
|
||||||
|
if (auto tid = ad.originalType.isTypeIdentifier())
|
||||||
|
{
|
||||||
|
if (tid.idents.length)
|
||||||
|
{
|
||||||
|
static if (0)
|
||||||
|
{
|
||||||
|
printf("TypeStruct::dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
|
||||||
|
printf("AliasDeclaration: %s\n", ad.toChars());
|
||||||
|
if (ad.aliassym)
|
||||||
|
printf("aliassym: %s\n", ad.aliassym.toChars());
|
||||||
|
printf("tid type: %s\n", toChars(tid));
|
||||||
|
}
|
||||||
|
/* Rewrite e.s as e.(tid.ident).(tid.idents)
|
||||||
|
*/
|
||||||
|
Expression die = new DotIdExp(e.loc, e, tid.ident);
|
||||||
|
foreach (id; tid.idents) // maybe use typeToExpressionHelper()
|
||||||
|
die = new DotIdExp(e.loc, die, cast(Identifier)id);
|
||||||
|
/* Ambiguous syntax, only way to disambiguate it to try it
|
||||||
|
*/
|
||||||
|
die = dmd.expressionsem.trySemantic(die, sc);
|
||||||
|
if (die && die.isDotVarExp()) // shrink wrap around DotVarExp()
|
||||||
|
{
|
||||||
|
return die;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
s = s.toAlias();
|
s = s.toAlias();
|
||||||
|
|
||||||
if (auto em = s.isEnumMember())
|
if (auto em = s.isEnumMember())
|
||||||
|
@ -6074,7 +6111,7 @@ Dsymbol toDsymbol(Type type, Scope* sc)
|
||||||
|
|
||||||
Dsymbol visitIdentifier(TypeIdentifier type)
|
Dsymbol visitIdentifier(TypeIdentifier type)
|
||||||
{
|
{
|
||||||
//printf("TypeIdentifier::toDsymbol('%s')\n", toChars());
|
//printf("TypeIdentifier::toDsymbol('%s')\n", toChars(type));
|
||||||
if (!sc)
|
if (!sc)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -6086,7 +6123,6 @@ Dsymbol toDsymbol(Type type, Scope* sc)
|
||||||
s = t.toDsymbol(sc);
|
s = t.toDsymbol(sc);
|
||||||
if (e)
|
if (e)
|
||||||
s = getDsymbol(e);
|
s = getDsymbol(e);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ template Qual(alias T)
|
||||||
alias Qual = T;
|
alias Qual = T;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test()
|
void test1()
|
||||||
{
|
{
|
||||||
int x = 3;
|
int x = 3;
|
||||||
int y = 4;
|
int y = 4;
|
||||||
|
@ -25,7 +25,33 @@ void test()
|
||||||
assert(XY[1] == 4);
|
assert(XY[1] == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
/**********************************************/
|
||||||
|
|
||||||
|
struct T
|
||||||
{
|
{
|
||||||
test();
|
int k,i = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct S
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
T t;
|
||||||
|
alias ti = t.i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test2()
|
||||||
|
{
|
||||||
|
T t = T(1, 2);
|
||||||
|
S s;
|
||||||
|
assert(s.ti == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************/
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test1();
|
||||||
|
test2();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue