X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=nesc.git;a=blobdiff_plain;f=src%2Funparse.c;fp=src%2Funparse.c;h=e0d083272fbfa11caf889e4510d67384d861cee9;hp=432ae96b243bb185b9b00e7d15dcbbf22a187859;hb=7b54393e237ed8f23c0c74f0a6cbc8de26c5bf98;hpb=57d4530c4d6814fa25338a00cc65b95938c723b6 diff --git a/src/unparse.c b/src/unparse.c index 432ae96..e0d0832 100644 --- a/src/unparse.c +++ b/src/unparse.c @@ -391,6 +391,7 @@ void prt_typename(typename tname, psd_options options); void prt_typeof_expr(typeof_expr texpr); void prt_typeof_type(typeof_type ttype); void prt_gcc_attribute(gcc_attribute a); +void prt_target_attribute(target_attribute a); void prt_nesc_attribute(nesc_attribute a); void prt_rid(rid r, psd_options options); void prt_qualifier(qualifier q); @@ -592,17 +593,6 @@ void prt_ellipsis_decl(ellipsis_decl d) output("..."); } -static type_element interesting_element(type_element elems) -{ - type_element elem; - - scan_type_element (elem, elems) - if (is_tag_ref(elem)) - return elem; - - return NULL; -} - static void prt_prefix(location loc, data_declaration ddecl, type_element modifiers) { @@ -819,7 +809,8 @@ void prt_function_body(function_decl d) prt_diff_info(d->ddecl); prt_prefix(d->location, d->ddecl, d->modifiers); /* gcc wants the attributes here */ - prt_type_elements(CAST(type_element, d->attributes), 0); + prt_type_elements(CAST(type_element, d->attributes), + flag_gccize ? 0 : psd_no_target_attributes); if (ret) { @@ -831,6 +822,9 @@ void prt_function_body(function_decl d) prt_declarator(d->declarator, d->modifiers, NULL, d->ddecl, psd_print_default); + if (!flag_gccize) + prt_type_elements(CAST(type_element, d->attributes), psd_only_target_attributes); + startline(); prt_parameter_declarations(d->old_parms); extrablock = prt_network_parameter_copies(d); @@ -865,15 +859,15 @@ void prt_variable_decl(type_element modifiers, variable_decl d, else prt_declarator(d->declarator, modifiers, NULL, d->ddecl, options); + if (d->asm_stmt) + prt_asm_stmt_plain(d->asm_stmt); + if (d->attributes) { output(" "); prt_type_elements(CAST(type_element, d->attributes), 0); } - if (d->asm_stmt) - prt_asm_stmt_plain(d->asm_stmt); - if (d->arg1 && !(use_nido && is_module_variable(d->ddecl))) { output(" = "); @@ -1116,6 +1110,14 @@ void prt_interesting_elements(type_element elements, psd_options options) bool prt_type_element(type_element em, psd_options options) { + if ((options & psd_only_target_attributes) && + em->kind != kind_target_attribute) + return FALSE; + + if ((options & psd_no_target_attributes) && + em->kind == kind_target_attribute) + return FALSE; + switch (em->kind) { case kind_component_typeref: /* fall through to prt_typename */ @@ -1123,6 +1125,12 @@ bool prt_type_element(type_element em, psd_options options) case kind_typeof_expr: prt_typeof_expr(CAST(typeof_expr, em)); break; case kind_typeof_type: prt_typeof_type(CAST(typeof_type, em)); break; case kind_gcc_attribute: prt_gcc_attribute(CAST(gcc_attribute, em)); break; + case kind_target_attribute: + if (flag_gccize) + prt_gcc_attribute(CAST(gcc_attribute, em)); + else + prt_target_attribute(CAST(target_attribute, em)); + break; case kind_nesc_attribute: prt_nesc_attribute(CAST(nesc_attribute, em)); break; case kind_qualifier: prt_qualifier(CAST(qualifier, em)); break; case kind_rid: @@ -1149,6 +1157,7 @@ bool prt_attribute_element(type_element em) switch (em->kind) { case kind_gcc_attribute: + case kind_target_attribute: prt_gcc_attribute(CAST(gcc_attribute, em)); return TRUE; case kind_nesc_attribute: @@ -1203,6 +1212,22 @@ void prt_gcc_attribute(gcc_attribute a) } } +void prt_target_attribute(target_attribute a) +{ + set_location(a->location); + if (!strcmp(a->word1->cstring.data, "iar_at")) + output("@"); + else if (!strcmp(a->word1->cstring.data, "keil_address")) + output("="); + else + prt_word(a->word1); + if (a->args) + { + output(" "); + prt_expressions(a->args, TRUE); + } +} + void prt_nesc_attribute(nesc_attribute a) { /* If the attribute has a macro_name, then print attribute like @@ -1887,9 +1912,24 @@ void prt_binary(binary e, int context_priority) } break; case kind_leq: case kind_geq: case kind_lt: case kind_gt: - lpri = P_REL; pri = P_REL; rpri = P_SHIFT; break; + pri = P_REL; + if (CONSERVATIVE_PARENS) + lpri = rpri = P_PLUS; + else + { + lpri = P_REL; rpri = P_SHIFT; + } + break; case kind_eq: case kind_ne: - lpri = P_EQUALS; pri = P_EQUALS; rpri = P_REL; break; + pri = P_EQUALS; + if (CONSERVATIVE_PARENS) + lpri = rpri = P_PLUS; + else + { + lpri = P_EQUALS; + rpri = P_REL; + } + break; case kind_bitand: pri = P_BITAND; if (CONSERVATIVE_PARENS)