Add namespace support. (#2940)

This handles namespacing of functions. Parsing and semantics are changed
significantly, while lowering works without changes. Variables can't be
namespaced yet because they're dealing with patterns, and I didn't dig
through that code.

Most of the logic is done through the new name declaration stack, which
is necessary because semantics isn't quite sure where the declaration
name ends. It'd be complex for parsing to send a signal about this,
probably involving node variants and rewrites of the tree, and this
solution seems to work well. Unfortunately this means a new stack, but
that may be inevitable due to the extra information needing to be
tracked.

Note this doesn't deal with scoped lookups of non-namespace things,
which we'll need for generics. That'll probably involve pushing resolved
scopes onto a stack (or maybe just setting a singleton value?) to affect
contextual name lookup. But, I think the basics are there to make it
work when we can test the behavior.

This renames "designator expression" to "qualified expression" and adds
"qualified declaration" in order to use terminology more consistent with
C++.

Namespaces will probably need to be considered for name mangling down
the line, but this still uses the basic name.
This commit is contained in:
Jon Ross-Perkins
2023-07-06 20:43:40 +00:00
committed by GitHub
parent 7d817c857a
commit 918c089e03
63 changed files with 1136 additions and 179 deletions
+2 -2
View File
@@ -13,8 +13,8 @@ auto ParserHandleFunctionIntroducer(ParserContext& context) -> void {
state.state = ParserState::FunctionAfterParameters;
context.PushState(state);
state.state = ParserState::DeclarationNameAndParamsAsRequired;
context.PushState(state);
context.PushState(ParserState::DeclarationNameAndParamsAsRequired,
state.token);
}
auto ParserHandleFunctionAfterParameters(ParserContext& context) -> void {