-
-
Save AlexeyProkhin/7bff68f700970e7280fb to your computer and use it in GitHub Desktop.
Type visitor for dmd.
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
#include "visitor.h" | |
#include "mtype.h" | |
Visitor::~Visitor() | |
{ | |
} | |
void Visitor::visitType(Type *type) | |
{ | |
if (type->ty == Terror) | |
visit((TypeError*)type); | |
else if (type->ty == Tvector) | |
visit((TypeVector*)type); | |
else if (type->ty == Tsarray) | |
visit((TypeSArray*)type); | |
else if (type->ty == Tarray) | |
visit((TypeDArray*)type); | |
else if (type->ty == Taarray) | |
visit((TypeAArray*)type); | |
else if (type->ty == Tpointer) | |
visit((TypePointer*)type); | |
else if (type->ty == Treference) | |
visit((TypeReference*)type); | |
else if (type->ty == Tfunction) | |
visit((TypeFunction*)type); | |
else if (type->ty == Tdelegate) | |
visit((TypeDelegate*)type); | |
else if (type->ty == Tident) | |
visit((TypeIdentifier*)type); | |
else if (type->ty == Tinstance) | |
visit((TypeInstance*)type); | |
else if (type->ty == Ttypeof) | |
visit((TypeTypeof*)type); | |
else if (type->ty == Treturn) | |
visit((TypeReturn*)type); | |
else if (type->ty == Tstruct) | |
visit((TypeStruct*)type); | |
else if (type->ty == Tenum) | |
visit((TypeEnum*)type); | |
else if (type->ty == Ttypedef) | |
visit((TypeTypedef*)type); | |
else if (type->ty == Tclass) | |
visit((TypeClass*)type); | |
else if (type->ty == Ttuple) | |
visit((TypeTuple*)type); | |
else if (type->ty == Tslice) | |
visit((TypeSlice*)type); | |
else if (type->ty == Tnull) | |
visit((TypeNull*)type); | |
} | |
void Visitor::visit(Type *arg) | |
{ | |
assert(0); | |
} | |
#define VISIT(Type, Base) \ | |
void Visitor::visit(Type *arg) { \ | |
visit((Base*)arg); \ | |
} | |
VISIT(TypeError, Type) | |
VISIT(TypeNext, Type) | |
VISIT(TypeBasic, Type) | |
VISIT(TypeVector, Type) | |
VISIT(TypeArray, TypeNext) | |
VISIT(TypeSArray, TypeArray) | |
VISIT(TypeDArray, TypeArray) | |
VISIT(TypeAArray, TypeArray) | |
VISIT(TypePointer, TypeNext) | |
VISIT(TypeReference, TypeNext) | |
VISIT(TypeFunction, TypeNext) | |
VISIT(TypeDelegate, TypeNext) | |
VISIT(TypeQualified, Type) | |
VISIT(TypeIdentifier, TypeQualified) | |
VISIT(TypeInstance, TypeQualified) | |
VISIT(TypeTypeof, TypeQualified) | |
VISIT(TypeReturn, TypeQualified) | |
VISIT(TypeStruct, Type) | |
VISIT(TypeEnum, Type) | |
VISIT(TypeTypedef, Type) | |
VISIT(TypeClass, Type) | |
VISIT(TypeTuple, Type) | |
VISIT(TypeSlice, Type) | |
VISIT(TypeNull, Type) | |
#undef VISIT |
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
#ifndef DMD_VISITOR_H | |
#define DMD_VISITOR_H | |
#ifdef __DMC__ | |
#pragma once | |
#endif /* __DMC__ */ | |
class Type; | |
class TypeError; | |
class TypeNext; | |
class TypeBasic; | |
class TypeVector; | |
class TypeArray; | |
class TypeSArray; | |
class TypeDArray; | |
class TypeAArray; | |
class TypePointer; | |
class TypeReference; | |
class TypeFunction; | |
class TypeDelegate; | |
class TypeQualified; | |
class TypeIdentifier; | |
class TypeInstance; | |
class TypeTypeof; | |
class TypeReturn; | |
class TypeStruct ; | |
class TypeEnum; | |
class TypeTypedef; | |
class TypeClass; | |
class TypeTuple; | |
class TypeSlice; | |
class TypeNull; | |
class Visitor | |
{ | |
public: | |
virtual ~Visitor(); | |
void visitType(Type *type); | |
protected: | |
virtual void visit(Type*); | |
virtual void visit(TypeError*); | |
virtual void visit(TypeNext*); | |
virtual void visit(TypeBasic*); | |
virtual void visit(TypeVector*); | |
virtual void visit(TypeArray*); | |
virtual void visit(TypeSArray*); | |
virtual void visit(TypeDArray*); | |
virtual void visit(TypeAArray*); | |
virtual void visit(TypePointer*); | |
virtual void visit(TypeReference*); | |
virtual void visit(TypeFunction*); | |
virtual void visit(TypeDelegate*); | |
virtual void visit(TypeQualified*); | |
virtual void visit(TypeIdentifier*); | |
virtual void visit(TypeInstance*); | |
virtual void visit(TypeTypeof*); | |
virtual void visit(TypeReturn*); | |
virtual void visit(TypeStruct*); | |
virtual void visit(TypeEnum*); | |
virtual void visit(TypeTypedef*); | |
virtual void visit(TypeClass*); | |
virtual void visit(TypeTuple*); | |
virtual void visit(TypeSlice*); | |
virtual void visit(TypeNull*); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment