Default return statement for function declaration
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "StatementFunction.h"
|
#include "StatementFunction.h"
|
||||||
|
|
||||||
#include "Parser/Statement/StatementBlock.h"
|
#include "Parser/Statement/StatementBlock.h"
|
||||||
|
#include "Parser/Statement/StatementReturn.h"
|
||||||
|
|
||||||
static string valueTypeToString(ValueType valueType) {
|
static string valueTypeToString(ValueType valueType) {
|
||||||
switch (valueType) {
|
switch (valueType) {
|
||||||
@@ -16,7 +17,16 @@ static string valueTypeToString(ValueType valueType) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StatementFunction::StatementFunction(string name, vector<pair<string, ValueType>> arguments, ValueType returnValueType, shared_ptr<StatementBlock> statementBlock):
|
StatementFunction::StatementFunction(string name, vector<pair<string, ValueType>> arguments, ValueType returnValueType, shared_ptr<StatementBlock> statementBlock):
|
||||||
Statement(StatementKind::FUNCTION), name(name), arguments(arguments), returnValueType(returnValueType), statementBlock(statementBlock) { }
|
Statement(StatementKind::FUNCTION), name(name), arguments(arguments), returnValueType(returnValueType), statementBlock(statementBlock) {
|
||||||
|
vector<shared_ptr<Statement>> statements = statementBlock->getStatements();
|
||||||
|
if (!statements.empty() && statements.back()->getKind() == StatementKind::RETURN)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// add an emty return statement if none is present
|
||||||
|
shared_ptr<StatementReturn> statementReturn = make_shared<StatementReturn>(nullptr);
|
||||||
|
statements.push_back(statementReturn);
|
||||||
|
this->statementBlock = make_shared<StatementBlock>(statements);
|
||||||
|
}
|
||||||
|
|
||||||
string StatementFunction::getName() {
|
string StatementFunction::getName() {
|
||||||
return name;
|
return name;
|
||||||
|
|||||||
Reference in New Issue
Block a user