mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 14:01:05 +01:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user