This machine mirrors various open-source projects.
20 Gbit/s uplink.
If there are any issues or you want another project mirrored, please contact
mirror-service -=AT=- netcologne DOT de !
00001 //===-- ast/TypeDumper.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 "TypeDumper.h" 00010 #include "comma/ast/Decl.h" 00011 #include "comma/ast/Expr.h" 00012 #include "comma/ast/Type.h" 00013 00014 #include "llvm/Support/Format.h" 00015 00016 using namespace comma; 00017 00018 using llvm::dyn_cast; 00019 using llvm::cast; 00020 using llvm::isa; 00021 00022 llvm::raw_ostream &TypeDumper::printHeader(Type *node) 00023 { 00024 AstDumperBase::printHeader(node); 00025 if (DiscreteType *discrete = dyn_cast<DiscreteType>(node)) 00026 S << " '" << discrete->getIdInfo()->getString() << '\''; 00027 return S; 00028 } 00029 00030 llvm::raw_ostream &TypeDumper::dump(Type *type, unsigned level) 00031 { 00032 unsigned savedLevel = indentLevel; 00033 indentLevel = level; 00034 visitType(type); 00035 indentLevel = savedLevel; 00036 return S; 00037 } 00038 00039 llvm::raw_ostream &TypeDumper::dumpAST(Ast *node) 00040 { 00041 return dumper->dump(node, indentLevel); 00042 } 00043 00044 llvm::raw_ostream &TypeDumper::dumpParameters(SubroutineType *node) 00045 { 00046 unsigned arity = node->getArity(); 00047 unsigned argIndex = 0; 00048 00049 S << "("; 00050 while (argIndex < arity) { 00051 visitType(node->getArgType(argIndex)); 00052 if (++argIndex < arity) 00053 S << "; "; 00054 } 00055 return S << ")"; 00056 } 00057 00058 void TypeDumper::visitDomainType(DomainType *node) 00059 { 00060 printHeader(node) << ' ' << node->getDomainTypeDecl()->getString(); 00061 if (DomainInstanceDecl *instance = node->getInstanceDecl()) { 00062 indent(); 00063 for (unsigned i = 0; i < instance->getArity(); ++i) { 00064 S << '\n'; 00065 printIndentation(); 00066 visitType(instance->getActualParamType(i)); 00067 } 00068 dedent(); 00069 } 00070 S << '>'; 00071 } 00072 00073 void TypeDumper::visitFunctionType(FunctionType *node) 00074 { 00075 printHeader(node) << ' '; 00076 dumpParameters(node) << '\n'; 00077 indent(); 00078 printIndentation(); 00079 visitType(node->getReturnType()); 00080 dedent(); 00081 S << '>'; 00082 } 00083 00084 void TypeDumper::visitProcedureType(ProcedureType *node) 00085 { 00086 printHeader(node) << ' '; 00087 dumpParameters(node) << '>'; 00088 } 00089 00090 void TypeDumper::visitEnumerationType(EnumerationType *node) 00091 { 00092 printHeader(node) << '>'; 00093 } 00094 00095 void TypeDumper::visitIntegerType(IntegerType *node) 00096 { 00097 printHeader(node); 00098 if (Range *range = node->getConstraint()) { 00099 S << ' '; 00100 dumpAST(range->getLowerBound()); 00101 S << ' '; 00102 dumpAST(range->getUpperBound()); 00103 } 00104 S << '>'; 00105 } 00106 00107 void TypeDumper::visitIncompleteType(IncompleteType *node) 00108 { 00109 printHeader(node) << '>'; 00110 } 00111 00112 void TypeDumper::visitArrayType(ArrayType *node) 00113 { 00114 printHeader(node) << '>'; 00115 } 00116 00117 void TypeDumper::visitAccessType(AccessType *node) 00118 { 00119 printHeader(node) << ' '; 00120 visitType(node->getTargetType()); 00121 S << '>'; 00122 } 00123 00124 void TypeDumper::visitRecordType(RecordType *node) 00125 { 00126 printHeader(node); 00127 indent(); 00128 for (unsigned i = 0; i < node->numComponents(); ++i) { 00129 S << '\n'; 00130 printIndentation(); 00131 visitType(node->getComponentType(i)); 00132 } 00133 dedent(); 00134 S << '>'; 00135 }