00001 //===-- ast/TypeVisitor.cpp ----------------------------------- -*- C++ -*-===// 00002 // 00003 // This file is distributed under the MIT license. See LICENSE.txt for details. 00004 // 00005 // Copyright (C) 2009-2010, Stephen Wilson 00006 // 00007 //===----------------------------------------------------------------------===// 00008 00009 #include "comma/ast/Type.h" 00010 #include "comma/ast/TypeVisitor.h" 00011 00012 using namespace comma; 00013 00014 using llvm::dyn_cast; 00015 using llvm::cast; 00016 using llvm::isa; 00017 00018 //===----------------------------------------------------------------------===// 00019 // Virtual visitors. These methods provide implementations which walk the type 00020 // hierarchy graph. 00021 00022 void TypeVisitor::visitType(Type *node) 00023 { 00024 if (SubroutineType *srTy = dyn_cast<SubroutineType>(node)) 00025 visitSubroutineType(srTy); 00026 else if (DomainType *domTy = dyn_cast<DomainType>(node)) 00027 visitDomainType(domTy); 00028 else if (IntegerType *intTy = dyn_cast<IntegerType>(node)) 00029 visitIntegerType(intTy); 00030 else if (ArrayType *arrTy = dyn_cast<ArrayType>(node)) 00031 visitArrayType(arrTy); 00032 else if (EnumerationType *enumTy = dyn_cast<EnumerationType>(node)) 00033 visitEnumerationType(enumTy); 00034 else if (RecordType *recTy = dyn_cast<RecordType>(node)) 00035 visitRecordType(recTy); 00036 else if (AccessType *accessTy = dyn_cast<AccessType>(node)) 00037 visitAccessType(accessTy); 00038 else if (IncompleteType *incompleteTy = dyn_cast<IncompleteType>(node)) 00039 visitIncompleteType(incompleteTy); 00040 else 00041 assert(false && "Cannot visit this kind of node!"); 00042 } 00043 00044 void TypeVisitor::visitSubroutineType(SubroutineType *node) 00045 { 00046 if (FunctionType *fnTy = dyn_cast<FunctionType>(node)) 00047 visitFunctionType(fnTy); 00048 else if (ProcedureType *procTy = dyn_cast<ProcedureType>(node)) 00049 visitProcedureType(procTy); 00050 else 00051 assert(false && "Cannot visit this kind of node!"); 00052 } 00053 00054 //===----------------------------------------------------------------------===// 00055 // Non-virtual visitors, with empty out-of-line implementations. 00056 00057 void TypeVisitor::visitDomainType(DomainType *node) { } 00058 void TypeVisitor::visitFunctionType(FunctionType *node) { } 00059 void TypeVisitor::visitProcedureType(ProcedureType *node) { } 00060 void TypeVisitor::visitEnumerationType(EnumerationType *node) { } 00061 void TypeVisitor::visitIntegerType(IntegerType *node) { } 00062 void TypeVisitor::visitArrayType(ArrayType *node) { } 00063 void TypeVisitor::visitRecordType(RecordType *node) { } 00064 void TypeVisitor::visitAccessType(AccessType *node) { } 00065 void TypeVisitor::visitIncompleteType(IncompleteType *node) { }