clang-format

This commit is contained in:
David Ungar
2018-05-30 20:25:41 -07:00
committed by David Ungar
parent abe7544c1a
commit 44e5cd3bba

View File

@@ -214,18 +214,19 @@ static void emitProvidesTopLevelNames(
out << "- \"" << escape(operatorFunction->getName()) << "\"\n"; out << "- \"" << escape(operatorFunction->getName()) << "\"\n";
} }
static void emitProvidesExtensionDecl(const ExtensionDecl *ED, static void emitProvidesExtensionDecl(
llvm::raw_fd_ostream &out, const ExtensionDecl *ED, llvm::raw_fd_ostream &out,
llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals, llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals,
llvm::SmallVectorImpl<const FuncDecl *> &memberOperatorDecls, llvm::SmallVectorImpl<const FuncDecl *> &memberOperatorDecls,
llvm::SmallVectorImpl<const ExtensionDecl *> &extensionsWithJustMembers); llvm::SmallVectorImpl<const ExtensionDecl *> &extensionsWithJustMembers);
static void emitProvidesNominalTypeDecl(const NominalTypeDecl *NTD, static void emitProvidesNominalTypeDecl(
llvm::raw_fd_ostream &out, const NominalTypeDecl *NTD, llvm::raw_fd_ostream &out,
llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals, llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals,
llvm::SmallVectorImpl<const FuncDecl *> &memberOperatorDecls); llvm::SmallVectorImpl<const FuncDecl *> &memberOperatorDecls);
static void emitProvidesValueDecl(const ValueDecl *VD, llvm::raw_fd_ostream &out); static void emitProvidesValueDecl(const ValueDecl *VD,
llvm::raw_fd_ostream &out);
static void emitProvidesTopLevelDecl( static void emitProvidesTopLevelDecl(
const Decl *const D, llvm::raw_fd_ostream &out, const Decl *const D, llvm::raw_fd_ostream &out,
@@ -241,7 +242,8 @@ static void emitProvidesTopLevelDecl(
break; break;
case DeclKind::Extension: case DeclKind::Extension:
emitProvidesExtensionDecl(cast<ExtensionDecl>(D), out, extendedNominals, memberOperatorDecls, extensionsWithJustMembers); emitProvidesExtensionDecl(cast<ExtensionDecl>(D), out, extendedNominals,
memberOperatorDecls, extensionsWithJustMembers);
break; break;
case DeclKind::InfixOperator: case DeclKind::InfixOperator:
@@ -258,15 +260,16 @@ static void emitProvidesTopLevelDecl(
case DeclKind::Struct: case DeclKind::Struct:
case DeclKind::Class: case DeclKind::Class:
case DeclKind::Protocol: case DeclKind::Protocol:
emitProvidesNominalTypeDecl(cast<NominalTypeDecl>(D), out, extendedNominals, memberOperatorDecls); emitProvidesNominalTypeDecl(cast<NominalTypeDecl>(D), out, extendedNominals,
break; memberOperatorDecls);
break;
case DeclKind::TypeAlias: case DeclKind::TypeAlias:
case DeclKind::Var: case DeclKind::Var:
case DeclKind::Func: case DeclKind::Func:
case DeclKind::Accessor: case DeclKind::Accessor:
emitProvidesValueDecl(cast<ValueDecl>(D), out); emitProvidesValueDecl(cast<ValueDecl>(D), out);
break; break;
case DeclKind::PatternBinding: case DeclKind::PatternBinding:
case DeclKind::TopLevelCode: case DeclKind::TopLevelCode:
@@ -289,24 +292,23 @@ static void emitProvidesTopLevelDecl(
} }
} }
static void emitProvidesExtensionDecl(const ExtensionDecl *const ED, static void emitProvidesExtensionDecl(
llvm::raw_fd_ostream &out, const ExtensionDecl *const ED, llvm::raw_fd_ostream &out,
llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals, llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals,
llvm::SmallVectorImpl<const FuncDecl *> &memberOperatorDecls, llvm::SmallVectorImpl<const FuncDecl *> &memberOperatorDecls,
llvm::SmallVectorImpl<const ExtensionDecl *> &extensionsWithJustMembers) { llvm::SmallVectorImpl<const ExtensionDecl *> &extensionsWithJustMembers) {
auto *NTD = ED->getExtendedType()->getAnyNominal(); auto *NTD = ED->getExtendedType()->getAnyNominal();
if (!NTD) if (!NTD)
return; return;
if (NTD->hasAccess() && if (NTD->hasAccess() && NTD->getFormalAccess() <= AccessLevel::FilePrivate) {
NTD->getFormalAccess() <= AccessLevel::FilePrivate) {
return; return;
} }
// Check if the extension is just adding members, or if it is // Check if the extension is just adding members, or if it is
// introducing a conformance to a public protocol. // introducing a conformance to a public protocol.
bool justMembers = bool justMembers =
std::all_of(ED->getInherited().begin(), ED->getInherited().end(), std::all_of(ED->getInherited().begin(), ED->getInherited().end(),
extendedTypeIsPrivate); extendedTypeIsPrivate);
if (justMembers) { if (justMembers) {
if (std::all_of(ED->getMembers().begin(), ED->getMembers().end(), if (std::all_of(ED->getMembers().begin(), ED->getMembers().end(),
declIsPrivate)) { declIsPrivate)) {
@@ -319,14 +321,13 @@ static void emitProvidesExtensionDecl(const ExtensionDecl *const ED,
ED->getMembers()); ED->getMembers());
} }
static void emitProvidesNominalTypeDecl(const NominalTypeDecl *const NTD, static void emitProvidesNominalTypeDecl(
llvm::raw_fd_ostream &out, const NominalTypeDecl *const NTD, llvm::raw_fd_ostream &out,
llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals, llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals,
llvm::SmallVectorImpl<const FuncDecl *> &memberOperatorDecls) { llvm::SmallVectorImpl<const FuncDecl *> &memberOperatorDecls) {
if (!NTD->hasName()) if (!NTD->hasName())
return; return;
if (NTD->hasAccess() && if (NTD->hasAccess() && NTD->getFormalAccess() <= AccessLevel::FilePrivate) {
NTD->getFormalAccess() <= AccessLevel::FilePrivate) {
return; return;
} }
out << "- \"" << escape(NTD->getName()) << "\"\n"; out << "- \"" << escape(NTD->getName()) << "\"\n";
@@ -335,7 +336,8 @@ static void emitProvidesNominalTypeDecl(const NominalTypeDecl *const NTD,
NTD->getMembers()); NTD->getMembers());
} }
static void emitProvidesValueDecl(const ValueDecl *const VD, llvm::raw_fd_ostream &out) { static void emitProvidesValueDecl(const ValueDecl *const VD,
llvm::raw_fd_ostream &out) {
if (!VD->hasName()) if (!VD->hasName())
return; return;
if (VD->hasAccess() && VD->getFormalAccess() <= AccessLevel::FilePrivate) { if (VD->hasAccess() && VD->getFormalAccess() <= AccessLevel::FilePrivate) {
@@ -344,10 +346,9 @@ static void emitProvidesValueDecl(const ValueDecl *const VD, llvm::raw_fd_ostrea
out << "- \"" << escape(VD->getBaseName()) << "\"\n"; out << "- \"" << escape(VD->getBaseName()) << "\"\n";
} }
static void emitProvidesNominalTypes( static void emitProvidesNominalTypes(
const llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals, const llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals,
llvm::raw_fd_ostream &out) { llvm::raw_fd_ostream &out) {
out << "provides-nominal:\n"; out << "provides-nominal:\n";
for (auto entry : extendedNominals) { for (auto entry : extendedNominals) {
if (!entry.second) if (!entry.second)
@@ -359,22 +360,22 @@ static void emitProvidesNominalTypes(
} }
static void emitProvidesMembers( static void emitProvidesMembers(
const llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals, const llvm::MapVector<const NominalTypeDecl *, bool> &extendedNominals,
const llvm::SmallVectorImpl<const ExtensionDecl *> const llvm::SmallVectorImpl<const ExtensionDecl *>
&extensionsWithJustMembers, &extensionsWithJustMembers,
llvm::raw_fd_ostream &out) { llvm::raw_fd_ostream &out) {
out << "provides-member:\n"; out << "provides-member:\n";
for (auto entry : extendedNominals) { for (auto entry : extendedNominals) {
out << "- [\""; out << "- [\"";
out << mangleTypeAsContext(entry.first); out << mangleTypeAsContext(entry.first);
out << "\", \"\"]\n"; out << "\", \"\"]\n";
} }
// This is also part of "provides-member". // This is also part of "provides-member".
for (auto *ED : extensionsWithJustMembers) { for (auto *ED : extensionsWithJustMembers) {
auto mangledName = auto mangledName =
mangleTypeAsContext(ED->getExtendedType()->getAnyNominal()); mangleTypeAsContext(ED->getExtendedType()->getAnyNominal());
for (auto *member : ED->getMembers()) { for (auto *member : ED->getMembers()) {
auto *VD = dyn_cast<ValueDecl>(member); auto *VD = dyn_cast<ValueDecl>(member);
if (!VD || !VD->hasName() || if (!VD || !VD->hasName() ||
@@ -382,7 +383,7 @@ static void emitProvidesMembers(
continue; continue;
} }
out << "- [\"" << mangledName << "\", \"" << escape(VD->getBaseName()) out << "- [\"" << mangledName << "\", \"" << escape(VD->getBaseName())
<< "\"]\n"; << "\"]\n";
} }
} }
} }
@@ -398,17 +399,17 @@ static void emitProvidesDynamicLookupMembers(const SourceFile *const SF,
class NameCollector : public VisibleDeclConsumer { class NameCollector : public VisibleDeclConsumer {
private: private:
SmallVector<DeclBaseName, 16> names; SmallVector<DeclBaseName, 16> names;
public: public:
void foundDecl(ValueDecl *VD, DeclVisibilityKind Reason) override { void foundDecl(ValueDecl *VD, DeclVisibilityKind Reason) override {
names.push_back(VD->getBaseName()); names.push_back(VD->getBaseName());
} }
ArrayRef<DeclBaseName> getNames() { ArrayRef<DeclBaseName> getNames() {
llvm::array_pod_sort( llvm::array_pod_sort(
names.begin(), names.end(), names.begin(), names.end(),
[](const DeclBaseName *lhs, const DeclBaseName *rhs) { [](const DeclBaseName *lhs, const DeclBaseName *rhs) {
return lhs->compare(*rhs); return lhs->compare(*rhs);
}); });
names.erase(std::unique(names.begin(), names.end()), names.end()); names.erase(std::unique(names.begin(), names.end()), names.end());
return names; return names;
} }