Provide ways to get back to the original Clang declaration from

a SILFunction or SILGLobalVariable.

This will be used as one step towards moving IRGen off of the
global external-definitions list.
This commit is contained in:
John McCall
2016-05-18 11:33:17 -07:00
parent ea1bf9c999
commit c2b8bb22ba
11 changed files with 105 additions and 37 deletions

View File

@@ -105,6 +105,9 @@ private:
/// The declcontext of this function.
DeclContext *DeclCtx;
/// The owning declaration of this function's clang node, if applicable.
ValueDecl *ClangNodeOwner = nullptr;
/// The source location and scope of the function.
const SILDebugScope *DebugScope;
@@ -146,9 +149,6 @@ private:
/// it public.
unsigned KeepAsPublic : 1;
/// This flag indicates if a function has a body generated by Clang.
unsigned ForeignBody : 1;
/// This is the number of uses of this SILFunction inside the SIL.
/// It does not include references from debug scopes.
unsigned RefCount = 0;
@@ -515,9 +515,37 @@ public:
bool isKeepAsPublic() const { return KeepAsPublic; }
void setKeepAsPublic(bool keep) { KeepAsPublic = keep; }
/// Get this function's foreign body attribute.
HasForeignBody_t hasForeignBody() const { return HasForeignBody_t(ForeignBody); }
void setForeignBody(HasForeignBody_t foreign) { ForeignBody = foreign; }
/// Return whether this function has a foreign implementation which can
/// be emitted on demand.
bool hasForeignBody() const;
/// Return whether this function corresponds to a Clang node.
bool hasClangNode() const {
return ClangNodeOwner != nullptr;
}
/// Set the owning declaration of the Clang node associated with this
/// function. We have to store an owner (a Swift declaration) instead of
/// directly referencing the original declaration due to current
/// limitations in the serializer.
void setClangNodeOwner(ValueDecl *owner) {
assert(owner->hasClangNode());
ClangNodeOwner = owner;
}
/// Return the owning declaration of the Clang node associated with this
/// function. This should only be used for serialization.
ValueDecl *getClangNodeOwner() const {
return ClangNodeOwner;
}
/// Return the Clang node associated with this function if it has one.
ClangNode getClangNode() const {
return (ClangNodeOwner ? ClangNodeOwner->getClangNode() : ClangNode());
}
const clang::Decl *getClangDecl() const {
return (ClangNodeOwner ? ClangNodeOwner->getClangDecl() : nullptr);
}
/// Retrieve the generic parameter list containing the contextual archetypes
/// of the function.