Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

first swath of naming utility refactoring. #837

Merged
merged 3 commits into from
Mar 15, 2024

Conversation

stephen-hawley
Copy link
Contributor

Naming of various things in BTfS is spread all over the place. I'm trying to centralize it so it's easier to refactor.

This is step 1 of n - and in this case I've created a new class for creating unique names which also includes the ability to abide by scoping. This code is not used...yet. The general approach for this is to use a stack of hash sets. When you enter a new scope the top-most hashset is used to populate the new scope. Here's the thinking on that: The contents of the hash sets will be relatively small: on the order of 10 items (ie, no fewer than 1 and no more than 100, but typically 6-8). Scopes will typically be exited and entered on function boundaries and I don't anticipate having to create new ones for control structures as these tend to nest very linearly. Checking for existing symbols should be cheaper than it was before and since that is the most common operation, I felt this was better than walking the stack of scopes, but PRs are welcome if you disagree.

The general philosophy here is to use static methods when things are stateless and classes when things require state.

I've also moved SanitizeIdentifier and related code from TypeMapper and CleanseOperatorName from MethodWrapping and put them into CSSafeNaming.

public void ExitScope ()
{
if (names.Count == 0)
throw new Exception ("exited top level scope - that's bad");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this visible to the customer? If it is, it should be more informative

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By being public, it is, in theory, visible to the customer but in practice it will only be used by BTfS (or its descendants).
So yeah, everything could be internal, but it makes testing harder.

@stephen-hawley stephen-hawley merged commit fa2051d into main Mar 15, 2024
@stephen-hawley stephen-hawley deleted the alternative-binding-approach branch March 15, 2024 14:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants