[Expr/AST] Add unresolvedApply component to handle method arguments.

This commit is contained in:
Amritpan Kaur
2024-09-04 18:17:55 -07:00
parent 0af27a6354
commit 0c614e09d1
8 changed files with 81 additions and 14 deletions

View File

@@ -5889,6 +5889,7 @@ public:
public:
enum class Kind : unsigned {
Invalid,
UnresolvedApply,
UnresolvedMember,
UnresolvedSubscript,
Member,
@@ -5914,13 +5915,15 @@ public:
ArgumentList *ArgList;
const ProtocolConformanceRef *HashableConformancesData;
std::optional<FunctionRefInfo> ComponentFuncRefKind;
unsigned TupleIndex;
Kind KindValue;
Type ComponentType;
SourceLoc Loc;
// Private constructor for subscript component.
// Private constructor for unresolvedSubscript, subscript and
// unresolvedApply component.
explicit Component(DeclNameOrRef decl, ArgumentList *argList,
ArrayRef<ProtocolConformanceRef> indexHashables,
Kind kind, Type type, SourceLoc loc);
@@ -5933,6 +5936,14 @@ public:
Decl = decl;
}
// Private constructor for an unresolvedMember or member kind.
explicit Component(DeclNameOrRef decl, Kind kind, Type type,
FunctionRefInfo funcRefKind, SourceLoc loc)
: Decl(decl), ComponentFuncRefKind(funcRefKind), KindValue(kind),
ComponentType(type), Loc(loc) {
assert(kind == Kind::Member || kind == Kind::UnresolvedMember);
}
// Private constructor for tuple element kind.
explicit Component(unsigned tupleIndex, Type elementType, SourceLoc loc)
: Component(Kind::TupleElement, elementType, loc) {
@@ -5941,15 +5952,25 @@ public:
// Private constructor for basic components with no additional information.
explicit Component(Kind kind, Type type, SourceLoc loc)
: Decl(), KindValue(kind), ComponentType(type), Loc(loc) {}
: Decl(), ComponentFuncRefKind(std::nullopt), KindValue(kind),
ComponentType(type), Loc(loc) {}
public:
Component() : Component(Kind::Invalid, Type(), SourceLoc()) {}
/// Create an unresolved component for a member.
/// Create an unresolved component for an unresolved apply.
static Component forUnresolvedApply(ASTContext &ctx,
ArgumentList *argList) {
return Component({}, argList, {}, Kind::UnresolvedApply, Type(),
argList->getLParenLoc());
};
/// Create an unresolved component for an unresolved member.
static Component forUnresolvedMember(DeclNameRef UnresolvedName,
SourceLoc Loc) {
return Component(UnresolvedName, Kind::UnresolvedMember, Type(), Loc);
FunctionRefInfo funcRefKind,
SourceLoc loc) {
return Component(UnresolvedName, Kind::UnresolvedMember, Type(),
funcRefKind, loc);
}
/// Create an unresolved component for a subscript.
@@ -5967,9 +5988,8 @@ public:
}
/// Create a component for a property.
static Component forProperty(ConcreteDeclRef property,
Type propertyType,
SourceLoc loc) {
static Component forMember(ConcreteDeclRef property, Type propertyType,
SourceLoc loc) {
return Component(property, Kind::Member, propertyType, loc);
}
@@ -6054,6 +6074,7 @@ public:
case Kind::UnresolvedSubscript:
case Kind::UnresolvedMember:
case Kind::UnresolvedApply:
case Kind::Invalid:
case Kind::CodeCompletion:
return false;
@@ -6065,6 +6086,7 @@ public:
switch (getKind()) {
case Kind::Subscript:
case Kind::UnresolvedSubscript:
case Kind::UnresolvedApply:
return ArgList;
case Kind::Invalid:
@@ -6099,6 +6121,7 @@ public:
case Kind::OptionalChain:
case Kind::OptionalWrap:
case Kind::OptionalForce:
case Kind::UnresolvedApply:
case Kind::UnresolvedMember:
case Kind::Member:
case Kind::Identity:
@@ -6122,6 +6145,7 @@ public:
case Kind::OptionalChain:
case Kind::OptionalWrap:
case Kind::OptionalForce:
case Kind::UnresolvedApply:
case Kind::Member:
case Kind::Identity:
case Kind::TupleElement:
@@ -6140,6 +6164,7 @@ public:
case Kind::Invalid:
case Kind::UnresolvedMember:
case Kind::UnresolvedSubscript:
case Kind::UnresolvedApply:
case Kind::OptionalChain:
case Kind::OptionalWrap:
case Kind::OptionalForce:
@@ -6161,6 +6186,7 @@ public:
case Kind::Invalid:
case Kind::UnresolvedMember:
case Kind::UnresolvedSubscript:
case Kind::UnresolvedApply:
case Kind::OptionalChain:
case Kind::OptionalWrap:
case Kind::OptionalForce:
@@ -6181,6 +6207,7 @@ public:
case Kind::Invalid:
case Kind::UnresolvedMember:
case Kind::UnresolvedSubscript:
case Kind::UnresolvedApply:
case Kind::OptionalChain:
case Kind::OptionalWrap:
case Kind::OptionalForce:
@@ -6194,6 +6221,30 @@ public:
llvm_unreachable("unhandled kind");
}
FunctionRefInfo getFunctionRefInfo() const {
switch (getKind()) {
case Kind::UnresolvedMember:
assert(ComponentFuncRefKind &&
"FunctionRefInfo should not be nullopt for UnresolvedMember");
return *ComponentFuncRefKind;
case Kind::Member:
case Kind::Subscript:
case Kind::Invalid:
case Kind::UnresolvedSubscript:
case Kind::OptionalChain:
case Kind::OptionalWrap:
case Kind::OptionalForce:
case Kind::Identity:
case Kind::TupleElement:
case Kind::DictionaryKey:
case Kind::CodeCompletion:
case Kind::UnresolvedApply:
llvm_unreachable("no function ref kind for this kind");
}
llvm_unreachable("unhandled kind");
}
Type getComponentType() const {
return ComponentType;
}