Skip to content

Commit

Permalink
Set Handle Error Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fly-lang committed Apr 26, 2024
1 parent 5333184 commit fc666b4
Show file tree
Hide file tree
Showing 42 changed files with 661 additions and 685 deletions.
2 changes: 0 additions & 2 deletions include/AST/ASTBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ namespace fly {

public:

ASTFunctionBase *getTop() const;

ASTBlockKind getBlockKind() const;

const std::vector<ASTStmt *> &getContent() const;
Expand Down
19 changes: 16 additions & 3 deletions include/AST/ASTCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ namespace fly {
class ASTArg;
class ASTCallExpr;
class ASTVar;
class ASTError;

enum class ASTCallKind {
CALL_NORMAL,
CALL_NEW,
CALL_FUNCTION,
CALL_CONSTRUCTOR
};

enum class ASTMemoryKind {
CALL_MANAGED,
CALL_UNIQUE,
CALL_SHARED,
CALL_WEAK
Expand All @@ -44,24 +49,32 @@ namespace fly {
friend class SemaBuilder;
friend class SemaResolver;

ASTError *ErrorHandler = nullptr;

std::vector<ASTArg *> Args;

ASTFunctionBase *Def = nullptr;

ASTCallKind CallKind = ASTCallKind::CALL_NORMAL;
ASTCallKind CallKind = ASTCallKind::CALL_FUNCTION;

ASTMemoryKind MemoryKind = ASTMemoryKind::CALL_MANAGED;

ASTCall(const SourceLocation &Loc, llvm::StringRef Name);

ASTCall(ASTFunctionBase *Function);

public:

const ASTError *getErrorHandler() const;

const std::vector<ASTArg *> getArgs() const;

ASTFunctionBase *getDef() const;

ASTCallKind getCallKind() const;

ASTMemoryKind getMemoryKind() const;

std::string str() const;
};

Expand Down
74 changes: 0 additions & 74 deletions include/AST/ASTError.h

This file was deleted.

14 changes: 1 addition & 13 deletions include/AST/ASTExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace fly {

public:

virtual ASTType *getType() const;
ASTType *getType() const;

ASTExprKind getExprKind() const;

Expand Down Expand Up @@ -160,8 +160,6 @@ namespace fly {

ASTVarRef *getVarRef() const;

ASTType *getType() const override;

std::string str() const override;
};

Expand All @@ -181,8 +179,6 @@ namespace fly {

ASTCall *getCall() const;

ASTType *getType() const override;

std::string str() const override;
};

Expand All @@ -204,8 +200,6 @@ namespace fly {

virtual ASTExprGroupKind getGroupKind();

virtual ASTType *getType() const override = 0;

std::string str() const;
};

Expand Down Expand Up @@ -233,8 +227,6 @@ namespace fly {

const ASTVarRefExpr *getFirst() const;

ASTType *getType() const override;

std::string str() const override;
};

Expand Down Expand Up @@ -268,8 +260,6 @@ namespace fly {

const ASTExpr *getSecond() const;

ASTType *getType() const override;

std::string str() const override;
};

Expand Down Expand Up @@ -301,8 +291,6 @@ namespace fly {

ASTTernaryOperatorKind getOperatorKind() const;

ASTType *getType() const override;

const ASTExpr *getFirst() const;

const ASTExpr *getSecond() const;
Expand Down
7 changes: 7 additions & 0 deletions include/AST/ASTFailStmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
namespace fly {

class ASTVarRef;
class ASTHandleStmt;

class ASTFailStmt : public ASTStmt {

friend class SemaBuilder;

ASTExpr *Expr = nullptr;

ASTHandleStmt *Handle = nullptr;

ASTFailStmt(ASTStmt *Parent, const SourceLocation &Loc);

public:
Expand All @@ -30,6 +33,10 @@ namespace fly {

void setExpr(ASTExpr *);

bool hasHandle();

ASTHandleStmt *getHandle();

std::string str() const override;
};
}
Expand Down
6 changes: 6 additions & 0 deletions include/AST/ASTFunctionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace fly {
// Body is the main BlockStmt
ASTBlock *Body = nullptr;

ASTParam *ErrorHandler = nullptr;

protected:

ASTFunctionBase(const SourceLocation &Loc, ASTFunctionKind Kind, ASTType *ReturnType, llvm::StringRef Name,
Expand All @@ -86,6 +88,10 @@ namespace fly {

const ASTBlock *getBody() const;

void setErrorHandler(ASTParam *ErrorHandler);

ASTParam *getErrorHandler();

virtual CodeGenFunctionBase *getCodeGen() const = 0;

bool isVarArg();
Expand Down
13 changes: 10 additions & 3 deletions include/AST/ASTHandleStmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,35 @@
namespace fly {

class ASTVarRef;
class CodeGenHandle;

class ASTHandleStmt : public ASTStmt {

friend class SemaBuilder;
friend class SemaResolver;

ASTVarRef *ErrorRef = nullptr;
ASTVarRef *ErrorHandlerRef = nullptr;

ASTStmt *Handle = nullptr;

CodeGenHandle * CodeGen = nullptr;

ASTHandleStmt(ASTStmt *Parent, const SourceLocation &Loc);

public:

ASTVarRef *getErrorRef() const;
ASTVarRef *getErrorHandlerRef() const;

void setErrorRef(ASTVarRef *errorRef);
void setErrorHandlerRef(ASTVarRef *errorRef);

ASTStmt *getHandle() const;

void setHandle(ASTStmt *H);

CodeGenHandle *getCodeGen() const;

void setCodeGen(CodeGenHandle *codeGen);

std::string str() const;
};
}
Expand Down
9 changes: 6 additions & 3 deletions include/AST/ASTStmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace fly {

class ASTExpr;
class ASTBlock;
class ASTVar;
class ASTFunctionBase;

class ASTStmt : public ASTBase {
Expand All @@ -44,19 +45,21 @@ namespace fly {

ASTStmtKind Kind;

bool HandleError = false;
ASTVar *ErrorHandler = nullptr;

ASTStmt(ASTStmt *Parent, const SourceLocation &Loc, ASTStmtKind Kind);

public:

virtual ASTStmt *getParent() const;

ASTFunctionBase *getTop() const;

ASTStmtKind getKind() const;

void setHandleError(bool HandleError);
void setErrorHandler(ASTVar *ErrorHandler);

bool isHandlerError();
ASTVar *getErrorHandler();

virtual std::string str() const;
};
Expand Down
2 changes: 0 additions & 2 deletions include/AST/ASTVarRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

#include "AST/ASTIdentifier.h"

#include <string>

namespace fly {

class ASTVar;
Expand Down
57 changes: 57 additions & 0 deletions include/CodeGen/CodeGenError.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//===--------------------------------------------------------------------------------------------------------------===//
// include/CodeGen/CodeGenFail.h - Code Generator of Fail
//
// Part of the Fly Project https://flylang.org
// Under the Apache License v2.0 see LICENSE for details.
// Thank you to LLVM Project https://llvm.org/
//
//===--------------------------------------------------------------------------------------------------------------===//

#ifndef FLY_CODEGEN_ERROR_H
#define FLY_CODEGEN_ERROR_H

#include "CodeGenVarBase.h"
#include "llvm/IR/DerivedTypes.h"

namespace fly {

class CodeGenModule;
class CodeGenFunctionBase;
class ASTExpr;
class ASTVar;

class CodeGenError : public CodeGenVarBase {

CodeGenModule *CGM = nullptr;

ASTVar *Error = nullptr;

llvm::Type *T = nullptr;

llvm::Value *Pointer = nullptr;

public:

CodeGenError(CodeGenModule *CGM, ASTVar *Error);

static llvm::StructType *GenErrorType(CodeGenModule *CGM);

void Init() override;

llvm::Type *getType();

llvm::StoreInst *Store(llvm::Value *Val) override;

llvm::LoadInst *Load() override;

llvm::Value *getValue() override;

llvm::Value *getPointer() override;

ASTVar *getVar() override;

void Store(ASTExpr *Expr);
};
}

#endif //FLY_CODEGEN_ERROR_H
Loading

0 comments on commit fc666b4

Please sign in to comment.