Add scope handling for functions and variables (#690)

* Add Report.debug

* Implement function call scoping

* Implement variable scoping
- Rename `Identifier::scope` to `calling_scope`, and concatenate the identifier scope into `name` if necessary.
- Track current scope in SemanticAnalyzer, similar to UserFunctionVisitor.
- Use current scope in SemanticAnalyzer when visiting identifiers.

* Update grammar for `::identifier` global scoping

* Introduce ScopableName for function resolution

* Address review comments
- Check for display_debugs missing

* Add ScopableName for identifier resolution

* Some cleanup
- Remove `Identifier::calling_scope`, as it is tracked in the semantic
  analyzer
- Refactor `ScopeName::exists` to `global` for better clarification of
  its use
- Removed `X::maybe_scoped_string/name`

* Address self-review comments

* Rename `Function::module_name` to `scope`
This commit is contained in:
Kevin Eady 2024-08-11 23:01:38 +02:00
parent 4ae9519343
commit e3512d001b
71 changed files with 1669 additions and 963 deletions

View file

@ -12,8 +12,8 @@ namespace Pol::Bscript::Compiler
ModuleFunctionDeclaration::ModuleFunctionDeclaration(
const SourceLocation& source_location, std::string module_name, std::string name,
std::unique_ptr<FunctionParameterList> parameter_list )
: Function( source_location, std::move( name ), std::move( parameter_list ) ),
module_name( std::move( module_name ) )
: Function( source_location, std::move( module_name ), std::move( name ),
std::move( parameter_list ) )
{
}
@ -24,8 +24,7 @@ void ModuleFunctionDeclaration::accept( NodeVisitor& visitor )
void ModuleFunctionDeclaration::describe_to( std::string& w ) const
{
fmt::format_to( std::back_inserter( w ), "module-function-declaration({}::{})", module_name,
name );
fmt::format_to( std::back_inserter( w ), "module-function-declaration({}::{})", scope, name );
}
} // namespace Pol::Bscript::Compiler