From 9175257bbc9b686ebeffa98344ed19c4ebbc9c5b Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 28 May 2023 16:12:12 +0200 Subject: [PATCH] Fix function return source position with implicit return --- oscar64/Declaration.cpp | 2 +- oscar64/Declaration.h | 2 +- oscar64/InterCodeGenerator.cpp | 2 +- oscar64/Parser.cpp | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 3446b0f..916c75f 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -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) { } diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index b0e7c39..d5f8062 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -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; diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index ea3437b..3d335fb 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -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); diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 64c2aa0..3ee9031 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -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(); }