summaryrefslogtreecommitdiff
path: root/src/mcpp-macro.h
blob: 719972c1de690e1ac1b69b8d261f7f19dbb521b5 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef __MCPU_CPP_MACRO_H__
#define __MCPU_CPP_MACRO_H__ 1

#include <defs.h>
#include <mcpp-language.h>
#include <mcpp-text.h>

#define MCPU_CPP_MACRO_BUCKETS 257
#define MCPU_CPP_MACRO_EXPANSION_LIMIT 400

enum mcpu_macro_origin
{
  MCPU_MACRO_ORIGIN_SOURCE = 0,
  MCPU_MACRO_ORIGIN_BUILTIN,
  MCPU_MACRO_ORIGIN_COMMAND_LINE
};


enum mcpu_macro_builtin
{
  MCPU_MACRO_BUILTIN_NONE = 0,
  MCPU_MACRO_BUILTIN_FILE,
  MCPU_MACRO_BUILTIN_LINE,
  MCPU_MACRO_BUILTIN_DATE,
  MCPU_MACRO_BUILTIN_TIME,
  MCPU_MACRO_BUILTIN_BASE_FILE,
  MCPU_MACRO_BUILTIN_INCLUDE_LEVEL,
  MCPU_MACRO_BUILTIN_REAL_MAX,
  MCPU_MACRO_BUILTIN_REAL_MIN,
  MCPU_MACRO_BUILTIN_REAL_EPSILON,
  MCPU_MACRO_BUILTIN_REAL_MAX_EXP,
  MCPU_MACRO_BUILTIN_REAL_MIN_EXP,
  MCPU_MACRO_BUILTIN_REAL_MAX_10_EXP,
  MCPU_MACRO_BUILTIN_REAL_MIN_10_EXP
};

typedef struct mcpp_options mcpp_options;
typedef struct mcpu_macro_expansion_context mcpu_macro_expansion_context;
struct mcpu_macro_expansion_context
{
  const char *filename;
  const char *base_filename;
  unsigned    line_number;
  size_t      include_level;
  const char *date;
  const char         *time;
  const mcpp_options *options;
};

typedef struct mcpu_macro mcpu_macro;
struct mcpu_macro
{
  __mpu_char16_t  *name;
  size_t           name_length;

  int              nargs;
  int              variadic;
  __mpu_char16_t **argnames;
  size_t          *argname_lengths;

  __mpu_char16_t  *replacement;
  size_t           replacement_length;

  enum mcpu_macro_builtin builtin;
  enum mcpu_macro_origin  origin;
  unsigned                builtin_bits;
  int                     expanding;
  mcpu_macro      *next;
};

typedef struct mcpu_macro_table mcpu_macro_table;
struct mcpu_macro_table
{
  mcpu_macro *bucket[MCPU_CPP_MACRO_BUCKETS];
};

void mcpu_macro_table_init( mcpu_macro_table *table );
void mcpu_macro_table_free( mcpu_macro_table *table );
mcpu_macro *mcpu_macro_find( mcpu_macro_table *table,
                             const __mpu_char16_t *name,
                             size_t name_length );
int  mcpu_macro_define_object( mcpu_macro_table *table,
                               const __mpu_char16_t *name,
                               size_t name_length,
                               const __mpu_char16_t *replacement,
                               size_t replacement_length,
                               enum mcpu_macro_origin origin );
int  mcpu_macro_define_builtin( mcpu_macro_table *table,
                                const __mpu_char16_t *name,
                                size_t name_length,
                                enum mcpu_macro_builtin builtin );
int  mcpu_macro_define_sized_builtin( mcpu_macro_table *table,
                                      const __mpu_char16_t *name,
                                      size_t name_length,
                                      enum mcpu_macro_builtin builtin,
                                      unsigned bits );
int  mcpu_macro_define_function( mcpu_macro_table *table,
                                 const __mpu_char16_t *name,
                                 size_t name_length,
                                 const __mpu_char16_t *const *argnames,
                                 const size_t *argname_lengths,
                                 size_t nargs, int variadic,
                                 const __mpu_char16_t *replacement,
                                 size_t replacement_length,
                                 enum mcpu_macro_origin origin );
int  mcpu_macro_definition_equal( const mcpu_macro *macro,
                                  int nargs, int variadic,
                                  const __mpu_char16_t *const *argnames,
                                  const size_t *argname_lengths,
                                  const __mpu_char16_t *replacement,
                                  size_t replacement_length );
int  mcpu_macro_undef( mcpu_macro_table *table,
                       const __mpu_char16_t *name,
                       size_t name_length );
int  mcpu_macro_dump( const mcpu_macro_table *table, FILE *stream,
                      int include_predefined );
int  mcpu_macro_dump_text( const mcpu_macro_table *table, mcpu_text *output,
                           const char *line_filename );
int  mcpu_macro_expand( mcpu_macro_table *table,
                        const __mpu_char16_t *input,
                        size_t length,
                        enum mcpu_language language,
                        const mcpu_macro_expansion_context *context,
                        mcpu_text *output );

#endif /* __MCPU_CPP_MACRO_H__ */