Expression * crb_create_null_expression(void) { Expression *exp; exp = crb_alloc_expression(NULL_EXPRESSION); return exp; }
Expression * crb_create_array_expression(ExpressionList *list) { Expression *exp; exp = crb_alloc_expression(ARRAY_EXPRESSION); exp->u.array_literal = list; return exp; }
Expression * crb_create_boolean_expression(CRB_Boolean value) { Expression *exp; exp = crb_alloc_expression(BOOLEAN_EXPRESSION); exp->u.boolean_value = value; return exp; }
Expression * crb_create_incdec_expression(Expression *operand, ExpressionType inc_or_dec) { Expression *exp; exp = crb_alloc_expression(inc_or_dec); exp->u.inc_dec.operand = operand; return exp; }
Expression * crb_create_identifier_expression(char *identifier) { Expression *exp; exp = crb_alloc_expression(IDENTIFIER_EXPRESSION); exp->u.identifier = identifier; return exp; }
Expression * crb_create_logical_not_expression(Expression *operand) { Expression *exp; exp = crb_alloc_expression(LOGICAL_NOT_EXPRESSION); exp->u.logical_not = operand; return exp; }
Expression * crb_create_assign_expression(char *variable, Expression *operand) { Expression *exp; exp = crb_alloc_expression(ASSIGN_EXPRESSION); exp->u.assign_expression.variable = variable; exp->u.assign_expression.operand = operand; return exp; }
Expression * crb_create_member_expression(Expression *expression, char *member_name) { Expression *exp; exp = crb_alloc_expression(MEMBER_EXPRESSION); exp->u.member_expression.expression = expression; exp->u.member_expression.member_name = member_name; return exp; }
Expression * crb_create_index_expression(Expression *array, Expression *index) { Expression *exp; exp = crb_alloc_expression(INDEX_EXPRESSION); exp->u.index_expression.array = array; exp->u.index_expression.index = index; return exp; }
Expression * crb_create_comma_expression(Expression *left, Expression *right) { Expression *exp; exp = crb_alloc_expression(COMMA_EXPRESSION); exp->u.comma.left = left; exp->u.comma.right = right; return exp; }
Expression * crb_create_function_call_expression(Expression *function, ArgumentList *argument) { Expression *exp; exp = crb_alloc_expression(FUNCTION_CALL_EXPRESSION); exp->u.function_call_expression.function = function; exp->u.function_call_expression.argument = argument; return exp; }
Expression * crb_create_closure_definition(char *identifier, CRB_ParameterList *parameter_list, CRB_Block *block) { Expression *exp; exp = crb_alloc_expression(CLOSURE_EXPRESSION); exp->u.closure.function_definition = create_function_definition(identifier, parameter_list, CRB_TRUE, block); return exp; }
Expression * crb_create_minus_expression(Expression *operand) { if (operand->type == INT_EXPRESSION || operand->type == DOUBLE_EXPRESSION) { CRB_Value v; v = crb_eval_minus_expression(crb_get_current_interpreter(), NULL, operand); /* Notice! Overwriting operand expression. */ *operand = convert_value_to_expression(&v); return operand; } else { Expression *exp; exp = crb_alloc_expression(MINUS_EXPRESSION); exp->u.minus_expression = operand; return exp; } }
Expression * crb_create_binary_expression(ExpressionType operator, Expression *left, Expression *right) { if ((left->type == INT_EXPRESSION || left->type == DOUBLE_EXPRESSION) && (right->type == INT_EXPRESSION || right->type == DOUBLE_EXPRESSION)) { CRB_Value v; v = crb_eval_binary_expression(crb_get_current_interpreter(), NULL, operator, left, right); /* Overwriting left hand expression. */ *left = convert_value_to_expression(&v); return left; } else { Expression *exp; exp = crb_alloc_expression(operator); exp->u.binary_expression.left = left; exp->u.binary_expression.right = right; return exp; } }
Expression * crb_create_assign_expression(CRB_Boolean is_final, Expression *left, AssignmentOperator operator, Expression *operand) { Expression *exp; exp = crb_alloc_expression(ASSIGN_EXPRESSION); if (is_final) { if (left->type == INDEX_EXPRESSION) { crb_compile_error(ARRAY_ELEMENT_CAN_NOT_BE_FINAL_ERR, CRB_MESSAGE_ARGUMENT_END); } else if (operator != NORMAL_ASSIGN) { crb_compile_error(COMPLEX_ASSIGNMENT_OPERATOR_TO_FINAL_ERR, CRB_MESSAGE_ARGUMENT_END); } } exp->u.assign_expression.is_final = is_final; exp->u.assign_expression.left = left; exp->u.assign_expression.operator = operator; exp->u.assign_expression.operand = operand; return exp; }