2 * This file is part of cparser.
3 * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "lang_features.h"
33 #include "adt/error.h"
35 struct obstack ast_obstack;
40 /** If set, implicit casts are printed. */
41 bool print_implicit_casts = false;
43 /** If set parenthesis are printed to indicate operator precedence. */
44 bool print_parenthesis = false;
46 static void print_statement(const statement_t *statement);
47 static void print_expression_prec(const expression_t *expression, unsigned prec);
49 void change_indent(int delta)
55 void print_indent(void)
57 for(int i = 0; i < indent; ++i)
63 PREC_COMMA = 2, /* , left to right */
64 PREC_ASSIGN = 4, /* = += -= *= /= %= <<= >>= &= ^= |= right to left */
65 PREC_COND = 6, /* ?: right to left */
66 PREC_LOG_OR = 8, /* || left to right */
67 PREC_LOG_AND = 10, /* && left to right */
68 PREC_BIT_OR = 12, /* | left to right */
69 PREC_BIT_XOR = 14, /* ^ left to right */
70 PREC_BIT_AND = 16, /* & left to right */
71 PREC_EQ = 18, /* == != left to right */
72 PREC_CMP = 20, /* < <= > >= left to right */
73 PREC_SHF = 22, /* << >> left to right */
74 PREC_PLUS = 24, /* + - left to right */
75 PREC_MUL = 26, /* * / % left to right */
76 PREC_UNARY = 28, /* ! ~ ++ -- + - (type) * & sizeof right to left */
77 PREC_ACCESS = 30, /* () [] -> . left to right */
78 PREC_PRIM = 32, /* primary */
83 * Returns 1 if a given precedence level has right-to-left
84 * associativity, else -1.
86 * @param precedence the operator precedence
88 static int right_to_left(unsigned precedence) {
89 return (precedence == PREC_ASSIGN || precedence == PREC_COND ||
90 precedence == PREC_UNARY) ? 1 : -1;
94 * Return the precedence of an expression given by its kind.
96 * @param kind the expression kind
98 static unsigned get_expression_precedence(expression_kind_t kind)
100 static const unsigned prec[] = {
101 [EXPR_UNKNOWN] = PREC_PRIM,
102 [EXPR_INVALID] = PREC_PRIM,
103 [EXPR_REFERENCE] = PREC_PRIM,
104 [EXPR_CHARACTER_CONSTANT] = PREC_PRIM,
105 [EXPR_WIDE_CHARACTER_CONSTANT] = PREC_PRIM,
106 [EXPR_CONST] = PREC_PRIM,
107 [EXPR_STRING_LITERAL] = PREC_PRIM,
108 [EXPR_WIDE_STRING_LITERAL] = PREC_PRIM,
109 [EXPR_COMPOUND_LITERAL] = PREC_UNARY,
110 [EXPR_CALL] = PREC_PRIM,
111 [EXPR_CONDITIONAL] = PREC_COND,
112 [EXPR_SELECT] = PREC_ACCESS,
113 [EXPR_ARRAY_ACCESS] = PREC_ACCESS,
114 [EXPR_SIZEOF] = PREC_UNARY,
115 [EXPR_CLASSIFY_TYPE] = PREC_UNARY,
116 [EXPR_ALIGNOF] = PREC_UNARY,
118 [EXPR_FUNCNAME] = PREC_PRIM,
119 [EXPR_BUILTIN_SYMBOL] = PREC_PRIM,
120 [EXPR_BUILTIN_CONSTANT_P] = PREC_PRIM,
121 [EXPR_BUILTIN_PREFETCH] = PREC_PRIM,
122 [EXPR_OFFSETOF] = PREC_PRIM,
123 [EXPR_VA_START] = PREC_PRIM,
124 [EXPR_VA_ARG] = PREC_PRIM,
125 [EXPR_STATEMENT] = PREC_ACCESS,
127 [EXPR_UNARY_NEGATE] = PREC_UNARY,
128 [EXPR_UNARY_PLUS] = PREC_UNARY,
129 [EXPR_UNARY_BITWISE_NEGATE] = PREC_UNARY,
130 [EXPR_UNARY_NOT] = PREC_UNARY,
131 [EXPR_UNARY_DEREFERENCE] = PREC_UNARY,
132 [EXPR_UNARY_TAKE_ADDRESS] = PREC_UNARY,
133 [EXPR_UNARY_POSTFIX_INCREMENT] = PREC_UNARY,
134 [EXPR_UNARY_POSTFIX_DECREMENT] = PREC_UNARY,
135 [EXPR_UNARY_PREFIX_INCREMENT] = PREC_UNARY,
136 [EXPR_UNARY_PREFIX_DECREMENT] = PREC_UNARY,
137 [EXPR_UNARY_CAST] = PREC_UNARY,
138 [EXPR_UNARY_CAST_IMPLICIT] = PREC_UNARY,
139 [EXPR_UNARY_ASSUME] = PREC_PRIM,
141 [EXPR_BINARY_ADD] = PREC_PLUS,
142 [EXPR_BINARY_SUB] = PREC_PLUS,
143 [EXPR_BINARY_MUL] = PREC_MUL,
144 [EXPR_BINARY_DIV] = PREC_MUL,
145 [EXPR_BINARY_MOD] = PREC_MUL,
146 [EXPR_BINARY_EQUAL] = PREC_EQ,
147 [EXPR_BINARY_NOTEQUAL] = PREC_EQ,
148 [EXPR_BINARY_LESS] = PREC_CMP,
149 [EXPR_BINARY_LESSEQUAL] = PREC_CMP,
150 [EXPR_BINARY_GREATER] = PREC_CMP,
151 [EXPR_BINARY_GREATEREQUAL] = PREC_CMP,
152 [EXPR_BINARY_BITWISE_AND] = PREC_BIT_AND,
153 [EXPR_BINARY_BITWISE_OR] = PREC_BIT_OR,
154 [EXPR_BINARY_BITWISE_XOR] = PREC_BIT_XOR,
155 [EXPR_BINARY_LOGICAL_AND] = PREC_LOG_AND,
156 [EXPR_BINARY_LOGICAL_OR] = PREC_LOG_OR,
157 [EXPR_BINARY_SHIFTLEFT] = PREC_SHF,
158 [EXPR_BINARY_SHIFTRIGHT] = PREC_SHF,
159 [EXPR_BINARY_ASSIGN] = PREC_ASSIGN,
160 [EXPR_BINARY_MUL_ASSIGN] = PREC_ASSIGN,
161 [EXPR_BINARY_DIV_ASSIGN] = PREC_ASSIGN,
162 [EXPR_BINARY_MOD_ASSIGN] = PREC_ASSIGN,
163 [EXPR_BINARY_ADD_ASSIGN] = PREC_ASSIGN,
164 [EXPR_BINARY_SUB_ASSIGN] = PREC_ASSIGN,
165 [EXPR_BINARY_SHIFTLEFT_ASSIGN] = PREC_ASSIGN,
166 [EXPR_BINARY_SHIFTRIGHT_ASSIGN] = PREC_ASSIGN,
167 [EXPR_BINARY_BITWISE_AND_ASSIGN] = PREC_ASSIGN,
168 [EXPR_BINARY_BITWISE_XOR_ASSIGN] = PREC_ASSIGN,
169 [EXPR_BINARY_BITWISE_OR_ASSIGN] = PREC_ASSIGN,
170 [EXPR_BINARY_COMMA] = PREC_COMMA,
172 [EXPR_BINARY_BUILTIN_EXPECT] = PREC_PRIM,
173 [EXPR_BINARY_ISGREATER] = PREC_PRIM,
174 [EXPR_BINARY_ISGREATEREQUAL] = PREC_PRIM,
175 [EXPR_BINARY_ISLESS] = PREC_PRIM,
176 [EXPR_BINARY_ISLESSEQUAL] = PREC_PRIM,
177 [EXPR_BINARY_ISLESSGREATER] = PREC_PRIM,
178 [EXPR_BINARY_ISUNORDERED] = PREC_PRIM
180 assert((unsigned)kind < (sizeof(prec)/sizeof(prec[0])));
181 unsigned res = prec[kind];
183 assert(res != PREC_BOTTOM);
188 * Print a constant expression.
190 * @param cnst the constant expression
192 static void print_const(const const_expression_t *cnst)
194 if(cnst->base.type == NULL)
197 const type_t *const type = skip_typeref(cnst->base.type);
199 if (is_type_integer(type)) {
200 fprintf(out, "%lld", cnst->v.int_value);
201 } else if (is_type_float(type)) {
202 fprintf(out, "%Lf", cnst->v.float_value);
204 panic("unknown constant");
209 * Print a quoted string constant.
211 * @param string the string constant
212 * @param border the border char
213 * @param skip number of chars to skip at the end
215 static void print_quoted_string(const string_t *const string, char border, int skip)
218 const char *end = string->begin + string->size - skip;
219 for (const char *c = string->begin; c != end; ++c) {
224 case '\\': fputs("\\\\", out); break;
225 case '\a': fputs("\\a", out); break;
226 case '\b': fputs("\\b", out); break;
227 case '\f': fputs("\\f", out); break;
228 case '\n': fputs("\\n", out); break;
229 case '\r': fputs("\\r", out); break;
230 case '\t': fputs("\\t", out); break;
231 case '\v': fputs("\\v", out); break;
232 case '\?': fputs("\\?", out); break;
234 if (c_mode & _GNUC) {
235 fputs("\\e", out); break;
240 fprintf(out, "\\%03o", *c);
251 * Prints a wide string literal expression.
253 * @param wstr the wide string literal expression
254 * @param border the border char
255 * @param skip number of chars to skip at the end
257 static void print_quoted_wide_string(const wide_string_t *const wstr,
258 char border, int skip)
262 const wchar_rep_t *end = wstr->begin + wstr->size - skip;
263 for (const wchar_rep_t *c = wstr->begin; c != end; ++c) {
265 case L'\"': fputs("\\\"", out); break;
266 case L'\\': fputs("\\\\", out); break;
267 case L'\a': fputs("\\a", out); break;
268 case L'\b': fputs("\\b", out); break;
269 case L'\f': fputs("\\f", out); break;
270 case L'\n': fputs("\\n", out); break;
271 case L'\r': fputs("\\r", out); break;
272 case L'\t': fputs("\\t", out); break;
273 case L'\v': fputs("\\v", out); break;
274 case L'\?': fputs("\\?", out); break;
276 if (c_mode & _GNUC) {
277 fputs("\\e", out); break;
281 const unsigned tc = *c;
284 fprintf(out, "\\%03o", (char)*c);
288 } else if (tc < 0x800) {
289 fputc(0xC0 | (tc >> 6), out);
290 fputc(0x80 | (tc & 0x3F), out);
291 } else if (tc < 0x10000) {
292 fputc(0xE0 | ( tc >> 12), out);
293 fputc(0x80 | ((tc >> 6) & 0x3F), out);
294 fputc(0x80 | ( tc & 0x3F), out);
296 fputc(0xF0 | ( tc >> 18), out);
297 fputc(0x80 | ((tc >> 12) & 0x3F), out);
298 fputc(0x80 | ((tc >> 6) & 0x3F), out);
299 fputc(0x80 | ( tc & 0x3F), out);
308 * Print a constant character expression.
310 * @param cnst the constant character expression
312 static void print_character_constant(const const_expression_t *cnst)
314 print_quoted_string(&cnst->v.character, '\'', 0);
317 static void print_wide_character_constant(const const_expression_t *cnst)
319 print_quoted_wide_string(&cnst->v.wide_character, '\'', 0);
323 * Prints a string literal expression.
325 * @param string_literal the string literal expression
327 static void print_string_literal(
328 const string_literal_expression_t *string_literal)
330 print_quoted_string(&string_literal->value, '"', 1);
334 * Prints a predefined symbol.
336 static void print_funcname(
337 const funcname_expression_t *funcname)
340 switch(funcname->kind) {
341 case FUNCNAME_FUNCTION: s = (c_mode & _C99) ? "__func__" : "__FUNCTION__"; break;
342 case FUNCNAME_PRETTY_FUNCTION: s = "__PRETTY_FUNCTION__"; break;
343 case FUNCNAME_FUNCSIG: s = "__FUNCSIG__"; break;
344 case FUNCNAME_FUNCDNAME: s = "__FUNCDNAME__"; break;
351 static void print_wide_string_literal(
352 const wide_string_literal_expression_t *const wstr)
354 print_quoted_wide_string(&wstr->value, '"', 1);
357 static void print_compound_literal(
358 const compound_literal_expression_t *expression)
361 print_type(expression->type);
363 print_initializer(expression->initializer);
367 * Prints a call expression.
369 * @param call the call expression
371 static void print_call_expression(const call_expression_t *call)
373 unsigned prec = get_expression_precedence(call->base.kind);
374 print_expression_prec(call->function, prec);
376 call_argument_t *argument = call->arguments;
378 while(argument != NULL) {
384 print_expression_prec(argument->expression, PREC_COMMA + 1);
386 argument = argument->next;
392 * Prints a binary expression.
394 * @param binexpr the binary expression
396 static void print_binary_expression(const binary_expression_t *binexpr)
398 unsigned prec = get_expression_precedence(binexpr->base.kind);
399 int r2l = right_to_left(prec);
401 if(binexpr->base.kind == EXPR_BINARY_BUILTIN_EXPECT) {
402 fputs("__builtin_expect(", out);
403 print_expression_prec(binexpr->left, prec);
405 print_expression_prec(binexpr->right, prec);
410 print_expression_prec(binexpr->left, prec + r2l);
411 if (binexpr->base.kind != EXPR_BINARY_COMMA) {
414 switch (binexpr->base.kind) {
415 case EXPR_BINARY_COMMA: fputs(",", out); break;
416 case EXPR_BINARY_ASSIGN: fputs("=", out); break;
417 case EXPR_BINARY_ADD: fputs("+", out); break;
418 case EXPR_BINARY_SUB: fputs("-", out); break;
419 case EXPR_BINARY_MUL: fputs("*", out); break;
420 case EXPR_BINARY_MOD: fputs("%", out); break;
421 case EXPR_BINARY_DIV: fputs("/", out); break;
422 case EXPR_BINARY_BITWISE_OR: fputs("|", out); break;
423 case EXPR_BINARY_BITWISE_AND: fputs("&", out); break;
424 case EXPR_BINARY_BITWISE_XOR: fputs("^", out); break;
425 case EXPR_BINARY_LOGICAL_OR: fputs("||", out); break;
426 case EXPR_BINARY_LOGICAL_AND: fputs("&&", out); break;
427 case EXPR_BINARY_NOTEQUAL: fputs("!=", out); break;
428 case EXPR_BINARY_EQUAL: fputs("==", out); break;
429 case EXPR_BINARY_LESS: fputs("<", out); break;
430 case EXPR_BINARY_LESSEQUAL: fputs("<=", out); break;
431 case EXPR_BINARY_GREATER: fputs(">", out); break;
432 case EXPR_BINARY_GREATEREQUAL: fputs(">=", out); break;
433 case EXPR_BINARY_SHIFTLEFT: fputs("<<", out); break;
434 case EXPR_BINARY_SHIFTRIGHT: fputs(">>", out); break;
436 case EXPR_BINARY_ADD_ASSIGN: fputs("+=", out); break;
437 case EXPR_BINARY_SUB_ASSIGN: fputs("-=", out); break;
438 case EXPR_BINARY_MUL_ASSIGN: fputs("*=", out); break;
439 case EXPR_BINARY_MOD_ASSIGN: fputs("%=", out); break;
440 case EXPR_BINARY_DIV_ASSIGN: fputs("/=", out); break;
441 case EXPR_BINARY_BITWISE_OR_ASSIGN: fputs("|=", out); break;
442 case EXPR_BINARY_BITWISE_AND_ASSIGN: fputs("&=", out); break;
443 case EXPR_BINARY_BITWISE_XOR_ASSIGN: fputs("^=", out); break;
444 case EXPR_BINARY_SHIFTLEFT_ASSIGN: fputs("<<=", out); break;
445 case EXPR_BINARY_SHIFTRIGHT_ASSIGN: fputs(">>=", out); break;
446 default: panic("invalid binexpression found");
449 print_expression_prec(binexpr->right, prec - r2l);
453 * Prints an unary expression.
455 * @param unexpr the unary expression
457 static void print_unary_expression(const unary_expression_t *unexpr)
459 unsigned prec = get_expression_precedence(unexpr->base.kind);
460 switch(unexpr->base.kind) {
461 case EXPR_UNARY_NEGATE: fputs("-", out); break;
462 case EXPR_UNARY_PLUS: fputs("+", out); break;
463 case EXPR_UNARY_NOT: fputs("!", out); break;
464 case EXPR_UNARY_BITWISE_NEGATE: fputs("~", out); break;
465 case EXPR_UNARY_PREFIX_INCREMENT: fputs("++", out); break;
466 case EXPR_UNARY_PREFIX_DECREMENT: fputs("--", out); break;
467 case EXPR_UNARY_DEREFERENCE: fputs("*", out); break;
468 case EXPR_UNARY_TAKE_ADDRESS: fputs("&", out); break;
470 case EXPR_UNARY_POSTFIX_INCREMENT:
471 print_expression_prec(unexpr->value, prec);
474 case EXPR_UNARY_POSTFIX_DECREMENT:
475 print_expression_prec(unexpr->value, prec);
478 case EXPR_UNARY_CAST_IMPLICIT:
479 case EXPR_UNARY_CAST:
481 print_type(unexpr->base.type);
484 case EXPR_UNARY_ASSUME:
485 fputs("__assume(", out);
486 print_expression_prec(unexpr->value, PREC_COMMA + 1);
490 panic("invalid unary expression found");
492 print_expression_prec(unexpr->value, prec);
496 * Prints a reference expression.
498 * @param ref the reference expression
500 static void print_reference_expression(const reference_expression_t *ref)
502 fprintf(out, "%s", ref->declaration->symbol->string);
506 * Prints an array expression.
508 * @param expression the array expression
510 static void print_array_expression(const array_access_expression_t *expression)
512 unsigned prec = get_expression_precedence(expression->base.kind);
513 if(!expression->flipped) {
514 print_expression_prec(expression->array_ref, prec);
516 print_expression_prec(expression->index, PREC_BOTTOM);
519 print_expression_prec(expression->index, prec);
521 print_expression_prec(expression->array_ref, PREC_BOTTOM);
527 * Prints a typeproperty expression (sizeof or __alignof__).
529 * @param expression the type property expression
531 static void print_typeprop_expression(const typeprop_expression_t *expression)
533 if (expression->base.kind == EXPR_SIZEOF) {
534 fputs("sizeof", out);
536 assert(expression->base.kind == EXPR_ALIGNOF);
537 fputs("__alignof__", out);
539 if(expression->tp_expression != NULL) {
540 /* always print the '()' here, sizeof x is right but unusual */
542 print_expression_prec(expression->tp_expression, PREC_ACCESS);
546 print_type(expression->type);
552 * Prints an builtin symbol.
554 * @param expression the builtin symbol expression
556 static void print_builtin_symbol(const builtin_symbol_expression_t *expression)
558 fputs(expression->symbol->string, out);
562 * Prints a builtin constant expression.
564 * @param expression the builtin constant expression
566 static void print_builtin_constant(const builtin_constant_expression_t *expression)
568 fputs("__builtin_constant_p(", out);
569 print_expression_prec(expression->value, PREC_COMMA + 1);
574 * Prints a builtin prefetch expression.
576 * @param expression the builtin prefetch expression
578 static void print_builtin_prefetch(const builtin_prefetch_expression_t *expression)
580 fputs("__builtin_prefetch(", out);
581 print_expression_prec(expression->adr, PREC_COMMA + 1);
582 if (expression->rw) {
584 print_expression_prec(expression->rw, PREC_COMMA + 1);
586 if (expression->locality) {
588 print_expression_prec(expression->locality, PREC_COMMA + 1);
594 * Prints a conditional expression.
596 * @param expression the conditional expression
598 static void print_conditional(const conditional_expression_t *expression)
600 unsigned prec = get_expression_precedence(expression->base.kind);
602 print_expression_prec(expression->condition, prec);
604 if (expression->true_expression != NULL) {
605 print_expression_prec(expression->true_expression, prec);
610 print_expression_prec(expression->false_expression, prec);
615 * Prints a va_start expression.
617 * @param expression the va_start expression
619 static void print_va_start(const va_start_expression_t *const expression)
621 fputs("__builtin_va_start(", out);
622 print_expression_prec(expression->ap, PREC_COMMA + 1);
624 fputs(expression->parameter->symbol->string, out);
629 * Prints a va_arg expression.
631 * @param expression the va_arg expression
633 static void print_va_arg(const va_arg_expression_t *expression)
635 fputs("__builtin_va_arg(", out);
636 print_expression_prec(expression->ap, PREC_COMMA + 1);
638 print_type(expression->base.type);
643 * Prints a select expression (. or ->).
645 * @param expression the select expression
647 static void print_select(const select_expression_t *expression)
649 unsigned prec = get_expression_precedence(expression->base.kind);
650 print_expression_prec(expression->compound, prec);
651 if(is_type_pointer(skip_typeref(expression->compound->base.type))) {
656 fputs(expression->symbol->string, out);
660 * Prints a type classify expression.
662 * @param expr the type classify expression
664 static void print_classify_type_expression(
665 const classify_type_expression_t *const expr)
667 fputs("__builtin_classify_type(", out);
668 print_expression_prec(expr->type_expression, PREC_COMMA + 1);
673 * Prints a designator.
675 * @param designator the designator
677 static void print_designator(const designator_t *designator)
679 for ( ; designator != NULL; designator = designator->next) {
680 if (designator->symbol == NULL) {
682 print_expression_prec(designator->array_index, PREC_BOTTOM);
686 fputs(designator->symbol->string, out);
692 * Prints an offsetof expression.
694 * @param expression the offset expression
696 static void print_offsetof_expression(const offsetof_expression_t *expression)
698 fputs("__builtin_offsetof", out);
700 print_type(expression->type);
702 print_designator(expression->designator);
707 * Prints a statement expression.
709 * @param expression the statement expression
711 static void print_statement_expression(const statement_expression_t *expression)
714 print_statement(expression->statement);
719 * Prints an expression with parenthesis if needed.
721 * @param expression the expression to print
722 * @param top_prec the precedence of the user of this expression.
724 static void print_expression_prec(const expression_t *expression, unsigned top_prec)
726 if (expression->kind == EXPR_UNARY_CAST_IMPLICIT && !print_implicit_casts) {
727 expression = expression->unary.value;
729 unsigned prec = get_expression_precedence(expression->base.kind);
730 if (print_parenthesis && top_prec != PREC_BOTTOM)
734 switch(expression->kind) {
737 fprintf(out, "$invalid expression$");
739 case EXPR_CHARACTER_CONSTANT:
740 print_character_constant(&expression->conste);
742 case EXPR_WIDE_CHARACTER_CONSTANT:
743 print_wide_character_constant(&expression->conste);
746 print_const(&expression->conste);
749 print_funcname(&expression->funcname);
751 case EXPR_STRING_LITERAL:
752 print_string_literal(&expression->string);
754 case EXPR_WIDE_STRING_LITERAL:
755 print_wide_string_literal(&expression->wide_string);
757 case EXPR_COMPOUND_LITERAL:
758 print_compound_literal(&expression->compound_literal);
761 print_call_expression(&expression->call);
764 print_binary_expression(&expression->binary);
767 print_reference_expression(&expression->reference);
769 case EXPR_ARRAY_ACCESS:
770 print_array_expression(&expression->array_access);
773 print_unary_expression(&expression->unary);
777 print_typeprop_expression(&expression->typeprop);
779 case EXPR_BUILTIN_SYMBOL:
780 print_builtin_symbol(&expression->builtin_symbol);
782 case EXPR_BUILTIN_CONSTANT_P:
783 print_builtin_constant(&expression->builtin_constant);
785 case EXPR_BUILTIN_PREFETCH:
786 print_builtin_prefetch(&expression->builtin_prefetch);
788 case EXPR_CONDITIONAL:
789 print_conditional(&expression->conditional);
792 print_va_start(&expression->va_starte);
795 print_va_arg(&expression->va_arge);
798 print_select(&expression->select);
800 case EXPR_CLASSIFY_TYPE:
801 print_classify_type_expression(&expression->classify_type);
804 print_offsetof_expression(&expression->offsetofe);
807 print_statement_expression(&expression->statement);
812 fprintf(out, "some expression of type %d", (int) expression->kind);
820 * Print an compound statement.
822 * @param block the compound statement
824 static void print_compound_statement(const compound_statement_t *block)
829 statement_t *statement = block->statements;
830 while(statement != NULL) {
831 if (statement->base.kind == STATEMENT_CASE_LABEL)
834 print_statement(statement);
836 statement = statement->base.next;
844 * Print a return statement.
846 * @param statement the return statement
848 static void print_return_statement(const return_statement_t *statement)
850 fprintf(out, "return ");
851 if(statement->value != NULL)
852 print_expression(statement->value);
857 * Print an expression statement.
859 * @param statement the expression statement
861 static void print_expression_statement(const expression_statement_t *statement)
863 print_expression(statement->expression);
868 * Print a goto statement.
870 * @param statement the goto statement
872 static void print_goto_statement(const goto_statement_t *statement)
874 fprintf(out, "goto ");
875 fputs(statement->label->symbol->string, out);
876 fprintf(stderr, "(%p)", (void*) statement->label);
881 * Print a label statement.
883 * @param statement the label statement
885 static void print_label_statement(const label_statement_t *statement)
887 fprintf(stderr, "(%p)", (void*) statement->label);
888 fprintf(out, "%s:\n", statement->label->symbol->string);
889 print_statement(statement->statement);
893 * Print an if statement.
895 * @param statement the if statement
897 static void print_if_statement(const if_statement_t *statement)
900 print_expression(statement->condition);
902 print_statement(statement->true_statement);
904 if(statement->false_statement != NULL) {
907 print_statement(statement->false_statement);
912 * Print a switch statement.
914 * @param statement the switch statement
916 static void print_switch_statement(const switch_statement_t *statement)
918 fputs("switch (", out);
919 print_expression(statement->expression);
921 print_statement(statement->body);
925 * Print a case label (including the default label).
927 * @param statement the case label statement
929 static void print_case_label(const case_label_statement_t *statement)
931 if(statement->expression == NULL) {
932 fputs("default:\n", out);
935 print_expression(statement->expression);
936 if (statement->end_range != NULL) {
938 print_expression(statement->end_range);
943 if(statement->statement != NULL) {
944 if (statement->statement->base.kind == STATEMENT_CASE_LABEL) {
948 print_statement(statement->statement);
953 * Print a declaration statement.
955 * @param statement the statement
957 static void print_declaration_statement(
958 const declaration_statement_t *statement)
961 declaration_t *declaration = statement->declarations_begin;
962 for( ; declaration != statement->declarations_end->next;
963 declaration = declaration->next) {
964 if(declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY)
972 print_declaration(declaration);
978 * Print a while statement.
980 * @param statement the statement
982 static void print_while_statement(const while_statement_t *statement)
984 fputs("while (", out);
985 print_expression(statement->condition);
987 print_statement(statement->body);
991 * Print a do-while statement.
993 * @param statement the statement
995 static void print_do_while_statement(const do_while_statement_t *statement)
998 print_statement(statement->body);
1000 fputs("while (", out);
1001 print_expression(statement->condition);
1006 * Print a for statement.
1008 * @param statement the statement
1010 static void print_for_statement(const for_statement_t *statement)
1012 fputs("for (", out);
1013 if(statement->scope.declarations != NULL) {
1014 assert(statement->initialisation == NULL);
1015 print_declaration(statement->scope.declarations);
1016 if(statement->scope.declarations->next != NULL) {
1017 panic("multiple declarations in for statement not supported yet");
1021 if(statement->initialisation) {
1022 print_expression(statement->initialisation);
1026 if(statement->condition != NULL) {
1027 print_expression(statement->condition);
1030 if(statement->step != NULL) {
1031 print_expression(statement->step);
1034 print_statement(statement->body);
1038 * Print assembler arguments.
1040 * @param arguments the arguments
1042 static void print_asm_arguments(asm_argument_t *arguments)
1044 asm_argument_t *argument = arguments;
1045 for( ; argument != NULL; argument = argument->next) {
1046 if(argument != arguments)
1049 if(argument->symbol) {
1050 fprintf(out, "[%s] ", argument->symbol->string);
1052 print_quoted_string(&argument->constraints, '"', 1);
1054 print_expression(argument->expression);
1060 * Print assembler clobbers.
1062 * @param clobbers the clobbers
1064 static void print_asm_clobbers(asm_clobber_t *clobbers)
1066 asm_clobber_t *clobber = clobbers;
1067 for( ; clobber != NULL; clobber = clobber->next) {
1068 if(clobber != clobbers)
1071 print_quoted_string(&clobber->clobber, '"', 1);
1076 * Print an assembler statement.
1078 * @param statement the statement
1080 static void print_asm_statement(const asm_statement_t *statement)
1083 if(statement->is_volatile) {
1084 fputs("volatile ", out);
1087 print_quoted_string(&statement->asm_text, '"', 1);
1088 if(statement->inputs == NULL && statement->outputs == NULL
1089 && statement->clobbers == NULL)
1090 goto end_of_print_asm_statement;
1093 print_asm_arguments(statement->inputs);
1094 if(statement->outputs == NULL && statement->clobbers == NULL)
1095 goto end_of_print_asm_statement;
1098 print_asm_arguments(statement->outputs);
1099 if(statement->clobbers == NULL)
1100 goto end_of_print_asm_statement;
1103 print_asm_clobbers(statement->clobbers);
1105 end_of_print_asm_statement:
1110 * Print a microsoft __try statement.
1112 * @param statement the statement
1114 static void print_ms_try_statement(const ms_try_statement_t *statement)
1116 fputs("__try ", out);
1117 print_statement(statement->try_statement);
1119 if(statement->except_expression != NULL) {
1120 fputs("__except(", out);
1121 print_expression(statement->except_expression);
1124 fputs("__finally ", out);
1126 print_statement(statement->final_statement);
1130 * Print a microsoft __leave statement.
1132 * @param statement the statement
1134 static void print_leave_statement(const leave_statement_t *statement)
1137 fputs("__leave;\n", out);
1141 * Print a statement.
1143 * @param statement the statement
1145 void print_statement(const statement_t *statement)
1147 switch(statement->kind) {
1148 case STATEMENT_EMPTY:
1151 case STATEMENT_COMPOUND:
1152 print_compound_statement(&statement->compound);
1154 case STATEMENT_RETURN:
1155 print_return_statement(&statement->returns);
1157 case STATEMENT_EXPRESSION:
1158 print_expression_statement(&statement->expression);
1160 case STATEMENT_LABEL:
1161 print_label_statement(&statement->label);
1163 case STATEMENT_GOTO:
1164 print_goto_statement(&statement->gotos);
1166 case STATEMENT_CONTINUE:
1167 fputs("continue;\n", out);
1169 case STATEMENT_BREAK:
1170 fputs("break;\n", out);
1173 print_if_statement(&statement->ifs);
1175 case STATEMENT_SWITCH:
1176 print_switch_statement(&statement->switchs);
1178 case STATEMENT_CASE_LABEL:
1179 print_case_label(&statement->case_label);
1181 case STATEMENT_DECLARATION:
1182 print_declaration_statement(&statement->declaration);
1184 case STATEMENT_WHILE:
1185 print_while_statement(&statement->whiles);
1187 case STATEMENT_DO_WHILE:
1188 print_do_while_statement(&statement->do_while);
1191 print_for_statement(&statement->fors);
1194 print_asm_statement(&statement->asms);
1196 case STATEMENT_MS_TRY:
1197 print_ms_try_statement(&statement->ms_try);
1199 case STATEMENT_LEAVE:
1200 print_leave_statement(&statement->leave);
1202 case STATEMENT_INVALID:
1203 fprintf(out, "$invalid statement$");
1209 * Print a storage class.
1211 * @param storage_class the storage class
1213 static void print_storage_class(storage_class_tag_t storage_class)
1215 switch(storage_class) {
1216 case STORAGE_CLASS_ENUM_ENTRY:
1217 case STORAGE_CLASS_NONE:
1219 case STORAGE_CLASS_TYPEDEF: fputs("typedef ", out); break;
1220 case STORAGE_CLASS_EXTERN: fputs("extern ", out); break;
1221 case STORAGE_CLASS_STATIC: fputs("static ", out); break;
1222 case STORAGE_CLASS_AUTO: fputs("auto ", out); break;
1223 case STORAGE_CLASS_REGISTER: fputs("register ", out); break;
1224 case STORAGE_CLASS_THREAD: fputs("__thread", out); break;
1225 case STORAGE_CLASS_THREAD_EXTERN: fputs("extern __thread", out); break;
1226 case STORAGE_CLASS_THREAD_STATIC: fputs("static __thread", out); break;
1231 * Print an initializer.
1233 * @param initializer the initializer
1235 void print_initializer(const initializer_t *initializer)
1237 if(initializer == NULL) {
1242 switch(initializer->kind) {
1243 case INITIALIZER_VALUE: {
1244 const initializer_value_t *value = &initializer->value;
1245 print_expression(value->value);
1248 case INITIALIZER_LIST: {
1249 assert(initializer->kind == INITIALIZER_LIST);
1251 const initializer_list_t *list = &initializer->list;
1253 for(size_t i = 0 ; i < list->len; ++i) {
1254 const initializer_t *sub_init = list->initializers[i];
1255 print_initializer(list->initializers[i]);
1256 if(i < list->len-1) {
1257 if(sub_init == NULL || sub_init->kind != INITIALIZER_DESIGNATOR)
1264 case INITIALIZER_STRING:
1265 print_quoted_string(&initializer->string.string, '"', 1);
1267 case INITIALIZER_WIDE_STRING:
1268 print_quoted_wide_string(&initializer->wide_string.string, '"', 1);
1270 case INITIALIZER_DESIGNATOR:
1271 print_designator(initializer->designator.designator);
1276 panic("invalid initializer kind found");
1280 * Print microsoft extended declaration modifiers.
1282 static void print_ms_modifiers(const declaration_t *declaration) {
1283 if((c_mode & _MS) == 0)
1286 decl_modifiers_t modifiers = declaration->modifiers;
1288 /* DM_FORCEINLINE handled outside. */
1289 if ((modifiers & ~DM_FORCEINLINE) != 0 ||
1290 declaration->alignment != 0 ||
1291 declaration->get_property_sym != NULL ||
1292 declaration->put_property_sym != NULL) {
1295 fputs("__declspec", out);
1296 if(modifiers & DM_DLLIMPORT) {
1297 fputs(next, out); next = ", "; fputs("dllimport", out);
1299 if(modifiers & DM_DLLEXPORT) {
1300 fputs(next, out); next = ", "; fputs("dllexport", out);
1302 if(modifiers & DM_THREAD) {
1303 fputs(next, out); next = ", "; fputs("thread", out);
1305 if(modifiers & DM_NAKED) {
1306 fputs(next, out); next = ", "; fputs("naked", out);
1308 if(modifiers & DM_THREAD) {
1309 fputs(next, out); next = ", "; fputs("thread", out);
1311 if(modifiers & DM_SELECTANY) {
1312 fputs(next, out); next = ", "; fputs("selectany", out);
1314 if(modifiers & DM_NOTHROW) {
1315 fputs(next, out); next = ", "; fputs("nothrow", out);
1317 if(modifiers & DM_NORETURN) {
1318 fputs(next, out); next = ", "; fputs("noreturn", out);
1320 if(modifiers & DM_NOINLINE) {
1321 fputs(next, out); next = ", "; fputs("noinline", out);
1323 if (modifiers & DM_DEPRECATED) {
1324 fputs(next, out); next = ", "; fputs("deprecated", out);
1325 if(declaration->deprecated_string != NULL)
1326 fprintf(out, "(\"%s\")", declaration->deprecated_string);
1328 if(declaration->alignment != 0) {
1329 fputs(next, out); next = ", "; fprintf(out, "align(%u)", declaration->alignment);
1331 if(modifiers & DM_RESTRICT) {
1332 fputs(next, out); next = ", "; fputs("restrict", out);
1334 if(modifiers & DM_NOALIAS) {
1335 fputs(next, out); next = ", "; fputs("noalias", out);
1337 if(declaration->get_property_sym != NULL || declaration->put_property_sym != NULL) {
1339 fputs(next, out); next = ", "; fprintf(out, "property(");
1340 if(declaration->get_property_sym != NULL) {
1341 fprintf(out, "get=%s", declaration->get_property_sym->string);
1344 if(declaration->put_property_sym != NULL)
1345 fprintf(out, "%sput=%s", comma, declaration->put_property_sym->string);
1353 * Print a declaration in the NORMAL namespace.
1355 * @param declaration the declaration
1357 static void print_normal_declaration(const declaration_t *declaration)
1359 print_storage_class((storage_class_tag_t) declaration->declared_storage_class);
1360 if (declaration->is_inline) {
1361 if (declaration->modifiers & DM_FORCEINLINE) {
1362 fputs("__forceinline ", out);
1363 } else if (declaration->modifiers & DM_MICROSOFT_INLINE) {
1364 fputs("__inline ", out);
1366 fputs("inline ", out);
1369 print_ms_modifiers(declaration);
1370 print_type_ext(declaration->type, declaration->symbol,
1371 &declaration->scope);
1373 if(declaration->type->kind == TYPE_FUNCTION) {
1374 if(declaration->init.statement != NULL) {
1376 print_statement(declaration->init.statement);
1379 } else if(declaration->init.initializer != NULL) {
1381 print_initializer(declaration->init.initializer);
1387 * Prints an expression.
1389 * @param expression the expression
1391 void print_expression(const expression_t *expression) {
1392 print_expression_prec(expression, PREC_BOTTOM);
1396 * Print a declaration.
1398 * @param declaration the declaration
1400 void print_declaration(const declaration_t *declaration)
1402 if(declaration->namespc != NAMESPACE_NORMAL &&
1403 declaration->symbol == NULL)
1406 switch(declaration->namespc) {
1407 case NAMESPACE_NORMAL:
1408 print_normal_declaration(declaration);
1410 case NAMESPACE_STRUCT:
1411 fputs("struct ", out);
1412 fputs(declaration->symbol->string, out);
1414 print_compound_definition(declaration);
1417 case NAMESPACE_UNION:
1418 fputs("union ", out);
1419 fputs(declaration->symbol->string, out);
1421 print_compound_definition(declaration);
1424 case NAMESPACE_ENUM:
1425 fputs("enum ", out);
1426 fputs(declaration->symbol->string, out);
1428 print_enum_definition(declaration);
1435 * Print the AST of a translation unit.
1437 * @param unit the translation unit
1439 void print_ast(const translation_unit_t *unit)
1443 declaration_t *declaration = unit->scope.declarations;
1444 for( ; declaration != NULL; declaration = declaration->next) {
1445 if(declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY)
1447 if(declaration->namespc != NAMESPACE_NORMAL &&
1448 declaration->symbol == NULL)
1452 print_declaration(declaration);
1457 bool is_constant_initializer(const initializer_t *initializer)
1459 switch(initializer->kind) {
1460 case INITIALIZER_STRING:
1461 case INITIALIZER_WIDE_STRING:
1462 case INITIALIZER_DESIGNATOR:
1465 case INITIALIZER_VALUE:
1466 return is_constant_expression(initializer->value.value);
1468 case INITIALIZER_LIST:
1469 for(size_t i = 0; i < initializer->list.len; ++i) {
1470 initializer_t *sub_initializer = initializer->list.initializers[i];
1471 if(!is_constant_initializer(sub_initializer))
1476 panic("invalid initializer kind found");
1479 static bool is_object_with_linker_constant_address(const expression_t *expression)
1481 switch(expression->kind) {
1482 case EXPR_UNARY_DEREFERENCE:
1483 return is_address_constant(expression->unary.value);
1486 type_t *base_type = skip_typeref(expression->select.compound->base.type);
1487 if(is_type_pointer(base_type)) {
1489 return is_address_constant(expression->select.compound);
1491 return is_object_with_linker_constant_address(expression->select.compound);
1495 case EXPR_ARRAY_ACCESS:
1496 return is_constant_expression(expression->array_access.index)
1497 && is_address_constant(expression->array_access.array_ref);
1499 case EXPR_REFERENCE: {
1500 declaration_t *declaration = expression->reference.declaration;
1501 switch((storage_class_tag_t) declaration->storage_class) {
1502 case STORAGE_CLASS_NONE:
1503 case STORAGE_CLASS_EXTERN:
1504 case STORAGE_CLASS_STATIC:
1516 bool is_address_constant(const expression_t *expression)
1518 switch(expression->kind) {
1519 case EXPR_UNARY_TAKE_ADDRESS:
1520 return is_object_with_linker_constant_address(expression->unary.value);
1522 case EXPR_UNARY_DEREFERENCE: {
1524 = revert_automatic_type_conversion(expression->unary.value);
1525 /* dereferencing a function is a NOP */
1526 if(is_type_function(real_type)) {
1527 return is_address_constant(expression->unary.value);
1533 case EXPR_UNARY_CAST: {
1534 type_t *dest = skip_typeref(expression->base.type);
1535 if (!is_type_pointer(dest) &&
1536 ! (dest->kind == TYPE_ATOMIC
1537 && (get_atomic_type_flags(dest->atomic.akind) & ATOMIC_TYPE_FLAG_INTEGER)
1538 && (get_atomic_type_size(dest->atomic.akind) >= get_atomic_type_size(get_intptr_kind()))))
1541 return (is_constant_expression(expression->unary.value)
1542 || is_address_constant(expression->unary.value));
1545 case EXPR_BINARY_ADD:
1546 case EXPR_BINARY_SUB: {
1547 expression_t *left = expression->binary.left;
1548 expression_t *right = expression->binary.right;
1550 if(is_type_pointer(skip_typeref(left->base.type))) {
1551 return is_address_constant(left) && is_constant_expression(right);
1552 } else if(is_type_pointer(skip_typeref(right->base.type))) {
1553 return is_constant_expression(left) && is_address_constant(right);
1559 case EXPR_REFERENCE: {
1560 declaration_t *declaration = expression->reference.declaration;
1561 type_t *type = skip_typeref(declaration->type);
1562 if(is_type_function(type))
1564 if(is_type_array(type)) {
1565 return is_object_with_linker_constant_address(expression);
1575 static bool is_builtin_const_call(const expression_t *expression)
1577 expression_t *function = expression->call.function;
1578 if (function->kind != EXPR_BUILTIN_SYMBOL) {
1582 symbol_t *symbol = function->builtin_symbol.symbol;
1584 switch (symbol->ID) {
1585 case T___builtin_huge_val:
1586 case T___builtin_nan:
1587 case T___builtin_nanf:
1588 case T___builtin_nand:
1595 static bool is_constant_pointer(const expression_t *expression)
1597 if (is_constant_expression(expression))
1600 switch (expression->kind) {
1602 return is_constant_pointer(expression->select.compound);
1603 case EXPR_UNARY_CAST:
1604 return is_constant_pointer(expression->unary.value);
1610 static bool is_object_with_constant_address(const expression_t *expression)
1612 switch(expression->kind) {
1614 expression_t *compound = expression->select.compound;
1615 type_t *compound_type = compound->base.type;
1616 compound_type = skip_typeref(compound_type);
1617 if(is_type_pointer(compound_type)) {
1618 return is_constant_pointer(compound);
1620 return is_object_with_constant_address(compound);
1623 case EXPR_ARRAY_ACCESS:
1624 return is_constant_pointer(expression->array_access.array_ref)
1625 && is_constant_expression(expression->array_access.index);
1626 case EXPR_UNARY_DEREFERENCE:
1627 return is_constant_pointer(expression->unary.value);
1633 bool is_constant_expression(const expression_t *expression)
1635 switch(expression->kind) {
1638 case EXPR_CHARACTER_CONSTANT:
1639 case EXPR_WIDE_CHARACTER_CONSTANT:
1640 case EXPR_STRING_LITERAL:
1641 case EXPR_WIDE_STRING_LITERAL:
1642 case EXPR_CLASSIFY_TYPE:
1646 case EXPR_BUILTIN_CONSTANT_P:
1650 type_t *type = expression->typeprop.type;
1652 type = expression->typeprop.tp_expression->base.type;
1654 type = skip_typeref(type);
1655 if (is_type_array(type) && type->array.is_vla)
1660 case EXPR_BUILTIN_SYMBOL:
1661 case EXPR_BUILTIN_PREFETCH:
1665 case EXPR_STATEMENT:
1666 case EXPR_UNARY_POSTFIX_INCREMENT:
1667 case EXPR_UNARY_POSTFIX_DECREMENT:
1668 case EXPR_UNARY_PREFIX_INCREMENT:
1669 case EXPR_UNARY_PREFIX_DECREMENT:
1670 case EXPR_UNARY_ASSUME: /* has VOID type */
1671 case EXPR_UNARY_DEREFERENCE:
1672 case EXPR_BINARY_ASSIGN:
1673 case EXPR_BINARY_MUL_ASSIGN:
1674 case EXPR_BINARY_DIV_ASSIGN:
1675 case EXPR_BINARY_MOD_ASSIGN:
1676 case EXPR_BINARY_ADD_ASSIGN:
1677 case EXPR_BINARY_SUB_ASSIGN:
1678 case EXPR_BINARY_SHIFTLEFT_ASSIGN:
1679 case EXPR_BINARY_SHIFTRIGHT_ASSIGN:
1680 case EXPR_BINARY_BITWISE_AND_ASSIGN:
1681 case EXPR_BINARY_BITWISE_XOR_ASSIGN:
1682 case EXPR_BINARY_BITWISE_OR_ASSIGN:
1683 case EXPR_BINARY_COMMA:
1686 case EXPR_UNARY_TAKE_ADDRESS:
1687 return is_object_with_constant_address(expression->unary.value);
1690 return is_builtin_const_call(expression);
1692 case EXPR_UNARY_NEGATE:
1693 case EXPR_UNARY_PLUS:
1694 case EXPR_UNARY_BITWISE_NEGATE:
1695 case EXPR_UNARY_NOT:
1696 return is_constant_expression(expression->unary.value);
1698 case EXPR_UNARY_CAST:
1699 case EXPR_UNARY_CAST_IMPLICIT:
1700 return is_type_arithmetic(skip_typeref(expression->base.type))
1701 && is_constant_expression(expression->unary.value);
1703 case EXPR_BINARY_ADD:
1704 case EXPR_BINARY_SUB:
1705 case EXPR_BINARY_MUL:
1706 case EXPR_BINARY_DIV:
1707 case EXPR_BINARY_MOD:
1708 case EXPR_BINARY_EQUAL:
1709 case EXPR_BINARY_NOTEQUAL:
1710 case EXPR_BINARY_LESS:
1711 case EXPR_BINARY_LESSEQUAL:
1712 case EXPR_BINARY_GREATER:
1713 case EXPR_BINARY_GREATEREQUAL:
1714 case EXPR_BINARY_BITWISE_AND:
1715 case EXPR_BINARY_BITWISE_OR:
1716 case EXPR_BINARY_BITWISE_XOR:
1717 case EXPR_BINARY_LOGICAL_AND:
1718 case EXPR_BINARY_LOGICAL_OR:
1719 case EXPR_BINARY_SHIFTLEFT:
1720 case EXPR_BINARY_SHIFTRIGHT:
1721 case EXPR_BINARY_BUILTIN_EXPECT:
1722 case EXPR_BINARY_ISGREATER:
1723 case EXPR_BINARY_ISGREATEREQUAL:
1724 case EXPR_BINARY_ISLESS:
1725 case EXPR_BINARY_ISLESSEQUAL:
1726 case EXPR_BINARY_ISLESSGREATER:
1727 case EXPR_BINARY_ISUNORDERED:
1728 return is_constant_expression(expression->binary.left)
1729 && is_constant_expression(expression->binary.right);
1731 case EXPR_COMPOUND_LITERAL:
1732 return is_constant_initializer(expression->compound_literal.initializer);
1734 case EXPR_CONDITIONAL: {
1735 expression_t *condition = expression->conditional.condition;
1736 if(!is_constant_expression(condition))
1739 long val = fold_constant(condition);
1741 return is_constant_expression(expression->conditional.true_expression);
1743 return is_constant_expression(expression->conditional.false_expression);
1746 case EXPR_ARRAY_ACCESS:
1747 return is_constant_expression(expression->array_access.array_ref)
1748 && is_constant_expression(expression->array_access.index);
1750 case EXPR_REFERENCE: {
1751 declaration_t *declaration = expression->reference.declaration;
1752 if(declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY)
1764 panic("invalid expression found (is constant expression)");
1768 * Initialize the AST construction.
1772 obstack_init(&ast_obstack);
1780 obstack_free(&ast_obstack, NULL);
1784 * Set the output stream for the AST printer.
1786 * @param stream the output stream
1788 void ast_set_output(FILE *stream)
1791 type_set_output(stream);
1795 * Allocate an AST object of the given size.
1797 * @param size the size of the object to allocate
1799 * @return A new allocated object in the AST memeory space.
1801 void *(allocate_ast)(size_t size)
1803 return _allocate_ast(size);