mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Implement 'extern library' support for functions. (#4220)
Support for types (particularly classes) is left as a TODO. There's also an issue I'm observing with a "define in impl" test, but this is probably an issue with resolving the prior declaration which is imported indirectly. The PR was already feeling big, so I'm choosing to cut here. Note, this does not implement the rule "The owning library's API file must import the `extern` declaration, and must also contain a declaration."
This commit is contained in:
@@ -130,10 +130,12 @@ class NodeStack {
|
||||
return PeekIs(RequiredParseCategory);
|
||||
}
|
||||
|
||||
// Returns whether there is a name on top of the stack.
|
||||
auto PeekIsName() const -> bool {
|
||||
// Returns whether there is a node with the corresponding ID on top of the
|
||||
// stack.
|
||||
template <typename IdT>
|
||||
auto PeekIs() const -> bool {
|
||||
return !stack_.empty() &&
|
||||
NodeKindToIdKind(PeekNodeKind()) == Id::KindFor<SemIR::NameId>();
|
||||
NodeKindToIdKind(PeekNodeKind()) == Id::KindFor<IdT>();
|
||||
}
|
||||
|
||||
// Returns whether the *next* node on the stack is a given kind. This doesn't
|
||||
@@ -274,6 +276,16 @@ class NodeStack {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Pops the top of the stack if it has the given category, and returns the ID.
|
||||
// Otherwise returns std::nullopt.
|
||||
template <typename IdT>
|
||||
auto PopIf() -> std::optional<IdT> {
|
||||
if (PeekIs<IdT>()) {
|
||||
return Pop<IdT>();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Pops the top of the stack and returns the node_id and the ID if it is
|
||||
// of the specified kind.
|
||||
template <const Parse::NodeKind& RequiredParseKind>
|
||||
@@ -436,6 +448,9 @@ class NodeStack {
|
||||
return Id::KindFor<SemIR::ImplId>();
|
||||
case Parse::NodeKind::SelfValueName:
|
||||
return Id::KindFor<SemIR::NameId>();
|
||||
case Parse::NodeKind::DefaultLibrary:
|
||||
case Parse::NodeKind::LibraryName:
|
||||
return Id::KindFor<SemIR::LibraryNameId>();
|
||||
case Parse::NodeKind::ArrayExprSemi:
|
||||
case Parse::NodeKind::BuiltinName:
|
||||
case Parse::NodeKind::ClassIntroducer:
|
||||
|
||||
Reference in New Issue
Block a user