safe_operations<c> operator -()
	{
		if (!check_unary_minus(value, second, typename container <c>::tag()))
			std::overflow_error("In expression is ovwerflow");
		value = -value;
		return (*this);
	}
Example #2
0
File: expr.c Project: Dasio/IFJ
static void convert_to_ExprToken(Token *token, ExprTokenVector *expr_vector)
{
	Symbol *id = NULL;
	assert(token); // just in case
	temp_expr_token.type = TERM;
	temp_expr_token.handle_start = false;
	temp_expr_token.token = token;

	temp_expr_token.E.var_type = UNDEF_;
	temp_expr_token.E.data_type = UNDEF;

	switch(token->type)
	{
		case TT_identifier:
			id = SymbolFind(funcContext, token->str.data);
			if (id) // <loc_var> or <arg> or <function>
			{
				if (check_id_function(id))
					token->type = TT_function;
				else
				{
					temp_expr_token.E.var_type = LOCAL;
					temp_expr_token.E.offset = id->index;
					temp_expr_token.E.data_type = (DataType) id->type;
				}
			}
			else
			{
				id = SymbolFind(mainContext, token->str.data);
				if (id) // <glob_var> or <function>
				{
					if (id->type == T_FunPointer) // function
						token->type = TT_function;
					else
					{
						temp_expr_token.E.var_type = GLOBAL;
						temp_expr_token.E.offset = id->index;
						temp_expr_token.E.data_type = (DataType) id->type;
					}
				}
			}
			if (id == NULL)
			{
				setError(ERR_UndefVarOrFunction);
				return;
			}
			break;
		case TT_real:
			temp_expr_token.E.var_type = CONST;
			temp_expr_token.E.data_type = DOUBLE;
			temp_expr_token.E.double_ = token->r;
			temp_expr_token.E.initialized = true;
			break;
		case TT_integer:
			temp_expr_token.E.var_type = CONST;
			temp_expr_token.E.data_type = INT;
			temp_expr_token.E.int_ = token->n;
			temp_expr_token.E.initialized = true;
			break;
		case TT_string:
			temp_expr_token.E.var_type = CONST;
			temp_expr_token.E.data_type = STRING;
			temp_expr_token.E.str = &(token->str);
			temp_expr_token.E.initialized = true;
			break;
		case TT_bool:
			temp_expr_token.E.var_type = CONST;
			temp_expr_token.E.data_type = BOOL;
			temp_expr_token.E.bool_ = (bool)token->n;
			temp_expr_token.E.initialized = true;
			break;
		case TT_minus:
			if (check_unary_minus(expr_vector))
				token->type = TT_unaryMinus;
			break;
		default: // :-)
			break;
	}
}