Permalink
Browse files

fixed strange AST structure (integrated InstStmt to FuncCallExpr)

  • Loading branch information...
1 parent 014511b commit e708ab42ba739618577ca0f37d051890d3868807 @peryaudo committed with peryaudo Dec 27, 2013
View
@@ -8,7 +8,7 @@ else
LIBS = `llvm-config --libs`
endif
-CXXFLAGS = -Wall -coverage
+CXXFLAGS = -Wall -coverage -g
CPPFLAGS =
LDFLAGS = `llvm-config --ldflags`
@@ -47,6 +47,8 @@ test: $(PERYAN_UNIT_TEST_TARGET) $(PERYAN_INTEGRATION_TEST_TARGET)
lcov --remove test/coverage/peryan.info "/usr/*" -o test/coverage/peryan.info --rc lcov_branch_coverage=1
genhtml test/coverage/peryan.info --branch-coverage -o test/coverage/ --rc lcov_branch_coverage=1
+unittest: $(PERYAN_UNIT_TEST_TARGET)
+ $(PERYAN_UNIT_TEST_TARGET)
DEPS = $(addprefix $(DEPDIR)/, $(patsubst %.cc, %.d, $(PERYAN_SRCS))) \
$(addprefix $(DEPDIR)/, $(patsubst %.cc, %.d, $(PERYAN_UNIT_TEST_SRCS)))
@@ -100,4 +102,4 @@ $(PERYAN_INTEGRATION_TEST_TARGET): $(PERYAN_INTEGRATION_TEST_SRCDIR)/tester.pr \
mkdir -p $(TEST_BINDIR)
$(PERYAN_TARGET) --runtime-path $(BINDIR) $< -o $@
-.PHONY: all test clean
+.PHONY: all test unittest clean
View
@@ -35,7 +35,8 @@ struct String *PRStringConstructorCStr(char *cStr)
if (res->str == NULL)
AbortWithErrorMessage("runtime error: failed to allocate memory");
- for (i = 0; (res->str[i] = cStr[i]) != 0; ++i) ;
+ for (i = 0; (res->str[i] = cStr[i]) != 0; ++i)
+ ;
DBG_PRINT(-, PRStringConstructorCStr);
return res;
@@ -99,8 +100,10 @@ struct String *PRStringConcatenate(struct String *lhs, struct String *rhs)
if (res->str == NULL)
AbortWithErrorMessage("runtime error: failed to allocate memory");
- for (i = 0; (res->str[i] = lhs->str[i]) != 0; ++i) ;
- for (i = 0; (res->str[i + lhs->length] = rhs->str[i]) != 0; ++i) ;
+ for (i = 0; (res->str[i] = lhs->str[i]) != 0; ++i)
+ ;
+ for (i = 0; (res->str[i + lhs->length] = rhs->str[i]) != 0; ++i)
+ ;
DBG_PRINT(-, PRStringConcatenate);
return res;
View
@@ -66,7 +66,7 @@ class AST {
virtual ~AST() {};
};
-class Stmt : public AST {
+class Stmt : public virtual AST {
public:
virtual AST::ASTType getASTType() { return STMT; }
@@ -139,7 +139,7 @@ class FuncTypeSpec : public TypeSpec {
};
-class Expr : public AST {
+class Expr : public virtual AST {
public:
virtual AST::ASTType getASTType() { return EXPR; }
@@ -158,7 +158,7 @@ class Identifier : public Expr {
std::string getString() { return token.getString(); }
- Identifier(const Token& token) : Expr(token), typeSpec(NULL), symbol(NULL) {}
+ Identifier(const Token& token) : AST(token), Expr(token), typeSpec(NULL), symbol(NULL) {}
Symbol *symbol;
};
@@ -169,7 +169,7 @@ class BinaryExpr : public Expr {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
Expr *lhs, *rhs;
- BinaryExpr(Expr *lhs, const Token& token, Expr *rhs) : Expr(token), lhs(lhs), rhs(rhs) {}
+ BinaryExpr(Expr *lhs, const Token& token, Expr *rhs) : AST(token), Expr(token), lhs(lhs), rhs(rhs) {}
};
class UnaryExpr : public Expr {
@@ -178,7 +178,7 @@ class UnaryExpr : public Expr {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
Expr *rhs;
- UnaryExpr(const Token& token, Expr *rhs) : Expr(token), rhs(rhs) {}
+ UnaryExpr(const Token& token, Expr *rhs) : AST(token), Expr(token), rhs(rhs) {}
};
class StrLiteralExpr : public Expr {
@@ -187,7 +187,7 @@ class StrLiteralExpr : public Expr {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
std::string str;
- StrLiteralExpr(const Token& token) : Expr(token), str(token.getString()) {}
+ StrLiteralExpr(const Token& token) : AST(token), Expr(token), str(token.getString()) {}
};
class IntLiteralExpr : public Expr {
@@ -196,7 +196,7 @@ class IntLiteralExpr : public Expr {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
int integer;
- IntLiteralExpr(const Token& token) : Expr(token), integer(token.getInteger()) {}
+ IntLiteralExpr(const Token& token) : AST(token), Expr(token), integer(token.getInteger()) {}
};
class FloatLiteralExpr : public Expr {
@@ -205,7 +205,7 @@ class FloatLiteralExpr : public Expr {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
double float_;
- FloatLiteralExpr(const Token& token) : Expr(token), float_(token.getFloat()) {}
+ FloatLiteralExpr(const Token& token) : AST(token), Expr(token), float_(token.getFloat()) {}
};
class CharLiteralExpr : public Expr {
@@ -214,7 +214,7 @@ class CharLiteralExpr : public Expr {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
char char_;
- CharLiteralExpr(const Token& token) : Expr(token), char_(token.getChar()) {}
+ CharLiteralExpr(const Token& token) : AST(token), Expr(token), char_(token.getChar()) {}
};
class BoolLiteralExpr : public Expr {
@@ -223,7 +223,7 @@ class BoolLiteralExpr : public Expr {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
bool bool_;
- BoolLiteralExpr(const Token& token) : Expr(token), bool_(token.getType() == Token::KW_TRUE) {}
+ BoolLiteralExpr(const Token& token) : AST(token), Expr(token), bool_(token.getType() == Token::KW_TRUE) {}
};
class ArrayLiteralExpr : public Expr {
@@ -233,19 +233,20 @@ class ArrayLiteralExpr : public Expr {
std::vector<Expr *> elements;
- ArrayLiteralExpr(const Token& token) : Expr(token) {}
+ ArrayLiteralExpr(const Token& token) : AST(token), Expr(token) {}
};
-class FuncCallExpr : public Expr {
+class FuncCallExpr : public Expr, public Stmt {
public:
virtual AST::ASTType getASTType() { return FUNC_CALL_EXPR; }
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
Expr *func;
std::vector<Expr *> params;
- FuncCallExpr(const Token& token, Expr *func) : Expr(token), func(func), partial(false) {}
+ FuncCallExpr(const Token& token, Expr *func, bool isInst = false) : AST(token), Expr(token), Stmt(token), func(func), partial(false), isInst(isInst) {}
bool partial;
+ bool isInst;
};
class ConstructorExpr : public Expr {
@@ -255,7 +256,7 @@ class ConstructorExpr : public Expr {
TypeSpec *constructor;
std::vector<Expr *> params;
- ConstructorExpr(const Token& token, TypeSpec *constructor) : Expr(token), constructor(constructor) {}
+ ConstructorExpr(const Token& token, TypeSpec *constructor) : AST(token), Expr(token), constructor(constructor) {}
};
class RefExpr : public Expr {
@@ -264,7 +265,7 @@ class RefExpr : public Expr {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
Expr *refered;
- RefExpr(Expr *refered) : Expr(refered->token), refered(refered) {}
+ RefExpr(Expr *refered) : AST(token), Expr(refered->token), refered(refered) {}
};
class DerefExpr : public Expr {
@@ -273,7 +274,7 @@ class DerefExpr : public Expr {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
Expr *derefered;
- DerefExpr(Expr *derefered) : Expr(derefered->token), derefered(derefered) {}
+ DerefExpr(Expr *derefered) : AST(token), Expr(derefered->token), derefered(derefered) {}
};
class SubscrExpr : public Expr {
@@ -285,7 +286,7 @@ class SubscrExpr : public Expr {
Expr *subscript;
SubscrExpr(Expr *array, const Token& token, Expr *subscript)
- : Expr(token), array(array), subscript(subscript) {}
+ : AST(token), Expr(token), array(array), subscript(subscript) {}
};
class MemberExpr : public Expr {
@@ -296,7 +297,7 @@ class MemberExpr : public Expr {
Expr *receiver;
Identifier *member;
MemberExpr(Expr *receiver, const Token& token, Identifier *member)
- : Expr(token), receiver(receiver), member(member) {}
+ : AST(token), Expr(token), receiver(receiver), member(member) {}
};
class StaticMemberExpr : public Expr {
@@ -307,7 +308,7 @@ class StaticMemberExpr : public Expr {
TypeSpec *receiver;
Identifier *member;
StaticMemberExpr(TypeSpec *receiver, const Token& token, Identifier *member)
- : Expr(token), receiver(receiver), member(member) {}
+ : AST(token), Expr(token), receiver(receiver), member(member) {}
};
class CompStmt : public Stmt {
@@ -316,7 +317,7 @@ class CompStmt : public Stmt {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
std::vector<Stmt *> stmts;
- CompStmt(const Token& token) : Stmt(token) {}
+ CompStmt(const Token& token) : AST(token), Stmt(token) {}
LocalScope *scope;
};
@@ -329,7 +330,7 @@ class FuncExpr : public Expr {
std::vector<Identifier *> params;
TypeSpec *retTypeSpec;
CompStmt *body;
- FuncExpr(const Token& token, CompStmt *body) : Expr(token), body(body) {}
+ FuncExpr(const Token& token, CompStmt *body) : AST(token), Expr(token), body(body) {}
};
class FuncDefStmt : public Stmt {
@@ -342,7 +343,7 @@ class FuncDefStmt : public Stmt {
TypeSpec *retTypeSpec;
CompStmt *body;
FuncDefStmt(const Token& token, Identifier *name, CompStmt *body)
- : Stmt(token), name(name), body(body), symbol(NULL) {}
+ : AST(token), Stmt(token), name(name), body(body), symbol(NULL) {}
std::vector<Expr *> defaults;
@@ -357,22 +358,11 @@ class VarDefStmt : public Stmt {
Identifier *id;
Expr *init;
VarDefStmt(const Token& token, Identifier *id, Expr *init)
- : Stmt(token), id(id), init(init), symbol(NULL) {}
+ : AST(token), Stmt(token), id(id), init(init), symbol(NULL) {}
VarSymbol *symbol;
};
-class InstStmt : public Stmt {
-public:
- virtual AST::ASTType getASTType() { return INST_STMT; }
- virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
-
- Expr *inst;
- std::vector<Expr *> params;
- InstStmt(const Token& token, Expr *inst) : Stmt(token), inst(inst) {}
-};
-
-
class AssignStmt : public Stmt {
public:
virtual AST::ASTType getASTType() { return ASSIGN_STMT; }
@@ -381,7 +371,7 @@ class AssignStmt : public Stmt {
Expr *lhs;
Expr *rhs;
AssignStmt(Expr *lhs, const Token& token, Expr *rhs)
- : Stmt(token), lhs(lhs), rhs(rhs) {}
+ : AST(token), Stmt(token), lhs(lhs), rhs(rhs) {}
};
class IfStmt : public Stmt {
@@ -393,7 +383,7 @@ class IfStmt : public Stmt {
std::vector<CompStmt *> ifThen;
CompStmt *elseThen;
IfStmt(const Token& token, std::vector<Expr *> ifCond, std::vector<CompStmt *> ifThen, CompStmt *elseThen)
- : Stmt(token), ifCond(ifCond), ifThen(ifThen), elseThen(elseThen) {}
+ : AST(token), Stmt(token), ifCond(ifCond), ifThen(ifThen), elseThen(elseThen) {}
};
class RepeatStmt : public Stmt {
@@ -404,7 +394,7 @@ class RepeatStmt : public Stmt {
Expr *count;
std::vector<Stmt *> stmts;
RepeatStmt(const Token& token, Expr *count)
- : Stmt(token), count(count), scope(NULL) {}
+ : AST(token), Stmt(token), count(count), scope(NULL) {}
LocalScope *scope;
};
@@ -414,7 +404,7 @@ class Label : public Expr {
virtual AST::ASTType getASTType() { return LABEL; }
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
- Label(const Token& token) : Expr(token), symbol(NULL) {}
+ Label(const Token& token) : AST(token), Expr(token), symbol(NULL) {}
LabelSymbol *symbol;
};
@@ -425,7 +415,7 @@ class LabelStmt : public Stmt {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
Label *label;
- LabelStmt(const Token& token, Label *label) : Stmt(token), label(label) {}
+ LabelStmt(const Token& token, Label *label) : AST(token), Stmt(token), label(label) {}
};
@@ -435,7 +425,7 @@ class GotoStmt : public Stmt {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
Label *to;
- GotoStmt(const Token& token, Label *to) : Stmt(token), to(to) {}
+ GotoStmt(const Token& token, Label *to) : AST(token), Stmt(token), to(to) {}
};
class GosubStmt : public Stmt {
@@ -444,23 +434,23 @@ class GosubStmt : public Stmt {
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
Label *to;
- GosubStmt(const Token& token, Label *to) : Stmt(token), to(to) {}
+ GosubStmt(const Token& token, Label *to) : AST(token), Stmt(token), to(to) {}
};
class ContinueStmt : public Stmt {
public:
virtual AST::ASTType getASTType() { return CONTINUE_STMT; }
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
- ContinueStmt(const Token& token) : Stmt(token) {}
+ ContinueStmt(const Token& token) : AST(token), Stmt(token) {}
};
class BreakStmt : public Stmt {
public:
virtual AST::ASTType getASTType() { return BREAK_STMT; }
virtual void accept(ASTVisitor *visitor) { return visitor->visit(this); }
- BreakStmt(const Token& token) : Stmt(token) {}
+ BreakStmt(const Token& token) : AST(token), Stmt(token) {}
};
class ReturnStmt : public Stmt {
@@ -471,7 +461,7 @@ class ReturnStmt : public Stmt {
Expr *expr;
ReturnStmt(const Token& token, Expr *expr)
- : Stmt(token), expr(expr) {}
+ : AST(token), Stmt(token), expr(expr) {}
};
class ExternStmt : public Stmt {
@@ -482,7 +472,7 @@ class ExternStmt : public Stmt {
Identifier *id;
ExternStmt(const Token& token, Identifier *id)
- : Stmt(token), id(id), symbol(NULL) {}
+ : AST(token), Stmt(token), id(id), symbol(NULL) {}
std::vector<Expr *> defaults;
@@ -497,7 +487,7 @@ class NamespaceStmt : public Stmt {
TypeSpec *name;
NamespaceStmt(const Token& token, TypeSpec *name)
- : Stmt(token), name(name), symbol(NULL) {}
+ : AST(token), Stmt(token), name(name), symbol(NULL) {}
std::vector<Stmt *> stmts;
View
@@ -126,18 +126,6 @@ class ASTPrinter : public ASTVisitor {
return;
}
- virtual void visit(InstStmt *is) {
- inc();
- ss_<<"(InstStmt ";
- is->inst->accept(this);
- for (std::vector<Expr *>::iterator it = is->params.begin(); it != is->params.end(); ++it) {
- ind(); (*it)->accept(this);
- }
- ss_<<")";
- dec();
- return;
- }
-
virtual void visit(AssignStmt *as) {
inc();
ss_<<"(AssignStmt "<<as->token.toString();
Oops, something went wrong.

0 comments on commit e708ab4

Please sign in to comment.