2
* $Id: pirmacro.h 44007 2010-02-16 11:11:08Z bacek $
3
* Copyright (C) 2008-2009, Parrot Foundation.
5
#ifndef PARROT_PIR_PIRMACRO_H_GUARD
6
#define PARROT_PIR_PIRMACRO_H_GUARD
9
/* struct to represent macro parameter declaration, or,
10
* a macro argument, or, a .macro_local.
12
typedef struct macro_param {
14
struct macro_param *next;
19
/* struct to represent a macro definition; it has a name (.macro <name>),
20
* a body, which is a string buffer containing the macro definition.
21
* C<cursor> is used to write into this buffer; C<linedefined> stores the
22
* linenumber at which the macro definition started.
23
* C<parameters> is a list of macro parameters; C<macrolocals> is a list
24
* of declared C<.macro_local>s.
25
* C<buffersize> contains the size of the buffer; if the buffer is full
26
* its size is doubled.
28
typedef struct macro_def {
31
char *cursor; /* to write into the body buffer */
32
int takes_args; /* flag to indicate whether this is a .macro or .macro_const */
35
macro_param *parameters;
36
macro_param *macrolocals;
40
struct macro_def *next; /* macro definitions are stored in a list */
45
/* A constant table represents a "scope" for macro and constants.
46
* All .macro_const and .macro definitions are stored in the "global"
47
* table, but when expanding a macro, the parameter values are stored
48
* in a "local" table, which is "pushed" onto a conceptual stack.
49
* This conceptual stack is implemented by linking the tables together.
50
* When searching in a table, the table elements are search first, and
51
* when the element is not found, the element is looked for in the
52
* table pointed to by the "prev" field.
54
typedef struct macro_table {
55
macro_def *definitions;
57
/* when a macro's buffer is being scanned, yyscan_t's YY_CURRENT_BUFFER must be stored
58
* somewhere; this is the buffer that wat being scanned before the macro expansion.
59
* This way, we can switch back to this buffer after scanning the macro's body.
60
* Note that macro_table's are only used for real macros, not .macro_const'ants.
62
struct yy_buffer_state *prev_buff;
64
/* store current line number here; when popping this table, it's restored. */
67
/* store scope number; when popping this table, it's restored. */
70
/* a pointer to the macro_def of which this is the symbol table */
73
/* constant tables are linked through this pointer,
74
* and organized as a stack. If a constant is not found
75
* in this table, then the previous table is tried, and so on,
76
* while there is a previous table.
78
struct macro_table *prev;
83
/* HEADERIZER BEGIN: compilers/pirc/src/pirmacro.c */
84
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
87
ARGIN*macro_def * const macro),
88
ARGIN(char const * const name))
89
__attribute__nonnull__(2);
91
void declare_macro_local(
92
ARGIN(macro_def * const macro),
93
ARGIN(char const * const name))
94
__attribute__nonnull__(1)
95
__attribute__nonnull__(2);
97
void delete_macro_table(ARGMOD(macro_table * table))
98
__attribute__nonnull__(1)
99
FUNC_MODIFIES(* table);
101
PARROT_WARN_UNUSED_RESULT
102
PARROT_CAN_RETURN_NULL
103
macro_def * find_macro(
104
ARGIN(macro_table * const table),
105
ARGIN(char const * const name))
106
__attribute__nonnull__(1)
107
__attribute__nonnull__(2);
109
PARROT_WARN_UNUSED_RESULT
111
ARGIN(macro_def * const macro),
112
ARGIN(char const * const name))
113
__attribute__nonnull__(1)
114
__attribute__nonnull__(2);
117
PARROT_IGNORABLE_RESULT
118
PARROT_CAN_RETURN_NULL
119
macro_def * new_macro(
120
ARGIN(macro_table * const table),
121
ARGIN(char const * const name),
125
__attribute__nonnull__(1)
126
__attribute__nonnull__(2);
128
void new_macro_const(
129
ARGIN(macro_table * const table),
130
ARGIN(char const * const name),
131
ARGIN(char const * const value),
133
__attribute__nonnull__(1)
134
__attribute__nonnull__(2)
135
__attribute__nonnull__(3);
138
PARROT_WARN_UNUSED_RESULT
139
PARROT_CANNOT_RETURN_NULL
140
macro_param * new_macro_param(ARGIN(char const * const value))
141
__attribute__nonnull__(1);
144
PARROT_CANNOT_RETURN_NULL
145
PARROT_WARN_UNUSED_RESULT
146
macro_table * new_macro_table(ARGIN(macro_table * const current))
147
__attribute__nonnull__(1);
149
void store_macro_char(ARGIN(macro_def * const macro), char c)
150
__attribute__nonnull__(1);
152
void store_macro_string(
153
ARGIN(macro_def * const macro),
154
ARGIN(char const * const str),
156
__attribute__nonnull__(1)
157
__attribute__nonnull__(2);
159
#define ASSERT_ARGS_add_macro_param __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
160
PARROT_ASSERT_ARG(name))
161
#define ASSERT_ARGS_declare_macro_local __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
162
PARROT_ASSERT_ARG(macro) \
163
, PARROT_ASSERT_ARG(name))
164
#define ASSERT_ARGS_delete_macro_table __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
165
PARROT_ASSERT_ARG(table))
166
#define ASSERT_ARGS_find_macro __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
167
PARROT_ASSERT_ARG(table) \
168
, PARROT_ASSERT_ARG(name))
169
#define ASSERT_ARGS_is_macro_local __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
170
PARROT_ASSERT_ARG(macro) \
171
, PARROT_ASSERT_ARG(name))
172
#define ASSERT_ARGS_new_macro __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
173
PARROT_ASSERT_ARG(table) \
174
, PARROT_ASSERT_ARG(name))
175
#define ASSERT_ARGS_new_macro_const __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
176
PARROT_ASSERT_ARG(table) \
177
, PARROT_ASSERT_ARG(name) \
178
, PARROT_ASSERT_ARG(value))
179
#define ASSERT_ARGS_new_macro_param __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
180
PARROT_ASSERT_ARG(value))
181
#define ASSERT_ARGS_new_macro_table __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
182
PARROT_ASSERT_ARG(current))
183
#define ASSERT_ARGS_store_macro_char __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
184
PARROT_ASSERT_ARG(macro))
185
#define ASSERT_ARGS_store_macro_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
186
PARROT_ASSERT_ARG(macro) \
187
, PARROT_ASSERT_ARG(str))
188
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
189
/* HEADERIZER END: compilers/pirc/src/pirmacro.c */
191
#endif /* PARROT_PIR_PIRMACRO_H_GUARD */
196
* c-file-style: "parrot"
198
* vim: expandtab shiftwidth=4: