[AST] Adding indexing operations
This commit is contained in:
@@ -89,11 +89,45 @@ private:
|
|||||||
std::vector<T> values_;
|
std::vector<T> values_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum range_enum_t{
|
||||||
|
ALL,
|
||||||
|
NEWAXIS
|
||||||
|
};
|
||||||
|
|
||||||
|
class range: public node{
|
||||||
|
public:
|
||||||
|
range(range_enum_t type)
|
||||||
|
: type_(type){}
|
||||||
|
|
||||||
|
range_enum_t type() const{
|
||||||
|
return type_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
const range_enum_t type_;
|
||||||
|
};
|
||||||
|
|
||||||
class expression: public node{
|
class expression: public node{
|
||||||
public:
|
public:
|
||||||
virtual llvm::Value* codegen(module *) const = 0;
|
virtual llvm::Value* codegen(module *) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class postfix_expression: public expression{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class indexing_expression: public postfix_expression{
|
||||||
|
public:
|
||||||
|
indexing_expression(node *id, node *ranges)
|
||||||
|
: id_((const identifier*)id), ranges_((const list<range*>*)ranges) {}
|
||||||
|
|
||||||
|
llvm::Value* codegen(module *) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const identifier* id_;
|
||||||
|
const list<range*>* ranges_;
|
||||||
|
};
|
||||||
|
|
||||||
class unary_expression: public node{
|
class unary_expression: public node{
|
||||||
public:
|
public:
|
||||||
unary_expression(node *id): id_((const identifier*)id) {}
|
unary_expression(node *id): id_((const identifier*)id) {}
|
||||||
|
@@ -49,7 +49,7 @@ TYPE_T get_type_spec(node *op) { return ((token*)op)->type; }
|
|||||||
%token XOR_ASSIGN OR_ASSIGN TYPE_NAME
|
%token XOR_ASSIGN OR_ASSIGN TYPE_NAME
|
||||||
%token VOID UINT8 UINT16 UINT32 UINT64 INT8 INT16 INT32 INT64 FP32 FP64
|
%token VOID UINT8 UINT16 UINT32 UINT64 INT8 INT16 INT32 INT64 FP32 FP64
|
||||||
%token IF ELSE FOR
|
%token IF ELSE FOR
|
||||||
%token DEF
|
%token NEWAXIS
|
||||||
|
|
||||||
%start translation_unit
|
%start translation_unit
|
||||||
%%
|
%%
|
||||||
@@ -115,8 +115,21 @@ primary_expression
|
|||||||
| '(' expression ')' { $$ = $1; }
|
| '(' expression ')' { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
range
|
||||||
|
: ':' { $$ = new range(tdl::ast::ALL); }
|
||||||
|
| NEWAXIS { $$ = new range(tdl::ast::NEWAXIS); }
|
||||||
|
|
||||||
|
range_list
|
||||||
|
: range { $$ = new list<range*>((range*)$1); }
|
||||||
|
| range_list ',' range { $$ = append_ptr_list<range>($1, $2); }
|
||||||
|
|
||||||
|
postfix_expression
|
||||||
|
: primary_expression { $$ = $1;}
|
||||||
|
| identifier '[' range_list ']' { $$ = new indexing_expression($1, $2);}
|
||||||
|
;
|
||||||
|
|
||||||
unary_expression
|
unary_expression
|
||||||
: primary_expression { $$ = $1; }
|
: postfix_expression { $$ = $1; }
|
||||||
| INC_OP unary_expression { $$ = new unary_operator(INC, $2); }
|
| INC_OP unary_expression { $$ = new unary_operator(INC, $2); }
|
||||||
| DEC_OP unary_expression { $$ = new unary_operator(DEC, $2); }
|
| DEC_OP unary_expression { $$ = new unary_operator(DEC, $2); }
|
||||||
| unary_operator cast_expression { $$ = new unary_operator(get_unary_op($1), $2); }
|
| unary_operator cast_expression { $$ = new unary_operator(get_unary_op($1), $2); }
|
||||||
|
@@ -16,7 +16,7 @@ int comment();
|
|||||||
%}
|
%}
|
||||||
|
|
||||||
%%
|
%%
|
||||||
"def" { count(); return(DEF); }
|
"newaxis" { count(); return(NEWAXIS); }
|
||||||
"if" { count(); return(IF); }
|
"if" { count(); return(IF); }
|
||||||
"else" { count(); return(ELSE); }
|
"else" { count(); return(ELSE); }
|
||||||
"for" { count(); return(FOR); }
|
"for" { count(); return(FOR); }
|
||||||
|
@@ -482,6 +482,11 @@ Value* binary_operator::codegen(module *mod) const{
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Postfix expression */
|
||||||
|
Value* indexing_expression::codegen(module *mod) const{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
/* Unary operator */
|
/* Unary operator */
|
||||||
Value *unary_operator::llvm_op(llvm::IRBuilder<> &builder, Value *arg, const std::string &name) const{
|
Value *unary_operator::llvm_op(llvm::IRBuilder<> &builder, Value *arg, const std::string &name) const{
|
||||||
Type *atype = arg->getType();
|
Type *atype = arg->getType();
|
||||||
|
Reference in New Issue
Block a user