Counter-fix add_flag().
[cparser] / ast.c
diff --git a/ast.c b/ast.c
index 21f8028..164c864 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -95,6 +95,7 @@ static unsigned get_expression_precedence(expression_kind_t kind)
                [EXPR_UNKNOWN]                   = PREC_PRIMARY,
                [EXPR_INVALID]                   = PREC_PRIMARY,
                [EXPR_REFERENCE]                 = PREC_PRIMARY,
+               [EXPR_REFERENCE_ENUM_VALUE]      = PREC_PRIMARY,
                [EXPR_CHARACTER_CONSTANT]        = PREC_PRIMARY,
                [EXPR_WIDE_CHARACTER_CONSTANT]   = PREC_PRIMARY,
                [EXPR_CONST]                     = PREC_PRIMARY,
@@ -195,7 +196,9 @@ static void print_const(const const_expression_t *cnst)
 
        const type_t *const type = skip_typeref(cnst->base.type);
 
-       if (is_type_integer(type)) {
+       if (is_type_atomic(type, ATOMIC_TYPE_BOOL)) {
+               fputs(cnst->v.int_value ? "true" : "false", out);
+       } else if (is_type_integer(type)) {
                fprintf(out, "%lld", cnst->v.int_value);
        } else if (is_type_float(type)) {
                long double const val = cnst->v.float_value;
@@ -802,6 +805,7 @@ static void print_expression_prec(const expression_t *expression, unsigned top_p
                print_binary_expression(&expression->binary);
                break;
        case EXPR_REFERENCE:
+       case EXPR_REFERENCE_ENUM_VALUE:
                print_reference_expression(&expression->reference);
                break;
        case EXPR_ARRAY_ACCESS:
@@ -1473,6 +1477,34 @@ static void print_ms_modifiers(const declaration_t *declaration)
                fputs(") ", out);
 }
 
+static void print_scope(const scope_t *scope)
+{
+       const entity_t *entity = scope->entities;
+       for ( ; entity != NULL; entity = entity->base.next) {
+               print_indent();
+               print_entity(entity);
+               fputs("\n", out);
+       }
+}
+
+static void print_namespace(const namespace_t *namespace)
+{
+       fputs("namespace ", out);
+       if (namespace->base.symbol != NULL) {
+               fputs(namespace->base.symbol->string, out);
+               fputc(' ', out);
+       }
+
+       fputs("{\n", out);
+       ++indent;
+
+       print_scope(&namespace->members);
+
+       --indent;
+       print_indent();
+       fputs("}\n", out);
+}
+
 /**
  * Print a variable or function declaration
  */
@@ -1539,10 +1571,12 @@ void print_entity(const entity_t *entity)
 
        switch ((entity_kind_tag_t) entity->kind) {
        case ENTITY_VARIABLE:
-       case ENTITY_FUNCTION:
        case ENTITY_COMPOUND_MEMBER:
                print_declaration(entity);
                return;
+       case ENTITY_FUNCTION:
+               print_declaration(entity);
+               return;
        case ENTITY_TYPEDEF:
                print_typedef(entity);
                return;
@@ -1571,6 +1605,9 @@ void print_entity(const entity_t *entity)
                print_enum_definition(&entity->enume);
                fputc(';', out);
                return;
+       case ENTITY_NAMESPACE:
+               print_namespace(&entity->namespacee);
+               return;
        case ENTITY_LABEL:
        case ENTITY_ENUM_VALUE:
        case ENTITY_LOCAL_LABEL: