Fix function return source position with implicit return

This commit is contained in:
drmortalwombat 2023-05-28 16:12:12 +02:00
parent d6faefb5fc
commit 9175257bbc
4 changed files with 5 additions and 3 deletions

View File

@ -92,7 +92,7 @@ void DeclarationScope::End(const Location& loc)
}
Expression::Expression(const Location& loc, ExpressionType type)
: mLocation(loc), mType(type), mLeft(nullptr), mRight(nullptr), mConst(false)
: mLocation(loc), mEndLocation(loc), mType(type), mLeft(nullptr), mRight(nullptr), mConst(false)
{
}

View File

@ -163,7 +163,7 @@ public:
Expression(const Location& loc, ExpressionType type);
~Expression(void);
Location mLocation;
Location mLocation, mEndLocation;
ExpressionType mType;
Expression * mLeft, * mRight;
Token mToken;

View File

@ -3798,7 +3798,7 @@ InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod
else
mErrors->Error(dec->mLocation, EERR_UNDEFINED_OBJECT, "Calling undefined function", dec->mIdent->mString);
InterInstruction * ins = new InterInstruction(exp ? exp->mLocation : dec->mLocation, IC_RETURN);
InterInstruction * ins = new InterInstruction(exp ? exp->mEndLocation : dec->mLocation, IC_RETURN);
exitBlock->Append(ins);
exitBlock->Close(nullptr, nullptr);

View File

@ -2185,12 +2185,14 @@ Expression* Parser::ParseStatement(void)
if (mScanner->mToken != TK_CLOSE_BRACE)
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected");
exp->mEndLocation = mScanner->mLocation;
mScope->End(mScanner->mLocation);
mScanner->NextToken();
}
else
{
exp = new Expression(mScanner->mLocation, EX_VOID);
exp->mEndLocation = mScanner->mLocation;
mScanner->NextToken();
}