Commit f2aa696b by Eric Botcazou Committed by Eric Botcazou

c-ada-spec.c (print_constructor): New function.

	* c-ada-spec.c (print_constructor): New function.
	(print_destructor): Retrieve the origin of the destructor.
	(print_ada_declaration): Revamp handling of constructors/destructors.

From-SVN: r206228
parent 2748936a
2013-12-28 Eric Botcazou <ebotcazou@adacore.com>
* c-ada-spec.c (print_constructor): New function.
(print_destructor): Retrieve the origin of the destructor.
(print_ada_declaration): Revamp handling of constructors/destructors.
2013-12-23 Stuart Hastings <stuart@apple.com> 2013-12-23 Stuart Hastings <stuart@apple.com>
Bill Maddox <maddox@google.com> Bill Maddox <maddox@google.com>
Jason Merrill <jason@redhat.com> Jason Merrill <jason@redhat.com>
......
...@@ -2521,20 +2521,34 @@ dump_nested_types (pretty_printer *buffer, tree t, tree parent, bool forward, ...@@ -2521,20 +2521,34 @@ dump_nested_types (pretty_printer *buffer, tree t, tree parent, bool forward,
TREE_VISITED (t) = 1; TREE_VISITED (t) = 1;
} }
/* Dump in BUFFER constructor spec corresponding to T. */
static void
print_constructor (pretty_printer *buffer, tree t)
{
tree decl_name = DECL_NAME (DECL_ORIGIN (t));
pp_string (buffer, "New_");
pp_ada_tree_identifier (buffer, decl_name, t, false);
}
/* Dump in BUFFER destructor spec corresponding to T. */ /* Dump in BUFFER destructor spec corresponding to T. */
static void static void
print_destructor (pretty_printer *buffer, tree t) print_destructor (pretty_printer *buffer, tree t)
{ {
const char *s = IDENTIFIER_POINTER (DECL_NAME (t)); tree decl_name = DECL_NAME (DECL_ORIGIN (t));
const char *s = IDENTIFIER_POINTER (decl_name);
if (*s == '_') if (*s == '_')
for (s += 2; *s != ' '; s++) {
pp_character (buffer, *s); for (s += 2; *s != ' '; s++)
pp_character (buffer, *s);
}
else else
{ {
pp_string (buffer, "Delete_"); pp_string (buffer, "Delete_");
pp_ada_tree_identifier (buffer, DECL_NAME (t), t, false); pp_ada_tree_identifier (buffer, decl_name, t, false);
} }
} }
...@@ -2785,7 +2799,7 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) ...@@ -2785,7 +2799,7 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc)
} }
else if (TREE_CODE (t) == FUNCTION_DECL) else if (TREE_CODE (t) == FUNCTION_DECL)
{ {
bool is_function = true, is_abstract_class = false; bool is_function, is_abstract_class = false;
bool is_method = TREE_CODE (TREE_TYPE (t)) == METHOD_TYPE; bool is_method = TREE_CODE (TREE_TYPE (t)) == METHOD_TYPE;
tree decl_name = DECL_NAME (t); tree decl_name = DECL_NAME (t);
int prev_in_function = in_function; int prev_in_function = in_function;
...@@ -2805,24 +2819,21 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) ...@@ -2805,24 +2819,21 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc)
is_copy_constructor = cpp_check (t, IS_COPY_CONSTRUCTOR); is_copy_constructor = cpp_check (t, IS_COPY_CONSTRUCTOR);
} }
/* Skip __comp_dtor destructor which is redundant with the '~class()'
destructor. */
if (is_destructor
&& !strncmp (IDENTIFIER_POINTER (decl_name), "__comp", 6))
return 0;
/* Skip copy constructors: some are internal only, and those that are /* Skip copy constructors: some are internal only, and those that are
not cannot be called easily from Ada anyway. */ not cannot be called easily from Ada anyway. */
if (is_copy_constructor) if (is_copy_constructor)
return 0; return 0;
/* If this function has an entry in the dispatch table, we cannot if (is_constructor || is_destructor)
omit it. */
if (!DECL_VINDEX (t) && *IDENTIFIER_POINTER (decl_name) == '_')
{ {
if (IDENTIFIER_POINTER (decl_name)[1] == '_') /* Only consider constructors/destructors for complete objects. */
if (strncmp (IDENTIFIER_POINTER (decl_name), "__comp", 6) != 0)
return 0; return 0;
}
/* If this function has an entry in the vtable, we cannot omit it. */
else if (!DECL_VINDEX (t) && *IDENTIFIER_POINTER (decl_name) == '_')
{
INDENT (spc); INDENT (spc);
pp_string (buffer, "-- skipped func "); pp_string (buffer, "-- skipped func ");
pp_string (buffer, IDENTIFIER_POINTER (decl_name)); pp_string (buffer, IDENTIFIER_POINTER (decl_name));
...@@ -2832,19 +2843,22 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) ...@@ -2832,19 +2843,22 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc)
if (need_indent) if (need_indent)
INDENT (spc); INDENT (spc);
if (is_constructor) if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (t))) && !is_constructor)
pp_string (buffer, "function New_");
else if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
{ {
is_function = false;
pp_string (buffer, "procedure "); pp_string (buffer, "procedure ");
is_function = false;
} }
else else
pp_string (buffer, "function "); {
pp_string (buffer, "function ");
is_function = true;
}
in_function = is_function; in_function = is_function;
if (is_destructor) if (is_constructor)
print_constructor (buffer, t);
else if (is_destructor)
print_destructor (buffer, t); print_destructor (buffer, t);
else else
dump_ada_decl_name (buffer, t, false); dump_ada_decl_name (buffer, t, false);
...@@ -2856,16 +2870,9 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) ...@@ -2856,16 +2870,9 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc)
if (is_function) if (is_function)
{ {
pp_string (buffer, " return "); pp_string (buffer, " return ");
tree ret_type
if (is_constructor) = is_constructor ? DECL_CONTEXT (t) : TREE_TYPE (TREE_TYPE (t));
{ dump_generic_ada_node (buffer, ret_type, type, spc, false, true);
dump_ada_decl_name (buffer, t, false);
}
else
{
dump_generic_ada_node
(buffer, TREE_TYPE (TREE_TYPE (t)), type, spc, false, true);
}
} }
if (is_constructor if (is_constructor
...@@ -2877,7 +2884,7 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) ...@@ -2877,7 +2884,7 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc)
for (tmp = TYPE_METHODS (type); tmp; tmp = TREE_CHAIN (tmp)) for (tmp = TYPE_METHODS (type); tmp; tmp = TREE_CHAIN (tmp))
if (cpp_check (tmp, IS_ABSTRACT)) if (cpp_check (tmp, IS_ABSTRACT))
{ {
is_abstract_class = 1; is_abstract_class = true;
break; break;
} }
} }
...@@ -2896,8 +2903,8 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) ...@@ -2896,8 +2903,8 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc)
if (is_constructor) if (is_constructor)
{ {
pp_string (buffer, "pragma CPP_Constructor (New_"); pp_string (buffer, "pragma CPP_Constructor (");
dump_ada_decl_name (buffer, t, false); print_constructor (buffer, t);
pp_string (buffer, ", \""); pp_string (buffer, ", \"");
pp_asm_name (buffer, t); pp_asm_name (buffer, t);
pp_string (buffer, "\");"); pp_string (buffer, "\");");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment