~dexter/parrot-pkg/maverick

« back to all changes in this revision

Viewing changes to compilers/pirc/src/pirmacro.h

  • Committer: Piotr Roszatycki
  • Date: 2011-01-11 14:34:28 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: piotr.roszatycki@gmail.com-20110111143428-s7pa7qz38m61o4tw
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id: pirmacro.h 44007 2010-02-16 11:11:08Z bacek $
3
 
 * Copyright (C) 2008-2009, Parrot Foundation.
4
 
 */
5
 
#ifndef PARROT_PIR_PIRMACRO_H_GUARD
6
 
#define PARROT_PIR_PIRMACRO_H_GUARD
7
 
 
8
 
 
9
 
/* struct to represent macro parameter declaration, or,
10
 
 * a macro argument, or, a .macro_local.
11
 
 */
12
 
typedef struct macro_param {
13
 
    char const         *name;
14
 
    struct macro_param *next;
15
 
 
16
 
} macro_param;
17
 
 
18
 
 
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.
27
 
 */
28
 
typedef struct macro_def {
29
 
    char const       *name;
30
 
    char             *body;
31
 
    char             *cursor;  /* to write into the body buffer */
32
 
    int               takes_args;  /* flag to indicate whether this is a .macro or .macro_const */
33
 
 
34
 
    int               linedefined;
35
 
    macro_param      *parameters;
36
 
    macro_param      *macrolocals;
37
 
 
38
 
    unsigned          buffersize;
39
 
 
40
 
    struct macro_def *next; /* macro definitions are stored in a list */
41
 
 
42
 
} macro_def;
43
 
 
44
 
 
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.
53
 
 */
54
 
typedef struct macro_table {
55
 
    macro_def *definitions;
56
 
 
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.
61
 
     */
62
 
    struct yy_buffer_state *prev_buff;
63
 
 
64
 
    /* store current line number here; when popping this table, it's restored. */
65
 
    int lineno;
66
 
 
67
 
    /* store scope number; when popping this table, it's restored. */
68
 
    int scopeno;
69
 
 
70
 
    /* a pointer to the macro_def of which this is the symbol table */
71
 
    macro_def *thismacro;
72
 
 
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.
77
 
     */
78
 
    struct macro_table *prev;
79
 
 
80
 
} macro_table;
81
 
 
82
 
 
83
 
/* HEADERIZER BEGIN: compilers/pirc/src/pirmacro.c */
84
 
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
85
 
 
86
 
void add_macro_param(
87
 
    ARGIN*macro_def * const macro),
88
 
    ARGIN(char const * const name))
89
 
        __attribute__nonnull__(2);
90
 
 
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);
96
 
 
97
 
void delete_macro_table(ARGMOD(macro_table * table))
98
 
        __attribute__nonnull__(1)
99
 
        FUNC_MODIFIES(* table);
100
 
 
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);
108
 
 
109
 
PARROT_WARN_UNUSED_RESULT
110
 
int is_macro_local(
111
 
    ARGIN(macro_def * const macro),
112
 
    ARGIN(char const * const name))
113
 
        __attribute__nonnull__(1)
114
 
        __attribute__nonnull__(2);
115
 
 
116
 
PARROT_MALLOC
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),
122
 
    int lineno,
123
 
    int takes_args,
124
 
    unsigned initsize)
125
 
        __attribute__nonnull__(1)
126
 
        __attribute__nonnull__(2);
127
 
 
128
 
void new_macro_const(
129
 
    ARGIN(macro_table * const table),
130
 
    ARGIN(char const * const name),
131
 
    ARGIN(char const * const value),
132
 
    int lineno)
133
 
        __attribute__nonnull__(1)
134
 
        __attribute__nonnull__(2)
135
 
        __attribute__nonnull__(3);
136
 
 
137
 
PARROT_MALLOC
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);
142
 
 
143
 
PARROT_MALLOC
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);
148
 
 
149
 
void store_macro_char(ARGIN(macro_def * const macro), char c)
150
 
        __attribute__nonnull__(1);
151
 
 
152
 
void store_macro_string(
153
 
    ARGIN(macro_def * const macro),
154
 
    ARGIN(char const * const str),
155
 
    ...)
156
 
        __attribute__nonnull__(1)
157
 
        __attribute__nonnull__(2);
158
 
 
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 */
190
 
 
191
 
#endif /* PARROT_PIR_PIRMACRO_H_GUARD */
192
 
 
193
 
 
194
 
/*
195
 
 * Local variables:
196
 
 *   c-file-style: "parrot"
197
 
 * End:
198
 
 * vim: expandtab shiftwidth=4:
199
 
 */
200