polserver/pol-core/bscript/compiler/ast/Argument.cpp
Kevin Eady 6838c74cb4 Add super() function call for constructors (#694)
* Grammar updates
- Make class parameters required

* Add ClassLink; wip with `super()` calls in ctors

* More AST nodes as ScopableNames
- (function call) Argument
- FunctionParameterDeclaration

* Add support for ambiguity handling

* Add few more tests

* Handle returns in constructors
- Semantic analysis to error on returning a value
- Introduce specific emitter method for returning from constructor
- Various tests

* Refactor super building to pre-semantic analysis

* Adding several tests, some are TODO
- found an issue with function resolver and funcrefs, fix later

* Address self-review comments

* Fix funcref global func references, tests
2024-10-10 18:06:04 +02:00

39 lines
1.1 KiB
C++

#include "Argument.h"
#include "bscript/compiler/ast/Expression.h"
#include "bscript/compiler/ast/NodeVisitor.h"
namespace Pol::Bscript::Compiler
{
Argument::Argument( const SourceLocation& source_location, const ScopableName& identifier,
std::unique_ptr<Expression> expression, bool spread )
: Node( source_location, std::move( expression ) ),
identifier( std::make_unique<ScopableName>( identifier ) ),
spread( spread )
{
}
Argument::Argument( const SourceLocation& source_location, std::unique_ptr<Expression> expression,
bool spread )
: Node( source_location, std::move( expression ) ), identifier( nullptr ), spread( spread )
{
}
void Argument::accept( NodeVisitor& visitor )
{
visitor.visit_argument( *this );
}
void Argument::describe_to( std::string& w ) const
{
fmt::format_to( std::back_inserter( w ), "argument({}{})", spread ? "..." : "",
identifier ? identifier->string() : "" );
}
std::unique_ptr<Expression> Argument::take_expression()
{
return take_child<Expression>( 0 );
}
} // namespace Pol::Bscript::Compiler