polserver/pol-core/bscript/compiler/model/FunctionLink.cpp
Kevin Eady e3512d001b 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`
2024-10-10 18:06:04 +02:00

38 lines
981 B
C++

#include "FunctionLink.h"
#include "bscript/compiler/ast/ModuleFunctionDeclaration.h"
#include "bscript/compiler/ast/UserFunction.h"
#include "bscript/compiler/file/SourceLocation.h"
namespace Pol::Bscript::Compiler
{
FunctionLink::FunctionLink( const SourceLocation& source_location, std::string calling_scope )
: source_location( source_location ),
calling_scope( std::move( calling_scope ) ),
linked_function( nullptr )
{
}
Function* FunctionLink::function() const
{
return linked_function;
}
ModuleFunctionDeclaration* FunctionLink::module_function_declaration() const
{
return dynamic_cast<ModuleFunctionDeclaration*>( linked_function );
}
UserFunction* FunctionLink::user_function() const
{
return dynamic_cast<UserFunction*>( linked_function );
}
void FunctionLink::link_to( Function* f )
{
if ( linked_function )
source_location.internal_error( "function already linked" );
linked_function = f;
}
} // namespace Pol::Bscript::Compiler