Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from stryku/42-implement-for-loop
Implemented for loop
- Loading branch information
Showing
25 changed files
with
1,171 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include "ast/for_node.hpp" | ||
#include "ast/ast_node_visitor.hpp" | ||
#include "ast/block_node.hpp" | ||
|
||
namespace cmsl::ast { | ||
for_node::for_node(ast_node::token_t for_kw, ast_node::token_t open_paren, | ||
std::unique_ptr<ast_node> init, | ||
ast_node::token_t init_semicolon, | ||
std::unique_ptr<ast_node> condition, | ||
ast_node::token_t condition_semicolon, | ||
std::unique_ptr<ast_node> iteration, | ||
ast_node::token_t close_paren, | ||
std::unique_ptr<block_node> body) | ||
: m_for_kw{ for_kw } | ||
, m_open_paren{ open_paren } | ||
, m_init{ std::move(init) } | ||
, m_init_semicolon{ init_semicolon } | ||
, m_condition{ std::move(condition) } | ||
, m_condition_semicolon{ condition_semicolon } | ||
, m_iteration{ std::move(iteration) } | ||
, m_close_paren{ close_paren } | ||
, m_body{ std::move(body) } | ||
{ | ||
} | ||
|
||
for_node::~for_node() = default; | ||
|
||
ast_node::token_t for_node::for_kw() const | ||
{ | ||
return m_for_kw; | ||
} | ||
|
||
ast_node::token_t for_node::open_paren() const | ||
{ | ||
return m_open_paren; | ||
} | ||
|
||
const ast_node* for_node::init() const | ||
{ | ||
return m_init.get(); | ||
} | ||
|
||
ast_node::token_t for_node::init_semicolon() const | ||
{ | ||
return m_init_semicolon; | ||
} | ||
|
||
const ast_node* for_node::condition() const | ||
{ | ||
return m_condition.get(); | ||
} | ||
|
||
ast_node::token_t for_node::condition_semicolon() const | ||
{ | ||
return m_condition_semicolon; | ||
} | ||
|
||
const ast_node* for_node::iteration() const | ||
{ | ||
return m_iteration.get(); | ||
} | ||
|
||
ast_node::token_t for_node::close_paren() const | ||
{ | ||
return m_close_paren; | ||
} | ||
|
||
const block_node& for_node::body() const | ||
{ | ||
return *m_body; | ||
} | ||
|
||
void for_node::visit(ast_node_visitor& visitor) const | ||
{ | ||
visitor.visit(*this); | ||
} | ||
|
||
source_location for_node::begin_location() const | ||
{ | ||
return m_for_kw.src_range().begin; | ||
} | ||
|
||
source_location for_node::end_location() const | ||
{ | ||
return m_body->end_location(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include "ast/ast_node.hpp" | ||
|
||
#include <memory> | ||
|
||
namespace cmsl::ast { | ||
|
||
class block_node; | ||
|
||
class for_node : public ast_node | ||
{ | ||
public: | ||
explicit for_node(token_t for_kw, token_t open_paren, | ||
std::unique_ptr<ast_node> init, token_t init_semicolon, | ||
std::unique_ptr<ast_node> condition, | ||
token_t condition_semicolon, | ||
std::unique_ptr<ast_node> iteration, | ||
ast_node::token_t close_paren, | ||
std::unique_ptr<block_node> body); | ||
~for_node(); | ||
|
||
token_t for_kw() const; | ||
token_t open_paren() const; | ||
const ast_node* init() const; | ||
token_t init_semicolon() const; | ||
const ast_node* condition() const; | ||
token_t condition_semicolon() const; | ||
const ast_node* iteration() const; | ||
token_t close_paren() const; | ||
const block_node& body() const; | ||
|
||
void visit(ast_node_visitor& visitor) const override; | ||
source_location begin_location() const override; | ||
source_location end_location() const override; | ||
|
||
private: | ||
token_t m_for_kw; | ||
token_t m_open_paren; | ||
std::unique_ptr<ast_node> m_init; | ||
token_t m_init_semicolon; | ||
std::unique_ptr<ast_node> m_condition; | ||
token_t m_condition_semicolon; | ||
std::unique_ptr<ast_node> m_iteration; | ||
token_t m_close_paren; | ||
std::unique_ptr<block_node> m_body; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.