Skip to content

Commit

Permalink
Fix AST import
Browse files Browse the repository at this point in the history
Use only llvm::SmallVector
  • Loading branch information
fly-lang committed Apr 27, 2024
1 parent fc666b4 commit e96a4ae
Show file tree
Hide file tree
Showing 52 changed files with 201 additions and 288 deletions.
36 changes: 11 additions & 25 deletions include/AST/ASTBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ namespace fly {

friend class SemaBuilder;

const SourceLocation Location;
SourceLocation Location;

llvm::StringRef Comment;

public:

ASTBase(const SourceLocation &Loc);
explicit ASTBase(const SourceLocation &Loc);

const SourceLocation &getLocation() const;
virtual const SourceLocation &getLocation() const;

llvm::StringRef getComment() const;

// TODO virtual std::string print() const = 0;

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

Expand All @@ -55,17 +57,17 @@ namespace fly {

Logger();

Logger(const std::string str);
explicit Logger(std::string str);

std::string End();

Logger &Super(const std::string val);
Logger &Super(std::string val);

Logger &Attr(const char *key, const std::string val);
Logger &Attr(const char *key, std::string val);

Logger &Attr(const char *key, const llvm::StringRef val);
Logger &Attr(const char *key, llvm::StringRef val);

Logger &Attr(const char *key, const SourceLocation &val);
Logger &Attr(const char *key, SourceLocation &val);

Logger &Attr(const char *key, bool val);

Expand All @@ -74,23 +76,7 @@ namespace fly {
Logger &Attr(const char *key, ASTBase *val);

template <typename T>
Logger &AttrList(const char *key, std::vector<T *> Vect) {
std::string Entry = OPEN_LIST;
if(!Vect.empty()) {
for (ASTBase *V : Vect) {
Entry += V->str() + SEP;
}
unsigned long end = Entry.length()-std::string(SEP).length()-1;
Entry = Entry.substr(0, end);
}
Entry += CLOSE_LIST;
Attr(key, Entry);
isEmpty = false;
return *this;
}

template <typename T>
Logger &AttrList(const char *key, llvm::SmallVector<T *, 4> Vect) {
Logger &AttrList(const char *key, llvm::SmallVector<T *, 8> Vect) {
std::string Entry = OPEN_LIST;
if(!Vect.empty()) {
for (ASTBase *V : Vect) {
Expand Down
4 changes: 2 additions & 2 deletions include/AST/ASTBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace fly {
ASTBlockKind BlockKind;

// List of Statements of the Block
std::vector<ASTStmt *> Content;
llvm::SmallVector<ASTStmt *, 8> Content;

// Contains all vars declared in this Block
llvm::StringMap<ASTLocalVar *> LocalVars;
Expand All @@ -78,7 +78,7 @@ namespace fly {

ASTBlockKind getBlockKind() const;

const std::vector<ASTStmt *> &getContent() const;
const llvm::SmallVector<ASTStmt *, 8> &getContent() const;

bool isEmpty() const;

Expand Down
13 changes: 6 additions & 7 deletions include/AST/ASTCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
#ifndef FLY_FUNCTION_CALL_H
#define FLY_FUNCTION_CALL_H

#include "AST/ASTBase.h"
#include "ASTExpr.h"
#include "AST/ASTIdentifier.h"

#include "llvm/ADT/SmallVector.h"

#include <vector>

namespace fly {

class ASTType;
Expand Down Expand Up @@ -51,7 +50,7 @@ namespace fly {

ASTError *ErrorHandler = nullptr;

std::vector<ASTArg *> Args;
llvm::SmallVector<ASTArg *, 8> Args;

ASTFunctionBase *Def = nullptr;

Expand All @@ -61,21 +60,21 @@ namespace fly {

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

ASTCall(ASTFunctionBase *Function);
explicit ASTCall(ASTFunctionBase *Function);

public:

const ASTError *getErrorHandler() const;

const std::vector<ASTArg *> getArgs() const;
llvm::SmallVector<ASTArg *, 8> getArgs() const;

ASTFunctionBase *getDef() const;

ASTCallKind getCallKind() const;

ASTMemoryKind getMemoryKind() const;

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

class ASTArg : public ASTBase {
Expand Down Expand Up @@ -103,7 +102,7 @@ namespace fly {

ASTCall *getCall() const;

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

};
}
Expand Down
4 changes: 2 additions & 2 deletions include/AST/ASTClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ namespace fly {

void setCodeGen(CodeGenClass *CGC);

std::string print() const;
std::string print() const override;

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

};
}
Expand Down
2 changes: 1 addition & 1 deletion include/AST/ASTClassType.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace fly {

ASTClassType(ASTIdentifier *Identifier);

ASTClassType(ASTClass *Class);
explicit ASTClassType(ASTClass *Class);

public:

Expand Down
14 changes: 7 additions & 7 deletions include/AST/ASTIdentityType.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ namespace fly {

ASTIdentityTypeKind IdentityKind;

ASTIdentityType(ASTIdentifier *Identifier);
explicit ASTIdentityType(ASTIdentifier *Identifier);

ASTIdentityType(ASTIdentifier *Identifier, ASTIdentityTypeKind IdentityKind);

ASTIdentityType(ASTIdentity *Def);
explicit ASTIdentityType(ASTIdentity *Def);

public:

virtual ASTIdentity *getDef() const;

const SourceLocation &getLocation() const ;
const SourceLocation &getLocation() const;

ASTIdentityTypeKind getIdentityKind() const;

bool operator ==(const ASTIdentityType &IdentityType) const;

const bool isNone() const;
bool isNone() const;

const bool isClass() const;
bool isClass() const;

const bool isEnum() const;
bool isEnum() const;

const std::string print() const override;
std::string print() const override;

std::string str() const override;
};
Expand Down
10 changes: 5 additions & 5 deletions include/AST/ASTIfBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace fly {
ASTExpr *Condition = nullptr;

// The list of Elseif Blocks
std::vector<ASTElsifBlock *> ElsifBlocks;
llvm::SmallVector<ASTElsifBlock *, 8> ElsifBlocks;

// The Else Block
ASTElseBlock *ElseBlock = nullptr;
Expand All @@ -43,11 +43,11 @@ namespace fly {

ASTExpr *getCondition();

std::vector<ASTElsifBlock *> getElsifBlocks();
llvm::SmallVector<ASTElsifBlock *, 8> getElsifBlocks();

ASTElseBlock *getElseBlock();

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

class ASTElsifBlock : public ASTBlock {
Expand All @@ -67,7 +67,7 @@ namespace fly {

ASTExpr *getCondition();

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

class ASTElseBlock : public ASTBlock {
Expand All @@ -80,7 +80,7 @@ namespace fly {

ASTElseBlock(ASTIfBlock *IfBlock, const SourceLocation &Loc);

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

Expand Down
9 changes: 5 additions & 4 deletions include/AST/ASTParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace fly {
friend class SemaBuilder;
friend class SemaResolver;

ASTValue *DefaultValue;
ASTValue *DefaultValue = nullptr;

ASTParam(const SourceLocation &Loc, ASTType *Type, llvm::StringRef Name, ASTScopes *Scopes);

Expand All @@ -49,17 +49,18 @@ namespace fly {

friend class ASTFunctionBase;

std::vector<ASTParam *> List;
llvm::SmallVector<ASTParam *, 8> List;

ASTParam* Ellipsis = nullptr;

public:
uint64_t getSize() const;

ASTParam *at(unsigned long Index) const;

const bool isEmpty() const;
bool isEmpty() const;

const std::vector<ASTParam *> &getList() const;
const llvm::SmallVector<ASTParam *, 8> &getList() const;

const ASTParam* getEllipsis() const;

Expand Down
4 changes: 2 additions & 2 deletions include/AST/ASTSwitchBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace fly {
ASTExpr *Expr = nullptr;

// The Case Blocks
std::vector<ASTSwitchCaseBlock *> Cases;
llvm::SmallVector<ASTSwitchCaseBlock *, 8> Cases;

// The Default Block
ASTSwitchDefaultBlock *Default = nullptr;
Expand All @@ -41,7 +41,7 @@ namespace fly {

ASTExpr *getExpr() const;

std::vector<ASTSwitchCaseBlock *> &getCases();
llvm::SmallVector<ASTSwitchCaseBlock *, 8> &getCases();

ASTSwitchDefaultBlock *getDefault();

Expand Down
Loading

0 comments on commit e96a4ae

Please sign in to comment.