Skip to content

Commit

Permalink
fix Issue 23658 - .di generation of variables should turn them into d…
Browse files Browse the repository at this point in the history
…eclarations
  • Loading branch information
WalterBright committed Jan 28, 2023
1 parent 72af67c commit 146c41d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 4 additions & 1 deletion compiler/src/dmd/frontend.h
Expand Up @@ -2812,6 +2812,7 @@ struct HdrGenState final
int32_t autoMember;
int32_t forStmtInit;
int32_t insideFuncBody;
int32_t insideAggregate;
bool declstring;
EnumDeclaration* inEnumDecl;
HdrGenState() :
Expand All @@ -2823,11 +2824,12 @@ struct HdrGenState final
autoMember(),
forStmtInit(),
insideFuncBody(),
insideAggregate(),
declstring(),
inEnumDecl()
{
}
HdrGenState(bool hdrgen, bool ddoc = false, bool fullDump = false, bool fullQual = false, int32_t tpltMember = 0, int32_t autoMember = 0, int32_t forStmtInit = 0, int32_t insideFuncBody = 0, bool declstring = false, EnumDeclaration* inEnumDecl = nullptr) :
HdrGenState(bool hdrgen, bool ddoc = false, bool fullDump = false, bool fullQual = false, int32_t tpltMember = 0, int32_t autoMember = 0, int32_t forStmtInit = 0, int32_t insideFuncBody = 0, int32_t insideAggregate = 0, bool declstring = false, EnumDeclaration* inEnumDecl = nullptr) :
hdrgen(hdrgen),
ddoc(ddoc),
fullDump(fullDump),
Expand All @@ -2836,6 +2838,7 @@ struct HdrGenState final
autoMember(autoMember),
forStmtInit(forStmtInit),
insideFuncBody(insideFuncBody),
insideAggregate(insideAggregate),
declstring(declstring),
inEnumDecl(inEnumDecl)
{}
Expand Down
19 changes: 17 additions & 2 deletions compiler/src/dmd/hdrgen.d
Expand Up @@ -65,6 +65,7 @@ struct HdrGenState
int autoMember;
int forStmtInit;
int insideFuncBody;
int insideAggregate;

bool declstring; // set while declaring alias for string,wstring or dstring
EnumDeclaration inEnumDecl;
Expand Down Expand Up @@ -1406,8 +1407,10 @@ public:
buf.writeByte('{');
buf.writenl();
buf.level++;
hgs.insideAggregate++;
foreach (s; *d.members)
s.accept(this);
hgs.insideAggregate--;
buf.level--;
buf.writeByte('}');
buf.writenl();
Expand All @@ -1428,8 +1431,10 @@ public:
buf.writeByte('{');
buf.writenl();
buf.level++;
hgs.insideAggregate++;
foreach (s; *d.members)
s.accept(this);
hgs.insideAggregate--;
buf.level--;
buf.writeByte('}');
}
Expand Down Expand Up @@ -1521,21 +1526,31 @@ public:

void visitVarDecl(VarDeclaration v, bool anywritten)
{
const bool isextern = hgs.hdrgen &&
!hgs.insideFuncBody &&
!hgs.tpltMember &&
!hgs.insideAggregate &&
!(v.storage_class & (STC.manifest | STC.auto_)) &&
v.type;

if (anywritten)
{
buf.writestring(", ");
buf.writestring(v.ident.toString());
}
else
{
if (stcToBuffer(buf, v.storage_class))
auto stc = v.storage_class;
if (isextern)
stc |= STC.extern_;
if (stcToBuffer(buf, stc))
buf.writeByte(' ');
if (v.type)
typeToBuffer(v.type, v.ident, buf, hgs);
else
buf.writestring(v.ident.toString());
}
if (v._init)
if (v._init && !isextern)
{
buf.writestring(" = ");
auto ie = v._init.isExpInitializer();
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/compilable/extra-files/header1.di
Expand Up @@ -277,7 +277,7 @@ void templ(T)(T val)
{
pragma (msg, "Invalid destination type.");
}
static char[] charArray = ['"', '\''];
static extern char[] charArray;
class Point
{
auto x = 10;
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/compilable/extra-files/header1i.di
Expand Up @@ -357,7 +357,7 @@ void templ(T)(T val)
{
pragma (msg, "Invalid destination type.");
}
static char[] charArray = ['"', '\''];
static extern char[] charArray;
class Point
{
auto x = 10;
Expand Down

0 comments on commit 146c41d

Please sign in to comment.