Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4945 from yebblies/typeinfod
Convert typinf.c to D
- Loading branch information
Showing
5 changed files
with
138 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters