#include "symbol_t.h"
#include "type_t.h"
#include "parser.h"
+#include "lang_features.h"
#include <assert.h>
#include <stdio.h>
[EXPR_CLASSIFY_TYPE] = PREC_UNARY,
[EXPR_ALIGNOF] = PREC_UNARY,
- [EXPR_FUNCTION] = PREC_PRIM,
- [EXPR_PRETTY_FUNCTION] = PREC_PRIM,
+ [EXPR_FUNCNAME] = PREC_PRIM,
[EXPR_BUILTIN_SYMBOL] = PREC_PRIM,
[EXPR_BUILTIN_CONSTANT_P] = PREC_PRIM,
[EXPR_BUILTIN_PREFETCH] = PREC_PRIM,
[EXPR_UNARY_CAST] = PREC_UNARY,
[EXPR_UNARY_CAST_IMPLICIT] = PREC_UNARY,
[EXPR_UNARY_ASSUME] = PREC_PRIM,
- [EXPR_UNARY_BITFIELD_EXTRACT] = PREC_ACCESS,
[EXPR_BINARY_ADD] = PREC_PLUS,
[EXPR_BINARY_SUB] = PREC_PLUS,
print_quoted_string(&string_literal->value, '"');
}
+/**
+ * Prints a predefined symbol.
+ */
+static void print_funcname(
+ const funcname_expression_t *funcname)
+{
+ const char *s = "";
+ switch(funcname->kind) {
+ case FUNCNAME_FUNCTION: s = (c_mode & _C99) ? "__func__" : "__FUNCTION__"; break;
+ case FUNCNAME_PRETTY_FUNCTION: s = "__PRETTY_FUNCTION__"; break;
+ case FUNCNAME_FUNCSIG: s = "__FUNCSIG__"; break;
+ case FUNCNAME_FUNCDNAME: s = "__FUNCDNAME__"; break;
+ }
+ fputc('"', out);
+ fputs(s, out);
+ fputc('"', out);
+}
+
static void print_wide_string_literal(
const wide_string_literal_expression_t *const wstr)
{
case EXPR_UNARY_DEREFERENCE: fputs("*", out); break;
case EXPR_UNARY_TAKE_ADDRESS: fputs("&", out); break;
- case EXPR_UNARY_BITFIELD_EXTRACT:
- print_expression_prec(unexpr->value, prec);
- return;
-
case EXPR_UNARY_POSTFIX_INCREMENT:
print_expression_prec(unexpr->value, prec);
fputs("++", out);
case EXPR_CONST:
print_const(&expression->conste);
break;
- case EXPR_FUNCTION:
- case EXPR_PRETTY_FUNCTION:
+ case EXPR_FUNCNAME:
+ print_funcname(&expression->funcname);
+ break;
case EXPR_STRING_LITERAL:
print_string_literal(&expression->string);
break;
fputs(");\n", out);
}
+/**
+ * Print a microsoft __try statement.
+ *
+ * @param statement the statement
+ */
+static void print_ms_try_statement(const ms_try_statement_t *statement)
+{
+ fputs("__try ", out);
+ print_statement(statement->try_statement);
+ print_indent();
+ if(statement->except_expression != NULL) {
+ fputs("__except(", out);
+ print_expression(statement->except_expression);
+ fputs(") ", out);
+ } else {
+ fputs("__finally ", out);
+ }
+ print_statement(statement->final_statement);
+}
+
+/**
+ * Print a microsoft __leave statement.
+ *
+ * @param statement the statement
+ */
+static void print_leave_statement(const leave_statement_t *statement)
+{
+ (void) statement;
+ fputs("__leave;\n", out);
+}
+
/**
* Print a statement.
*
case STATEMENT_ASM:
print_asm_statement(&statement->asms);
break;
+ case STATEMENT_MS_TRY:
+ print_ms_try_statement(&statement->ms_try);
+ break;
+ case STATEMENT_LEAVE:
+ print_leave_statement(&statement->leave);
+ break;
case STATEMENT_INVALID:
fprintf(out, "$invalid statement$");
break;
* Print microsoft extended declaration modifiers.
*/
static void print_ms_modifiers(const declaration_t *declaration) {
- decl_modifiers_t modifiers = declaration->modifiers;
+ if((c_mode & _MS) == 0)
+ return;
+
+ decl_modifiers_t modifiers = declaration->decl_modifiers;
/* DM_FORCEINLINE handled outside. */
- if((modifiers & ~DM_FORCEINLINE) != 0 || declaration->alignment != 0 ||
+ if((modifiers & ~DM_FORCEINLINE) != 0 ||
+ declaration->alignment != 0 || declaration->deprecated != 0 ||
declaration->get_property_sym != NULL || declaration->put_property_sym != NULL) {
char *next = "(";
if(modifiers & DM_NOINLINE) {
fputs(next, out); next = ", "; fputs("noinline", out);
}
- if(modifiers & DM_DEPRECATED) {
+ if(declaration->deprecated != 0) {
fputs(next, out); next = ", "; fputs("deprecated", out);
if(declaration->deprecated_string != NULL)
fprintf(out, "(\"%s\")", declaration->deprecated_string);
{
print_storage_class((storage_class_tag_t) declaration->declared_storage_class);
if(declaration->is_inline) {
- if(declaration->modifiers & DM_FORCEINLINE)
+ if(declaration->decl_modifiers & DM_FORCEINLINE)
fputs("__forceinline ", out);
else {
- if(declaration->modifiers & DM_MICROSOFT_INLINE)
+ if(declaration->decl_modifiers & DM_MICROSOFT_INLINE)
fputs("__inline ", out);
else
fputs("inline ", out);
}
}
+static bool is_builtin_const_call(const expression_t *expression)
+{
+ expression_t *function = expression->call.function;
+ if (function->kind != EXPR_BUILTIN_SYMBOL) {
+ return false;
+ }
+
+ symbol_t *symbol = function->builtin_symbol.symbol;
+
+ switch (symbol->ID) {
+ case T___builtin_huge_val:
+ case T___builtin_nan:
+ case T___builtin_nanf:
+ case T___builtin_nand:
+ return true;
+ }
+
+ return false;
+}
+
bool is_constant_expression(const expression_t *expression)
{
switch(expression->kind) {
case EXPR_WIDE_STRING_LITERAL:
case EXPR_SIZEOF:
case EXPR_CLASSIFY_TYPE:
- case EXPR_FUNCTION:
- case EXPR_PRETTY_FUNCTION:
+ case EXPR_FUNCNAME:
case EXPR_OFFSETOF:
case EXPR_ALIGNOF:
case EXPR_BUILTIN_CONSTANT_P:
case EXPR_BUILTIN_SYMBOL:
case EXPR_BUILTIN_PREFETCH:
- case EXPR_CALL:
case EXPR_SELECT:
case EXPR_VA_START:
case EXPR_VA_ARG:
case EXPR_UNARY_POSTFIX_DECREMENT:
case EXPR_UNARY_PREFIX_INCREMENT:
case EXPR_UNARY_PREFIX_DECREMENT:
- case EXPR_UNARY_BITFIELD_EXTRACT:
case EXPR_UNARY_ASSUME: /* has VOID type */
case EXPR_UNARY_TAKE_ADDRESS:
case EXPR_UNARY_DEREFERENCE:
case EXPR_BINARY_COMMA:
return false;
+ case EXPR_CALL:
+ return is_builtin_const_call(expression);
+
case EXPR_UNARY_NEGATE:
case EXPR_UNARY_PLUS:
case EXPR_UNARY_BITWISE_NEGATE: