/*
* This file is part of cparser.
- * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
*/
#include <config.h>
[EXPR_UNARY_NEGATE] = PREC_UNARY,
[EXPR_UNARY_PLUS] = PREC_UNARY,
- [EXPR_UNARY_BITWISE_NEGATE] = PREC_UNARY,
+ [EXPR_UNARY_COMPLEMENT] = PREC_UNARY,
[EXPR_UNARY_NOT] = PREC_UNARY,
[EXPR_UNARY_DEREFERENCE] = PREC_UNARY,
[EXPR_UNARY_TAKE_ADDRESS] = PREC_UNARY,
[EXPR_UNARY_DELETE] = PREC_UNARY,
[EXPR_UNARY_DELETE_ARRAY] = PREC_UNARY,
[EXPR_UNARY_THROW] = PREC_ASSIGNMENT,
+ [EXPR_UNARY_IMAG] = PREC_UNARY,
+ [EXPR_UNARY_REAL] = PREC_UNARY,
[EXPR_BINARY_ADD] = PREC_ADDITIVE,
[EXPR_BINARY_SUB] = PREC_ADDITIVE,
{
unsigned prec = get_expression_precedence(unexpr->base.kind);
switch (unexpr->base.kind) {
- case EXPR_UNARY_NEGATE: print_char ('-' ); break;
- case EXPR_UNARY_PLUS: print_char ('+' ); break;
- case EXPR_UNARY_NOT: print_char ('!' ); break;
- case EXPR_UNARY_BITWISE_NEGATE: print_char ('~' ); break;
- case EXPR_UNARY_PREFIX_INCREMENT: print_string("++"); break;
- case EXPR_UNARY_PREFIX_DECREMENT: print_string("--"); break;
- case EXPR_UNARY_DEREFERENCE: print_char ('*' ); break;
- case EXPR_UNARY_TAKE_ADDRESS: print_char ('&' ); break;
- case EXPR_UNARY_DELETE: print_string("delete "); break;
+ case EXPR_UNARY_NEGATE: print_char ('-' ); break;
+ case EXPR_UNARY_PLUS: print_char ('+' ); break;
+ case EXPR_UNARY_NOT: print_char ('!' ); break;
+ case EXPR_UNARY_COMPLEMENT: print_char ('~' ); break;
+ case EXPR_UNARY_PREFIX_INCREMENT: print_string("++"); break;
+ case EXPR_UNARY_PREFIX_DECREMENT: print_string("--"); break;
+ case EXPR_UNARY_DEREFERENCE: print_char ('*' ); break;
+ case EXPR_UNARY_TAKE_ADDRESS: print_char ('&' ); break;
+ case EXPR_UNARY_DELETE: print_string("delete "); break;
case EXPR_UNARY_DELETE_ARRAY: print_string("delete [] "); break;
+ case EXPR_UNARY_REAL: print_string("__real__ "); break;
+ case EXPR_UNARY_IMAG: print_string("__imag__ "); break;
case EXPR_UNARY_POSTFIX_INCREMENT:
print_expression_prec(unexpr->value, prec);
print_assignment_expression(unexpr->value);
print_char(')');
return;
-
case EXPR_UNARY_THROW:
if (unexpr->value == NULL) {
print_string("throw");
if (designator->symbol == NULL) {
print_char('[');
print_expression(designator->array_index);
+ if (designator->range_last) {
+ print_string(" ... ");
+ print_expression(designator->range_last);
+ }
print_char(']');
} else {
print_char('.');
case EXPR_UNARY_DEREFERENCE:
return is_linker_constant(expression->unary.value);
+ case EXPR_COMPOUND_LITERAL: {
+ const compound_literal_expression_t *literal
+ = &expression->compound_literal;
+ return literal->global_scope ||
+ ((literal->type->base.qualifiers & TYPE_QUALIFIER_CONST)
+ && is_constant_initializer(literal->initializer));
+ }
+
case EXPR_SELECT: {
type_t *base_type = skip_typeref(expression->select.compound->base.type);
if (is_type_pointer(base_type)) {
case EXPR_UNARY_NEGATE:
case EXPR_UNARY_PLUS:
- case EXPR_UNARY_BITWISE_NEGATE:
+ case EXPR_UNARY_COMPLEMENT:
case EXPR_UNARY_NOT:
return is_constant_expression(expression->unary.value);
+ case EXPR_UNARY_IMAG:
+ case EXPR_UNARY_REAL: {
+ type_t *type = skip_typeref(expression->base.type);
+ if (!is_type_valid(type))
+ return EXPR_CLASS_ERROR;
+ return is_constant_expression(expression->unary.value);
+ }
+
case EXPR_UNARY_CAST: {
type_t *const type = skip_typeref(expression->base.type);
if (is_type_scalar(type))