Handle semantic name lookup for function parameters. (#2839)

I'm adding a separate function for this instead of adding a bool to AddToNameLookup because this way I don't need to pass in a parse node.
This commit is contained in:
Jon Ross-Perkins
2023-05-23 10:47:27 -07:00
committed by GitHub
parent 98105a23b4
commit bd4e22001f
5 changed files with 54 additions and 30 deletions
+11 -4
View File
@@ -68,10 +68,7 @@ auto SemanticsContext::AddNodeAndPush(ParseTree::Node parse_node,
auto SemanticsContext::AddNameToLookup(ParseTree::Node name_node,
SemanticsStringId name_id,
SemanticsNodeId target_id) -> void {
auto [it, inserted] = current_scope().names.insert(name_id);
if (inserted) {
name_lookup_[name_id].push_back(target_id);
} else {
if (!AddNameToLookupImpl(name_id, target_id)) {
CARBON_DIAGNOSTIC(NameRedefined, Error, "Redefining {0} in the same scope.",
llvm::StringRef);
CARBON_DIAGNOSTIC(PreviousDefinition, Note, "Previous definition is here.");
@@ -84,6 +81,16 @@ auto SemanticsContext::AddNameToLookup(ParseTree::Node name_node,
}
}
auto SemanticsContext::AddNameToLookupImpl(SemanticsStringId name_id,
SemanticsNodeId target_id) -> bool {
if (current_scope().names.insert(name_id).second) {
name_lookup_[name_id].push_back(target_id);
return true;
} else {
return false;
}
}
auto SemanticsContext::BindName(ParseTree::Node name_node,
SemanticsNodeId type_id,
SemanticsNodeId target_id)