mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[AST] Introduce the ASTPrinter class, and have its callbacks invoked during AST printing.
This provides useful extension points during AST printing. Swift SVN r11338
This commit is contained in:
74
include/swift/AST/ASTPrinter.h
Normal file
74
include/swift/AST/ASTPrinter.h
Normal file
@@ -0,0 +1,74 @@
|
||||
//===--- ASTPrinter.h - Class for printing the AST --------------*- C++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See http://swift.org/LICENSE.txt for license information
|
||||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SWIFT_AST_ASTPRINTER_H
|
||||
#define SWIFT_AST_ASTPRINTER_H
|
||||
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
namespace swift {
|
||||
class Decl;
|
||||
class Module;
|
||||
class TypeDecl;
|
||||
|
||||
/// An abstract class used to print an AST.
|
||||
class ASTPrinter {
|
||||
public:
|
||||
virtual ~ASTPrinter() {}
|
||||
|
||||
virtual void printText(StringRef Text) = 0;
|
||||
|
||||
/// Called before printing of a declaration.
|
||||
virtual void printDeclPre(const Decl *D) {}
|
||||
/// Called before printing at the point which would be considered the location
|
||||
/// of the declaration (normally the name of the declaration).
|
||||
virtual void printDeclLoc(const Decl *D) {}
|
||||
/// Called after finishing printing of a declaration.
|
||||
virtual void printDeclPost(const Decl *D) {}
|
||||
|
||||
/// Called when printing the referenced name of a type declaration.
|
||||
virtual void printTypeRef(const TypeDecl *TD, StringRef Text) {
|
||||
printText(Text);
|
||||
}
|
||||
/// Called when printing the referenced name of a module.
|
||||
virtual void printModuleRef(const Module *Mod, StringRef Text) {
|
||||
printText(Text);
|
||||
}
|
||||
|
||||
// Helper functions.
|
||||
|
||||
ASTPrinter &operator<<(StringRef Text) {
|
||||
printText(Text);
|
||||
return *this;
|
||||
}
|
||||
ASTPrinter &operator<<(unsigned long long N);
|
||||
void indent(unsigned NumSpaces);
|
||||
|
||||
private:
|
||||
virtual void anchor();
|
||||
};
|
||||
|
||||
/// An AST printer for a raw_ostream.
|
||||
class StreamPrinter : public ASTPrinter {
|
||||
protected:
|
||||
raw_ostream &OS;
|
||||
|
||||
public:
|
||||
explicit StreamPrinter(raw_ostream &OS) : OS(OS) {}
|
||||
|
||||
void printText(StringRef Text) override;
|
||||
};
|
||||
|
||||
} // namespace swift
|
||||
|
||||
#endif // LLVM_SWIFT_AST_ASTPRINTER_H
|
||||
@@ -43,6 +43,7 @@ namespace clang {
|
||||
namespace swift {
|
||||
class ArchetypeType;
|
||||
class ASTContext;
|
||||
class ASTPrinter;
|
||||
class ASTWalker;
|
||||
class Type;
|
||||
class Expr;
|
||||
@@ -377,18 +378,14 @@ public:
|
||||
///
|
||||
/// \param OS Output stream to which the declaration will be printed.
|
||||
void print(raw_ostream &OS) const;
|
||||
void print(raw_ostream &OS, const PrintOptions &Opts) const;
|
||||
|
||||
/// \brief Pretty-print the given declaration.
|
||||
///
|
||||
/// \param os Output stream to which the declaration will be printed.
|
||||
/// \param Printer ASTPrinter object.
|
||||
///
|
||||
/// \param options Options to control how pretty-printing is performed.
|
||||
///
|
||||
/// \param declOffsets If non-null, will be populated with the stream offsets
|
||||
/// at which each declaration encountered is printed.
|
||||
void print(raw_ostream &os, const PrintOptions &options,
|
||||
SmallVectorImpl<std::pair<Decl *, uint64_t>> *declOffsets
|
||||
= nullptr) const;
|
||||
/// \param Opts Options to control how pretty-printing is performed.
|
||||
void print(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
|
||||
/// \brief Determine whether this declaration should be printed when
|
||||
/// encountered in its declaration context's list of members.
|
||||
|
||||
@@ -325,7 +325,7 @@ namespace swift {
|
||||
|
||||
/// \brief The set of declarations for which we have pretty-printed
|
||||
/// results that we can point to on the command line.
|
||||
llvm::DenseMap<Decl *, SourceLoc> PrettyPrintedDeclarations;
|
||||
llvm::DenseMap<const Decl *, SourceLoc> PrettyPrintedDeclarations;
|
||||
|
||||
friend class InFlightDiagnostic;
|
||||
|
||||
|
||||
@@ -201,6 +201,7 @@ public:
|
||||
"only for use within the debugger");
|
||||
void dump(raw_ostream &OS) const;
|
||||
void print(raw_ostream &OS, unsigned Indent = 0) const;
|
||||
void print(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
|
||||
// Only allow allocation of Exprs using the allocator in ASTContext
|
||||
// or by doing a placement new.
|
||||
|
||||
@@ -639,8 +639,9 @@ public:
|
||||
|
||||
/// \brief Pretty-print the contents of this source file.
|
||||
///
|
||||
/// \param OS The stream to which the contents will be printed.
|
||||
/// \param Printer The AST printer used for printing the contents.
|
||||
/// \param PO Options controlling the printing process.
|
||||
void print(ASTPrinter &Printer, const PrintOptions &PO);
|
||||
void print(raw_ostream &OS, const PrintOptions &PO);
|
||||
|
||||
static bool classof(const FileUnit *file) {
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
#include "swift/Basic/LLVM.h"
|
||||
|
||||
namespace swift {
|
||||
class ASTPrinter;
|
||||
class Module;
|
||||
struct PrintOptions;
|
||||
|
||||
void printModuleInterface(Module *M, raw_ostream &OS,
|
||||
void printModuleInterface(Module *M, ASTPrinter &Printer,
|
||||
const PrintOptions &Options);
|
||||
|
||||
} // namespace swift
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
namespace swift {
|
||||
|
||||
class ASTPrinter;
|
||||
class ArchetypeType;
|
||||
class ASTContext;
|
||||
class LazyResolver;
|
||||
@@ -106,6 +107,7 @@ public:
|
||||
void dump() const;
|
||||
|
||||
void print(raw_ostream &OS, const PrintOptions &PO = PrintOptions()) const;
|
||||
void print(ASTPrinter &Printer, const PrintOptions &PO) const;
|
||||
|
||||
/// Return the name of the type as a string, for use in diagnostics only.
|
||||
std::string getString(const PrintOptions &PO = PrintOptions()) const;
|
||||
|
||||
@@ -73,7 +73,8 @@ public:
|
||||
void operator delete(void *data) = delete;
|
||||
void *operator new(size_t bytes, void *data) = delete;
|
||||
|
||||
void print(llvm::raw_ostream &OS) const;
|
||||
void print(raw_ostream &OS, const PrintOptions &Opts = PrintOptions()) const;
|
||||
void print(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
void dump() const;
|
||||
};
|
||||
|
||||
@@ -100,7 +101,7 @@ public:
|
||||
private:
|
||||
SourceLoc getStartLocImpl() const { return Range.Start; }
|
||||
SourceLoc getEndLocImpl() const { return Range.End; }
|
||||
void printImpl(llvm::raw_ostream &OS) const;
|
||||
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
friend class TypeRepr;
|
||||
};
|
||||
|
||||
@@ -122,6 +123,7 @@ public:
|
||||
TypeRepr *getTypeRepr() const { return Ty; }
|
||||
|
||||
void printAttrs(llvm::raw_ostream &OS) const;
|
||||
void printAttrs(ASTPrinter &Printer) const;
|
||||
|
||||
static bool classof(const TypeRepr *T) {
|
||||
return T->getKind() == TypeReprKind::Attributed;
|
||||
@@ -131,7 +133,7 @@ public:
|
||||
private:
|
||||
SourceLoc getStartLocImpl() const { return Attrs.AtLoc; }
|
||||
SourceLoc getEndLocImpl() const { return Ty->getEndLoc(); }
|
||||
void printImpl(llvm::raw_ostream &OS) const;
|
||||
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
friend class TypeRepr;
|
||||
};
|
||||
|
||||
@@ -214,7 +216,7 @@ private:
|
||||
return Components.back().getGenericArgs().back()->getEndLoc();
|
||||
return Components.back().getIdLoc();
|
||||
}
|
||||
void printImpl(llvm::raw_ostream &OS) const;
|
||||
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
friend class TypeRepr;
|
||||
};
|
||||
|
||||
@@ -246,7 +248,7 @@ public:
|
||||
private:
|
||||
SourceLoc getStartLocImpl() const { return ArgsTy->getStartLoc(); }
|
||||
SourceLoc getEndLocImpl() const { return RetTy->getEndLoc(); }
|
||||
void printImpl(llvm::raw_ostream &OS) const;
|
||||
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
friend class TypeRepr;
|
||||
};
|
||||
|
||||
@@ -285,7 +287,7 @@ private:
|
||||
return Base->getEndLoc();
|
||||
return Brackets.End;
|
||||
}
|
||||
void printImpl(llvm::raw_ostream &OS) const;
|
||||
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
friend class TypeRepr;
|
||||
};
|
||||
|
||||
@@ -312,7 +314,7 @@ public:
|
||||
private:
|
||||
SourceLoc getStartLocImpl() const { return Base->getStartLoc(); }
|
||||
SourceLoc getEndLocImpl() const { return QuestionLoc; }
|
||||
void printImpl(llvm::raw_ostream &OS) const;
|
||||
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
friend class TypeRepr;
|
||||
};
|
||||
|
||||
@@ -353,7 +355,7 @@ public:
|
||||
private:
|
||||
SourceLoc getStartLocImpl() const { return Parens.Start; }
|
||||
SourceLoc getEndLocImpl() const { return Parens.End; }
|
||||
void printImpl(llvm::raw_ostream &OS) const;
|
||||
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
friend class TypeRepr;
|
||||
};
|
||||
|
||||
@@ -383,7 +385,7 @@ public:
|
||||
private:
|
||||
SourceLoc getStartLocImpl() const { return IdLoc; }
|
||||
SourceLoc getEndLocImpl() const { return Ty->getEndLoc(); }
|
||||
void printImpl(llvm::raw_ostream &OS) const;
|
||||
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
friend class TypeRepr;
|
||||
};
|
||||
|
||||
@@ -421,7 +423,7 @@ public:
|
||||
private:
|
||||
SourceLoc getStartLocImpl() const { return ProtocolLoc; }
|
||||
SourceLoc getEndLocImpl() const { return AngleBrackets.End; }
|
||||
void printImpl(llvm::raw_ostream &OS) const;
|
||||
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
friend class TypeRepr;
|
||||
};
|
||||
|
||||
@@ -449,7 +451,7 @@ public:
|
||||
private:
|
||||
SourceLoc getStartLocImpl() const { return Base->getStartLoc(); }
|
||||
SourceLoc getEndLocImpl() const { return MetaLoc; }
|
||||
void printImpl(llvm::raw_ostream &OS) const;
|
||||
void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const;
|
||||
friend class TypeRepr;
|
||||
};
|
||||
|
||||
|
||||
@@ -379,6 +379,7 @@ public:
|
||||
void dump() const;
|
||||
void print(raw_ostream &OS,
|
||||
const PrintOptions &PO = PrintOptions()) const;
|
||||
void print(ASTPrinter &Printer, const PrintOptions &PO) const;
|
||||
|
||||
/// Return the name of the type as a string, for use in diagnostics only.
|
||||
std::string getString(const PrintOptions &PO = PrintOptions()) const;
|
||||
@@ -1770,6 +1771,7 @@ public:
|
||||
void dump() const;
|
||||
void print(llvm::raw_ostream &out,
|
||||
const PrintOptions &options = PrintOptions()) const;
|
||||
void print(ASTPrinter &Printer, const PrintOptions &Options) const;
|
||||
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &out,
|
||||
SILParameterInfo type) {
|
||||
type.print(out);
|
||||
@@ -1849,6 +1851,7 @@ public:
|
||||
void dump() const;
|
||||
void print(llvm::raw_ostream &out,
|
||||
const PrintOptions &options = PrintOptions()) const;
|
||||
void print(ASTPrinter &Printer, const PrintOptions &Options) const;
|
||||
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &out,
|
||||
SILResultInfo type) {
|
||||
type.print(out);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/AST/AST.h"
|
||||
#include "swift/AST/ASTPrinter.h"
|
||||
#include "swift/AST/ASTVisitor.h"
|
||||
#include "swift/Basic/STLExtras.h"
|
||||
#include "llvm/ADT/APFloat.h"
|
||||
@@ -1446,6 +1447,14 @@ void Expr::print(raw_ostream &OS, unsigned Indent) const {
|
||||
PrintExpr(OS, Indent).visit(const_cast<Expr*>(this));
|
||||
}
|
||||
|
||||
void Expr::print(ASTPrinter &Printer, const PrintOptions &Opts) const {
|
||||
// FIXME: Fully use the ASTPrinter.
|
||||
llvm::SmallString<128> Str;
|
||||
llvm::raw_svector_ostream OS(Str);
|
||||
print(OS);
|
||||
Printer << OS.str();
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Printing for TypeRepr and all subclasses.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/AST/ASTPrinter.h"
|
||||
#include "swift/AST/Decl.h"
|
||||
#include "swift/AST/DiagnosticEngine.h"
|
||||
#include "swift/AST/Module.h"
|
||||
@@ -325,7 +326,20 @@ void DiagnosticEngine::flushActiveDiagnostic() {
|
||||
// so we can point to it.
|
||||
SourceLoc ppLoc = PrettyPrintedDeclarations[ActiveDiagnosticDecl];
|
||||
if (ppLoc.isInvalid()) {
|
||||
SmallVector<std::pair<Decl *, uint64_t>, 8> entries;
|
||||
class TrackingPrinter : public StreamPrinter {
|
||||
SmallVectorImpl<std::pair<const Decl *, uint64_t>> &Entries;
|
||||
|
||||
public:
|
||||
TrackingPrinter(
|
||||
SmallVectorImpl<std::pair<const Decl *, uint64_t>> &Entries,
|
||||
raw_ostream &OS) :
|
||||
StreamPrinter(OS), Entries(Entries) {}
|
||||
|
||||
void printDeclLoc(const Decl *D) override {
|
||||
Entries.push_back({ D, OS.tell() });
|
||||
}
|
||||
};
|
||||
SmallVector<std::pair<const Decl *, uint64_t>, 8> entries;
|
||||
llvm::SmallString<128> buffer;
|
||||
llvm::SmallString<128> bufferName;
|
||||
{
|
||||
@@ -397,7 +411,8 @@ void DiagnosticEngine::flushActiveDiagnostic() {
|
||||
|
||||
// Pretty-print the declaration we've picked.
|
||||
llvm::raw_svector_ostream out(buffer);
|
||||
ppDecl->print(out, options, &entries);
|
||||
TrackingPrinter printer(entries, out);
|
||||
ppDecl->print(printer, options);
|
||||
}
|
||||
|
||||
// Build a buffer with the pretty-printed declaration.
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/AST/ASTPrinter.h"
|
||||
#include "swift/AST/ASTWalker.h"
|
||||
#include "swift/AST/Diagnostics.h"
|
||||
#include "swift/AST/LazyResolver.h"
|
||||
@@ -1057,12 +1058,17 @@ bool Module::walk(ASTWalker &Walker) {
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void SourceFile::print(raw_ostream &OS, const PrintOptions &PO) {
|
||||
StreamPrinter Printer(OS);
|
||||
print(Printer, PO);
|
||||
}
|
||||
|
||||
void SourceFile::print(ASTPrinter &Printer, const PrintOptions &PO) {
|
||||
for (auto decl : Decls) {
|
||||
if (!decl->shouldPrintInContext(PO))
|
||||
continue;
|
||||
|
||||
decl->print(OS, PO);
|
||||
OS << "\n";
|
||||
decl->print(Printer, PO);
|
||||
Printer << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/AST/ASTPrinter.h"
|
||||
#include "swift/AST/TypeRepr.h"
|
||||
#include "swift/AST/ASTContext.h"
|
||||
#include "swift/AST/ExprHandle.h"
|
||||
@@ -59,9 +60,14 @@ void *TypeRepr::operator new(size_t Bytes, ASTContext &C, unsigned Alignment) {
|
||||
return C.Allocate(Bytes, Alignment);
|
||||
}
|
||||
|
||||
void TypeRepr::print(raw_ostream &OS) const {
|
||||
void TypeRepr::print(raw_ostream &OS, const PrintOptions &Opts) const {
|
||||
StreamPrinter Printer(OS);
|
||||
print(Printer, Opts);
|
||||
}
|
||||
|
||||
void TypeRepr::print(ASTPrinter &Printer, const PrintOptions &Opts) const {
|
||||
if (this == nullptr) {
|
||||
OS << "<null>";
|
||||
Printer << "<null>";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -69,36 +75,44 @@ void TypeRepr::print(raw_ostream &OS) const {
|
||||
#define TYPEREPR(CLASS, PARENT) \
|
||||
case TypeReprKind::CLASS: { \
|
||||
auto Ty = static_cast<const CLASS##TypeRepr*>(this); \
|
||||
return Ty->printImpl(OS); \
|
||||
return Ty->printImpl(Printer, Opts); \
|
||||
}
|
||||
#include "swift/AST/TypeReprNodes.def"
|
||||
}
|
||||
llvm_unreachable("unknown kind!");
|
||||
}
|
||||
|
||||
void ErrorTypeRepr::printImpl(llvm::raw_ostream &OS) const {
|
||||
OS << "<<error type>>";
|
||||
void ErrorTypeRepr::printImpl(ASTPrinter &Printer,
|
||||
const PrintOptions &Opts) const {
|
||||
Printer << "<<error type>>";
|
||||
}
|
||||
|
||||
void AttributedTypeRepr::printImpl(llvm::raw_ostream &OS) const {
|
||||
printAttrs(OS);
|
||||
OS << ' ' << Ty;
|
||||
void AttributedTypeRepr::printImpl(ASTPrinter &Printer,
|
||||
const PrintOptions &Opts) const {
|
||||
printAttrs(Printer);
|
||||
Printer << " ";
|
||||
Ty->print(Printer, Opts);
|
||||
}
|
||||
|
||||
void AttributedTypeRepr::printAttrs(llvm::raw_ostream &OS) const {
|
||||
StreamPrinter Printer(OS);
|
||||
printAttrs(Printer);
|
||||
}
|
||||
|
||||
void AttributedTypeRepr::printAttrs(ASTPrinter &Printer) const {
|
||||
const TypeAttributes &Attrs = getAttrs();
|
||||
if (Attrs.has(TAK_inout)) OS << "@inout ";
|
||||
if (Attrs.has(TAK_auto_closure)) OS << "@auto_closure ";
|
||||
if (Attrs.has(TAK_thin)) OS << "@thin ";
|
||||
if (Attrs.has(TAK_noreturn)) OS << "@noreturn ";
|
||||
if (Attrs.has(TAK_objc_block)) OS << "@objc_block ";
|
||||
if (Attrs.has(TAK_inout)) Printer << "@inout ";
|
||||
if (Attrs.has(TAK_auto_closure)) Printer << "@auto_closure ";
|
||||
if (Attrs.has(TAK_thin)) Printer << "@thin ";
|
||||
if (Attrs.has(TAK_noreturn)) Printer << "@noreturn ";
|
||||
if (Attrs.has(TAK_objc_block)) Printer << "@objc_block ";
|
||||
if (Attrs.cc.hasValue()) {
|
||||
switch (Attrs.cc.getValue()) {
|
||||
case AbstractCC::C: OS << "@cc(cdecl)"; break;
|
||||
case AbstractCC::ObjCMethod: OS << "@cc(objc_method)"; break;
|
||||
case AbstractCC::Freestanding: OS << "@cc(freestanding)"; break;
|
||||
case AbstractCC::Method: OS << "@cc(method)"; break;
|
||||
case AbstractCC::WitnessMethod: OS << "@cc(witness_method)"; break;
|
||||
case AbstractCC::C: Printer << "@cc(cdecl)"; break;
|
||||
case AbstractCC::ObjCMethod: Printer << "@cc(objc_method)"; break;
|
||||
case AbstractCC::Freestanding: Printer << "@cc(freestanding)"; break;
|
||||
case AbstractCC::Method: Printer << "@cc(method)"; break;
|
||||
case AbstractCC::WitnessMethod: Printer << "@cc(witness_method)"; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,45 +128,66 @@ IdentTypeRepr *IdentTypeRepr::createSimple(ASTContext &C, SourceLoc Loc,
|
||||
return create(C, llvm::makeArrayRef(IdTypeComponent));
|
||||
}
|
||||
|
||||
static void printGenericArgs(raw_ostream &OS, ArrayRef<TypeRepr *> Args) {
|
||||
static void printGenericArgs(ASTPrinter &Printer, const PrintOptions &Opts,
|
||||
ArrayRef<TypeRepr *> Args) {
|
||||
if (Args.empty())
|
||||
return;
|
||||
|
||||
OS << '<';
|
||||
Printer << "<";
|
||||
bool First = true;
|
||||
for (auto Arg : Args) {
|
||||
if (First)
|
||||
First = false;
|
||||
else
|
||||
OS << ", ";
|
||||
OS << Arg;
|
||||
Printer << ", ";
|
||||
Arg->print(Printer, Opts);
|
||||
}
|
||||
OS << '>';
|
||||
Printer << ">";
|
||||
}
|
||||
|
||||
void IdentTypeRepr::printImpl(llvm::raw_ostream &OS) const {
|
||||
OS << Components[0].getIdentifier();
|
||||
printGenericArgs(OS, Components[0].getGenericArgs());
|
||||
void IdentTypeRepr::printImpl(ASTPrinter &Printer,
|
||||
const PrintOptions &Opts) const {
|
||||
bool isFirst = true;
|
||||
for (const Component &C : Components) {
|
||||
if (!isFirst)
|
||||
Printer << ".";
|
||||
else
|
||||
isFirst = false;
|
||||
|
||||
for (const Component &C : Components.slice(1, Components.size()-1)) {
|
||||
OS << '.' << C.getIdentifier().get();
|
||||
printGenericArgs(OS, C.getGenericArgs());
|
||||
if (Module *Mod = C.getBoundModule()) {
|
||||
Printer.printModuleRef(Mod, C.getIdentifier().str());
|
||||
} else if (Type Ty = C.getBoundType()) {
|
||||
if (auto NTD = Ty->getAnyNominal())
|
||||
Printer.printTypeRef(NTD, C.getIdentifier().str());
|
||||
else
|
||||
Printer << C.getIdentifier().str();
|
||||
} else {
|
||||
Printer << C.getIdentifier().str();
|
||||
}
|
||||
printGenericArgs(Printer, Opts, C.getGenericArgs());
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionTypeRepr::printImpl(llvm::raw_ostream &OS) const {
|
||||
OS << ArgsTy << " -> " << RetTy;
|
||||
void FunctionTypeRepr::printImpl(ASTPrinter &Printer,
|
||||
const PrintOptions &Opts) const {
|
||||
ArgsTy->print(Printer, Opts);
|
||||
Printer << " -> ";
|
||||
RetTy->print(Printer, Opts);
|
||||
}
|
||||
|
||||
void ArrayTypeRepr::printImpl(llvm::raw_ostream &OS) const {
|
||||
OS << Base << '[';
|
||||
void ArrayTypeRepr::printImpl(ASTPrinter &Printer,
|
||||
const PrintOptions &Opts) const {
|
||||
Base->print(Printer, Opts);
|
||||
Printer << "[";
|
||||
if (Size)
|
||||
Size->getExpr()->print(OS);
|
||||
OS << ']';
|
||||
Size->getExpr()->print(Printer, Opts);
|
||||
Printer << "]";
|
||||
}
|
||||
|
||||
void OptionalTypeRepr::printImpl(llvm::raw_ostream &OS) const {
|
||||
OS << Base << '?';
|
||||
void OptionalTypeRepr::printImpl(ASTPrinter &Printer,
|
||||
const PrintOptions &Opts) const {
|
||||
Base->print(Printer, Opts);
|
||||
Printer << "?";
|
||||
}
|
||||
|
||||
TupleTypeRepr *TupleTypeRepr::create(ASTContext &C,
|
||||
@@ -163,22 +198,24 @@ TupleTypeRepr *TupleTypeRepr::create(ASTContext &C,
|
||||
Parens, Ellipsis);
|
||||
}
|
||||
|
||||
void TupleTypeRepr::printImpl(llvm::raw_ostream &OS) const {
|
||||
OS << '(';
|
||||
void TupleTypeRepr::printImpl(ASTPrinter &Printer,
|
||||
const PrintOptions &Opts) const {
|
||||
Printer << "(";
|
||||
|
||||
for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
|
||||
if (i) OS << ", ";
|
||||
OS << Elements[i];
|
||||
if (i) Printer << ", ";
|
||||
Elements[i]->print(Printer, Opts);
|
||||
}
|
||||
if (hasEllipsis())
|
||||
OS << "...";
|
||||
OS << ')';
|
||||
Printer << "...";
|
||||
Printer << ")";
|
||||
}
|
||||
|
||||
void NamedTypeRepr::printImpl(llvm::raw_ostream &OS) const {
|
||||
void NamedTypeRepr::printImpl(ASTPrinter &Printer,
|
||||
const PrintOptions &Opts) const {
|
||||
if (!Id.empty())
|
||||
OS << Id << " : ";
|
||||
OS << Ty;
|
||||
Printer << Id.str() << " : ";
|
||||
Ty->print(Printer, Opts);
|
||||
}
|
||||
|
||||
ProtocolCompositionTypeRepr *
|
||||
@@ -190,19 +227,22 @@ ProtocolCompositionTypeRepr::create(ASTContext &C,
|
||||
ProtocolLoc, AngleBrackets);
|
||||
}
|
||||
|
||||
void ProtocolCompositionTypeRepr::printImpl(llvm::raw_ostream &OS) const {
|
||||
OS << "protocol<";
|
||||
void ProtocolCompositionTypeRepr::printImpl(ASTPrinter &Printer,
|
||||
const PrintOptions &Opts) const {
|
||||
Printer << "protocol<";
|
||||
bool First = true;
|
||||
for (auto Proto : Protocols) {
|
||||
if (First)
|
||||
First = false;
|
||||
else
|
||||
OS << ", ";
|
||||
OS << Proto;
|
||||
Printer << ", ";
|
||||
Proto->print(Printer, Opts);
|
||||
}
|
||||
OS << '>';
|
||||
Printer << ">";
|
||||
}
|
||||
|
||||
void MetaTypeTypeRepr::printImpl(llvm::raw_ostream &OS) const {
|
||||
OS << Base << ".metatype";
|
||||
void MetaTypeTypeRepr::printImpl(ASTPrinter &Printer,
|
||||
const PrintOptions &Opts) const {
|
||||
Base->print(Printer, Opts);
|
||||
Printer << ".metatype";
|
||||
}
|
||||
|
||||
@@ -1251,7 +1251,7 @@ void SILModule::print(llvm::raw_ostream &OS, bool Verbose,
|
||||
if ((isa<ValueDecl>(D) || isa<OperatorDecl>(D)) &&
|
||||
!emittedFunctions.count(D) &&
|
||||
!D->isImplicit()) {
|
||||
D->print(OS, Options, nullptr);
|
||||
D->print(OS, Options);
|
||||
OS << "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user