Skip to content

Commit

Permalink
Move di generator to after semantic analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
rikkimax committed Jun 7, 2024
1 parent 05c8980 commit 48a49ef
Show file tree
Hide file tree
Showing 62 changed files with 4,683 additions and 3,986 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dmd/arrayop.d
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private Expressions* buildArrayOp(Scope* sc, Expression e, Objects* tiargs)
// RPN, prefix unary ops with u
OutBuffer buf;
buf.writestring("u");
buf.writestring(EXPtoString(e.op));
buf.writestring(expressionTypeToString(e.op));
e.e1.accept(this);
tiargs.push(new StringExp(Loc.initial, buf.extractSlice()).expressionSemantic(sc));
}
Expand All @@ -249,7 +249,7 @@ private Expressions* buildArrayOp(Scope* sc, Expression e, Objects* tiargs)
// RPN
e.e1.accept(this);
e.e2.accept(this);
tiargs.push(new StringExp(Loc.initial, EXPtoString(e.op)).expressionSemantic(sc));
tiargs.push(new StringExp(Loc.initial, expressionTypeToString(e.op)).expressionSemantic(sc));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/astcodegen.d
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct ASTCodegen
alias Dsymbols = dmd.dsymbol.Dsymbols;
alias Visibility = dmd.dsymbol.Visibility;

alias stcToBuffer = dmd.hdrgen.stcToBuffer;
alias stcToBuffer = dmd.hdrgen.storageClassToBuffer;
alias linkageToChars = dmd.hdrgen.linkageToChars;
alias visibilityToChars = dmd.hdrgen.visibilityToChars;

Expand Down
9 changes: 9 additions & 0 deletions compiler/src/dmd/astenums.d
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ enum STC : ulong // transfer changes to declaration.h
STC.TYPECTOR | STC.final_ | STC.tls | STC.gshared | STC.ref_ | STC.return_ | STC.property |
STC.nothrow_ | STC.pure_ | STC.safe | STC.trusted | STC.system), /// for a FuncDeclaration

// These storage classes when used as attributes should emitted differently as part of .di header generator
lhsHeaderAttributes = STC.static_ | STC.extern_ | STC.final_ | STC.abstract_ | STC.override_ |
STC.synchronized_ | STC.deprecated_ | STC.disable,
// For module (de)constructors limit lhs
lhsHeaderMCtorAttributes = STC.extern_ | STC.final_ | STC.abstract_ | STC.override_ |
STC.synchronized_ | STC.deprecated_ | STC.disable,
// For module (de)constructors limit rhs
rhsHeaderMCtorAttributes = STC.visibleStorageClasses & ~(STC.lhsHeaderMCtorAttributes | STC.shared_ | STC.static_),

}

alias StorageClass = ulong;
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dmd/ctfeexpr.d
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extern (D) struct UnionExp
extern (D) Expression copy()
{
Expression e = exp();
//if (e.size > sizeof(u)) printf("%s\n", EXPtoString(e.op).ptr);
//if (e.size > sizeof(u)) printf("%s\n", expressionTypeToString(e.op).ptr);
assert(e.size <= u.sizeof);
switch (e.op)
{
Expand Down Expand Up @@ -1325,8 +1325,8 @@ bool ctfeEqual(const ref Loc loc, EXP op, Expression e1, Expression e2)
bool ctfeIdentity(const ref Loc loc, EXP op, Expression e1, Expression e2)
{
//printf("ctfeIdentity %s %s\n", e1.toChars(), e2.toChars());
//printf("ctfeIdentity op = '%s', e1 = %s %s, e2 = %s %s\n", EXPtoString(op).ptr,
// EXPtoString(e1.op).ptr, e1.toChars(), EXPtoString(e2.op).ptr, e1.toChars());
//printf("ctfeIdentity op = '%s', e1 = %s %s, e2 = %s %s\n", expressionTypeToString(op).ptr,
// expressionTypeToString(e1.op).ptr, e1.toChars(), expressionTypeToString(e2.op).ptr, e1.toChars());
bool cmp;
if (e1.op == EXP.null_)
{
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -3590,13 +3590,13 @@ LmodCompare:
return null;
}

//printf("test %s\n", EXPtoString(op).ptr);
//printf("test %s\n", expressionTypeToString(op).ptr);
e1 = e1.optimize(WANTvalue);
if (isCommutative(op) && e1.isConst())
{
/* Swap operands to minimize number of functions generated
*/
//printf("swap %s\n", EXPtoString(op).ptr);
//printf("swap %s\n", expressionTypeToString(op).ptr);
Expression tmp = e1;
e1 = e2;
e2 = tmp;
Expand Down Expand Up @@ -3777,7 +3777,7 @@ void fix16997(Scope* sc, UnaExp ue)
case Twchar:
case Tdchar:
deprecation(ue.loc, "integral promotion not done for `%s`, remove '-revert=intpromote' switch or `%scast(int)(%s)`",
ue.toChars(), EXPtoString(ue.op).ptr, ue.e1.toChars());
ue.toChars(), expressionTypeToString(ue.op).ptr, ue.e1.toChars());
break;

default:
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ public:
{
debug (LOG)
{
printf("%s Expression::interpret() '%s' %s\n", e.loc.toChars(), EXPtoString(e.op).ptr, e.toChars());
printf("%s Expression::interpret() '%s' %s\n", e.loc.toChars(), expressionTypeToString(e.op).ptr, e.toChars());
printf("type = %s\n", e.type.toChars());
showCtfeExpr(e);
}
Expand Down Expand Up @@ -3266,7 +3266,7 @@ public:
return;

default:
printf("be = '%s' %s at [%s]\n", EXPtoString(e.op).ptr, e.toChars(), e.loc.toChars());
printf("be = '%s' %s at [%s]\n", expressionTypeToString(e.op).ptr, e.toChars(), e.loc.toChars());

Check warning on line 3269 in compiler/src/dmd/dinterpret.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dinterpret.d#L3269

Added line #L3269 was not covered by tests
assert(0);
}
}
Expand Down Expand Up @@ -4778,7 +4778,7 @@ public:
if (auto ce = ea.isCastExp())
ea = ce.e1;

// printf("2 ea = %s, %s %s\n", ea.type.toChars(), EXPtoString(ea.op).ptr, ea.toChars());
// printf("2 ea = %s, %s %s\n", ea.type.toChars(), expressionTypeToString(ea.op).ptr, ea.toChars());
if (ea.op == EXP.variable || ea.op == EXP.symbolOffset)
result = getVarExp(e.loc, istate, (cast(SymbolExp)ea).var, CTFEGoal.RValue);
else if (auto ae = ea.isAddrExp())
Expand Down Expand Up @@ -7130,7 +7130,7 @@ private Expression copyRegionExp(Expression e)
return e;

default:
printf("e: %s, %s\n", EXPtoString(e.op).ptr, e.toChars());
printf("e: %s, %s\n", expressionTypeToString(e.op).ptr, e.toChars());

Check warning on line 7133 in compiler/src/dmd/dinterpret.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dinterpret.d#L7133

Added line #L7133 was not covered by tests
assert(0);
}

Expand Down
20 changes: 10 additions & 10 deletions compiler/src/dmd/doc.d
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ final class ParamSection : Section
}
else if (fparam && fparam.type && fparam.ident)
{
toCBuffer(fparam.type, buf, fparam.ident, hgs);
hgs.toCBuffer(fparam.type, buf, fparam.ident);
}
else
{
Expand Down Expand Up @@ -1227,7 +1227,7 @@ void toDocBuffer(Dsymbol s, ref OutBuffer buf, Scope* sc)
//printf("Dsymbol::toDocbuffer() %s\n", s.toChars());
HdrGenState hgs;
hgs.ddoc = true;
toCBuffer(s, *buf, hgs);
hgs.toCBuffer(s, *buf);
}

void prefix(Dsymbol s)
Expand Down Expand Up @@ -1277,7 +1277,7 @@ void toDocBuffer(Dsymbol s, ref OutBuffer buf, Scope* sc)
HdrGenState hgs;
hgs.ddoc = true;
emitVisibility(*buf, i);
toCBuffer(i, *buf, hgs);
hgs.toCBuffer(i, *buf);
}

override void visit(Declaration d)
Expand All @@ -1296,10 +1296,10 @@ void toDocBuffer(Dsymbol s, ref OutBuffer buf, Scope* sc)
Type origType = d.originalType ? d.originalType : d.type;
if (origType.ty == Tfunction)
{
functionToBufferFull(cast(TypeFunction)origType, *buf, d.ident, hgs, td);
hgs.functionSignatureToBuffer(cast(TypeFunction)origType, *buf, d.ident, td);
}
else
toCBuffer(origType, *buf, d.ident, hgs);
hgs.toCBuffer(origType, *buf, d.ident);
}
else
buf.writestring(d.ident.toString());
Expand All @@ -1312,7 +1312,7 @@ void toDocBuffer(Dsymbol s, ref OutBuffer buf, Scope* sc)
{
if (i)
buf.writestring(", ");
toCBuffer((*td.origParameters)[i], *buf, hgs);
hgs.toCBuffer((*td.origParameters)[i], *buf);
}
}
buf.writeByte(')');
Expand All @@ -1326,7 +1326,7 @@ void toDocBuffer(Dsymbol s, ref OutBuffer buf, Scope* sc)
buf.writestring("$(DDOC_CONSTRAINT ");
}

toCBuffer(td.constraint, *buf, hgs);
hgs.toCBuffer(td.constraint, *buf);

if (noFuncDecl)
{
Expand Down Expand Up @@ -1487,7 +1487,7 @@ void toDocBuffer(Dsymbol s, ref OutBuffer buf, Scope* sc)
else
{
HdrGenState hgs;
toCBuffer(bc.type, *buf, null, hgs);
hgs.toCBuffer(bc.type, *buf, null);
}
}
buf.writestring(";\n");
Expand All @@ -1502,7 +1502,7 @@ void toDocBuffer(Dsymbol s, ref OutBuffer buf, Scope* sc)
{
buf.writestring(": $(DDOC_ENUM_BASETYPE ");
HdrGenState hgs;
toCBuffer(ed.memtype, *buf, null, hgs);
hgs.toCBuffer(ed.memtype, *buf, null);
buf.writestring(")");
}
buf.writestring(";\n");
Expand Down Expand Up @@ -5078,7 +5078,7 @@ void highlightCode(Scope* sc, Dsymbols* a, ref OutBuffer buf, size_t offset)

size_t lastOffset = parametersBuf.length;

toCBuffer(tp, parametersBuf, hgs);
hgs.toCBuffer(tp, parametersBuf);

paramLens[parami] = parametersBuf.length - lastOffset;
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
else
{
OutBuffer buf;
stcToBuffer(buf, stc);
storageClassToBuffer(buf, stc);

Check warning on line 899 in compiler/src/dmd/dsymbolsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbolsem.d#L899

Added line #L899 was not covered by tests
.error(dsym.loc, "%s `%s` cannot be `%s`", dsym.kind, dsym.toPrettyChars, buf.peekChars());
}
dsym.storage_class &= ~stc; // strip off
Expand All @@ -913,7 +913,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
if (stc)
{
OutBuffer buf;
stcToBuffer(buf, stc);
storageClassToBuffer(buf, stc);

Check warning on line 916 in compiler/src/dmd/dsymbolsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbolsem.d#L916

Added line #L916 was not covered by tests
.error(dsym.loc, "%s `%s` cannot be `scope` and `%s`", dsym.kind, dsym.toPrettyChars, buf.peekChars());
}
else if (dsym.isMember())
Expand Down Expand Up @@ -1671,7 +1671,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
ob.writeByte(' ');
if (imp.isstatic)
{
stcToBuffer(*ob, STC.static_);
storageClassToBuffer(*ob, STC.static_);

Check warning on line 1674 in compiler/src/dmd/dsymbolsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbolsem.d#L1674

Added line #L1674 was not covered by tests
ob.writeByte(' ');
}
ob.writestring(": ");
Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dmd/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ private bool match(RootObject o1, RootObject o2)

static if (log)
{
printf("\te1 = %s '%s' %s\n", e1.type ? e1.type.toChars() : "null", EXPtoString(e1.op).ptr, e1.toChars());
printf("\te2 = %s '%s' %s\n", e2.type ? e2.type.toChars() : "null", EXPtoString(e2.op).ptr, e2.toChars());
printf("\te1 = %s '%s' %s\n", e1.type ? e1.type.toChars() : "null", expressionTypeToString(e1.op).ptr, e1.toChars());
printf("\te2 = %s '%s' %s\n", e2.type ? e2.type.toChars() : "null", expressionTypeToString(e2.op).ptr, e2.toChars());
}

// two expressions can be equal although they do not have the same
Expand Down Expand Up @@ -747,7 +747,7 @@ extern (C++) final class TemplateDeclaration : ScopeDsymbol
{
HdrGenState hgs;
OutBuffer buf;
toCharsMaybeConstraints(this, buf, hgs);
hgs.toCharsMaybeConstraints(this, buf);
return buf.extractChars();
}

Expand All @@ -758,7 +758,7 @@ extern (C++) final class TemplateDeclaration : ScopeDsymbol
{
HdrGenState hgs = { skipConstraints: true };
OutBuffer buf;
toCharsMaybeConstraints(this, buf, hgs);
hgs.toCharsMaybeConstraints(this, buf);

Check warning on line 761 in compiler/src/dmd/dtemplate.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dtemplate.d#L761

Added line #L761 was not covered by tests
return buf.extractChars();
}

Expand Down Expand Up @@ -4581,7 +4581,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol
else if (ea)
{
Lexpr:
//printf("+[%d] ea = %s %s\n", j, EXPtoString(ea.op).ptr, ea.toChars());
//printf("+[%d] ea = %s %s\n", j, expressionTypeToString(ea.op).ptr, ea.toChars());
if (flags & 1) // only used by __traits
{
ea = ea.expressionSemantic(sc);
Expand Down Expand Up @@ -4626,7 +4626,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol
ea = ErrorExp.get();
}
}
//printf("-[%d] ea = %s %s\n", j, EXPtoString(ea.op).ptr, ea.toChars());
//printf("-[%d] ea = %s %s\n", j, expressionTypeToString(ea.op).ptr, ea.toChars());
if (TupleExp te = ea.isTupleExp())
{
// Expand tuple
Expand Down Expand Up @@ -4979,7 +4979,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol
OutBuffer buf;
HdrGenState hgs;
hgs.skipConstraints = true;
toCharsMaybeConstraints(tdecl, buf, hgs);
hgs.toCharsMaybeConstraints(tdecl, buf);
const tmsg = buf.peekChars();
const cmsg = tdecl.getConstraintEvalError(tip);
if (cmsg)
Expand Down Expand Up @@ -6388,7 +6388,7 @@ void printTemplateStats(bool listInstances, ErrorSink eSink)
buf.reset();
HdrGenState hgs;
hgs.skipConstraints = true;
toCharsMaybeConstraints(ss.td, buf, hgs);
hgs.toCharsMaybeConstraints(ss.td, buf);
const tchars = buf.peekChars();
if (listInstances && ss.ts.allInstances)
{
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/dtoh.d
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,7 @@ public:
case identity: return "==";
case notIdentity: return "!=";
default:
return EXPtoString(op);
return expressionTypeToString(op);
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/e2ir.d
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ elem* toElem(Expression e, ref IRState irs)
{
elem* visit(Expression e)
{
printf("[%s] %s: %s\n", e.loc.toChars(), EXPtoString(e.op).ptr, e.toChars());
printf("[%s] %s: %s\n", e.loc.toChars(), expressionTypeToString(e.op).ptr, e.toChars());

Check warning on line 565 in compiler/src/dmd/e2ir.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/e2ir.d#L565

Added line #L565 was not covered by tests
assert(0);
}

Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dmd/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,15 @@ extern (C++) abstract class Expression : ASTNode

dinteger_t toInteger()
{
//printf("Expression %s\n", EXPtoString(op).ptr);
//printf("Expression %s\n", expressionTypeToString(op).ptr);
if (!type.isTypeError())
error(loc, "integer constant expression expected instead of `%s`", toChars());
return 0;
}

uinteger_t toUInteger()
{
//printf("Expression %s\n", EXPtoString(op).ptr);
//printf("Expression %s\n", expressionTypeToString(op).ptr);
return cast(uinteger_t)toInteger();
}

Expand Down Expand Up @@ -601,7 +601,7 @@ extern (C++) abstract class Expression : ASTNode
const char* msg = type.isAggregate() ?
"operator `%s` is not defined for `%s` of type `%s`" :
"illegal operator `%s` for `%s` of type `%s`";
error(loc, msg, EXPtoString(op).ptr, toChars(), type.toChars());
error(loc, msg, expressionTypeToString(op).ptr, toChars(), type.toChars());
return true;
}
return checkValue();
Expand Down Expand Up @@ -635,7 +635,7 @@ extern (C++) abstract class Expression : ASTNode

error(loc, "read-modify-write operations are not allowed for `shared` variables");
errorSupplemental(loc, "Use `core.atomic.atomicOp!\"%s\"(%s, %s)` instead",
EXPtoString(rmwOp).ptr, toChars(), ex ? ex.toChars() : "1");
expressionTypeToString(rmwOp).ptr, toChars(), ex ? ex.toChars() : "1");

Check warning on line 638 in compiler/src/dmd/expression.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/expression.d#L638

Added line #L638 was not covered by tests
return true;
}

Expand Down Expand Up @@ -3036,11 +3036,11 @@ extern (C++) abstract class UnaExp : Expression

if (e1.op == EXP.type)
{
error(loc, "incompatible type for `%s(%s)`: cannot use `%s` with types", EXPtoString(op).ptr, e1.toChars(), EXPtoString(op).ptr);
error(loc, "incompatible type for `%s(%s)`: cannot use `%s` with types", expressionTypeToString(op).ptr, e1.toChars(), expressionTypeToString(op).ptr);

Check warning on line 3039 in compiler/src/dmd/expression.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/expression.d#L3039

Added line #L3039 was not covered by tests
}
else
{
error(loc, "incompatible type for `%s(%s)`: `%s`", EXPtoString(op).ptr, e1.toChars(), e1.type.toChars());
error(loc, "incompatible type for `%s(%s)`: `%s`", expressionTypeToString(op).ptr, e1.toChars(), e1.type.toChars());
}
return ErrorExp.get();
}
Expand Down Expand Up @@ -3103,11 +3103,11 @@ extern (C++) abstract class BinExp : Expression
return e2;

// CondExp uses 'a ? b : c' but we're comparing 'b : c'
const(char)* thisOp = (op == EXP.question) ? ":" : EXPtoString(op).ptr;
const(char)* thisOp = (op == EXP.question) ? ":" : expressionTypeToString(op).ptr;
if (e1.op == EXP.type || e2.op == EXP.type)
{
error(loc, "incompatible types for `(%s) %s (%s)`: cannot use `%s` with types",
e1.toChars(), thisOp, e2.toChars(), EXPtoString(op).ptr);
e1.toChars(), thisOp, e2.toChars(), expressionTypeToString(op).ptr);
}
else if (e1.type.equals(e2.type))
{
Expand Down
Loading

0 comments on commit 48a49ef

Please sign in to comment.