Skip to content

Commit

Permalink
Break mtype.d dependency on dmangle.d (#16016)
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanN7 authored Jan 11, 2024
1 parent f5dd1a8 commit e64aaee
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
29 changes: 29 additions & 0 deletions compiler/src/dmd/declaration.d
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,35 @@ extern (C++) final class SymbolDeclaration : Declaration

/***********************************************************
*/
private Identifier getTypeInfoIdent(Type t)
{
import dmd.dmangle;
import core.stdc.stdlib;
import dmd.root.rmem;
// _init_10TypeInfo_%s
OutBuffer buf;
buf.reserve(32);
mangleToBuffer(t, buf);

const slice = buf[];

// Allocate buffer on stack, fail over to using malloc()
char[128] namebuf;
const namelen = 19 + size_t.sizeof * 3 + slice.length + 1;
auto name = namelen <= namebuf.length ? namebuf.ptr : cast(char*)Mem.check(malloc(namelen));

const length = snprintf(name, namelen, "_D%lluTypeInfo_%.*s6__initZ",
cast(ulong)(9 + slice.length), cast(int)slice.length, slice.ptr);
//printf("%p %s, deco = %s, name = %s\n", this, toChars(), deco, name);
assert(0 < length && length < namelen); // don't overflow the buffer

auto id = Identifier.idPool(name[0 .. length]);

if (name != namebuf.ptr)
free(name);
return id;
}

extern (C++) class TypeInfoDeclaration : VarDeclaration
{
Type tinfo;
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,6 @@ class Type : public ASTNode
virtual structalign_t alignment();
virtual Expression* defaultInitLiteral(const Loc& loc);
virtual bool isZeroInit(const Loc& loc);
Identifier* getTypeInfoIdent();
virtual int32_t hasWild() const;
virtual bool hasVoidInitPointers();
virtual bool hasSystemFields();
Expand Down
27 changes: 0 additions & 27 deletions compiler/src/dmd/mtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import dmd.dclass;
import dmd.dcast;
import dmd.declaration;
import dmd.denum;
import dmd.dmangle;
import dmd.dscope;
import dmd.dstruct;
import dmd.dsymbol;
Expand Down Expand Up @@ -2150,32 +2149,6 @@ extern (C++) abstract class Type : ASTNode
return false; // assume not
}

final Identifier getTypeInfoIdent()
{
// _init_10TypeInfo_%s
OutBuffer buf;
buf.reserve(32);
mangleToBuffer(this, buf);

const slice = buf[];

// Allocate buffer on stack, fail over to using malloc()
char[128] namebuf;
const namelen = 19 + size_t.sizeof * 3 + slice.length + 1;
auto name = namelen <= namebuf.length ? namebuf.ptr : cast(char*)Mem.check(malloc(namelen));

const length = snprintf(name, namelen, "_D%lluTypeInfo_%.*s6__initZ",
cast(ulong)(9 + slice.length), cast(int)slice.length, slice.ptr);
//printf("%p %s, deco = %s, name = %s\n", this, toChars(), deco, name);
assert(0 < length && length < namelen); // don't overflow the buffer

auto id = Identifier.idPool(name[0 .. length]);

if (name != namebuf.ptr)
free(name);
return id;
}

/***************************************
* Return !=0 if the type or any of its subtypes is wild.
*/
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dmd/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ class Type : public ASTNode
virtual structalign_t alignment();
virtual Expression *defaultInitLiteral(const Loc &loc);
virtual bool isZeroInit(const Loc &loc = Loc()); // if initializer is 0
Identifier *getTypeInfoIdent();
virtual int hasWild() const;
virtual bool hasVoidInitPointers();
virtual bool hasSystemFields();
Expand Down

0 comments on commit e64aaee

Please sign in to comment.