-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathTypeCheckRequest.cpp
105 lines (84 loc) · 3.21 KB
/
TypeCheckRequest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//===--- TypeCheckRequest.cpp - Type Checking Request ---------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 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
//
//===----------------------------------------------------------------------===//
//
// This file implements the TypeCheckRequest type, which describes a
// request to the type checker to compute certain information.
//
//===----------------------------------------------------------------------===//
#include "swift/Sema/TypeCheckRequest.h"
#include "swift/AST/Decl.h"
using namespace swift;
SourceLoc TypeCheckRequest::getLoc() const {
switch (getPayloadKind(getKind())) {
#define DELEGATE_GET_LOC(PayloadName) \
case PayloadKind::PayloadName: \
return get##PayloadName##Payload()->getLoc();
DELEGATE_GET_LOC(Class)
DELEGATE_GET_LOC(Enum)
case PayloadKind::InheritedClauseEntry: {
auto payload = getInheritedClauseEntryPayload();
if (auto typeDecl = payload.first.dyn_cast<TypeDecl *>())
return typeDecl->getInherited()[payload.second].getLoc();
return payload.first.get<ExtensionDecl *>()->getInherited()[payload.second]
.getLoc();
}
DELEGATE_GET_LOC(Protocol)
case PayloadKind::DeclContextLookup:
return getDeclContextLookupPayload().Loc;
case PayloadKind::TypeResolution:
return std::get<0>(getTypeResolutionPayload())->getLoc();
DELEGATE_GET_LOC(TypeDeclResolution)
#undef DELEGATE_GET_LOC
}
}
Decl *TypeCheckRequest::getAnchor() const {
switch (getPayloadKind(getKind())) {
#define DECL_PAYLOAD(PayloadName) \
case PayloadKind::PayloadName: \
return get##PayloadName##Payload();
#define NO_DECL_PAYLOAD(PayloadName) \
case PayloadKind::PayloadName: \
return nullptr;
DECL_PAYLOAD(Class)
DECL_PAYLOAD(Enum)
case PayloadKind::InheritedClauseEntry: {
auto payload = getInheritedClauseEntryPayload();
if (auto typeDecl = payload.first.dyn_cast<TypeDecl *>())
return typeDecl;
return payload.first.get<ExtensionDecl *>();
}
DECL_PAYLOAD(Protocol)
case PayloadKind::DeclContextLookup: {
auto dc = getDeclContextLookupPayload().DC;
if (auto nominal = dyn_cast<NominalTypeDecl>(dc))
return nominal;
if (auto ext = dyn_cast<ExtensionDecl>(dc))
return ext;
return nullptr;
}
NO_DECL_PAYLOAD(TypeResolution)
DECL_PAYLOAD(TypeDeclResolution)
#undef NO_DECL_PAYLOAD
#undef DECL_PAYLOAD
}
}
bool swift::operator==(const TypeCheckRequest &x, const TypeCheckRequest &y) {
// Check the request kinds.
if (x.getKind() != y.getKind()) return false;
// Check the payload.
switch (TypeCheckRequest::getPayloadKind(x.getKind())) {
#define TYPE_CHECK_REQUEST_PAYLOAD(PayloadName,...) \
case TypeCheckRequest::PayloadKind::PayloadName: \
return x.get##PayloadName##Payload() == y.get##PayloadName##Payload();
#include "swift/Sema/TypeCheckRequestPayloads.def"
}
}