os/textandloc/fontservices/textshaperplugin/IcuSource/common/utracimp.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
*******************************************************************************
sl@0
     3
*
sl@0
     4
*   Copyright (C) 2003-2004, International Business Machines
sl@0
     5
*   Corporation and others.  All Rights Reserved.
sl@0
     6
*
sl@0
     7
*******************************************************************************
sl@0
     8
*   file name:  utracimp.h
sl@0
     9
*   encoding:   US-ASCII
sl@0
    10
*   tab size:   8 (not used)
sl@0
    11
*   indentation:4
sl@0
    12
*
sl@0
    13
*   created on: 2003aug06
sl@0
    14
*   created by: Markus W. Scherer
sl@0
    15
*
sl@0
    16
*   Internal header for ICU tracing/logging.
sl@0
    17
*
sl@0
    18
*
sl@0
    19
*   Various notes:
sl@0
    20
*   - using a trace level variable to only call trace functions
sl@0
    21
*     when the level is sufficient
sl@0
    22
*   - using the same variable for tracing on/off to never make a function
sl@0
    23
*     call when off
sl@0
    24
*   - the function number is put into a local variable by the entry macro
sl@0
    25
*     and used implicitly to avoid copy&paste/typing mistakes by the developer
sl@0
    26
*   - the application must call utrace_setFunctions() and pass in
sl@0
    27
*     implementations for the trace functions
sl@0
    28
*   - ICU trace macros call ICU functions that route through the function
sl@0
    29
*     pointers if they have been set;
sl@0
    30
*     this avoids an indirection at the call site
sl@0
    31
*     (which would cost more code for another check and for the indirection)
sl@0
    32
*
sl@0
    33
*   ### TODO Issues:
sl@0
    34
*   - Verify that va_list is portable among compilers for the same platform.
sl@0
    35
*     va_list should be portable because printf() would fail otherwise!
sl@0
    36
*   - Should enum values like UTraceLevel be passed into int32_t-type arguments,
sl@0
    37
*     or should enum types be used?
sl@0
    38
*/
sl@0
    39
sl@0
    40
#ifndef __UTRACIMP_H__
sl@0
    41
#define __UTRACIMP_H__
sl@0
    42
sl@0
    43
#include "unicode/utrace.h"
sl@0
    44
#include <stdarg.h>
sl@0
    45
sl@0
    46
U_CDECL_BEGIN
sl@0
    47
sl@0
    48
/**
sl@0
    49
 * \var utrace_level
sl@0
    50
 * Trace level variable. Negative for "off".
sl@0
    51
 * Use only via UTRACE_ macros.
sl@0
    52
 * @internal
sl@0
    53
 */
sl@0
    54
#ifdef UTRACE_IMPL
sl@0
    55
U_EXPORT int32_t
sl@0
    56
#else
sl@0
    57
U_CFUNC U_COMMON_API int32_t
sl@0
    58
#endif
sl@0
    59
utrace_level;
sl@0
    60
sl@0
    61
sl@0
    62
/** 
sl@0
    63
 *   Traced Function Exit return types.  
sl@0
    64
 *   Flags indicating the number and types of varargs included in a call
sl@0
    65
 *   to a UTraceExit function.
sl@0
    66
 *   Bits 0-3:  The function return type.  First variable param.
sl@0
    67
 *   Bit    4:  Flag for presence of U_ErrorCode status param.
sl@0
    68
 *   @internal
sl@0
    69
 */
sl@0
    70
typedef enum UTraceExitVal {
sl@0
    71
    /** The traced function returns no value  @internal */
sl@0
    72
    UTRACE_EXITV_NONE   = 0,
sl@0
    73
    /** The traced function returns an int32_t, or compatible, type.  @internal */
sl@0
    74
    UTRACE_EXITV_I32    = 1,
sl@0
    75
    /** The traced function returns a pointer  @internal */
sl@0
    76
    UTRACE_EXITV_PTR    = 2,
sl@0
    77
    /** The traced function returns a UBool  @internal */
sl@0
    78
    UTRACE_EXITV_BOOL   = 3,
sl@0
    79
    /** Mask to extract the return type values from a UTraceExitVal  @internal */
sl@0
    80
    UTRACE_EXITV_MASK   = 0xf,
sl@0
    81
    /** Bit indicating that the traced function includes a UErrorCode parameter  @internal */
sl@0
    82
    UTRACE_EXITV_STATUS = 0x10
sl@0
    83
} UTraceExitVal;
sl@0
    84
sl@0
    85
/**
sl@0
    86
 * Trace function for the entry point of a function.
sl@0
    87
 * Do not use directly, use UTRACE_ENTRY instead.
sl@0
    88
 * @param fnNumber The UTraceFunctionNumber for the current function.
sl@0
    89
 * @internal
sl@0
    90
 */
sl@0
    91
U_CAPI void U_EXPORT2
sl@0
    92
utrace_entry(int32_t fnNumber);
sl@0
    93
sl@0
    94
/**
sl@0
    95
 * Trace function for each exit point of a function.
sl@0
    96
 * Do not use directly, use UTRACE_EXIT* instead.
sl@0
    97
 * @param fnNumber The UTraceFunctionNumber for the current function.
sl@0
    98
 * @param returnType The type of the value returned by the function.
sl@0
    99
 * @param errorCode The UErrorCode value at function exit. See UTRACE_EXIT.
sl@0
   100
 * @internal
sl@0
   101
 */
sl@0
   102
U_CAPI void U_EXPORT2
sl@0
   103
utrace_exit(int32_t fnNumber, int32_t returnType, ...);
sl@0
   104
sl@0
   105
sl@0
   106
/**
sl@0
   107
 * Trace function used inside functions that have a UTRACE_ENTRY() statement.
sl@0
   108
 * Do not use directly, use UTRACE_DATAX() macros instead.
sl@0
   109
 *
sl@0
   110
 * @param utraceFnNumber The number of the current function, from the local
sl@0
   111
 *        variable of the same name.
sl@0
   112
 * @param level The trace level for this message.
sl@0
   113
 * @param fmt The trace format string.
sl@0
   114
 *
sl@0
   115
 * @internal
sl@0
   116
 */
sl@0
   117
U_CAPI void U_EXPORT2
sl@0
   118
utrace_data(int32_t utraceFnNumber, int32_t level, const char *fmt, ...);
sl@0
   119
sl@0
   120
U_CDECL_END
sl@0
   121
sl@0
   122
#if U_ENABLE_TRACING
sl@0
   123
sl@0
   124
/**
sl@0
   125
 * Boolean expression to see if ICU tracing is turned on
sl@0
   126
 * to at least the specified level.
sl@0
   127
 * @internal
sl@0
   128
 */
sl@0
   129
#define UTRACE_LEVEL(level) (utrace_level>=(level))
sl@0
   130
sl@0
   131
/**
sl@0
   132
  *  Flag bit in utraceFnNumber, the local variable added to each function 
sl@0
   133
  *  with tracing code to contains the function number.
sl@0
   134
  *
sl@0
   135
  *  Set the flag if the function's entry is traced, which will cause the
sl@0
   136
  *  function's exit to also be traced.  utraceFnNumber is uncoditionally 
sl@0
   137
  *  set at entry, whether or not the entry is traced, so that it will
sl@0
   138
  *  always be available for error trace output.
sl@0
   139
  *  @internal
sl@0
   140
  */            
sl@0
   141
#define UTRACE_TRACED_ENTRY 0x80000000
sl@0
   142
sl@0
   143
/**
sl@0
   144
 * Trace statement for the entry point of a function.
sl@0
   145
 * Stores the function number in a local variable.
sl@0
   146
 * In C code, must be placed immediately after the last variable declaration.
sl@0
   147
 * Must be matched with UTRACE_EXIT() at all function exit points.
sl@0
   148
 *
sl@0
   149
 * Tracing should start with UTRACE_ENTRY after checking for
sl@0
   150
 * U_FAILURE at function entry, so that if a function returns immediately
sl@0
   151
 * because of a pre-existing error condition, it does not show up in the trace,
sl@0
   152
 * consistent with ICU's error handling model.
sl@0
   153
 *
sl@0
   154
 * @param fnNumber The UTraceFunctionNumber for the current function.
sl@0
   155
 * @internal
sl@0
   156
 */
sl@0
   157
#define UTRACE_ENTRY(fnNumber) \
sl@0
   158
    int32_t utraceFnNumber=(fnNumber); \
sl@0
   159
    if(utrace_level>=UTRACE_INFO) { \
sl@0
   160
        utrace_entry(fnNumber); \
sl@0
   161
        utraceFnNumber |= UTRACE_TRACED_ENTRY; \
sl@0
   162
    }
sl@0
   163
sl@0
   164
sl@0
   165
/**
sl@0
   166
 * Trace statement for the entry point of open and close functions.
sl@0
   167
 * Produces trace output at a less verbose setting than plain UTRACE_ENTRY
sl@0
   168
 * Stores the function number in a local variable.
sl@0
   169
 * In C code, must be placed immediately after the last variable declaration.
sl@0
   170
 * Must be matched with UTRACE_EXIT() at all function exit points.
sl@0
   171
 *
sl@0
   172
 * @param fnNumber The UTraceFunctionNumber for the current function.
sl@0
   173
 * @internal
sl@0
   174
 */
sl@0
   175
#define UTRACE_ENTRY_OC(fnNumber) \
sl@0
   176
    int32_t utraceFnNumber=(fnNumber); \
sl@0
   177
    if(utrace_level>=UTRACE_OPEN_CLOSE) { \
sl@0
   178
        utrace_entry(fnNumber); \
sl@0
   179
        utraceFnNumber |= UTRACE_TRACED_ENTRY; \
sl@0
   180
    }
sl@0
   181
sl@0
   182
/**
sl@0
   183
 * Trace statement for each exit point of a function that has a UTRACE_ENTRY()
sl@0
   184
 * statement.
sl@0
   185
 *
sl@0
   186
 * @param errorCode The function's ICU UErrorCode value at function exit,
sl@0
   187
 *                  or U_ZERO_ERROR if the function does not use a UErrorCode.
sl@0
   188
 *                  0==U_ZERO_ERROR indicates success,
sl@0
   189
 *                  positive values an error (see u_errorName()),
sl@0
   190
 *                  negative values an informational status.
sl@0
   191
 *
sl@0
   192
 * @internal
sl@0
   193
 */
sl@0
   194
#define UTRACE_EXIT() \
sl@0
   195
    {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
sl@0
   196
        utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_NONE); \
sl@0
   197
    }}
sl@0
   198
sl@0
   199
/**
sl@0
   200
 * Trace statement for each exit point of a function that has a UTRACE_ENTRY()
sl@0
   201
 * statement, and that returns a value.
sl@0
   202
 *
sl@0
   203
 * @param val       The function's return value, int32_t or comatible type.
sl@0
   204
 *
sl@0
   205
 * @internal 
sl@0
   206
 */
sl@0
   207
#define UTRACE_EXIT_VALUE(val) \
sl@0
   208
    {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
sl@0
   209
        utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_I32, val); \
sl@0
   210
    }}
sl@0
   211
sl@0
   212
#define UTRACE_EXIT_STATUS(status) \
sl@0
   213
    {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
sl@0
   214
        utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_STATUS, status); \
sl@0
   215
    }}
sl@0
   216
sl@0
   217
#define UTRACE_EXIT_VALUE_STATUS(val, status) \
sl@0
   218
    {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
sl@0
   219
        utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (UTRACE_EXITV_I32 | UTRACE_EXITV_STATUS), val, status); \
sl@0
   220
    }}
sl@0
   221
sl@0
   222
#define UTRACE_EXIT_PTR_STATUS(ptr, status) \
sl@0
   223
    {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
sl@0
   224
        utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (UTRACE_EXITV_PTR | UTRACE_EXITV_STATUS), ptr, status); \
sl@0
   225
    }}
sl@0
   226
sl@0
   227
/**
sl@0
   228
 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
sl@0
   229
 * Takes no data arguments.
sl@0
   230
 * The number of arguments for this macro must match the number of inserts
sl@0
   231
 * in the format string. Vector inserts count as two arguments.
sl@0
   232
 * Calls utrace_data() if the level is high enough.
sl@0
   233
 * @internal
sl@0
   234
 */
sl@0
   235
#define UTRACE_DATA0(level, fmt) \
sl@0
   236
    if(UTRACE_LEVEL(level)) { \
sl@0
   237
        utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt)); \
sl@0
   238
    }
sl@0
   239
sl@0
   240
/**
sl@0
   241
 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
sl@0
   242
 * Takes one data argument.
sl@0
   243
 * The number of arguments for this macro must match the number of inserts
sl@0
   244
 * in the format string. Vector inserts count as two arguments.
sl@0
   245
 * Calls utrace_data() if the level is high enough.
sl@0
   246
 * @internal
sl@0
   247
 */
sl@0
   248
#define UTRACE_DATA1(level, fmt, a) \
sl@0
   249
    if(UTRACE_LEVEL(level)) { \
sl@0
   250
        utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY , (level), (fmt), (a)); \
sl@0
   251
    }
sl@0
   252
sl@0
   253
/**
sl@0
   254
 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
sl@0
   255
 * Takes two data arguments.
sl@0
   256
 * The number of arguments for this macro must match the number of inserts
sl@0
   257
 * in the format string. Vector inserts count as two arguments.
sl@0
   258
 * Calls utrace_data() if the level is high enough.
sl@0
   259
 * @internal
sl@0
   260
 */
sl@0
   261
#define UTRACE_DATA2(level, fmt, a, b) \
sl@0
   262
    if(UTRACE_LEVEL(level)) { \
sl@0
   263
        utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY , (level), (fmt), (a), (b)); \
sl@0
   264
    }
sl@0
   265
sl@0
   266
/**
sl@0
   267
 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
sl@0
   268
 * Takes three data arguments.
sl@0
   269
 * The number of arguments for this macro must match the number of inserts
sl@0
   270
 * in the format string. Vector inserts count as two arguments.
sl@0
   271
 * Calls utrace_data() if the level is high enough.
sl@0
   272
 * @internal
sl@0
   273
 */
sl@0
   274
#define UTRACE_DATA3(level, fmt, a, b, c) \
sl@0
   275
    if(UTRACE_LEVEL(level)) { \
sl@0
   276
        utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c)); \
sl@0
   277
    }
sl@0
   278
sl@0
   279
/**
sl@0
   280
 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
sl@0
   281
 * Takes four data arguments.
sl@0
   282
 * The number of arguments for this macro must match the number of inserts
sl@0
   283
 * in the format string. Vector inserts count as two arguments.
sl@0
   284
 * Calls utrace_data() if the level is high enough.
sl@0
   285
 * @internal
sl@0
   286
 */
sl@0
   287
#define UTRACE_DATA4(level, fmt, a, b, c, d) \
sl@0
   288
    if(UTRACE_LEVEL(level)) { \
sl@0
   289
        utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d)); \
sl@0
   290
    }
sl@0
   291
sl@0
   292
/**
sl@0
   293
 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
sl@0
   294
 * Takes five data arguments.
sl@0
   295
 * The number of arguments for this macro must match the number of inserts
sl@0
   296
 * in the format string. Vector inserts count as two arguments.
sl@0
   297
 * Calls utrace_data() if the level is high enough.
sl@0
   298
 * @internal
sl@0
   299
 */
sl@0
   300
#define UTRACE_DATA5(level, fmt, a, b, c, d, e) \
sl@0
   301
    if(UTRACE_LEVEL(level)) { \
sl@0
   302
        utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e)); \
sl@0
   303
    }
sl@0
   304
sl@0
   305
/**
sl@0
   306
 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
sl@0
   307
 * Takes six data arguments.
sl@0
   308
 * The number of arguments for this macro must match the number of inserts
sl@0
   309
 * in the format string. Vector inserts count as two arguments.
sl@0
   310
 * Calls utrace_data() if the level is high enough.
sl@0
   311
 * @internal
sl@0
   312
 */
sl@0
   313
#define UTRACE_DATA6(level, fmt, a, b, c, d, e, f) \
sl@0
   314
    if(UTRACE_LEVEL(level)) { \
sl@0
   315
        utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f)); \
sl@0
   316
    }
sl@0
   317
sl@0
   318
/**
sl@0
   319
 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
sl@0
   320
 * Takes seven data arguments.
sl@0
   321
 * The number of arguments for this macro must match the number of inserts
sl@0
   322
 * in the format string. Vector inserts count as two arguments.
sl@0
   323
 * Calls utrace_data() if the level is high enough.
sl@0
   324
 * @internal
sl@0
   325
 */
sl@0
   326
#define UTRACE_DATA7(level, fmt, a, b, c, d, e, f, g) \
sl@0
   327
    if(UTRACE_LEVEL(level)) { \
sl@0
   328
        utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g)); \
sl@0
   329
    }
sl@0
   330
sl@0
   331
/**
sl@0
   332
 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
sl@0
   333
 * Takes eight data arguments.
sl@0
   334
 * The number of arguments for this macro must match the number of inserts
sl@0
   335
 * in the format string. Vector inserts count as two arguments.
sl@0
   336
 * Calls utrace_data() if the level is high enough.
sl@0
   337
 * @internal
sl@0
   338
 */
sl@0
   339
#define UTRACE_DATA8(level, fmt, a, b, c, d, e, f, g, h) \
sl@0
   340
    if(UTRACE_LEVEL(level)) { \
sl@0
   341
        utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h)); \
sl@0
   342
    }
sl@0
   343
sl@0
   344
/**
sl@0
   345
 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
sl@0
   346
 * Takes nine data arguments.
sl@0
   347
 * The number of arguments for this macro must match the number of inserts
sl@0
   348
 * in the format string. Vector inserts count as two arguments.
sl@0
   349
 * Calls utrace_data() if the level is high enough.
sl@0
   350
 * @internal
sl@0
   351
 */
sl@0
   352
#define UTRACE_DATA9(level, fmt, a, b, c, d, e, f, g, h, i) \
sl@0
   353
    if(UTRACE_LEVEL(level)) { \
sl@0
   354
        utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h), (i)); \
sl@0
   355
    }
sl@0
   356
sl@0
   357
#else
sl@0
   358
sl@0
   359
/*
sl@0
   360
 * When tracing is disabled, the following macros become empty
sl@0
   361
 */
sl@0
   362
sl@0
   363
#define UTRACE_LEVEL(level) 0
sl@0
   364
#define UTRACE_ENTRY(fnNumber)
sl@0
   365
#define UTRACE_ENTRY_OC(fnNumber)
sl@0
   366
#define UTRACE_EXIT()
sl@0
   367
#define UTRACE_EXIT_VALUE(val)
sl@0
   368
#define UTRACE_EXIT_STATUS(status)
sl@0
   369
#define UTRACE_EXIT_VALUE_STATUS(val, status)
sl@0
   370
#define UTRACE_EXIT_PTR_STATUS(ptr, status)
sl@0
   371
#define UTRACE_DATA0(level, fmt)
sl@0
   372
#define UTRACE_DATA1(level, fmt, a)
sl@0
   373
#define UTRACE_DATA2(level, fmt, a, b)
sl@0
   374
#define UTRACE_DATA3(level, fmt, a, b, c)
sl@0
   375
#define UTRACE_DATA4(level, fmt, a, b, c, d)
sl@0
   376
#define UTRACE_DATA5(level, fmt, a, b, c, d, e)
sl@0
   377
#define UTRACE_DATA6(level, fmt, a, b, c, d, e, f)
sl@0
   378
#define UTRACE_DATA7(level, fmt, a, b, c, d, e, f, g)
sl@0
   379
#define UTRACE_DATA8(level, fmt, a, b, c, d, e, f, g, h)
sl@0
   380
#define UTRACE_DATA9(level, fmt, a, b, c, d, e, f, g, h, i)
sl@0
   381
sl@0
   382
#endif
sl@0
   383
sl@0
   384
#endif