Skip to content

Commit

Permalink
Merge pull request #264 from andrey-terekhov/feature
Browse files Browse the repository at this point in the history
К новому релизу
  • Loading branch information
IvanArkhipov1999 authored Jan 27, 2022
2 parents 914e61a + 7f84b9d commit e4db015
Show file tree
Hide file tree
Showing 347 changed files with 1,856 additions and 2,009 deletions.
71 changes: 22 additions & 49 deletions libs/compiler/AST.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ node expression_null_literal(node *const context, const item_t type, const locat
}


node expression_boolean_literal(node *const context, const item_t type, const bool value, const location loc)
{
node nd = node_create(context, OP_LITERAL);

node_add_arg(&nd, type); // Тип значения выражения
node_add_arg(&nd, RVALUE); // Категория значения выражения
node_add_arg(&nd, value ? 1 : 0); // Значение литерала
node_add_arg(&nd, (item_t)loc.begin); // Начальная позиция выражения
node_add_arg(&nd, (item_t)loc.end); // Конечная позиция выражения

return nd;
}

bool expression_literal_get_boolean(const node *const nd)
{
assert(node_get_type(nd) == OP_LITERAL);
return node_get_arg(nd, 2) != 0;
}


node expression_character_literal(node *const context, const item_t type, const char32_t value, const location loc)
{
node nd = node_create(context, OP_LITERAL);
Expand Down Expand Up @@ -485,8 +505,6 @@ statement_t statement_get_class(const node *const nd)
{
case OP_DECLSTMT:
return STMT_DECL;
case OP_LABEL:
return STMT_LABEL;
case OP_CASE:
return STMT_CASE;
case OP_DEFAULT:
Expand All @@ -505,8 +523,6 @@ statement_t statement_get_class(const node *const nd)
return STMT_DO;
case OP_FOR:
return STMT_FOR;
case OP_GOTO:
return STMT_GOTO;
case OP_CONTINUE:
return STMT_CONTINUE;
case OP_BREAK:
Expand All @@ -519,30 +535,6 @@ statement_t statement_get_class(const node *const nd)
}


node statement_labeled(const size_t label, node *const substmt, const location loc)
{
node nd = node_insert(substmt, OP_LABEL, 3);

node_set_arg(&nd, 0, (item_t)label); // ID метки
node_set_arg(&nd, 1, (item_t)loc.begin); // Начальная позиция оператора
node_set_arg(&nd, 2, (item_t)loc.end); // Конечная позиция оператора

return nd;
}

size_t statement_labeled_get_label(const node *const nd)
{
assert(node_get_type(nd) == OP_LABEL);
return (size_t)node_get_arg(nd, 0);
}

node statement_labeled_get_substmt(const node *const nd)
{
assert(node_get_type(nd) == OP_LABEL);
return node_get_child(nd, 0);
}


node statement_case(node *const expr, node *const substmt, const location loc)
{
node nd = node_insert(expr, OP_CASE, 2);
Expand Down Expand Up @@ -821,24 +813,6 @@ node statement_for_get_body(const node *const nd)
}


node statement_goto(node *const context, const size_t label, const location loc)
{
node nd = node_create(context, OP_GOTO);

node_add_arg(&nd, (item_t)label); // ID метки
node_add_arg(&nd, (item_t)loc.begin); // Начальная позиция оператора
node_add_arg(&nd, (item_t)loc.end); // Конечная позиция оператора

return nd;
}

size_t statement_goto_get_label(const node *const nd)
{
assert(node_get_type(nd) == OP_GOTO);
return (size_t)llabs(node_get_arg(nd, 0));
}


node statement_continue(node *const context, const location loc)
{
node nd = node_create(context, OP_CONTINUE);
Expand Down Expand Up @@ -868,7 +842,7 @@ node statement_return(node *const context, node *const expr, const location loc)
node_add_arg(&nd, 0); // Содержит ли выражение
node_add_arg(&nd, (item_t)loc.begin); // Начальная позиция оператора
node_add_arg(&nd, (item_t)loc.end); // Конечная позиция оператора

if (node_is_correct(expr))
{
node_set_arg(&nd, 0, 1);
Expand Down Expand Up @@ -916,8 +890,7 @@ declaration_t declaration_get_class(const node *const nd)
case OP_FUNC_DEF:
return DECL_FUNC;
default:
system_error(node_unexpected);
return 0;
return DECL_INVALID;
}
}

Expand Down
76 changes: 23 additions & 53 deletions libs/compiler/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ typedef enum EXPRESSION
typedef enum STATEMENT
{
STMT_DECL, /**< Declaration statement */
STMT_LABEL, /**< Labeled statement */
STMT_CASE, /**< Case statement */
STMT_DEFAULT, /**< Default statement */
STMT_COMPOUND, /**< Compound statement */
Expand All @@ -66,7 +65,6 @@ typedef enum STATEMENT
STMT_WHILE, /**< While statement */
STMT_DO, /**< Do statement */
STMT_FOR, /**< For statement */
STMT_GOTO, /**< Goto statement */
STMT_CONTINUE, /**< Continue statement */
STMT_BREAK, /**< Break statement */
STMT_RETURN, /**< Return statement */
Expand All @@ -78,6 +76,7 @@ typedef enum DECLARATION
DECL_VAR, /**< Variable declaration */
DECL_FUNC, /**< Function declaration */
DECL_TYPE, /**< Type declaration */
DECL_INVALID, /**< Invalid declaration */
} declaration_t;


Expand Down Expand Up @@ -173,6 +172,28 @@ size_t expression_identifier_get_id(const node *const nd);
node expression_null_literal(node *const context, const item_t type, const location loc);


/**
* Create new boolean literal expression
*
* @param context Context node
* @param type Value type
* @param value Literal value
* @param loc Literal location
*
* @return Boolean literal expression
*/
node expression_boolean_literal(node *const context, const item_t type, const bool value, const location loc);

/**
* Get value of boolean literal expression
*
* @param nd Literal expression
*
* @return Boolean value
*/
bool expression_literal_get_boolean(const node *const nd);


/**
* Create new character literal expression
*
Expand Down Expand Up @@ -609,36 +630,6 @@ node expression_initializer_get_subexpr(const node *const nd, const size_t index
statement_t statement_get_class(const node *const nd);


/**
* Create new labeled statement
*
* @param label Index in identifiers table
* @param substmt Substatement
* @param loc Statement location
*
* @return Labeled statement
*/
node statement_labeled(const size_t label, node *const substmt, const location loc);

/**
* Get label id of labeled statement
*
* @param nd Labeled statement
*
* @return Label id
*/
size_t statement_labeled_get_label(const node *const nd);

/**
* Get substatement of labeled statement
*
* @param nd Labeled statement
*
* @return Substatement
*/
node statement_labeled_get_substmt(const node *const nd);


/**
* Create new case statement
*
Expand Down Expand Up @@ -947,27 +938,6 @@ node statement_for_get_increment(const node *const nd);
node statement_for_get_body(const node *const nd);


/**
* Create new goto statement
*
* @param context Context node
* @param label Index in identifiers table
* @param loc Statement location
*
* @return Goto statement
*/
node statement_goto(node *const context, const size_t label, const location loc);

/**
* Get label id of goto statement
*
* @param nd Goto statement
*
* @return Label id
*/
size_t statement_goto_get_label(const node *const nd);


/**
* Create new continue statement
*
Expand Down
Loading

0 comments on commit e4db015

Please sign in to comment.