Skip to content

Commit b59bd53

Browse files
committed
mtype.h: Add convenience methods back to Type class
1 parent 24a4107 commit b59bd53

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

compiler/src/dmd/mtype.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ typedef struct TYPE type;
4242

4343
namespace dmd
4444
{
45+
void Type_init();
4546
Type *typeSemantic(Type *t, Loc loc, Scope *sc);
4647
Type *merge(Type *type);
4748
Expression *defaultInitLiteral(Type *t, Loc loc);
49+
Type *toBasetype(Type *type);
50+
Type *nextOf(Type* type);
51+
Type *baseElemOf(Type* type);
4852
}
4953

5054
enum class TY : uint8_t
@@ -215,6 +219,8 @@ class Type : public ASTNode
215219

216220
static Type *basic[(int)TY::TMAX];
217221

222+
static void _init() { return dmd::Type_init(); }
223+
218224
virtual const char *kind();
219225
Type *copy() const;
220226
virtual Type *syntaxCopy();
@@ -241,6 +247,10 @@ class Type : public ASTNode
241247
bool isNaked() const { return mod == 0; }
242248
Type *nullAttributes() const;
243249

250+
Type *toBasetype() { return dmd::toBasetype(this); }
251+
Type *nextOf() { return dmd::nextOf(this); }
252+
Type *baseElemOf() { return dmd::baseElemOf(this); }
253+
244254
virtual ClassDeclaration *isClassHandle();
245255
virtual int hasWild() const;
246256

@@ -732,15 +742,13 @@ namespace dmd
732742
Type *addMod(Type *type, MOD mod);
733743
Type *addStorageClass(Type *type, StorageClass stc);
734744
Type *substWildTo(Type *type, unsigned mod);
735-
Type *toBasetype(Type *type);
736745
uinteger_t size(Type *type);
737746
uinteger_t size(Type *type, Loc loc);
738747
MATCH implicitConvTo(Type* from, Type* to);
739748
MATCH constConv(Type* from, Type* to);
740749
bool hasUnsafeBitpatterns(Type* type);
741750
bool hasInvariant(Type* type);
742751
bool hasVoidInitPointers(Type* type);
743-
void Type_init();
744752
void transitive(TypeNext* type);
745753
structalign_t alignment(Type* type);
746754
Type* memType(TypeEnum* type);
@@ -754,8 +762,6 @@ namespace dmd
754762
Type *makeWildConst(Type* type);
755763
Type *makeSharedWild(Type* type);
756764
Type *makeSharedWildConst(Type* type);
757-
Type *nextOf(Type* type);
758-
Type *baseElemOf(Type* type);
759765
Type *isLazyArray(Parameter* param);
760766
unsigned char deduceWild(Type* type, Type* t, bool isRef);
761767
bool isIntegral(Type* type);

compiler/src/tests/cxxfrontend.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static void frontend_init()
7878
target.cpu = CPU::native;
7979
target._init(global.params);
8080

81-
dmd::Type_init();
81+
Type::_init();
8282
Id::initialize();
8383
Module::_init();
8484
Expression::_init();
@@ -956,7 +956,7 @@ class MiniGlueVisitor : public Visitor
956956
{
957957
s->getRelatedLabeled()->accept(this);
958958
s->condition->accept(this);
959-
Type *condtype = dmd::baseElemOf(s->condition->type);
959+
Type *condtype = s->condition->type->toBasetype();
960960
if (!dmd::isScalar(condtype))
961961
assert(0);
962962
if (s->cases)
@@ -1002,11 +1002,11 @@ class MiniGlueVisitor : public Visitor
10021002
}
10031003
void visit(ReturnStatement *s) override
10041004
{
1005-
if (s->exp == NULL || dmd::toBasetype(s->exp->type)->ty == TY::Tvoid)
1005+
if (s->exp == NULL || s->exp->type->toBasetype()->ty == TY::Tvoid)
10061006
return;
10071007
TypeFunction *tf = func->type->toTypeFunction();
1008-
Type *type = func->tintro != NULL ? dmd::nextOf(func->tintro) : dmd::nextOf(tf);
1009-
if ((func->isMain() || func->isCMain()) && dmd::toBasetype(type)->ty == TY::Tvoid)
1008+
Type *type = func->tintro != NULL ? func->tintro->nextOf() : tf->nextOf();
1009+
if ((func->isMain() || func->isCMain()) && type->toBasetype()->ty == TY::Tvoid)
10101010
type = Type::tint32;
10111011
if (func->shidden)
10121012
{
@@ -1037,7 +1037,7 @@ class MiniGlueVisitor : public Visitor
10371037
sle = s->exp->isStructLiteralExp();
10381038
if (sle != NULL)
10391039
{
1040-
dmd::baseElemOf(type)->isTypeStruct()->sym->accept(this);
1040+
type->baseElemOf()->isTypeStruct()->sym->accept(this);
10411041
sle->sym = (Symbol*)func->shidden;
10421042
}
10431043
s->exp->accept(this);
@@ -1093,7 +1093,7 @@ class MiniGlueVisitor : public Visitor
10931093
}
10941094
void visit(ThrowStatement *s) override
10951095
{
1096-
dmd::toBasetype(s->exp->type)->isClassHandle()->accept(this);
1096+
s->exp->type->toBasetype()->isClassHandle()->accept(this);
10971097
s->exp->accept(this);
10981098
}
10991099
void visit(TryCatchStatement *s) override
@@ -1254,9 +1254,9 @@ class MiniGlueVisitor : public Visitor
12541254
{
12551255
if (!func || !func->isAuto())
12561256
return;
1257-
Type *tb = dmd::baseElemOf(dmd::nextOf(func->type));
1257+
Type *tb = func->type->nextOf()->baseElemOf();
12581258
while (tb->ty == TY::Tarray || tb->ty == TY::Tpointer)
1259-
tb = dmd::baseElemOf(dmd::nextOf(tb));
1259+
tb = tb->nextOf()->baseElemOf();
12601260
TemplateInstance *ti = NULL;
12611261
if (tb->ty == TY::Tstruct)
12621262
ti = tb->isTypeStruct()->sym->isInstantiated();
@@ -1481,7 +1481,7 @@ class MiniGlueVisitor : public Visitor
14811481
(void)fd->isGenerated();
14821482
(void)fd->ident;
14831483
(void)fd->storage_class;
1484-
(void)dmd::nextOf(fd->type)->isTypeNoreturn();
1484+
(void)fd->type->nextOf()->isTypeNoreturn();
14851485
}
14861486
else
14871487
{

0 commit comments

Comments
 (0)