Skip to content

Commit 2e4c0ae

Browse files
committed
---
yaml --- r: 349377 b: refs/heads/master-next c: 9461dcd h: refs/heads/master i: 349375: 077951a
1 parent 2af1614 commit 2e4c0ae

File tree

7 files changed

+58
-56
lines changed

7 files changed

+58
-56
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: 4d1d2d7c41bf80e8239c6c345a89768f311aa961
3+
refs/heads/master-next: 9461dcdc00e3320be12b74ed8d6be2b404b5638c
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/include/swift/AST/ClangModuleLoader.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define SWIFT_AST_CLANG_MODULE_LOADER_H
1515

1616
#include "swift/AST/ModuleLoader.h"
17-
#include "swift/Demangling/Demangle.h"
1817

1918
namespace clang {
2019
class ASTContext;
@@ -28,11 +27,24 @@ namespace swift {
2827
class DeclContext;
2928
class VisibleDeclConsumer;
3029

30+
/// Represents the different namespaces for types in C.
31+
///
32+
/// A simplified version of clang::Sema::LookupKind.
33+
enum class ClangTypeKind {
34+
Typedef,
35+
ObjCClass = Typedef,
36+
/// Structs, enums, and unions.
37+
Tag,
38+
ObjCProtocol,
39+
};
40+
3141
class ClangModuleLoader : public ModuleLoader {
3242
private:
3343
virtual void anchor();
44+
3445
protected:
3546
using ModuleLoader::ModuleLoader;
47+
3648
public:
3749
virtual clang::ASTContext &getClangASTContext() const = 0;
3850
virtual clang::Preprocessor &getClangPreprocessor() const = 0;
@@ -56,9 +68,9 @@ class ClangModuleLoader : public ModuleLoader {
5668
///
5769
/// This routine is used for various hacks that are only permitted within
5870
/// overlays of imported modules, e.g., Objective-C bridging conformances.
59-
virtual bool isInOverlayModuleForImportedModule(
60-
const DeclContext *overlayDC,
61-
const DeclContext *importedDC) = 0;
71+
virtual bool
72+
isInOverlayModuleForImportedModule(const DeclContext *overlayDC,
73+
const DeclContext *importedDC) = 0;
6274

6375
/// Look for declarations associated with the given name.
6476
///
@@ -70,7 +82,7 @@ class ClangModuleLoader : public ModuleLoader {
7082
/// Note that this method does no filtering. If it finds the type in a loaded
7183
/// module, it returns it. This is intended for use in reflection / debugging
7284
/// contexts where access is not a problem.
73-
virtual void lookupTypeDecl(StringRef clangName, Demangle::Node::Kind kind,
85+
virtual void lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
7486
llvm::function_ref<void(TypeDecl *)> receiver) {}
7587

7688
/// Look up type a declaration synthesized by the Clang importer itself, using
@@ -82,11 +94,11 @@ class ClangModuleLoader : public ModuleLoader {
8294
/// module, it returns it. This is intended for use in reflection / debugging
8395
/// contexts where access is not a problem.
8496
virtual void
85-
lookupRelatedEntity(StringRef clangName, StringRef relatedEntityKind,
97+
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
98+
StringRef relatedEntityKind,
8699
llvm::function_ref<void(TypeDecl *)> receiver) {}
87100
};
88101

89102
} // namespace swift
90103

91104
#endif // LLVM_SWIFT_AST_CLANG_MODULE_LOADER_H
92-

branches/master-next/include/swift/ClangImporter/ClangImporter.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,6 @@ class TypeDecl;
6060
class VisibleDeclConsumer;
6161
enum class SelectorSplitKind;
6262

63-
/// Represents the different namespaces for types in C.
64-
///
65-
/// A simplified version of clang::Sema::LookupKind.
66-
enum class ClangTypeKind {
67-
Typedef,
68-
ObjCClass = Typedef,
69-
/// Structs, enums, and unions.
70-
Tag,
71-
ObjCProtocol,
72-
};
73-
7463
/// Class that imports Clang modules into Swift, mapping directly
7564
/// from Clang ASTs over to Swift ASTs.
7665
class ClangImporter final : public ClangModuleLoader {
@@ -168,8 +157,8 @@ class ClangImporter final : public ClangModuleLoader {
168157
/// Note that this method does no filtering. If it finds the type in a loaded
169158
/// module, it returns it. This is intended for use in reflection / debugging
170159
/// contexts where access is not a problem.
171-
void lookupTypeDecl(StringRef clangName, Demangle::Node::Kind kind,
172-
llvm::function_ref<void(TypeDecl*)> receiver) override;
160+
void lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
161+
llvm::function_ref<void(TypeDecl *)> receiver) override;
173162

174163
/// Look up type a declaration synthesized by the Clang importer itself, using
175164
/// a "related entity kind" to determine which type it should be. For example,
@@ -180,7 +169,8 @@ class ClangImporter final : public ClangModuleLoader {
180169
/// module, it returns it. This is intended for use in reflection / debugging
181170
/// contexts where access is not a problem.
182171
void
183-
lookupRelatedEntity(StringRef clangName, StringRef relatedEntityKind,
172+
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
173+
StringRef relatedEntityKind,
184174
llvm::function_ref<void(TypeDecl *)> receiver) override;
185175

186176
/// Look for textually included declarations from the bridging header.

branches/master-next/include/swift/DWARFImporter/DWARFImporter.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "swift/AST/ClangModuleLoader.h"
2121
#include "swift/AST/Module.h"
22-
#include "swift/Demangling/Demangle.h"
2322

2423
namespace llvm {
2524
}
@@ -43,8 +42,7 @@ class DWARFImporterDelegate {
4342
virtual ~DWARFImporterDelegate() = default;
4443
/// Perform a qualified lookup of a Clang type with this name.
4544
/// \param kind Only return results with this type kind.
46-
virtual void lookupValue(StringRef name,
47-
llvm::Optional<Demangle::Node::Kind> kind,
45+
virtual void lookupValue(StringRef name, llvm::Optional<ClangTypeKind> kind,
4846
SmallVectorImpl<clang::Decl *> &results) {}
4947
};
5048

@@ -111,7 +109,7 @@ class DWARFImporter final : public ClangModuleLoader {
111109
NLKind lookupKind, SmallVectorImpl<ValueDecl *> &results);
112110
/// Perform a qualified lookup of a Clang type with this name and only return
113111
/// results with the specified type kind.
114-
void lookupTypeDecl(StringRef rawName, Demangle::Node::Kind kind,
112+
void lookupTypeDecl(StringRef rawName, ClangTypeKind kind,
115113
llvm::function_ref<void(TypeDecl *)> receiver) override;
116114
bool
117115
isInOverlayModuleForImportedModule(const DeclContext *overlayDC,

branches/master-next/lib/AST/ASTDemangler.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,23 @@ ASTBuilder::findTypeDecl(DeclContext *dc,
10231023
return result;
10241024
}
10251025

1026+
static Optional<ClangTypeKind>
1027+
getClangTypeKindForNodeKind(Demangle::Node::Kind kind) {
1028+
switch (kind) {
1029+
case Demangle::Node::Kind::Protocol:
1030+
return ClangTypeKind::ObjCProtocol;
1031+
case Demangle::Node::Kind::Class:
1032+
return ClangTypeKind::ObjCClass;
1033+
case Demangle::Node::Kind::TypeAlias:
1034+
return ClangTypeKind::Typedef;
1035+
case Demangle::Node::Kind::Structure:
1036+
case Demangle::Node::Kind::Enum:
1037+
return ClangTypeKind::Tag;
1038+
default:
1039+
return None;
1040+
}
1041+
}
1042+
10261043
GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
10271044
StringRef relatedEntityKind,
10281045
ForeignModuleKind foreignKind,
@@ -1060,23 +1077,28 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
10601077
consumer.foundDecl(found, DeclVisibilityKind::VisibleAtTopLevel);
10611078
};
10621079

1080+
Optional<ClangTypeKind> lookupKind = getClangTypeKindForNodeKind(kind);
1081+
if (!lookupKind)
1082+
return nullptr;
1083+
10631084
switch (foreignKind) {
10641085
case ForeignModuleKind::SynthesizedByImporter:
10651086
if (!relatedEntityKind.empty()) {
1066-
importer->lookupRelatedEntity(name, relatedEntityKind, found);
1087+
importer->lookupRelatedEntity(name, *lookupKind, relatedEntityKind,
1088+
found);
10671089
break;
10681090
}
10691091
importer->lookupValue(Ctx.getIdentifier(name), consumer);
10701092
if (consumer.Result)
10711093
consumer.Result = getAcceptableTypeDeclCandidate(consumer.Result, kind);
10721094
break;
10731095
case ForeignModuleKind::Imported:
1074-
importer->lookupTypeDecl(name, kind, found);
1096+
importer->lookupTypeDecl(name, *lookupKind, found);
10751097

10761098
// Try the DWARFImporter if it exists.
10771099
if (!consumer.Result)
10781100
if (auto *dwarf_importer = Ctx.getDWARFModuleLoader())
1079-
dwarf_importer->lookupTypeDecl(name, kind, found);
1101+
dwarf_importer->lookupTypeDecl(name, *lookupKind, found);
10801102
}
10811103

10821104
return consumer.Result;

branches/master-next/lib/ClangImporter/ClangImporter.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,34 +2495,14 @@ void ClangImporter::lookupValue(DeclName name, VisibleDeclConsumer &consumer){
24952495
});
24962496
}
24972497

2498-
static Optional<ClangTypeKind>
2499-
getClangTypeKindForNodeKind(Demangle::Node::Kind kind) {
2500-
switch (kind) {
2501-
case Demangle::Node::Kind::Protocol:
2502-
return ClangTypeKind::ObjCProtocol;
2503-
case Demangle::Node::Kind::Class:
2504-
return ClangTypeKind::ObjCClass;
2505-
case Demangle::Node::Kind::TypeAlias:
2506-
return ClangTypeKind::Typedef;
2507-
case Demangle::Node::Kind::Structure:
2508-
case Demangle::Node::Kind::Enum:
2509-
return ClangTypeKind::Tag;
2510-
default:
2511-
return None;
2512-
}
2513-
}
2514-
25152498
void ClangImporter::lookupTypeDecl(
2516-
StringRef rawName, Demangle::Node::Kind kind,
2499+
StringRef rawName, ClangTypeKind kind,
25172500
llvm::function_ref<void(TypeDecl *)> receiver) {
25182501
clang::DeclarationName clangName(
25192502
&Impl.Instance->getASTContext().Idents.get(rawName));
25202503

25212504
clang::Sema::LookupNameKind lookupKind;
2522-
auto clang_kind = getClangTypeKindForNodeKind(kind);
2523-
if (!clang_kind)
2524-
return;
2525-
switch (*clang_kind) {
2505+
switch (kind) {
25262506
case ClangTypeKind::Typedef:
25272507
lookupKind = clang::Sema::LookupOrdinaryName;
25282508
break;
@@ -2553,17 +2533,17 @@ void ClangImporter::lookupTypeDecl(
25532533
}
25542534

25552535
void ClangImporter::lookupRelatedEntity(
2556-
StringRef rawName, StringRef relatedEntityKind,
2536+
StringRef rawName, ClangTypeKind kind, StringRef relatedEntityKind,
25572537
llvm::function_ref<void(TypeDecl *)> receiver) {
25582538
using CISTAttr = ClangImporterSynthesizedTypeAttr;
25592539
if (relatedEntityKind ==
25602540
CISTAttr::manglingNameForKind(CISTAttr::Kind::NSErrorWrapper) ||
25612541
relatedEntityKind ==
25622542
CISTAttr::manglingNameForKind(CISTAttr::Kind::NSErrorWrapperAnon)) {
2563-
auto underlyingKind = Demangle::Node::Kind::Structure;
2543+
auto underlyingKind = ClangTypeKind::Tag;
25642544
if (relatedEntityKind ==
25652545
CISTAttr::manglingNameForKind(CISTAttr::Kind::NSErrorWrapperAnon)) {
2566-
underlyingKind = Demangle::Node::Kind::TypeAlias;
2546+
underlyingKind = ClangTypeKind::Typedef;
25672547
}
25682548
lookupTypeDecl(rawName, underlyingKind,
25692549
[this, receiver] (const TypeDecl *foundType) {

branches/master-next/lib/DWARFImporter/DWARFImporter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class DWARFImporter::Implementation {
177177
}
178178
}
179179

180-
void lookupTypeDecl(StringRef rawName, Demangle::Node::Kind kind,
180+
void lookupTypeDecl(StringRef rawName, ClangTypeKind kind,
181181
llvm::function_ref<void(TypeDecl *)> receiver) {
182182
SmallVector<clang::Decl *, 1> decls;
183183
delegate->lookupValue(rawName, kind, decls);
@@ -250,7 +250,7 @@ void DWARFImporter::lookupValue(ModuleDecl::AccessPathTy accessPath,
250250
}
251251

252252
void DWARFImporter::lookupTypeDecl(
253-
StringRef rawName, Demangle::Node::Kind kind,
253+
StringRef rawName, ClangTypeKind kind,
254254
llvm::function_ref<void(TypeDecl *)> receiver) {
255255
Impl.lookupTypeDecl(rawName, kind, receiver);
256256
}

0 commit comments

Comments
 (0)