aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/CodeGen.cc16
-rw-r--r--lib/Parser/ParserFile.cc8
2 files changed, 17 insertions, 7 deletions
diff --git a/lib/CodeGen/CodeGen.cc b/lib/CodeGen/CodeGen.cc
index 0e372d0..fbf807b 100644
--- a/lib/CodeGen/CodeGen.cc
+++ b/lib/CodeGen/CodeGen.cc
@@ -1017,21 +1017,23 @@ void CodeGen::emitStmt(StmtAST *Stmt) {
if (auto *Ret = dynamic_cast<ReturnStmtAST*>(Stmt)) {
Function *F = Builder->GetInsertBlock()->getParent();
const FuncSig *Sig = FuncGen->getSignature(F->getName().str());
- if (Sig && Sig->ReturnTypeName == "VOID" && Ret->getRetVal()) {
+ // Pseudocode cannot name a function "main" (reserved runtime symbol),
+ // so no signature means we are emitting the top level.
+ if (!Sig) {
+ reportError("RETURN is only allowed inside a FUNCTION or PROCEDURE");
+ return;
+ }
+ if (Sig->ReturnTypeName == "VOID" && Ret->getRetVal()) {
reportError("RETURN with a value is only allowed in a FUNCTION");
return;
}
- if (Sig && Sig->ReturnTypeName != "VOID" && !Ret->getRetVal()) {
+ if (Sig->ReturnTypeName != "VOID" && !Ret->getRetVal()) {
reportError("RETURN in a FUNCTION requires a value");
return;
}
Value *RetVal = nullptr;
if (Ret->getRetVal()) {
- if (Sig) {
- RetVal = emitCoercedExpr(Ret->getRetVal(), resolveType(Sig->ReturnTypeName));
- } else {
- RetVal = emitExpr(Ret->getRetVal());
- }
+ RetVal = emitCoercedExpr(Ret->getRetVal(), resolveType(Sig->ReturnTypeName));
if (!RetVal) return;
}
FuncGen->emitReturn(Ret, RetVal);
diff --git a/lib/Parser/ParserFile.cc b/lib/Parser/ParserFile.cc
index 6fd368c..4a4ae31 100644
--- a/lib/Parser/ParserFile.cc
+++ b/lib/Parser/ParserFile.cc
@@ -57,6 +57,14 @@ std::unique_ptr<StmtAST> Parser::ParseReadFile() {
std::string VarName = Lex.IdentifierStr;
getNextToken(); // eat the variable name
+ if (CurTok == '[' || CurTok == '.' || CurTok == '^') {
+ // Consume the whole designator so it cannot replay as statements.
+ std::vector<DesignatorAccess> Dummy;
+ ParseDesignatorSuffix(Dummy);
+ fprintf(stderr, "Error: READFILE target must be a plain STRING variable at line %d\n", Line);
+ return nullptr;
+ }
+
return std::make_unique<ReadFileStmtAST>(std::move(FileName), VarName, Line);
}