mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ConstraintSystem] Elevate TypedNode access helpers up to the namespace
Originally such accessors were only useful for `FailureDiagnostic` but now since `ConstraintLocator` is anchored with `TypedNode` it makes sense to make them universally accessible.
This commit is contained in:
@@ -4447,3 +4447,27 @@ void ConstraintSystem::maybeProduceFallbackDiagnostic(
|
||||
|
||||
ctx.Diags.diagnose(target.getLoc(), diag::failed_to_produce_diagnostic);
|
||||
}
|
||||
|
||||
SourceLoc constraints::getLoc(TypedNode anchor) {
|
||||
if (auto *E = anchor.dyn_cast<const Expr *>()) {
|
||||
return E->getLoc();
|
||||
} else if (auto *T = anchor.dyn_cast<const TypeLoc *>()) {
|
||||
return T->getLoc();
|
||||
} else if (auto *V = anchor.dyn_cast<const VarDecl *>()) {
|
||||
return V->getNameLoc();
|
||||
} else {
|
||||
return anchor.get<const Pattern *>()->getLoc();
|
||||
}
|
||||
}
|
||||
|
||||
SourceRange constraints::getSourceRange(TypedNode anchor) {
|
||||
if (auto *E = anchor.dyn_cast<const Expr *>()) {
|
||||
return E->getSourceRange();
|
||||
} else if (auto *T = anchor.dyn_cast<const TypeLoc *>()) {
|
||||
return T->getSourceRange();
|
||||
} else if (auto *V = anchor.dyn_cast<const VarDecl *>()) {
|
||||
return V->getSourceRange();
|
||||
} else {
|
||||
return anchor.get<const Pattern *>()->getSourceRange();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user