void preOrder(struct treeNode *p,int dep) { if (p == NULL) return ; int i; for (i = 1; i < dep; i++) printf(" "); typePrint(p); for (i = 0; i < p->childNum; i++) preOrder(p->ch[i], dep + 1); }
void printName(llvm::raw_ostream &out, ObjectPtr x) { switch (x->objKind) { case IDENTIFIER : { Identifier *y = (Identifier *)x.ptr(); if (_safeNames > 0) { out << "#"; for (unsigned i = 0; i < y->str.size(); ++i) { char ch = y->str[i]; if (isSafe(ch)) out << ch; else out << 'c' << (unsigned int)ch; } } else { out << "\""; for (unsigned i = 0; i < y->str.size(); ++i) { char ch = y->str[i]; switch (ch) { case '\0': out << "\\0"; break; case '\n': out << "\\n"; break; case '\r': out << "\\r"; break; case '\t': out << "\\t"; break; case '\f': out << "\\f"; break; case '\\': out << "\\\\"; break; case '\'': out << "\\'"; break; case '\"': out << "\\\""; break; default: if (ch >= '\x20' && ch <= '\x7E') out << ch; else { out << "\\x"; if (ch < 16) out << '0'; out.write_hex((unsigned long long int)ch); } break; } } out << "\""; } break; } case GLOBAL_VARIABLE : { GlobalVariable *y = (GlobalVariable *)x.ptr(); out << y->name->str; break; } case GLOBAL_ALIAS : { GlobalAlias *y = (GlobalAlias *)x.ptr(); out << y->name->str; break; } case RECORD_DECL : { RecordDecl *y = (RecordDecl *)x.ptr(); out << y->name->str; break; } case VARIANT_DECL : { VariantDecl *y = (VariantDecl *)x.ptr(); out << y->name->str; break; } case PROCEDURE : { Procedure *y = (Procedure *)x.ptr(); out << y->name->str; break; } case MODULE : { Module *m = (Module *)x.ptr(); out << m->moduleName; break; } case INTRINSIC : { IntrinsicSymbol *intrin = (IntrinsicSymbol *)x.ptr(); out << intrin->name->str; break; } case PRIM_OP : { out << primOpName((PrimOp *)x.ptr()); break; } case TYPE : { typePrint(out, (Type *)x.ptr()); break; } case VALUE_HOLDER : { ValueHolder *y = (ValueHolder *)x.ptr(); if (isStaticOrTupleOfStatics(y->type)) { printStaticOrTupleOfStatics(out, y->type); } else { EValuePtr ev = new EValue(y->type, y->buf); printValue(out, ev); } break; } case EXTERNAL_PROCEDURE : { ExternalProcedure *proc = (ExternalProcedure*)x.ptr(); out << "external " << proc->name->str; break; } default : { out << "UnknownNamedObject(" << x->objKind << ")"; break; } } }
static void print(llvm::raw_ostream &out, const Object *x) { if (x == NULL) { out << "NULL"; return; } switch (x->objKind) { case SOURCE : { const Source *y = (const Source *)x; out << "Source(" << y->fileName << ")"; break; } case IDENTIFIER : { const Identifier *y = (const Identifier *)x; out << "Identifier(" << y->str << ")"; break; } case DOTTED_NAME : { const DottedName *y = (const DottedName *)x; out << "DottedName(" << llvm::makeArrayRef(y->parts) << ")"; break; } case EXPRESSION : { const Expr *y = (const Expr *)x; printExpr(out, y); break; } case EXPR_LIST : { const ExprList *y = (const ExprList *)x; out << "ExprList(" << y->exprs << ")"; break; } case STATEMENT : { const Statement *y = (const Statement *)x; printStatement(out, y); break; } case CASE_BLOCK : { const CaseBlock *y = (const CaseBlock *)x; out << "CaseBlock(" << y->caseLabels << ", " << y->body << ")"; break; } case CATCH : { const Catch *y = (const Catch *)x; out << "Catch(" << y->exceptionVar << ", " << y->exceptionType << ", " << y->body << ")"; break; } case CODE : { const Code *y = (const Code *)x; out << "Code(" << y->patternVars << ", " << y->predicate; out << ", " << y->formalArgs << ", " << y->hasVarArg; out << ", " << y->returnSpecs << ", " << y->varReturnSpec; out << ", " << y->body << ")"; break; } case FORMAL_ARG : { const FormalArg *y = (const FormalArg *)x; out << "FormalArg(" << y->name << ", " << y->type << ", " << y->tempness << ")"; break; } case RETURN_SPEC : { const ReturnSpec *y = (const ReturnSpec *)x; out << "ReturnSpec(" << y->type << ", " << y->name << ")"; break; } case RECORD_DECL : { const RecordDecl *y = (const RecordDecl *)x; out << "RecordDecl(" << y->name << ", " << y->params; out << ", " << y->varParam << ", " << y->body << ")"; break; } case RECORD_BODY : { const RecordBody *y = (const RecordBody *)x; out << "RecordBody(" << y->isComputed << ", " << y->computed; out << ", " << y->fields << ")"; break; } case RECORD_FIELD : { const RecordField *y = (const RecordField *)x; out << "RecordField(" << y->name << ", " << y->type << ")"; break; } case VARIANT_DECL : { const VariantDecl *y = (const VariantDecl *)x; out << "VariantDecl(" << y->name << ", " << y->params; out << ", " << y->varParam << ")"; break; } case INSTANCE_DECL : { const InstanceDecl *y = (const InstanceDecl *)x; out << "InstanceDecl(" << y->patternVars << ", " << y->predicate; out << ", " << y->target << ", " << y->members << ")"; break; } case OVERLOAD : { const Overload *y = (const Overload *)x; out << "Overload(" << y->target << ", " << y->code << ", " << y->callByName << ", " << y->isInline << ")"; break; } case PROCEDURE : { const Procedure *y = (const Procedure *)x; out << "Procedure(" << y->name << ")"; break; } case INTRINSIC : { const IntrinsicSymbol *intrin = (const IntrinsicSymbol *)x; out << "IntrinsicSymbol(" << intrin->name << ", " << intrin->id << ")"; break; } case ENUM_DECL : { const EnumDecl *y = (const EnumDecl *)x; out << "EnumDecl(" << y->name << ", " << y->members << ")"; break; } case ENUM_MEMBER : { const EnumMember *y = (const EnumMember *)x; out << "EnumMember(" << y->name << ")"; break; } case NEW_TYPE_DECL : { const NewTypeDecl *y = (const NewTypeDecl *)x; out << "NewTypeDecl(" << y->name << ")"; break; } case GLOBAL_VARIABLE : { const GlobalVariable *y = (const GlobalVariable *)x; out << "GlobalVariable(" << y->name << ", " << y->params << ", " << y->varParam << ", " << y->expr << ")"; break; } case EXTERNAL_PROCEDURE : { const ExternalProcedure *y = (const ExternalProcedure *)x; out << "ExternalProcedure(" << y->name << ", " << y->args; out << ", " << y->hasVarArgs << ", " << y->returnType; out << ", " << y->body << ")"; break; } case EXTERNAL_ARG: { const ExternalArg *y = (const ExternalArg *)x; out << "ExternalArg(" << y->name << ", " << y->type << ")"; break; } case EXTERNAL_VARIABLE : { const ExternalVariable *y = (const ExternalVariable *)x; out << "ExternalVariable(" << y->name << ", " << y->type << ")"; break; } case GLOBAL_ALIAS : { const GlobalAlias *y = (const GlobalAlias *)x; out << "GlobalAlias(" << y->name << ", " << y->params << ", " << y->varParam << ", " << y->expr << ")"; break; } case IMPORT : { const Import *y = (const Import *)x; switch (y->importKind) { case IMPORT_MODULE : { const ImportModule *z = (const ImportModule *)y; out << "Import(" << z->dottedName << ", " << z->alias << ")"; break; } case IMPORT_STAR : { const ImportStar *z = (const ImportStar *)y; out << "ImportStar(" << z->dottedName << ")"; break; } case IMPORT_MEMBERS : { const ImportMembers *z = (const ImportMembers *)y; out << "ImportMembers(" << z->visibility << ", " << z->dottedName << ", ["; for (size_t i = 0; i < z->members.size(); ++i) { if (i != 0) out << ", "; const ImportedMember &a = z->members[i]; out << "(" << a.name << ", " << a.alias << ")"; } out << "])"; break; } default : assert(false); } break; } case EVAL_TOPLEVEL : { const EvalTopLevel *eval = (const EvalTopLevel *)x; out << "EvalTopLevel(" << eval->args << ")"; break; } case STATIC_ASSERT_TOP_LEVEL : { const StaticAssertTopLevel *staticAssert = (const StaticAssertTopLevel*)x; out << "StaticAssertTopLevel(" << staticAssert->cond; for (size_t i = 0; i < staticAssert->message->size(); ++i) { out << ", " << staticAssert->message->exprs[i]; } out << ")"; break; } case MODULE_DECLARATION : { const ModuleDeclaration *y = (const ModuleDeclaration *)x; out << "ModuleDeclaration(" << y->name << ", " << y->attributes << ")"; break; } case MODULE : { const Module *y = (const Module *)x; out << "Module(" << bigVec(y->imports) << ", " << bigVec(y->topLevelItems) << ")"; break; } case PRIM_OP : { const PrimOp *y = (const PrimOp *)x; out << "PrimOp(" << primOpName(const_cast<PrimOp *>(y)) << ")"; break; } case TYPE : { const Type *y = (const Type *)x; typePrint(out, const_cast<Type *>(y)); break; } case PATTERN : { const Pattern *y = (const Pattern *)x; patternPrint(out, const_cast<Pattern *>(y)); break; } case MULTI_PATTERN : { const MultiPattern *y = (const MultiPattern *)x; patternPrint(out, const_cast<MultiPattern *>(y)); break; } case VALUE_HOLDER : { const ValueHolder *y = (const ValueHolder *)x; EValuePtr ev = new EValue(y->type, y->buf); out << "ValueHolder("; printTypeAndValue(out, ev); out << ")"; break; } case MULTI_STATIC : { const MultiStatic *y = (const MultiStatic *)x; out << "MultiStatic(" << y->values << ")"; break; } case PVALUE : { const PValue *y = (const PValue *)x; out << "PValue(" << y->data << ")"; break; } case MULTI_PVALUE : { const MultiPValue *y = (const MultiPValue *)x; out << "MultiPValue(" << llvm::makeArrayRef(y->values) << ")"; break; } case EVALUE : { const EValue *y = (const EValue *)x; out << "EValue(" << y->type << ")"; break; } case MULTI_EVALUE : { const MultiEValue *y = (const MultiEValue *)x; out << "MultiEValue(" << y->values << ")"; break; } case CVALUE : { const CValue *y = (const CValue *)x; out << "CValue(" << y->type << ")"; break; } case MULTI_CVALUE : { const MultiCValue *y = (const MultiCValue *)x; out << "MultiCValue(" << y->values << ")"; break; } case DOCUMENTATION : { const Documentation *d = (const Documentation *)x; out << "Documentation(" << d->text << ")"; break; } default : out << "UnknownObj(" << x->objKind << ")"; break; } }