polserver/pol-core/bscript/compiler/ast/FunctionCall.h
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

49 lines
1.5 KiB
C++

#ifndef POLSERVER_FUNCTIONCALL_H
#define POLSERVER_FUNCTIONCALL_H
#include "bscript/compiler/ast/Expression.h"
#include "bscript/compiler/model/ScopableName.h"
namespace Pol::Bscript::Compiler
{
class Argument;
class FunctionLink;
class ModuleFunctionDeclaration;
class FunctionParameterDeclaration;
class UserFunction;
class FunctionCall : public Expression
{
public:
// A compile-time, statically linked function call
FunctionCall( const SourceLocation&, std::string calling_scope, ScopableName scoped_name,
std::vector<std::unique_ptr<Argument>> arguments );
// A run-time, dynamically executed expression-as-callee function call
FunctionCall( const SourceLocation&, std::string calling_scope, std::unique_ptr<Node> callee,
std::vector<std::unique_ptr<Argument>> arguments );
void accept( NodeVisitor& visitor ) override;
void describe_to( std::string& ) const override;
std::vector<std::unique_ptr<Argument>> take_arguments();
[[nodiscard]] std::vector<std::reference_wrapper<FunctionParameterDeclaration>> parameters()
const;
const std::shared_ptr<FunctionLink> function_link;
// Used in FunctionResolver. If the function does not exist under
// `method_name`, check `calling_scope::method_name` (if calling scope
// exists).
const std::string calling_scope;
// nullptr in expression-as-callees function calls
std::unique_ptr<ScopableName> scoped_name;
// Eg. `foo()` or `Animal::foo()`
std::string string() const;
};
} // namespace Pol::Bscript::Compiler
#endif // POLSERVER_FUNCTIONCALL_H