Commit 4c016457 by Janne Blomqvist

fortran: C++ support for generating C prototypes

When generating C prototypes for Fortran procedures with the
-fc-prototypes and -fc-prototypes-external options, print a snippet
defining macros for complex types, and add C++ support by suppressing
mangling.

fortran/ChangeLog:

2019-05-12  Janne Blomqvist  <jb@gcc.gnu.org>

	* dump-parse-tree.c (get_c_type_name): Use macros for complex type
	names.
	* parse.c (gfc_parse_file): Define complex macros, add CPP support
	when printing C prototypes.

From-SVN: r271106
parent 1fa26ccd
2019-05-12 Janne Blomqvist <jb@gcc.gnu.org>
* dump-parse-tree.c (get_c_type_name): Use macros for complex type
names.
* parse.c (gfc_parse_file): Define complex macros, add CPP support
when printing C prototypes.
2019-05-10 Thomas Koenig <tkoenig@gcc.gnu.org> 2019-05-10 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/61968 PR fortran/61968
......
...@@ -3143,11 +3143,11 @@ get_c_type_name (gfc_typespec *ts, gfc_array_spec *as, const char **pre, ...@@ -3143,11 +3143,11 @@ get_c_type_name (gfc_typespec *ts, gfc_array_spec *as, const char **pre,
else if (strcmp (*type_name, "size_t") == 0) else if (strcmp (*type_name, "size_t") == 0)
*type_name = "ssize_t"; *type_name = "ssize_t";
else if (strcmp (*type_name, "float_complex") == 0) else if (strcmp (*type_name, "float_complex") == 0)
*type_name = "float complex"; *type_name = "__GFORTRAN_FLOAT_COMPLEX";
else if (strcmp (*type_name, "double_complex") == 0) else if (strcmp (*type_name, "double_complex") == 0)
*type_name = "double complex"; *type_name = "__GFORTRAN_DOUBLE_COMPLEX";
else if (strcmp (*type_name, "long_double_complex") == 0) else if (strcmp (*type_name, "long_double_complex") == 0)
*type_name = "long double complex"; *type_name = "__GFORTRAN_LONG_DOUBLE_COMPLEX";
ret = T_OK; ret = T_OK;
} }
...@@ -3166,11 +3166,11 @@ get_c_type_name (gfc_typespec *ts, gfc_array_spec *as, const char **pre, ...@@ -3166,11 +3166,11 @@ get_c_type_name (gfc_typespec *ts, gfc_array_spec *as, const char **pre,
else if (strcmp (*type_name, "size_t") == 0) else if (strcmp (*type_name, "size_t") == 0)
*type_name = "ssize_t"; *type_name = "ssize_t";
else if (strcmp (*type_name, "float_complex") == 0) else if (strcmp (*type_name, "float_complex") == 0)
*type_name = "float complex"; *type_name = "__GFORTRAN_FLOAT_COMPLEX";
else if (strcmp (*type_name, "double_complex") == 0) else if (strcmp (*type_name, "double_complex") == 0)
*type_name = "double complex"; *type_name = "__GFORTRAN_DOUBLE_COMPLEX";
else if (strcmp (*type_name, "long_double_complex") == 0) else if (strcmp (*type_name, "long_double_complex") == 0)
*type_name = "long double complex"; *type_name = "__GFORTRAN_LONG_DOUBLE_COMPLEX";
ret = T_WARN; ret = T_WARN;
break; break;
......
...@@ -6331,6 +6331,24 @@ done: ...@@ -6331,6 +6331,24 @@ done:
} }
/* Dump C prototypes. */ /* Dump C prototypes. */
if (flag_c_prototypes || flag_c_prototypes_external)
{
fprintf (stdout,
_("#include <stddef.h>\n"
"#ifdef __cplusplus\n"
"#include <complex>\n"
"#define __GFORTRAN_FLOAT_COMPLEX std::complex<float>\n"
"#define __GFORTRAN_DOUBLE_COMPLEX std::complex<double>\n"
"#define __GFORTRAN_LONG_DOUBLE_COMPLEX std::complex<long double>\n"
"extern \"C\" {\n"
"#else\n"
"#define __GFORTRAN_FLOAT_COMPLEX float _Complex\n"
"#define __GFORTRAN_DOUBLE_COMPLEX double _Complex\n"
"#define __GFORTRAN_LONG_DOUBLE_COMPLEX long double _Complex\n"
"#endif\n\n"));
}
/* First dump BIND(C) prototypes. */
if (flag_c_prototypes) if (flag_c_prototypes)
{ {
for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns; for (gfc_current_ns = gfc_global_ns_list; gfc_current_ns;
...@@ -6342,6 +6360,10 @@ done: ...@@ -6342,6 +6360,10 @@ done:
if (flag_c_prototypes_external) if (flag_c_prototypes_external)
gfc_dump_external_c_prototypes (stdout); gfc_dump_external_c_prototypes (stdout);
if (flag_c_prototypes || flag_c_prototypes_external)
fprintf (stdout,
_("\n#ifdef __cplusplus\n}\n#endif\n"));
/* Do the translation. */ /* Do the translation. */
translate_all_program_units (gfc_global_ns_list); translate_all_program_units (gfc_global_ns_list);
......
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