Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions compiler/src/dmd/cparse.d
Original file line number Diff line number Diff line change
Expand Up @@ -5075,8 +5075,7 @@ final class CParser(AST) : Parser!AST
if (pt && *pt)
t = *pt;
}
if (t.mcache && t.mcache.typedefIdent)
{
if ((t.mcache && t.mcache.typedefIdent) || t.isTypeBasic()) {
t = t.copy();
t.mcache = null;
}
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -4082,6 +4082,7 @@ struct HdrGenState final
bool fullDump;
bool importcHdr;
bool inCAlias;
bool inFuncReturn;
bool doFuncBodies;
bool vcg_ast;
bool skipConstraints;
Expand All @@ -4101,6 +4102,7 @@ struct HdrGenState final
fullDump(),
importcHdr(),
inCAlias(),
inFuncReturn(),
doFuncBodies(),
vcg_ast(),
skipConstraints(),
Expand All @@ -4116,12 +4118,13 @@ struct HdrGenState final
inEnumDecl()
{
}
HdrGenState(bool hdrgen, bool ddoc = false, bool fullDump = false, bool importcHdr = false, bool inCAlias = false, bool doFuncBodies = false, bool vcg_ast = false, bool skipConstraints = false, bool showOneMember = true, bool errorMsg = 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) :
HdrGenState(bool hdrgen, bool ddoc = false, bool fullDump = false, bool importcHdr = false, bool inCAlias = false, bool inFuncReturn = false, bool doFuncBodies = false, bool vcg_ast = false, bool skipConstraints = false, bool showOneMember = true, bool errorMsg = 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),
importcHdr(importcHdr),
inCAlias(inCAlias),
inFuncReturn(inFuncReturn),
doFuncBodies(doFuncBodies),
vcg_ast(vcg_ast),
skipConstraints(skipConstraints),
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dmd/hdrgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct HdrGenState
bool fullDump; /// true if generating a full AST dump file
bool importcHdr; /// true if generating a .di file from an ImportC file
bool inCAlias; /// Set to prevent ImportC translating typedefs as `alias X = X`
bool inFuncReturn; /// Set when printing function return type to avoid typedef name
bool doFuncBodies; /// include function bodies in output
bool vcg_ast; /// write out codegen-ast
bool skipConstraints; // skip constraints when doing templates
Expand Down Expand Up @@ -4096,7 +4097,9 @@ private void visitFuncIdentWithPostfix(TypeFunction t, const char[] ident, ref O
buf.write("static ");
if (t.next)
{
hgs.inFuncReturn = true;
typeToBuffer(t.next, null, buf, hgs);
hgs.inFuncReturn = false;
if (ident)
buf.put(' ');
}
Expand Down Expand Up @@ -4165,7 +4168,9 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te
}
else if (t.next)
{
hgs.inFuncReturn = true;
typeToBuffer(t.next, null, buf, hgs);
hgs.inFuncReturn = false;
if (ident)
buf.put(' ');
}
Expand Down Expand Up @@ -4547,7 +4552,7 @@ private void typeToBufferx(Type t, ref OutBuffer buf, ref HdrGenState hgs)
buf.put("noreturn");
}

if (hgs.importcHdr && !hgs.inCAlias && t.mcache && t.mcache.typedefIdent)
if (hgs.importcHdr && !hgs.inCAlias && !hgs.inFuncReturn && t.mcache && t.mcache.typedefIdent)
{
buf.put(t.mcache.typedefIdent.toString());
return;
Expand Down
13 changes: 13 additions & 0 deletions compiler/test/compilable/ctod.i
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ extern (C)
Callback cb = void;
}
extern __gshared int[cast(ULONG)3] arr;
alias NOPE1 = void;
void mylib_hello1();
alias NOPE2 = int;
int mylib_hello2();
void mylib_hello3(void*);
/+enum int __DATE__ = 1+/;
/+enum int __TIME__ = 1+/;
/+enum int __TIMESTAMP__ = 1+/;
Expand Down Expand Up @@ -131,3 +136,11 @@ int arr[(ULONG) 3];
#define DEF 123
#define SQL_DRIVER_STMT_ATTR_BASE 0x00004000 // 32-bit
#define ABC 64

typedef void NOPE1;
void mylib_hello1(void);

typedef int NOPE2;
int mylib_hello2(void);

void mylib_hello3(void*);
Loading