diff --git a/include/swift/AST/Expr.h b/include/swift/AST/Expr.h index e476335731b..59b407b3397 100644 --- a/include/swift/AST/Expr.h +++ b/include/swift/AST/Expr.h @@ -1118,6 +1118,9 @@ public: #include "swift/AST/TokenKinds.def" }; + static StringRef + getLiteralKindPlainName(ObjectLiteralExpr::LiteralKind kind); + private: ArgumentList *ArgList; SourceLoc PoundLoc; diff --git a/include/swift/AST/StorageImpl.h b/include/swift/AST/StorageImpl.h index 15f3f61a1e3..dbd1aa2760e 100644 --- a/include/swift/AST/StorageImpl.h +++ b/include/swift/AST/StorageImpl.h @@ -203,8 +203,6 @@ enum class ReadImplKind { }; enum { NumReadImplKindBits = 4 }; -StringRef getReadImplKindName(ReadImplKind kind); - /// How are simple write accesses implemented? enum class WriteImplKind { /// It's immutable. @@ -231,8 +229,6 @@ enum class WriteImplKind { }; enum { NumWriteImplKindBits = 4 }; -StringRef getWriteImplKindName(WriteImplKind kind); - /// How are read-write accesses implemented? enum class ReadWriteImplKind { /// It's immutable. @@ -258,8 +254,6 @@ enum class ReadWriteImplKind { }; enum { NumReadWriteImplKindBits = 4 }; -StringRef getReadWriteImplKindName(ReadWriteImplKind kind); - class StorageImplInfo { using IntType = uint16_t; static_assert(NumReadImplKindBits + NumWriteImplKindBits diff --git a/include/swift/AST/TypeRepr.h b/include/swift/AST/TypeRepr.h index 151cafa8c1c..bff44f974d5 100644 --- a/include/swift/AST/TypeRepr.h +++ b/include/swift/AST/TypeRepr.h @@ -189,6 +189,7 @@ public: void print(raw_ostream &OS, const PrintOptions &Opts = PrintOptions()) const; void print(ASTPrinter &Printer, const PrintOptions &Opts) const; SWIFT_DEBUG_DUMP; + void dump(raw_ostream &OS, unsigned indent = 0) const; }; /// A TypeRepr for a type with a syntax error. Can be used both as a diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 6cfa478634b..a3d0d6b6933 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -42,6 +42,27 @@ #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/raw_ostream.h" +// +// AST DUMPING TIPS +// ================ +// +// * Pass values before names (because names are often optional and can be +// omitted or empty). +// +// * Put all `printField*()` and `printFlag*()` calls before `printRec()` calls. +// `printRec()` variants print a child node, and all fields of the current +// node need to be printed before any child node is printed. +// +// * `printField()` expects a "simple" argument that will be converted to a +// keyword string by passing it through `getDumpString()`. For values that are +// at all complicated, use `printFieldQuoted()`, which will automatically +// quote and escape the value. +// +// * Confine all direct formatting for the console (e.g. printing quotes or +// parentheses) in `PrintBase`. Eventually we want to allow e.g. JSON dumping; +// limiting the amount of direct I/O helps us with that. +// + using namespace swift; struct TerminalColor { @@ -76,7 +97,7 @@ DEF_COLOR(ExprModifier, CYAN, false) DEF_COLOR(DeclModifier, CYAN, false) DEF_COLOR(ArgModifier, CYAN, false) DEF_COLOR(ClosureModifier, CYAN, false) -DEF_COLOR(TypeField, CYAN, false) +DEF_COLOR(FieldLabel, CYAN, false) DEF_COLOR(Location, CYAN, false) #undef DEF_COLOR @@ -114,27 +135,62 @@ namespace { } }; + +/// Wraps a \c raw_ostream so that anything printed through it is automatically +/// escaped appropriately for a double-quoted string. +class escaping_ostream : public raw_ostream { + raw_ostream &base_os; + +public: + escaping_ostream(raw_ostream &base_os) + : raw_ostream(/*unbuffered=*/true), base_os(base_os) + {} + + virtual ~escaping_ostream() {} + + virtual void reserveExtraSpace(uint64_t ExtraSize) override { + base_os.reserveExtraSpace(ExtraSize); + } + + virtual raw_ostream &changeColor(enum Colors Color, bool Bold = false, + bool BG = false) override { + return base_os.changeColor(Color, Bold, BG); + } + + virtual raw_ostream &resetColor() override { + return base_os.resetColor(); + } + + virtual raw_ostream &reverseColor() override { + return base_os.reverseColor(); + } + + virtual bool is_displayed() const override { + return base_os.is_displayed(); + } + + virtual bool has_colors() const override { + return base_os.has_colors(); + } + + virtual void enable_colors(bool enable) override { + base_os.enable_colors(enable); + } + +private: + virtual void write_impl(const char *Ptr, size_t Size) override { + base_os.write_escaped(StringRef(Ptr, Size), /*UseHexEscapes=*/true); + } + + virtual uint64_t current_pos() const override { + return base_os.tell(); + } + + virtual void anchor() override {} +}; } // end anonymous namespace -static void printGenericParameters(raw_ostream &OS, GenericParamList *Params) { - if (!Params) - return; - OS << ' '; - Params->print(OS); -} - -static void printSourceRange(raw_ostream &OS, const SourceRange R, - const ASTContext &Ctx) { - if (!R.isValid()) - return; - - PrintWithColorRAII(OS, RangeColor) << " range="; - R.print(PrintWithColorRAII(OS, RangeColor).getOS(), Ctx.SourceMgr, - /*PrintText=*/false); -} - -static StringRef -getSILFunctionTypeRepresentationString(SILFunctionType::Representation value) { +static StringRef getDumpString(SILFunctionType::Representation value) { switch (value) { case SILFunctionType::Representation::Thick: return "thick"; case SILFunctionType::Representation::Block: return "block"; @@ -151,7 +207,7 @@ getSILFunctionTypeRepresentationString(SILFunctionType::Representation value) { llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch."); } -StringRef swift::getReadImplKindName(ReadImplKind kind) { +static StringRef getDumpString(ReadImplKind kind) { switch (kind) { case ReadImplKind::Stored: return "stored"; @@ -167,7 +223,7 @@ StringRef swift::getReadImplKindName(ReadImplKind kind) { llvm_unreachable("bad kind"); } -StringRef swift::getWriteImplKindName(WriteImplKind kind) { +static StringRef getDumpString(WriteImplKind kind) { switch (kind) { case WriteImplKind::Immutable: return "immutable"; @@ -187,7 +243,7 @@ StringRef swift::getWriteImplKindName(WriteImplKind kind) { llvm_unreachable("bad kind"); } -StringRef swift::getReadWriteImplKindName(ReadWriteImplKind kind) { +static StringRef getDumpString(ReadWriteImplKind kind) { switch (kind) { case ReadWriteImplKind::Immutable: return "immutable"; @@ -207,7 +263,7 @@ StringRef swift::getReadWriteImplKindName(ReadWriteImplKind kind) { llvm_unreachable("bad kind"); } -static StringRef getImportKindString(ImportKind value) { +static StringRef getDumpString(ImportKind value) { switch (value) { case ImportKind::Module: return "module"; case ImportKind::Type: return "type"; @@ -222,8 +278,7 @@ static StringRef getImportKindString(ImportKind value) { llvm_unreachable("Unhandled ImportKind in switch."); } -static StringRef -getForeignErrorConventionKindString(ForeignErrorConvention::Kind value) { +static StringRef getDumpString(ForeignErrorConvention::Kind value) { switch (value) { case ForeignErrorConvention::ZeroResult: return "ZeroResult"; case ForeignErrorConvention::NonZeroResult: return "NonZeroResult"; @@ -234,7 +289,7 @@ getForeignErrorConventionKindString(ForeignErrorConvention::Kind value) { llvm_unreachable("Unhandled ForeignErrorConvention in switch."); } -static StringRef getDefaultArgumentKindString(DefaultArgumentKind value) { +static StringRef getDumpString(DefaultArgumentKind value) { switch (value) { case DefaultArgumentKind::None: return "none"; #define MAGIC_IDENTIFIER(NAME, STRING, SYNTAX_KIND) \ @@ -250,8 +305,7 @@ static StringRef getDefaultArgumentKindString(DefaultArgumentKind value) { llvm_unreachable("Unhandled DefaultArgumentKind in switch."); } -static StringRef -getObjCSelectorExprKindString(ObjCSelectorExpr::ObjCSelectorKind value) { +static StringRef getDumpString(ObjCSelectorExpr::ObjCSelectorKind value) { switch (value) { case ObjCSelectorExpr::Method: return "method"; case ObjCSelectorExpr::Getter: return "getter"; @@ -260,7 +314,7 @@ getObjCSelectorExprKindString(ObjCSelectorExpr::ObjCSelectorKind value) { llvm_unreachable("Unhandled ObjCSelectorExpr in switch."); } -static StringRef getAccessSemanticsString(AccessSemantics value) { +static StringRef getDumpString(AccessSemantics value) { switch (value) { case AccessSemantics::Ordinary: return "ordinary"; case AccessSemantics::DirectToStorage: return "direct_to_storage"; @@ -270,7 +324,7 @@ static StringRef getAccessSemanticsString(AccessSemantics value) { llvm_unreachable("Unhandled AccessSemantics in switch."); } -static StringRef getMetatypeRepresentationString(MetatypeRepresentation value) { +static StringRef getDumpString(MetatypeRepresentation value) { switch (value) { case MetatypeRepresentation::Thin: return "thin"; case MetatypeRepresentation::Thick: return "thick"; @@ -279,8 +333,7 @@ static StringRef getMetatypeRepresentationString(MetatypeRepresentation value) { llvm_unreachable("Unhandled MetatypeRepresentation in switch."); } -static StringRef -getStringLiteralExprEncodingString(StringLiteralExpr::Encoding value) { +static StringRef getDumpString(StringLiteralExpr::Encoding value) { switch (value) { case StringLiteralExpr::UTF8: return "utf8"; case StringLiteralExpr::OneUnicodeScalar: return "unicodeScalar"; @@ -288,7 +341,7 @@ getStringLiteralExprEncodingString(StringLiteralExpr::Encoding value) { llvm_unreachable("Unhandled StringLiteral in switch."); } -static StringRef getCtorInitializerKindString(CtorInitializerKind value) { +static StringRef getDumpString(CtorInitializerKind value) { switch (value) { case CtorInitializerKind::Designated: return "designated"; case CtorInitializerKind::Convenience: return "convenience"; @@ -298,7 +351,7 @@ static StringRef getCtorInitializerKindString(CtorInitializerKind value) { llvm_unreachable("Unhandled CtorInitializerKind in switch."); } -static StringRef getAssociativityString(Associativity value) { +static StringRef getDumpString(Associativity value) { switch (value) { case Associativity::None: return "none"; case Associativity::Left: return "left"; @@ -307,62 +360,82 @@ static StringRef getAssociativityString(Associativity value) { llvm_unreachable("Unhandled Associativity in switch."); } - -static void printArgument(raw_ostream &OS, const Argument &arg, - unsigned indentLevel, - std::function printRec) { - OS.indent(indentLevel); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, ExprColor) << "argument"; - - auto label = arg.getLabel(); - if (!label.empty()) { - PrintWithColorRAII(OS, ArgumentsColor) << " label="; - PrintWithColorRAII(OS, ArgumentsColor) << label.str(); - } - if (arg.isInOut()) - PrintWithColorRAII(OS, ArgModifierColor) << " inout"; - - OS << '\n'; - printRec(arg.getExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; +static StringRef getDumpString(CheckedCastKind kind) { + return getCheckedCastKindName(kind); } - -static void printArgumentList(raw_ostream &OS, - const ArgumentList *argList, - unsigned &indentLevel, - std::function printRec, - bool indent = true) { - if (indent) - indentLevel += 2; - - OS.indent(indentLevel); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, ExprColor) << "argument_list"; - - if (argList->isImplicit()) - PrintWithColorRAII(OS, ArgModifierColor) << " implicit"; - - if (argList->hasAnyArgumentLabels()) { - PrintWithColorRAII(OS, ArgumentsColor) << " labels="; - for (auto arg : *argList) { - auto label = arg.getLabel(); - PrintWithColorRAII(OS, ArgumentsColor) - << (label.empty() ? "_" : label.str()) << ":"; - } +static StringRef getDumpString(bool value) { + return value ? "true" : "false"; +} +static StringRef getDumpString(AccessLevel level) { + return getAccessLevelSpelling(level); +} +static StringRef getDumpString(LifetimeAnnotation lifetime) { + switch (lifetime) { + case LifetimeAnnotation::EagerMove: + return "_eagerMove"; + case LifetimeAnnotation::Lexical: + return "_lexical"; + case LifetimeAnnotation::None: + return ""; + } + + llvm_unreachable("Unhandled LifetimeAnnotation in switch."); +} +static StringRef getDumpString(AccessorKind kind) { + return getAccessorKindString(kind); +} +static StringRef getDumpString(MagicIdentifierLiteralExpr::Kind kind) { + return MagicIdentifierLiteralExpr::getKindString(kind); +} +static StringRef getDumpString(ObjectLiteralExpr::LiteralKind kind) { + return ObjectLiteralExpr::getLiteralKindPlainName(kind); +} +static StringRef getDumpString(FunctionRefKind kind) { + return getFunctionRefKindStr(kind); +} +static StringRef getDumpString(ParamSpecifier specifier) { + return ParamDecl::getSpecifierSpelling(specifier); +} +static StringRef getDumpString(ValueOwnership ownership) { + switch (ownership) { + case ValueOwnership::Default: + return ""; + case ValueOwnership::Owned: + return "owned"; + case ValueOwnership::Shared: + return "shared"; + case ValueOwnership::InOut: + return "inout"; } - indentLevel += 2; - for (auto arg : *argList) { - OS << '\n'; - printArgument(OS, arg, indentLevel, printRec); + llvm_unreachable("Unhandled ValueOwnership in switch."); +} +static StringRef getDumpString(ForeignErrorConvention::IsOwned_t owned) { + switch (owned) { + case swift::ForeignErrorConvention::IsNotOwned: + return "unowned"; + case swift::ForeignErrorConvention::IsOwned: + return "owned"; } - indentLevel -= 2; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + llvm_unreachable("Unhandled ForeignErrorConvention::IsOwned_t in switch."); +} +static StringRef getDumpString(RequirementKind kind) { + switch (kind) { + case RequirementKind::SameShape: return "same_shape"; + case RequirementKind::Conformance: return "conforms_to"; + case RequirementKind::Layout: return "has_layout"; + case RequirementKind::Superclass: return "subclass_of"; + case RequirementKind::SameType: return "same_type"; + } - if (indent) - indentLevel -= 2; + llvm_unreachable("Unhandled RequirementKind in switch."); +} +static unsigned getDumpString(unsigned value) { + return value; +} +static size_t getDumpString(size_t value) { + return value; } //===----------------------------------------------------------------------===// @@ -377,160 +450,564 @@ static void printName(raw_ostream &os, DeclName name) { os << name; } -static void dumpSubstitutionMapRec( - SubstitutionMap map, llvm::raw_ostream &out, - SubstitutionMap::DumpStyle style, unsigned indent, - llvm::SmallPtrSetImpl &visited); +static Type defaultGetTypeOfExpr(Expr *E) { return E->getType(); } +static Type defaultGetTypeOfKeyPathComponent(KeyPathExpr *E, unsigned index) { + return E->getComponents()[index].getComponentType(); +} + +using VisitedConformances = llvm::SmallPtrSetImpl; namespace { - class PrintPattern : public PatternVisitor { - public: + /// PrintBase - Base type for recursive structured dumps of AST nodes. + /// + /// Please keep direct I/O, especially of structural elements like + /// parentheses and quote marks, confined to this base class. This will help + /// if we eventually support alternate output formats for AST dumps. + class PrintBase { raw_ostream &OS; unsigned Indent; + public: + llvm::function_ref GetTypeOfExpr; + llvm::function_ref GetTypeOfTypeRepr; + llvm::function_ref + GetTypeOfKeyPathComponent; + char quote = '"'; - explicit PrintPattern(raw_ostream &os, unsigned indent = 0) - : OS(os), Indent(indent) { } + explicit PrintBase(raw_ostream &os, unsigned indent = 0, + llvm::function_ref getTypeOfExpr = defaultGetTypeOfExpr, + llvm::function_ref getTypeOfTypeRepr = nullptr, + llvm::function_ref + getTypeOfKeyPathComponent = + defaultGetTypeOfKeyPathComponent) + : OS(os), Indent(indent), GetTypeOfExpr(getTypeOfExpr), + GetTypeOfTypeRepr(getTypeOfTypeRepr), + GetTypeOfKeyPathComponent(getTypeOfKeyPathComponent) { } - void printRec(Decl *D) { D->dump(OS, Indent + 2); } - void printRec(Expr *E) { E->dump(OS, Indent + 2); } - void printRec(Stmt *S, const ASTContext &Ctx) { S->dump(OS, &Ctx, Indent + 2); } - void printRec(TypeRepr *T); - void printRec(const Pattern *P) { - PrintPattern(OS, Indent+2).visit(const_cast(P)); + bool hasNonStandardOutput() { + return &OS != &llvm::errs() && &OS != &llvm::dbgs(); } - raw_ostream &printCommon(Pattern *P, const char *Name) { + /// Call `Body` in a context where the printer is ready for a child to be printed. + template + void printRecArbitrary(Fn Body, StringRef label = "") { + Indent += 2; + OS << '\n'; + Body(label); + Indent -= 2; + } + + /// Print a declaration as a child node. + void printRec(Decl *D, StringRef label = ""); + + /// Print an expression as a child node. + void printRec(Expr *E, StringRef label = ""); + + /// Print a statement as a child node. + void printRec(Stmt *S, const ASTContext *Ctx, StringRef label = ""); + + /// Print a type representation as a child node. + void printRec(TypeRepr *T, StringRef label = ""); + + /// Print a pattern as a child node. + void printRec(const Pattern *P, StringRef label = ""); + + /// Print a type as a child node. + void printRec(Type ty, StringRef label = ""); + + /// Print an \c ASTNode as a child node. + void printRec(const ASTNode &Elt, const ASTContext *Ctx, + StringRef label = "") { + if (auto *SubExpr = Elt.dyn_cast()) + printRec(SubExpr, label); + else if (auto *SubStmt = Elt.dyn_cast()) + printRec(SubStmt, Ctx, label); + else + printRec(Elt.get(), label); + } + + /// Print a statement condition element as a child node. + void printRec(StmtConditionElement C, const ASTContext *Ctx, + StringRef Label = "") { + switch (C.getKind()) { + case StmtConditionElement::CK_Boolean: + return printRec(C.getBoolean()); + case StmtConditionElement::CK_PatternBinding: + printRecArbitrary([&](StringRef Label) { + printHead("pattern", PatternColor, Label); + printRec(C.getPattern()); + printRec(C.getInitializer()); + printFoot(); + }, Label); + break; + case StmtConditionElement::CK_Availability: + printRecArbitrary([&](StringRef Label) { + printHead("#available", PatternColor, Label); + for (auto *Query : C.getAvailability()->getQueries()) { + OS << '\n'; + switch (Query->getKind()) { + case AvailabilitySpecKind::PlatformVersionConstraint: + cast(Query)->print(OS, Indent + 2); + break; + case AvailabilitySpecKind::LanguageVersionConstraint: + case AvailabilitySpecKind::PackageDescriptionVersionConstraint: + cast(Query)->print(OS, Indent + 2); + break; + case AvailabilitySpecKind::OtherPlatform: + cast(Query)->print(OS, Indent + 2); + break; + } + } + printFoot(); + }, Label); + break; + case StmtConditionElement::CK_HasSymbol: + printRecArbitrary([&](StringRef Label) { + printHead("#_hasSymbol", PatternColor, Label); + printSourceRange(C.getSourceRange(), Ctx); + printRec(C.getHasSymbolInfo()->getSymbolExpr()); + printFoot(); + }, Label); + break; + } + } + + /// Print a range of nodes as a single "array" child node. + template + void printRecRange(const NodeRange &range, StringRef topLabel) { + printRecArbitrary([&](StringRef topLabel) { + printHead("array", ASTNodeColor, topLabel); + for (auto node : range) { + printRec(node, ""); + } + printFoot(); + }, topLabel); + } + + /// Print a range of nodes as a single "array" child node. + template + void printRecRange(const NodeRange &range, const ASTContext *Ctx, StringRef topLabel) { + printRecArbitrary([&](StringRef topLabel) { + printHead("array", ASTNodeColor, topLabel); + for (auto node : range) { + printRec(node, Ctx, ""); + } + printFoot(); + }, topLabel); + } + + /// Print the beginning of a new node, including its type and an optional label for it. + void printHead(StringRef Name, TerminalColor Color, + StringRef Label = "") { OS.indent(Indent); PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, PatternColor) << Name; + if (!Label.empty()) { + PrintWithColorRAII(OS, FieldLabelColor) << Label; + OS << "="; + } - if (P->isImplicit()) - PrintWithColorRAII(OS, ExprModifierColor) << " implicit"; + PrintWithColorRAII(OS, Color) << Name; + } + + /// Print the end of a new node. + void printFoot() { + PrintWithColorRAII(OS, ParenthesisColor) << ')'; + } + + /// Print a single argument as a child node. + void printRec(const Argument &arg) { + printRecArbitrary([&](StringRef L) { + printHead("argument", ExprColor, L); + + auto label = arg.getLabel(); + if (!label.empty()) { + printFieldQuoted(label.str(), "label", ArgumentsColor); + } + printFlag(arg.isInOut(), "inout", ArgModifierColor); + + printRec(arg.getExpr()); + printFoot(); + }); + } + + /// Print an argument list as a child node. + void printRec(const ArgumentList *argList, StringRef label = "") { + printRecArbitrary([&](StringRef label) { + visitArgumentList(argList, label); + }, label); + } + + /// Print an argument list node. + void visitArgumentList(const ArgumentList *argList, StringRef label = "") { + printHead("argument_list", ExprColor, label); + + printFlag(argList->isImplicit(), "implicit", ArgModifierColor); + + if (argList->hasAnyArgumentLabels()) { + printFieldQuotedRaw([&](raw_ostream &OS) { + for (auto arg : *argList) { + auto label = arg.getLabel(); + OS << (label.empty() ? "_" : label.str()) << ":"; + } + }, "labels", ArgumentsColor); + } + + for (auto arg : *argList) { + printRec(arg); + } + + printFoot(); + } + + /// Print a parameter list as a child node. + void printRec(const ParameterList *params, const ASTContext *ctx = nullptr, + StringRef label = "") { + printRecArbitrary([&](StringRef label) { + visitParameterList(params, ctx, label); + }, label); + } + + /// Print a parameter list node. + void visitParameterList(const ParameterList *params, + const ASTContext *ctx = nullptr, + StringRef label = "") { + printHead("parameter_list", ParameterColor, label); + + if (!ctx && params->size() != 0 && params->get(0)) + ctx = ¶ms->get(0)->getASTContext(); + printSourceRange(params->getSourceRange(), ctx); + + for (auto P : *params) { + printRec(const_cast(P)); + } + + printFoot(); + } + + /// Print an \c IfConfigClause as a child node. + void printRec(const IfConfigClause &Clause, const ASTContext *Ctx = nullptr, + StringRef Label = "") { + printRecArbitrary([&](StringRef Label) { + printHead((Clause.Cond ? "#if:" : "#else:"), StmtColor, Label); + + printFlag(Clause.isActive, "active", DeclModifierColor); + + if (Clause.Cond) { + printRec(Clause.Cond); + } + printRecRange(Clause.Elements, Ctx, "elements"); + + printFoot(); + }, Label); + } + + /// Print a substitution map as a child node. + void printRec(SubstitutionMap map, StringRef label = "") { + SmallPtrSet Dumped; + printRec(map, Dumped, label); + } + + /// Print a substitution map as a child node. + void printRec(SubstitutionMap map, VisitedConformances &visited, + StringRef label = ""); + + /// Print a substitution map as a child node. + void printRec(const ProtocolConformanceRef &conf, + VisitedConformances &visited, StringRef label = ""); + + /// Print a conformance reference as a child node. + void printRec(const ProtocolConformanceRef &conf, StringRef label = "") { + SmallPtrSet Dumped; + printRec(conf, Dumped, label); + } + + /// Print a conformance reference as a child node. + void printRec(const ProtocolConformance *conformance, + VisitedConformances &visited, StringRef label = ""); + + /// Print a requirement node. + void visitRequirement(const Requirement &requirement, StringRef label = "") { + printHead("requirement", ASTNodeColor, label); + + PrintOptions opts; + opts.ProtocolQualifiedDependentMemberTypes = true; + + printFieldQuotedRaw([&](raw_ostream &out) { + requirement.getFirstType().print(out, opts); + }, ""); + + printField(requirement.getKind(), ""); + + if (requirement.getKind() != RequirementKind::Layout + && requirement.getSecondType()) + printFieldQuotedRaw([&](raw_ostream &out) { + requirement.getSecondType().print(out, opts); + }, ""); + else if (requirement.getLayoutConstraint()) + printFieldQuoted(requirement.getLayoutConstraint(), ""); + + printFoot(); + } + + /// Print a requirement as a child node. + void printRec(const Requirement &requirement, StringRef label = "") { + printRecArbitrary([&](StringRef label) { + visitRequirement(requirement); + }); + } + + /// Print a field with a short keyword-style value, printing the value by + /// passing a closure that takes a \c raw_ostream. + template + void printFieldRaw(Fn body, StringRef name, + TerminalColor color = FieldLabelColor) { + OS << " "; + if (!name.empty()) + PrintWithColorRAII(OS, color) << name << "="; + body(PrintWithColorRAII(OS, color).getOS()); + } + + /// Print a field with a short keyword-style value. The value will be + /// formatted using a \c getDumpString() overload. + template + void printField(const T &value, StringRef name, + TerminalColor color = FieldLabelColor) { + printFieldRaw([&](raw_ostream &OS) { OS << getDumpString(value); }, + name, color); + } + + /// Print a field with a long value that will be automatically quoted and + /// escaped, printing the value by passing a closure that takes a + /// \c raw_ostream. + template + void printFieldQuotedRaw(Fn body, StringRef name, + TerminalColor color = FieldLabelColor) { + printFieldRaw([&](raw_ostream &OS) { + OS << quote; + { escaping_ostream escOS(OS); body(escOS); } + OS << quote; + }, name, color); + } + + /// Print a field with a long value that will be automatically quoted and + /// escaped. + template + void printFieldQuoted(const T &value, StringRef name, + TerminalColor color = FieldLabelColor) { + printFieldQuotedRaw([&](raw_ostream &OS) { OS << value; }, name, color); + } + + /// Print a simple boolean value, printing the value by passing a closure + /// that takes a \c raw_ostream. + template + void printFlagRaw(Fn body, TerminalColor color = FieldLabelColor) { + printFieldRaw(body, "", color); + } + + /// Print a simple boolean value unconditionally. + void printFlag(StringRef name, TerminalColor color = FieldLabelColor) { + printFieldRaw([&](raw_ostream &OS) { OS << name; }, "", color); + } + + /// Print a simple boolean value. + void printFlag(bool isSet, StringRef name, + TerminalColor color = FieldLabelColor) { + if (isSet) + printFlag(name, color); + } + + /// Print a field containing a node's source location. + void printSourceLoc(const SourceLoc L, const ASTContext *Ctx, + StringRef label = "location") { + if (!L.isValid() || !Ctx) + return; + + printFieldRaw([&](raw_ostream &OS) { + escaping_ostream escOS(OS); + L.print(escOS, Ctx->SourceMgr); + }, label, LocationColor); + } + + /// Print a field containing a node's source range. + void printSourceRange(const SourceRange R, const ASTContext *Ctx) { + if (!R.isValid() || !Ctx) + return; + + printFieldRaw([&](raw_ostream &OS) { + escaping_ostream escOS(OS); + R.print(escOS, Ctx->SourceMgr, /*PrintText=*/false); + }, "range", RangeColor); + } + + /// Print a field containing a node's name, printing the node's name by + /// passing a closure that takes a \c raw_ostream. + template + void printNameRaw(Fn body, bool leadingSpace = true) { + if (leadingSpace) + OS << ' '; + PrintWithColorRAII colored(OS, IdentifierColor); + OS << quote; + { + escaping_ostream escaping_os(OS); + body(escaping_os); + } + OS << quote; + } + + /// Print a field containing a node's name. + void printName(DeclName name, bool leadingSpace = true) { + printNameRaw([&](raw_ostream &OS) { + ::printName(OS, name); + }, leadingSpace); + } + + /// Print an unnamed field containing a node's name, read from a declaration. + void printDeclName(const ValueDecl *D, bool leadingSpace = true) { + if (D->getName()) { + printName(D->getName(), leadingSpace); + } else { + if (leadingSpace) + OS << ' '; + PrintWithColorRAII(OS, IdentifierColor) + << "'; + } + } + + /// Print a field containing a node's name, read from a declaration. + void printDeclNameField(const ValueDecl *D, StringRef name) { + printFieldRaw([&](raw_ostream &os) { + printDeclName(D, /*leadingSpace=*/false); + }, name); + } + + /// Print a field containing a concrete reference to a declaration. + void printDeclRefField(ConcreteDeclRef declRef, StringRef label, + TerminalColor Color = DeclColor) { + printFieldQuotedRaw([&](raw_ostream &OS) { declRef.dump(OS); }, label, + Color); + } + }; + + class PrintPattern : public PatternVisitor, + public PrintBase { + public: + using PrintBase::PrintBase; + + void printCommon(Pattern *P, const char *Name, StringRef Label) { + printHead(Name, PatternColor, Label); + + printFlag(P->isImplicit(), "implicit", ExprModifierColor); if (P->hasType()) { - PrintWithColorRAII(OS, TypeColor) << " type='"; - P->getType().print(PrintWithColorRAII(OS, TypeColor).getOS()); - PrintWithColorRAII(OS, TypeColor) << "'"; + printFieldQuoted(P->getType(), "type", TypeColor); } - return OS; } - void visitParenPattern(ParenPattern *P) { - printCommon(P, "pattern_paren") << '\n'; + void visitParenPattern(ParenPattern *P, StringRef label) { + printCommon(P, "pattern_paren", label); printRec(P->getSubPattern()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitTuplePattern(TuplePattern *P) { - printCommon(P, "pattern_tuple"); + void visitTuplePattern(TuplePattern *P, StringRef label) { + printCommon(P, "pattern_tuple", label); - OS << " names="; - interleave(P->getElements(), - [&](const TuplePatternElt &elt) { - auto name = elt.getLabel(); - OS << (name.empty() ? "''" : name.str()); - }, - [&] { OS << ","; }); + printFieldQuotedRaw([&](raw_ostream &OS) { + interleave(P->getElements(), OS, + [&](const TuplePatternElt &elt) { + auto name = elt.getLabel(); + OS << (name.empty() ? "''" : name.str()); + }, ","); + }, "names"); for (auto &elt : P->getElements()) { - OS << '\n'; printRec(elt.getPattern()); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitNamedPattern(NamedPattern *P) { - printCommon(P, "pattern_named"); - PrintWithColorRAII(OS, IdentifierColor) << " '" << P->getNameStr() << "'"; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitNamedPattern(NamedPattern *P, StringRef label) { + printCommon(P, "pattern_named", label); + printDeclName(P->getDecl()); + printFoot(); } - void visitAnyPattern(AnyPattern *P) { + void visitAnyPattern(AnyPattern *P, StringRef label) { if (P->isAsyncLet()) { - printCommon(P, "async_let "); + printCommon(P, "async_let ", label); } - printCommon(P, "pattern_any"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printCommon(P, "pattern_any", label); + printFoot(); } - void visitTypedPattern(TypedPattern *P) { - printCommon(P, "pattern_typed") << '\n'; + void visitTypedPattern(TypedPattern *P, StringRef label) { + printCommon(P, "pattern_typed", label); printRec(P->getSubPattern()); if (auto *repr = P->getTypeRepr()) { - OS << '\n'; printRec(repr); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitIsPattern(IsPattern *P) { - printCommon(P, "pattern_is") - << ' ' << getCheckedCastKindName(P->getCastKind()) << ' '; - P->getCastType().print(OS); + void visitIsPattern(IsPattern *P, StringRef label) { + printCommon(P, "pattern_is", label); + printField(P->getCastKind(), "cast_kind"); + printFieldQuoted(P->getCastType(), "cast_to", TypeColor); if (auto sub = P->getSubPattern()) { - OS << '\n'; printRec(sub); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitExprPattern(ExprPattern *P) { - printCommon(P, "pattern_expr"); - OS << '\n'; + void visitExprPattern(ExprPattern *P, StringRef label) { + printCommon(P, "pattern_expr", label); if (auto m = P->getCachedMatchExpr()) printRec(m); else printRec(P->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitBindingPattern(BindingPattern *P) { - printCommon(P, P->isLet() ? "pattern_let" : "pattern_var"); - OS << '\n'; + void visitBindingPattern(BindingPattern *P, StringRef label) { + printCommon(P, P->isLet() ? "pattern_let" : "pattern_var", label); printRec(P->getSubPattern()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitEnumElementPattern(EnumElementPattern *P) { - printCommon(P, "pattern_enum_element"); - OS << ' '; - P->getParentType().print(PrintWithColorRAII(OS, TypeColor).getOS()); - PrintWithColorRAII(OS, IdentifierColor) << '.' << P->getName(); + void visitEnumElementPattern(EnumElementPattern *P, StringRef label) { + printCommon(P, "pattern_enum_element", label); + + printFieldQuotedRaw([&](raw_ostream &OS) { + P->getParentType().print(PrintWithColorRAII(OS, TypeColor).getOS()); + OS << '.'; + PrintWithColorRAII(OS, IdentifierColor) << P->getName(); + }, "element"); + if (P->hasSubPattern()) { - OS << '\n'; printRec(P->getSubPattern()); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitOptionalSomePattern(OptionalSomePattern *P) { - printCommon(P, "pattern_optional_some"); - OS << '\n'; + void visitOptionalSomePattern(OptionalSomePattern *P, StringRef label) { + printCommon(P, "pattern_optional_some", label); printRec(P->getSubPattern()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitBoolPattern(BoolPattern *P) { - printCommon(P, "pattern_bool"); - OS << (P->getValue() ? " true)" : " false)"); + void visitBoolPattern(BoolPattern *P, StringRef label) { + printCommon(P, "pattern_bool", label); + printField(P->getValue(), "value"); + printFoot(); } }; /// PrintDecl - Visitor implementation of Decl::print. - class PrintDecl : public DeclVisitor { + class PrintDecl : public DeclVisitor, + public PrintBase { public: - raw_ostream &OS; - unsigned Indent; - - explicit PrintDecl(raw_ostream &os, unsigned indent = 0) - : OS(os), Indent(indent) { } + using PrintBase::PrintBase; private: - void printRec(Decl *D) { PrintDecl(OS, Indent + 2).visit(D); } - void printRec(Expr *E) { E->dump(OS, Indent+2); } - void printRec(Stmt *S, const ASTContext &Ctx) { S->dump(OS, &Ctx, Indent+2); } - void printRec(Pattern *P) { PrintPattern(OS, Indent+2).visit(P); } - void printRec(TypeRepr *T); - void printWhereRequirements( - PointerUnion Owner) - const { + PointerUnion Owner + ) { const auto printWhere = [&](const TrailingWhereClause *Where) { if (Where) { - OS << " where requirements: "; - Where->print(OS, /*printWhereKeyword*/ false); + printFieldQuotedRaw([&](raw_ostream &OS) { + Where->print(OS, /*printWhereKeyword*/ false); + }, "where_requirements"); } }; @@ -542,225 +1019,193 @@ namespace { } } - // Print a field with a value. - template - raw_ostream &printField(StringRef name, const T &value) { - OS << " "; - PrintWithColorRAII(OS, TypeFieldColor) << name; - OS << "=" << value; - return OS; - } - - void printCommon(Decl *D, const char *Name, + void printCommon(Decl *D, const char *Name, StringRef Label, TerminalColor Color = DeclColor) { - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, Color) << Name; + printHead(Name, Color, Label); - if (D->isImplicit()) - PrintWithColorRAII(OS, DeclModifierColor) << " implicit"; - - if (D->isHoisted()) - PrintWithColorRAII(OS, DeclModifierColor) << " hoisted"; - - printSourceRange(OS, D->getSourceRange(), D->getASTContext()); - - if (D->TrailingSemiLoc.isValid()) - PrintWithColorRAII(OS, DeclModifierColor) << " trailing_semi"; + printFlag(D->isImplicit(), "implicit", DeclModifierColor); + printFlag(D->isHoisted(), "hoisted", DeclModifierColor); + printSourceRange(D->getSourceRange(), &D->getASTContext()); + printFlag(D->TrailingSemiLoc.isValid(), "trailing_semi", + DeclModifierColor); } void printInherited(InheritedTypes Inherited) { if (Inherited.empty()) return; - OS << " inherits: "; - interleave(Inherited.getEntries(), - [&](InheritedEntry Super) { Super.getType().print(OS); }, - [&] { OS << ", "; }); + printFieldQuotedRaw([&](raw_ostream &OS) { + interleave(Inherited.getEntries(), OS, + [&](InheritedEntry Super) { Super.getType().print(OS); }, + ", "); + }, "inherits"); } public: - void visitImportDecl(ImportDecl *ID) { - printCommon(ID, "import_decl"); - - if (ID->isExported()) - OS << " exported"; + void visitImportDecl(ImportDecl *ID, StringRef label) { + printCommon(ID, "import_decl", label); + printFlag(ID->isExported(), "exported"); if (ID->getImportKind() != ImportKind::Module) - OS << " kind=" << getImportKindString(ID->getImportKind()); + printField(ID->getImportKind(), "kind"); - OS << " '"; - // Check if module aliasing was used for the given imported module; for - // example, if '-module-alias Foo=Bar' was passed and this module has - // 'import Foo', its corresponding real module name 'Bar' should be printed. - ImportPath::Builder scratch; - ID->getRealImportPath(scratch).print(OS); - OS << "')"; + printFieldQuotedRaw([&](raw_ostream &OS) { + // Check if module aliasing was used for the given imported module; for + // example, if '-module-alias Foo=Bar' was passed and this module has + // 'import Foo', its corresponding real module name 'Bar' should be printed. + ImportPath::Builder scratch; + ID->getRealImportPath(scratch).print(OS); + }, "module", IdentifierColor); + + printFoot(); } - void visitExtensionDecl(ExtensionDecl *ED) { - printCommon(ED, "extension_decl", ExtensionColor); - OS << ' '; - if (ED->hasBeenBound()) - ED->getExtendedType().print(OS); - else - ED->getExtendedTypeRepr()->print(OS); + void visitExtensionDecl(ExtensionDecl *ED, StringRef label) { + printCommon(ED, "extension_decl", label, ExtensionColor); + printFlag(!ED->hasBeenBound(), "unbound"); + printNameRaw([&](raw_ostream &OS) { + if (ED->hasBeenBound()) + ED->getExtendedType().print(OS); + else + ED->getExtendedTypeRepr()->print(OS); + }); printCommonPost(ED); } - void printDeclName(const ValueDecl *D) { - if (D->getName()) { - PrintWithColorRAII(OS, IdentifierColor) - << '\"' << D->getName() << '\"'; - } else { - PrintWithColorRAII(OS, IdentifierColor) - << "'anonname=" << (const void*)D << '\''; - } - } + void visitTypeAliasDecl(TypeAliasDecl *TAD, StringRef label) { + printCommon(TAD, "typealias", label); - void visitTypeAliasDecl(TypeAliasDecl *TAD) { - printCommon(TAD, "typealias"); - PrintWithColorRAII(OS, TypeColor) << " type="; if (auto underlying = TAD->getCachedUnderlyingType()) { - PrintWithColorRAII(OS, TypeColor) - << "'" << underlying.getString() << "'"; + printFieldQuoted(underlying, "type", TypeColor); } else { - PrintWithColorRAII(OS, TypeColor) << "<<>>"; + printFlag("unresolved_type", TypeColor); } printWhereRequirements(TAD); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitOpaqueTypeDecl(OpaqueTypeDecl *OTD) { - printCommon(OTD, "opaque_type"); - OS << " naming_decl="; - printDeclName(OTD->getNamingDecl()); - PrintWithColorRAII(OS, TypeColor) << " opaque_interface=" - << OTD->getDeclaredInterfaceType().getString(); - OS << " in " - << OTD->getOpaqueInterfaceGenericSignature()->getAsString(); + void visitOpaqueTypeDecl(OpaqueTypeDecl *OTD, StringRef label) { + printCommon(OTD, "opaque_type", label); + + printDeclNameField(OTD->getNamingDecl(), "naming_decl"); + printFieldQuotedRaw([&](raw_ostream &OS) { + OS << OTD->getDeclaredInterfaceType() << " in " + << OTD->getOpaqueInterfaceGenericSignature()->getAsString(); + + }, "opaque_interface", TypeColor); + if (auto underlyingSubs = OTD->getUniqueUnderlyingTypeSubstitutions()) { - OS << " underlying:\n"; - SmallPtrSet Dumped; - dumpSubstitutionMapRec(*underlyingSubs, OS, - SubstitutionMap::DumpStyle::Full, - Indent + 2, Dumped); + printRec(*underlyingSubs); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitGenericTypeParamDecl(GenericTypeParamDecl *decl) { - printCommon(decl, "generic_type_param"); - OS << " depth=" << decl->getDepth() << " index=" << decl->getIndex(); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitGenericTypeParamDecl(GenericTypeParamDecl *decl, StringRef label) { + printCommon(decl, "generic_type_param", label); + printField(decl->getDepth(), "depth"); + printField(decl->getIndex(), "index"); + printFoot(); } - void visitAssociatedTypeDecl(AssociatedTypeDecl *decl) { - printCommon(decl, "associated_type_decl"); + void visitAssociatedTypeDecl(AssociatedTypeDecl *decl, StringRef label) { + printCommon(decl, "associated_type_decl", label); if (auto defaultDef = decl->getDefaultDefinitionType()) { - OS << " default="; - defaultDef.print(OS); + printFieldQuoted(defaultDef, "default"); } printWhereRequirements(decl); if (decl->overriddenDeclsComputed()) { - OS << " overridden="; - interleave(decl->getOverriddenDecls(), - [&](AssociatedTypeDecl *overridden) { - OS << overridden->getProtocol()->getName(); - }, [&]() { - OS << ", "; - }); + printFieldQuotedRaw([&](raw_ostream &OS) { + interleave(decl->getOverriddenDecls(), OS, + [&](AssociatedTypeDecl *overridden) { + OS << overridden->getProtocol()->getName(); + }, ", "); + }, "overridden"); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitProtocolDecl(ProtocolDecl *PD) { - printCommon(PD, "protocol"); + void visitProtocolDecl(ProtocolDecl *PD, StringRef label) { + printCommon(PD, "protocol", label); - OS << " requirement signature="; if (PD->isRequirementSignatureComputed()) { auto requirements = PD->getRequirementSignatureAsGenericSignature(); - OS << requirements->getAsString(); + std::string reqSigStr = requirements->getAsString(); + printFieldQuoted(reqSigStr, "requirement_signature"); } else { - OS << ""; + printFlag("uncomputed_requirement_signature"); } + printCommonPost(PD); } - void printCommon(ValueDecl *VD, const char *Name, - TerminalColor Color = DeclColor) { - printCommon((Decl*)VD, Name, Color); + void printGenericParameters(GenericParamList *Params) { + if (!Params) + return; + + printFieldQuotedRaw([&](raw_ostream &OS) { + Params->print(OS); + }, "", TypeColor); + } + + void printCommon(ValueDecl *VD, const char *Name, StringRef Label, + TerminalColor Color = DeclColor) { + printCommon((Decl*)VD, Name, Label, Color); - OS << ' '; printDeclName(VD); if (auto *AFD = dyn_cast(VD)) - printGenericParameters(OS, AFD->getParsedGenericParams()); + printGenericParameters(AFD->getParsedGenericParams()); if (auto *GTD = dyn_cast(VD)) - printGenericParameters(OS, GTD->getParsedGenericParams()); + printGenericParameters(GTD->getParsedGenericParams()); if (auto *MD = dyn_cast(VD)) - printGenericParameters(OS, MD->getParsedGenericParams()); + printGenericParameters(MD->getParsedGenericParams()); if (VD->hasInterfaceType()) { - PrintWithColorRAII(OS, InterfaceTypeColor) << " interface type='"; - VD->getInterfaceType()->print( - PrintWithColorRAII(OS, InterfaceTypeColor).getOS()); - PrintWithColorRAII(OS, InterfaceTypeColor) << "'"; + printFieldQuoted(VD->getInterfaceType(), "interface type", + InterfaceTypeColor); } if (VD->hasAccess()) { - PrintWithColorRAII(OS, AccessLevelColor) << " access=" - << getAccessLevelSpelling(VD->getFormalAccess()); + printField(VD->getFormalAccess(), "access", AccessLevelColor); } if (VD->overriddenDeclsComputed()) { auto overridden = VD->getOverriddenDecls(); if (!overridden.empty()) { - PrintWithColorRAII(OS, OverrideColor) << " override="; - interleave(overridden, - [&](ValueDecl *overridden) { - overridden->dumpRef( - PrintWithColorRAII(OS, OverrideColor).getOS()); - }, [&]() { - OS << ", "; - }); + printFieldQuotedRaw([&](raw_ostream &OS) { + interleave(overridden, OS, + [&](ValueDecl *overridden) { + overridden->dumpRef(OS); + }, ", "); + }, "override", OverrideColor); } } auto VarD = dyn_cast(VD); const auto &attrs = VD->getAttrs(); - if (attrs.hasAttribute() && !(VarD && VarD->isLet())) - OS << " final"; - if (attrs.hasAttribute()) - OS << " @objc"; - if (attrs.hasAttribute()) - OS << " dynamic"; + printFlag(attrs.hasAttribute() && !(VarD && VarD->isLet()), + "final"); + printFlag(attrs.hasAttribute(), "@objc"); + printFlag(attrs.hasAttribute(), "dynamic"); if (auto *attr = attrs.getAttribute()) { - OS << " @_dynamicReplacement(for: \""; - OS << attr->getReplacedFunctionName(); - OS << "\")"; - } - switch (VD->getLifetimeAnnotation()) { - case LifetimeAnnotation::EagerMove: - OS << " _eagerMove"; - break; - case LifetimeAnnotation::Lexical: - OS << " _lexical"; - break; - case LifetimeAnnotation::None: - break; + printFlagRaw([&](raw_ostream &OS) { + OS << "@_dynamicReplacement(for: \""; + OS << attr->getReplacedFunctionName(); + OS << "\")"; + }); } + auto lifetimeString = getDumpString(VD->getLifetimeAnnotation()); + if (!lifetimeString.empty()) + printFlag(lifetimeString); } - void printCommon(NominalTypeDecl *NTD, const char *Name, + void printCommon(NominalTypeDecl *NTD, const char *Name, StringRef Label, TerminalColor Color = DeclColor) { - printCommon((ValueDecl *)NTD, Name, Color); + printCommon((ValueDecl *)NTD, Name, Label, Color); - if (NTD->hasInterfaceType()) { - if (NTD->isResilient()) - OS << " resilient"; - else - OS << " non-resilient"; - } + if (NTD->hasInterfaceType()) + printFlag(NTD->isResilient() ? "resilient" : "non_resilient"); } void printCommonPost(const IterableDeclContext *IDC) { @@ -779,337 +1224,256 @@ namespace { } for (Decl *D : IDC->getMembers()) { - OS << '\n'; printRec(D); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitSourceFile(const SourceFile &SF) { - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, ASTNodeColor) << "source_file "; - PrintWithColorRAII(OS, LocationColor) << '\"' << SF.getFilename() << '\"'; + printHead("source_file", ASTNodeColor); + printNameRaw([&](raw_ostream &OS) { + OS << SF.getFilename(); + }); if (auto items = SF.getCachedTopLevelItems()) { for (auto item : *items) { if (item.isImplicit()) continue; - OS << '\n'; - if (auto decl = item.dyn_cast()) { printRec(decl); } else if (auto stmt = item.dyn_cast()) { - stmt->dump(OS, &SF.getASTContext(), Indent + 2); + printRec(stmt, &SF.getASTContext()); } else { auto expr = item.get(); - expr->dump(OS, Indent + 2); + printRec(expr); } } } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitVarDecl(VarDecl *VD) { - printCommon(VD, "var_decl"); - if (VD->isDistributed()) - PrintWithColorRAII(OS, DeclModifierColor) << " distributed"; - if (VD->isLet()) - PrintWithColorRAII(OS, DeclModifierColor) << " let"; - if (VD->getAttrs().hasAttribute()) - PrintWithColorRAII(OS, DeclModifierColor) << " lazy"; + void visitVarDecl(VarDecl *VD, StringRef label) { + printCommon(VD, "var_decl", label); + + printFlag(VD->isDistributed(), "distributed", DeclModifierColor); + printFlag(VD->isLet(), "let", DeclModifierColor); + printFlag(VD->getAttrs().hasAttribute(), "lazy", + DeclModifierColor); printStorageImpl(VD); + printFlag(VD->getAttrs().hasAttribute(), + "known_to_be_local", DeclModifierColor); + printAccessors(VD); - if (VD->getAttrs().hasAttribute()) { - OS << " known-to-be-local"; - } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } void printStorageImpl(AbstractStorageDecl *D) { - if (D->isStatic()) - PrintWithColorRAII(OS, DeclModifierColor) << " type"; + printFlag(D->isStatic(), "type", DeclModifierColor); if (D->hasInterfaceType()) { auto impl = D->getImplInfo(); - PrintWithColorRAII(OS, DeclModifierColor) - << " readImpl=" - << getReadImplKindName(impl.getReadImpl()); + printField(impl.getReadImpl(), "readImpl", DeclModifierColor); if (!impl.supportsMutation()) { - PrintWithColorRAII(OS, DeclModifierColor) - << " immutable"; + printFlag("immutable", DeclModifierColor); } else { - PrintWithColorRAII(OS, DeclModifierColor) - << " writeImpl=" - << getWriteImplKindName(impl.getWriteImpl()); - PrintWithColorRAII(OS, DeclModifierColor) - << " readWriteImpl=" - << getReadWriteImplKindName(impl.getReadWriteImpl()); + printField(impl.getWriteImpl(), "writeImpl", DeclModifierColor); + printField(impl.getReadWriteImpl(), "readWriteImpl", + DeclModifierColor); } } } void printAccessors(AbstractStorageDecl *D) { for (auto accessor : D->getAllAccessors()) { - OS << "\n"; printRec(accessor); } } - void visitParamDecl(ParamDecl *PD) { - printParameter(PD); + void visitParamDecl(ParamDecl *PD, StringRef label) { + printHead("parameter", ParameterColor, label); + + printDeclName(PD); + if (!PD->getArgumentName().empty()) + printFieldQuoted(PD->getArgumentName(), "apiName", IdentifierColor); + if (PD->hasInterfaceType()) { + printFieldQuoted(PD->getInterfaceType(), "interface type", + InterfaceTypeColor); + } + + if (auto specifier = PD->getCachedSpecifier()) { + if (*specifier != ParamDecl::Specifier::Default) { + printFlag(ParamDecl::getSpecifierSpelling(*specifier)); + } + } + + if (PD->hasInterfaceType()) + printFlag(PD->isVariadic(), "variadic"); + printFlag(PD->isAutoClosure(), "autoclosure"); + printFlag(PD->getAttrs().hasAttribute(),"nonEphemeral"); + + auto lifetimeString = + getDumpString(PD->getLifetimeAnnotationFromAttributes()); + if (!lifetimeString.empty()) + printFlag(lifetimeString); + + printFlag(PD->isNoImplicitCopy(), "noImplicitCopy"); + + if (PD->getDefaultArgumentKind() != DefaultArgumentKind::None) { + printField(PD->getDefaultArgumentKind(), "default_arg"); + } + if (PD->hasDefaultExpr() && + !PD->getDefaultArgumentCaptureInfo().isTrivial()) { + printFieldRaw([&](raw_ostream &OS) { + PD->getDefaultArgumentCaptureInfo().print(OS); + }, "", CapturesColor); + } + + printFlag(PD->getAttrs().hasAttribute(), + "known_to_be_local", DeclModifierColor); + + if (auto init = PD->getStructuralDefaultExpr()) { + printRec(init, "expression"); + } + + printFoot(); } - void visitEnumCaseDecl(EnumCaseDecl *ECD) { - printCommon(ECD, "enum_case_decl"); + void visitParameterList(ParameterList *PL, StringRef label) { + PrintBase::visitParameterList(PL, /*ctx=*/nullptr, label); + } + + void visitEnumCaseDecl(EnumCaseDecl *ECD, StringRef label) { + printCommon(ECD, "enum_case_decl", label); for (EnumElementDecl *D : ECD->getElements()) { - OS << '\n'; printRec(D); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitEnumDecl(EnumDecl *ED) { - printCommon(ED, "enum_decl"); + void visitEnumDecl(EnumDecl *ED, StringRef label) { + printCommon(ED, "enum_decl", label); printCommonPost(ED); } - void visitEnumElementDecl(EnumElementDecl *EED) { - printCommon(EED, "enum_element_decl"); + void visitEnumElementDecl(EnumElementDecl *EED, StringRef label) { + printCommon(EED, "enum_element_decl", label); if (auto *paramList = EED->getParameterList()) { - Indent += 2; - OS << "\n"; - printParameterList(paramList); - Indent -= 2; + printRec(paramList); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitStructDecl(StructDecl *SD) { - printCommon(SD, "struct_decl"); + void visitStructDecl(StructDecl *SD, StringRef label) { + printCommon(SD, "struct_decl", label); printCommonPost(SD); } - void visitClassDecl(ClassDecl *CD) { - printCommon(CD, "class_decl"); - if (CD->isExplicitActor()) { - OS << " actor"; - } else if (CD->isExplicitDistributedActor()) { - OS << " distributed actor"; - } - if (CD->getAttrs().hasAttribute()) - OS << " @_staticInitializeObjCMetadata"; + void visitClassDecl(ClassDecl *CD, StringRef label) { + printCommon(CD, "class_decl", label); + + printFlag(CD->isExplicitDistributedActor(), "distributed"); + printFlag(CD->isExplicitActor(), "actor"); + printFlag(CD->getAttrs().hasAttribute(), + "@_staticInitializeObjCMetadata"); + printCommonPost(CD); } - void visitBuiltinTupleDecl(BuiltinTupleDecl *BTD) { - printCommon(BTD, "builtin_tuple_decl"); + void visitBuiltinTupleDecl(BuiltinTupleDecl *BTD, StringRef label) { + printCommon(BTD, "builtin_tuple_decl", label); printCommonPost(BTD); } - void visitPatternBindingDecl(PatternBindingDecl *PBD) { - printCommon(PBD, "pattern_binding_decl"); + void visitPatternBindingDecl(PatternBindingDecl *PBD, StringRef label) { + printCommon(PBD, "pattern_binding_decl", label); for (auto idx : range(PBD->getNumPatternEntries())) { - OS << '\n'; printRec(PBD->getPattern(idx)); if (PBD->getOriginalInit(idx)) { - OS << '\n'; - OS.indent(Indent + 2); - OS << "Original init:\n"; - printRec(PBD->getOriginalInit(idx)); + printRec(PBD->getOriginalInit(idx), "original_init"); } if (PBD->getInit(idx)) { - OS << '\n'; - OS.indent(Indent + 2); - OS << "Processed init:\n"; - printRec(PBD->getInit(idx)); + printRec(PBD->getInit(idx), "processed_init"); } } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitSubscriptDecl(SubscriptDecl *SD) { - printCommon(SD, "subscript_decl"); + void visitSubscriptDecl(SubscriptDecl *SD, StringRef label) { + printCommon(SD, "subscript_decl", label); printStorageImpl(SD); printAccessors(SD); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void printCommonAFD(AbstractFunctionDecl *D, const char *Type) { - printCommon(D, Type, FuncColor); + void printCommonAFD(AbstractFunctionDecl *D, const char *Type, StringRef Label) { + printCommon(D, Type, Label, FuncColor); if (!D->getCaptureInfo().isTrivial()) { - OS << " "; - D->getCaptureInfo().print(OS); + printFlagRaw([&](raw_ostream &OS) { + D->getCaptureInfo().print(OS); + }); } - if (D->getAttrs().hasAttribute()) { - PrintWithColorRAII(OS, ExprModifierColor) << " nonisolated"; - } - if (D->isDistributed()) { - PrintWithColorRAII(OS, ExprModifierColor) << " distributed"; - } - if (D->isDistributedThunk()) { - PrintWithColorRAII(OS, ExprModifierColor) << " distributed-thunk"; - } - - if (auto fac = D->getForeignAsyncConvention()) { - OS << " foreign_async="; - if (auto type = fac->completionHandlerType()) - type.print(OS); - OS << ",completion_handler_param=" - << fac->completionHandlerParamIndex(); - if (auto errorParamIndex = fac->completionHandlerErrorParamIndex()) - OS << ",error_param=" << *errorParamIndex; - } - - if (auto fec = D->getForeignErrorConvention()) { - OS << " foreign_error="; - OS << getForeignErrorConventionKindString(fec->getKind()); - bool wantResultType = ( - fec->getKind() == ForeignErrorConvention::ZeroResult || - fec->getKind() == ForeignErrorConvention::NonZeroResult); - - OS << ((fec->isErrorOwned() == ForeignErrorConvention::IsOwned) - ? ",owned" - : ",unowned"); - OS << ",param=" << llvm::utostr(fec->getErrorParameterIndex()); - OS << ",paramtype=" << fec->getErrorParameterType().getString(); - if (wantResultType) - OS << ",resulttype=" << fec->getResultType().getString(); - } - } - - void printParameter(const ParamDecl *P) { - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, ParameterColor) << "parameter "; - if (P->getAttrs().hasAttribute()) { - OS << "known-to-be-local "; - } - printDeclName(P); - if (!P->getArgumentName().empty()) - PrintWithColorRAII(OS, IdentifierColor) - << " apiName=" << P->getArgumentName(); - - if (P->hasInterfaceType()) { - PrintWithColorRAII(OS, InterfaceTypeColor) << " interface type='"; - P->getInterfaceType().print( - PrintWithColorRAII(OS, InterfaceTypeColor).getOS()); - PrintWithColorRAII(OS, InterfaceTypeColor) << "'"; - } - - if (auto specifier = P->getCachedSpecifier()) { - if (*specifier != ParamDecl::Specifier::Default) { - OS << ' ' << ParamDecl::getSpecifierSpelling(*specifier); - } - } - - if (P->hasInterfaceType()) - if (P->isVariadic()) - OS << " variadic"; - - if (P->isAutoClosure()) - OS << " autoclosure"; - - if (P->getAttrs().hasAttribute()) - OS << " nonEphemeral"; - - switch (P->getLifetimeAnnotationFromAttributes()) { - case LifetimeAnnotation::EagerMove: - OS << " _eagerMove"; - break; - case LifetimeAnnotation::Lexical: - OS << " _lexical"; - break; - case LifetimeAnnotation::None: - break; - } - - if (P->isNoImplicitCopy()) - OS << " noImplicitCopy"; - - if (P->getDefaultArgumentKind() != DefaultArgumentKind::None) { - printField("default_arg", - getDefaultArgumentKindString(P->getDefaultArgumentKind())); - } - - if (P->hasDefaultExpr() && - !P->getDefaultArgumentCaptureInfo().isTrivial()) { - OS << " "; - P->getDefaultArgumentCaptureInfo().print( - PrintWithColorRAII(OS, CapturesColor).getOS()); - } - - if (auto init = P->getStructuralDefaultExpr()) { - OS << " expression=\n"; - printRec(init); - } - - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - - void printParameterList(const ParameterList *params, const ASTContext *ctx = nullptr) { - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, ParameterColor) << "parameter_list"; - - if (!ctx && params->size() != 0 && params->get(0)) - ctx = ¶ms->get(0)->getASTContext(); - - if (ctx) { - printSourceRange(OS, params->getSourceRange(), *ctx); - } - - Indent += 2; - for (auto P : *params) { - OS << '\n'; - printParameter(P); - } - Indent -= 2; - - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFlag(D->getAttrs().hasAttribute(), "nonisolated", + ExprModifierColor); + printFlag(D->isDistributed(), "distributed", ExprModifierColor); + printFlag(D->isDistributedThunk(), "distributed_thunk",ExprModifierColor); } void printAbstractFunctionDecl(AbstractFunctionDecl *D) { - Indent += 2; if (auto *P = D->getImplicitSelfDecl()) { - OS << '\n'; - printParameter(P); + printRec(P); } - - OS << '\n'; - printParameterList(D->getParameters(), &D->getASTContext()); - Indent -= 2; + printRec(D->getParameters(), &D->getASTContext()); if (auto FD = dyn_cast(D)) { if (FD->getResultTypeRepr()) { - OS << '\n'; - Indent += 2; - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - OS << "result\n"; - printRec(FD->getResultTypeRepr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRec(FD->getResultTypeRepr(), "result"); if (auto opaque = FD->getOpaqueResultTypeDecl()) { - OS << '\n'; - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - OS << "opaque_result_decl\n"; - printRec(opaque); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRec(opaque, "opaque_result_decl"); } - Indent -= 2; } } + if (auto fac = D->getForeignAsyncConvention()) { + printRecArbitrary([&](StringRef label) { + printHead("foreign_async_convention", ASTNodeColor, label); + if (auto type = fac->completionHandlerType()) + printFieldQuoted(type, "completion_handler_type", TypeColor); + printField(fac->completionHandlerParamIndex(), + "completion_handler_param"); + if (auto errorParamIndex = fac->completionHandlerErrorParamIndex()) + printField(*errorParamIndex, "error_param"); + printFoot(); + }); + } + + if (auto fec = D->getForeignErrorConvention()) { + printRecArbitrary([&](StringRef label) { + printHead("foreign_error_convention", ASTNodeColor, label); + printField(fec->getKind(), "kind"); + + bool wantResultType = ( + fec->getKind() == ForeignErrorConvention::ZeroResult || + fec->getKind() == ForeignErrorConvention::NonZeroResult); + + printFlag(getDumpString(fec->isErrorOwned())); + + printField(fec->getErrorParameterIndex(), "param"); + printFieldQuoted(fec->getErrorParameterType(), "paramtype"); + if (wantResultType) + printFieldQuoted(fec->getResultType(), "resulttype"); + printFoot(); + }); + } + if (D->hasSingleExpressionBody()) { // There won't be an expression if this is an initializer that was // originally spelled "init?(...) { nil }", because "nil" is modeled // via FailStmt in this context. if (auto *Body = D->getSingleExpressionBody()) { - OS << '\n'; printRec(Body); return; @@ -1117,201 +1481,151 @@ namespace { } if (auto Body = D->getBody(/*canSynthesize=*/false)) { - OS << '\n'; - printRec(Body, D->getASTContext()); + printRec(Body, &D->getASTContext()); } } - void printCommonFD(FuncDecl *FD, const char *type) { - printCommonAFD(FD, type); - if (FD->isStatic()) - OS << " type"; + void printCommonFD(FuncDecl *FD, const char *type, StringRef Label) { + printCommonAFD(FD, type, Label); + printFlag(FD->isStatic(), "type"); } - void visitFuncDecl(FuncDecl *FD) { - printCommonFD(FD, "func_decl"); + void visitFuncDecl(FuncDecl *FD, StringRef label) { + printCommonFD(FD, "func_decl", label); printAbstractFunctionDecl(FD); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitAccessorDecl(AccessorDecl *AD) { - printCommonFD(AD, "accessor_decl"); - OS << " " << getAccessorKindString(AD->getAccessorKind()); - OS << "_for=" << AD->getStorage()->getName(); + void visitAccessorDecl(AccessorDecl *AD, StringRef label) { + printCommonFD(AD, "accessor_decl", label); + printFlag(getDumpString(AD->getAccessorKind())); + printDeclNameField(AD->getStorage(), "for"); printAbstractFunctionDecl(AD); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitConstructorDecl(ConstructorDecl *CD) { - printCommonAFD(CD, "constructor_decl"); - if (CD->isRequired()) - PrintWithColorRAII(OS, DeclModifierColor) << " required"; - PrintWithColorRAII(OS, DeclModifierColor) << " " - << getCtorInitializerKindString(CD->getInitKind()); + void visitConstructorDecl(ConstructorDecl *CD, StringRef label) { + printCommonAFD(CD, "constructor_decl", label); + printFlag(CD->isRequired(), "required", DeclModifierColor); + printFlag(getDumpString(CD->getInitKind()), DeclModifierColor); if (CD->isFailable()) - PrintWithColorRAII(OS, DeclModifierColor) << " failable=" - << (CD->isImplicitlyUnwrappedOptional() - ? "ImplicitlyUnwrappedOptional" - : "Optional"); + printField((CD->isImplicitlyUnwrappedOptional() + ? "ImplicitlyUnwrappedOptional" + : "Optional"), "failable", DeclModifierColor); printAbstractFunctionDecl(CD); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitDestructorDecl(DestructorDecl *DD) { - printCommonAFD(DD, "destructor_decl"); + void visitDestructorDecl(DestructorDecl *DD, StringRef label) { + printCommonAFD(DD, "destructor_decl", label); printAbstractFunctionDecl(DD); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitTopLevelCodeDecl(TopLevelCodeDecl *TLCD) { - printCommon(TLCD, "top_level_code_decl"); + void visitTopLevelCodeDecl(TopLevelCodeDecl *TLCD, StringRef label) { + printCommon(TLCD, "top_level_code_decl", label); if (TLCD->getBody()) { - OS << "\n"; - printRec(TLCD->getBody(), static_cast(TLCD)->getASTContext()); + printRec(TLCD->getBody(), &static_cast(TLCD)->getASTContext()); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - - void printASTNodes(const ArrayRef &Elements, const ASTContext &Ctx, StringRef Name) { - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << "("; - PrintWithColorRAII(OS, ASTNodeColor) << Name; - for (auto Elt : Elements) { - OS << '\n'; - if (auto *SubExpr = Elt.dyn_cast()) - printRec(SubExpr); - else if (auto *SubStmt = Elt.dyn_cast()) - printRec(SubStmt, Ctx); - else - printRec(Elt.get()); - } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitIfConfigDecl(IfConfigDecl *ICD) { - printCommon(ICD, "if_config_decl"); - Indent += 2; - for (auto &Clause : ICD->getClauses()) { - OS << '\n'; - OS.indent(Indent); - PrintWithColorRAII(OS, StmtColor) << (Clause.Cond ? "#if:" : "#else:"); - if (Clause.isActive) - PrintWithColorRAII(OS, DeclModifierColor) << " active"; - if (Clause.Cond) { - OS << "\n"; - printRec(Clause.Cond); - } - - OS << '\n'; - Indent += 2; - printASTNodes(Clause.Elements, ICD->getASTContext(), "elements"); - Indent -= 2; - } - - Indent -= 2; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitIfConfigDecl(IfConfigDecl *ICD, StringRef label) { + printCommon(ICD, "if_config_decl", label); + printRecRange(ICD->getClauses(), &ICD->getASTContext(), "clauses"); + printFoot(); } - void visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD) { - printCommon(PDD, "pound_diagnostic_decl"); - auto kind = PDD->isError() ? "error" : "warning"; - OS << " kind=" << kind << "\n"; - Indent += 2; + void visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD, StringRef label) { + printCommon(PDD, "pound_diagnostic_decl", label); + printField(PDD->isError() ? "error" : "warning", "kind"); printRec(PDD->getMessage()); - Indent -= 2; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitPrecedenceGroupDecl(PrecedenceGroupDecl *PGD) { - printCommon(PGD, "precedence_group_decl "); - OS << PGD->getName() << "\n"; + void visitPrecedenceGroupDecl(PrecedenceGroupDecl *PGD, StringRef label) { + printCommon(PGD, "precedence_group_decl", label); + printName(PGD->getName()); + printField(PGD->getAssociativity(), "associativity"); + printField(PGD->isAssignment(), "assignment"); - OS.indent(Indent+2); - OS << "associativity " - << getAssociativityString(PGD->getAssociativity()) << "\n"; - - OS.indent(Indent+2); - OS << "assignment " << (PGD->isAssignment() ? "true" : "false"); - - auto printRelations = - [&](StringRef label, ArrayRef rels) { + auto printRelationsRec = + [&](ArrayRef rels, StringRef name) { if (rels.empty()) return; - OS << '\n'; - OS.indent(Indent+2); - OS << label << ' ' << rels[0].Name; - for (auto &rel : rels.slice(1)) - OS << ", " << rel.Name; + printRecArbitrary([&](StringRef label) { + printHead(name, FieldLabelColor, label); + for (auto &rel : rels) + printFlag(rel.Name.str()); + printFoot(); + }); }; - printRelations("higherThan", PGD->getHigherThan()); - printRelations("lowerThan", PGD->getLowerThan()); + printRelationsRec(PGD->getHigherThan(), "higherThan"); + printRelationsRec(PGD->getLowerThan(), "lowerThan"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitInfixOperatorDecl(InfixOperatorDecl *IOD) { - printCommon(IOD, "infix_operator_decl"); - OS << " " << IOD->getName(); + void visitInfixOperatorDecl(InfixOperatorDecl *IOD, StringRef label) { + printCommon(IOD, "infix_operator_decl", label); + printName(IOD->getName()); if (!IOD->getPrecedenceGroupName().empty()) - OS << " precedence_group_name=" << IOD->getPrecedenceGroupName(); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFieldQuoted(IOD->getPrecedenceGroupName(), + "precedence_group_name"); + printFoot(); } - void visitPrefixOperatorDecl(PrefixOperatorDecl *POD) { - printCommon(POD, "prefix_operator_decl"); - OS << " " << POD->getName(); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitPrefixOperatorDecl(PrefixOperatorDecl *POD, StringRef label) { + printCommon(POD, "prefix_operator_decl", label); + printName(POD->getName()); + printFoot(); } - void visitPostfixOperatorDecl(PostfixOperatorDecl *POD) { - printCommon(POD, "postfix_operator_decl"); - OS << " " << POD->getName(); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitPostfixOperatorDecl(PostfixOperatorDecl *POD, StringRef label) { + printCommon(POD, "postfix_operator_decl", label); + printName(POD->getName()); + printFoot(); } - void visitModuleDecl(ModuleDecl *MD) { - printCommon(MD, "module"); - - if (MD->isNonSwiftModule()) - OS << " non_swift"; - - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitModuleDecl(ModuleDecl *MD, StringRef label) { + printCommon(MD, "module", label); + printFlag(MD->isNonSwiftModule(), "non_swift"); + printFoot(); } - void visitMissingDecl(MissingDecl *missing) { - printCommon(missing, "missing_decl"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitMissingDecl(MissingDecl *missing, StringRef label) { + printCommon(missing, "missing_decl", label); + printFoot(); } - void visitMissingMemberDecl(MissingMemberDecl *MMD) { - printCommon(MMD, "missing_member_decl "); - PrintWithColorRAII(OS, IdentifierColor) - << '\"' << MMD->getName() << '\"'; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitMissingMemberDecl(MissingMemberDecl *MMD, StringRef label) { + printCommon(MMD, "missing_member_decl ", label); + printName(MMD->getName()); + printFoot(); } - void visitMacroDecl(MacroDecl *MD) { - printCommon(MD, "macro_decl"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitMacroDecl(MacroDecl *MD, StringRef label) { + printCommon(MD, "macro_decl", label); + // TODO: Fill this in? + printFoot(); } - void visitMacroExpansionDecl(MacroExpansionDecl *MED) { - printCommon(MED, "macro_expansion_decl "); - OS << MED->getMacroName(); - OS << '\n'; - printArgumentList(OS, MED->getArgs(), Indent, - [&](Expr *E) { printRec(E); }); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitMacroExpansionDecl(MacroExpansionDecl *MED, StringRef label) { + printCommon(MED, "macro_expansion_decl", label); + printName(MED->getMacroName().getFullName()); + printRec(MED->getArgs()); + printFoot(); } }; } // end anonymous namespace void ParameterList::dump() const { dump(llvm::errs(), 0); + llvm::errs() << '\n'; } void ParameterList::dump(raw_ostream &OS, unsigned Indent) const { - PrintDecl(OS, Indent).printParameterList(this); - llvm::errs() << '\n'; + PrintDecl(OS, Indent) + .visitParameterList(const_cast(this), ""); } void Decl::dump() const { @@ -1330,7 +1644,7 @@ void Decl::dump(const char *filename) const { } void Decl::dump(raw_ostream &OS, unsigned Indent) const { - PrintDecl(OS, Indent).visit(const_cast(this)); + PrintDecl(OS, Indent).visit(const_cast(this), ""); OS << '\n'; } @@ -1482,7 +1796,7 @@ void Pattern::dump() const { } void Pattern::dump(raw_ostream &OS, unsigned Indent) const { - PrintPattern(OS, Indent).visit(const_cast(this)); + PrintPattern(OS, Indent).visit(const_cast(this), ""); OS << '\n'; } @@ -1492,335 +1806,207 @@ void Pattern::dump(raw_ostream &OS, unsigned Indent) const { namespace { /// PrintStmt - Visitor implementation of Stmt::dump. -class PrintStmt : public StmtVisitor { +class PrintStmt : public StmtVisitor, + public PrintBase { public: - raw_ostream &OS; + using PrintBase::PrintBase; const ASTContext *Ctx; - unsigned Indent; - PrintStmt(raw_ostream &os, const ASTContext *ctx, unsigned indent) - : OS(os), Ctx(ctx), Indent(indent) { + PrintStmt(raw_ostream &os, const ASTContext *ctx, unsigned indent = 0, + llvm::function_ref getTypeOfExpr = defaultGetTypeOfExpr, + llvm::function_ref getTypeOfTypeRepr = nullptr, + llvm::function_ref + getTypeOfKeyPathComponent = defaultGetTypeOfKeyPathComponent) + : PrintBase(os, indent, getTypeOfExpr, getTypeOfTypeRepr, + getTypeOfKeyPathComponent), Ctx(ctx) { } + + using PrintBase::printRec; + + void printRec(Stmt *S, StringRef Label = "") { + PrintBase::printRec(S, Ctx, Label); } - void printRec(Stmt *S) { - Indent += 2; - if (S) - visit(S); - else - OS.indent(Indent) << "(**NULL STATEMENT**)"; - Indent -= 2; + void printCommon(Stmt *S, const char *Name, StringRef Label) { + printHead(Name, StmtColor, Label); + + printFlag(S->isImplicit(), "implicit"); + printSourceRange(S->getSourceRange(), Ctx); + printFlag(S->TrailingSemiLoc.isValid(), "trailing_semi"); } - void printRec(Decl *D) { D->dump(OS, Indent + 2); } - void printRec(Expr *E) { E->dump(OS, Indent + 2); } - void printRec(const Pattern *P) { - PrintPattern(OS, Indent+2).visit(const_cast(P)); + void visitBraceStmt(BraceStmt *S, StringRef label) { + printCommon(S, "brace_stmt", label); + for (auto &Elt : S->getElements()) + printRec(Elt, Ctx); + printFoot(); } - void printRec(StmtConditionElement C) { - switch (C.getKind()) { - case StmtConditionElement::CK_Boolean: - return printRec(C.getBoolean()); - case StmtConditionElement::CK_PatternBinding: - Indent += 2; - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, PatternColor) << "pattern\n"; - - printRec(C.getPattern()); - OS << "\n"; - printRec(C.getInitializer()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - Indent -= 2; - break; - case StmtConditionElement::CK_Availability: - Indent += 2; - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - OS << "#available\n"; - for (auto *Query : C.getAvailability()->getQueries()) { - OS << '\n'; - switch (Query->getKind()) { - case AvailabilitySpecKind::PlatformVersionConstraint: - cast(Query)->print(OS, Indent + 2); - break; - case AvailabilitySpecKind::LanguageVersionConstraint: - case AvailabilitySpecKind::PackageDescriptionVersionConstraint: - cast(Query)->print(OS, Indent + 2); - break; - case AvailabilitySpecKind::OtherPlatform: - cast(Query)->print(OS, Indent + 2); - break; - } - } - PrintWithColorRAII(OS, ParenthesisColor) << ")"; - Indent -= 2; - break; - case StmtConditionElement::CK_HasSymbol: - Indent += 2; - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - OS << "#_hasSymbol"; - if (Ctx) - printSourceRange(OS, C.getSourceRange(), *Ctx); - OS << "\n"; - printRec(C.getHasSymbolInfo()->getSymbolExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ")"; - Indent -= 2; - break; - } - } - - raw_ostream &printCommon(Stmt *S, const char *Name) { - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, StmtColor) << Name; - - if (S->isImplicit()) - OS << " implicit"; - - if (Ctx) - printSourceRange(OS, S->getSourceRange(), *Ctx); - - if (S->TrailingSemiLoc.isValid()) - OS << " trailing_semi"; - - return OS; - } - - void visitBraceStmt(BraceStmt *S) { - printCommon(S, "brace_stmt"); - printASTNodes(S->getElements()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - - void printASTNodes(const ArrayRef &Elements) { - for (auto Elt : Elements) { - OS << '\n'; - if (auto *SubExpr = Elt.dyn_cast()) - printRec(SubExpr); - else if (auto *SubStmt = Elt.dyn_cast()) - printRec(SubStmt); - else - printRec(Elt.get()); - } - } - - void visitReturnStmt(ReturnStmt *S) { - printCommon(S, "return_stmt"); + void visitReturnStmt(ReturnStmt *S, StringRef label) { + printCommon(S, "return_stmt", label); if (S->hasResult()) { - OS << '\n'; printRec(S->getResult()); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitYieldStmt(YieldStmt *S) { - printCommon(S, "yield_stmt"); + void visitYieldStmt(YieldStmt *S, StringRef label) { + printCommon(S, "yield_stmt", label); for (auto yield : S->getYields()) { - OS << '\n'; printRec(yield); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitThenStmt(ThenStmt *S) { - printCommon(S, "then_stmt"); - OS << '\n'; + void visitThenStmt(ThenStmt *S, StringRef label) { + printCommon(S, "then_stmt", label); printRec(S->getResult()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitDeferStmt(DeferStmt *S) { - printCommon(S, "defer_stmt") << '\n'; + void visitDeferStmt(DeferStmt *S, StringRef label) { + printCommon(S, "defer_stmt", label); printRec(S->getTempDecl()); - OS << '\n'; printRec(S->getCallExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitIfStmt(IfStmt *S) { - printCommon(S, "if_stmt") << '\n'; - for (auto elt : S->getCond()) { - printRec(elt); - OS << "\n"; - } + void visitIfStmt(IfStmt *S, StringRef label) { + printCommon(S, "if_stmt", label); + printRecRange(S->getCond(), Ctx, "conditions"); printRec(S->getThenStmt()); if (S->getElseStmt()) { - OS << '\n'; printRec(S->getElseStmt()); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitGuardStmt(GuardStmt *S) { - printCommon(S, "guard_stmt") << '\n'; - for (auto elt : S->getCond()) - printRec(elt); - OS << '\n'; + void visitGuardStmt(GuardStmt *S, StringRef label) { + printCommon(S, "guard_stmt", label); + printRecRange(S->getCond(), Ctx, "conditions"); printRec(S->getBody()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitDoStmt(DoStmt *S) { - printCommon(S, "do_stmt") << '\n'; + void visitDoStmt(DoStmt *S, StringRef label) { + printCommon(S, "do_stmt", label); printRec(S->getBody()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitWhileStmt(WhileStmt *S) { - printCommon(S, "while_stmt") << '\n'; - for (auto elt : S->getCond()) - printRec(elt); - OS << '\n'; + void visitWhileStmt(WhileStmt *S, StringRef label) { + printCommon(S, "while_stmt", label); + printRecRange(S->getCond(), Ctx, "conditions"); printRec(S->getBody()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitRepeatWhileStmt(RepeatWhileStmt *S) { - printCommon(S, "repeat_while_stmt") << '\n'; + void visitRepeatWhileStmt(RepeatWhileStmt *S, StringRef label) { + printCommon(S, "repeat_while_stmt", label); printRec(S->getBody()); - OS << '\n'; printRec(S->getCond()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitForEachStmt(ForEachStmt *S) { - printCommon(S, "for_each_stmt"); - OS << '\n'; + void visitForEachStmt(ForEachStmt *S, StringRef label) { + printCommon(S, "for_each_stmt", label); printRec(S->getPattern()); - OS << '\n'; if (S->getWhere()) { - Indent += 2; - OS.indent(Indent) << "(where\n"; - printRec(S->getWhere()); - OS << ")\n"; - Indent -= 2; + printRec(S->getWhere(), "where"); } printRec(S->getParsedSequence()); - OS << '\n'; if (S->getIteratorVar()) { printRec(S->getIteratorVar()); - OS << '\n'; } if (S->getNextCall()) { printRec(S->getNextCall()); - OS << '\n'; } if (S->getConvertElementExpr()) { printRec(S->getConvertElementExpr()); - OS << '\n'; } if (S->getElementExpr()) { printRec(S->getElementExpr()); - OS << '\n'; } printRec(S->getBody()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitBreakStmt(BreakStmt *S) { - printCommon(S, "break_stmt"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitBreakStmt(BreakStmt *S, StringRef label) { + printCommon(S, "break_stmt", label); + printFoot(); } - void visitContinueStmt(ContinueStmt *S) { - printCommon(S, "continue_stmt"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitContinueStmt(ContinueStmt *S, StringRef label) { + printCommon(S, "continue_stmt", label); + printFoot(); } - void visitFallthroughStmt(FallthroughStmt *S) { - printCommon(S, "fallthrough_stmt"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitFallthroughStmt(FallthroughStmt *S, StringRef label) { + printCommon(S, "fallthrough_stmt", label); + printFoot(); } - void visitSwitchStmt(SwitchStmt *S) { - printCommon(S, "switch_stmt") << '\n'; + void visitSwitchStmt(SwitchStmt *S, StringRef label) { + printCommon(S, "switch_stmt", label); printRec(S->getSubjectExpr()); for (auto N : S->getRawCases()) { - OS << '\n'; if (N.is()) printRec(N.get()); else printRec(N.get()); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitCaseStmt(CaseStmt *S) { - printCommon(S, "case_stmt"); - if (S->hasUnknownAttr()) - OS << " @unknown"; + void visitCaseStmt(CaseStmt *S, StringRef label) { + printCommon(S, "case_stmt", label); + printFlag(S->hasUnknownAttr(), "@unknown"); if (S->hasCaseBodyVariables()) { - OS << '\n'; - OS.indent(Indent + 2); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, StmtColor) << "case_body_variables"; - OS << '\n'; - for (auto *vd : S->getCaseBodyVariables()) { - OS.indent(2); - // TODO: Printing a var decl does an Indent ... dump(vd) ... '\n'. We - // should see if we can factor this dumping so that the caller of - // printRec(VarDecl) has more control over the printing. - printRec(vd); - } - OS.indent(Indent + 2); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRecRange(S->getCaseBodyVariables(), "case_body_variables"); } for (const auto &LabelItem : S->getCaseLabelItems()) { - OS << '\n'; - OS.indent(Indent + 2); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, StmtColor) << "case_label_item"; - if (LabelItem.isDefault()) - OS << " default"; - if (auto *CasePattern = LabelItem.getPattern()) { - OS << '\n'; - printRec(CasePattern); - } - if (auto *Guard = LabelItem.getGuardExpr()) { - OS << '\n'; - Guard->dump(OS, Indent+4); - } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRecArbitrary([&](StringRef label) { + printHead("case_label_item", StmtColor, label); + printFlag(LabelItem.isDefault(), "default"); + + if (auto *CasePattern = LabelItem.getPattern()) { + printRec(CasePattern); + } + if (auto *Guard = LabelItem.getGuardExpr()) { + printRec(const_cast(Guard)); + } + + printFoot(); + }); } - OS << '\n'; + printRec(S->getBody()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitFailStmt(FailStmt *S) { - printCommon(S, "fail_stmt"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitFailStmt(FailStmt *S, StringRef label) { + printCommon(S, "fail_stmt", label); + printFoot(); } - void visitThrowStmt(ThrowStmt *S) { - printCommon(S, "throw_stmt") << '\n'; + void visitThrowStmt(ThrowStmt *S, StringRef label) { + printCommon(S, "throw_stmt", label); printRec(S->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitDiscardStmt(DiscardStmt *S) { - printCommon(S, "discard_stmt") << '\n'; + void visitDiscardStmt(DiscardStmt *S, StringRef label) { + printCommon(S, "discard_stmt", label); printRec(S->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitPoundAssertStmt(PoundAssertStmt *S) { - printCommon(S, "pound_assert"); - OS << " message=" << QuotedString(S->getMessage()) << "\n"; + void visitPoundAssertStmt(PoundAssertStmt *S, StringRef label) { + printCommon(S, "pound_assert", label); + printFieldQuoted(S->getMessage(), "message"); printRec(S->getCondition()); - OS << ")"; + printFoot(); } - void visitDoCatchStmt(DoCatchStmt *S) { - printCommon(S, "do_catch_stmt") << '\n'; - printRec(S->getBody()); - OS << '\n'; - Indent += 2; - visitCatches(S->getCatches()); - Indent -= 2; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitCatches(ArrayRef clauses) { - for (auto clause : clauses) { - visitCaseStmt(clause); - } + void visitDoCatchStmt(DoCatchStmt *S, StringRef label) { + printCommon(S, "do_catch_stmt", label); + printRec(S->getBody(), "body"); + printRecRange(S->getCatches(), Ctx, "catch_stmts"); + printFoot(); } }; @@ -1832,7 +2018,7 @@ void Stmt::dump() const { } void Stmt::dump(raw_ostream &OS, const ASTContext *Ctx, unsigned Indent) const { - PrintStmt(OS, Ctx, Indent).visit(const_cast(this)); + PrintStmt(OS, Ctx, Indent).visit(const_cast(this), ""); } //===----------------------------------------------------------------------===// @@ -1841,89 +2027,30 @@ void Stmt::dump(raw_ostream &OS, const ASTContext *Ctx, unsigned Indent) const { namespace { /// PrintExpr - Visitor implementation of Expr::dump. -class PrintExpr : public ExprVisitor { +class PrintExpr : public ExprVisitor, + public PrintBase { public: - raw_ostream &OS; - llvm::function_ref GetTypeOfExpr; - llvm::function_ref GetTypeOfTypeRepr; - llvm::function_ref - GetTypeOfKeyPathComponent; - unsigned Indent; - - PrintExpr(raw_ostream &os, llvm::function_ref getTypeOfExpr, - llvm::function_ref getTypeOfTypeRepr, - llvm::function_ref - getTypeOfKeyPathComponent, - unsigned indent) - : OS(os), GetTypeOfExpr(getTypeOfExpr), - GetTypeOfTypeRepr(getTypeOfTypeRepr), - GetTypeOfKeyPathComponent(getTypeOfKeyPathComponent), Indent(indent) {} - - void printRec(Expr *E) { - Indent += 2; - if (E) - visit(E); - else - OS.indent(Indent) << "(**NULL EXPRESSION**)"; - Indent -= 2; - } - - void printRecLabeled(Expr *E, StringRef label) { - Indent += 2; - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, ExprColor) << label; - OS << '\n'; - printRec(E); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - Indent -= 2; - } + using PrintBase::PrintBase; /// FIXME: This should use ExprWalker to print children. - void printRec(Decl *D) { D->dump(OS, Indent + 2); } - void printRec(Stmt *S, const ASTContext &Ctx) { S->dump(OS, &Ctx, Indent + 2); } - void printRec(const Pattern *P) { - PrintPattern(OS, Indent+2).visit(const_cast(P)); - } - void printRec(TypeRepr *T); - void printRec(ProtocolConformanceRef conf) { - conf.dump(OS, Indent + 2); - } - - void printDeclRef(ConcreteDeclRef declRef) { - declRef.dump(PrintWithColorRAII(OS, DeclColor).getOS()); - } - - raw_ostream &printCommon(Expr *E, const char *C) { + void printCommon(Expr *E, const char *C, StringRef label) { PrintOptions PO; PO.PrintTypesForDebugging = true; - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, ExprColor) << C; + printHead(C, ExprColor, label); - if (E->isImplicit()) - PrintWithColorRAII(OS, ExprModifierColor) << " implicit"; - PrintWithColorRAII(OS, TypeColor) << " type='"; - PrintWithColorRAII(OS, TypeColor) << GetTypeOfExpr(E).getString(PO) << '\''; + printFlag(E->isImplicit(), "implicit", ExprModifierColor); + printFieldQuoted(GetTypeOfExpr(E).getString(PO), "type", TypeColor); // If we have a source range and an ASTContext, print the source range. if (auto Ty = GetTypeOfExpr(E)) { auto &Ctx = Ty->getASTContext(); - auto L = E->getLoc(); - if (L.isValid()) { - PrintWithColorRAII(OS, LocationColor) << " location="; - L.print(PrintWithColorRAII(OS, LocationColor).getOS(), Ctx.SourceMgr); - } - - printSourceRange(OS, E->getSourceRange(), Ctx); + printSourceLoc(E->getLoc(), &Ctx); + printSourceRange(E->getSourceRange(), &Ctx); } - if (E->TrailingSemiLoc.isValid()) - OS << " trailing_semi"; - - return OS; + printFlag(E->TrailingSemiLoc.isValid(), "trailing_semi"); } void printSemanticExpr(Expr * semanticExpr) { @@ -1931,1153 +2058,1055 @@ public: return; } - OS << '\n'; - printRecLabeled(semanticExpr, "semantic_expr"); + printRec(semanticExpr, "semantic_expr"); } - void visitErrorExpr(ErrorExpr *E) { - printCommon(E, "error_expr"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitErrorExpr(ErrorExpr *E, StringRef label) { + printCommon(E, "error_expr", label); + printFoot(); } - void visitCodeCompletionExpr(CodeCompletionExpr *E) { - printCommon(E, "code_completion_expr"); + void visitCodeCompletionExpr(CodeCompletionExpr *E, StringRef label) { + printCommon(E, "code_completion_expr", label); if (E->getBase()) { - OS << '\n'; printRec(E->getBase()); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitNilLiteralExpr(NilLiteralExpr *E) { - printCommon(E, "nil_literal_expr"); - PrintWithColorRAII(OS, LiteralValueColor) << " initializer="; - E->getInitializer().dump(PrintWithColorRAII(OS, LiteralValueColor).getOS()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void printInitializerField(ConcreteDeclRef declRef, StringRef label) { + printFieldQuotedRaw([&](raw_ostream &OS) { declRef.dump(OS); }, label, + ExprModifierColor); } - void visitIntegerLiteralExpr(IntegerLiteralExpr *E) { - printCommon(E, "integer_literal_expr"); - if (E->isNegative()) - PrintWithColorRAII(OS, LiteralValueColor) << " negative"; - PrintWithColorRAII(OS, LiteralValueColor) << " value="; + void visitNilLiteralExpr(NilLiteralExpr *E, StringRef label) { + printCommon(E, "nil_literal_expr", label); + printInitializerField(E->getInitializer(), "initializer"); + printFoot(); + } + + void visitIntegerLiteralExpr(IntegerLiteralExpr *E, StringRef label) { + printCommon(E, "integer_literal_expr", label); + + printFlag(E->isNegative(), "negative", LiteralValueColor); Type T = GetTypeOfExpr(E); if (T.isNull() || !T->is()) - PrintWithColorRAII(OS, LiteralValueColor) << E->getDigitsText(); + printFieldQuoted(E->getDigitsText(), "value", LiteralValueColor); else - PrintWithColorRAII(OS, LiteralValueColor) << E->getValue(); - PrintWithColorRAII(OS, LiteralValueColor) << " builtin_initializer="; - E->getBuiltinInitializer().dump( - PrintWithColorRAII(OS, LiteralValueColor).getOS()); - PrintWithColorRAII(OS, LiteralValueColor) << " initializer="; - E->getInitializer().dump(PrintWithColorRAII(OS, LiteralValueColor).getOS()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitFloatLiteralExpr(FloatLiteralExpr *E) { - printCommon(E, "float_literal_expr"); - if (E->isNegative()) - PrintWithColorRAII(OS, LiteralValueColor) << " negative"; - PrintWithColorRAII(OS, LiteralValueColor) - << " value=" << E->getDigitsText(); - PrintWithColorRAII(OS, LiteralValueColor) << " builtin_initializer="; - E->getBuiltinInitializer().dump( - PrintWithColorRAII(OS, LiteralValueColor).getOS()); - PrintWithColorRAII(OS, LiteralValueColor) << " initializer="; - E->getInitializer().dump(PrintWithColorRAII(OS, LiteralValueColor).getOS()); - if (!E->getBuiltinType().isNull()) { - PrintWithColorRAII(OS, TypeColor) << " builtin_type='"; - E->getBuiltinType().print(PrintWithColorRAII(OS, TypeColor).getOS()); - PrintWithColorRAII(OS, TypeColor) << "'"; - } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } + printFieldQuoted(E->getValue(), "value", LiteralValueColor); + printInitializerField(E->getBuiltinInitializer(), "builtin_initializer"); + printInitializerField(E->getInitializer(), "initializer"); - void visitBooleanLiteralExpr(BooleanLiteralExpr *E) { - printCommon(E, "boolean_literal_expr"); - PrintWithColorRAII(OS, LiteralValueColor) - << " value=" << (E->getValue() ? "true" : "false") - << " builtin_initializer="; - E->getBuiltinInitializer().dump( - PrintWithColorRAII(OS, LiteralValueColor).getOS()); - PrintWithColorRAII(OS, LiteralValueColor) << " initializer="; - E->getInitializer().dump(PrintWithColorRAII(OS, LiteralValueColor).getOS()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - - void visitStringLiteralExpr(StringLiteralExpr *E) { - printCommon(E, "string_literal_expr"); - PrintWithColorRAII(OS, LiteralValueColor) << " encoding=" - << getStringLiteralExprEncodingString(E->getEncoding()) - << " value=" << QuotedString(E->getValue()) - << " builtin_initializer="; - E->getBuiltinInitializer().dump( - PrintWithColorRAII(OS, LiteralValueColor).getOS()); - PrintWithColorRAII(OS, LiteralValueColor) << " initializer="; - E->getInitializer().dump(PrintWithColorRAII(OS, LiteralValueColor).getOS()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitInterpolatedStringLiteralExpr(InterpolatedStringLiteralExpr *E) { - printCommon(E, "interpolated_string_literal_expr"); + void visitFloatLiteralExpr(FloatLiteralExpr *E, StringRef label) { + printCommon(E, "float_literal_expr", label); + printFlag(E->isNegative(), "negative", LiteralValueColor); + printFieldQuoted(E->getDigitsText(), "value", LiteralValueColor); + printInitializerField(E->getBuiltinInitializer(), "builtin_initializer"); + printInitializerField(E->getInitializer(), "initializer"); + if (!E->getBuiltinType().isNull()) { + printFieldQuoted(E->getBuiltinType(), "builtin_type", ExprModifierColor); + } + + printFoot(); + } + + void visitBooleanLiteralExpr(BooleanLiteralExpr *E, StringRef label) { + printCommon(E, "boolean_literal_expr", label); + + printField(E->getValue(), "value", LiteralValueColor); + printInitializerField(E->getBuiltinInitializer(), "builtin_initializer"); + printInitializerField(E->getInitializer(), "initializer"); + + printFoot(); + } + + void visitStringLiteralExpr(StringLiteralExpr *E, StringRef label) { + printCommon(E, "string_literal_expr", label); + + printField(E->getEncoding(), "encoding", ExprModifierColor); + printFieldQuoted(E->getValue(), "value", LiteralValueColor); + printInitializerField(E->getBuiltinInitializer(), "builtin_initializer"); + printInitializerField(E->getInitializer(), "initializer"); + + printFoot(); + } + void visitInterpolatedStringLiteralExpr(InterpolatedStringLiteralExpr *E, StringRef label) { + printCommon(E, "interpolated_string_literal_expr", label); + // Print the trailing quote location if (auto Ty = GetTypeOfExpr(E)) { auto &Ctx = Ty->getASTContext(); - auto TQL = E->getTrailingQuoteLoc(); - if (TQL.isValid()) { - PrintWithColorRAII(OS, LocationColor) << " trailing_quote_loc="; - TQL.print(PrintWithColorRAII(OS, LocationColor).getOS(), - Ctx.SourceMgr); - } + printSourceLoc(E->getTrailingQuoteLoc(), &Ctx, "trailing_quote_loc"); } - PrintWithColorRAII(OS, LiteralValueColor) - << " literal_capacity=" - << E->getLiteralCapacity() << " interpolation_count=" - << E->getInterpolationCount(); - PrintWithColorRAII(OS, LiteralValueColor) << " builder_init="; - E->getBuilderInit().dump(PrintWithColorRAII(OS, LiteralValueColor).getOS()); - PrintWithColorRAII(OS, LiteralValueColor) << " result_init="; - E->getInitializer().dump(PrintWithColorRAII(OS, LiteralValueColor).getOS()); - OS << "\n"; + printField(E->getLiteralCapacity(), "literal_capacity", ExprModifierColor); + printField(E->getInterpolationCount(), "interpolation_count", + ExprModifierColor); + printInitializerField(E->getBuilderInit(), "builder_init"); + printInitializerField(E->getInitializer(), "result_init"); + printRec(E->getAppendingExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitMagicIdentifierLiteralExpr(MagicIdentifierLiteralExpr *E) { - printCommon(E, "magic_identifier_literal_expr") - << " kind=" << MagicIdentifierLiteralExpr::getKindString(E->getKind()); + void visitMagicIdentifierLiteralExpr(MagicIdentifierLiteralExpr *E, StringRef label) { + printCommon(E, "magic_identifier_literal_expr", label); + + printField(E->getKind(), "kind", ExprModifierColor); if (E->isString()) { - OS << " encoding=" - << getStringLiteralExprEncodingString(E->getStringEncoding()); + printField(E->getStringEncoding(), "encoding", ExprModifierColor); } - OS << " builtin_initializer="; - E->getBuiltinInitializer().dump(OS); - OS << " initializer="; - E->getInitializer().dump(OS); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printInitializerField(E->getBuiltinInitializer(), "builtin_initializer"); + printInitializerField(E->getInitializer(), "initializer"); + + printFoot(); } - void visitRegexLiteralExpr(RegexLiteralExpr *E) { - printCommon(E, "regex_literal_expr"); - PrintWithColorRAII(OS, LiteralValueColor) - << " text=" << QuotedString(E->getRegexText()) - << " initializer="; - E->getInitializer().dump(PrintWithColorRAII(OS, LiteralValueColor).getOS()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitRegexLiteralExpr(RegexLiteralExpr *E, StringRef label) { + printCommon(E, "regex_literal_expr", label); + + printFieldQuoted(E->getRegexText(), "text", LiteralValueColor); + printInitializerField(E->getInitializer(), "initializer"); + + printFoot(); } - void visitObjectLiteralExpr(ObjectLiteralExpr *E) { - printCommon(E, "object_literal") - << " kind='" << E->getLiteralKindPlainName() << "'"; - PrintWithColorRAII(OS, LiteralValueColor) << " initializer="; - E->getInitializer().dump(PrintWithColorRAII(OS, LiteralValueColor).getOS()); - OS << "\n"; - printArgumentList(E->getArgs()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitObjectLiteralExpr(ObjectLiteralExpr *E, StringRef label) { + printCommon(E, "object_literal", label); + + printField(E->getLiteralKind(), "kind"); + printInitializerField(E->getInitializer(), "initializer"); + + printRec(E->getArgs()); + + printFoot(); } - void visitDiscardAssignmentExpr(DiscardAssignmentExpr *E) { - printCommon(E, "discard_assignment_expr"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitDiscardAssignmentExpr(DiscardAssignmentExpr *E, StringRef label) { + printCommon(E, "discard_assignment_expr", label); + printFoot(); } - void visitDeclRefExpr(DeclRefExpr *E) { - printCommon(E, "declref_expr"); - PrintWithColorRAII(OS, DeclColor) << " decl="; - printDeclRef(E->getDeclRef()); + void visitDeclRefExpr(DeclRefExpr *E, StringRef label) { + printCommon(E, "declref_expr", label); + + printDeclRefField(E->getDeclRef(), "decl"); if (E->getAccessSemantics() != AccessSemantics::Ordinary) - PrintWithColorRAII(OS, AccessLevelColor) - << " " << getAccessSemanticsString(E->getAccessSemantics()); - PrintWithColorRAII(OS, ExprModifierColor) - << " function_ref=" << getFunctionRefKindStr(E->getFunctionRefKind()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFlag(getDumpString(E->getAccessSemantics()), AccessLevelColor); + printField(E->getFunctionRefKind(), "function_ref", + ExprModifierColor); + + printFoot(); } - void visitSuperRefExpr(SuperRefExpr *E) { - printCommon(E, "super_ref_expr"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitSuperRefExpr(SuperRefExpr *E, StringRef label) { + printCommon(E, "super_ref_expr", label); + printFoot(); } - void visitTypeExpr(TypeExpr *E) { - printCommon(E, "type_expr"); - PrintWithColorRAII(OS, TypeReprColor) << " typerepr='"; + void visitTypeExpr(TypeExpr *E, StringRef label) { + printCommon(E, "type_expr", label); + if (E->getTypeRepr()) - E->getTypeRepr()->print(PrintWithColorRAII(OS, TypeReprColor).getOS()); + printFieldQuotedRaw([&](raw_ostream &OS) { E->getTypeRepr()->print(OS); }, + "typerepr", TypeReprColor); else - PrintWithColorRAII(OS, TypeReprColor) << "<>"; - PrintWithColorRAII(OS, TypeReprColor) << "'"; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFlag("null_typerepr"); + + printFoot(); } - void visitOtherConstructorDeclRefExpr(OtherConstructorDeclRefExpr *E) { - printCommon(E, "other_constructor_ref_expr"); - PrintWithColorRAII(OS, DeclColor) << " decl="; - printDeclRef(E->getDeclRef()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitOtherConstructorDeclRefExpr(OtherConstructorDeclRefExpr *E, StringRef label) { + printCommon(E, "other_constructor_ref_expr", label); + printDeclRefField(E->getDeclRef(), "decl"); + printFoot(); } - void visitOverloadedDeclRefExpr(OverloadedDeclRefExpr *E) { - printCommon(E, "overloaded_decl_ref_expr"); - PrintWithColorRAII(OS, IdentifierColor) << " name=" - << E->getDecls()[0]->getBaseName(); - PrintWithColorRAII(OS, ExprModifierColor) - << " number_of_decls=" << E->getDecls().size() - << " function_ref=" << getFunctionRefKindStr(E->getFunctionRefKind()); + void visitOverloadedDeclRefExpr(OverloadedDeclRefExpr *E, StringRef label) { + printCommon(E, "overloaded_decl_ref_expr", label); + + printFieldQuoted(E->getDecls()[0]->getBaseName(), "name", IdentifierColor); + printField(E->getDecls().size(), "number_of_decls", ExprModifierColor); + printField(E->getFunctionRefKind(), "function_ref", ExprModifierColor); + if (!E->isForOperator()) { - PrintWithColorRAII(OS, ExprModifierColor) << " decls=[\n"; - interleave( - E->getDecls(), - [&](ValueDecl *D) { - OS.indent(Indent + 2); - D->dumpRef(PrintWithColorRAII(OS, DeclModifierColor).getOS()); - }, - [&] { PrintWithColorRAII(OS, DeclModifierColor) << ",\n"; }); - PrintWithColorRAII(OS, ExprModifierColor) << "]"; + for (auto D : E->getDecls()) { + printRecArbitrary([&](StringRef label) { + printHead("candidate_decl", DeclModifierColor, label); + printNameRaw([&](raw_ostream &OS) { D->dumpRef(OS); }); + printFoot(); + }); + } } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *E) { - printCommon(E, "unresolved_decl_ref_expr"); - PrintWithColorRAII(OS, IdentifierColor) << " name=" << E->getName(); - PrintWithColorRAII(OS, ExprModifierColor) - << " function_ref=" << getFunctionRefKindStr(E->getFunctionRefKind()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *E, StringRef label) { + printCommon(E, "unresolved_decl_ref_expr", label); + + printFieldQuoted(E->getName(), "name", IdentifierColor); + printField(E->getFunctionRefKind(), "function_ref", ExprModifierColor); + + printFoot(); } - void visitUnresolvedSpecializeExpr(UnresolvedSpecializeExpr *E) { - printCommon(E, "unresolved_specialize_expr") << '\n'; + void visitUnresolvedSpecializeExpr(UnresolvedSpecializeExpr *E, StringRef label) { + printCommon(E, "unresolved_specialize_expr", label); + printRec(E->getSubExpr()); for (TypeLoc T : E->getUnresolvedParams()) { - OS << '\n'; printRec(T.getTypeRepr()); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitMemberRefExpr(MemberRefExpr *E) { - printCommon(E, "member_ref_expr"); - PrintWithColorRAII(OS, DeclColor) << " decl="; - printDeclRef(E->getMember()); + void visitMemberRefExpr(MemberRefExpr *E, StringRef label) { + printCommon(E, "member_ref_expr", label); + + printDeclRefField(E->getMember(), "decl"); if (E->getAccessSemantics() != AccessSemantics::Ordinary) - PrintWithColorRAII(OS, AccessLevelColor) - << " " << getAccessSemanticsString(E->getAccessSemantics()); - if (E->isSuper()) - OS << " super"; + printFlag(getDumpString(E->getAccessSemantics()), AccessLevelColor); + printFlag(E->isSuper(), "super"); - OS << '\n'; printRec(E->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitDynamicMemberRefExpr(DynamicMemberRefExpr *E) { - printCommon(E, "dynamic_member_ref_expr"); - PrintWithColorRAII(OS, DeclColor) << " decl="; - E->getMember().dump(OS); - OS << '\n'; + void visitDynamicMemberRefExpr(DynamicMemberRefExpr *E, StringRef label) { + printCommon(E, "dynamic_member_ref_expr", label); + + printDeclRefField(E->getMember(), "decl"); + printRec(E->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { - printCommon(E, "unresolved_member_expr") - << " name='" << E->getName() << "'"; - PrintWithColorRAII(OS, ExprModifierColor) - << " function_ref=" << getFunctionRefKindStr(E->getFunctionRefKind()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitUnresolvedMemberExpr(UnresolvedMemberExpr *E, StringRef label) { + printCommon(E, "unresolved_member_expr", label); + + printFieldQuoted(E->getName(), "name", ExprModifierColor); + printField(E->getFunctionRefKind(), "function_ref", ExprModifierColor); + printFoot(); } - void visitDotSelfExpr(DotSelfExpr *E) { - printCommon(E, "dot_self_expr"); - OS << '\n'; + void visitDotSelfExpr(DotSelfExpr *E, StringRef label) { + printCommon(E, "dot_self_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitParenExpr(ParenExpr *E) { - printCommon(E, "paren_expr"); - OS << '\n'; + void visitParenExpr(ParenExpr *E, StringRef label) { + printCommon(E, "paren_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitAwaitExpr(AwaitExpr *E) { - printCommon(E, "await_expr"); - OS << '\n'; + void visitAwaitExpr(AwaitExpr *E, StringRef label) { + printCommon(E, "await_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitConsumeExpr(ConsumeExpr *E) { - printCommon(E, "consume_expr"); - OS << '\n'; + void visitConsumeExpr(ConsumeExpr *E, StringRef label) { + printCommon(E, "consume_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitCopyExpr(CopyExpr *E) { - printCommon(E, "copy_expr"); - OS << '\n'; + void visitCopyExpr(CopyExpr *E, StringRef label) { + printCommon(E, "copy_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitBorrowExpr(BorrowExpr *E) { - printCommon(E, "borrow_expr"); - OS << '\n'; + void visitBorrowExpr(BorrowExpr *E, StringRef label) { + printCommon(E, "borrow_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitUnresolvedMemberChainResultExpr(UnresolvedMemberChainResultExpr *E){ - printCommon(E, "unresolved_member_chain_expr"); - OS << '\n'; + void visitUnresolvedMemberChainResultExpr(UnresolvedMemberChainResultExpr *E, StringRef label){ + printCommon(E, "unresolved_member_chain_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitTupleExpr(TupleExpr *E) { - printCommon(E, "tuple_expr"); + void visitTupleExpr(TupleExpr *E, StringRef label) { + printCommon(E, "tuple_expr", label); if (E->hasElementNames()) { - PrintWithColorRAII(OS, IdentifierColor) << " names="; - - interleave(E->getElementNames(), - [&](Identifier name) { - PrintWithColorRAII(OS, IdentifierColor) - << (name.empty()?"''":name.str()); - }, - [&] { PrintWithColorRAII(OS, IdentifierColor) << ","; }); + printFieldQuotedRaw([&](raw_ostream &OS) { + interleave(E->getElementNames(), OS, + [&](Identifier name) { + OS << (name.empty()?"''":name.str()); + }, + ","); + }, "names", IdentifierColor); } for (unsigned i = 0, e = E->getNumElements(); i != e; ++i) { - OS << '\n'; if (E->getElement(i)) printRec(E->getElement(i)); - else - OS.indent(Indent+2) << "<>"; + else { + printRecArbitrary([&](StringRef label) { + printHead("", ExprColor); + printFoot(); + }); + } } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitArrayExpr(ArrayExpr *E) { - printCommon(E, "array_expr"); - PrintWithColorRAII(OS, LiteralValueColor) << " initializer="; - E->getInitializer().dump(PrintWithColorRAII(OS, LiteralValueColor).getOS()); + void visitArrayExpr(ArrayExpr *E, StringRef label) { + printCommon(E, "array_expr", label); + + printInitializerField(E->getInitializer(), "initializer"); + for (auto elt : E->getElements()) { - OS << '\n'; printRec(elt); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitDictionaryExpr(DictionaryExpr *E) { - printCommon(E, "dictionary_expr"); - PrintWithColorRAII(OS, LiteralValueColor) << " initializer="; - E->getInitializer().dump(PrintWithColorRAII(OS, LiteralValueColor).getOS()); + void visitDictionaryExpr(DictionaryExpr *E, StringRef label) { + printCommon(E, "dictionary_expr", label); + + printInitializerField(E->getInitializer(), "initializer"); + for (auto elt : E->getElements()) { - OS << '\n'; printRec(elt); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitSubscriptExpr(SubscriptExpr *E) { - printCommon(E, "subscript_expr"); + void visitSubscriptExpr(SubscriptExpr *E, StringRef label) { + printCommon(E, "subscript_expr", label); + if (E->getAccessSemantics() != AccessSemantics::Ordinary) - PrintWithColorRAII(OS, AccessLevelColor) - << " " << getAccessSemanticsString(E->getAccessSemantics()); - if (E->isSuper()) - OS << " super"; + printFlag(getDumpString(E->getAccessSemantics()), AccessLevelColor); + printFlag(E->isSuper(), "super"); if (E->hasDecl()) { - PrintWithColorRAII(OS, DeclColor) << " decl="; - printDeclRef(E->getDecl()); + printDeclRefField(E->getDecl(), "decl"); } - OS << '\n'; + printRec(E->getBase()); - OS << '\n'; - printArgumentList(E->getArgs()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRec(E->getArgs()); + + printFoot(); } - void visitKeyPathApplicationExpr(KeyPathApplicationExpr *E) { - printCommon(E, "keypath_application_expr"); - OS << '\n'; + void visitKeyPathApplicationExpr(KeyPathApplicationExpr *E, StringRef label) { + printCommon(E, "keypath_application_expr", label); printRec(E->getBase()); - OS << '\n'; printRec(E->getKeyPath()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitDynamicSubscriptExpr(DynamicSubscriptExpr *E) { - printCommon(E, "dynamic_subscript_expr"); - PrintWithColorRAII(OS, DeclColor) << " decl="; - printDeclRef(E->getMember()); - OS << '\n'; + void visitDynamicSubscriptExpr(DynamicSubscriptExpr *E, StringRef label) { + printCommon(E, "dynamic_subscript_expr", label); + + printDeclRefField(E->getMember(), "decl"); + printRec(E->getBase()); - OS << '\n'; - printArgumentList(E->getArgs()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRec(E->getArgs()); + + printFoot(); } - void visitUnresolvedDotExpr(UnresolvedDotExpr *E) { - printCommon(E, "unresolved_dot_expr") - << " field '" << E->getName() << "'"; - PrintWithColorRAII(OS, ExprModifierColor) - << " function_ref=" << getFunctionRefKindStr(E->getFunctionRefKind()); + void visitUnresolvedDotExpr(UnresolvedDotExpr *E, StringRef label) { + printCommon(E, "unresolved_dot_expr", label); + + printFieldQuoted(E->getName(), "field"); + printField(E->getFunctionRefKind(), "function_ref", ExprModifierColor); + if (E->getBase()) { - OS << '\n'; printRec(E->getBase()); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitTupleElementExpr(TupleElementExpr *E) { - printCommon(E, "tuple_element_expr") - << " field #" << E->getFieldNumber() << '\n'; + void visitTupleElementExpr(TupleElementExpr *E, StringRef label) { + printCommon(E, "tuple_element_expr", label); + + printField(E->getFieldNumber(), "field #"); + printRec(E->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitDestructureTupleExpr(DestructureTupleExpr *E) { - printCommon(E, "destructure_tuple_expr"); - OS << " destructured="; - PrintWithColorRAII(OS, ParenthesisColor) << '('; - Indent += 2; - for (auto *elt : E->getDestructuredElements()) { - OS << "\n"; - printRec(elt); - } - Indent -= 2; - PrintWithColorRAII(OS, ParenthesisColor) << ")\n"; + void visitDestructureTupleExpr(DestructureTupleExpr *E, StringRef label) { + printCommon(E, "destructure_tuple_expr", label); + + printRecRange(E->getDestructuredElements(), "destructured"); printRec(E->getSubExpr()); - OS << "\n"; printRec(E->getResultExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitUnresolvedTypeConversionExpr(UnresolvedTypeConversionExpr *E) { - printCommon(E, "unresolvedtype_conversion_expr") << '\n'; + void visitUnresolvedTypeConversionExpr(UnresolvedTypeConversionExpr *E, StringRef label) { + printCommon(E, "unresolvedtype_conversion_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitFunctionConversionExpr(FunctionConversionExpr *E) { - printCommon(E, "function_conversion_expr") << '\n'; + void visitFunctionConversionExpr(FunctionConversionExpr *E, StringRef label) { + printCommon(E, "function_conversion_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitCovariantFunctionConversionExpr(CovariantFunctionConversionExpr *E){ - printCommon(E, "covariant_function_conversion_expr") << '\n'; + void visitCovariantFunctionConversionExpr(CovariantFunctionConversionExpr *E, StringRef label){ + printCommon(E, "covariant_function_conversion_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitCovariantReturnConversionExpr(CovariantReturnConversionExpr *E){ - printCommon(E, "covariant_return_conversion_expr") << '\n'; + void visitCovariantReturnConversionExpr(CovariantReturnConversionExpr *E, StringRef label){ + printCommon(E, "covariant_return_conversion_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitUnderlyingToOpaqueExpr(UnderlyingToOpaqueExpr *E){ - printCommon(E, "underlying_to_opaque_expr") << '\n'; + void visitUnderlyingToOpaqueExpr(UnderlyingToOpaqueExpr *E, StringRef label){ + printCommon(E, "underlying_to_opaque_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitErasureExpr(ErasureExpr *E) { - printCommon(E, "erasure_expr") << '\n'; + void visitErasureExpr(ErasureExpr *E, StringRef label) { + printCommon(E, "erasure_expr", label); for (auto conf : E->getConformances()) { printRec(conf); - OS << '\n'; } printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitAnyHashableErasureExpr(AnyHashableErasureExpr *E) { - printCommon(E, "any_hashable_erasure_expr") << '\n'; + void visitAnyHashableErasureExpr(AnyHashableErasureExpr *E, StringRef label) { + printCommon(E, "any_hashable_erasure_expr", label); printRec(E->getConformance()); - OS << '\n'; printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitConditionalBridgeFromObjCExpr(ConditionalBridgeFromObjCExpr *E) { - printCommon(E, "conditional_bridge_from_objc_expr") << " conversion="; - printDeclRef(E->getConversion()); - OS << '\n'; + void visitConditionalBridgeFromObjCExpr(ConditionalBridgeFromObjCExpr *E, StringRef label) { + printCommon(E, "conditional_bridge_from_objc_expr", label); + + printDeclRefField(E->getConversion(), "conversion"); + printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitBridgeFromObjCExpr(BridgeFromObjCExpr *E) { - printCommon(E, "bridge_from_objc_expr") << '\n'; + void visitBridgeFromObjCExpr(BridgeFromObjCExpr *E, StringRef label) { + printCommon(E, "bridge_from_objc_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitBridgeToObjCExpr(BridgeToObjCExpr *E) { - printCommon(E, "bridge_to_objc_expr") << '\n'; + void visitBridgeToObjCExpr(BridgeToObjCExpr *E, StringRef label) { + printCommon(E, "bridge_to_objc_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitLoadExpr(LoadExpr *E) { - printCommon(E, "load_expr") << '\n'; + void visitLoadExpr(LoadExpr *E, StringRef label) { + printCommon(E, "load_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitABISafeConversionExpr(ABISafeConversionExpr *E) { - printCommon(E, "abi_safe_conversion_expr") << '\n'; + void visitABISafeConversionExpr(ABISafeConversionExpr *E, StringRef label) { + printCommon(E, "abi_safe_conversion_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitMetatypeConversionExpr(MetatypeConversionExpr *E) { - printCommon(E, "metatype_conversion_expr") << '\n'; + void visitMetatypeConversionExpr(MetatypeConversionExpr *E, StringRef label) { + printCommon(E, "metatype_conversion_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitCollectionUpcastConversionExpr(CollectionUpcastConversionExpr *E) { - printCommon(E, "collection_upcast_expr"); - OS << '\n'; + void visitCollectionUpcastConversionExpr(CollectionUpcastConversionExpr *E, StringRef label) { + printCommon(E, "collection_upcast_expr", label); printRec(E->getSubExpr()); if (auto keyConversion = E->getKeyConversion()) { - OS << '\n'; - printRecLabeled(keyConversion.Conversion, "key_conversion"); + printRec(keyConversion.Conversion, "key_conversion"); } if (auto valueConversion = E->getValueConversion()) { - OS << '\n'; - printRecLabeled(valueConversion.Conversion, "value_conversion"); + printRec(valueConversion.Conversion, "value_conversion"); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitDerivedToBaseExpr(DerivedToBaseExpr *E) { - printCommon(E, "derived_to_base_expr") << '\n'; + void visitDerivedToBaseExpr(DerivedToBaseExpr *E, StringRef label) { + printCommon(E, "derived_to_base_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitArchetypeToSuperExpr(ArchetypeToSuperExpr *E) { - printCommon(E, "archetype_to_super_expr") << '\n'; + void visitArchetypeToSuperExpr(ArchetypeToSuperExpr *E, StringRef label) { + printCommon(E, "archetype_to_super_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitInjectIntoOptionalExpr(InjectIntoOptionalExpr *E) { - printCommon(E, "inject_into_optional") << '\n'; + void visitInjectIntoOptionalExpr(InjectIntoOptionalExpr *E, StringRef label) { + printCommon(E, "inject_into_optional", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitClassMetatypeToObjectExpr(ClassMetatypeToObjectExpr *E) { - printCommon(E, "class_metatype_to_object") << '\n'; + void visitClassMetatypeToObjectExpr(ClassMetatypeToObjectExpr *E, StringRef label) { + printCommon(E, "class_metatype_to_object", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitExistentialMetatypeToObjectExpr(ExistentialMetatypeToObjectExpr *E) { - printCommon(E, "existential_metatype_to_object") << '\n'; + void visitExistentialMetatypeToObjectExpr(ExistentialMetatypeToObjectExpr *E, StringRef label) { + printCommon(E, "existential_metatype_to_object", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitProtocolMetatypeToObjectExpr(ProtocolMetatypeToObjectExpr *E) { - printCommon(E, "protocol_metatype_to_object") << '\n'; + void visitProtocolMetatypeToObjectExpr(ProtocolMetatypeToObjectExpr *E, StringRef label) { + printCommon(E, "protocol_metatype_to_object", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitInOutToPointerExpr(InOutToPointerExpr *E) { - printCommon(E, "inout_to_pointer") - << (E->isNonAccessing() ? " nonaccessing" : "") << '\n'; + void visitInOutToPointerExpr(InOutToPointerExpr *E, StringRef label) { + printCommon(E, "inout_to_pointer", label); + printFlag(E->isNonAccessing(), "nonaccessing"); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitArrayToPointerExpr(ArrayToPointerExpr *E) { - printCommon(E, "array_to_pointer") - << (E->isNonAccessing() ? " nonaccessing" : "") << '\n'; + void visitArrayToPointerExpr(ArrayToPointerExpr *E, StringRef label) { + printCommon(E, "array_to_pointer", label); + printFlag(E->isNonAccessing(), "nonaccessing"); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitStringToPointerExpr(StringToPointerExpr *E) { - printCommon(E, "string_to_pointer") << '\n'; + void visitStringToPointerExpr(StringToPointerExpr *E, StringRef label) { + printCommon(E, "string_to_pointer", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitPointerToPointerExpr(PointerToPointerExpr *E) { - printCommon(E, "pointer_to_pointer") << '\n'; + void visitPointerToPointerExpr(PointerToPointerExpr *E, StringRef label) { + printCommon(E, "pointer_to_pointer", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitForeignObjectConversionExpr(ForeignObjectConversionExpr *E) { - printCommon(E, "foreign_object_conversion") << '\n'; + void visitForeignObjectConversionExpr(ForeignObjectConversionExpr *E, StringRef label) { + printCommon(E, "foreign_object_conversion", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitUnevaluatedInstanceExpr(UnevaluatedInstanceExpr *E) { - printCommon(E, "unevaluated_instance") << '\n'; + void visitUnevaluatedInstanceExpr(UnevaluatedInstanceExpr *E, StringRef label) { + printCommon(E, "unevaluated_instance", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitDifferentiableFunctionExpr(DifferentiableFunctionExpr *E) { - printCommon(E, "differentiable_function") << '\n'; + void visitDifferentiableFunctionExpr(DifferentiableFunctionExpr *E, StringRef label) { + printCommon(E, "differentiable_function", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitLinearFunctionExpr(LinearFunctionExpr *E) { - printCommon(E, "linear_function") << '\n'; + void visitLinearFunctionExpr(LinearFunctionExpr *E, StringRef label) { + printCommon(E, "linear_function", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitDifferentiableFunctionExtractOriginalExpr( - DifferentiableFunctionExtractOriginalExpr *E) { - printCommon(E, "differentiable_function_extract_original") << '\n'; + DifferentiableFunctionExtractOriginalExpr *E, StringRef label) { + printCommon(E, "differentiable_function_extract_original", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitLinearFunctionExtractOriginalExpr( - LinearFunctionExtractOriginalExpr *E) { - printCommon(E, "linear_function_extract_original") << '\n'; + LinearFunctionExtractOriginalExpr *E, StringRef label) { + printCommon(E, "linear_function_extract_original", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitLinearToDifferentiableFunctionExpr( - LinearToDifferentiableFunctionExpr *E) { - printCommon(E, "linear_to_differentiable_function") << '\n'; + LinearToDifferentiableFunctionExpr *E, StringRef label) { + printCommon(E, "linear_to_differentiable_function", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitInOutExpr(InOutExpr *E) { - printCommon(E, "inout_expr") << '\n'; + void visitInOutExpr(InOutExpr *E, StringRef label) { + printCommon(E, "inout_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitVarargExpansionExpr(VarargExpansionExpr *E) { - printCommon(E, "vararg_expansion_expr") << '\n'; + void visitVarargExpansionExpr(VarargExpansionExpr *E, StringRef label) { + printCommon(E, "vararg_expansion_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitPackExpansionExpr(PackExpansionExpr *E) { - printCommon(E, "pack_expansion_expr") << "\n"; + void visitPackExpansionExpr(PackExpansionExpr *E, StringRef label) { + printCommon(E, "pack_expansion_expr", label); printRec(E->getPatternExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitPackElementExpr(PackElementExpr *E) { - printCommon(E, "pack_element_expr") << "\n"; + void visitPackElementExpr(PackElementExpr *E, StringRef label) { + printCommon(E, "pack_element_expr", label); printRec(E->getPackRefExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitMaterializePackExpr(MaterializePackExpr *E) { - printCommon(E, "materialize_pack_expr") << "\n"; + void visitMaterializePackExpr(MaterializePackExpr *E, StringRef label) { + printCommon(E, "materialize_pack_expr", label); printRec(E->getFromExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitForceTryExpr(ForceTryExpr *E) { - printCommon(E, "force_try_expr"); - OS << '\n'; + void visitForceTryExpr(ForceTryExpr *E, StringRef label) { + printCommon(E, "force_try_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitOptionalTryExpr(OptionalTryExpr *E) { - printCommon(E, "optional_try_expr"); - OS << '\n'; + void visitOptionalTryExpr(OptionalTryExpr *E, StringRef label) { + printCommon(E, "optional_try_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitTryExpr(TryExpr *E) { - printCommon(E, "try_expr"); - OS << '\n'; + void visitTryExpr(TryExpr *E, StringRef label) { + printCommon(E, "try_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitSequenceExpr(SequenceExpr *E) { - printCommon(E, "sequence_expr"); + void visitSequenceExpr(SequenceExpr *E, StringRef label) { + printCommon(E, "sequence_expr", label); for (unsigned i = 0, e = E->getNumElements(); i != e; ++i) { - OS << '\n'; printRec(E->getElement(i)); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitCaptureListExpr(CaptureListExpr *E) { - printCommon(E, "capture_list"); + void visitCaptureListExpr(CaptureListExpr *E, StringRef label) { + printCommon(E, "capture_list", label); for (auto capture : E->getCaptureList()) { - OS << '\n'; - Indent += 2; printRec(capture.PBD); - Indent -= 2; } printRec(E->getClosureBody()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - llvm::raw_ostream &printClosure(AbstractClosureExpr *E, char const *name) { - printCommon(E, name); + void printClosure(AbstractClosureExpr *E, char const *name, + StringRef label) { + printCommon(E, name, label); // If we aren't printing to standard error or the debugger output stream, // this client expects to see the computed discriminator. Compute it now. - if (&OS != &llvm::errs() && &OS != &llvm::dbgs()) + if (hasNonStandardOutput()) (void)E->getDiscriminator(); - PrintWithColorRAII(OS, DiscriminatorColor) - << " discriminator=" << E->getRawDiscriminator(); + printField(E->getRawDiscriminator(), "discriminator", DiscriminatorColor); switch (auto isolation = E->getActorIsolation()) { case ClosureActorIsolation::Nonisolated: break; case ClosureActorIsolation::ActorInstance: - PrintWithColorRAII(OS, CapturesColor) << " actor-isolated=" - << isolation.getActorInstance()->printRef(); + printFieldQuoted(isolation.getActorInstance()->printRef(), + "actor_isolated", CapturesColor); break; case ClosureActorIsolation::GlobalActor: - PrintWithColorRAII(OS, CapturesColor) << " global-actor-isolated=" - << isolation.getGlobalActor().getString(); + printFieldQuoted(isolation.getGlobalActor().getString(), + "global_actor_isolated", CapturesColor); break; } if (!E->getCaptureInfo().isTrivial()) { - OS << " "; - E->getCaptureInfo().print(PrintWithColorRAII(OS, CapturesColor).getOS()); + printFieldRaw([&](raw_ostream &OS) { + E->getCaptureInfo().print(OS); + }, "", CapturesColor); } // Printing a function type doesn't indicate whether it's escaping because it doesn't // matter in 99% of contexts. AbstractClosureExpr nodes are one of the only exceptions. if (auto Ty = GetTypeOfExpr(E)) { if (auto fType = Ty->getAs()) { - if (!fType->getExtInfo().isNoEscape()) - PrintWithColorRAII(OS, ClosureModifierColor) << " escaping"; - if (fType->getExtInfo().isSendable()) - PrintWithColorRAII(OS, ClosureModifierColor) << " concurrent"; + printFlag(!fType->getExtInfo().isNoEscape(), "escaping", + ClosureModifierColor); + printFlag(fType->getExtInfo().isSendable(), "sendable", + ClosureModifierColor); } } - - return OS; } - void visitClosureExpr(ClosureExpr *E) { - printClosure(E, "closure_expr"); - if (E->hasSingleExpressionBody()) - PrintWithColorRAII(OS, ClosureModifierColor) << " single-expression"; - if (E->allowsImplicitSelfCapture()) - PrintWithColorRAII(OS, ClosureModifierColor) << " implicit-self"; - if (E->inheritsActorContext()) - PrintWithColorRAII(OS, ClosureModifierColor) << " inherits-actor-context"; + void visitClosureExpr(ClosureExpr *E, StringRef label) { + printClosure(E, "closure_expr", label); + printFlag(E->hasSingleExpressionBody(), "single_expression", + ClosureModifierColor); + printFlag(E->allowsImplicitSelfCapture(), "implicit_self", + ClosureModifierColor); + printFlag(E->inheritsActorContext(), "inherits_actor_context", + ClosureModifierColor); if (E->getParameters()) { - OS << '\n'; - PrintDecl(OS, Indent+2).printParameterList(E->getParameters(), &E->getASTContext()); + printRec(E->getParameters(), &E->getASTContext()); } + printRec(E->getBody(), &E->getASTContext()); - OS << '\n'; - printRec(E->getBody(), E->getASTContext()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitAutoClosureExpr(AutoClosureExpr *E) { - printClosure(E, "autoclosure_expr") << '\n'; + void visitAutoClosureExpr(AutoClosureExpr *E, StringRef label) { + printClosure(E, "autoclosure_expr", label); if (E->getParameters()) { - OS << '\n'; - PrintDecl(OS, Indent+2).printParameterList(E->getParameters(), &E->getASTContext()); + printRec(E->getParameters(), &E->getASTContext()); } - OS << '\n'; printRec(E->getSingleExpressionBody()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitDynamicTypeExpr(DynamicTypeExpr *E) { - printCommon(E, "metatype_expr"); - OS << '\n'; + void visitDynamicTypeExpr(DynamicTypeExpr *E, StringRef label) { + printCommon(E, "metatype_expr", label); printRec(E->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitOpaqueValueExpr(OpaqueValueExpr *E) { - printCommon(E, "opaque_value_expr") << " @ " << (void*)E; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitOpaqueValueExpr(OpaqueValueExpr *E, StringRef label) { + printCommon(E, "opaque_value_expr", label); + printNameRaw([&](raw_ostream &OS) { OS << (void*)E; }); + printFoot(); } void visitPropertyWrapperValuePlaceholderExpr( - PropertyWrapperValuePlaceholderExpr *E) { - printCommon(E, "property_wrapper_value_placeholder_expr"); - OS << '\n'; + PropertyWrapperValuePlaceholderExpr *E, StringRef label) { + printCommon(E, "property_wrapper_value_placeholder_expr", label); printRec(E->getOpaqueValuePlaceholder()); if (auto *value = E->getOriginalWrappedValue()) { - OS << '\n'; printRec(value); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitAppliedPropertyWrapperExpr(AppliedPropertyWrapperExpr *E) { - printCommon(E, "applied_property_wrapper_expr"); - OS << '\n'; + void visitAppliedPropertyWrapperExpr(AppliedPropertyWrapperExpr *E, StringRef label) { + printCommon(E, "applied_property_wrapper_expr", label); printRec(E->getValue()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitDefaultArgumentExpr(DefaultArgumentExpr *E) { - printCommon(E, "default_argument_expr"); - OS << " default_args_owner="; - E->getDefaultArgsOwner().dump(OS); - OS << " param=" << E->getParamIndex(); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitDefaultArgumentExpr(DefaultArgumentExpr *E, StringRef label) { + printCommon(E, "default_argument_expr", label); + printDeclRefField(E->getDefaultArgsOwner(), "default_args_owner"); + printField(E->getParamIndex(), "param"); + printFoot(); } - void printArgumentList(const ArgumentList *argList, bool indent = true) { - ::printArgumentList(OS, argList, Indent, [&](Expr *E) { printRec(E); }, - indent); - } - - void printApplyExpr(ApplyExpr *E, const char *NodeName) { - printCommon(E, NodeName); + void printApplyExpr(ApplyExpr *E, const char *NodeName, StringRef label) { + printCommon(E, NodeName, label); if (E->isThrowsSet()) { - PrintWithColorRAII(OS, ExprModifierColor) - << (E->throws() ? " throws" : " nothrow"); + printFlag(E->throws() ? "throws" : "nothrow", ExprModifierColor); } - PrintWithColorRAII(OS, ExprModifierColor) - << " isolationCrossing="; - auto isolationCrossing = E->getIsolationCrossing(); - if (isolationCrossing.has_value()) { - PrintWithColorRAII(OS, ExprModifierColor) - << "{caller='"; - simple_display(PrintWithColorRAII(OS, ExprModifierColor).getOS(), - isolationCrossing.value().getCallerIsolation()); - PrintWithColorRAII(OS, ExprModifierColor) - << "', callee='"; - simple_display(PrintWithColorRAII(OS, ExprModifierColor).getOS(), - isolationCrossing.value().getCalleeIsolation()); + printFieldQuotedRaw([&](raw_ostream &OS) { + auto isolationCrossing = E->getIsolationCrossing(); + if (isolationCrossing.has_value()) { + OS << "{caller='"; + simple_display(OS, isolationCrossing.value().getCallerIsolation()); + OS << "', callee='"; + simple_display(OS, isolationCrossing.value().getCalleeIsolation()); + OS << "'}"; + } else { + OS << "none"; + } + }, "isolation_crossing", ExprModifierColor); - PrintWithColorRAII(OS, ExprModifierColor) - << "'}"; - } else { - PrintWithColorRAII(OS, ExprModifierColor) - << "none"; - } - OS << '\n'; printRec(E->getFn()); - OS << '\n'; - printArgumentList(E->getArgs()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRec(E->getArgs()); + + printFoot(); } - void visitCallExpr(CallExpr *E) { - printApplyExpr(E, "call_expr"); + void visitCallExpr(CallExpr *E, StringRef label) { + printApplyExpr(E, "call_expr", label); } - void visitPrefixUnaryExpr(PrefixUnaryExpr *E) { - printApplyExpr(E, "prefix_unary_expr"); + void visitPrefixUnaryExpr(PrefixUnaryExpr *E, StringRef label) { + printApplyExpr(E, "prefix_unary_expr", label); } - void visitPostfixUnaryExpr(PostfixUnaryExpr *E) { - printApplyExpr(E, "postfix_unary_expr"); + void visitPostfixUnaryExpr(PostfixUnaryExpr *E, StringRef label) { + printApplyExpr(E, "postfix_unary_expr", label); } - void visitBinaryExpr(BinaryExpr *E) { - printApplyExpr(E, "binary_expr"); + void visitBinaryExpr(BinaryExpr *E, StringRef label) { + printApplyExpr(E, "binary_expr", label); } - void visitDotSyntaxCallExpr(DotSyntaxCallExpr *E) { - printApplyExpr(E, "dot_syntax_call_expr"); + void visitDotSyntaxCallExpr(DotSyntaxCallExpr *E, StringRef label) { + printApplyExpr(E, "dot_syntax_call_expr", label); } - void visitConstructorRefCallExpr(ConstructorRefCallExpr *E) { - printApplyExpr(E, "constructor_ref_call_expr"); + void visitConstructorRefCallExpr(ConstructorRefCallExpr *E, StringRef label) { + printApplyExpr(E, "constructor_ref_call_expr", label); } - void visitDotSyntaxBaseIgnoredExpr(DotSyntaxBaseIgnoredExpr *E) { - printCommon(E, "dot_syntax_base_ignored") << '\n'; + void visitDotSyntaxBaseIgnoredExpr(DotSyntaxBaseIgnoredExpr *E, StringRef label) { + printCommon(E, "dot_syntax_base_ignored", label); printRec(E->getLHS()); - OS << '\n'; printRec(E->getRHS()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void printExplicitCastExpr(ExplicitCastExpr *E, const char *name) { - printCommon(E, name) << ' '; + void printExplicitCastExpr(ExplicitCastExpr *E, const char *name, StringRef label) { + printCommon(E, name, label); + if (auto checkedCast = dyn_cast(E)) - OS << getCheckedCastKindName(checkedCast->getCastKind()) << ' '; - OS << "writtenType='"; - if (GetTypeOfTypeRepr) - GetTypeOfTypeRepr(E->getCastTypeRepr()).print(OS); - else - E->getCastType().print(OS); - OS << "'\n"; - printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitForcedCheckedCastExpr(ForcedCheckedCastExpr *E) { - printExplicitCastExpr(E, "forced_checked_cast_expr"); - } - void visitConditionalCheckedCastExpr(ConditionalCheckedCastExpr *E) { - printExplicitCastExpr(E, "conditional_checked_cast_expr"); - } - void visitIsExpr(IsExpr *E) { - printExplicitCastExpr(E, "is_subtype_expr"); - } - void visitCoerceExpr(CoerceExpr *E) { - printExplicitCastExpr(E, "coerce_expr"); - } - void visitArrowExpr(ArrowExpr *E) { - printCommon(E, "arrow"); - if (E->getAsyncLoc().isValid()) - OS << " async"; - if (E->getThrowsLoc().isValid()) - OS << " throws"; - OS << '\n'; - printRec(E->getArgsExpr()); - OS << '\n'; - printRec(E->getResultExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitRebindSelfInConstructorExpr(RebindSelfInConstructorExpr *E) { - printCommon(E, "rebind_self_in_constructor_expr") << '\n'; - printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitTernaryExpr(TernaryExpr *E) { - printCommon(E, "ternary_expr") << '\n'; - printRec(E->getCondExpr()); - OS << '\n'; - printRec(E->getThenExpr()); - OS << '\n'; - printRec(E->getElseExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitAssignExpr(AssignExpr *E) { - printCommon(E, "assign_expr") << '\n'; - printRec(E->getDest()); - OS << '\n'; - printRec(E->getSrc()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitEnumIsCaseExpr(EnumIsCaseExpr *E) { - printCommon(E, "enum_is_case_expr") << ' ' << - E->getEnumElement()->getBaseIdentifier() << "\n"; - printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitUnresolvedPatternExpr(UnresolvedPatternExpr *E) { - printCommon(E, "unresolved_pattern_expr") << '\n'; - printRec(E->getSubPattern()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitBindOptionalExpr(BindOptionalExpr *E) { - printCommon(E, "bind_optional_expr") - << " depth=" << E->getDepth() << '\n'; - printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitOptionalEvaluationExpr(OptionalEvaluationExpr *E) { - printCommon(E, "optional_evaluation_expr") << '\n'; - printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - void visitForceValueExpr(ForceValueExpr *E) { - printCommon(E, "force_value_expr"); - if (E->isForceOfImplicitlyUnwrappedOptional()) - PrintWithColorRAII(OS, ExprModifierColor) << " implicit_iuo_unwrap"; - OS << '\n'; + printFlag(getDumpString(checkedCast->getCastKind())); + printFieldQuotedRaw([&](raw_ostream &OS) { + if (GetTypeOfTypeRepr) + GetTypeOfTypeRepr(E->getCastTypeRepr()).print(OS); + else + E->getCastType().print(OS); + }, "written_type", TypeReprColor); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitOpenExistentialExpr(OpenExistentialExpr *E) { - printCommon(E, "open_existential_expr") << '\n'; + void visitForcedCheckedCastExpr(ForcedCheckedCastExpr *E, StringRef label) { + printExplicitCastExpr(E, "forced_checked_cast_expr", label); + } + void visitConditionalCheckedCastExpr(ConditionalCheckedCastExpr *E, StringRef label) { + printExplicitCastExpr(E, "conditional_checked_cast_expr", label); + } + void visitIsExpr(IsExpr *E, StringRef label) { + printExplicitCastExpr(E, "is_subtype_expr", label); + } + void visitCoerceExpr(CoerceExpr *E, StringRef label) { + printExplicitCastExpr(E, "coerce_expr", label); + } + void visitArrowExpr(ArrowExpr *E, StringRef label) { + printCommon(E, "arrow", label); + + printFlag(E->getAsyncLoc().isValid(), "async"); + printFlag(E->getThrowsLoc().isValid(), "throws"); + + printRec(E->getArgsExpr()); + printRec(E->getResultExpr()); + + printFoot(); + } + void visitRebindSelfInConstructorExpr(RebindSelfInConstructorExpr *E, StringRef label) { + printCommon(E, "rebind_self_in_constructor_expr", label); + printRec(E->getSubExpr()); + printFoot(); + } + void visitTernaryExpr(TernaryExpr *E, StringRef label) { + printCommon(E, "ternary_expr", label); + printRec(E->getCondExpr()); + printRec(E->getThenExpr()); + printRec(E->getElseExpr()); + printFoot(); + } + void visitAssignExpr(AssignExpr *E, StringRef label) { + printCommon(E, "assign_expr", label); + printRec(E->getDest()); + printRec(E->getSrc()); + printFoot(); + } + void visitEnumIsCaseExpr(EnumIsCaseExpr *E, StringRef label) { + printCommon(E, "enum_is_case_expr", label); + printName(E->getEnumElement()->getBaseIdentifier()); + printRec(E->getSubExpr()); + printFoot(); + } + void visitUnresolvedPatternExpr(UnresolvedPatternExpr *E, StringRef label) { + printCommon(E, "unresolved_pattern_expr", label); + printRec(E->getSubPattern()); + printFoot(); + } + void visitBindOptionalExpr(BindOptionalExpr *E, StringRef label) { + printCommon(E, "bind_optional_expr", label); + printField(E->getDepth(), "depth"); + printRec(E->getSubExpr()); + printFoot(); + } + void visitOptionalEvaluationExpr(OptionalEvaluationExpr *E, StringRef label) { + printCommon(E, "optional_evaluation_expr", label); + printRec(E->getSubExpr()); + printFoot(); + } + void visitForceValueExpr(ForceValueExpr *E, StringRef label) { + printCommon(E, "force_value_expr", label); + + printFlag(E->isForceOfImplicitlyUnwrappedOptional(), "implicit_iuo_unwrap", + ExprModifierColor); + + printRec(E->getSubExpr()); + + printFoot(); + } + void visitOpenExistentialExpr(OpenExistentialExpr *E, StringRef label) { + printCommon(E, "open_existential_expr", label); printRec(E->getOpaqueValue()); - OS << '\n'; printRec(E->getExistentialValue()); - OS << '\n'; printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitMakeTemporarilyEscapableExpr(MakeTemporarilyEscapableExpr *E) { - printCommon(E, "make_temporarily_escapable_expr") << '\n'; + void visitMakeTemporarilyEscapableExpr(MakeTemporarilyEscapableExpr *E, StringRef label) { + printCommon(E, "make_temporarily_escapable_expr", label); printRec(E->getOpaqueValue()); - OS << '\n'; printRec(E->getNonescapingClosureValue()); - OS << '\n'; printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitEditorPlaceholderExpr(EditorPlaceholderExpr *E) { - printCommon(E, "editor_placeholder_expr") << ' '; + void visitEditorPlaceholderExpr(EditorPlaceholderExpr *E, StringRef label) { + printCommon(E, "editor_placeholder_expr", label); // Print the trailing angle bracket location if (auto Ty = GetTypeOfExpr(E)) { auto &Ctx = Ty->getASTContext(); - auto TABL = E->getTrailingAngleBracketLoc(); - if (TABL.isValid()) { - PrintWithColorRAII(OS, LocationColor) << " trailing_angle_bracket_loc="; - TABL.print(PrintWithColorRAII(OS, LocationColor).getOS(), - Ctx.SourceMgr); - } + printSourceLoc(E->getTrailingAngleBracketLoc(), &Ctx, + "trailing_angle_bracket_loc"); } - OS << '\n'; auto *TyR = E->getPlaceholderTypeRepr(); auto *ExpTyR = E->getTypeForExpansion(); if (TyR) printRec(TyR); if (ExpTyR && ExpTyR != TyR) { - OS << '\n'; printRec(ExpTyR); } printSemanticExpr(E->getSemanticExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitLazyInitializerExpr(LazyInitializerExpr *E) { - printCommon(E, "lazy_initializer_expr") << '\n'; + void visitLazyInitializerExpr(LazyInitializerExpr *E, StringRef label) { + printCommon(E, "lazy_initializer_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitObjCSelectorExpr(ObjCSelectorExpr *E) { - printCommon(E, "objc_selector_expr"); - OS << " kind=" << getObjCSelectorExprKindString(E->getSelectorKind()); - PrintWithColorRAII(OS, DeclColor) << " decl="; - printDeclRef(E->getMethod()); - OS << '\n'; + void visitObjCSelectorExpr(ObjCSelectorExpr *E, StringRef label) { + printCommon(E, "objc_selector_expr", label); + + printField(E->getSelectorKind(), "kind"); + printDeclRefField(E->getMethod(), "decl"); + printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitKeyPathExpr(KeyPathExpr *E) { - printCommon(E, "keypath_expr"); - if (E->isObjC()) - OS << " objc"; + void visitKeyPathExpr(KeyPathExpr *E, StringRef label) { + printCommon(E, "keypath_expr", label); - OS << '\n'; - Indent += 2; - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, ExprColor) << "components"; - OS.indent(Indent + 2); - for (unsigned i : indices(E->getComponents())) { - auto &component = E->getComponents()[i]; - OS << '\n'; - OS.indent(Indent + 2); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - switch (component.getKind()) { - case KeyPathExpr::Component::Kind::Invalid: - PrintWithColorRAII(OS, ASTNodeColor) << "invalid"; - break; + printFlag(E->isObjC(), "objc"); - case KeyPathExpr::Component::Kind::OptionalChain: - PrintWithColorRAII(OS, ASTNodeColor) << "optional_chain"; - break; - - case KeyPathExpr::Component::Kind::OptionalForce: - PrintWithColorRAII(OS, ASTNodeColor) << "optional_force"; - break; - - case KeyPathExpr::Component::Kind::OptionalWrap: - PrintWithColorRAII(OS, ASTNodeColor) << "optional_wrap"; - break; - - case KeyPathExpr::Component::Kind::Property: - PrintWithColorRAII(OS, ASTNodeColor) << "property"; - PrintWithColorRAII(OS, DeclColor) << " decl="; - printDeclRef(component.getDeclRef()); - break; - - case KeyPathExpr::Component::Kind::Subscript: - PrintWithColorRAII(OS, ASTNodeColor) << "subscript"; - PrintWithColorRAII(OS, DeclColor) << " decl='"; - printDeclRef(component.getDeclRef()); - PrintWithColorRAII(OS, DeclColor) << "'"; - break; - - case KeyPathExpr::Component::Kind::UnresolvedProperty: - PrintWithColorRAII(OS, ASTNodeColor) << "unresolved_property"; - PrintWithColorRAII(OS, IdentifierColor) - << " decl_name='" << component.getUnresolvedDeclName() << "'"; - break; - - case KeyPathExpr::Component::Kind::UnresolvedSubscript: - PrintWithColorRAII(OS, ASTNodeColor) << "unresolved_subscript"; - break; - case KeyPathExpr::Component::Kind::Identity: - PrintWithColorRAII(OS, ASTNodeColor) << "identity"; - break; + printRecArbitrary([&](StringRef label) { + printHead("components", ExprColor, label); + for (unsigned i : indices(E->getComponents())) { + auto &component = E->getComponents()[i]; + printRecArbitrary([&](StringRef label) { + switch (component.getKind()) { + case KeyPathExpr::Component::Kind::Invalid: + printHead("invalid", ASTNodeColor); + break; - case KeyPathExpr::Component::Kind::TupleElement: - PrintWithColorRAII(OS, ASTNodeColor) << "tuple_element "; - PrintWithColorRAII(OS, DiscriminatorColor) - << "#" << component.getTupleIndex(); - break; - case KeyPathExpr::Component::Kind::DictionaryKey: - PrintWithColorRAII(OS, ASTNodeColor) << "dict_key"; - PrintWithColorRAII(OS, IdentifierColor) - << " key='" << component.getUnresolvedDeclName() << "'"; - break; - case KeyPathExpr::Component::Kind::CodeCompletion: - PrintWithColorRAII(OS, ASTNodeColor) << "completion"; - break; + case KeyPathExpr::Component::Kind::OptionalChain: + printHead("optional_chain", ASTNodeColor); + break; + + case KeyPathExpr::Component::Kind::OptionalForce: + printHead("optional_force", ASTNodeColor); + break; + + case KeyPathExpr::Component::Kind::OptionalWrap: + printHead("optional_wrap", ASTNodeColor); + break; + + case KeyPathExpr::Component::Kind::Property: + printHead("property", ASTNodeColor); + printDeclRefField(component.getDeclRef(), "decl"); + break; + + case KeyPathExpr::Component::Kind::Subscript: + printHead("subscript", ASTNodeColor); + printDeclRefField(component.getDeclRef(), "decl"); + break; + + case KeyPathExpr::Component::Kind::UnresolvedProperty: + printHead("unresolved_property", ASTNodeColor); + printFieldQuoted(component.getUnresolvedDeclName(), "decl_name", + IdentifierColor); + break; + + case KeyPathExpr::Component::Kind::UnresolvedSubscript: + printHead("unresolved_subscript", ASTNodeColor); + break; + case KeyPathExpr::Component::Kind::Identity: + printHead("identity", ASTNodeColor); + break; + + case KeyPathExpr::Component::Kind::TupleElement: + printHead("tuple_element", ASTNodeColor); + printField(component.getTupleIndex(), "index", DiscriminatorColor); + break; + case KeyPathExpr::Component::Kind::DictionaryKey: + printHead("dict_key", ASTNodeColor); + printFieldQuoted(component.getUnresolvedDeclName(), "key", + IdentifierColor); + break; + case KeyPathExpr::Component::Kind::CodeCompletion: + printHead("completion", ASTNodeColor); + break; + } + printFieldQuoted(GetTypeOfKeyPathComponent(E, i), "type"); + if (auto *args = component.getSubscriptArgs()) { + printRec(args); + } + printFoot(); + }); } - PrintWithColorRAII(OS, TypeColor) - << " type='" << GetTypeOfKeyPathComponent(E, i) << "'"; - if (auto *args = component.getSubscriptArgs()) { - OS << '\n'; - printArgumentList(args); - } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - Indent -= 2; + printFoot(); + }); if (auto stringLiteral = E->getObjCStringLiteralExpr()) { - OS << '\n'; - printRecLabeled(stringLiteral, "objc_string_literal"); + printRec(stringLiteral, "objc_string_literal"); } if (!E->isObjC()) { if (auto root = E->getParsedRoot()) { - OS << "\n"; - printRecLabeled(root, "parsed_root"); + printRec(root, "parsed_root"); } if (auto path = E->getParsedPath()) { - OS << "\n"; - printRecLabeled(path, "parsed_path"); + printRec(path, "parsed_path"); } } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitKeyPathDotExpr(KeyPathDotExpr *E) { - printCommon(E, "key_path_dot_expr"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitKeyPathDotExpr(KeyPathDotExpr *E, StringRef label) { + printCommon(E, "key_path_dot_expr", label); + printFoot(); } - void visitSingleValueStmtExpr(SingleValueStmtExpr *E) { - printCommon(E, "single_value_stmt_expr"); - OS << '\n'; - printRec(E->getStmt(), E->getDeclContext()->getASTContext()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitSingleValueStmtExpr(SingleValueStmtExpr *E, StringRef label) { + printCommon(E, "single_value_stmt_expr", label); + printRec(E->getStmt(), &E->getDeclContext()->getASTContext()); + printFoot(); } - void visitOneWayExpr(OneWayExpr *E) { - printCommon(E, "one_way_expr"); - OS << '\n'; + void visitOneWayExpr(OneWayExpr *E, StringRef label) { + printCommon(E, "one_way_expr", label); printRec(E->getSubExpr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitTapExpr(TapExpr *E) { - printCommon(E, "tap_expr"); - PrintWithColorRAII(OS, DeclColor) << " var="; - printDeclRef(E->getVar()); - OS << '\n'; - + void visitTapExpr(TapExpr *E, StringRef label) { + printCommon(E, "tap_expr", label); + printDeclRefField(E->getVar(), "var"); printRec(E->getSubExpr()); - OS << '\n'; - - printRec(E->getBody(), E->getVar()->getDeclContext()->getASTContext()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRec(E->getBody(), &E->getVar()->getDeclContext()->getASTContext()); + printFoot(); } - void visitTypeJoinExpr(TypeJoinExpr *E) { - printCommon(E, "type_join_expr"); + void visitTypeJoinExpr(TypeJoinExpr *E, StringRef label) { + printCommon(E, "type_join_expr", label); if (auto *var = E->getVar()) { - PrintWithColorRAII(OS, DeclColor) << " var="; - printRec(var); - OS << '\n'; + printRec(var, "var"); } if (auto *SVE = E->getSingleValueStmtExpr()) { - PrintWithColorRAII(OS, ExprColor) << "single_value_stmt_expr="; - printRec(SVE); - OS << '\n'; + printRec(SVE, "single_value_stmt_expr"); } - OS << '\n'; - for (auto *member : E->getElements()) { printRec(member); - OS << '\n'; } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitMacroExpansionExpr(MacroExpansionExpr *E) { - printCommon(E, "macro_expansion_expr"); - PrintWithColorRAII(OS, IdentifierColor) << " name=" << E->getMacroName(); - PrintWithColorRAII(OS, DiscriminatorColor) - << " discriminator=" << E->getRawDiscriminator(); + void visitMacroExpansionExpr(MacroExpansionExpr *E, StringRef label) { + printCommon(E, "macro_expansion_expr", label); + + printFieldQuoted(E->getMacroName(), "name", IdentifierColor); + printField(E->getRawDiscriminator(), "discriminator", DiscriminatorColor); + if (E->getArgs()) { - OS << '\n'; - printArgumentList(E->getArgs()); + printRec(E->getArgs()); } if (auto rewritten = E->getRewritten()) { - OS << " rewritten=\n"; - printRec(rewritten); + printRec(rewritten, "rewritten"); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } }; @@ -3093,18 +3122,14 @@ void Expr::dump(raw_ostream &OS, llvm::function_ref getTypeOfExpr, llvm::function_ref getTypeOfKeyPathComponent, unsigned Indent) const { - PrintExpr(OS, getTypeOfExpr, getTypeOfTypeRepr, getTypeOfKeyPathComponent, - Indent) - .visit(const_cast(this)); + PrintExpr(OS, Indent, getTypeOfExpr, getTypeOfTypeRepr, + getTypeOfKeyPathComponent) + .visit(const_cast(this), ""); } void Expr::dump(raw_ostream &OS, unsigned Indent) const { - auto getTypeOfExpr = [](Expr *E) -> Type { return E->getType(); }; - auto getTypeOfKeyPathComponent = [](KeyPathExpr *E, unsigned index) -> Type { - return E->getComponents()[index].getComponentType(); - }; - dump(OS, getTypeOfExpr, /*getTypeOfTypeRepr*/ nullptr, - getTypeOfKeyPathComponent, Indent); + dump(OS, defaultGetTypeOfExpr, /*getTypeOfTypeRepr*/ nullptr, + defaultGetTypeOfKeyPathComponent, Indent); } void Expr::print(ASTPrinter &Printer, const PrintOptions &Opts) const { @@ -3117,17 +3142,11 @@ void Expr::print(ASTPrinter &Printer, const PrintOptions &Opts) const { void ArgumentList::dump() const { dump(llvm::errs(), 0); + llvm::errs() << '\n'; } void ArgumentList::dump(raw_ostream &OS, unsigned Indent) const { - auto getTypeOfExpr = [](Expr *E) -> Type { return E->getType(); }; - auto getTypeOfKeyPathComponent = [](KeyPathExpr *E, unsigned index) -> Type { - return E->getComponents()[index].getComponentType(); - }; - PrintExpr printer(OS, getTypeOfExpr, /*getTypeOfTypeRepr*/ nullptr, - getTypeOfKeyPathComponent, Indent); - printer.printArgumentList(this, /*indent*/ false); - llvm::errs() << '\n'; + PrintBase(OS, Indent).visitArgumentList(this); } //===----------------------------------------------------------------------===// @@ -3135,543 +3154,571 @@ void ArgumentList::dump(raw_ostream &OS, unsigned Indent) const { //===----------------------------------------------------------------------===// namespace { -class PrintTypeRepr : public TypeReprVisitor { +class PrintTypeRepr : public TypeReprVisitor, + public PrintBase { public: - raw_ostream &OS; - unsigned Indent; + using PrintBase::PrintBase; - PrintTypeRepr(raw_ostream &os, unsigned indent) - : OS(os), Indent(indent) { } - - void printRec(Decl *D) { D->dump(OS, Indent + 2); } - void printRec(Expr *E) { E->dump(OS, Indent + 2); } - void printRec(TypeRepr *T) { PrintTypeRepr(OS, Indent + 2).visit(T); } - - raw_ostream &printCommon(const char *Name) { - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - PrintWithColorRAII(OS, TypeReprColor) << Name; - return OS; + void printCommon(const char *Name, StringRef Label) { + printHead(Name, TypeReprColor, Label); } - void visitErrorTypeRepr(ErrorTypeRepr *T) { - printCommon("type_error"); + void visitErrorTypeRepr(ErrorTypeRepr *T, StringRef label) { + printCommon("type_error", label); } - void visitAttributedTypeRepr(AttributedTypeRepr *T) { - printCommon("type_attributed") << " attrs="; - T->printAttrs(OS); - OS << '\n'; + void visitAttributedTypeRepr(AttributedTypeRepr *T, StringRef label) { + printCommon("type_attributed", label); + printFieldQuotedRaw([&](raw_ostream &OS) { T->printAttrs(OS); }, "attrs"); printRec(T->getTypeRepr()); } - void visitIdentTypeRepr(IdentTypeRepr *T) { - printCommon("type_ident"); + void visitIdentTypeRepr(IdentTypeRepr *T, StringRef label) { + printCommon("type_ident", label); - PrintWithColorRAII(OS, IdentifierColor) - << " id='" << T->getNameRef() << '\''; - OS << " bind="; + printFieldQuoted(T->getNameRef(), "id", IdentifierColor); if (T->isBound()) - T->getBoundDecl()->dumpRef(OS); + printFieldQuoted(T->getBoundDecl()->printRef(), "bind"); else - OS << "none"; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFlag("unbound"); + if (auto *GenIdT = dyn_cast(T)) { for (auto genArg : GenIdT->getGenericArgs()) { - OS << '\n'; printRec(genArg); } } + + printFoot(); } - void visitMemberTypeRepr(MemberTypeRepr *T) { - printCommon("type_member"); + void visitMemberTypeRepr(MemberTypeRepr *T, StringRef label) { + printCommon("type_member", label); - OS << '\n'; printRec(T->getBaseComponent()); for (auto *comp : T->getMemberComponents()) { - OS << '\n'; printRec(comp); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitFunctionTypeRepr(FunctionTypeRepr *T) { - printCommon("type_function"); - OS << '\n'; printRec(T->getArgsTypeRepr()); - if (T->isAsync()) - OS << " async "; - if (T->isThrowing()) - OS << " throws "; - OS << '\n'; printRec(T->getResultTypeRepr()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitFunctionTypeRepr(FunctionTypeRepr *T, StringRef label) { + printCommon("type_function", label); + + printFlag(T->isAsync(), "async"); + printFlag(T->isThrowing(), "throws"); + + printRec(T->getArgsTypeRepr()); + printRec(T->getResultTypeRepr()); + + printFoot(); } - void visitArrayTypeRepr(ArrayTypeRepr *T) { - printCommon("type_array") << '\n'; + void visitArrayTypeRepr(ArrayTypeRepr *T, StringRef label) { + printCommon("type_array", label); printRec(T->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitDictionaryTypeRepr(DictionaryTypeRepr *T) { - printCommon("type_dictionary") << '\n'; + void visitDictionaryTypeRepr(DictionaryTypeRepr *T, StringRef label) { + printCommon("type_dictionary", label); printRec(T->getKey()); - OS << '\n'; printRec(T->getValue()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitVarargTypeRepr(VarargTypeRepr *T) { - printCommon("vararg") << '\n'; + void visitVarargTypeRepr(VarargTypeRepr *T, StringRef label) { + printCommon("vararg", label); printRec(T->getElementType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitPackTypeRepr(PackTypeRepr *T) { - printCommon("pack") << '\n'; + void visitPackTypeRepr(PackTypeRepr *T, StringRef label) { + printCommon("pack", label); for (auto elt : T->getElements()) printRec(elt); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitPackExpansionTypeRepr(PackExpansionTypeRepr *T) { - printCommon("pack_expansion") << '\n'; + void visitPackExpansionTypeRepr(PackExpansionTypeRepr *T, StringRef label) { + printCommon("pack_expansion", label); printRec(T->getPatternType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitPackElementTypeRepr(PackElementTypeRepr *T) { - printCommon("pack_element"); + void visitPackElementTypeRepr(PackElementTypeRepr *T, StringRef label) { + printCommon("pack_element", label); printRec(T->getPackType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitTupleTypeRepr(TupleTypeRepr *T) { - printCommon("type_tuple"); + void visitTupleTypeRepr(TupleTypeRepr *T, StringRef label) { + printCommon("type_tuple", label); if (T->hasElementNames()) { - OS << " names="; - for (unsigned i = 0, end = T->getNumElements(); i != end; ++i) { - if (i) OS << ","; - auto name = T->getElementName(i); - if (T->isNamedParameter(i)) - OS << (name.empty() ? "_" : "_ " + name.str()); - else - OS << (name.empty() ? "''" : name.str()); - } + printFieldQuotedRaw([&](raw_ostream &OS) { + llvm::interleave(T->getElements(), OS, + [&](const TupleTypeReprElement &Elt) { + auto name = Elt.Name; + if (Elt.UnderscoreLoc.isValid()) + OS << (name.empty() ? "_" : "_ " + name.str()); + else + OS << (name.empty() ? "''" : name.str()); + }, ","); + }, "names"); } for (auto elem : T->getElements()) { - OS << '\n'; printRec(elem.Type); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } - void visitCompositionTypeRepr(CompositionTypeRepr *T) { - printCommon("type_composite"); + void visitCompositionTypeRepr(CompositionTypeRepr *T, StringRef label) { + printCommon("type_composite", label); for (auto elem : T->getTypes()) { - OS << '\n'; printRec(elem); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitMetatypeTypeRepr(MetatypeTypeRepr *T) { - printCommon("type_metatype") << '\n'; + void visitMetatypeTypeRepr(MetatypeTypeRepr *T, StringRef label) { + printCommon("type_metatype", label); printRec(T->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitProtocolTypeRepr(ProtocolTypeRepr *T) { - printCommon("type_protocol") << '\n'; + void visitProtocolTypeRepr(ProtocolTypeRepr *T, StringRef label) { + printCommon("type_protocol", label); printRec(T->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitOwnershipTypeRepr(OwnershipTypeRepr *T) { - printCommon("type_ownership") - << ' ' - << T->getSpecifierSpelling() - << '\n'; + void visitOwnershipTypeRepr(OwnershipTypeRepr *T, StringRef label) { + printCommon("type_ownership", label); + printFlag(getDumpString(T->getSpecifier())); printRec(T->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitIsolatedTypeRepr(IsolatedTypeRepr *T) { - printCommon("isolated") << '\n'; + void visitIsolatedTypeRepr(IsolatedTypeRepr *T, StringRef label) { + printCommon("isolated", label); printRec(T->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitCompileTimeConstTypeRepr(CompileTimeConstTypeRepr *T) { - printCommon("_const") << '\n'; + void visitCompileTimeConstTypeRepr(CompileTimeConstTypeRepr *T, StringRef label) { + printCommon("_const", label); printRec(T->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitOptionalTypeRepr(OptionalTypeRepr *T) { - printCommon("type_optional") << '\n'; + void visitOptionalTypeRepr(OptionalTypeRepr *T, StringRef label) { + printCommon("type_optional", label); printRec(T->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitImplicitlyUnwrappedOptionalTypeRepr( - ImplicitlyUnwrappedOptionalTypeRepr *T) { - printCommon("type_implicitly_unwrapped_optional") << '\n'; + ImplicitlyUnwrappedOptionalTypeRepr *T, StringRef label) { + printCommon("type_implicitly_unwrapped_optional", label); printRec(T->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitOpaqueReturnTypeRepr(OpaqueReturnTypeRepr *T) { - printCommon("type_opaque_return"); + void visitOpaqueReturnTypeRepr(OpaqueReturnTypeRepr *T, StringRef label) { + printCommon("type_opaque_return", label); printRec(T->getConstraint()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitNamedOpaqueReturnTypeRepr(NamedOpaqueReturnTypeRepr *T) { - printCommon("type_named_opaque_return") << '\n'; + void visitNamedOpaqueReturnTypeRepr(NamedOpaqueReturnTypeRepr *T, StringRef label) { + printCommon("type_named_opaque_return", label); printRec(T->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitExistentialTypeRepr(ExistentialTypeRepr *T) { - printCommon("type_existential"); + void visitExistentialTypeRepr(ExistentialTypeRepr *T, StringRef label) { + printCommon("type_existential", label); printRec(T->getConstraint()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } - void visitPlaceholderTypeRepr(PlaceholderTypeRepr *T) { - printCommon("type_placeholder"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void visitPlaceholderTypeRepr(PlaceholderTypeRepr *T, StringRef label) { + printCommon("type_placeholder", label); + printFoot(); } - void visitFixedTypeRepr(FixedTypeRepr *T) { - printCommon("type_fixed"); + void visitFixedTypeRepr(FixedTypeRepr *T, StringRef label) { + printCommon("type_fixed", label); + auto Ty = T->getType(); if (Ty) { - auto &srcMgr = Ty->getASTContext().SourceMgr; - if (T->getLoc().isValid()) { - OS << " location=@"; - T->getLoc().print(OS, srcMgr); - } else { - OS << " location=<>"; - } + printSourceLoc(T->getLoc(), &Ty->getASTContext()); } - OS << " type="; Ty.dump(OS); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printRec(Ty, "type"); + + printFoot(); } - void visitSelfTypeRepr(SelfTypeRepr *T) { - printCommon("type_self"); + void visitSelfTypeRepr(SelfTypeRepr *T, StringRef label) { + printCommon("type_self", label); + auto Ty = T->getType(); if (Ty) { - auto &srcMgr = Ty->getASTContext().SourceMgr; - if (T->getLoc().isValid()) { - OS << " location=@"; - T->getLoc().print(OS, srcMgr); - } else { - OS << " location=<>"; - } + printSourceLoc(T->getLoc(), &Ty->getASTContext()); } - OS << " type="; Ty.dump(OS); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printRec(Ty, "type"); + + printFoot(); } - void visitSILBoxTypeRepr(SILBoxTypeRepr *T) { - printCommon("sil_box"); - Indent += 2; + void visitSILBoxTypeRepr(SILBoxTypeRepr *T, StringRef label) { + printCommon("sil_box", label); - ArrayRef Fields = T->getFields(); - for (unsigned i = 0, end = Fields.size(); i != end; ++i) { - OS << '\n'; - printCommon("sil_box_field"); - if (Fields[i].isMutable()) { - OS << " mutable"; - } - OS << '\n'; - printRec(Fields[i].getFieldType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + for (auto &Field : T->getFields()) { + printRecArbitrary([&](StringRef label) { + printCommon("sil_box_field", label); + printFlag(Field.isMutable(), "mutable"); + + printRec(Field.getFieldType()); + printFoot(); + }); } - for (auto genArg : T->getGenericArguments()) { - OS << '\n'; - printRec(genArg); - } + printRecRange(T->getGenericArguments(), "generic_arguments"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - Indent -= 2; + printFoot(); } }; +void PrintBase::printRec(Decl *D, StringRef label) { + printRecArbitrary([&](StringRef label) { + if (!D) { + printHead("", DeclColor, label); + printFoot(); + } else { + PrintDecl(OS, Indent, GetTypeOfExpr, GetTypeOfTypeRepr, + GetTypeOfKeyPathComponent).visit(D, label); + } + }, label); +} +void PrintBase::printRec(Expr *E, StringRef label) { + printRecArbitrary([&](StringRef label) { + if (!E) { + printHead("", ExprColor, label); + printFoot(); + } else { + PrintExpr(OS, Indent, GetTypeOfExpr, GetTypeOfTypeRepr, + GetTypeOfKeyPathComponent).visit(E, label); + } + }, label); +} +void PrintBase::printRec(Stmt *S, const ASTContext *Ctx, StringRef label) { + printRecArbitrary([&](StringRef label) { + if (!S) { + printHead("", ExprColor, label); + printFoot(); + } else { + PrintStmt(OS, Ctx, Indent, GetTypeOfExpr, GetTypeOfTypeRepr, + GetTypeOfKeyPathComponent).visit(S, label); + } + }, label); +} +void PrintBase::printRec(TypeRepr *T, StringRef label) { + printRecArbitrary([&](StringRef label) { + if (!T) { + printHead("", TypeReprColor, label); + printFoot(); + } else { + PrintTypeRepr(OS, Indent, GetTypeOfExpr, GetTypeOfTypeRepr, + GetTypeOfKeyPathComponent).visit(T, label); + } + }, label); +} +void PrintBase::printRec(const Pattern *P, StringRef label) { + printRecArbitrary([&](StringRef label) { + if (!P) { + printHead("", PatternColor, label); + printFoot(); + } else { + PrintPattern(OS, Indent, GetTypeOfExpr, GetTypeOfTypeRepr, + GetTypeOfKeyPathComponent).visit(const_cast(P), + label); + } + }, label); +} + + } // end anonymous namespace -void PrintDecl::printRec(TypeRepr *T) { - PrintTypeRepr(OS, Indent+2).visit(T); -} - -void PrintExpr::printRec(TypeRepr *T) { - PrintTypeRepr(OS, Indent+2).visit(T); -} - -void PrintPattern::printRec(TypeRepr *T) { - PrintTypeRepr(OS, Indent+2).visit(T); -} - void TypeRepr::dump() const { - PrintTypeRepr(llvm::errs(), 0).visit(const_cast(this)); + dump(llvm::errs()); llvm::errs() << '\n'; } - -// Recursive helpers to avoid infinite recursion for recursive protocol -// conformances. -static void dumpProtocolConformanceRec( - const ProtocolConformance *conformance, llvm::raw_ostream &out, - unsigned indent, - llvm::SmallPtrSetImpl &visited); - -static void dumpPackConformanceRec( - const PackConformance *conformance, llvm::raw_ostream &out, - unsigned indent, - llvm::SmallPtrSetImpl &visited); - -static void dumpProtocolConformanceRefRec( - const ProtocolConformanceRef conformance, llvm::raw_ostream &out, - unsigned indent, - llvm::SmallPtrSetImpl &visited) { - if (conformance.isInvalid()) { - out.indent(indent) << "(invalid_conformance)"; - } else if (conformance.isConcrete()) { - dumpProtocolConformanceRec(conformance.getConcrete(), out, indent, visited); - } else if (conformance.isPack()) { - dumpPackConformanceRec(conformance.getPack(), out, indent, visited); - } else { - assert(conformance.isAbstract()); - - out.indent(indent) << "(abstract_conformance protocol=" - << conformance.getAbstract()->getName(); - PrintWithColorRAII(out, ParenthesisColor) << ')'; - } +void TypeRepr::dump(raw_ostream &os, unsigned indent) const { + PrintTypeRepr(os, indent).visit(const_cast(this), ""); } -static void dumpProtocolConformanceRec( - const ProtocolConformance *conformance, llvm::raw_ostream &out, - unsigned indent, - llvm::SmallPtrSetImpl &visited) { - // A recursive conformance shouldn't have its contents printed, or there's - // infinite recursion. (This also avoids printing things that occur multiple - // times in a conformance hierarchy.) - auto shouldPrintDetails = visited.insert(conformance).second; +namespace { - auto printCommon = [&](StringRef kind) { - out.indent(indent); - PrintWithColorRAII(out, ParenthesisColor) << '('; - out << kind << "_conformance type=" << conformance->getType() - << " protocol=" << conformance->getProtocol()->getName(); +class PrintConformance : public PrintBase { +public: + using PrintBase::PrintBase; - if (!shouldPrintDetails) - out << " (details printed above)"; - }; - - switch (conformance->getKind()) { - case ProtocolConformanceKind::Normal: { - auto normal = cast(conformance); - - printCommon("normal"); - if (!shouldPrintDetails) - break; - - // Maybe print information about the conforming context? - if (normal->isLazilyLoaded()) { - out << " lazy"; + void visitProtocolConformanceRef(const ProtocolConformanceRef conformance, + VisitedConformances &visited, + StringRef label) { + if (conformance.isInvalid()) { + printHead("invalid_conformance", ASTNodeColor, label); + printFoot(); + } else if (conformance.isConcrete()) { + visitProtocolConformance(conformance.getConcrete(), visited, label); + } else if (conformance.isPack()) { + visitPackConformance(conformance.getPack(), visited, label); } else { - normal->forEachTypeWitness( - [&](const AssociatedTypeDecl *req, Type ty, - const TypeDecl *) -> bool { - out << '\n'; - out.indent(indent + 2); - PrintWithColorRAII(out, ParenthesisColor) << '('; - out << "assoc_type req=" << req->getName() << " type="; - PrintWithColorRAII(out, TypeColor) << Type(ty->getDesugaredType()); - PrintWithColorRAII(out, ParenthesisColor) << ')'; + assert(conformance.isAbstract()); + + printHead("abstract_conformance", ASTNodeColor, label); + printFieldQuoted(conformance.getAbstract()->getName(), "protocol"); + printFoot(); + } + } + + void visitProtocolConformance(const ProtocolConformance *conformance, + VisitedConformances &visited, StringRef label) { + // A recursive conformance shouldn't have its contents printed, or there's + // infinite recursion. (This also avoids printing things that occur multiple + // times in a conformance hierarchy.) + auto shouldPrintDetails = visited.insert(conformance).second; + + auto printCommon = [&](StringRef kind) { + printHead(kind, ASTNodeColor, label); + printFieldQuoted(conformance->getType(), "type"); + printFieldQuoted(conformance->getProtocol()->getName(), "protocol"); + printFlag(!shouldPrintDetails, "
"); + }; + + switch (conformance->getKind()) { + case ProtocolConformanceKind::Normal: { + auto normal = cast(conformance); + + printCommon("normal_conformance"); + if (!shouldPrintDetails) + break; + + // Maybe print information about the conforming context? + if (normal->isLazilyLoaded()) { + printFlag("lazy"); + } else { + normal->forEachTypeWitness([&](const AssociatedTypeDecl *req, Type ty, + const TypeDecl *) -> bool { + printRecArbitrary([&](StringRef label) { + printHead("assoc_type", ASTNodeColor, label); + printFieldQuoted(req->getName(), "req"); + printFieldQuoted(Type(ty->getDesugaredType()), "type", TypeColor); + printFoot(); + }); return false; }); - normal->forEachValueWitness([&](const ValueDecl *req, - Witness witness) { - out << '\n'; - out.indent(indent + 2); - PrintWithColorRAII(out, ParenthesisColor) << '('; - out << "value req=" << req->getName() << " witness="; - if (!witness) { - out << "(none)"; - } else if (witness.getDecl() == req) { - out << "(dynamic)"; - } else { - witness.getDecl()->dumpRef(out); + normal->forEachValueWitness([&](const ValueDecl *req, + Witness witness) { + printRecArbitrary([&](StringRef label) { + printHead("value", ASTNodeColor, label); + printFieldQuoted(req->getName(), "req"); + if (!witness) + printFlag("no_witness"); + else if (witness.getDecl() == req) + printFlag("dynamic_witness"); + else + printFieldQuotedRaw([&](raw_ostream &out) { + witness.getDecl()->dumpRef(out); + }, "witness"); + printFoot(); + }); + }); + + for (auto sigConf : normal->getSignatureConformances()) { + printRec(sigConf, visited); + } } - PrintWithColorRAII(out, ParenthesisColor) << ')'; + + if (auto condReqs = normal->getConditionalRequirementsIfAvailable()) { + for (auto requirement : *condReqs) { + printRec(requirement); + } + } else { + printRecArbitrary([&](StringRef label) { + printHead("", + ASTNodeColor); + printFoot(); + }); + } + break; + } + + case ProtocolConformanceKind::Self: { + printCommon("self_conformance"); + break; + } + + case ProtocolConformanceKind::Inherited: { + auto conf = cast(conformance); + printCommon("inherited_conformance"); + if (!shouldPrintDetails) + break; + + printRec(conf->getInheritedConformance(), visited); + break; + } + + case ProtocolConformanceKind::Specialized: { + auto conf = cast(conformance); + printCommon("specialized_conformance"); + if (!shouldPrintDetails) + break; + + printRec(conf->getSubstitutionMap(), visited); + if (auto condReqs = conf->getConditionalRequirementsIfAvailableOrCached(/*computeIfPossible=*/false)) { + for (auto subReq : *condReqs) { + printRec(subReq); + } + } else { + printRecArbitrary([&](StringRef label) { + printHead("", + ASTNodeColor); + printFoot(); + }); + } + printRec(conf->getGenericConformance(), visited); + break; + } + + case ProtocolConformanceKind::Builtin: { + printCommon("builtin_conformance"); + } + } + + printFoot(); + } + + void visitPackConformance(const PackConformance *conformance, + VisitedConformances &visited, StringRef label) { + printHead("pack_conformance", ASTNodeColor, label); + + printFieldQuoted(Type(conformance->getType()), "type"); + printFieldQuoted(conformance->getProtocol()->getName(), "protocol"); + + for (auto conformanceRef : conformance->getPatternConformances()) { + printRec(conformanceRef, visited); + } + + printFoot(); + } + + void visitSubstitutionMap(SubstitutionMap map, + SubstitutionMap::DumpStyle style, + VisitedConformances &visited, StringRef label) { + // In Minimal style, use single quote so this dump can appear in + // double-quoted fields without escaping. + std::optional> restoreQuote; + if (style == SubstitutionMap::DumpStyle::Minimal) + restoreQuote.emplace(quote, '\''); + + auto genericSig = map.getGenericSignature(); + printHead("substitution_map", ASTNodeColor, label); + SWIFT_DEFER { printFoot(); }; + + if (genericSig.isNull()) { + printFlag("null_generic_signature"); + return; + } + + printFieldQuotedRaw([&](raw_ostream &out) { genericSig->print(out); }, + "generic_signature"); + + auto printSubstitution = [&](GenericTypeParamType * genericParam, + Type replacementType) { + printFieldQuotedRaw([&](raw_ostream &out) { + genericParam->print(out); + out << " -> "; + if (replacementType) { + PrintOptions opts; + opts.PrintForSIL = true; + opts.PrintTypesForDebugging = true; + replacementType->print(out, opts); + } + else + out << ""; + }, ""); + }; + + auto genericParams = genericSig.getGenericParams(); + auto replacementTypes = + static_cast(map).getReplacementTypesBuffer(); + for (unsigned i : indices(genericParams)) { + if (style == SubstitutionMap::DumpStyle::Minimal) { + printSubstitution(genericParams[i], replacementTypes[i]); + } else { + printRecArbitrary([&](StringRef label) { + printHead("substitution", ASTNodeColor, label); + printSubstitution(genericParams[i], replacementTypes[i]); + printFoot(); + }); + } + } + + // A minimal dump doesn't need the details about the conformances, a lot of + // that info can be inferred from the signature. + if (style == SubstitutionMap::DumpStyle::Minimal) + return; + + auto conformances = map.getConformances(); + for (const auto &req : genericSig.getRequirements()) { + if (req.getKind() != RequirementKind::Conformance) + continue; + + printRecArbitrary([&](StringRef label) { + printHead("conformance", ASTNodeColor, label); + printFieldQuoted(req.getFirstType(), "type"); + printRec(conformances.front(), visited); + printFoot(); }); - - for (auto sigConf : normal->getSignatureConformances()) { - out << '\n'; - dumpProtocolConformanceRefRec(sigConf, out, indent + 2, visited); - } + conformances = conformances.slice(1); } - - if (auto condReqs = normal->getConditionalRequirementsIfAvailable()) { - for (auto requirement : *condReqs) { - out << '\n'; - out.indent(indent + 2); - requirement.dump(out); - } - } else { - out << '\n'; - out.indent(indent + 2); - out << "(conditional requirements unable to be computed)"; - } - break; } +}; - case ProtocolConformanceKind::Self: { - printCommon("self"); - break; - } - - case ProtocolConformanceKind::Inherited: { - auto conf = cast(conformance); - printCommon("inherited"); - if (!shouldPrintDetails) - break; - - out << '\n'; - dumpProtocolConformanceRec(conf->getInheritedConformance(), out, indent + 2, - visited); - break; - } - - case ProtocolConformanceKind::Specialized: { - auto conf = cast(conformance); - printCommon("specialized"); - if (!shouldPrintDetails) - break; - - out << '\n'; - dumpSubstitutionMapRec(conf->getSubstitutionMap(), out, - SubstitutionMap::DumpStyle::Full, indent + 2, - visited); - out << '\n'; - if (auto condReqs = conf->getConditionalRequirementsIfAvailableOrCached( - /*computeIfPossible=*/false)) { - for (auto subReq : *condReqs) { - out.indent(indent + 2); - subReq.dump(out); - out << '\n'; - } - } else { - out.indent(indent + 2); - out << "(conditional requirements unable to be computed)\n"; - } - dumpProtocolConformanceRec(conf->getGenericConformance(), out, indent + 2, - visited); - break; - } - - case ProtocolConformanceKind::Builtin: { - printCommon("builtin"); - } - } - - PrintWithColorRAII(out, ParenthesisColor) << ')'; +void PrintBase::printRec(SubstitutionMap map, VisitedConformances &visited, + StringRef label) { + printRecArbitrary([&](StringRef label) { + PrintConformance(OS, Indent) + .visitSubstitutionMap(map, SubstitutionMap::DumpStyle::Full, visited, + label); + }, label); } -static void dumpPackConformanceRec( - const PackConformance *conformance, llvm::raw_ostream &out, - unsigned indent, - llvm::SmallPtrSetImpl &visited) { - out.indent(indent); - PrintWithColorRAII(out, ParenthesisColor) << '('; - out << "pack_conformance type=" << Type(conformance->getType()) - << " protocol=" << conformance->getProtocol()->getName(); - - auto conformances = conformance->getPatternConformances(); - if (!conformances.empty()) { - out << "\n"; - - for (auto conformanceRef : conformances) { - dumpProtocolConformanceRefRec(conformanceRef, out, indent, visited); - } - } - - PrintWithColorRAII(out, ParenthesisColor) << ')'; +void PrintBase::printRec(const ProtocolConformanceRef &ref, + VisitedConformances &visited, StringRef label) { + printRecArbitrary([&](StringRef label) { + PrintConformance(OS, Indent) + .visitProtocolConformanceRef(ref, visited, label); + }, label); } -static void dumpSubstitutionMapRec( - SubstitutionMap map, llvm::raw_ostream &out, - SubstitutionMap::DumpStyle style, unsigned indent, - llvm::SmallPtrSetImpl &visited) { - auto genericSig = map.getGenericSignature(); - out.indent(indent); - - auto printParen = [&](char p) { - PrintWithColorRAII(out, ParenthesisColor) << p; - }; - printParen('('); - SWIFT_DEFER { printParen(')'); }; - out << "substitution_map generic_signature="; - if (genericSig.isNull()) { - out << ""; - return; - } - - genericSig->print(out); - auto genericParams = genericSig.getGenericParams(); - auto replacementTypes = - static_cast(map).getReplacementTypesBuffer(); - for (unsigned i : indices(genericParams)) { - if (style == SubstitutionMap::DumpStyle::Minimal) { - out << " "; - } else { - out << "\n"; - out.indent(indent + 2); - } - printParen('('); - out << "substitution "; - genericParams[i]->print(out); - out << " -> "; - if (replacementTypes[i]) { - PrintOptions opts; - opts.PrintForSIL = true; - opts.PrintTypesForDebugging = true; - replacementTypes[i]->print(out, opts); - } - else - out << "<>"; - printParen(')'); - } - // A minimal dump doesn't need the details about the conformances, a lot of - // that info can be inferred from the signature. - if (style == SubstitutionMap::DumpStyle::Minimal) - return; - - auto conformances = map.getConformances(); - for (const auto &req : genericSig.getRequirements()) { - if (req.getKind() != RequirementKind::Conformance) - continue; - - out << "\n"; - out.indent(indent + 2); - printParen('('); - out << "conformance type="; - req.getFirstType()->print(out); - out << "\n"; - dumpProtocolConformanceRefRec(conformances.front(), out, indent + 4, - visited); - - printParen(')'); - conformances = conformances.slice(1); - } +void PrintBase::printRec(const ProtocolConformance *conformance, + VisitedConformances &visited, StringRef label) { + printRecArbitrary([&](StringRef label) { + PrintConformance(OS, Indent) + .visitProtocolConformance(conformance, visited, label); + }, label); } +} // end anonymous namespace + void ProtocolConformanceRef::dump() const { dump(llvm::errs()); llvm::errs() << '\n'; @@ -3683,12 +3730,12 @@ void ProtocolConformanceRef::dump(llvm::raw_ostream &out, unsigned indent, if (!details && isConcrete()) visited.insert(getConcrete()); - dumpProtocolConformanceRefRec(*this, out, indent, visited); + PrintConformance(out, indent).visitProtocolConformanceRef(*this, visited, ""); } void ProtocolConformanceRef::print(llvm::raw_ostream &out) const { llvm::SmallPtrSet visited; - dumpProtocolConformanceRefRec(*this, out, 0, visited); + PrintConformance(out, 0).visitProtocolConformanceRef(*this, visited, ""); } void ProtocolConformance::dump() const { @@ -3699,18 +3746,18 @@ void ProtocolConformance::dump() const { void ProtocolConformance::dump(llvm::raw_ostream &out, unsigned indent) const { llvm::SmallPtrSet visited; - dumpProtocolConformanceRec(this, out, indent, visited); + PrintConformance(out, indent).visitProtocolConformance(this, visited, ""); } void PackConformance::dump(llvm::raw_ostream &out, unsigned indent) const { llvm::SmallPtrSet visited; - dumpPackConformanceRec(this, out, indent, visited); + PrintConformance(out, indent).visitPackConformance(this, visited, ""); } void SubstitutionMap::dump(llvm::raw_ostream &out, DumpStyle style, unsigned indent) const { llvm::SmallPtrSet visited; - dumpSubstitutionMapRec(*this, out, style, indent, visited); + PrintConformance(out, indent).visitSubstitutionMap(*this, style, visited, ""); } void SubstitutionMap::dump() const { @@ -3723,43 +3770,10 @@ void SubstitutionMap::dump() const { //===----------------------------------------------------------------------===// namespace { - class PrintType : public TypeVisitor { - raw_ostream &OS; - unsigned Indent; - - raw_ostream &printCommon(StringRef label, StringRef name) { - OS.indent(Indent); - PrintWithColorRAII(OS, ParenthesisColor) << '('; - if (!label.empty()) { - PrintWithColorRAII(OS, TypeFieldColor) << label; - OS << "="; - } - - PrintWithColorRAII(OS, TypeColor) << name; - return OS; - } - - // Print a single flag. - raw_ostream &printFlag(StringRef name) { - PrintWithColorRAII(OS, TypeFieldColor) << " " << name; - return OS; - } - - // Print a single flag if it is set. - raw_ostream &printFlag(bool isSet, StringRef name) { - if (isSet) - printFlag(name); - - return OS; - } - - // Print a field with a value. - template - raw_ostream &printField(StringRef name, const T &value) { - OS << " "; - PrintWithColorRAII(OS, TypeFieldColor) << name; - OS << "=" << value; - return OS; + class PrintType : public TypeVisitor, + public PrintBase { + void printCommon(StringRef name, StringRef label) { + printHead(name, TypeColor, label); } void dumpParameterFlags(ParameterTypeFlags paramFlags) { @@ -3767,79 +3781,59 @@ namespace { printFlag(paramFlags.isAutoClosure(), "autoclosure"); printFlag(paramFlags.isNonEphemeral(), "nonEphemeral"); printFlag(paramFlags.isCompileTimeConst(), "compileTimeConst"); - switch (paramFlags.getValueOwnership()) { - case ValueOwnership::Default: break; - case ValueOwnership::Owned: printFlag("owned"); break; - case ValueOwnership::Shared: printFlag("shared"); break; - case ValueOwnership::InOut: printFlag("inout"); break; - } + printFlag(getDumpString(paramFlags.getValueOwnership())); } public: - PrintType(raw_ostream &os, unsigned indent) : OS(os), Indent(indent) { } - - void printRec(Type type) { - printRec("", type); - } - - void printRec(StringRef label, Type type) { - OS << "\n"; - - if (type.isNull()) - OS << "<>"; - else { - Indent += 2; - visit(type, label); - Indent -=2; - } - } + using PrintBase::PrintBase; #define TRIVIAL_TYPE_PRINTER(Class,Name) \ void visit##Class##Type(Class##Type *T, StringRef label) { \ - printCommon(label, #Name "_type") << ")"; \ + printCommon(#Name "_type", label); printFoot(); \ } void visitErrorType(ErrorType *T, StringRef label) { - printCommon(label, "error_type"); + printCommon("error_type", label); if (auto originalType = T->getOriginalType()) - printRec("original_type", originalType); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRec(originalType, "original_type"); + printFoot(); } TRIVIAL_TYPE_PRINTER(Unresolved, unresolved) void visitPlaceholderType(PlaceholderType *T, StringRef label) { - printCommon(label, "placeholder_type"); + printCommon("placeholder_type", label); auto originator = T->getOriginator(); if (auto *typeVar = originator.dyn_cast()) { - printRec("type_variable", typeVar); + printRec(typeVar, "type_variable"); } else if (auto *VD = originator.dyn_cast()) { - VD->dumpRef(PrintWithColorRAII(OS, DeclColor).getOS()); + printFieldQuotedRaw([&](raw_ostream &OS) { VD->dumpRef(OS); }, "", + DeclColor); } else if (auto *EE = originator.dyn_cast()) { printFlag("error_expr"); } else if (auto *DMT = originator.dyn_cast()) { - printRec("dependent_member_type", DMT); + printRec(DMT, "dependent_member_type"); } else if (originator.is()) { printFlag("placeholder_type_repr"); } else { assert(false && "unknown originator"); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitBuiltinIntegerType(BuiltinIntegerType *T, StringRef label) { - printCommon(label, "builtin_integer_type"); + printCommon("builtin_integer_type", label); if (T->isFixedWidth()) - printField("bit_width", T->getFixedWidth()); + printField(T->getFixedWidth(), "bit_width"); else printFlag("word_sized"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitBuiltinFloatType(BuiltinFloatType *T, StringRef label) { - printCommon(label, "builtin_float_type"); - printField("bit_width", T->getBitWidth()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printCommon("builtin_float_type", label); + printField(T->getBitWidth(), "bit_width"); + printFoot(); } TRIVIAL_TYPE_PRINTER(BuiltinIntegerLiteral, builtin_integer_literal) @@ -3856,483 +3850,505 @@ namespace { TRIVIAL_TYPE_PRINTER(SILToken, sil_token) void visitBuiltinVectorType(BuiltinVectorType *T, StringRef label) { - printCommon(label, "builtin_vector_type"); - printField("num_elements", T->getNumElements()); + printCommon("builtin_vector_type", label); + printField(T->getNumElements(), "num_elements"); printRec(T->getElementType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitTypeAliasType(TypeAliasType *T, StringRef label) { - printCommon(label, "type_alias_type"); - printField("decl", T->getDecl()->printRef()); - PrintWithColorRAII(OS, TypeColor) << " underlying="; - if (auto underlying = T->getSinglyDesugaredType()) { - PrintWithColorRAII(OS, TypeColor) - << "'" << underlying->getString() << "'"; - } else { - PrintWithColorRAII(OS, TypeColor) << "<<>>"; - } - if (T->getParent()) - printRec("parent", T->getParent()); + printCommon("type_alias_type", label); - for (const auto &arg : T->getDirectGenericArgs()) - printRec(arg); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFieldQuoted(T->getDecl()->printRef(), "decl"); + if (auto underlying = T->getSinglyDesugaredType()) { + printField(underlying, "underlying", TypeColor); + } else { + printFlag("unresolved_underlying"); + } + + if (T->getParent()) + printRec(T->getParent(), "parent"); + printRecRange(T->getDirectGenericArgs(), "direct_generic_args"); + + printFoot(); } void visitPackType(PackType *T, StringRef label) { - printCommon(label, "pack_type"); - printField("num_elements", T->getNumElements()); - Indent += 2; + printCommon("pack_type", label); + + printField(T->getNumElements(), "num_elements"); + for (Type elt : T->getElementTypes()) { printRec(elt); } - Indent -= 2; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } void visitSILPackType(SILPackType *T, StringRef label) { - printCommon(label, "sil_pack_type"); - printField("element_is_address", T->isElementAddress()); - printField("num_elements", T->getNumElements()); - Indent += 2; + printCommon("sil_pack_type", label); + + printField(T->isElementAddress(), "element_is_address"); + printField(T->getNumElements(), "num_elements"); + for (Type elt : T->getElementTypes()) { printRec(elt); } - Indent -= 2; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } void visitPackExpansionType(PackExpansionType *T, StringRef label) { - printCommon(label, "pack_expansion_type"); - printRec("pattern", T->getPatternType()); - printRec("count", T->getCountType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printCommon("pack_expansion_type", label); + printRec(T->getPatternType(), "pattern"); + printRec(T->getCountType(), "count"); + printFoot(); } void visitPackElementType(PackElementType *T, StringRef label) { - printCommon(label, "element_type"); - printField("level", T->getLevel()); - printRec("pack", T->getPackType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printCommon("element_type", label); + + printField(T->getLevel(), "level"); + + printRec(T->getPackType(), "pack"); + + printFoot(); } void visitParenType(ParenType *T, StringRef label) { - printCommon(label, "paren_type"); + printCommon("paren_type", label); + printRec(T->getUnderlyingType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } void visitTupleType(TupleType *T, StringRef label) { - printCommon(label, "tuple_type"); - printField("num_elements", T->getNumElements()); - Indent += 2; + printCommon("tuple_type", label); + + printField(T->getNumElements(), "num_elements"); + for (const auto &elt : T->getElements()) { - OS << "\n"; - OS.indent(Indent) << "("; - PrintWithColorRAII(OS, TypeFieldColor) << "tuple_type_elt"; - if (elt.hasName()) - printField("name", elt.getName().str()); - printRec(elt.getType()); - OS << ")"; + printRecArbitrary([&](StringRef label) { + printHead("tuple_type_elt", FieldLabelColor, label); + if (elt.hasName()) + printFieldQuoted(elt.getName().str(), "name"); + printRec(elt.getType()); + printFoot(); + }); } - Indent -= 2; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } #define REF_STORAGE(Name, name, ...) \ void visit##Name##StorageType(Name##StorageType *T, StringRef label) { \ - printCommon(label, #name "_storage_type"); \ + printCommon(#name "_storage_type", label); \ printRec(T->getReferentType()); \ - PrintWithColorRAII(OS, ParenthesisColor) << ')'; \ + printFoot(); \ } #include "swift/AST/ReferenceStorage.def" - void visitEnumType(EnumType *T, StringRef label) { - printCommon(label, "enum_type"); - printField("decl", T->getDecl()->printRef()); - if (T->getParent()) - printRec("parent", T->getParent()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; +#define VISIT_NOMINAL_TYPE(TypeClass, Name) \ + void visit##TypeClass(TypeClass *T, StringRef label) { \ + printCommon(#Name, label); \ + \ + printFieldQuoted(T->getDecl()->printRef(), "decl"); \ + \ + if (T->getParent()) \ + printRec(T->getParent(), "parent"); \ + \ + printFoot(); \ } - void visitStructType(StructType *T, StringRef label) { - printCommon(label, "struct_type"); - printField("decl", T->getDecl()->printRef()); - if (T->getParent()) - printRec("parent", T->getParent()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } + VISIT_NOMINAL_TYPE(EnumType, enum_type) + VISIT_NOMINAL_TYPE(StructType, struct_type) + VISIT_NOMINAL_TYPE(ClassType, class_type) + VISIT_NOMINAL_TYPE(ProtocolType, protocol_type) - void visitClassType(ClassType *T, StringRef label) { - printCommon(label, "class_type"); - printField("decl", T->getDecl()->printRef()); - if (T->getParent()) - printRec("parent", T->getParent()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } - - void visitProtocolType(ProtocolType *T, StringRef label) { - printCommon(label, "protocol_type"); - printField("decl", T->getDecl()->printRef()); - if (T->getParent()) - printRec("parent", T->getParent()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; - } +#undef VISIT_NOMINAL_TYPE void visitBuiltinTupleType(BuiltinTupleType *T, StringRef label) { - printCommon(label, "builtin_tuple_type"); - printField("decl", T->getDecl()->printRef()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printCommon("builtin_tuple_type", label); + printFieldQuoted(T->getDecl()->printRef(), "decl"); + printFoot(); } void visitMetatypeType(MetatypeType *T, StringRef label) { - printCommon(label, "metatype_type"); + printCommon("metatype_type", label); + if (T->hasRepresentation()) - OS << " " << getMetatypeRepresentationString(T->getRepresentation()); + printFlag(getDumpString(T->getRepresentation())); + printRec(T->getInstanceType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } void visitExistentialMetatypeType(ExistentialMetatypeType *T, StringRef label) { - printCommon(label, "existential_metatype_type"); + printCommon("existential_metatype_type", label); + if (T->hasRepresentation()) - OS << " " << getMetatypeRepresentationString(T->getRepresentation()); + printFlag(getDumpString(T->getRepresentation())); + printRec(T->getInstanceType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } void visitModuleType(ModuleType *T, StringRef label) { - printCommon(label, "module_type"); - printField("module", T->getModule()->getName()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printCommon("module_type", label); + printDeclNameField(T->getModule(), "module"); + printFoot(); } void visitDynamicSelfType(DynamicSelfType *T, StringRef label) { - printCommon(label, "dynamic_self_type"); + printCommon("dynamic_self_type", label); printRec(T->getSelfType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void printArchetypeCommon(ArchetypeType *T, StringRef className, StringRef label) { - printCommon(label, className); - printField("address", static_cast(T)); - printRec("interface_type", T->getInterfaceType()); + printCommon(className, label); + + printField(static_cast(T), "address"); printFlag(T->requiresClass(), "class"); if (auto layout = T->getLayoutConstraint()) { - OS << " layout="; - layout->print(OS); + printFieldRaw([&](raw_ostream &OS) { + layout->print(OS); + }, "layout"); } for (auto proto : T->getConformsTo()) - printField("conforms_to", proto->printRef()); - if (auto superclass = T->getSuperclass()) - printRec("superclass", superclass); - + printFieldQuoted(proto->printRef(), "conforms_to"); } - + + void printArchetypeCommonRec(ArchetypeType *T) { + printRec(T->getInterfaceType(), "interface_type"); + if (auto superclass = T->getSuperclass()) + printRec(superclass, "superclass"); + } + void visitPrimaryArchetypeType(PrimaryArchetypeType *T, StringRef label) { printArchetypeCommon(T, "primary_archetype_type", label); - printField("name", T->getFullName()); - OS << "\n"; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFieldQuoted(T->getFullName(), "name"); + + printArchetypeCommonRec(T); + + printFoot(); } void visitOpenedArchetypeType(OpenedArchetypeType *T, StringRef label) { printArchetypeCommon(T, "opened_archetype_type", label); - printRec("opened_existential", - T->getGenericEnvironment()->getOpenedExistentialType()); - printField("opened_existential_id", T->getOpenedExistentialID()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFieldQuoted(T->getOpenedExistentialID(), "opened_existential_id"); + + printArchetypeCommonRec(T); + printRec(T->getGenericEnvironment()->getOpenedExistentialType(), "opened_existential"); + + printFoot(); } void visitOpaqueTypeArchetypeType(OpaqueTypeArchetypeType *T, StringRef label) { printArchetypeCommon(T, "opaque_type", label); - printField("decl", T->getDecl()->getNamingDecl()->printRef()); + + printFieldQuoted(T->getDecl()->getNamingDecl()->printRef(), "decl"); + + printArchetypeCommonRec(T); if (!T->getSubstitutions().empty()) { - OS << '\n'; - SmallPtrSet Dumped; - dumpSubstitutionMapRec(T->getSubstitutions(), OS, - SubstitutionMap::DumpStyle::Full, - Indent + 2, Dumped); + printRec(T->getSubstitutions()); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } void visitPackArchetypeType(PackArchetypeType *T, StringRef label) { printArchetypeCommon(T, "pack_archetype_type", label); - printField("name", T->getFullName()); - OS << "\n"; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFieldQuoted(T->getFullName(), "name"); + printArchetypeCommonRec(T); + printFoot(); } void visitElementArchetypeType(ElementArchetypeType *T, StringRef label) { printArchetypeCommon(T, "element_archetype_type", label); - printField("opened_element_id", T->getOpenedElementID()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFieldQuoted(T->getOpenedElementID(), "opened_element_id"); + printFoot(); } void visitGenericTypeParamType(GenericTypeParamType *T, StringRef label) { - printCommon(label, "generic_type_param_type"); - printField("depth", T->getDepth()); - printField("index", T->getIndex()); + printCommon("generic_type_param_type", label); + printField(T->getDepth(), "depth"); + printField(T->getIndex(), "index"); if (auto decl = T->getDecl()) - printField("decl", decl->printRef()); + printFieldQuoted(decl->printRef(), "decl"); printFlag(T->isParameterPack(), "pack"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitDependentMemberType(DependentMemberType *T, StringRef label) { - printCommon(label, "dependent_member_type"); + printCommon("dependent_member_type", label); + if (auto assocType = T->getAssocType()) { - printField("assoc_type", assocType->printRef()); + printFieldQuoted(assocType->printRef(), "assoc_type"); } else { - printField("name", T->getName()); + printFieldQuoted(T->getName(), "name"); } - printRec("base", T->getBase()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printRec(T->getBase(), "base"); + + printFoot(); } - void printAnyFunctionParams(ArrayRef params, - StringRef label) { - printCommon(label, "function_params"); - printField("num_params", params.size()); - Indent += 2; - for (const auto ¶m : params) { - OS << "\n"; - OS.indent(Indent) << "("; - PrintWithColorRAII(OS, TypeFieldColor) << "param"; - if (param.hasLabel()) - printField("name", param.getLabel().str()); - if (param.hasInternalLabel()) - printField("internal_name", param.getInternalLabel().str()); - dumpParameterFlags(param.getParameterFlags()); - printRec(param.getPlainType()); - OS << ")"; - } - Indent -= 2; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + void printAnyFunctionParamsRec(ArrayRef params, + StringRef label) { + printRecArbitrary([&](StringRef label) { + printCommon("function_params", label); + + printField(params.size(), "num_params"); + for (const auto ¶m : params) { + printRecArbitrary([&](StringRef label) { + printHead("param", FieldLabelColor, label); + + if (param.hasLabel()) + printFieldQuoted(param.getLabel().str(), "name"); + if (param.hasInternalLabel()) + printFieldQuoted(param.getInternalLabel().str(), "internal_name"); + dumpParameterFlags(param.getParameterFlags()); + + printRec(param.getPlainType()); + + printFoot(); + }); + } + printFoot(); + }, label); } - void printAnyFunctionTypeCommon(AnyFunctionType *T, StringRef label, + void printClangTypeRec(const ClangTypeInfo &info, const ASTContext &ctx) { + // [TODO: Improve-Clang-type-printing] + if (!info.empty()) { + printRecArbitrary([&](StringRef label) { + printHead("clang_type", ASTNodeColor, label); + printNameRaw([&](raw_ostream &OS) { + auto &clangCtx = ctx.getClangModuleLoader()->getClangASTContext(); + info.dump(OS, clangCtx); + }); + printFoot(); + }); + } + } + + void printAnyFunctionTypeCommonRec(AnyFunctionType *T, StringRef label, StringRef name) { - printCommon(label, name); + printCommon(name, label); if (T->hasExtInfo()) { SILFunctionType::Representation representation = T->getExtInfo().getSILRepresentation(); if (representation != SILFunctionType::Representation::Thick) { - printField("representation", - getSILFunctionTypeRepresentationString(representation)); + printField(representation, "representation"); } printFlag(!T->isNoEscape(), "escaping"); printFlag(T->isSendable(), "Sendable"); printFlag(T->isAsync(), "async"); printFlag(T->isThrowing(), "throws"); } - if (Type globalActor = T->getGlobalActor()) { - printField("global_actor", globalActor.getString()); + printFieldQuoted(globalActor.getString(), "global_actor"); } - OS << "\n"; - Indent += 2; - // [TODO: Improve-Clang-type-printing] - if (!T->getClangTypeInfo().empty()) { - std::string s; - llvm::raw_string_ostream os(s); - auto &ctx = T->getASTContext().getClangModuleLoader() - ->getClangASTContext(); - T->getClangTypeInfo().dump(os, ctx); - printField("clang_type", os.str()); - } - - printAnyFunctionParams(T->getParams(), "input"); - Indent -=2; - printRec("output", T->getResult()); + printClangTypeRec(T->getClangTypeInfo(), T->getASTContext()); + printAnyFunctionParamsRec(T->getParams(), "input"); + printRec(T->getResult(), "output"); } void visitFunctionType(FunctionType *T, StringRef label) { - printAnyFunctionTypeCommon(T, label, "function_type"); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printAnyFunctionTypeCommonRec(T, label, "function_type"); + printFoot(); } void visitGenericFunctionType(GenericFunctionType *T, StringRef label) { - printAnyFunctionTypeCommon(T, label, "generic_function_type"); + printAnyFunctionTypeCommonRec(T, label, "generic_function_type"); // FIXME: generic signature dumping needs improvement - OS << "\n"; - OS.indent(Indent + 2) << "("; - printField("generic_sig", T->getGenericSignature()->getAsString()); - OS << ")"; - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRecArbitrary([&](StringRef label) { + printHead("generic_sig", TypeColor, label); + printFieldQuoted(T->getGenericSignature()->getAsString(), ""); + printFoot(); + }); + printFoot(); } void visitSILFunctionType(SILFunctionType *T, StringRef label) { - printCommon(label, "sil_function_type"); - printField("type", T->getString()); + printCommon("sil_function_type", label); + printFieldQuoted(T->getString(), "type"); for (auto param : T->getParameters()) { - printRec("input", param.getInterfaceType()); + printRec(param.getInterfaceType(), "input"); } for (auto yield : T->getYields()) { - printRec("yield", yield.getInterfaceType()); + printRec(yield.getInterfaceType(), "yield"); } for (auto result : T->getResults()) { - printRec("result", result.getInterfaceType()); + printRec(result.getInterfaceType(), "result"); } if (auto error = T->getOptionalErrorResult()) { - printRec("error", error->getInterfaceType()); + printRec(error->getInterfaceType(), "error"); } - OS << '\n'; - T->getPatternSubstitutions().dump(OS, SubstitutionMap::DumpStyle::Full, - Indent+2); - OS << '\n'; - T->getInvocationSubstitutions().dump(OS, SubstitutionMap::DumpStyle::Full, - Indent+2); - // [TODO: Improve-Clang-type-printing] - if (!T->getClangTypeInfo().empty()) { - std::string s; - llvm::raw_string_ostream os(s); - auto &ctx = - T->getASTContext().getClangModuleLoader()->getClangASTContext(); - T->getClangTypeInfo().dump(os, ctx); - printField("clang_type", os.str()); - } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRec(T->getPatternSubstitutions()); + printRec(T->getInvocationSubstitutions()); + printClangTypeRec(T->getClangTypeInfo(), T->getASTContext()); + + printFoot(); } void visitSILBlockStorageType(SILBlockStorageType *T, StringRef label) { - printCommon(label, "sil_block_storage_type"); + printCommon("sil_block_storage_type", label); printRec(T->getCaptureType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitSILMoveOnlyWrappedType(SILMoveOnlyWrappedType *T, StringRef label) { - printCommon(label, "sil_move_only_type"); + printCommon("sil_move_only_type", label); printRec(T->getInnerType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitSILBoxType(SILBoxType *T, StringRef label) { - printCommon(label, "sil_box_type"); + printCommon("sil_box_type", label); // FIXME: Print the structure of the type. - printField("type", T->getString()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFieldQuoted(T->getString(), "type"); + printFoot(); } void visitArraySliceType(ArraySliceType *T, StringRef label) { - printCommon(label, "array_slice_type"); + printCommon("array_slice_type", label); printRec(T->getBaseType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitOptionalType(OptionalType *T, StringRef label) { - printCommon(label, "optional_type"); + printCommon("optional_type", label); printRec(T->getBaseType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitDictionaryType(DictionaryType *T, StringRef label) { - printCommon(label, "dictionary_type"); - printRec("key", T->getKeyType()); - printRec("value", T->getValueType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printCommon("dictionary_type", label); + printRec(T->getKeyType(), "key"); + printRec(T->getValueType(), "value"); + printFoot(); } void visitVariadicSequenceType(VariadicSequenceType *T, StringRef label) { - printCommon(label, "variadic_sequence_type"); + printCommon("variadic_sequence_type", label); printRec(T->getBaseType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitProtocolCompositionType(ProtocolCompositionType *T, StringRef label) { - printCommon(label, "protocol_composition_type"); - if (T->hasExplicitAnyObject()) - OS << " any_object"; + + printCommon("protocol_composition_type", label); + + printFlag(T->hasExplicitAnyObject(), "any_object"); + for (auto proto : T->getMembers()) { printRec(proto); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + + printFoot(); } void visitParameterizedProtocolType(ParameterizedProtocolType *T, StringRef label) { - printCommon(label, "parameterized_protocol_type"); - printRec("base", T->getBaseType()); + printCommon("parameterized_protocol_type", label); + printRec(T->getBaseType(), "base"); for (auto arg : T->getArgs()) { printRec(arg); } - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitExistentialType(ExistentialType *T, StringRef label) { - printCommon(label, "existential_type"); + printCommon("existential_type", label); printRec(T->getConstraintType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitLValueType(LValueType *T, StringRef label) { - printCommon(label, "lvalue_type"); + printCommon("lvalue_type", label); printRec(T->getObjectType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitInOutType(InOutType *T, StringRef label) { - printCommon(label, "inout_type"); + printCommon("inout_type", label); printRec(T->getObjectType()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitUnboundGenericType(UnboundGenericType *T, StringRef label) { - printCommon(label, "unbound_generic_type"); - printField("decl", T->getDecl()->printRef()); + printCommon("unbound_generic_type", label); + printFieldQuoted(T->getDecl()->printRef(), "decl"); if (T->getParent()) - printRec("parent", T->getParent()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printRec(T->getParent(), "parent"); + printFoot(); } void visitBoundGenericClassType(BoundGenericClassType *T, StringRef label) { - printCommon(label, "bound_generic_class_type"); - printField("decl", T->getDecl()->printRef()); + printCommon("bound_generic_class_type", label); + printFieldQuoted(T->getDecl()->printRef(), "decl"); if (T->getParent()) - printRec("parent", T->getParent()); + printRec(T->getParent(), "parent"); for (auto arg : T->getGenericArgs()) printRec(arg); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitBoundGenericStructType(BoundGenericStructType *T, StringRef label) { - printCommon(label, "bound_generic_struct_type"); - printField("decl", T->getDecl()->printRef()); + printCommon("bound_generic_struct_type", label); + printFieldQuoted(T->getDecl()->printRef(), "decl"); if (T->getParent()) - printRec("parent", T->getParent()); + printRec(T->getParent(), "parent"); for (auto arg : T->getGenericArgs()) printRec(arg); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitBoundGenericEnumType(BoundGenericEnumType *T, StringRef label) { - printCommon(label, "bound_generic_enum_type"); - printField("decl", T->getDecl()->printRef()); + printCommon("bound_generic_enum_type", label); + printFieldQuoted(T->getDecl()->printRef(), "decl"); if (T->getParent()) - printRec("parent", T->getParent()); + printRec(T->getParent(), "parent"); for (auto arg : T->getGenericArgs()) printRec(arg); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printFoot(); } void visitTypeVariableType(TypeVariableType *T, StringRef label) { - printCommon(label, "type_variable_type"); - printField("id", T->getID()); - PrintWithColorRAII(OS, ParenthesisColor) << ')'; + printCommon("type_variable_type", label); + printField(T->getID(), "id"); + printFoot(); } #undef TRIVIAL_TYPE_PRINTER }; + + void PrintBase::printRec(Type type, StringRef label) { + printRecArbitrary([&](StringRef label) { + if (type.isNull()) { + printHead("", DeclColor, label); + printFoot(); + } else { + PrintType(OS, Indent, GetTypeOfExpr, GetTypeOfTypeRepr, + GetTypeOfKeyPathComponent).visit(type, label); + } + }, label); + } } // end anonymous namespace void Type::dump() const { @@ -4452,34 +4468,7 @@ void Requirement::dump() const { llvm::errs() << '\n'; } void Requirement::dump(raw_ostream &out) const { - switch (getKind()) { - case RequirementKind::SameShape: - out << "same_shape: "; - break; - case RequirementKind::Conformance: - out << "conforms_to: "; - break; - case RequirementKind::Layout: - out << "layout: "; - break; - case RequirementKind::Superclass: - out << "superclass: "; - break; - case RequirementKind::SameType: - out << "same_type: "; - break; - } - - PrintOptions opts; - opts.ProtocolQualifiedDependentMemberTypes = true; - - getFirstType().print(out, opts); - out << " "; - - if (getKind() != RequirementKind::Layout && getSecondType()) - getSecondType().print(out, opts); - else if (getLayoutConstraint()) - out << getLayoutConstraint(); + PrintBase(out, 0).visitRequirement(*this); } void SILParameterInfo::dump() const { diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 32cd78a4346..c83d7709546 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1222,14 +1222,19 @@ StringRef ObjectLiteralExpr::getLiteralKindRawName() const { llvm_unreachable("unspecified literal"); } -StringRef ObjectLiteralExpr::getLiteralKindPlainName() const { - switch (getLiteralKind()) { +StringRef ObjectLiteralExpr:: +getLiteralKindPlainName(ObjectLiteralExpr::LiteralKind kind) { + switch (kind) { #define POUND_OBJECT_LITERAL(Name, Desc, Proto) case Name: return Desc; #include "swift/AST/TokenKinds.def" } llvm_unreachable("unspecified literal"); } +StringRef ObjectLiteralExpr::getLiteralKindPlainName() const { + return ObjectLiteralExpr::getLiteralKindPlainName(getLiteralKind()); +} + ConstructorDecl *OtherConstructorDeclRefExpr::getDecl() const { return cast_or_null(Ctor.getDecl()); } diff --git a/test/AutoDiff/Parse/differentiable_func_type.swift b/test/AutoDiff/Parse/differentiable_func_type.swift index 513aec76752..7626a676c38 100644 --- a/test/AutoDiff/Parse/differentiable_func_type.swift +++ b/test/AutoDiff/Parse/differentiable_func_type.swift @@ -2,37 +2,37 @@ // expected-warning @+1 {{'@differentiable' has been renamed to '@differentiable(reverse)'}} {{23-23=(reverse)}} let a: @differentiable (Float) -> Float // okay -// CHECK: (pattern_named 'a' -// CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) +// CHECK: (pattern_named "a" +// CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " let b: @differentiable(reverse) (Float) -> Float // okay -// CHECK: (pattern_named 'b' -// CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) +// CHECK: (pattern_named "b" +// CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " let c: @differentiable(reverse) (Float, @noDerivative Float) -> Float // okay -// CHECK: (pattern_named 'c' -// CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) +// CHECK: (pattern_named "c" +// CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " // CHECK-NEXT: (type_function // CHECK-NEXT: (type_tuple -// CHECK-NEXT: (type_ident id='Float' bind=none) -// CHECK-NEXT: (type_attributed attrs=@noDerivative -// CHECK-NEXT: (type_ident id='Float' bind=none)) -// CHECK-NEXT: (type_ident id='Float' bind=none)))) +// CHECK-NEXT: (type_ident id="Float" unbound) +// CHECK-NEXT: (type_attributed attrs="@noDerivative " +// CHECK-NEXT: (type_ident id="Float" unbound)) +// CHECK-NEXT: (type_ident id="Float" unbound)))) let d: @differentiable(reverse) (Float) throws -> Float // okay -// CHECK: (pattern_named 'd' -// CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) +// CHECK: (pattern_named "d" +// CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " let e: @differentiable(reverse) (Float) throws -> Float // okay -// CHECK: (pattern_named 'e' -// CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) +// CHECK: (pattern_named "e" +// CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " // Generic type test. struct A { func foo() { let local: @differentiable(reverse) (T) -> T // okay - // CHECK: (pattern_named 'local' - // CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) + // CHECK: (pattern_named "local" + // CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " } } @@ -49,29 +49,29 @@ let d: @differentiable(notValidArg) (Float) -> Float struct B { struct linear {} let propertyB1: @differentiable(reverse) (linear) -> Float // okay - // CHECK: (pattern_named 'propertyB1' - // CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) + // CHECK: (pattern_named "propertyB1" + // CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " let propertyB2: @differentiable(reverse) (linear) -> linear // okay - // CHECK: (pattern_named 'propertyB2' - // CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) + // CHECK: (pattern_named "propertyB2" + // CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " let propertyB3: @differentiable(reverse) (linear, linear) -> linear // okay - // CHECK: (pattern_named 'propertyB3' - // CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) + // CHECK: (pattern_named "propertyB3" + // CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " let propertyB4: @differentiable(reverse) (linear, Float) -> linear // okay - // CHECK: (pattern_named 'propertyB4' - // CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) + // CHECK: (pattern_named "propertyB4" + // CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " let propertyB5: @differentiable(reverse) (Float, linear) -> linear // okay - // CHECK: (pattern_named 'propertyB5' - // CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) + // CHECK: (pattern_named "propertyB5" + // CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " let propertyB6: @differentiable(reverse) (linear, linear, Float, linear) -> Float // okay - // CHECK: (pattern_named 'propertyB6' - // CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) + // CHECK: (pattern_named "propertyB6" + // CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " // expected-error @+1 {{expected ')' in '@differentiable' attribute}} let propertyB7: @differentiable(reverse (linear) -> Float @@ -81,21 +81,21 @@ struct B { struct C { typealias reverse = (C) -> C let propertyC1: @differentiable(reverse) (reverse) -> Float // okay - // CHECK: (pattern_named 'propertyC1' - // CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) + // CHECK: (pattern_named "propertyC1" + // CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " let propertyC2: @differentiable(reverse) (reverse) -> reverse // okay - // CHECK: (pattern_named 'propertyC2' - // CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) + // CHECK: (pattern_named "propertyC2" + // CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " let propertyC3: @differentiable(reverse) reverse // okay - // CHECK: (pattern_named 'propertyC3' - // CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) + // CHECK: (pattern_named "propertyC3" + // CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) " let propertyC4: reverse // okay - // CHECK: (pattern_named 'propertyC4' + // CHECK: (pattern_named "propertyC4" let propertyC6: @differentiable(reverse) @convention(c) reverse // okay - // CHECK: (pattern_named 'propertyC6' - // CHECK-NEXT: (type_attributed attrs=@differentiable(reverse) + // CHECK: (pattern_named "propertyC6" + // CHECK-NEXT: (type_attributed attrs="@differentiable(reverse) @convention(c) " } diff --git a/test/Concurrency/async_main_resolution.swift b/test/Concurrency/async_main_resolution.swift index 51af600be61..4a201a65bd2 100644 --- a/test/Concurrency/async_main_resolution.swift +++ b/test/Concurrency/async_main_resolution.swift @@ -62,13 +62,13 @@ extension MainProtocol { @main struct MyMain : AsyncMainProtocol {} #endif -// CHECK-IS-SYNC-LABEL: "MyMain" interface type='MyMain.Type' -// CHECK-IS-SYNC: (func_decl implicit "$main()" interface type='(MyMain.Type) -> () -> ()' -// CHECK-IS-SYNC: (declref_expr implicit type='(MyMain.Type) -> () -> ()' +// CHECK-IS-SYNC-LABEL: "MyMain" interface type="MyMain.Type" +// CHECK-IS-SYNC: (func_decl implicit "$main()" interface type="(MyMain.Type) -> () -> ()" +// CHECK-IS-SYNC: (declref_expr implicit type="(MyMain.Type) -> () -> ()" -// CHECK-IS-ASYNC-LABEL: "MyMain" interface type='MyMain.Type' -// CHECK-IS-ASYNC: (func_decl implicit "$main()" interface type='(MyMain.Type) -> () async -> ()' -// CHECK-IS-ASYNC: (declref_expr implicit type='(MyMain.Type) -> () async -> ()' +// CHECK-IS-ASYNC-LABEL: "MyMain" interface type="MyMain.Type" +// CHECK-IS-ASYNC: (func_decl implicit "$main()" interface type="(MyMain.Type) -> () async -> ()" +// CHECK-IS-ASYNC: (declref_expr implicit type="(MyMain.Type) -> () async -> ()" // CHECK-IS-ERROR1: error: 'MyMain' is annotated with @main and must provide a main static function of type {{\(\) -> Void or \(\) throws -> Void|\(\) -> Void, \(\) throws -> Void, \(\) async -> Void, or \(\) async throws -> Void}} // CHECK-IS-ERROR2: error: ambiguous use of 'main' diff --git a/test/Concurrency/closure_isolation.swift b/test/Concurrency/closure_isolation.swift index dd29c814fa8..cf3c315c4dc 100644 --- a/test/Concurrency/closure_isolation.swift +++ b/test/Concurrency/closure_isolation.swift @@ -18,32 +18,32 @@ extension MyActor { func testClosureIsolation() async { // CHECK: acceptClosure // CHECK: closure_expr - // CHECK: actor-isolated + // CHECK: actor_isolated acceptClosure { self.syncMethod() } // CHECK: acceptSendableClosure // CHECK: closure_expr - // CHECK-NOT: actor-isolated + // CHECK-NOT: actor_isolated acceptSendableClosure { print(self) } // CHECK: acceptAsyncClosure // CHECK: closure_expr - // CHECK-SAME: actor-isolated=closure_isolation.(file).MyActor extension.testClosureIsolation().self + // CHECK-SAME: actor_isolated="closure_isolation.(file).MyActor extension.testClosureIsolation().self@ acceptAsyncClosure { await method() } // CHECK: acceptAsyncClosure // CHECK: closure_expr - // CHECK-NOT: actor-isolated + // CHECK-NOT: actor_isolated acceptAsyncClosure { () async in print() } // CHECK: acceptEscapingAsyncClosure // CHECK: closure_expr - // CHECK: actor-isolated + // CHECK: actor_isolated acceptEscapingAsyncClosure { self.syncMethod() } // CHECK: acceptEscapingAsyncClosure // CHECK: closure_expr - // CHECK: actor-isolated + // CHECK: actor_isolated acceptEscapingAsyncClosure { () async in print(self) } } } @@ -63,21 +63,21 @@ func someAsyncFunc() async { } @SomeGlobalActor func someGlobalActorFunc() async { // CHECK: acceptAsyncClosure // CHECK: closure_expr - // CHECK-SAME: global-actor-isolated=SomeGlobalActor + // CHECK-SAME: global_actor_isolated="SomeGlobalActor" acceptAsyncClosure { await someAsyncFunc() } // CHECK: acceptAsyncClosure // CHECK: closure_expr - // CHECK-SAME: global-actor-isolated=SomeGlobalActor + // CHECK-SAME: global_actor_isolated="SomeGlobalActor" acceptAsyncClosure { () async in print("hello") } // CHECK: acceptEscapingAsyncClosure // CHECK: closure_expr - // CHECK: actor-isolated + // CHECK: actor_isolated acceptEscapingAsyncClosure { await someAsyncFunc() } // CHECK: acceptEscapingAsyncClosure // CHECK: closure_expr - // CHECK: actor-isolated + // CHECK: actor_isolated acceptEscapingAsyncClosure { () async in print("hello") } } diff --git a/test/Concurrency/where_clause_main_resolution.swift b/test/Concurrency/where_clause_main_resolution.swift index 9f491b974b5..de7dd534948 100644 --- a/test/Concurrency/where_clause_main_resolution.swift +++ b/test/Concurrency/where_clause_main_resolution.swift @@ -16,28 +16,28 @@ protocol App { // Load in the source file name and grab line numbers for default main funcs // CHECK: (source_file "[[SOURCE_FILE:[^"]+]]" -// CHECK: (extension_decl range={{\[}}[[SOURCE_FILE]]:{{[0-9]+}}:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} App where -// CHECK: (extension_decl range={{\[}}[[SOURCE_FILE]]:{{[0-9]+}}:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} App where -// CHECK: (extension_decl range={{\[}}[[SOURCE_FILE]]:{{[0-9]+}}:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} App where +// CHECK: (extension_decl range={{\[}}[[SOURCE_FILE]]:{{[0-9]+}}:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} "App" where +// CHECK: (extension_decl range={{\[}}[[SOURCE_FILE]]:{{[0-9]+}}:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} "App" where +// CHECK: (extension_decl range={{\[}}[[SOURCE_FILE]]:{{[0-9]+}}:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} "App" where // CHECK: (extension_decl range={{\[}}[[SOURCE_FILE]]:{{[0-9]+}}:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} // CHECK-NOT: where // CHECK-NEXT: (func_decl range={{\[}}[[SOURCE_FILE]]:[[DEFAULT_ASYNCHRONOUS_MAIN_LINE:[0-9]+]]:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} "main()" -// CHECK-SAME: interface type=' (Self.Type) -> () async -> ()' +// CHECK-SAME: interface type=" (Self.Type) -> () async -> ()" extension App where Configuration == Config1 { -// CHECK-CONFIG1: (func_decl implicit "$main()" interface type='(MainType.Type) -> () -> ()' +// CHECK-CONFIG1: (func_decl implicit "$main()" interface type="(MainType.Type) -> () -> ()" // CHECK-CONFIG1: [[SOURCE_FILE]]:[[# @LINE+1 ]] static func main() { } } extension App where Configuration == Config2 { -// CHECK-CONFIG2: (func_decl implicit "$main()" interface type='(MainType.Type) -> () async -> ()' +// CHECK-CONFIG2: (func_decl implicit "$main()" interface type="(MainType.Type) -> () async -> ()" // CHECK-CONFIG2: [[SOURCE_FILE]]:[[# @LINE+1 ]] static func main() async { } } extension App where Configuration == Config3 { -// CHECK-CONFIG3-ASYNC: (func_decl implicit "$main()" interface type='(MainType.Type) -> () async -> ()' +// CHECK-CONFIG3-ASYNC: (func_decl implicit "$main()" interface type="(MainType.Type) -> () async -> ()" // CHECK-CONFIG3-ASYNC: [[SOURCE_FILE]]:[[DEFAULT_ASYNCHRONOUS_MAIN_LINE]] } diff --git a/test/Constraints/init_literal_via_coercion.swift b/test/Constraints/init_literal_via_coercion.swift index 1a63790c5fb..5b138d7bc0e 100644 --- a/test/Constraints/init_literal_via_coercion.swift +++ b/test/Constraints/init_literal_via_coercion.swift @@ -5,15 +5,15 @@ // `0 as <#Type#>` should get literal bound early via equality constraint. // CHECK: ---Constraint solving at [{{.*}}:12:1 - line:12:13]--- -// CHECK: (integer_literal_expr type='[[LITERAL_VAR:\$T[0-9]+]]' {{.*}} +// CHECK: (integer_literal_expr type="[[LITERAL_VAR:\$T[0-9]+]]" {{.*}} // CHECK: Type Variables: // CHECK: [[LITERAL_VAR]] as UInt32 {{.*}} // CHECK-NOT: disjunction (remembered) \[\[locator@{{.*}} [Coerce@{{.*}}\]\]]: _ = UInt32(0) // CHECK: ---Constraint solving at [{{.*}}22:1 - line:22:13]--- -// CHECK: (coerce_expr implicit type='[[CAST_TYPE:\$T[0-9]+]]' {{.*}} -// CHECK-NEXT: (nil_literal_expr type='[[LITERAL_VAR:\$T[0-9]+]]' {{.*}} +// CHECK: (coerce_expr implicit type="[[CAST_TYPE:\$T[0-9]+]]" {{.*}} +// CHECK-NEXT: (nil_literal_expr type="[[LITERAL_VAR:\$T[0-9]+]]" {{.*}} // CHECK: Type Variables: // CHECK: [[LITERAL_VAR]] as Int? {{.*}} // CHECK: disjunction (remembered) {{.*}} diff --git a/test/Constraints/invalid_decl_ref.swift b/test/Constraints/invalid_decl_ref.swift index a85a67ed080..7c65fa08543 100644 --- a/test/Constraints/invalid_decl_ref.swift +++ b/test/Constraints/invalid_decl_ref.swift @@ -4,6 +4,6 @@ import Foundation -// CHECK: declref_expr type='module' -// CHECK-NEXT: type_expr type='Data.Type' +// CHECK: declref_expr type="module" +// CHECK-NEXT: type_expr type="Data.Type" let type = SomeModule.Data.self diff --git a/test/Constraints/issue-58019.swift b/test/Constraints/issue-58019.swift index 92c9d642d32..3b380a99d7f 100644 --- a/test/Constraints/issue-58019.swift +++ b/test/Constraints/issue-58019.swift @@ -3,9 +3,9 @@ // https://github.com/apple/swift/issues/58019 func fetch() { - // CHECK: open_existential_expr implicit type='Void' - // CHECK: opaque_value_expr implicit type='any MyError' - // CHECK-NOT: type='SryMap<$T{{.*}}>.Failure' + // CHECK: open_existential_expr implicit type="Void" + // CHECK: opaque_value_expr implicit type="any MyError" + // CHECK-NOT: type="SryMap<$T{{.*}}>.Failure" sryMap { return "" } .napError{ $0.abc() } } diff --git a/test/Constraints/issue-60806.swift b/test/Constraints/issue-60806.swift index 8b8ad69bee5..a6087e67708 100644 --- a/test/Constraints/issue-60806.swift +++ b/test/Constraints/issue-60806.swift @@ -18,8 +18,8 @@ enum NonBarBaz { let _: Foo = Foo { (a: Bar) -> Void in switch a { - // CHECK: (pattern_is type='any Bar' value_cast Baz - // CHECK-NEXT: (pattern_enum_element type='Baz' Baz.someCase + // CHECK: (pattern_is type="any Bar" cast_kind=value_cast cast_to="Baz" + // CHECK-NEXT: (pattern_enum_element type="Baz" element="Baz.someCase" case let .someCase(value) as Baz: print(value) // expected-warning@-1 {{cast from 'any Bar' to unrelated type 'NonBarBaz' always fails}} diff --git a/test/Constraints/nil-coalescing-favoring.swift b/test/Constraints/nil-coalescing-favoring.swift index 0001f97014b..ddf85f0a9e3 100644 --- a/test/Constraints/nil-coalescing-favoring.swift +++ b/test/Constraints/nil-coalescing-favoring.swift @@ -6,9 +6,9 @@ struct B { struct A { init(_ other: B) {} - // CHECK: constructor_decl{{.*}}interface type='(A.Type) -> (B?) -> A' + // CHECK: constructor_decl{{.*}}interface type="(A.Type) -> (B?) -> A" init(_ other: B?) { - // CHECK: dot_syntax_call_expr type='(B) -> A' + // CHECK: dot_syntax_call_expr type="(B) -> A" self.init(other ?? ._none) } } diff --git a/test/Constraints/result_builder_conjunction_selection.swift b/test/Constraints/result_builder_conjunction_selection.swift index c3452f4d8e4..1b47d8349ce 100644 --- a/test/Constraints/result_builder_conjunction_selection.swift +++ b/test/Constraints/result_builder_conjunction_selection.swift @@ -32,7 +32,7 @@ do { func test(_: T, @Builder _: () -> some P) {} // CHECK: ---Initial constraints for the given expression--- - // CHECK: (integer_literal_expr type='[[LITERAL_VAR:\$T[0-9]+]]' {{.*}} + // CHECK: (integer_literal_expr type="[[LITERAL_VAR:\$T[0-9]+]]" {{.*}} // CHECK: (attempting type variable binding [[CLOSURE:\$T[0-9]+]] := () -> {{.*}} // CHECK-NOT: (attempting type variable binding [[LITERAL_VAR]] := {{.*}} // CHECK: (attempting conjunction element pattern binding element @ 0 @@ -48,7 +48,7 @@ do { func test(_: T, @Builder _: (T) -> some P) {} // CHECK: ---Initial constraints for the given expression--- - // CHECK: (integer_literal_expr type='[[LITERAL_VAR:\$T[0-9]+]]' {{.*}} + // CHECK: (integer_literal_expr type="[[LITERAL_VAR:\$T[0-9]+]]" {{.*}} // CHECK: (attempting type variable binding [[LITERAL_VAR]] := Int // CHECK: (attempting conjunction element pattern binding element @ 0 test(42) { v in @@ -63,12 +63,12 @@ do { // CHECK: ---Initial constraints for the given expression--- // CHECK: (attempting type variable {{.*}} := () -> {{.*}} // CHECK: (attempting conjunction element pattern binding element @ 0 : - // CHECK-NEXT: (pattern_named 'x') + // CHECK-NEXT: (pattern_named "x") // CHECK: (attempting conjunction element syntactic element // CHECK-NEXT: (call_expr {{.*}} // CHECK: (attempting type variable {{.*}} := (Bool) -> {{.*}} // CHECK: (attempting conjunction element pattern binding element @ 0 - // CHECK: (pattern_named implicit '$__builder{{.*}}') + // CHECK: (pattern_named implicit "$__builder{{.*}}") // CHECK: (applying conjunction result to outer context // CHECK: (attempting type variable {{.*}} := (Int?) -> {{.*}} // CHECK: (attempting disjunction choice {{.*}} bound to decl {{.*}}.Int.init(_:) diff --git a/test/Constraints/result_builder_generic_infer.swift b/test/Constraints/result_builder_generic_infer.swift index d08dcdb1958..f93f2bd5805 100644 --- a/test/Constraints/result_builder_generic_infer.swift +++ b/test/Constraints/result_builder_generic_infer.swift @@ -22,34 +22,34 @@ struct ProtocolSubstitution: P { typealias A = Int // CHECK: var_decl{{.*}}x1 - // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature= (substitution T -> Int)) + // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='' 'T -> Int') var x1: [S] { S() } // CHECK: var_decl{{.*}}x2 - // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature= (substitution T -> ProtocolSubstitution)) + // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='' 'T -> ProtocolSubstitution') var x2: [S] { S() } } // CHECK: struct_decl{{.*}}ArchetypeSubstitution struct ArchetypeSubstitution: P { // CHECK: var_decl{{.*}}x1 - // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature= (substitution T -> A)) + // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='' 'T -> A') var x1: [S] { S() } // CHECK: var_decl{{.*}}x2 - // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature= (substitution T -> ArchetypeSubstitution)) + // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='' 'T -> ArchetypeSubstitution') var x2: [S] { S() } } // CHECK-LABEL: struct_decl{{.*}}ExplicitGenericAttribute struct ExplicitGenericAttribute { // CHECK: var_decl{{.*}}x1 - // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature= (substitution T -> T)) + // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='' 'T -> T') @Builder var x1: [S] { S() } // CHECK: var_decl{{.*}}x2 - // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature= (substitution T -> T.A)) + // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='' 'T -> T.A') @Builder var x2: [S] { S() } } @@ -61,10 +61,10 @@ extension ConcreteTypeSubstitution: P where Value == Int { typealias A = Value // CHECK: var_decl{{.*}}x1 - // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature= (substitution T -> Int)) + // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='' 'T -> Int') var x1: [S] { S() } // CHECK: var_decl{{.*}}x2 - // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature= (substitution T -> ConcreteTypeSubstitution)) + // CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='' 'T -> ConcreteTypeSubstitution') var x2: [S] { S() } } diff --git a/test/Constraints/result_builder_switch_with_vars.swift b/test/Constraints/result_builder_switch_with_vars.swift index 6fb9bc18760..895d7bb58a3 100644 --- a/test/Constraints/result_builder_switch_with_vars.swift +++ b/test/Constraints/result_builder_switch_with_vars.swift @@ -49,8 +49,8 @@ func tuplify(@TupleBuilder body: (E) throws -> T) rethrows { tuplify { switch $0 { // CHECK: (case_body_variables - // CHECK-NEXT: (var_decl implicit {{.*}} "a" interface type='String' let readImpl=stored immutable) - // CHECK-NEXT: (var_decl implicit {{.*}} "b" interface type='Int' let readImpl=stored immutable) + // CHECK-NEXT: (var_decl implicit {{.*}} "a" interface type="String" let readImpl=stored immutable) + // CHECK-NEXT: (var_decl implicit {{.*}} "b" interface type="Int" let readImpl=stored immutable) case let .test(a, b): a b @@ -58,8 +58,8 @@ tuplify { switch $0 { // CHECK: (case_body_variables - // CHECK-NEXT: (var_decl implicit {{.*}} "a" interface type='String' let readImpl=stored immutable) - // CHECK-NEXT: (var_decl implicit {{.*}} "b" interface type='Int' let readImpl=stored immutable) + // CHECK-NEXT: (var_decl implicit {{.*}} "a" interface type="String" let readImpl=stored immutable) + // CHECK-NEXT: (var_decl implicit {{.*}} "b" interface type="Int" let readImpl=stored immutable) case .test(let a, let b): a b @@ -67,21 +67,21 @@ tuplify { switch $0 { // CHECK: (case_body_variables - // CHECK-NEXT: (var_decl implicit {{.*}} "value" interface type='(a: String, b: Int)' let readImpl=stored immutable) + // CHECK-NEXT: (var_decl implicit {{.*}} "value" interface type="(a: String, b: Int)" let readImpl=stored immutable) case let .test((value)): value.a } switch $0 { // CHECK: (case_body_variables - // CHECK-NEXT: (var_decl implicit {{.*}} "value" interface type='(a: String, b: Int)' let readImpl=stored immutable) + // CHECK-NEXT: (var_decl implicit {{.*}} "value" interface type="(a: String, b: Int)" let readImpl=stored immutable) case let .test(value): value.a } switch $0 { // CHECK: (case_body_variables - // CHECK-NEXT: (var_decl implicit {{.*}} "value" interface type='(a: String, b: Int)' let readImpl=stored immutable) + // CHECK-NEXT: (var_decl implicit {{.*}} "value" interface type="(a: String, b: Int)" let readImpl=stored immutable) case .test(let value): value.a } diff --git a/test/DWARFImporter/basic.swift b/test/DWARFImporter/basic.swift index 69d28ec43e3..a5c30f96495 100644 --- a/test/DWARFImporter/basic.swift +++ b/test/DWARFImporter/basic.swift @@ -23,10 +23,10 @@ import ObjCModule let pureSwift = Int32(42) // FAIL-NOT: var_decl -// CHECK: var_decl "pureSwift" {{.*}} type='Int32' -// SWIFTONLY: var_decl "pureSwift" {{.*}} type='Int32' +// CHECK: var_decl "pureSwift" {{.*}} type="Int32" +// SWIFTONLY: var_decl "pureSwift" {{.*}} type="Int32" let point = Point(x: 1, y: 2) -// CHECK: var_decl "point" {{.*}} type='Point' +// CHECK: var_decl "point" {{.*}} type="Point" // SWIFTONLY-NOT: var_decl "point" diff --git a/test/Distributed/distributed_actor_executor_ast.swift b/test/Distributed/distributed_actor_executor_ast.swift index 1cdf281ca1b..25ab0ed2222 100644 --- a/test/Distributed/distributed_actor_executor_ast.swift +++ b/test/Distributed/distributed_actor_executor_ast.swift @@ -25,21 +25,21 @@ distributed actor DefaultWorker { } // Check DefaultWorker, the DefaultActor version of the synthesis: -// CHECK: (class_decl range=[{{.*}}] "DefaultWorker" interface type='DefaultWorker.Type' access=internal non-resilient actor +// CHECK: (class_decl range=[{{.*}}] "DefaultWorker" interface type="DefaultWorker.Type" access=internal non_resilient distributed actor // The unowned executor property: -// CHECK: (var_decl implicit "unownedExecutor" interface type='UnownedSerialExecutor' access=internal final readImpl=getter immutable +// CHECK: (var_decl implicit "unownedExecutor" interface type="UnownedSerialExecutor" access=internal final readImpl=getter immutable // We guard the rest of the body; we only return a default executor if the actor is local: // CHECK: (guard_stmt implicit -// CHECK: (call_expr implicit type='Bool' nothrow -// CHECK: (declref_expr implicit type='@_NO_EXTINFO (AnyObject) -> Bool' decl=Distributed.(file).__isLocalActor function_ref=unapplied) +// CHECK: (call_expr implicit type="Bool" nothrow +// CHECK: (declref_expr implicit type="@_NO_EXTINFO (AnyObject) -> Bool" decl="Distributed.(file).__isLocalActor" function_ref=unapplied) // Check that we create the "remote reference" executor: // CHECK: (return_stmt implicit -// CHECK: (call_expr implicit type='UnownedSerialExecutor' nothrow -// CHECK: (declref_expr implicit type='(DefaultWorker) -> UnownedSerialExecutor' decl=Distributed.(file).buildDefaultDistributedRemoteActorExecutor [with (substitution_map generic_signature= (substitution Act -> DefaultWorker))] +// CHECK: (call_expr implicit type="UnownedSerialExecutor" nothrow +// CHECK: (declref_expr implicit type="(DefaultWorker) -> UnownedSerialExecutor" decl="Distributed.(file).buildDefaultDistributedRemoteActorExecutor [with (substitution_map generic_signature='' 'Act -> DefaultWorker')]" // Check the default executor synthesis for local actor otherwise: // CHECK: (return_stmt implicit -// CHECK: (call_expr implicit type='Builtin.Executor' nothrow -// CHECK: (declref_expr implicit type='(DefaultWorker) -> Builtin.Executor' decl=Builtin.(file).buildDefaultActorExecutorRef [with (substitution_map generic_signature= (substitution T -> DefaultWorker))] function_ref=unapplied) +// CHECK: (call_expr implicit type="Builtin.Executor" nothrow +// CHECK: (declref_expr implicit type="(DefaultWorker) -> Builtin.Executor" decl="Builtin.(file).buildDefaultActorExecutorRef [with (substitution_map generic_signature='' 'T -> DefaultWorker')]" function_ref=unapplied) diff --git a/test/Frontend/debug-generic-signatures.swift b/test/Frontend/debug-generic-signatures.swift index bcd175b7464..662212026df 100644 --- a/test/Frontend/debug-generic-signatures.swift +++ b/test/Frontend/debug-generic-signatures.swift @@ -32,9 +32,9 @@ protocol P3 { } // CHECK-LABEL: StructDecl name=Basic -// CHECK: (normal_conformance type=Basic protocol=P1 -// CHECK-NEXT: (assoc_type req=A type=Int) -// CHECK-NEXT: (value req=f() witness=main.(file).Basic.f()@{{.*}})) +// CHECK: (normal_conformance type="Basic" protocol="P1" +// CHECK-NEXT: (assoc_type req="A" type="Int") +// CHECK-NEXT: (value req="f()" witness="main.(file).Basic.f()@{{.*}}")) struct Basic: P1 { typealias A = Int func f() -> Int { fatalError() } @@ -43,11 +43,11 @@ struct Basic: P1 { // Recursive conformances should have finite output. // CHECK-LABEL: StructDecl name=Recur -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 -// CHECK-NEXT: (assoc_type req=A type=Recur) -// CHECK-NEXT: (assoc_type req=B type=Recur) -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 (details printed above)) -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 (details printed above))) +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2" +// CHECK-NEXT: (assoc_type req="A" type="Recur") +// CHECK-NEXT: (assoc_type req="B" type="Recur") +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2"
) +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2"
)) struct Recur: P2 { typealias A = Recur typealias B = Recur @@ -56,15 +56,15 @@ struct Recur: P2 { // The full information about a conformance doesn't need to be printed twice. // CHECK-LABEL: StructDecl name=NonRecur -// CHECK-NEXT: (normal_conformance type=NonRecur protocol=P2 -// CHECK-NEXT: (assoc_type req=A type=Recur) -// CHECK-NEXT: (assoc_type req=B type=Recur) -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 -// CHECK-NEXT: (assoc_type req=A type=Recur) -// CHECK-NEXT: (assoc_type req=B type=Recur) -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 (details printed above)) -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 (details printed above))) -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 (details printed above))) +// CHECK-NEXT: (normal_conformance type="NonRecur" protocol="P2" +// CHECK-NEXT: (assoc_type req="A" type="Recur") +// CHECK-NEXT: (assoc_type req="B" type="Recur") +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2" +// CHECK-NEXT: (assoc_type req="A" type="Recur") +// CHECK-NEXT: (assoc_type req="B" type="Recur") +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2"
) +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2"
)) +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2"
)) struct NonRecur: P2 { typealias A = Recur typealias B = Recur @@ -77,10 +77,10 @@ struct NonRecur: P2 { // CHECK-LABEL: ExtensionDecl line={{.*}} base=Generic struct Generic {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=Generic -// CHECK-NEXT: (normal_conformance type=Generic protocol=P1 -// CHECK-NEXT: (assoc_type req=A type=T) -// CHECK-NEXT: (value req=f() witness=main.(file).Generic extension.f()@{{.*}}) -// CHECK-NEXT: conforms_to: T P1) +// CHECK-NEXT: (normal_conformance type="Generic" protocol="P1" +// CHECK-NEXT: (assoc_type req="A" type="T") +// CHECK-NEXT: (value req="f()" witness="main.(file).Generic extension.f()@{{.*}}") +// CHECK-NEXT: (requirement "T" conforms_to "P1") extension Generic: P1 where T: P1 { typealias A = T func f() -> T { fatalError() } @@ -94,13 +94,13 @@ extension Generic: P1 where T: P1 { // CHECK-LABEL: ExtensionDecl line={{.*}} base=Super class Super {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=Super -// CHECK-NEXT: (normal_conformance type=Super protocol=P2 -// CHECK-NEXT: (assoc_type req=A type=T) -// CHECK-NEXT: (assoc_type req=B type=T) -// CHECK-NEXT: (abstract_conformance protocol=P2) -// CHECK-NEXT: (abstract_conformance protocol=P2) -// CHECK-NEXT: conforms_to: T P2 -// CHECK-NEXT: conforms_to: U P2) +// CHECK-NEXT: (normal_conformance type="Super" protocol="P2" +// CHECK-NEXT: (assoc_type req="A" type="T") +// CHECK-NEXT: (assoc_type req="B" type="T") +// CHECK-NEXT: (abstract_conformance protocol="P2") +// CHECK-NEXT: (abstract_conformance protocol="P2") +// CHECK-NEXT: (requirement "T" conforms_to "P2") +// CHECK-NEXT: (requirement "U" conforms_to "P2")) extension Super: P2 where T: P2, U: P2 { typealias A = T typealias B = T @@ -108,55 +108,55 @@ extension Super: P2 where T: P2, U: P2 { // Inherited/specialized conformances. // CHECK-LABEL: ClassDecl name=Sub -// CHECK-NEXT: (inherited_conformance type=Sub protocol=P2 -// CHECK-NEXT: (specialized_conformance type=Super protocol=P2 -// CHECK-NEXT: (substitution_map generic_signature= -// CHECK-NEXT: (substitution T -> NonRecur) -// CHECK-NEXT: (substitution U -> Recur) -// CHECK-NEXT: (conformance type=T -// CHECK-NEXT: (normal_conformance type=NonRecur protocol=P2 -// CHECK-NEXT: (assoc_type req=A type=Recur) -// CHECK-NEXT: (assoc_type req=B type=Recur) -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 -// CHECK-NEXT: (assoc_type req=A type=Recur) -// CHECK-NEXT: (assoc_type req=B type=Recur) -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 (details printed above)) -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 (details printed above))) -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 (details printed above)))) -// CHECK-NEXT: (conformance type=U -// CHECK-NEXT: (normal_conformance type=Recur protocol=P2 (details printed above)))) -// CHECK-NEXT: (conditional requirements unable to be computed) -// CHECK-NEXT: (normal_conformance type=Super protocol=P2 -// CHECK-NEXT: (assoc_type req=A type=T) -// CHECK-NEXT: (assoc_type req=B type=T) -// CHECK-NEXT: (abstract_conformance protocol=P2) -// CHECK-NEXT: (abstract_conformance protocol=P2) -// CHECK-NEXT: conforms_to: T P2 -// CHECK-NEXT: conforms_to: U P2))) +// CHECK-NEXT: (inherited_conformance type="Sub" protocol="P2" +// CHECK-NEXT: (specialized_conformance type="Super" protocol="P2" +// CHECK-NEXT: (substitution_map generic_signature="" +// CHECK-NEXT: (substitution "T -> NonRecur") +// CHECK-NEXT: (substitution "U -> Recur") +// CHECK-NEXT: (conformance type="T" +// CHECK-NEXT: (normal_conformance type="NonRecur" protocol="P2" +// CHECK-NEXT: (assoc_type req="A" type="Recur") +// CHECK-NEXT: (assoc_type req="B" type="Recur") +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2" +// CHECK-NEXT: (assoc_type req="A" type="Recur") +// CHECK-NEXT: (assoc_type req="B" type="Recur") +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2"
) +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2"
)) +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2"
))) +// CHECK-NEXT: (conformance type="U" +// CHECK-NEXT: (normal_conformance type="Recur" protocol="P2"
))) +// CHECK-NEXT: () +// CHECK-NEXT: (normal_conformance type="Super" protocol="P2" +// CHECK-NEXT: (assoc_type req="A" type="T") +// CHECK-NEXT: (assoc_type req="B" type="T") +// CHECK-NEXT: (abstract_conformance protocol="P2") +// CHECK-NEXT: (abstract_conformance protocol="P2") +// CHECK-NEXT: (requirement "T" conforms_to "P2") +// CHECK-NEXT: (requirement "U" conforms_to "P2")))) class Sub: Super {} // Specialization of a recursive conformance should be okay: recursion detection // should work through SubstitutionMaps. // CHECK-LABEL: StructDecl name=RecurGeneric -// CHECK-NEXT: (normal_conformance type=RecurGeneric protocol=P3 -// CHECK-NEXT: (assoc_type req=A type=RecurGeneric) -// CHECK-NEXT: (normal_conformance type=RecurGeneric protocol=P3 (details printed above))) +// CHECK-NEXT: (normal_conformance type="RecurGeneric" protocol="P3" +// CHECK-NEXT: (assoc_type req="A" type="RecurGeneric") +// CHECK-NEXT: (normal_conformance type="RecurGeneric" protocol="P3"
)) struct RecurGeneric: P3 { typealias A = RecurGeneric } // CHECK-LABEL: StructDecl name=Specialize -// CHECK-NEXT: (normal_conformance type=Specialize protocol=P3 -// CHECK-NEXT: (assoc_type req=A type=RecurGeneric) -// CHECK-NEXT: (specialized_conformance type=Specialize.A protocol=P3 -// CHECK-NEXT: (substitution_map generic_signature= -// CHECK-NEXT: (substitution T -> Specialize) -// CHECK-NEXT: (conformance type=T -// CHECK-NEXT: (normal_conformance type=Specialize protocol=P3 (details printed above)))) -// CHECK-NEXT: (normal_conformance type=RecurGeneric protocol=P3 -// CHECK-NEXT: (assoc_type req=A type=RecurGeneric) -// CHECK-NEXT: (normal_conformance type=RecurGeneric protocol=P3 (details printed above))))) +// CHECK-NEXT: (normal_conformance type="Specialize" protocol="P3" +// CHECK-NEXT: (assoc_type req="A" type="RecurGeneric") +// CHECK-NEXT: (specialized_conformance type="Specialize.A" protocol="P3" +// CHECK-NEXT: (substitution_map generic_signature="" +// CHECK-NEXT: (substitution "T -> Specialize") +// CHECK-NEXT: (conformance type="T" +// CHECK-NEXT: (normal_conformance type="Specialize" protocol="P3"
))) +// CHECK-NEXT: (normal_conformance type="RecurGeneric" protocol="P3" +// CHECK-NEXT: (assoc_type req="A" type="RecurGeneric") +// CHECK-NEXT: (normal_conformance type="RecurGeneric" protocol="P3"
)))) struct Specialize: P3 { typealias A = RecurGeneric } diff --git a/test/Frontend/dump-parse.swift b/test/Frontend/dump-parse.swift index f9ef8e3f3b6..825cd40f08e 100644 --- a/test/Frontend/dump-parse.swift +++ b/test/Frontend/dump-parse.swift @@ -6,10 +6,10 @@ func foo(_ n: Int) -> Int { // CHECK: (brace_stmt // CHECK: (return_stmt - // CHECK: (integer_literal_expr type='' value=42 {{.*}}))) + // CHECK: (integer_literal_expr type="" value="42" {{.*}}))) // CHECK-AST: (brace_stmt // CHECK-AST: (return_stmt - // CHECK-AST: (integer_literal_expr type='{{[^']+}}' {{.*}} value=42 {{.*}}) + // CHECK-AST: (integer_literal_expr type="{{[^"]+}}" {{.*}} value="42" {{.*}}) return 42 } @@ -18,13 +18,13 @@ func foo(_ n: Int) -> Int { // CHECK-AST-LABEL: (func_decl{{.*}}"bar()" func bar() { // CHECK: (brace_stmt - // CHECK-NEXT: (unresolved_decl_ref_expr type='{{[^']+}}' name=foo - // CHECK-NEXT: (unresolved_decl_ref_expr type='{{[^']+}}' name=foo - // CHECK-NEXT: (unresolved_decl_ref_expr type='{{[^']+}}' name=foo + // CHECK-NEXT: (unresolved_decl_ref_expr type="{{[^"]+}}" name="foo" + // CHECK-NEXT: (unresolved_decl_ref_expr type="{{[^"]+}}" name="foo" + // CHECK-NEXT: (unresolved_decl_ref_expr type="{{[^"]+}}" name="foo" // CHECK-AST: (brace_stmt - // CHECK-AST-NEXT: (declref_expr type='{{[^']+}}' {{.*}} decl=main.(file).foo - // CHECK-AST-NEXT: (declref_expr type='{{[^']+}}' {{.*}} decl=main.(file).foo - // CHECK-AST-NEXT: (declref_expr type='{{[^']+}}' {{.*}} decl=main.(file).foo + // CHECK-AST-NEXT: (declref_expr type="{{[^"]+}}" {{.*}} decl="main.(file).foo@ + // CHECK-AST-NEXT: (declref_expr type="{{[^"]+}}" {{.*}} decl="main.(file).foo@ + // CHECK-AST-NEXT: (declref_expr type="{{[^"]+}}" {{.*}} decl="main.(file).foo@ foo foo foo } @@ -38,8 +38,8 @@ enum TrailingSemi { case A,B; // CHECK-LABEL: (subscript_decl{{.*}}trailing_semi - // CHECK-NOT: (func_decl{{.*}}trailing_semi 'anonname={{.*}}' get_for=subscript(_:) - // CHECK: (accessor_decl{{.*}}'anonname={{.*}}' get_for=subscript(_:) + // CHECK-NOT: (func_decl{{.*}}trailing_semi get for="subscript(_:)" + // CHECK: (accessor_decl{{.*}} get for="subscript(_:)" subscript(x: Int) -> Int { // CHECK-LABEL: (pattern_binding_decl{{.*}}trailing_semi // CHECK-NOT: (var_decl{{.*}}trailing_semi "y" @@ -55,26 +55,26 @@ enum TrailingSemi { }; // The substitution map for a declref should be relatively unobtrusive. -// CHECK-AST-LABEL: (func_decl{{.*}}"generic(_:)" interface type=' (T) -> ()' access=internal captures=( ) +// CHECK-AST-LABEL: (func_decl{{.*}}"generic(_:)" "" interface type=" (T) -> ()" access=internal captures=( ) func generic(_: T) {} // CHECK-AST: (pattern_binding_decl -// CHECK-AST: (declref_expr type='(Int) -> ()' location={{.*}} range={{.*}} decl=main.(file).generic@{{.*}} [with (substitution_map generic_signature= (substitution T -> Int))] function_ref=unapplied)) +// CHECK-AST: (processed_init=declref_expr type="(Int) -> ()" location={{.*}} range={{.*}} decl="main.(file).generic@{{.*}} [with (substitution_map generic_signature='' 'T -> Int')]" function_ref=unapplied)) let _: (Int) -> () = generic // Closures should be marked as escaping or not. func escaping(_: @escaping (Int) -> Int) {} escaping({ $0 }) -// CHECK-AST: (declref_expr type='(@escaping (Int) -> Int) -> ()' +// CHECK-AST: (declref_expr type="(@escaping (Int) -> Int) -> ()" // CHECK-AST-NEXT: (argument_list // CHECK-AST-NEXT: (argument -// CHECK-AST-NEXT: (closure_expr type='(Int) -> Int' {{.*}} discriminator=0 escaping single-expression +// CHECK-AST-NEXT: (closure_expr type="(Int) -> Int" {{.*}} discriminator=0 escaping single_expression func nonescaping(_: (Int) -> Int) {} nonescaping({ $0 }) -// CHECK-AST: (declref_expr type='((Int) -> Int) -> ()' +// CHECK-AST: (declref_expr type="((Int) -> Int) -> ()" // CHECK-AST-NEXT: (argument_list // CHECK-AST-NEXT: (argument -// CHECK-AST-NEXT: (closure_expr type='(Int) -> Int' {{.*}} discriminator=1 single-expression +// CHECK-AST-NEXT: (closure_expr type="(Int) -> Int" {{.*}} discriminator=1 single_expression // CHECK-LABEL: (struct_decl range=[{{.+}}] "MyStruct") struct MyStruct {} @@ -85,23 +85,23 @@ enum MyEnum { // CHECK-LABEL: (enum_case_decl range=[{{.+}}] // CHECK-NEXT: (enum_element_decl range=[{{.+}}] "foo(x:)" // CHECK-NEXT: (parameter_list range=[{{.+}}] - // CHECK-NEXT: (parameter "x" apiName=x))) + // CHECK-NEXT: (parameter "x" apiName="x"))) // CHECK-NEXT: (enum_element_decl range=[{{.+}}] "bar")) // CHECK-NEXT: (enum_element_decl range=[{{.+}}] "foo(x:)" // CHECK-NEXT: (parameter_list range=[{{.+}}] - // CHECK-NEXT: (parameter "x" apiName=x))) + // CHECK-NEXT: (parameter "x" apiName="x"))) // CHECK-NEXT: (enum_element_decl range=[{{.+}}] "bar")) case foo(x: MyStruct), bar } // CHECK-LABEL: (top_level_code_decl range=[{{.+}}] // CHECK-NEXT: (brace_stmt implicit range=[{{.+}}] -// CHECK-NEXT: (sequence_expr type='' -// CHECK-NEXT: (discard_assignment_expr type='') -// CHECK-NEXT: (assign_expr type='' -// CHECK-NEXT: (**NULL EXPRESSION**) -// CHECK-NEXT: (**NULL EXPRESSION**)) -// CHECK-NEXT: (closure_expr type='' discriminator={{[0-9]+}} +// CHECK-NEXT: (sequence_expr type="" +// CHECK-NEXT: (discard_assignment_expr type="") +// CHECK-NEXT: (assign_expr type="" +// CHECK-NEXT: () +// CHECK-NEXT: ()) +// CHECK-NEXT: (closure_expr type="" discriminator={{[0-9]+}} // CHECK-NEXT: (parameter_list range=[{{.+}}] // CHECK-NEXT: (parameter "v")) // CHECK-NEXT: (brace_stmt range=[{{.+}}]))))) @@ -113,13 +113,12 @@ struct SelfParam { // CHECK-LABEL: (func_decl range=[{{.+}}] "createOptional()" type // CHECK-NEXT: (parameter "self") // CHECK-NEXT: (parameter_list range=[{{.+}}]) - // CHECK-NEXT: (result - // CHECK-NEXT: (type_optional - // CHECK-NEXT: (type_ident id='SelfParam' bind=none))) + // CHECK-NEXT: (result=type_optional + // CHECK-NEXT: (type_ident id="SelfParam" unbound)) static func createOptional() -> SelfParam? { - // CHECK-LABEL: (call_expr type='' - // CHECK-NEXT: (unresolved_decl_ref_expr type='' name=SelfParam function_ref=unapplied) + // CHECK-LABEL: (call_expr type="" + // CHECK-NEXT: (unresolved_decl_ref_expr type="" name="SelfParam" function_ref=unapplied) // CHECK-NEXT: (argument_list) SelfParam() } @@ -127,9 +126,8 @@ struct SelfParam { // CHECK-LABEL: (func_decl range=[{{.+}}] "dumpMemberTypeRepr()" // CHECK-NEXT: (parameter_list range=[{{.+}}]) -// CHECK-NEXT: (result -// CHECK-NEXT: (type_member -// CHECK-NEXT: (type_ident id='Array' bind=none) -// CHECK-NEXT: (type_ident id='Bool' bind=none) -// CHECK-NEXT: (type_ident id='Element' bind=none))) +// CHECK-NEXT: (result=type_member +// CHECK-NEXT: (type_ident id="Array" unbound +// CHECK-NEXT: (type_ident id="Bool" unbound)) +// CHECK-NEXT: (type_ident id="Element" unbound)) func dumpMemberTypeRepr() -> Array.Element { true } diff --git a/test/Frontend/module-alias-dump-ast.swift b/test/Frontend/module-alias-dump-ast.swift index 63e90c3d1b3..5aa3c8ab8f6 100644 --- a/test/Frontend/module-alias-dump-ast.swift +++ b/test/Frontend/module-alias-dump-ast.swift @@ -13,12 +13,12 @@ // RUN: %target-swift-frontend -dump-ast %t/FileLib.swift -module-alias XLogging=AppleLogging -I %t > %t/result-ast.output // RUN: %FileCheck %s -input-file %t/result-ast.output -check-prefix CHECK-AST -// CHECK-AST-NOT: bind=XLogging +// CHECK-AST-NOT: bind="XLogging" // CHECK-AST-NOT: module -// CHECK-AST-NOT: decl=XLogging -// CHECK-AST: type_ident id='XLogging' bind=AppleLogging +// CHECK-AST-NOT: decl="XLogging" +// CHECK-AST: type_ident id="XLogging" bind="AppleLogging" // CHECK-AST: module -// CHECK-AST: decl=AppleLogging +// CHECK-AST: decl="AppleLogging" // BEGIN FileLogging.swift public struct Logger { diff --git a/test/Generics/conditional_conformances.swift b/test/Generics/conditional_conformances.swift index cbcd9e07397..88e93e8f55e 100644 --- a/test/Generics/conditional_conformances.swift +++ b/test/Generics/conditional_conformances.swift @@ -19,8 +19,8 @@ func takes_P5(_: X) {} struct Free {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=Free -// CHECK-NEXT: (normal_conformance type=Free protocol=P2 -// CHECK-NEXT: conforms_to: T P1) +// CHECK-NEXT: (normal_conformance type="Free" protocol="P2" +// CHECK-NEXT: (requirement "T" conforms_to "P1")) extension Free: P2 where T: P1 {} // expected-note@-1 {{requirement from conditional conformance of 'Free' to 'P2'}} // expected-note@-2 {{requirement from conditional conformance of 'Free' to 'P2'}} @@ -34,8 +34,8 @@ func free_bad(_: U) { struct Constrained {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=Constrained // CHECK-LABEL: ExtensionDecl line={{.*}} base=Constrained -// CHECK-NEXT: (normal_conformance type=Constrained protocol=P2 -// CHECK-NEXT: conforms_to: T P3) +// CHECK-NEXT: (normal_conformance type="Constrained" protocol="P2" +// CHECK-NEXT: (requirement "T" conforms_to "P3")) extension Constrained: P2 where T: P3 {} // expected-note {{requirement from conditional conformance of 'Constrained' to 'P2'}} func constrained_good(_: U) { takes_P2(Constrained()) @@ -47,22 +47,22 @@ func constrained_bad(_: U) { struct RedundantSame {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundantSame // CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundantSame -// CHECK-NEXT: (normal_conformance type=RedundantSame protocol=P2) +// CHECK-NEXT: (normal_conformance type="RedundantSame" protocol="P2") extension RedundantSame: P2 where T: P1 {} // expected-warning@-1 {{redundant conformance constraint 'T' : 'P1'}} struct RedundantSuper {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundantSuper // CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundantSuper -// CHECK-NEXT: (normal_conformance type=RedundantSuper protocol=P2) +// CHECK-NEXT: (normal_conformance type="RedundantSuper" protocol="P2") extension RedundantSuper: P2 where T: P1 {} // expected-warning@-1 {{redundant conformance constraint 'T' : 'P1'}} struct OverlappingSub {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=OverlappingSub // CHECK-LABEL: ExtensionDecl line={{.*}} base=OverlappingSub -// CHECK-NEXT: (normal_conformance type=OverlappingSub protocol=P2 -// CHECK-NEXT: conforms_to: T P4) +// CHECK-NEXT: (normal_conformance type="OverlappingSub" protocol="P2" +// CHECK-NEXT: (requirement "T" conforms_to "P4")) extension OverlappingSub: P2 where T: P4 {} // expected-note {{requirement from conditional conformance of 'OverlappingSub' to 'P2'}} // expected-warning@-1 {{redundant conformance constraint 'T' : 'P1'}} func overlapping_sub_good(_: U) { @@ -76,8 +76,8 @@ func overlapping_sub_bad(_: U) { struct SameType {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=SameType // CHECK-LABEL: ExtensionDecl line={{.*}} base=SameType -// CHECK-NEXT: (normal_conformance type=SameType protocol=P2 -// CHECK-NEXT: same_type: T Int) +// CHECK-NEXT: (normal_conformance type="SameType" protocol="P2" +// CHECK-NEXT: (requirement "T" same_type "Int")) extension SameType: P2 where T == Int {} // expected-note@-1 {{requirement from conditional conformance of 'SameType' to 'P2'}} // expected-note@-2 {{requirement from conditional conformance of 'SameType' to 'P2'}} @@ -93,8 +93,8 @@ func same_type_bad(_: U) { struct SameTypeGeneric {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=SameTypeGeneric // CHECK-LABEL: ExtensionDecl line={{.*}} base=SameTypeGeneric -// CHECK-NEXT: (normal_conformance type=SameTypeGeneric protocol=P2 -// CHECK-NEXT: same_type: T U) +// CHECK-NEXT: (normal_conformance type="SameTypeGeneric" protocol="P2" +// CHECK-NEXT: (requirement "T" same_type "U")) extension SameTypeGeneric: P2 where T == U {} // expected-note@-1 {{requirement from conditional conformance of 'SameTypeGeneric' to 'P2'}} // expected-note@-2 {{requirement from conditional conformance of 'SameTypeGeneric' to 'P2'}} @@ -119,9 +119,9 @@ func same_type_bad(_: U, _: V) { struct Infer {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=Infer // CHECK-LABEL: ExtensionDecl line={{.*}} base=Infer -// CHECK-NEXT: (normal_conformance type=Infer protocol=P2 -// CHECK-NEXT: same_type: T Constrained -// CHECK-NEXT: conforms_to: U P1) +// CHECK-NEXT: (normal_conformance type="Infer" protocol="P2" +// CHECK-NEXT: (requirement "T" same_type "Constrained") +// CHECK-NEXT: (requirement "U" conforms_to "P1")) extension Infer: P2 where T == Constrained {} // expected-note@-1 2 {{requirement from conditional conformance of 'Infer, V>' to 'P2'}} func infer_good(_: U) { @@ -138,8 +138,8 @@ func infer_bad(_: U, _: V) { struct InferRedundant {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=InferRedundant // CHECK-LABEL: ExtensionDecl line={{.*}} base=InferRedundant -// CHECK-NEXT: (normal_conformance type=InferRedundant protocol=P2 -// CHECK-NEXT: same_type: T Constrained) +// CHECK-NEXT: (normal_conformance type="InferRedundant" protocol="P2" +// CHECK-NEXT: (requirement "T" same_type "Constrained")) extension InferRedundant: P2 where T == Constrained {} func infer_redundant_good(_: U) { takes_P2(InferRedundant, U>()) @@ -159,8 +159,8 @@ class C3: C2 {} struct ClassFree {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassFree // CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassFree -// CHECK-NEXT: (normal_conformance type=ClassFree protocol=P2 -// CHECK-NEXT: superclass: T C1) +// CHECK-NEXT: (normal_conformance type="ClassFree" protocol="P2" +// CHECK-NEXT: (requirement "T" subclass_of "C1")) extension ClassFree: P2 where T: C1 {} // expected-note {{requirement from conditional conformance of 'ClassFree' to 'P2'}} func class_free_good(_: U) { takes_P2(ClassFree()) @@ -173,8 +173,8 @@ func class_free_bad(_: U) { struct ClassMoreSpecific {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassMoreSpecific // CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassMoreSpecific -// CHECK-NEXT: (normal_conformance type=ClassMoreSpecific protocol=P2 -// CHECK-NEXT: superclass: T C3) +// CHECK-NEXT: (normal_conformance type="ClassMoreSpecific" protocol="P2" +// CHECK-NEXT: (requirement "T" subclass_of "C3")) extension ClassMoreSpecific: P2 where T: C3 {} // expected-note {{requirement from conditional conformance of 'ClassMoreSpecific' to 'P2'}} // expected-warning@-1 {{redundant superclass constraint 'T' : 'C1'}} func class_more_specific_good(_: U) { @@ -189,7 +189,7 @@ func class_more_specific_bad(_: U) { struct ClassLessSpecific {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassLessSpecific // CHECK-LABEL: ExtensionDecl line={{.*}} base=ClassLessSpecific -// CHECK-NEXT: (normal_conformance type=ClassLessSpecific protocol=P2) +// CHECK-NEXT: (normal_conformance type="ClassLessSpecific" protocol="P2") extension ClassLessSpecific: P2 where T: C1 {} // expected-warning@-1 {{redundant superclass constraint 'T' : 'C1'}} @@ -213,15 +213,15 @@ func subclass_bad() { struct InheritEqual {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritEqual // CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritEqual -// CHECK-NEXT: (normal_conformance type=InheritEqual protocol=P2 -// CHECK-NEXT: conforms_to: T P1) +// CHECK-NEXT: (normal_conformance type="InheritEqual" protocol="P2" +// CHECK-NEXT: (requirement "T" conforms_to "P1")) extension InheritEqual: P2 where T: P1 {} // expected-note {{requirement from conditional conformance of 'InheritEqual' to 'P2'}} // CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritEqual // CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritEqual -// CHECK-NEXT: (normal_conformance type=InheritEqual protocol=P5 -// CHECK-NEXT: (normal_conformance type=InheritEqual protocol=P2 -// CHECK-NEXT: conforms_to: T P1) -// CHECK-NEXT: conforms_to: T P1) +// CHECK-NEXT: (normal_conformance type="InheritEqual" protocol="P5" +// CHECK-NEXT: (normal_conformance type="InheritEqual" protocol="P2" +// CHECK-NEXT: (requirement "T" conforms_to "P1")) +// CHECK-NEXT: (requirement "T" conforms_to "P1")) extension InheritEqual: P5 where T: P1 {} // expected-note {{requirement from conditional conformance of 'InheritEqual' to 'P5'}} func inheritequal_good(_: U) { takes_P2(InheritEqual()) @@ -245,15 +245,15 @@ extension InheritLess: P5 {} struct InheritMore {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritMore // CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritMore -// CHECK-NEXT: (normal_conformance type=InheritMore protocol=P2 -// CHECK-NEXT: conforms_to: T P1) +// CHECK-NEXT: (normal_conformance type="InheritMore" protocol="P2" +// CHECK-NEXT: (requirement "T" conforms_to "P1")) extension InheritMore: P2 where T: P1 {} // expected-note {{requirement from conditional conformance of 'InheritMore' to 'P2'}} // CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritMore // CHECK-LABEL: ExtensionDecl line={{.*}} base=InheritMore -// CHECK-NEXT: (normal_conformance type=InheritMore protocol=P5 -// CHECK-NEXT: (normal_conformance type=InheritMore protocol=P2 -// CHECK-NEXT: conforms_to: T P1) -// CHECK-NEXT: conforms_to: T P4) +// CHECK-NEXT: (normal_conformance type="InheritMore" protocol="P5" +// CHECK-NEXT: (normal_conformance type="InheritMore" protocol="P2" +// CHECK-NEXT: (requirement "T" conforms_to "P1")) +// CHECK-NEXT: (requirement "T" conforms_to "P4")) extension InheritMore: P5 where T: P4 {} // expected-note 2 {{requirement from conditional conformance of 'InheritMore' to 'P5'}} func inheritequal_good_good(_: U) { takes_P2(InheritMore()) @@ -334,17 +334,17 @@ extension TwoDisjointConformances: P2 where T == String {} struct RedundancyOrderDependenceGood {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundancyOrderDependenceGood // CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundancyOrderDependenceGood -// CHECK-NEXT: (normal_conformance type=RedundancyOrderDependenceGood protocol=P2 -// CHECK-NEXT: same_type: T U) +// CHECK-NEXT: (normal_conformance type="RedundancyOrderDependenceGood" protocol="P2" +// CHECK-NEXT: (requirement "T" same_type "U")) extension RedundancyOrderDependenceGood: P2 where U: P1, T == U {} // expected-warning@-1 {{redundant conformance constraint 'U' : 'P1'}} struct RedundancyOrderDependenceBad {} // CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundancyOrderDependenceBad // CHECK-LABEL: ExtensionDecl line={{.*}} base=RedundancyOrderDependenceBad -// CHECK-NEXT: (normal_conformance type=RedundancyOrderDependenceBad protocol=P2 -// CHECK-NEXT: conforms_to: T P1 -// CHECK-NEXT: same_type: T U) +// CHECK-NEXT: (normal_conformance type="RedundancyOrderDependenceBad" protocol="P2" +// CHECK-NEXT: (requirement "T" conforms_to "P1") +// CHECK-NEXT: (requirement "T" same_type "U")) extension RedundancyOrderDependenceBad: P2 where T: P1, T == U {} // expected-warning {{redundant conformance constraint 'U' : 'P1'}} // Checking of conditional requirements for existential conversions. diff --git a/test/Generics/minimal_conformances_compare_concrete.swift b/test/Generics/minimal_conformances_compare_concrete.swift index a7b5d63a901..18f54a64214 100644 --- a/test/Generics/minimal_conformances_compare_concrete.swift +++ b/test/Generics/minimal_conformances_compare_concrete.swift @@ -14,9 +14,9 @@ struct G {} // CHECK-NEXT: Generic signature: extension G where X : Base, X : P, X == Derived {} -// RULE: + superclass: τ_0_0 Base -// RULE: + conforms_to: τ_0_0 P -// RULE: + same_type: τ_0_0 Derived +// RULE: + (requirement "\xCF\x84_0_0" subclass_of "Base") +// RULE: + (requirement "\xCF\x84_0_0" conforms_to "P") +// RULE: + (requirement "\xCF\x84_0_0" same_type "Derived") // RULE: Rewrite system: { // RULE-NEXT: - [P].[P] => [P] [permanent] @@ -36,4 +36,4 @@ extension G where X : Base, X : P, X == Derived {} // // - without concrete contraction, we used to hit a problem where the sort // in the minimal conformances algorithm would hit the unordered concrete -// conformances [concrete: Derived : P] vs [concrete: Base : P]. \ No newline at end of file +// conformances [concrete: Derived : P] vs [concrete: Base : P]. diff --git a/test/ImportResolution/import-resolution-overload.swift b/test/ImportResolution/import-resolution-overload.swift index 1f78b97b67b..1f66c9c7a0c 100644 --- a/test/ImportResolution/import-resolution-overload.swift +++ b/test/ImportResolution/import-resolution-overload.swift @@ -60,7 +60,7 @@ extension HasFooSub { func testHasFooSub(_ hfs: HasFooSub) -> Int { // CHECK: return_stmt // CHECK-NOT: func_decl - // CHECK: member_ref_expr{{.*}}decl=overload_vars.(file).HasFoo.foo + // CHECK: member_ref_expr{{.*}}decl="overload_vars.(file).HasFoo.foo return hfs.foo } @@ -72,7 +72,7 @@ extension HasBar { func testHasBar(_ hb: HasBar) -> Int { // CHECK: return_stmt // CHECK-NOT: func_decl - // CHECK: member_ref_expr{{.*}}decl=overload_vars.(file).HasBar.bar + // CHECK: member_ref_expr{{.*}}decl="overload_vars.(file).HasBar.bar return hb.bar } diff --git a/test/Parse/raw_string.swift b/test/Parse/raw_string.swift index 5a0f5c17d45..c8d8da0fcec 100644 --- a/test/Parse/raw_string.swift +++ b/test/Parse/raw_string.swift @@ -71,14 +71,13 @@ _ = ##""" // ===---------- False Multiline Delimiters --------=== /// Source code contains zero-width character in this format: `#"[U+200B]"[U+200B]"#` -/// The check contains zero-width character in this format: `"[U+200B]\"[U+200B]"` /// If this check fails after you implement `diagnoseZeroWidthMatchAndAdvance`, /// then you may need to tweak how to test for single-line string literals that /// resemble a multiline delimiter in `advanceIfMultilineDelimiter` so that it /// passes again. /// See https://github.com/apple/swift/issues/51192. _ = #"​"​"# -// CHECK: "​\"​" +// CHECK: "\xE2\x80\x8B\"\xE2\x80\x8B" _ = #""""# // CHECK: "\"\"" diff --git a/test/Parse/source_locs.swift b/test/Parse/source_locs.swift index 390b85c7efe..d68017ab3cf 100644 --- a/test/Parse/source_locs.swift +++ b/test/Parse/source_locs.swift @@ -7,5 +7,5 @@ func string_interpolation() { // RUN: not %target-swift-frontend -dump-ast %/s | %FileCheck %s // CHECK: (interpolated_string_literal_expr {{.*}} trailing_quote_loc=SOURCE_DIR/test/Parse/source_locs.swift:4:12 {{.*}} -// CHECK: (editor_placeholder_expr type='()' {{.*}} trailing_angle_bracket_loc=SOURCE_DIR/test/Parse/source_locs.swift:5:9 +// CHECK: (editor_placeholder_expr type="()" {{.*}} trailing_angle_bracket_loc=SOURCE_DIR/test/Parse/source_locs.swift:5:9 diff --git a/test/SILOptimizer/inline_generics.sil b/test/SILOptimizer/inline_generics.sil index 9499578121d..48de4b31de3 100644 --- a/test/SILOptimizer/inline_generics.sil +++ b/test/SILOptimizer/inline_generics.sil @@ -147,9 +147,9 @@ sil_vtable MyNumber {} // substituting we need to pick up the normal_conformance. // CHECK-LABEL: sil @test_inlining : $@convention(objc_method) (@owned MyNumber) -> () { -// CHECK-NOT: Generic specialization information for call-site dootherstuff conformances <(abstract_conformance protocol=OtherProto)> +// CHECK-NOT: Generic specialization information for call-site dootherstuff conformances <(abstract_conformance protocol="OtherProto")> // CHECK: Generic specialization information -// CHECK: (normal_conformance type=MyObject protocol=OtherProto) +// CHECK: (normal_conformance type="MyObject" protocol="OtherProto") // CHECK: end sil function 'test_inlining' sil @test_inlining : $@convention(objc_method) (@owned MyNumber) -> () { diff --git a/test/SILOptimizer/sil_combine_concrete_existential.sil b/test/SILOptimizer/sil_combine_concrete_existential.sil index a42c4c0735e..5626c523dea 100644 --- a/test/SILOptimizer/sil_combine_concrete_existential.sil +++ b/test/SILOptimizer/sil_combine_concrete_existential.sil @@ -670,8 +670,8 @@ sil @callee2 : $@convention(thin) <τ_0_0 where τ_0_0 : SubscriptionViewControl // CHECK: [[T5:%.*]] = function_ref @callee2 : $@convention(thin) <τ_0_0 where τ_0_0 : SubscriptionViewControllerDelegate> (@in τ_0_0, @thick SubscriptionViewControllerBuilder.Type) -> @owned SubscriptionViewControllerBuilder // CHECK: [[T6:%.*]] = alloc_stack $@opened("E4D92D2A-8893-11EA-9C89-ACDE48001122", any ResourceKitProtocol) Self // CHECK: copy_addr [[T4]] to [init] [[T6]] : $*@opened("E4D92D2A-8893-11EA-9C89-ACDE48001122", any ResourceKitProtocol) Self -// CHECK: Generic specialization information for call-site callee2 conformances <(inherited_conformance type=any ResourceKitProtocol protocol=SubscriptionViewControllerDelegate -// CHECK: (normal_conformance type=MyObject protocol=SubscriptionViewControllerDelegate))>: +// CHECK: Generic specialization information for call-site callee2 conformances <(inherited_conformance type="any ResourceKitProtocol" protocol="SubscriptionViewControllerDelegate" +// CHECK: (normal_conformance type="MyObject" protocol="SubscriptionViewControllerDelegate"))>: // CHECK: apply [[T5]]<@opened("E4D92D2A-8893-11EA-9C89-ACDE48001122", any ResourceKitProtocol) Self>([[T6]], [[T1]]) sil @test_opend_archetype_concrete_conformance_substitution : $@convention(method) (@guaranteed ResourceKitProtocol, @guaranteed ViewController) -> () { diff --git a/test/Sema/dynamic_self_implicit_conversions.swift b/test/Sema/dynamic_self_implicit_conversions.swift index 96909842458..3a85283bd67 100644 --- a/test/Sema/dynamic_self_implicit_conversions.swift +++ b/test/Sema/dynamic_self_implicit_conversions.swift @@ -19,32 +19,32 @@ class A { class B: A { func test() -> Self { - // CHECK: covariant_return_conversion_expr implicit type='Self' location={{.*}}.swift:[[@LINE+1]] + // CHECK: covariant_return_conversion_expr implicit type="Self" location={{.*}}.swift:[[@LINE+1]] _ = super.method() - // CHECK: covariant_function_conversion_expr implicit type='() -> Self' location={{.*}}.swift:[[@LINE+1]] + // CHECK: covariant_function_conversion_expr implicit type="() -> Self" location={{.*}}.swift:[[@LINE+1]] _ = super.method - // CHECK: covariant_return_conversion_expr implicit type='Self' location={{.*}}.swift:[[@LINE+1]] + // CHECK: covariant_return_conversion_expr implicit type="Self" location={{.*}}.swift:[[@LINE+1]] _ = super.property - // CHECK: covariant_return_conversion_expr implicit type='Self' location={{.*}}.swift:[[@LINE+1]] + // CHECK: covariant_return_conversion_expr implicit type="Self" location={{.*}}.swift:[[@LINE+1]] _ = super[] return super.property } static func testStatic() -> Self { - // CHECK: covariant_return_conversion_expr implicit type='Self' location={{.*}}.swift:[[@LINE+1]] + // CHECK: covariant_return_conversion_expr implicit type="Self" location={{.*}}.swift:[[@LINE+1]] _ = super.staticMethod() - // CHECK: covariant_function_conversion_expr implicit type='() -> Self' location={{.*}}.swift:[[@LINE+1]] + // CHECK: covariant_function_conversion_expr implicit type="() -> Self" location={{.*}}.swift:[[@LINE+1]] _ = super.staticMethod // CHECK-NOT: function_conversion_expr {{.*}} location={{.*}}.swift:[[@LINE+3]] // CHECK-NOT: covariant_function_conversion_expr {{.*}} location={{.*}}.swift:[[@LINE+2]] - // CHECK: covariant_return_conversion_expr implicit type='Self' location={{.*}}.swift:[[@LINE+1]] + // CHECK: covariant_return_conversion_expr implicit type="Self" location={{.*}}.swift:[[@LINE+1]] _ = self.method - // CHECK: covariant_return_conversion_expr implicit type='Self' location={{.*}}.swift:[[@LINE+1]] + // CHECK: covariant_return_conversion_expr implicit type="Self" location={{.*}}.swift:[[@LINE+1]] _ = self.init() - // CHECK: covariant_return_conversion_expr implicit type='Self' location={{.*}}.swift:[[@LINE+1]] + // CHECK: covariant_return_conversion_expr implicit type="Self" location={{.*}}.swift:[[@LINE+1]] _ = super.staticProperty - // CHECK: covariant_return_conversion_expr implicit type='Self' location={{.*}}.swift:[[@LINE+1]] + // CHECK: covariant_return_conversion_expr implicit type="Self" location={{.*}}.swift:[[@LINE+1]] _ = super[] return super.staticProperty @@ -53,8 +53,8 @@ class B: A { func testOnExistential(arg: P & A) { // FIXME: This could be a single conversion. - // CHECK: function_conversion_expr implicit type='() -> any A & P' location={{.*}}.swift:[[@LINE+2]] - // CHECK-NEXT: covariant_function_conversion_expr implicit type='() -> any A & P' location={{.*}}.swift:[[@LINE+1]] + // CHECK: function_conversion_expr implicit type="() -> any A & P" location={{.*}}.swift:[[@LINE+2]] + // CHECK-NEXT: covariant_function_conversion_expr implicit type="() -> any A & P" location={{.*}}.swift:[[@LINE+1]] _ = arg.method } diff --git a/test/Sema/property_wrappers.swift b/test/Sema/property_wrappers.swift index 82c26ca5bac..e163c45e8cd 100644 --- a/test/Sema/property_wrappers.swift +++ b/test/Sema/property_wrappers.swift @@ -17,11 +17,11 @@ struct WrapperWithClosureArg { // rdar://problem/59685601 // CHECK-LABEL: R_59685601 struct R_59685601 { - // CHECK: argument_list implicit labels=wrappedValue:reset: - // CHECK-NEXT: argument label=wrappedValue - // CHECK-NEXT: property_wrapper_value_placeholder_expr implicit type='String' - // CHECK-NEXT: opaque_value_expr implicit type='String' - // CHECK-NEXT: string_literal_expr type='String' + // CHECK: argument_list implicit labels="wrappedValue:reset:" + // CHECK-NEXT: argument label="wrappedValue" + // CHECK-NEXT: property_wrapper_value_placeholder_expr implicit type="String" + // CHECK-NEXT: opaque_value_expr implicit type="String" + // CHECK-NEXT: string_literal_expr type="String" @WrapperWithClosureArg(reset: { value, transaction in transaction.state = 10 }) @@ -37,13 +37,13 @@ struct Wrapper { struct TestInitSubscript { enum Color: CaseIterable { case pink } - // CHECK: argument_list labels=wrappedValue: - // CHECK-NEXT: argument label=wrappedValue - // CHECK-NEXT: subscript_expr type='TestInitSubscript.Color' + // CHECK: argument_list labels="wrappedValue:" + // CHECK-NEXT: argument label="wrappedValue" + // CHECK-NEXT: subscript_expr type="TestInitSubscript.Color" // CHECK: argument_list implicit // CHECK-NEXT: argument - // CHECK-NOT: property_wrapper_value_placeholder_expr implicit type='Int' - // CHECK: integer_literal_expr type='Int' + // CHECK-NOT: property_wrapper_value_placeholder_expr implicit type="Int" + // CHECK: integer_literal_expr type="Int" @Wrapper(wrappedValue: Color.allCases[0]) var color: Color } @@ -68,19 +68,19 @@ public class W_58201 { // CHECK-LABEL: struct_decl{{.*}}S1_58201 struct S1_58201 { - // CHECK: argument_list implicit labels=wrappedValue: - // CHECK-NEXT: argument label=wrappedValue - // CHECK-NEXT: autoclosure_expr implicit type='() -> Bool?' discriminator=0 captures=( ) escaping - // CHECK: autoclosure_expr implicit type='() -> Bool?' discriminator=1 escaping + // CHECK: argument_list implicit labels="wrappedValue:" + // CHECK-NEXT: argument label="wrappedValue" + // CHECK-NEXT: autoclosure_expr implicit type="() -> Bool?" discriminator=0 captures=( ) escaping + // CHECK: autoclosure_expr implicit type="() -> Bool?" discriminator=1 escaping @W_58201 var a: Bool? } // CHECK-LABEL: struct_decl{{.*}}S2_58201 struct S2_58201 { - // CHECK: argument_list implicit labels=wrappedValue: - // CHECK-NEXT: argument label=wrappedValue - // CHECK-NEXT: autoclosure_expr implicit type='() -> Bool' location={{.*}}.swift:[[@LINE+2]]:26 range=[{{.+}}] discriminator=0 captures=( ) escaping - // CHECK: autoclosure_expr implicit type='() -> Bool' location={{.*}}.swift:[[@LINE+1]]:26 range=[{{.+}}] discriminator=1 escaping + // CHECK: argument_list implicit labels="wrappedValue:" + // CHECK-NEXT: argument label="wrappedValue" + // CHECK-NEXT: autoclosure_expr implicit type="() -> Bool" location={{.*}}.swift:[[@LINE+2]]:26 range=[{{.+}}] discriminator=0 captures=( ) escaping + // CHECK: autoclosure_expr implicit type="() -> Bool" location={{.*}}.swift:[[@LINE+1]]:26 range=[{{.+}}] discriminator=1 escaping @W_58201 var b: Bool = false } diff --git a/test/Sema/type_eraser.swift b/test/Sema/type_eraser.swift index bb04aad8648..34e7fab0476 100644 --- a/test/Sema/type_eraser.swift +++ b/test/Sema/type_eraser.swift @@ -11,45 +11,45 @@ struct ConcreteP: P, Hashable {} // CHECK-LABEL: testBasic dynamic func testBasic() -> some P { - // CHECK: underlying_to_opaque_expr{{.*}}'some P' - // CHECK-NEXT: call_expr implicit type='AnyP' - // CHECK: argument_list implicit labels=erasing: - // CHECK-NEXT: argument label=erasing - // CHECK-NEXT: call_expr type='ConcreteP' + // CHECK: underlying_to_opaque_expr{{.*}}"some P" + // CHECK-NEXT: call_expr implicit type="AnyP" + // CHECK: argument_list implicit labels="erasing:" + // CHECK-NEXT: argument label="erasing" + // CHECK-NEXT: call_expr type="ConcreteP" ConcreteP() } // CHECK-LABEL: testTypeAlias typealias AliasForP = P dynamic func testTypeAlias() -> some AliasForP { - // CHECK: underlying_to_opaque_expr{{.*}}'some P' - // CHECK-NEXT: call_expr implicit type='AnyP' - // CHECK: argument_list implicit labels=erasing: - // CHECK-NEXT: argument label=erasing - // CHECK-NEXT: call_expr type='ConcreteP' + // CHECK: underlying_to_opaque_expr{{.*}}"some P" + // CHECK-NEXT: call_expr implicit type="AnyP" + // CHECK: argument_list implicit labels="erasing:" + // CHECK-NEXT: argument label="erasing" + // CHECK-NEXT: call_expr type="ConcreteP" ConcreteP() } // CHECK-LABEL: testNoDynamic func testNoDynamic() -> some P { - // CHECK: underlying_to_opaque_expr{{.*}}'some P' - // CHECK-NEXT: call_expr type='ConcreteP' + // CHECK: underlying_to_opaque_expr{{.*}}"some P" + // CHECK-NEXT: call_expr type="ConcreteP" ConcreteP() } // CHECK-LABEL: testNoOpaque dynamic func testNoOpaque() -> P { - // CHECK: erasure_expr implicit type='any P' - // CHECK-NEXT: normal_conformance type=ConcreteP protocol=P - // CHECK-NEXT: call_expr type='ConcreteP' + // CHECK: erasure_expr implicit type="any P" + // CHECK-NEXT: normal_conformance type="ConcreteP" protocol="P" + // CHECK-NEXT: call_expr type="ConcreteP" ConcreteP() } // CHECK-LABEL: testComposition typealias Composition = P & Hashable dynamic func testComposition() -> some Composition { - // CHECK: underlying_to_opaque_expr{{.*}}'some Hashable & P' - // CHECK-NEXT: call_expr type='ConcreteP' + // CHECK: underlying_to_opaque_expr{{.*}}"some Hashable & P" + // CHECK-NEXT: call_expr type="ConcreteP" ConcreteP() } @@ -66,11 +66,11 @@ class TestResultBuilder { // CHECK-LABEL: testTransformFnBody @Builder dynamic var testTransformFnBody: some P { // CHECK: return_stmt - // CHECK-NEXT: underlying_to_opaque_expr implicit type='some P' - // CHECK-NEXT: call_expr implicit type='AnyP' - // CHECK: argument_list implicit labels=erasing: - // CHECK-NEXT: argument label=erasing - // CHECK: declref_expr implicit type='@lvalue ConcreteP' + // CHECK-NEXT: underlying_to_opaque_expr implicit type="some P" + // CHECK-NEXT: call_expr implicit type="AnyP" + // CHECK: argument_list implicit labels="erasing:" + // CHECK-NEXT: argument label="erasing" + // CHECK: declref_expr implicit type="@lvalue ConcreteP" ConcreteP() } @@ -79,14 +79,14 @@ class TestResultBuilder { // CHECK-LABEL: testClosureBuilder dynamic var testClosureBuilder: some P { - // CHECK: underlying_to_opaque_expr implicit type='some P' - // CHECK-NEXT: call_expr implicit type='AnyP' - // CHECK: argument_list implicit labels=erasing: - // CHECK-NEXT: argument label=erasing - // CHECK: closure_expr type='() -> ConcreteP' + // CHECK: underlying_to_opaque_expr implicit type="some P" + // CHECK-NEXT: call_expr implicit type="AnyP" + // CHECK: argument_list implicit labels="erasing:" + // CHECK-NEXT: argument label="erasing" + // CHECK: closure_expr type="() -> ConcreteP" takesBuilder { // CHECK: return_stmt - // CHECK-NEXT: call_expr implicit type='ConcreteP' + // CHECK-NEXT: call_expr implicit type="ConcreteP" ConcreteP() } } @@ -95,11 +95,11 @@ class TestResultBuilder { // CHECK-LABEL: class_decl{{.*}}DynamicReplacement class DynamicReplacement { dynamic func testDynamicReplaceable() -> some P { - // CHECK: underlying_to_opaque_expr implicit type='some P' - // CHECK-NEXT: call_expr implicit type='AnyP' - // CHECK: argument_list implicit labels=erasing: - // CHECK-NEXT: argument label=erasing - // CHECK-NEXT: call_expr type='ConcreteP' + // CHECK: underlying_to_opaque_expr implicit type="some P" + // CHECK-NEXT: call_expr implicit type="AnyP" + // CHECK: argument_list implicit labels="erasing:" + // CHECK-NEXT: argument label="erasing" + // CHECK-NEXT: call_expr type="ConcreteP" ConcreteP() } } @@ -111,11 +111,11 @@ extension DynamicReplacement { func testDynamicReplacement() -> some P { print("not single expr return") // CHECK: return_stmt - // CHECK-NEXT: underlying_to_opaque_expr implicit type='some P' - // CHECK-NEXT: call_expr implicit type='AnyP' - // CHECK: argument_list implicit labels=erasing: - // CHECK-NEXT: argument label=erasing - // CHECK-NEXT: call_expr type='ConcreteP' + // CHECK-NEXT: underlying_to_opaque_expr implicit type="some P" + // CHECK-NEXT: call_expr implicit type="AnyP" + // CHECK: argument_list implicit labels="erasing:" + // CHECK-NEXT: argument label="erasing" + // CHECK-NEXT: call_expr type="ConcreteP" return ConcreteP() } } diff --git a/test/Sema/type_eraser_experimental_flag.swift b/test/Sema/type_eraser_experimental_flag.swift index 01da2263b7f..c55105c9cc6 100644 --- a/test/Sema/type_eraser_experimental_flag.swift +++ b/test/Sema/type_eraser_experimental_flag.swift @@ -11,7 +11,7 @@ struct ConcreteP: P, Hashable {} // CHECK-LABEL: testTypeErased func testTypeErased() -> some P { - // CHECK: underlying_to_opaque_expr{{.*}}'some P' - // CHECK-NEXT: call_expr implicit type='AnyP' + // CHECK: underlying_to_opaque_expr{{.*}}"some P" + // CHECK-NEXT: call_expr implicit type="AnyP" ConcreteP() -} \ No newline at end of file +} diff --git a/test/attr/ApplicationMain/attr_main_throws.swift b/test/attr/ApplicationMain/attr_main_throws.swift index 3558da69e39..6c3f53cc108 100644 --- a/test/attr/ApplicationMain/attr_main_throws.swift +++ b/test/attr/ApplicationMain/attr_main_throws.swift @@ -7,10 +7,10 @@ struct MyBase { } } -// CHECK-AST: (func_decl implicit "$main()" interface type='(MyBase.Type) -> () throws -> ()' access=internal type +// CHECK-AST: (func_decl implicit "$main()" interface type="(MyBase.Type) -> () throws -> ()" access=internal type // CHECK-AST-NEXT: (parameter "self") // CHECK-AST-NEXT: (parameter_list) // CHECK-AST-NEXT: (brace_stmt implicit // CHECK-AST-NEXT: (return_stmt implicit // CHECK-AST-NEXT: (try_expr implicit -// CHECK-AST-NEXT: (call_expr implicit type='()' +// CHECK-AST-NEXT: (call_expr implicit type="()" diff --git a/test/attr/attr_fixed_layout.swift b/test/attr/attr_fixed_layout.swift index d269d1ee42e..60a4d56463e 100644 --- a/test/attr/attr_fixed_layout.swift +++ b/test/attr/attr_fixed_layout.swift @@ -7,21 +7,21 @@ // Public types with @frozen are always fixed layout // -// RESILIENCE-ON: struct_decl{{.*}}"Point" interface type='Point.Type' access=public non-resilient -// RESILIENCE-OFF: struct_decl{{.*}}"Point" interface type='Point.Type' access=public non-resilient +// RESILIENCE-ON: struct_decl{{.*}}"Point" interface type="Point.Type" access=public non_resilient +// RESILIENCE-OFF: struct_decl{{.*}}"Point" interface type="Point.Type" access=public non_resilient @frozen public struct Point { let x, y: Int } -// RESILIENCE-ON: struct_decl{{.*}}"FixedPoint" interface type='FixedPoint.Type' access=public non-resilient -// RESILIENCE-OFF: struct_decl{{.*}}"FixedPoint" interface type='FixedPoint.Type' access=public non-resilient +// RESILIENCE-ON: struct_decl{{.*}}"FixedPoint" interface type="FixedPoint.Type" access=public non_resilient +// RESILIENCE-OFF: struct_decl{{.*}}"FixedPoint" interface type="FixedPoint.Type" access=public non_resilient @_fixed_layout public struct FixedPoint { // expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}} let x, y: Int } -// RESILIENCE-ON: enum_decl{{.*}}"ChooseYourOwnAdventure" interface type='ChooseYourOwnAdventure.Type' access=public non-resilient -// RESILIENCE-OFF: enum_decl{{.*}}"ChooseYourOwnAdventure" interface type='ChooseYourOwnAdventure.Type' access=public non-resilient +// RESILIENCE-ON: enum_decl{{.*}}"ChooseYourOwnAdventure" interface type="ChooseYourOwnAdventure.Type" access=public non_resilient +// RESILIENCE-OFF: enum_decl{{.*}}"ChooseYourOwnAdventure" interface type="ChooseYourOwnAdventure.Type" access=public non_resilient @frozen public enum ChooseYourOwnAdventure { case JumpIntoRabbitHole case EatMushroom @@ -31,23 +31,23 @@ // Public types are resilient when -enable-library-evolution is on // -// RESILIENCE-ON: struct_decl{{.*}}"Size" interface type='Size.Type' access=public resilient -// RESILIENCE-OFF: struct_decl{{.*}}"Size" interface type='Size.Type' access=public non-resilient +// RESILIENCE-ON: struct_decl{{.*}}"Size" interface type="Size.Type" access=public resilient +// RESILIENCE-OFF: struct_decl{{.*}}"Size" interface type="Size.Type" access=public non_resilient public struct Size { let w, h: Int } -// RESILIENCE-ON: struct_decl{{.*}}"UsableFromInlineStruct" interface type='UsableFromInlineStruct.Type' access=internal non-resilient -// RESILIENCE-OFF: struct_decl{{.*}}"UsableFromInlineStruct" interface type='UsableFromInlineStruct.Type' access=internal non-resilient +// RESILIENCE-ON: struct_decl{{.*}}"UsableFromInlineStruct" interface type="UsableFromInlineStruct.Type" access=internal non_resilient +// RESILIENCE-OFF: struct_decl{{.*}}"UsableFromInlineStruct" interface type="UsableFromInlineStruct.Type" access=internal non_resilient @frozen @usableFromInline struct UsableFromInlineStruct {} -// RESILIENCE-ON: struct_decl{{.*}}"UsableFromInlineFixedStruct" interface type='UsableFromInlineFixedStruct.Type' access=internal non-resilient -// RESILIENCE-OFF: struct_decl{{.*}}"UsableFromInlineFixedStruct" interface type='UsableFromInlineFixedStruct.Type' access=internal non-resilient +// RESILIENCE-ON: struct_decl{{.*}}"UsableFromInlineFixedStruct" interface type="UsableFromInlineFixedStruct.Type" access=internal non_resilient +// RESILIENCE-OFF: struct_decl{{.*}}"UsableFromInlineFixedStruct" interface type="UsableFromInlineFixedStruct.Type" access=internal non_resilient @_fixed_layout @usableFromInline struct UsableFromInlineFixedStruct {} // expected-warning@-1 {{'@frozen' attribute is now used for fixed-layout structs}} -// RESILIENCE-ON: enum_decl{{.*}}"TaxCredit" interface type='TaxCredit.Type' access=public resilient -// RESILIENCE-OFF: enum_decl{{.*}}"TaxCredit" interface type='TaxCredit.Type' access=public non-resilient +// RESILIENCE-ON: enum_decl{{.*}}"TaxCredit" interface type="TaxCredit.Type" access=public resilient +// RESILIENCE-OFF: enum_decl{{.*}}"TaxCredit" interface type="TaxCredit.Type" access=public non_resilient public enum TaxCredit { case EarnedIncome case MortgageDeduction @@ -57,8 +57,8 @@ public enum TaxCredit { // Internal types are always fixed layout // -// RESILIENCE-ON: struct_decl{{.*}}"Rectangle" interface type='Rectangle.Type' access=internal non-resilient -// RESILIENCE-OFF: struct_decl{{.*}}"Rectangle" interface type='Rectangle.Type' access=internal non-resilient +// RESILIENCE-ON: struct_decl{{.*}}"Rectangle" interface type="Rectangle.Type" access=internal non_resilient +// RESILIENCE-OFF: struct_decl{{.*}}"Rectangle" interface type="Rectangle.Type" access=internal non_resilient struct Rectangle { let topLeft: Point let bottomRight: Size diff --git a/test/attr/attr_native_dynamic.swift b/test/attr/attr_native_dynamic.swift index 54cae08b7e4..85aae3c498b 100644 --- a/test/attr/attr_native_dynamic.swift +++ b/test/attr/attr_native_dynamic.swift @@ -2,30 +2,30 @@ struct Strukt { // CHECK: (struct_decl {{.*}} "Strukt" - // CHECK: (var_decl {{.*}} "dynamicStorageOnlyVar" interface type='Int' access=internal dynamic readImpl=stored writeImpl=stored readWriteImpl=stored - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=dynamicStorageOnlyVar - // CHECK: (accessor_decl {{.*}} access=internal dynamic set_for=dynamicStorageOnlyVar - // CHECK: (accessor_decl {{.*}} access=internal _modify_for=dynamicStorageOnlyVar + // CHECK: (var_decl {{.*}} "dynamicStorageOnlyVar" interface type="Int" access=internal dynamic readImpl=stored writeImpl=stored readWriteImpl=stored + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="dynamicStorageOnlyVar" + // CHECK: (accessor_decl {{.*}} access=internal dynamic set for="dynamicStorageOnlyVar" + // CHECK: (accessor_decl {{.*}} access=internal _modify for="dynamicStorageOnlyVar" dynamic var dynamicStorageOnlyVar : Int = 0 - // CHECK: (var_decl {{.*}} "computedVar" interface type='Int' access=internal dynamic readImpl=getter immutable - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=computedVar + // CHECK: (var_decl {{.*}} "computedVar" interface type="Int" access=internal dynamic readImpl=getter immutable + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="computedVar" dynamic var computedVar : Int { return 0 } - // CHECK: (var_decl {{.*}} "computedVar2" interface type='Int' access=internal dynamic readImpl=getter immutable - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=computedVar2 + // CHECK: (var_decl {{.*}} "computedVar2" interface type="Int" access=internal dynamic readImpl=getter immutable + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="computedVar2" dynamic var computedVar2 : Int { get { return 0 } } - // CHECK: (var_decl {{.*}} "computedVarGetterSetter" interface type='Int' access=internal dynamic readImpl=getter writeImpl=setter readWriteImpl=materialize_to_temporary - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=computedVarGetterSetter - // CHECK: (accessor_decl {{.*}} access=internal dynamic set_for=computedVarGetterSetter - // CHECK: (accessor_decl {{.*}} access=internal _modify_for=computedVarGetterSetter + // CHECK: (var_decl {{.*}} "computedVarGetterSetter" interface type="Int" access=internal dynamic readImpl=getter writeImpl=setter readWriteImpl=materialize_to_temporary + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="computedVarGetterSetter" + // CHECK: (accessor_decl {{.*}} access=internal dynamic set for="computedVarGetterSetter" + // CHECK: (accessor_decl {{.*}} access=internal _modify for="computedVarGetterSetter" dynamic var computedVarGetterSetter : Int { get { return 0 @@ -34,10 +34,10 @@ struct Strukt { } } - // CHECK: (var_decl {{.*}} "computedVarGetterModify" interface type='Int' access=internal dynamic readImpl=getter writeImpl=modify_coroutine readWriteImpl=modify_coroutine - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=computedVarGetterModify - // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify_for=computedVarGetterModify - // CHECK: (accessor_decl {{.*}} access=internal set_for=computedVarGetterModify + // CHECK: (var_decl {{.*}} "computedVarGetterModify" interface type="Int" access=internal dynamic readImpl=getter writeImpl=modify_coroutine readWriteImpl=modify_coroutine + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="computedVarGetterModify" + // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify for="computedVarGetterModify" + // CHECK: (accessor_decl {{.*}} access=internal set for="computedVarGetterModify" dynamic var computedVarGetterModify : Int { get { return 0 @@ -46,11 +46,11 @@ struct Strukt { } } - // CHECK: (var_decl {{.*}} "computedVarReadSet" interface type='Int' access=internal dynamic readImpl=read_coroutine writeImpl=setter readWriteImpl=materialize_to_temporary - // CHECK: (accessor_decl {{.*}} access=internal dynamic _read_for=computedVarReadSet - // CHECK: (accessor_decl {{.*}} access=internal dynamic set_for=computedVarReadSet - // CHECK: (accessor_decl {{.*}} access=internal get_for=computedVarReadSet - // CHECK: (accessor_decl {{.*}} access=internal _modify_for=computedVarReadSet + // CHECK: (var_decl {{.*}} "computedVarReadSet" interface type="Int" access=internal dynamic readImpl=read_coroutine writeImpl=setter readWriteImpl=materialize_to_temporary + // CHECK: (accessor_decl {{.*}} access=internal dynamic _read for="computedVarReadSet" + // CHECK: (accessor_decl {{.*}} access=internal dynamic set for="computedVarReadSet" + // CHECK: (accessor_decl {{.*}} access=internal get for="computedVarReadSet" + // CHECK: (accessor_decl {{.*}} access=internal _modify for="computedVarReadSet" dynamic var computedVarReadSet : Int { _read { } @@ -58,11 +58,11 @@ struct Strukt { } } - // CHECK: (var_decl {{.*}} "computedVarReadModify" interface type='Int' access=internal dynamic readImpl=read_coroutine writeImpl=modify_coroutine readWriteImpl=modify_coroutine - // CHECK: (accessor_decl {{.*}} access=internal dynamic _read_for=computedVarReadModify - // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify_for=computedVarReadModify - // CHECK: (accessor_decl {{.*}} access=internal get_for=computedVarReadModify - // CHECK: (accessor_decl {{.*}} access=internal set_for=computedVarReadModify + // CHECK: (var_decl {{.*}} "computedVarReadModify" interface type="Int" access=internal dynamic readImpl=read_coroutine writeImpl=modify_coroutine readWriteImpl=modify_coroutine + // CHECK: (accessor_decl {{.*}} access=internal dynamic _read for="computedVarReadModify" + // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify for="computedVarReadModify" + // CHECK: (accessor_decl {{.*}} access=internal get for="computedVarReadModify" + // CHECK: (accessor_decl {{.*}} access=internal set for="computedVarReadModify" dynamic var computedVarReadModify : Int { _read { } @@ -70,11 +70,11 @@ struct Strukt { } } - // CHECK: (var_decl {{.*}} "storedWithObserver" interface type='Int' access=internal dynamic readImpl=stored writeImpl=stored_with_observers readWriteImpl=stored_with_didset - // CHECK: (accessor_decl {{.*}}access=private dynamic didSet_for=storedWithObserver - // CHECK: (accessor_decl {{.*}}access=internal dynamic get_for=storedWithObserver - // CHECK: (accessor_decl {{.*}}access=internal set_for=storedWithObserver - // CHECK: (accessor_decl {{.*}}access=internal _modify_for=storedWithObserver + // CHECK: (var_decl {{.*}} "storedWithObserver" interface type="Int" access=internal dynamic readImpl=stored writeImpl=stored_with_observers readWriteImpl=stored_with_didset + // CHECK: (accessor_decl {{.*}}access=private dynamic didSet for="storedWithObserver" + // CHECK: (accessor_decl {{.*}}access=internal dynamic get for="storedWithObserver" + // CHECK: (accessor_decl {{.*}}access=internal set for="storedWithObserver" + // CHECK: (accessor_decl {{.*}}access=internal _modify for="storedWithObserver" dynamic var storedWithObserver : Int { didSet { } @@ -86,9 +86,9 @@ struct Strukt { } // CHECK: (subscript_decl {{.*}} "subscript(_:)" {{.*}} access=internal dynamic readImpl=getter writeImpl=setter readWriteImpl=materialize_to_temporary - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal dynamic set_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal _modify_for=subscript(_:) + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal dynamic set for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal _modify for="subscript(_:)" dynamic subscript(_ index: Int) -> Int { get { return 1 @@ -98,9 +98,9 @@ struct Strukt { } // CHECK: (subscript_decl {{.*}} "subscript(_:)" {{.*}} access=internal dynamic readImpl=getter writeImpl=modify_coroutine readWriteImpl=modify_coroutine - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal set_for=subscript(_:) + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal set for="subscript(_:)" dynamic subscript(_ index: Float) -> Int { get { return 1 @@ -110,10 +110,10 @@ struct Strukt { } // CHECK: (subscript_decl {{.*}} "subscript(_:)" {{.*}} access=internal dynamic readImpl=read_coroutine writeImpl=modify_coroutine readWriteImpl=modify_coroutine - // CHECK: (accessor_decl {{.*}} access=internal dynamic _read_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal get_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal set_for=subscript(_:) + // CHECK: (accessor_decl {{.*}} access=internal dynamic _read for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal get for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal set for="subscript(_:)" dynamic subscript(_ index: Double) -> Int { _read { } @@ -122,10 +122,10 @@ struct Strukt { } // CHECK: (subscript_decl {{.*}} "subscript(_:)" {{.*}} access=internal dynamic readImpl=read_coroutine writeImpl=setter readWriteImpl=materialize_to_temporary - // CHECK: (accessor_decl {{.*}} access=internal dynamic _read_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal dynamic set_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal get_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal _modify_for=subscript(_:) + // CHECK: (accessor_decl {{.*}} access=internal dynamic _read for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal dynamic set for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal get for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal _modify for="subscript(_:)" dynamic subscript(_ index: Strukt) -> Int { _read { } @@ -136,30 +136,30 @@ struct Strukt { class Klass { // CHECK: (class_decl {{.*}} "Klass" - // CHECK: (var_decl {{.*}} "dynamicStorageOnlyVar" interface type='Int' access=internal dynamic readImpl=stored writeImpl=stored readWriteImpl=stored - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=dynamicStorageOnlyVar - // CHECK: (accessor_decl {{.*}} access=internal dynamic set_for=dynamicStorageOnlyVar - // CHECK: (accessor_decl {{.*}} access=internal _modify_for=dynamicStorageOnlyVar + // CHECK: (var_decl {{.*}} "dynamicStorageOnlyVar" interface type="Int" access=internal dynamic readImpl=stored writeImpl=stored readWriteImpl=stored + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="dynamicStorageOnlyVar" + // CHECK: (accessor_decl {{.*}} access=internal dynamic set for="dynamicStorageOnlyVar" + // CHECK: (accessor_decl {{.*}} access=internal _modify for="dynamicStorageOnlyVar" dynamic var dynamicStorageOnlyVar : Int = 0 - // CHECK: (var_decl {{.*}} "computedVar" interface type='Int' access=internal dynamic readImpl=getter immutable - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=computedVar + // CHECK: (var_decl {{.*}} "computedVar" interface type="Int" access=internal dynamic readImpl=getter immutable + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="computedVar" dynamic var computedVar : Int { return 0 } - // CHECK: (var_decl {{.*}} "computedVar2" interface type='Int' access=internal dynamic readImpl=getter immutable - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=computedVar2 + // CHECK: (var_decl {{.*}} "computedVar2" interface type="Int" access=internal dynamic readImpl=getter immutable + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="computedVar2" dynamic var computedVar2 : Int { get { return 0 } } - // CHECK: (var_decl {{.*}} "computedVarGetterSetter" interface type='Int' access=internal dynamic readImpl=getter writeImpl=setter readWriteImpl=materialize_to_temporary - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=computedVarGetterSetter - // CHECK: (accessor_decl {{.*}} access=internal dynamic set_for=computedVarGetterSetter - // CHECK: (accessor_decl {{.*}} access=internal _modify_for=computedVarGetterSetter + // CHECK: (var_decl {{.*}} "computedVarGetterSetter" interface type="Int" access=internal dynamic readImpl=getter writeImpl=setter readWriteImpl=materialize_to_temporary + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="computedVarGetterSetter" + // CHECK: (accessor_decl {{.*}} access=internal dynamic set for="computedVarGetterSetter" + // CHECK: (accessor_decl {{.*}} access=internal _modify for="computedVarGetterSetter" dynamic var computedVarGetterSetter : Int { get { return 0 @@ -168,10 +168,10 @@ class Klass { } } - // CHECK: (var_decl {{.*}} "computedVarGetterModify" interface type='Int' access=internal dynamic readImpl=getter writeImpl=modify_coroutine readWriteImpl=modify_coroutine - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=computedVarGetterModify - // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify_for=computedVarGetterModify - // CHECK: (accessor_decl {{.*}} access=internal set_for=computedVarGetterModify + // CHECK: (var_decl {{.*}} "computedVarGetterModify" interface type="Int" access=internal dynamic readImpl=getter writeImpl=modify_coroutine readWriteImpl=modify_coroutine + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="computedVarGetterModify" + // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify for="computedVarGetterModify" + // CHECK: (accessor_decl {{.*}} access=internal set for="computedVarGetterModify" dynamic var computedVarGetterModify : Int { get { return 0 @@ -180,11 +180,11 @@ class Klass { } } - // CHECK: (var_decl {{.*}} "computedVarReadSet" interface type='Int' access=internal dynamic readImpl=read_coroutine writeImpl=setter readWriteImpl=materialize_to_temporary - // CHECK: (accessor_decl {{.*}} access=internal dynamic _read_for=computedVarReadSet - // CHECK: (accessor_decl {{.*}} access=internal dynamic set_for=computedVarReadSet - // CHECK: (accessor_decl {{.*}} access=internal get_for=computedVarReadSet - // CHECK: (accessor_decl {{.*}} access=internal _modify_for=computedVarReadSet + // CHECK: (var_decl {{.*}} "computedVarReadSet" interface type="Int" access=internal dynamic readImpl=read_coroutine writeImpl=setter readWriteImpl=materialize_to_temporary + // CHECK: (accessor_decl {{.*}} access=internal dynamic _read for="computedVarReadSet" + // CHECK: (accessor_decl {{.*}} access=internal dynamic set for="computedVarReadSet" + // CHECK: (accessor_decl {{.*}} access=internal get for="computedVarReadSet" + // CHECK: (accessor_decl {{.*}} access=internal _modify for="computedVarReadSet" dynamic var computedVarReadSet : Int { _read { } @@ -192,11 +192,11 @@ class Klass { } } - // CHECK: (var_decl {{.*}} "computedVarReadModify" interface type='Int' access=internal dynamic readImpl=read_coroutine writeImpl=modify_coroutine readWriteImpl=modify_coroutine - // CHECK: (accessor_decl {{.*}} access=internal dynamic _read_for=computedVarReadModify - // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify_for=computedVarReadModify - // CHECK: (accessor_decl {{.*}} access=internal get_for=computedVarReadModify - // CHECK: (accessor_decl {{.*}} access=internal set_for=computedVarReadModify + // CHECK: (var_decl {{.*}} "computedVarReadModify" interface type="Int" access=internal dynamic readImpl=read_coroutine writeImpl=modify_coroutine readWriteImpl=modify_coroutine + // CHECK: (accessor_decl {{.*}} access=internal dynamic _read for="computedVarReadModify" + // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify for="computedVarReadModify" + // CHECK: (accessor_decl {{.*}} access=internal get for="computedVarReadModify" + // CHECK: (accessor_decl {{.*}} access=internal set for="computedVarReadModify" dynamic var computedVarReadModify : Int { _read { } @@ -214,10 +214,10 @@ class Klass { } // CHECK: (subscript_decl {{.*}} "subscript(_:)" {{.*}} access=internal dynamic readImpl=addressor writeImpl=mutable_addressor readWriteImpl=mutable_addressor - // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeAddress_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeMutableAddress_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal get_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal set_for=subscript(_:) + // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeAddress for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeMutableAddress for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal get for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal set for="subscript(_:)" dynamic subscript(_ index: Int) -> Int { unsafeAddress { fatalError() @@ -228,10 +228,10 @@ class Klass { } // CHECK: (subscript_decl {{.*}} "subscript(_:)" {{.*}} access=internal dynamic readImpl=getter writeImpl=mutable_addressor readWriteImpl=mutable_addressor - // CHECK: (accessor_decl {{.*}} access=internal dynamic get_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeMutableAddress_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal set_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal _modify_for=subscript(_:) + // CHECK: (accessor_decl {{.*}} access=internal dynamic get for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeMutableAddress for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal set for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal _modify for="subscript(_:)" dynamic subscript(_ index: Float) -> Int { get { return 1 @@ -242,11 +242,11 @@ class Klass { } // CHECK: (subscript_decl {{.*}} "subscript(_:)" {{.*}} access=internal dynamic readImpl=read_coroutine writeImpl=mutable_addressor readWriteImpl=mutable_addressor - // CHECK: (accessor_decl {{.*}} access=internal dynamic _read_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeMutableAddress_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal get_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal set_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal _modify_for=subscript(_:) + // CHECK: (accessor_decl {{.*}} access=internal dynamic _read for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeMutableAddress for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal get for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal set for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal _modify for="subscript(_:)" dynamic subscript(_ index: Double) -> Int { _read { } @@ -256,10 +256,10 @@ class Klass { } // CHECK: (subscript_decl {{.*}} "subscript(_:)" {{.*}} access=internal dynamic readImpl=addressor writeImpl=setter readWriteImpl=materialize_to_temporary - // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeAddress_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal dynamic set_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal get_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal _modify_for=subscript(_:) + // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeAddress for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal dynamic set for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal get for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal _modify for="subscript(_:)" dynamic subscript(_ index: Int8) -> Int { unsafeAddress { fatalError() @@ -269,10 +269,10 @@ class Klass { } // CHECK: (subscript_decl {{.*}} "subscript(_:)" {{.*}} access=internal dynamic readImpl=addressor writeImpl=modify_coroutine readWriteImpl=modify_coroutine - // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeAddress_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal get_for=subscript(_:) - // CHECK: (accessor_decl {{.*}} access=internal set_for=subscript(_:) + // CHECK: (accessor_decl {{.*}} access=internal dynamic unsafeAddress for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal dynamic _modify for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal get for="subscript(_:)" + // CHECK: (accessor_decl {{.*}} access=internal set for="subscript(_:)" dynamic subscript(_ index: Int16) -> Int { unsafeAddress { fatalError() @@ -285,12 +285,12 @@ class Klass { class SubKlass : Klass { // CHECK: (class_decl {{.*}} "SubKlass" - // CHECK: (func_decl {{.*}} "aMethod(arg:)" interface type='(SubKlass) -> (Int) -> Int' access=internal {{.*}} dynamic + // CHECK: (func_decl {{.*}} "aMethod(arg:)" interface type="(SubKlass) -> (Int) -> Int" access=internal {{.*}} dynamic override dynamic func aMethod(arg: Int) -> Int { return 23 } - // CHECK: (func_decl {{.*}} "anotherMethod()" interface type='(SubKlass) -> () -> Int' access=internal {{.*}} dynamic + // CHECK: (func_decl {{.*}} "anotherMethod()" interface type="(SubKlass) -> () -> Int" access=internal {{.*}} dynamic override dynamic func anotherMethod() -> Int { return 23 } diff --git a/test/attr/attr_objc.swift b/test/attr/attr_objc.swift index debee0fa8da..22dba743c93 100644 --- a/test/attr/attr_objc.swift +++ b/test/attr/attr_objc.swift @@ -2319,11 +2319,13 @@ class ClassThrows1 { @objc // access-note-move{{ImplicitClassThrows1}} class ImplicitClassThrows1 { // CHECK: @objc func methodReturnsVoid() throws - // CHECK-DUMP: func_decl{{.*}}"methodReturnsVoid()"{{.*}}foreign_error=ZeroResult,unowned,param=0,paramtype=Optional>>,resulttype=ObjCBool + // CHECK-DUMP-LABEL: func_decl{{.*}}"methodReturnsVoid()" + // CHECK-DUMP: (foreign_error_convention kind=ZeroResult unowned param=0 paramtype="Optional>>" resulttype="ObjCBool") func methodReturnsVoid() throws { } // CHECK: @objc func methodReturnsObjCClass() throws -> Class_ObjC1 - // CHECK-DUMP: func_decl{{.*}}"methodReturnsObjCClass()" {{.*}}foreign_error=NilResult,unowned,param=0,paramtype=Optional>> + // CHECK-DUMP-LABEL: func_decl{{.*}}"methodReturnsObjCClass()" + // CHECK-DUMP: (foreign_error_convention kind=NilResult unowned param=0 paramtype="Optional>>") func methodReturnsObjCClass() throws -> Class_ObjC1 { return Class_ObjC1() } @@ -2338,11 +2340,13 @@ class ImplicitClassThrows1 { func methodReturnsOptionalObjCClass() throws -> Class_ObjC1? { return nil } // CHECK: @objc func methodWithTrailingClosures(_ s: String, fn1: @escaping ((Int) -> Int), fn2: @escaping (Int) -> Int, fn3: @escaping (Int) -> Int) - // CHECK-DUMP: func_decl{{.*}}"methodWithTrailingClosures(_:fn1:fn2:fn3:)"{{.*}}foreign_error=ZeroResult,unowned,param=1,paramtype=Optional>>,resulttype=ObjCBool + // CHECK-DUMP-LABEL: func_decl{{.*}}"methodWithTrailingClosures(_:fn1:fn2:fn3:)" + // CHECK-DUMP: (foreign_error_convention kind=ZeroResult unowned param=1 paramtype="Optional>>" resulttype="ObjCBool") func methodWithTrailingClosures(_ s: String, fn1: (@escaping (Int) -> Int), fn2: @escaping (Int) -> Int, fn3: @escaping (Int) -> Int) throws { } // CHECK: @objc init(degrees: Double) throws - // CHECK-DUMP: constructor_decl{{.*}}"init(degrees:)"{{.*}}foreign_error=NilResult,unowned,param=1,paramtype=Optional>> + // CHECK-DUMP-LABEL: constructor_decl{{.*}}"init(degrees:)" + // CHECK-DUMP: (foreign_error_convention kind=NilResult unowned param=1 paramtype="Optional>>") init(degrees: Double) throws { } // CHECK: {{^}} func methodReturnsBridgedValueType() throws -> NSRange @@ -2369,7 +2373,8 @@ class ImplicitClassThrows1 { @objc // access-note-move{{SubclassImplicitClassThrows1}} class SubclassImplicitClassThrows1 : ImplicitClassThrows1 { // CHECK: @objc override func methodWithTrailingClosures(_ s: String, fn1: @escaping ((Int) -> Int), fn2: @escaping ((Int) -> Int), fn3: @escaping ((Int) -> Int)) - // CHECK-DUMP: func_decl{{.*}}"methodWithTrailingClosures(_:fn1:fn2:fn3:)"{{.*}}foreign_error=ZeroResult,unowned,param=1,paramtype=Optional>>,resulttype=ObjCBool + // CHECK-DUMP-LABEL: func_decl{{.*}}"methodWithTrailingClosures(_:fn1:fn2:fn3:)" + // CHECK-DUMP: (foreign_error_convention kind=ZeroResult unowned param=1 paramtype="Optional>>" resulttype="ObjCBool") override func methodWithTrailingClosures(_ s: String, fn1: (@escaping (Int) -> Int), fn2: (@escaping (Int) -> Int), fn3: (@escaping (Int) -> Int)) throws { } } @@ -2418,20 +2423,24 @@ class ThrowsObjCName { @objc(method7) // bad-access-note-move{{ThrowsObjCName.method7(x:)}} expected-error{{'@objc' method name provides names for 0 arguments, but method has 2 parameters (including the error parameter)}} func method7(x: Int) throws { } - // CHECK-DUMP: func_decl{{.*}}"method8(_:fn1:fn2:)"{{.*}}foreign_error=ZeroResult,unowned,param=2,paramtype=Optional>>,resulttype=ObjCBool + // CHECK-DUMP-LABEL: func_decl{{.*}}"method8(_:fn1:fn2:)" + // CHECK-DUMP: (foreign_error_convention kind=ZeroResult unowned param=2 paramtype="Optional>>" resulttype="ObjCBool") @objc(method8:fn1:error:fn2:) // access-note-move{{ThrowsObjCName.method8(_:fn1:fn2:)}} func method8(_ s: String, fn1: (@escaping (Int) -> Int), fn2: @escaping (Int) -> Int) throws { } - // CHECK-DUMP: func_decl{{.*}}"method9(_:fn1:fn2:)"{{.*}}foreign_error=ZeroResult,unowned,param=0,paramtype=Optional>>,resulttype=ObjCBool + // CHECK-DUMP-LABEL: func_decl{{.*}}"method9(_:fn1:fn2:)" + // CHECK-DUMP: (foreign_error_convention kind=ZeroResult unowned param=0 paramtype="Optional>>" resulttype="ObjCBool") @objc(method9AndReturnError:s:fn1:fn2:) // access-note-move{{ThrowsObjCName.method9(_:fn1:fn2:)}} func method9(_ s: String, fn1: (@escaping (Int) -> Int), fn2: @escaping (Int) -> Int) throws { } } class SubclassThrowsObjCName : ThrowsObjCName { - // CHECK-DUMP: func_decl{{.*}}"method8(_:fn1:fn2:)"{{.*}}foreign_error=ZeroResult,unowned,param=2,paramtype=Optional>>,resulttype=ObjCBool + // CHECK-DUMP-LABEL: func_decl{{.*}}"method8(_:fn1:fn2:)" + // CHECK-DUMP: (foreign_error_convention kind=ZeroResult unowned param=2 paramtype="Optional>>" resulttype="ObjCBool") override func method8(_ s: String, fn1: (@escaping (Int) -> Int), fn2: @escaping (Int) -> Int) throws { } - // CHECK-DUMP: func_decl{{.*}}"method9(_:fn1:fn2:)"{{.*}}foreign_error=ZeroResult,unowned,param=0,paramtype=Optional>>,resulttype=ObjCBool + // CHECK-DUMP-LABEL: func_decl{{.*}}"method9(_:fn1:fn2:)" + // CHECK-DUMP: (foreign_error_convention kind=ZeroResult unowned param=0 paramtype="Optional>>" resulttype="ObjCBool") override func method9(_ s: String, fn1: (@escaping (Int) -> Int), fn2: @escaping (Int) -> Int) throws { } } diff --git a/test/attr/attr_objc_async.swift b/test/attr/attr_objc_async.swift index 42fb7647012..42fbd8b11ec 100644 --- a/test/attr/attr_objc_async.swift +++ b/test/attr/attr_objc_async.swift @@ -8,13 +8,15 @@ import Foundation // CHECK: class MyClass class MyClass { - // CHECK: @objc func doBigJob() async -> Int - // CHECK-DUMP: func_decl{{.*}}doBigJob{{.*}}foreign_async=@convention(block) (Int) -> (),completion_handler_param=0 - @objc func doBigJob() async -> Int { return 0 } + // CHECK: @objc func doBigJobClass() async -> Int + // CHECK-DUMP-LABEL: func_decl{{.*}}doBigJobClass{{.*}} + // CHECK-DUMP: (foreign_async_convention completion_handler_type="@convention(block) (Int) -> ()" completion_handler_param=0) + @objc func doBigJobClass() async -> Int { return 0 } - // CHECK: @objc func doBigJobOrFail(_: Int) async throws -> (AnyObject, Int) - // CHECK-DUMP: func_decl{{.*}}doBigJobOrFail{{.*}}foreign_async=@convention(block) (Optional, Int, Optional) -> (),completion_handler_param=1,error_param=2 - @objc func doBigJobOrFail(_: Int) async throws -> (AnyObject, Int) { return (self, 0) } + // CHECK: @objc func doBigJobOrFailClass(_: Int) async throws -> (AnyObject, Int) + // CHECK-DUMP-LABEL: func_decl{{.*}}doBigJobOrFailClass{{.*}} + // CHECK-DUMP: (foreign_async_convention completion_handler_type="@convention(block) (Optional, Int, Optional) -> ()" completion_handler_param=1 error_param=2) + @objc func doBigJobOrFailClass(_: Int) async throws -> (AnyObject, Int) { return (self, 0) } @objc func takeAnAsync(_ fn: () async -> Int) { } // expected-error{{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}} // expected-note@-1{{'async' function types cannot be represented in Objective-C}} @@ -27,14 +29,16 @@ class MyClass { // CHECK: actor MyActor actor MyActor { - // CHECK: @objc func doBigJob() async -> Int - // CHECK-DUMP: func_decl{{.*}}doBigJob{{.*}}foreign_async=@convention(block) (Int) -> (),completion_handler_param=0 - @objc func doBigJob() async -> Int { return 0 } + // CHECK: @objc func doBigJobActor() async -> Int + // CHECK-DUMP-LABEL: func_decl{{.*}}doBigJobActor{{.*}} + // CHECK-DUMP: (foreign_async_convention completion_handler_type="@convention(block) (Int) -> ()" completion_handler_param=0) + @objc func doBigJobActor() async -> Int { return 0 } - // CHECK: @objc func doBigJobOrFail(_: Int) async throws -> (AnyObject, Int) - // CHECK-DUMP: func_decl{{.*}}doBigJobOrFail{{.*}}foreign_async=@convention(block) (Optional, Int, Optional) -> (),completion_handler_param=1,error_param=2 - @objc func doBigJobOrFail(_: Int) async throws -> (AnyObject, Int) { return (self, 0) } - // expected-warning@-1{{non-sendable type '(AnyObject, Int)' returned by actor-isolated '@objc' instance method 'doBigJobOrFail' cannot cross actor boundary}} + // CHECK: @objc func doBigJobOrFailActor(_: Int) async throws -> (AnyObject, Int) + // CHECK-DUMP-LABEL: func_decl{{.*}}doBigJobOrFailActor{{.*}} + // CHECK-DUMP: (foreign_async_convention completion_handler_type="@convention(block) (Optional, Int, Optional) -> ()" completion_handler_param=1 error_param=2) + @objc func doBigJobOrFailActor(_: Int) async throws -> (AnyObject, Int) { return (self, 0) } + // expected-warning@-1{{non-sendable type '(AnyObject, Int)' returned by actor-isolated '@objc' instance method 'doBigJobOrFailActor' cannot cross actor boundary}} // Actor-isolated entities cannot be exposed to Objective-C. @objc func synchronousBad() { } // expected-error{{actor-isolated instance method 'synchronousBad()' cannot be @objc}} diff --git a/test/decl/protocol/associated_type_overrides.swift b/test/decl/protocol/associated_type_overrides.swift index 554814b02fe..64dce163093 100644 --- a/test/decl/protocol/associated_type_overrides.swift +++ b/test/decl/protocol/associated_type_overrides.swift @@ -5,7 +5,7 @@ protocol P1 { } // CHECK-LABEL: (protocol{{.*}}"P2" -// CHECK-NEXT: (associated_type_decl{{.*}}"A" {{.*}} overridden=P1)) +// CHECK-NEXT: (associated_type_decl{{.*}}"A" {{.*}} overridden="P1")) protocol P2 : P1 { associatedtype A } @@ -15,13 +15,13 @@ protocol P3 { } // CHECK-LABEL: (protocol{{.*}}"P4" -// CHECK-NEXT: (associated_type_decl{{.*}}"A" {{.*}} overridden=P2, P3)) +// CHECK-NEXT: (associated_type_decl{{.*}}"A" {{.*}} overridden="P2, P3")) protocol P4 : P2, P3 { associatedtype A } // CHECK-LABEL: (protocol{{.*}}"P5" -// CHECK-NEXT: (associated_type_decl{{.*}}"A" {{.*}} overridden=P4)) +// CHECK-NEXT: (associated_type_decl{{.*}}"A" {{.*}} overridden="P4")) protocol P5 : P4, P2 { associatedtype A } diff --git a/test/decl/protocol/override.swift b/test/decl/protocol/override.swift index 617b1bbe325..aa5f00d9f11 100644 --- a/test/decl/protocol/override.swift +++ b/test/decl/protocol/override.swift @@ -17,7 +17,7 @@ protocol P0 { // CHECK: protocol{{.*}}"P1" protocol P1: P0 { // CHECK: associated_type_decl - // CHECK-SAME: overridden=P0 + // CHECK-SAME: overridden="P0" associatedtype A // CHECK: func_decl{{.*}}foo(){{.*}}Self : P1{{.*}}override={{.*}}P0.foo @@ -25,7 +25,7 @@ protocol P1: P0 { // CHECK: var_decl // CHECK-SAME: "prop" - // CHECK-SAME: override=override.(file).P0.prop + // CHECK-SAME: override="override.(file).P0.prop var prop: A { get } } @@ -42,7 +42,7 @@ protocol P2 { protocol P3: P1, P2 { // CHECK: associated_type_decl // CHECK-SAME: "A" - // CHECK-SAME: override=override.(file).P1.A + // CHECK-SAME: override="override.(file).P1.A // CHECK-SAME: override.(file).P2.A associatedtype A @@ -51,7 +51,7 @@ protocol P3: P1, P2 { // CHECK: var_decl // CHECK-SAME: "prop" - // CHECK-SAME: override=override.(file).P2.prop + // CHECK-SAME: override="override.(file).P2.prop // CHECK-SAME: override.(file).P1.prop var prop: A { get } } @@ -79,7 +79,7 @@ protocol P5: P0 where Self.A == Int { // CHECK: var_decl // CHECK-SAME: "prop" - // CHECK-SAME: override=override.(file).P0.prop + // CHECK-SAME: override="override.(file).P0.prop var prop: Int { get } } @@ -91,7 +91,7 @@ protocol P6: P0 { // CHECK: var_decl // CHECK-SAME: "prop" - // CHECK-SAME: override=override.(file).P0.prop + // CHECK-SAME: override="override.(file).P0.prop override var prop: A { get } } diff --git a/test/decl/protocol/req/existentials_covariant_erasure.swift b/test/decl/protocol/req/existentials_covariant_erasure.swift index 4ddbd05ad7b..9a276c8db41 100644 --- a/test/decl/protocol/req/existentials_covariant_erasure.swift +++ b/test/decl/protocol/req/existentials_covariant_erasure.swift @@ -1,6 +1,6 @@ // RUN: %target-swift-frontend -typecheck -dump-ast %s | %FileCheck %s -// Test that covariant 'Self' references get erased to the existential base type +// Test that covariant "Self" references get erased to the existential base type // when operating on existential values. class C {} @@ -34,11 +34,11 @@ do { let x5 = pc.lotsOfSelfFunc let x6 = pc.lotsOfSelfProp - // CHECK: (pattern_named type='((any P) -> Void, ((any P)?) -> Void, ([any P]) -> Void, ([Array?]) -> Void) -> [String : () -> any P]' 'x1') - // CHECK: (pattern_named type='((any P) -> Void, ((any P)?) -> Void, ([any P]) -> Void, ([Array?]) -> Void) -> [String : () -> any P]' 'x2') - // CHECK: (pattern_named type='((any P & Q) -> Void, ((any P & Q)?) -> Void, ([any P & Q]) -> Void, ([Array?]) -> Void) -> [String : () -> any P & Q]' 'x3') - // CHECK: (pattern_named type='((any P & Q) -> Void, ((any P & Q)?) -> Void, ([any P & Q]) -> Void, ([Array?]) -> Void) -> [String : () -> any P & Q]' 'x4') - // CHECK: (pattern_named type='((any C & P) -> Void, ((any C & P)?) -> Void, ([any C & P]) -> Void, ([Array?]) -> Void) -> [String : () -> any C & P]' 'x5') - // CHECK: (pattern_named type='((any C & P) -> Void, ((any C & P)?) -> Void, ([any C & P]) -> Void, ([Array?]) -> Void) -> [String : () -> any C & P]' 'x6') + // CHECK: (pattern_named type="((any P) -> Void, ((any P)?) -> Void, ([any P]) -> Void, ([Array?]) -> Void) -> [String : () -> any P]" "x1") + // CHECK: (pattern_named type="((any P) -> Void, ((any P)?) -> Void, ([any P]) -> Void, ([Array?]) -> Void) -> [String : () -> any P]" "x2") + // CHECK: (pattern_named type="((any P & Q) -> Void, ((any P & Q)?) -> Void, ([any P & Q]) -> Void, ([Array?]) -> Void) -> [String : () -> any P & Q]" "x3") + // CHECK: (pattern_named type="((any P & Q) -> Void, ((any P & Q)?) -> Void, ([any P & Q]) -> Void, ([Array?]) -> Void) -> [String : () -> any P & Q]" "x4") + // CHECK: (pattern_named type="((any C & P) -> Void, ((any C & P)?) -> Void, ([any C & P]) -> Void, ([Array?]) -> Void) -> [String : () -> any C & P]" "x5") + // CHECK: (pattern_named type="((any C & P) -> Void, ((any C & P)?) -> Void, ([any C & P]) -> Void, ([Array?]) -> Void) -> [String : () -> any C & P]" "x6") } } diff --git a/test/decl/var/property_wrappers_synthesis.swift b/test/decl/var/property_wrappers_synthesis.swift index e46d63d9c12..51f4b127d13 100644 --- a/test/decl/var/property_wrappers_synthesis.swift +++ b/test/decl/var/property_wrappers_synthesis.swift @@ -13,21 +13,21 @@ protocol DefaultInit { struct UseWrapper { // CHECK: var_decl{{.*}}"wrapped" - // CHECK: accessor_decl{{.*}}get_for=wrapped + // CHECK: accessor_decl{{.*}}get for="wrapped" // CHECK: member_ref_expr{{.*}}UseWrapper._wrapped - // CHECK: accessor_decl{{.*}}set_for=wrapped + // CHECK: accessor_decl{{.*}}set for="wrapped" // CHECK: member_ref_expr{{.*}}UseWrapper._wrapped - // CHECK: accessor_decl{{.*}}_modify_for=wrapped + // CHECK: accessor_decl{{.*}}_modify for="wrapped" // CHECK: yield_stmt // CHECK: member_ref_expr{{.*}}Wrapper.wrappedValue @Wrapper var wrapped = T() // CHECK: pattern_binding_decl implicit - // CHECK-NEXT: pattern_typed implicit type='Wrapper' - // CHECK-NEXT: pattern_named implicit type='Wrapper' '_wrapped' + // CHECK-NEXT: pattern_typed implicit type="Wrapper" + // CHECK-NEXT: pattern_named implicit type="Wrapper" "_wrapped" // CHECK: constructor_ref_call_expr // CHECK-NEXT: declref_expr{{.*}}Wrapper.init(wrappedValue:) init() { } @@ -36,7 +36,7 @@ struct UseWrapper { struct UseWillSetDidSet { // CHECK: var_decl{{.*}}"z" - // CHECK: accessor_decl{{.*}}set_for=z + // CHECK: accessor_decl{{.*}}set for="z" // CHECK: member_ref_expr{{.*}}UseWillSetDidSet._z @Wrapper var z: Int { @@ -81,10 +81,10 @@ struct Observable { class MyObservedType { @Observable var observedProperty = 17 - // CHECK: accessor_decl{{.*}}get_for=observedProperty - // CHECK: subscript_expr implicit type='@lvalue Int' decl={{.*}}.Observable.subscript(_enclosingInstance:wrapped:storage:) + // CHECK: accessor_decl{{.*}}get for="observedProperty" + // CHECK: subscript_expr implicit type="@lvalue Int" decl="{{.*}}.Observable.subscript(_enclosingInstance:wrapped:storage:)@ - // CHECK: accessor_decl{{.*}}set_for=observedProperty - // CHECK: subscript_expr implicit type='@lvalue Int' decl={{.*}}.Observable.subscript(_enclosingInstance:wrapped:storage:) + // CHECK: accessor_decl{{.*}}set for="observedProperty" + // CHECK: subscript_expr implicit type="@lvalue Int" decl="{{.*}}.Observable.subscript(_enclosingInstance:wrapped:storage:)@ } diff --git a/test/expr/capture/dynamic_self.swift b/test/expr/capture/dynamic_self.swift index aef2938889c..146211babdb 100644 --- a/test/expr/capture/dynamic_self.swift +++ b/test/expr/capture/dynamic_self.swift @@ -1,10 +1,10 @@ // RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s -// CHECK: func_decl{{.*}}"clone()" interface type='(Android) -> () -> Self' +// CHECK: func_decl{{.*}}"clone()" interface type="(Android) -> () -> Self" class Android { func clone() -> Self { - // CHECK: closure_expr type='() -> Self' {{.*}} discriminator=0 captures=( self) + // CHECK: closure_expr type="() -> Self" {{.*}} discriminator=0 captures=( self) let fn = { return self } return fn() } diff --git a/test/expr/capture/generic_params.swift b/test/expr/capture/generic_params.swift index 5d54f48f116..02334bcc349 100644 --- a/test/expr/capture/generic_params.swift +++ b/test/expr/capture/generic_params.swift @@ -2,33 +2,33 @@ func doSomething(_ t: T) {} -// CHECK: func_decl{{.*}}"outerGeneric(t:x:)" interface type=' (t: T, x: AnyObject) -> ()' +// CHECK: func_decl{{.*}}"outerGeneric(t:x:)" "" interface type=" (t: T, x: AnyObject) -> ()" func outerGeneric(t: T, x: AnyObject) { // Simple case -- closure captures outer generic parameter - // CHECK: closure_expr type='() -> ()' {{.*}} discriminator=0 captures=( t) escaping single-expression + // CHECK: closure_expr type="() -> ()" {{.*}} discriminator=0 captures=( t) escaping single_expression _ = { doSomething(t) } // Special case -- closure does not capture outer generic parameters - // CHECK: closure_expr type='() -> ()' {{.*}} discriminator=1 captures=(x) escaping single-expression + // CHECK: closure_expr type="() -> ()" {{.*}} discriminator=1 captures=(x) escaping single_expression _ = { doSomething(x) } // Special case -- closure captures outer generic parameter, but it does not // appear as the type of any expression - // CHECK: closure_expr type='() -> ()' {{.*}} discriminator=2 captures=( x) + // CHECK: closure_expr type="() -> ()" {{.*}} discriminator=2 captures=( x) _ = { if x is T {} } // Nested generic functions always capture outer generic parameters, even if // they're not mentioned in the function body - // CHECK: func_decl{{.*}}"innerGeneric(u:)" interface type=' (u: U) -> ()' {{.*}} captures=( ) + // CHECK: func_decl{{.*}}"innerGeneric(u:)" "" interface type=" (u: U) -> ()" {{.*}} captures=( ) func innerGeneric(u: U) {} // Make sure we look through typealiases typealias TT = (a: T, b: T) - // CHECK: func_decl{{.*}}"localFunction(tt:)" interface type=' (tt: TT) -> ()' {{.*}} captures=( ) + // CHECK: func_decl{{.*}}"localFunction(tt:)" interface type=" (tt: TT) -> ()" {{.*}} captures=( ) func localFunction(tt: TT) {} - // CHECK: closure_expr type='(TT) -> ()' {{.*}} captures=( ) + // CHECK: closure_expr type="(TT) -> ()" {{.*}} captures=( ) let _: (TT) -> () = { _ in } } diff --git a/test/expr/capture/local_lazy.swift b/test/expr/capture/local_lazy.swift index 8fe4171f64b..ae3a2ff54e1 100644 --- a/test/expr/capture/local_lazy.swift +++ b/test/expr/capture/local_lazy.swift @@ -5,7 +5,7 @@ struct S { func foo() -> Int { // Make sure the decl context for the autoclosure passed to ?? is deep // enough that it can 'see' the capture of $0 from the outer closure. - // CHECK-LABEL: (lazy_initializer_expr + // CHECK-LABEL: (original_init=lazy_initializer_expr // CHECK: (closure_expr // CHECK: location={{.*}}local_lazy.swift:[[@LINE+3]] // CHECK: (autoclosure_expr implicit @@ -17,7 +17,7 @@ struct S { extension S { func bar() -> Int { - // CHECK-LABEL: (lazy_initializer_expr + // CHECK-LABEL: (original_init=lazy_initializer_expr // CHECK: (closure_expr // CHECK: location={{.*}}local_lazy.swift:[[@LINE+3]] // CHECK: (autoclosure_expr implicit diff --git a/test/expr/capture/nested.swift b/test/expr/capture/nested.swift index 144b9ac209e..9d5bedf31d9 100644 --- a/test/expr/capture/nested.swift +++ b/test/expr/capture/nested.swift @@ -2,9 +2,9 @@ // CHECK: func_decl{{.*}}"foo2(_:)" func foo2(_ x: Int) -> (Int) -> (Int) -> Int { - // CHECK: closure_expr type='(Int) -> (Int) -> Int' {{.*}} discriminator=0 captures=(x) + // CHECK: closure_expr type="(Int) -> (Int) -> Int" {{.*}} discriminator=0 captures=(x) return {(bar: Int) -> (Int) -> Int in - // CHECK: closure_expr type='(Int) -> Int' {{.*}} discriminator=0 captures=(x, bar) + // CHECK: closure_expr type="(Int) -> Int" {{.*}} discriminator=0 captures=(x, bar) return {(bas: Int) -> Int in return x + bar + bas } diff --git a/test/expr/capture/top-level-guard.swift b/test/expr/capture/top-level-guard.swift index e8080e3a24f..c0f4ce8445a 100644 --- a/test/expr/capture/top-level-guard.swift +++ b/test/expr/capture/top-level-guard.swift @@ -15,12 +15,12 @@ guard let x = Optional(0) else { fatalError() } // CHECK: (top_level_code_decl _ = 0 // intervening code -// CHECK-LABEL: (func_decl{{.*}}"function()" interface type='() -> ()' access=internal captures=(x) +// CHECK-LABEL: (func_decl{{.*}}"function()" interface type="() -> ()" access=internal captures=(x) func function() { _ = x } -// CHECK-LABEL: (closure_expr +// CHECK-LABEL: (processed_init=closure_expr // CHECK: location={{.*}}top-level-guard.swift:[[@LINE+3]] // CHECK: captures=(x) // CHECK: (var_decl{{.*}}"closure" @@ -28,7 +28,7 @@ let closure: () -> Void = { _ = x } -// CHECK-LABEL: (capture_list +// CHECK-LABEL: (processed_init=capture_list // CHECK: location={{.*}}top-level-guard.swift:[[@LINE+5]] // CHECK: (closure_expr // CHECK: location={{.*}}top-level-guard.swift:[[@LINE+3]] @@ -39,7 +39,7 @@ let closureCapture: () -> Void = { [x] in } // CHECK-LABEL: (defer_stmt -// CHECK-NEXT: (func_decl{{.*}}implicit "$defer()" interface type='() -> ()' access=fileprivate captures=(x) +// CHECK-NEXT: (func_decl{{.*}}implicit "$defer()" interface type="() -> ()" access=fileprivate captures=(x) defer { _ = x } diff --git a/test/expr/cast/array_downcast_Foundation.swift b/test/expr/cast/array_downcast_Foundation.swift index f3b287bb499..08bcde4d1c0 100644 --- a/test/expr/cast/array_downcast_Foundation.swift +++ b/test/expr/cast/array_downcast_Foundation.swift @@ -35,26 +35,26 @@ func testDowncastNSArrayToArray(nsarray: NSArray) { // CHECK-LABEL: testDowncastOptionalObject func testDowncastOptionalObject(obj: AnyObject?!) -> [String]? { - // CHECK: (optional_evaluation_expr implicit type='[String]?' - // CHECK-NEXT: (inject_into_optional implicit type='[String]?' - // CHECK: (forced_checked_cast_expr type='[String]'{{.*value_cast}} - // CHECK: (bind_optional_expr implicit type='AnyObject' - // CHECK-NEXT: (force_value_expr implicit type='AnyObject?' - // CHECK-NEXT: (declref_expr type='AnyObject??' + // CHECK: (optional_evaluation_expr implicit type="[String]?" + // CHECK-NEXT: (inject_into_optional implicit type="[String]?" + // CHECK: (forced_checked_cast_expr type="[String]"{{.*value_cast}} + // CHECK: (bind_optional_expr implicit type="AnyObject" + // CHECK-NEXT: (force_value_expr implicit type="AnyObject?" + // CHECK-NEXT: (declref_expr type="AnyObject??" return obj as! [String]? } // CHECK-LABEL: testDowncastOptionalObjectConditional func testDowncastOptionalObjectConditional(obj: AnyObject?!) -> [String]?? { - // CHECK: (optional_evaluation_expr implicit type='[String]??' - // CHECK-NEXT: (inject_into_optional implicit type='[String]??' - // CHECK-NEXT: (optional_evaluation_expr implicit type='[String]?' - // CHECK-NEXT: (inject_into_optional implicit type='[String]?' - // CHECK-NEXT: (bind_optional_expr implicit type='[String]' - // CHECK-NEXT: (conditional_checked_cast_expr type='[String]?' {{.*value_cast}} writtenType='[String]?' - // CHECK-NEXT: (bind_optional_expr implicit type='AnyObject' - // CHECK-NEXT: (bind_optional_expr implicit type='AnyObject?' - // CHECK-NEXT: (declref_expr type='AnyObject??' + // CHECK: (optional_evaluation_expr implicit type="[String]??" + // CHECK-NEXT: (inject_into_optional implicit type="[String]??" + // CHECK-NEXT: (optional_evaluation_expr implicit type="[String]?" + // CHECK-NEXT: (inject_into_optional implicit type="[String]?" + // CHECK-NEXT: (bind_optional_expr implicit type="[String]" + // CHECK-NEXT: (conditional_checked_cast_expr type="[String]?" {{.*value_cast}} written_type="[String]?" + // CHECK-NEXT: (bind_optional_expr implicit type="AnyObject" + // CHECK-NEXT: (bind_optional_expr implicit type="AnyObject?" + // CHECK-NEXT: (declref_expr type="AnyObject??" return obj as? [String]? } diff --git a/test/expr/delayed-ident/optional_overload.swift b/test/expr/delayed-ident/optional_overload.swift index 11c9185022f..fc264814faf 100644 --- a/test/expr/delayed-ident/optional_overload.swift +++ b/test/expr/delayed-ident/optional_overload.swift @@ -40,11 +40,11 @@ let _: S1? = .init(S1()) let _: S1? = .init(overloaded: ()) // If members exist on Optional and Wrapped, always choose the one on optional // CHECK: declref_expr {{.*}} location={{.*}}optional_overload.swift:40 -// CHECK-SAME: decl=optional_overload.(file).Optional extension.init(overloaded:) +// CHECK-SAME: decl="optional_overload.(file).Optional extension.init(overloaded:)@ let _: S1? = .member_overload // Should choose the overload from Optional even if the Wrapped overload would otherwise have a better score // CHECK: member_ref_expr {{.*}} location={{.*}}optional_overload.swift:44 -// CHECK-SAME: decl=optional_overload.(file).Optional extension.member_overload +// CHECK-SAME: decl="optional_overload.(file).Optional extension.member_overload@ let _: S1? = .init(failable: ()) let _: S1? = .member3() let _: S1? = .member4 diff --git a/test/expr/primary/literal/collection_upcast_opt.swift b/test/expr/primary/literal/collection_upcast_opt.swift index 8130a6db5f4..b786e88f4fd 100644 --- a/test/expr/primary/literal/collection_upcast_opt.swift +++ b/test/expr/primary/literal/collection_upcast_opt.swift @@ -14,10 +14,10 @@ struct TakesArray { // CHECK-LABEL: func_decl{{.*}}"arrayUpcast(_:_:)" // CHECK: assign_expr // CHECK-NOT: collection_upcast_expr -// CHECK: array_expr type='[(X) -> Void]' -// CHECK: function_conversion_expr implicit type='(X) -> Void' +// CHECK: array_expr type="[(X) -> Void]" +// CHECK: function_conversion_expr implicit type="(X) -> Void" // CHECK-NEXT: {{declref_expr.*x1}} -// CHECK-NEXT: function_conversion_expr implicit type='(X) -> Void' +// CHECK-NEXT: function_conversion_expr implicit type="(X) -> Void" // CHECK-NEXT: {{declref_expr.*x2}} func arrayUpcast(_ x1: @escaping (P) -> Void, _ x2: @escaping (P) -> Void) { _ = TakesArray([x1, x2]) @@ -30,9 +30,9 @@ struct TakesDictionary { // CHECK-LABEL: func_decl{{.*}}"dictionaryUpcast(_:_:)" // CHECK: assign_expr // CHECK-NOT: collection_upcast_expr -// CHECK: paren_expr type='([Int : (X) -> Void])' +// CHECK: paren_expr type="([Int : (X) -> Void])" // CHECK-NOT: collection_upcast_expr -// CHECK: (dictionary_expr type='[Int : (X) -> Void]' +// CHECK: (dictionary_expr type="[Int : (X) -> Void]" func dictionaryUpcast(_ x1: @escaping (P) -> Void, _ x2: @escaping (P) -> Void) { _ = TakesDictionary(([1: x1, 2: x2])) }