unit: Use stdbool instead gboolean or near_bool_t
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Wed, 14 Aug 2013 07:27:54 +0000 (09:27 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Tue, 20 Aug 2013 09:05:30 +0000 (11:05 +0200)
commit60da653272e16348360f1daa422cac6b9b55c04f
tree9e16439b1821c653c9068e67ab908e096bdd025a
parent826ac6bb2b7af69d06a339bb5564cdb54a67e697
unit: Use stdbool instead gboolean or near_bool_t

This patch has been created via coccinelle:

// Rule set 1
f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
 ,...)

@r2@
type T;
identifier f;
parameter list[n] ps;
identifier i;
@@

T f(ps, near_bool_t i, ...);

@@
identifier r2.f;
expression list [r.n] es;
@@

f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
 ,...)

@@
typedef bool;
@@

- near_bool_t
+ bool

// Rule set 2

// This is not a beautiful script but it does the job.
// Improvemtents are welcome.

// Fix all assigments but do not convert yet the type
@@
gboolean x;
@@

x =
(
- TRUE
+ true
|
- FALSE
+ false
)

// Figure out which function signature will to be fixed...
// when we have the defitition
@r@
identifier f;
parameter list[n] ps;
identifier i;
@@

f(ps, gboolean i, ...) { ... }

// ... and now convert all call sites
@@
identifier r.f;
expression list [r.n] es;
@@

f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
 ,...)

// Figure out which function signature will to be fixed...
// when we have the declaration only
@r2@
type T;
identifier f;
parameter list[n] ps;
identifier i;
@@

T f(ps, gboolean i, ...);

// ... and now convert all call sites
@@
identifier r2.f;
expression list [r.n] es;
@@

f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
 ,...)

// A handfull of the GLib hooks we can't change. Let's remember
// all ther positions.
// 1. timeouts
@k1@
identifier f;
position p;
typedef gpointer;
identifier ptr;
@@

static gboolean@p f(gpointer ptr);

@k2@
identifier f;
position p;
identifier ptr;
@@

static gboolean@p f(gpointer ptr) { ... }

// hash map iterator functions
@k3@
identifier f;
position p;
identifier p1, p2, p3;
@@

static gboolean@p f(gpointer p1, gpointer p2, gpointer p3) { ... }

// 2. GIOChannel
@k4@
identifier f;
position p;
typedef GIOChannel, GIOCondition;
identifier ptr;
identifier ch, cn;
@@

static gboolean@p f(GIOChannel *ch, GIOCondition cn, gpointer ptr);

@k5@
identifier f;
position p;
identifier ptr;
identifier ch, cn;
@@

static gboolean@p f(GIOChannel *ch, GIOCondition cn, gpointer ptr) { ... }

// 3. GSourceFuncs
@k6@
identifier f;
position p;
typedef GSource;
identifier src;
@@

static gboolean@p f(GSource *src, ...) { ... }

// gdbus functions
@k7@
identifier f;
position p;
typedef DBusConnection;
identifier con;
@@

static gboolean@p f(DBusConnection *con, ...) { ... }

// Now convert all gboolean which are are not used for interactin
// with GLib
// Note here happens the magic!
@@
typedef bool;
position p != {k1.p,k2.p,k3.p,k4.p,k5.p,k6.p,k7.p};
@@

- gboolean@p
+ bool

// Update all return types
@@
identifier f;
@@
bool f(...) {
<...
- return TRUE;
+ return true;
...>
}

@@
identifier f;
@@
bool f(...) {
<...
- return FALSE;
+ return false;
...>
}

// Rule set 3
@@
expression E;
symbol TRUE;
symbol FALSE;
@@

(
E
- == TRUE
|
- TRUE == E
+ E
|
- E != TRUE
+ !E
|
- TRUE != E
+ !E
|
- E == FALSE
+ !E
|
- FALSE == E
+ !E
|
E
- != FALSE
|
- FALSE != E
+ E
)
unit/test-snep-read.c