00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 #include "comma/ast/Decl.h"
00010 #include "comma/ast/DeclVisitor.h"
00011 
00012 using namespace comma;
00013 
00014 using llvm::dyn_cast;
00015 using llvm::cast;
00016 using llvm::isa;
00017 
00020 #define DISPATCH(TYPE, NODE)         \
00021     Ast::AST_ ## TYPE:               \
00022     visit ## TYPE(cast<TYPE>(NODE)); \
00023     break
00024 
00025 
00026 
00027 
00028 
00029 void DeclVisitor::visitAst(Ast *node)
00030 {
00031     if (Decl *decl = dyn_cast<Decl>(node))
00032         visitDecl(decl);
00033 }
00034 
00035 void DeclVisitor::visitDecl(Decl *node)
00036 {
00037     if (ModelDecl *model = dyn_cast<ModelDecl>(node))
00038         visitModelDecl(model);
00039     else if (SubroutineDecl *routine = dyn_cast<SubroutineDecl>(node))
00040         visitSubroutineDecl(routine);
00041     else if (TypeDecl *typed = dyn_cast<TypeDecl>(node))
00042         visitTypeDecl(typed);
00043     else if (ValueDecl *value = dyn_cast<ValueDecl>(node))
00044         visitValueDecl(value);
00045     else if (SigInstanceDecl *instance = dyn_cast<SigInstanceDecl>(node))
00046         visitSigInstanceDecl(instance);
00047     else if (ExceptionDecl *exception = dyn_cast<ExceptionDecl>(node))
00048         visitExceptionDecl(exception);
00049     else
00050         assert(false && "Cannot visit this kind of node!");
00051 }
00052 
00053 void DeclVisitor::visitModelDecl(ModelDecl *node)
00054 {
00055     if (Domoid *domoid = dyn_cast<Domoid>(node))
00056         visitDomoid(domoid);
00057     else if (Sigoid *sigoid = dyn_cast<Sigoid>(node))
00058         visitSigoid(sigoid);
00059     else
00060         assert(false && "Cannot visit this kind of node!");
00061 }
00062 
00063 void DeclVisitor::visitSigoid(Sigoid *node)
00064 {
00065     switch (node->getKind()) {
00066     default:
00067         assert(false && "Cannot visit this kind of node!");
00068         break;
00069     case DISPATCH(SignatureDecl, node);
00070     case DISPATCH(VarietyDecl, node);
00071     };
00072 }
00073 
00074 void DeclVisitor::visitDomoid(Domoid *node)
00075 {
00076     switch (node->getKind()) {
00077     default:
00078         assert(false && "Cannot visit this kind of node!");
00079         break;
00080     case DISPATCH(DomainDecl, node);
00081     case DISPATCH(FunctorDecl, node);
00082     };
00083 }
00084 
00085 void DeclVisitor::visitSubroutineDecl(SubroutineDecl *node)
00086 {
00087     switch (node->getKind()) {
00088     default:
00089         assert(false && "Cannot visit this kind of node!");
00090         break;
00091     case DISPATCH(FunctionDecl, node);
00092     case DISPATCH(ProcedureDecl, node);
00093     };
00094 }
00095 
00096 void DeclVisitor::visitTypeDecl(TypeDecl *node)
00097 {
00098     switch (node->getKind()) {
00099     default:
00100         assert(false && "Cannot visit this kind of node!");
00101         break;
00102     case DISPATCH(AbstractDomainDecl, node);
00103     case DISPATCH(ArrayDecl, node);
00104     case DISPATCH(CarrierDecl, node);
00105     case DISPATCH(DomainInstanceDecl, node);
00106     case DISPATCH(EnumerationDecl, node);
00107     case DISPATCH(IntegerDecl, node);
00108     case DISPATCH(PercentDecl, node);
00109     case DISPATCH(IncompleteTypeDecl, node);
00110     };
00111 }
00112 
00113 void DeclVisitor::visitValueDecl(ValueDecl *node)
00114 {
00115     switch (node->getKind()) {
00116     default:
00117         assert(false && "Cannot visit this kind of node!");
00118         break;
00119     case DISPATCH(ObjectDecl, node);
00120     case DISPATCH(ParamValueDecl, node);
00121     case DISPATCH(LoopDecl, node);
00122     case DISPATCH(RenamedObjectDecl, node);
00123     };
00124 }
00125 
00126 void DeclVisitor::visitDomainTypeDecl(DomainTypeDecl *node)
00127 {
00128     switch (node->getKind()) {
00129     default:
00130         assert(false && "Cannot visit this kind of node!");
00131         break;
00132     case DISPATCH(DomainInstanceDecl, node);
00133     case DISPATCH(PercentDecl, node);
00134     case DISPATCH(AbstractDomainDecl, node);
00135     };
00136 }
00137 
00138 
00139 
00140 
00141 
00142 void DeclVisitor::visitFunctionDecl(FunctionDecl *node)
00143 {
00144     if (EnumLiteral *enumLit = dyn_cast<EnumLiteral>(node))
00145         visitEnumLiteral(enumLit);
00146 }
00147 
00148 
00149 
00150 
00151 
00152 void DeclVisitor::visitImportDecl(ImportDecl *node) { }
00153 void DeclVisitor::visitSignatureDecl(SignatureDecl *node) { }
00154 void DeclVisitor::visitVarietyDecl(VarietyDecl *node) { }
00155 void DeclVisitor::visitSigInstanceDecl(SigInstanceDecl *node) { }
00156 void DeclVisitor::visitAddDecl(AddDecl *node) { }
00157 void DeclVisitor::visitDomainDecl(DomainDecl *node) { }
00158 void DeclVisitor::visitFunctorDecl(FunctorDecl *node) { }
00159 void DeclVisitor::visitProcedureDecl(ProcedureDecl *node) { }
00160 void DeclVisitor::visitCarrierDecl(CarrierDecl *node) { }
00161 void DeclVisitor::visitAbstractDomainDecl(AbstractDomainDecl *node) { }
00162 void DeclVisitor::visitDomainInstanceDecl(DomainInstanceDecl *node) { }
00163 void DeclVisitor::visitPercentDecl(PercentDecl *node) { }
00164 void DeclVisitor::visitLoopDecl(LoopDecl *node) { }
00165 void DeclVisitor::visitParamValueDecl(ParamValueDecl *node) { }
00166 void DeclVisitor::visitObjectDecl(ObjectDecl *node) { }
00167 void DeclVisitor::visitRenamedObjectDecl(RenamedObjectDecl *node) { }
00168 void DeclVisitor::visitEnumLiteral(EnumLiteral *node) { }
00169 void DeclVisitor::visitEnumerationDecl(EnumerationDecl *node) { }
00170 void DeclVisitor::visitIntegerDecl(IntegerDecl *node) { }
00171 void DeclVisitor::visitArrayDecl(ArrayDecl *node) { }
00172 void DeclVisitor::visitExceptionDecl(ExceptionDecl *node) { }
00173 void DeclVisitor::visitIncompleteTypeDecl(IncompleteTypeDecl *node) { }