Skip to content

Commit

Permalink
Merge pull request #4945 from yebblies/typeinfod
Browse files Browse the repository at this point in the history
Convert typinf.c to D
  • Loading branch information
9rnsr committed Aug 24, 2015
2 parents 937ef39 + cb14a7d commit 010fc41
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 158 deletions.
5 changes: 2 additions & 3 deletions src/gluestub.d
Expand Up @@ -9,7 +9,7 @@

module ddmd.gluestub;

import ddmd.backend, ddmd.aggregate, ddmd.dmodule, ddmd.lib, ddmd.root.file, ddmd.statement, ddmd.dscope, ddmd.mtype;
import ddmd.backend, ddmd.aggregate, ddmd.dmodule, ddmd.lib, ddmd.root.file, ddmd.statement, ddmd.dscope, ddmd.mtype, ddmd.dsymbol;

// tocsym

Expand Down Expand Up @@ -90,7 +90,6 @@ extern (C++) RET retStyle(TypeFunction tf)
return RETregs;
}

extern (C++) Type getTypeInfoType(Type t, Scope* sc)
extern (C++) void toObjFile(Dsymbol ds, bool multiobj)
{
return Type.dtypeinfo.type;
}
7 changes: 4 additions & 3 deletions src/posix.mak
Expand Up @@ -182,7 +182,8 @@ DMD_SRCS=$(addsuffix .d,access aggregate aliasthis apply argtypes arrayop \
dtemplate dunittest dversion entity errors escape expression func \
globals hdrgen id identifier impcnvtab imphint init inline intrange \
json lexer lib link mars mtype nogc nspace opover optimize parse sapply \
sideeffect statement staticassert target tokens traits utf visitor)
sideeffect statement staticassert target tokens traits utf visitor \
typinf)

ifeq ($(D_OBJC),1)
DMD_SRCS += objc.d
Expand All @@ -195,7 +196,7 @@ ROOT_SRCS = $(addsuffix .d,$(addprefix $(ROOT)/,aav array file filename \
stringtable))

GLUE_OBJS = glue.o msc.o s2ir.o todt.o e2ir.o tocsym.o toobj.o toctype.o \
toelfdebug.o toir.o irstate.o typinf.o iasm.o
toelfdebug.o toir.o irstate.o iasm.o


ifeq ($(D_OBJC),1)
Expand Down Expand Up @@ -244,7 +245,7 @@ ROOT_SRC = $(addprefix $(ROOT)/,aav.h array.h file.h filename.h \

GLUE_SRC = glue.c msc.c s2ir.c todt.c e2ir.c tocsym.c \
toobj.c toctype.c tocvdebug.c toir.h toir.c \
libmscoff.c scanmscoff.c irstate.h irstate.c typinf.c iasm.c \
libmscoff.c scanmscoff.c irstate.h irstate.c iasm.c \
toelfdebug.c libelf.c scanelf.c libmach.c scanmach.c \
tk.c eh.c gluestub.c objc_glue.c objc_glue_stubs.c

Expand Down
146 changes: 0 additions & 146 deletions src/typinf.c

This file was deleted.

129 changes: 129 additions & 0 deletions src/typinf.d
@@ -0,0 +1,129 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2015 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt

module ddmd.typinf;

import ddmd.declaration, ddmd.dmodule, ddmd.dscope, ddmd.dstruct, ddmd.dsymbol, ddmd.errors, ddmd.globals, ddmd.mtype;

extern (C++) void toObjFile(Dsymbol ds, bool multiobj);

/****************************************************
* Get the exact TypeInfo.
*/
extern (C++) void genTypeInfo(Type torig, Scope* sc)
{
//printf("Type::genTypeInfo() %p, %s\n", this, toChars());
if (!Type.dtypeinfo)
{
torig.error(Loc(), "TypeInfo not found. object.d may be incorrectly installed or corrupt, compile with -v switch");
fatal();
}
Type t = torig.merge2(); // do this since not all Type's are merge'd
if (!t.vtinfo)
{
if (t.isShared()) // does both 'shared' and 'shared const'
t.vtinfo = TypeInfoSharedDeclaration.create(t);
else if (t.isConst())
t.vtinfo = TypeInfoConstDeclaration.create(t);
else if (t.isImmutable())
t.vtinfo = TypeInfoInvariantDeclaration.create(t);
else if (t.isWild())
t.vtinfo = TypeInfoWildDeclaration.create(t);
else
t.vtinfo = getTypeInfoDeclaration(t);
assert(t.vtinfo);
/* If this has a custom implementation in std/typeinfo, then
* do not generate a COMDAT for it.
*/
if (!builtinTypeInfo(t))
{
// Generate COMDAT
if (sc) // if in semantic() pass
{
if (sc.func && sc.func.inNonRoot())
{
// Bugzilla 13043: Avoid linking TypeInfo if it's not
// necessary for root module compilation
}
else
{
// Find module that will go all the way to an object file
Module m = sc._module.importedFrom;
m.members.push(t.vtinfo);
semanticTypeInfo(sc, t);
}
}
else // if in obj generation pass
{
toObjFile(t.vtinfo, global.params.multiobj);
}
}
}
if (!torig.vtinfo)
torig.vtinfo = t.vtinfo; // Types aren't merged, but we can share the vtinfo's
assert(torig.vtinfo);
}

extern (C++) Type getTypeInfoType(Type t, Scope* sc)
{
assert(t.ty != Terror);
genTypeInfo(t, sc);
return t.vtinfo.type;
}

extern (C++) TypeInfoDeclaration getTypeInfoDeclaration(Type t)
{
//printf("Type::getTypeInfoDeclaration() %s\n", t->toChars());
switch (t.ty)
{
case Tpointer:
return TypeInfoPointerDeclaration.create(t);
case Tarray:
return TypeInfoArrayDeclaration.create(t);
case Tsarray:
return TypeInfoStaticArrayDeclaration.create(t);
case Taarray:
return TypeInfoAssociativeArrayDeclaration.create(t);
case Tstruct:
return TypeInfoStructDeclaration.create(t);
case Tvector:
return TypeInfoVectorDeclaration.create(t);
case Tenum:
return TypeInfoEnumDeclaration.create(t);
case Tfunction:
return TypeInfoFunctionDeclaration.create(t);
case Tdelegate:
return TypeInfoDelegateDeclaration.create(t);
case Ttuple:
return TypeInfoTupleDeclaration.create(t);
case Tclass:
if ((cast(TypeClass)t).sym.isInterfaceDeclaration())
return TypeInfoInterfaceDeclaration.create(t);
else
return TypeInfoClassDeclaration.create(t);
default:
return TypeInfoDeclaration.create(t, 0);
}
}

/* ========================================================================= */
/* These decide if there's an instance for them already in std.typeinfo,
* because then the compiler doesn't need to build one.
*/
extern (C++) static bool builtinTypeInfo(Type t)
{
if (t.isTypeBasic() || t.ty == Tclass)
return !t.mod;
if (t.ty == Tarray)
{
Type next = t.nextOf();
// strings are so common, make them builtin
return !t.mod && (next.isTypeBasic() !is null && !next.mod || next.ty == Tchar && next.mod == MODimmutable || next.ty == Tchar && next.mod == MODconst);
}
return false;
}
9 changes: 3 additions & 6 deletions src/win32.mak
Expand Up @@ -147,12 +147,12 @@ DMD_SRCS=access.d aggregate.d aliasthis.d apply.d argtypes.d arrayop.d \
impcnvtab.d init.d inline.d intrange.d json.d lexer.d lib.d link.d \
mars.d mtype.d nogc.d nspace.d objc_stubs.d opover.d optimize.d parse.d \
sapply.d sideeffect.d statement.d staticassert.d target.d tokens.d \
traits.d utf.d visitor.d libomf.d scanomf.d
traits.d utf.d visitor.d libomf.d scanomf.d typinf.d

# Glue layer
GLUEOBJ=glue.obj msc.obj s2ir.obj todt.obj e2ir.obj tocsym.obj \
toobj.obj toctype.obj tocvdebug.obj toir.obj \
libmscoff.obj scanmscoff.obj irstate.obj typinf.obj \
libmscoff.obj scanmscoff.obj irstate.obj \
iasm.obj objc_glue_stubs.obj

# D back end
Expand Down Expand Up @@ -186,7 +186,7 @@ SRCS = win32.mak posix.mak osmodel.mak aggregate.h aliasthis.h arraytypes.h \
# Glue layer
GLUESRC= glue.c msc.c s2ir.c todt.c e2ir.c tocsym.c \
toobj.c toctype.c tocvdebug.c toir.h toir.c \
libmscoff.c scanmscoff.c irstate.h irstate.c typinf.c iasm.c \
libmscoff.c scanmscoff.c irstate.h irstate.c iasm.c \
toelfdebug.c libelf.c scanelf.c libmach.c scanmach.c \
tk.c eh.c objc_glue_stubs.c objc_glue.c

Expand Down Expand Up @@ -549,9 +549,6 @@ toobj.obj : $(CH) $(TOTALH) mars.h module.h toobj.c
type.obj : $C\type.c
$(CC) -c $(MFLAGS) $C\type

typinf.obj : $(CH) $(TOTALH) $C\rtlsym.h mars.h module.h typinf.c
$(CC) -c $(MFLAGS) -I$(ROOT) typinf

todt.obj : mtype.h expression.h $C\dt.h todt.c
$(CC) -c -I$(ROOT) $(MFLAGS) todt

Expand Down

0 comments on commit 010fc41

Please sign in to comment.