00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "DeclDumper.h"
00010 #include "comma/ast/Decl.h"
00011 #include "comma/ast/Expr.h"
00012 #include "comma/ast/Stmt.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 &DeclDumper::dump(Decl *decl, unsigned level)
00023 {
00024 unsigned savedLevel = indentLevel;
00025 indentLevel = level;
00026 visitDecl(decl);
00027 indentLevel = savedLevel;
00028 return S;
00029 }
00030
00031 llvm::raw_ostream &DeclDumper::printHeader(Ast *node)
00032 {
00033 const char *nameString = cast<Decl>(node)->getString();;
00034 AstDumperBase::printHeader(node) << llvm::format(" '%s'", nameString);
00035 return S;
00036 }
00037
00038
00039
00040
00041 void DeclDumper::visitImportDecl(ImportDecl *node)
00042 {
00043 printHeader(node) << '>';
00044 }
00045
00046 void DeclDumper::visitSignatureDecl(SignatureDecl *node)
00047 {
00048 printHeader(node) << '>';
00049 }
00050
00051 void DeclDumper::visitVarietyDecl(VarietyDecl *node)
00052 {
00053 printHeader(node) << '>';
00054 }
00055
00056 void DeclDumper::visitSigInstanceDecl(SigInstanceDecl *node)
00057 {
00058 printHeader(node) << '>';
00059 }
00060
00061 void DeclDumper::visitAddDecl(AddDecl *node)
00062 {
00063 printHeader(node);
00064
00065 if (node->countDecls()) {
00066 indent();
00067 DeclRegion::DeclRegion::DeclIter I = node->beginDecls();
00068 DeclRegion::DeclRegion::DeclIter E = node->endDecls();
00069 for ( ; I != E; ++I) {
00070 S << '\n';
00071 printIndentation();
00072 visitDecl(*I);
00073 }
00074 dedent();
00075 }
00076 S << '>';
00077 }
00078
00079 void DeclDumper::visitDomainDecl(DomainDecl *node)
00080 {
00081 printHeader(node) << '\n';
00082 indent();
00083 printIndentation();
00084 visitPercentDecl(node->getPercent());
00085
00086 if (AddDecl *add = node->getImplementation()) {
00087 S << '\n';
00088 printIndentation();
00089 visitAddDecl(add);
00090 }
00091 S << '>';
00092 }
00093
00094 void DeclDumper::visitFunctorDecl(FunctorDecl *node)
00095 {
00096 printHeader(node) << '>';
00097 }
00098
00099 void DeclDumper::visitSubroutineDecl(SubroutineDecl *node)
00100 {
00101 printHeader(node) << '\n';
00102 indent();
00103 printIndentation();
00104 dumpAST(node->getType());
00105 if (!node->isForwardDeclaration() && node->hasBody()) {
00106 S << '\n';
00107 printIndentation();
00108 dumpAST(node->getBody());
00109 }
00110 dedent();
00111 S << '>';
00112 }
00113
00114 void DeclDumper::visitFunctionDecl(FunctionDecl *node)
00115 {
00116 visitSubroutineDecl(node);
00117 }
00118
00119 void DeclDumper::visitProcedureDecl(ProcedureDecl *node)
00120 {
00121 visitSubroutineDecl(node);
00122 }
00123
00124 void DeclDumper::visitCarrierDecl(CarrierDecl *node)
00125 {
00126 printHeader(node) << '>';
00127 }
00128
00129 void DeclDumper::visitDomainTypeDecl(DomainTypeDecl *node)
00130 {
00131 if (AbstractDomainDecl *abstract = dyn_cast<AbstractDomainDecl>(node))
00132 visitAbstractDomainDecl(abstract);
00133 else {
00134 DomainInstanceDecl *instance = cast<DomainInstanceDecl>(node);
00135 visitDomainInstanceDecl(instance);
00136 }
00137 }
00138
00139 void DeclDumper::visitAbstractDomainDecl(AbstractDomainDecl *node)
00140 {
00141 printHeader(node) << '>';
00142 }
00143
00144 void DeclDumper::visitDomainInstanceDecl(DomainInstanceDecl *node)
00145 {
00146 printHeader(node);
00147
00148 if (unsigned arity = node->getArity()) {
00149 S << '\n';
00150 indent();
00151 printIndentation() << ":Params";
00152 indent();
00153 for (unsigned i = 0; i < arity; ++i) {
00154 S << '\n';
00155 printIndentation();
00156 visitDomainTypeDecl(node->getActualParam(i));
00157 }
00158 dedent();
00159 dedent();
00160 }
00161 S << '>';
00162 }
00163
00164 void DeclDumper::visitPercentDecl(PercentDecl *node)
00165 {
00166 printHeader(node);
00167
00168 if (node->countDecls()) {
00169 indent();
00170 DeclRegion::DeclRegion::DeclIter I = node->beginDecls();
00171 DeclRegion::DeclRegion::DeclIter E = node->endDecls();
00172 for ( ; I != E; ++I) {
00173 S << '\n';
00174 printIndentation();
00175 visitDecl(*I);
00176 }
00177 dedent();
00178 }
00179 S << '>';
00180 }
00181
00182 void DeclDumper::visitParamValueDecl(ParamValueDecl *node)
00183 {
00184 printHeader(node) << '>';
00185 }
00186
00187 void DeclDumper::visitLoopDecl(LoopDecl *node)
00188 {
00189 printHeader(node) << '>';
00190 }
00191
00192 void DeclDumper::visitObjectDecl(ObjectDecl *node)
00193 {
00194 printHeader(node);
00195 if (node->hasInitializer()) {
00196 S << '\n';
00197 indent();
00198 printIndentation();
00199 dumpAST(node->getInitializer());
00200 dedent();
00201 }
00202 S << '>';
00203 }
00204
00205 void DeclDumper::visitEnumLiteral(EnumLiteral *node)
00206 {
00207 printHeader(node) << '>';
00208 }
00209
00210 void DeclDumper::visitEnumerationDecl(EnumerationDecl *node)
00211 {
00212 printHeader(node) << '>';
00213 }
00214
00215 void DeclDumper::visitIntegerDecl(IntegerDecl *node)
00216 {
00217 printHeader(node) << '>';
00218 }
00219
00220 void DeclDumper::visitArrayDecl(ArrayDecl *node)
00221 {
00222 printHeader(node) << '>';
00223 }
00224
00225 void DeclDumper::visitExceptionDecl(ExceptionDecl *node)
00226 {
00227 printHeader(node) << '>';
00228 }
00229
00230 void DeclDumper::visitIncompleteTypeDecl(IncompleteTypeDecl *node)
00231 {
00232 printHeader(node) << '>';
00233 }
00234