summaryrefslogtreecommitdiff
path: root/tools/m4/convert_base.m4
blob: da5137c418007beae4436e9f15aac46f1b1fe2a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#
#  Define a hashing for names
#
define(`__HASH',`__`'m4_translit(`$*',`ABCDEFGHIJKLMNOPQRSTUVWXYZ<>[]&*, ',`abcdefghijklmnopqrstuvwxyzVBNMRSC_')`'')
define(`__EQUIV',`m4_ifdef(EV`'__HASH(`$1'),EV`'__HASH(`$1'),`$1')')

dnl __HASH2(firsttype, secondtype)
dnl
dnl Provides a textual combination of the two given types which can be used as
dnl a hash to store and retrieve conversions and initializations.  It first
dnl sees if the two types have equivalent types that should be used in their
dnl places (using the __EQUIV macro above).  Since the types returned by
dnl __EQUIV may contain commas (because of types such as std::map<>), quote the
dnl call to the macro to avoid the types to be interpreted as more than one
dnl argument to the pushdef() calls.  Also quote the expansion of the __E1 and
dnl __E2 macros in the m4_ifelse for the same reason.
define(`__HASH2',`dnl
pushdef(`__E1',`__EQUIV(`$1')')pushdef(`__E2',`__EQUIV(`$2')')dnl
m4_ifelse(_QUOTE(__E1),_QUOTE(__E2),`__EQ',__HASH(__E1)`'__HASH(__E2))`'dnl
popdef(`__E1')popdef(`__E2')`'')

define(`CF__EQ',`$3')

#  _CONVERT(fromtype, totype, name, wrap_line)
#
#    Print the conversion from 'fromtype' to 'totype'
define(`_CONVERT',`dnl
m4_ifelse(`$2',void,`$3',`dnl
pushdef(`__COV',`CF`'__HASH2(`$1',`$2')')dnl
m4_ifdef(__COV,`m4_indir(__COV,`$1',`$2',`$3')',`
m4_errprint(`No conversion from $1 to $2 defined (line: $4, parameter name: $3)
')
m4_m4exit(1)
')`'dnl
')`'dnl
')


# _CONVERSION(fromtype, totype, conversion)
#
#  Functions for populating the tables.
#
define(`_CONVERSION',`
m4_ifelse(`$3',,,`define(CF`'__HASH2(`$1',`$2'),`$3')')
')

define(`_EQUAL',`define(EV`'__HASH(`$1'),`$2')')

/*******************************************************************/


define(`__ARG3__',`$`'3')

# _CONV_ENUM(namespace, enum_name[, C_enum_name])
# Specify C_enum_name, if it's not the concatenation of namespace+enum_name.
define(`_CONV_ENUM',`dnl
pushdef(`C_ENUM_NAME', `m4_ifelse(`$3',,`$1$2',`$3')')
_CONVERSION(`C_ENUM_NAME', `$2', static_cast<$2>(__ARG3__))
_CONVERSION(`C_ENUM_NAME', `$1::$2', static_cast<$1::$2>(__ARG3__))
_CONVERSION(`$2', `C_ENUM_NAME', static_cast<C_ENUM_NAME>(__ARG3__))
_CONVERSION(`$1::$2', `C_ENUM_NAME', static_cast<C_ENUM_NAME>(__ARG3__))
popdef(`C_ENUM_NAME')
')dnl

# _CONV_INCLASS_ENUM(namespace, class_name, enum_name[, C_enum_name])
# Specify C_enum_name, if it's not the concatenation of namespace+class_name+enum_name.
define(`_CONV_INCLASS_ENUM',`dnl
pushdef(`C_ENUM_NAME', `m4_ifelse(`$4',,`$1$2$3',`$4')')
_CONVERSION(`C_ENUM_NAME', `$3', static_cast<$3>(__ARG3__))
_CONVERSION(`C_ENUM_NAME', `$2::$3', static_cast<$2::$3>(__ARG3__))
_CONVERSION(`C_ENUM_NAME', `$1::$2::$3', static_cast<$1::$2::$3>(__ARG3__))
_CONVERSION(`$3', `C_ENUM_NAME', static_cast<C_ENUM_NAME>(__ARG3__))
_CONVERSION(`$2::$3', `C_ENUM_NAME', static_cast<C_ENUM_NAME>(__ARG3__))
_CONVERSION(`$1::$2::$3', `C_ENUM_NAME', static_cast<C_ENUM_NAME>(__ARG3__))
popdef(`C_ENUM_NAME')
')dnl

# e.g. Glib::RefPtr<Gdk::Something> to GdkSomething*
define(`__CONVERT_REFPTR_TO_P',`Glib::unwrap($`'3)')

define(`__FR2P',`($`'3).gobj()')
define(`__CFR2P',`const_cast<$`'2>($`'3.gobj())')
define(`__FCR2P',`const_cast<$`'2>(($`'3).gobj())')

define(`__FL2H_SHALLOW',`$`'2($`'3, Glib::OWNERSHIP_SHALLOW)')

# e.g. Glib::RefPtr<const Gdk::Something> to GdkSomething*
#define(`__CONVERT_CONST_REFPTR_TO_P',`const_cast<$`'2>($`'3->gobj())')
define(`__CONVERT_CONST_REFPTR_TO_P',`const_cast<$`'2>(Glib::unwrap($`'3))')

# The Sun Forte compiler doesn't seem to be able to handle these, so we are using the altlernative,  __CONVERT_CONST_REFPTR_TO_P_SUN.
# The Sun compiler gives this error, for instance:
#  "widget.cc", line 4463: Error: Overloading ambiguity between "Glib::unwrap<Gdk::Window>(const Glib::RefPtr<const Gdk::Window>&)" and
# "Glib::unwrap<const Gdk::Window>(const Glib::RefPtr<const Gdk::Window>&)".
#
define(`__CONVERT_CONST_REFPTR_TO_P_SUN',`const_cast<$`'2>(Glib::unwrap<$1>($`'3))')


#include(convert_gtk.m4)
#include(convert_pango.m4)
#include(convert_gdk.m4)
#include(convert_atk.m4)
include(convert_glib.m4)