~ubuntu-branches/ubuntu/quantal/aspectc++/quantal

« back to all changes in this revision

Viewing changes to Puma/src/aspects/ExtGnu.ah

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "Puma/CSemDeclSpecs.h"
28
28
#include "Puma/Config.h"
29
29
 
 
30
#include "ExtGnuCSemDeclSpecs.ah"
30
31
 
31
32
namespace Puma {
32
33
  class CCSyntax;
33
34
  class CSyntax;
34
 
} // namespace Puma
35
 
 
36
 
 
37
 
using namespace Puma;
 
35
}
 
36
 
38
37
 
39
38
namespace Puma {
40
39
  slice class ExtGnuAsmSyntax;
60
59
  bool statement_exprs;
61
60
 
62
61
  // pointcut definitions
63
 
  pointcut node ()       = classes ("Puma::CT_AsmDef");
64
 
  pointcut syntax ()     = classes ("Puma::CSyntax");
65
 
  pointcut builder ()    = classes ("Puma::CBuilder");
66
 
  pointcut semantic ()   = classes ("Puma::CSemantic");
67
 
  pointcut ccsemantic () = classes ("Puma::CCSemantic");
 
62
  pointcut node ()          = "Puma::CT_AsmDef";
 
63
  pointcut syntax ()        = "Puma::CSyntax";
 
64
  pointcut builder ()       = "Puma::CBuilder";
 
65
  pointcut semantic ()      = "Puma::CSemantic";
 
66
  pointcut ccsemantic ()    = "Puma::CCSemantic";
 
67
  pointcut csemdeclspecs () = "Puma::CSemDeclSpecs";
68
68
 
69
69
  // ----------------------------------------------------
70
70
  // the Gnu ASM syntax
75
75
  advice builder ()    : slice Puma::ExtGnuAsmBuilder;
76
76
 
77
77
  // extended asm statement
78
 
  advice that (syntax) && execution ("% Puma::CSyntax::simple_decl()") : 
79
 
  after (CSyntax *syntax) {
80
 
    CTree *&result = *(CTree**)tjp->result ();
81
 
    if (extended_asm && !result &&
82
 
        ((JoinPoint::That*)syntax)->look_ahead (TOK_ASM) &&
83
 
        ((JoinPoint::That*)syntax)->parse (&JoinPoint::That::gnu_asm_def)) {
84
 
      result = ((JoinPoint::That*)syntax)->builder().simple_decl ();
85
 
    }
86
 
  }
87
 
 
88
 
  // extended asm statement
89
78
  advice that (syn) && within (derived (syntax ())) &&
90
 
         execution ("% Puma::%::asm_def()") : around (CSyntax *syn) {
 
79
         execution ("% Puma::%::asm_def()") : around (Puma::CSyntax *syn) {
91
80
    if (extended_asm)
92
81
      *tjp->result () = ((JoinPoint::That*)syn)->gnu_asm_def ();
93
82
    else
94
83
      tjp->proceed ();
95
84
  }
96
85
 
 
86
  // extended asm init declarator syntax
 
87
  advice that (syn) && within (derived (syntax ())) &&
 
88
         execution ("% Puma::%::init_declarator_ext()") :
 
89
    after (Puma::CSyntax *syn) {
 
90
    Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
 
91
    if (extended_asm && !result &&
 
92
        ((JoinPoint::That*)syn)->look_ahead (Puma::TOK_ASM))
 
93
      result = ((JoinPoint::That*)syn)->gnu_asm_spec ();
 
94
  }
 
95
 
 
96
//   // asm declaration specifiers
 
97
//   advice within (derived (syntax ())) &&
 
98
//          execution ("% Puma::%::init_simple_type_spec()") : after () {
 
99
//     if (extended_asm)
 
100
//       tjp->that ()->_simple_type_spec_1.set (Puma::TOK_ASM);
 
101
//   }
 
102
//   advice execution ("% Puma::CSyntax::rule_simple_type_spec()") : after () {
 
103
//     Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
 
104
//     if (extended_asm && !result && tjp->that ()->look_ahead (Puma::TOK_ASM) &&
 
105
//         tjp->that ()->parse (&JoinPoint::That::gnu_asm_spec))
 
106
//       result = tjp->that ()->builder ().gnu_asm_spec ();
 
107
//   }
 
108
//   advice execution ("% Puma::CCSyntax::rule_simple_type_spec()") : after () {
 
109
//     Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
 
110
//     if (extended_asm && !result && tjp->that ()->look_ahead (Puma::TOK_ASM) &&
 
111
//         tjp->that ()->parse (&JoinPoint::That::gnu_asm_spec))
 
112
//       result = tjp->that ()->semantic ().simple_type_spec ();
 
113
//   }
 
114
//   // make the analysis function aware of 'asm(...)'
 
115
//   advice execution("bool Puma::%::analyze(...)") && within (csemdeclspecs ()) &&
 
116
//          args (spec): after (Puma::CTree *spec) {
 
117
//     bool &result = *tjp->result ();
 
118
//     if (!result && spec->NodeName () == Puma::CT_GnuAsmSpec::NodeId ())
 
119
//       result = true;
 
120
//   }
 
121
 
97
122
  // ----------------------------------------------------
98
123
  // the 'restrict' keyword
99
124
  // ----------------------------------------------------
101
126
  // extended cv qualifier
102
127
  advice execution ("% Puma::CCSyntax::init_cv_qual()") : after () {
103
128
    if (extended_cv_qual)
104
 
      tjp->that ()->_cv_qual_1.set (TOK_RESTRICT);
 
129
      tjp->that ()->_cv_qual_1.set (Puma::TOK_RESTRICT);
105
130
  }
106
131
 
107
132
  // -------------------------
122
147
    execution ("% ...::rule_prim_expr()") : around () {
123
148
    JoinPoint::That *syntax = tjp->that ();
124
149
    if (statement_exprs &&
125
 
        ((JoinPoint::That*)syntax)->look_ahead (TOK_OPEN_ROUND) &&
126
 
        ((JoinPoint::That*)syntax)->look_ahead (TOK_OPEN_CURLY, 2)) {
127
 
      CTree *&result = *(CTree**)tjp->result ();
128
 
      ((JoinPoint::That*)syntax)->consume (); // skip the TOK_OPEN_ROUND
 
150
        ((JoinPoint::That*)syntax)->look_ahead (Puma::TOK_OPEN_ROUND) &&
 
151
        ((JoinPoint::That*)syntax)->look_ahead (Puma::TOK_OPEN_CURLY, 2)) {
 
152
      Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
 
153
      ((JoinPoint::That*)syntax)->consume (); // skip the Puma::TOK_OPEN_ROUND
129
154
      result =
130
155
        (((JoinPoint::That*)syntax)->parse (&JoinPoint::That::cmpd_stmt) &&
131
 
        ((JoinPoint::That*)syntax)->parse (TOK_CLOSE_ROUND)) ?
 
156
        ((JoinPoint::That*)syntax)->parse (Puma::TOK_CLOSE_ROUND)) ?
132
157
        ((JoinPoint::That*)syntax)->builder().gnu_statement_expr () : 0;
133
158
    }
134
159
    else
146
171
  advice ccsemantic () : slice Puma::ExtGnuTypeofCCSemantic;
147
172
 
148
173
  // introduce new state into CSemDeclSpecs
149
 
  pointcut csemdeclspecs () = "Puma::CSemDeclSpecs";
150
 
  advice csemdeclspecs () : slice class {
151
 
  public:
152
 
    int _typeofs;
153
 
    CT_GnuTypeof *_typeof_node;
154
 
  };
 
174
  advice csemdeclspecs () : slice Puma::ExtGnuCSemDeclSpecs;
155
175
 
156
176
  // syntax extension
157
177
  advice within (derived (syntax ())) &&
158
178
         execution ("% Puma::%::init_simple_type_spec()") : after () {
159
179
    if (typeof_keyword)
160
 
      tjp->that ()->_simple_type_spec_1.set (TOK_TYPEOF);
 
180
      tjp->that ()->_simple_type_spec_1.set (Puma::TOK_TYPEOF);
161
181
  }
162
182
  advice execution ("% Puma::CSyntax::rule_simple_type_spec()") : after () {
163
 
    CTree *&result = *(CTree**)tjp->result ();
164
 
    if (typeof_keyword && !result && tjp->that ()->look_ahead (TOK_TYPEOF) &&
 
183
    Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
 
184
    if (typeof_keyword && !result && tjp->that ()->look_ahead (Puma::TOK_TYPEOF) &&
165
185
        tjp->that ()->parse (&JoinPoint::That::gnu_typeof))
166
186
      result = tjp->that ()->builder ().simple_type_spec ();
167
187
  }
168
188
  advice execution ("% Puma::CCSyntax::rule_simple_type_spec()") : after () {
169
 
    CTree *&result = *(CTree**)tjp->result ();
170
 
    if (typeof_keyword && !result && tjp->that ()->look_ahead (TOK_TYPEOF) &&
 
189
    Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
 
190
    if (typeof_keyword && !result && tjp->that ()->look_ahead (Puma::TOK_TYPEOF) &&
171
191
        tjp->that ()->parse (&JoinPoint::That::gnu_typeof))
172
192
      result = tjp->that ()->semantic ().simple_type_spec ();
173
193
  }
174
194
 
175
195
  // initialize the new state before an analysis starts
176
196
  advice execution("bool Puma::%::analyze_seq()") && within (csemdeclspecs ()) &&
177
 
         that (csd) : before (CSemDeclSpecs &csd) {
 
197
         that (csd) : before (Puma::CSemDeclSpecs &csd) {
178
198
    csd._typeofs = 0;
179
199
    csd._typeof_node = 0;
180
200
  }
181
201
 
182
202
  // make the analysis function aware of 'typeof'
183
203
  advice execution("bool Puma::%::analyze(...)") && within (csemdeclspecs ()) &&
184
 
         that (csd) && args (spec): after (CSemDeclSpecs &csd, CTree *spec) {
 
204
         that (csd) && args (spec): after (Puma::CSemDeclSpecs &csd, Puma::CTree *spec) {
185
205
    bool &result = *tjp->result ();
186
 
    if (!result && spec->NodeName () == CT_GnuTypeof::NodeId ()) {
 
206
    if (!result && spec->NodeName () == Puma::CT_GnuTypeof::NodeId ()) {
187
207
      csd._typeofs++;      
188
 
      csd._typeof_node = (CT_GnuTypeof*)spec;
 
208
      csd._typeof_node = (Puma::CT_GnuTypeof*)spec;
189
209
      result = true;
190
210
    }
191
211
  }
193
213
  // make the check functions aware of 'typeof'
194
214
  advice execution("bool Puma::%::check_complex_decl_specs(...)") &&
195
215
         within (csemdeclspecs ()) && that (csd) && args (have_type):
196
 
         after (CSemDeclSpecs &csd, bool &have_type) {
 
216
         after (Puma::CSemDeclSpecs &csd, bool &have_type) {
197
217
    bool &result = *tjp->result ();
198
218
    if (result && !have_type && csd._typeofs) {
199
219
      have_type = true;
202
222
  }
203
223
  
204
224
  advice execution("bool Puma::%::check_signed_unsigned()") &&
205
 
         within (csemdeclspecs ()) && that (csd) : after (CSemDeclSpecs &csd) {
 
225
         within (csemdeclspecs ()) && that (csd) : after (Puma::CSemDeclSpecs &csd) {
206
226
    bool &result = *tjp->result ();
207
227
    if (result) {
208
 
      if ((csd._prim_map[CT_PrimDeclSpec::PDS_SIGNED] || 
209
 
           csd._prim_map[CT_PrimDeclSpec::PDS_UNSIGNED]) &&
 
228
      if ((csd._prim_map[Puma::CT_PrimDeclSpec::PDS_SIGNED] || 
 
229
           csd._prim_map[Puma::CT_PrimDeclSpec::PDS_UNSIGNED]) &&
210
230
          csd._typeofs) {
211
 
        *csd._err << sev_error << csd._dss->token ()->location () 
 
231
        *csd._err << Puma::sev_error << csd._dss->token ()->location () 
212
232
                  << "`signed' or `unsigned' invalid for 'typeof'"
213
 
                  << endMessage;
 
233
                  << Puma::endMessage;
214
234
        result = false;
215
235
      }
216
236
    }
217
237
  }
218
238
 
219
239
  advice execution("bool Puma::%::check_finally()") &&
220
 
         within (csemdeclspecs ()) && that (csd) : after (CSemDeclSpecs &csd) {
 
240
         within (csemdeclspecs ()) && that (csd) : after (Puma::CSemDeclSpecs &csd) {
221
241
    bool &result = *tjp->result ();
222
242
    if (result && csd._typeofs > 0) {
223
 
      *csd._err << sev_error << csd._dss->token ()->location () 
 
243
      *csd._err << Puma::sev_error << csd._dss->token ()->location () 
224
244
                << "invalid type specified in declaration"
225
 
                << endMessage;
 
245
                << Puma::endMessage;
226
246
      result = false;
227
247
    }
228
248
  }
229
249
 
230
250
  // make the type creation function aware of 'typeof'
231
251
  advice execution("% Puma::%::create_type()") && within (csemdeclspecs ()) &&
232
 
         that (csd) : after (CSemDeclSpecs &csd) {
233
 
    CTypeInfo *&result = *tjp->result ();
 
252
         that (csd) : after (Puma::CSemDeclSpecs &csd) {
 
253
    Puma::CTypeInfo *&result = *tjp->result ();
234
254
    if (result->isUndefined () && csd._typeofs) {
235
255
      csd._typeofs--;
236
256
      if (csd._typeof_node->Type ()) {
237
 
        result = CTypeInfo::Duplicate (csd._typeof_node->Type ());
 
257
        result = Puma::CTypeInfo::Duplicate (csd._typeof_node->Type ());
238
258
      }
239
259
    }
240
260
  }
259
279
  advice execution ("% Puma::CCNameLookup::lookup(%::CStructure *,bool,bool)") : 
260
280
  before () {
261
281
    if (std_hack) {
262
 
      CStructure *&scope = *(CStructure**)tjp->arg (0);
 
282
      Puma::CStructure *&scope = *(Puma::CStructure**)tjp->arg (0);
263
283
      bool &nested = *(bool*)tjp->arg (1);
264
284
      if (scope->Parent ()->GlobalScope () &&
265
285
          strcmp (scope->Name (), "std") == 0)
269
289
  
270
290
  // get the configuration and check whether the GNU mode is enabled
271
291
  advice args (config) && within (derived ("Puma::Syntax")) && 
272
 
         execution ("void Puma::%::configure(...)"): before (Config &config) {
 
292
         execution ("void Puma::%::configure(...)"): before (Puma::Config &config) {
273
293
    if (config.Option ("--gnu") || config.Option ("--gnu-2.95")) {
274
294
      extended_asm     = true;
275
295
      extended_cv_qual = true;
283
303
      std_hack = true;
284
304
  }
285
305
 
 
306
  // --------------------------------------------------
 
307
  // support for unnamed struct/union members
 
308
  // --------------------------------------------------
 
309
  
 
310
  advice execution ("% Puma::CSyntax::member_decl()") : around () {
 
311
    // 2: type_spec_seq                          ;
 
312
    // 3: type_spec_seq  member_declarator_list  ;
 
313
    Puma::CTree *&result = *(Puma::CTree**)tjp->result ();
 
314
    if (! (tjp->that ()->parse (&JoinPoint::That::type_spec_seq) && 
 
315
           tjp->that ()->opt(tjp->that ()->parse (&JoinPoint::That::member_declarator_list)) && 
 
316
           tjp->that ()->parse (Puma::TOK_SEMI_COLON))) {
 
317
      result = (Puma::CTree*)0;
 
318
    } else {
 
319
      tjp->that ()->semantic ().finish_decl ();
 
320
      result = tjp->that ()->builder ().member_decl (); 
 
321
    }
 
322
  }
 
323
 
286
324
protected:
287
325
  ExtGnu () : extended_asm (false), extended_cv_qual (false),
288
326
    gnu_builtins (false), std_hack (false), typeof_keyword (false),
298
336
// add rules to the C Syntax
299
337
slice class Puma::ExtGnuAsmSyntax {
300
338
public:
301
 
  CTree * gnu_asm_def ();
302
 
  CTree * gnu_asm_operands ();
303
 
  CTree * gnu_asm_operand ();
304
 
  CTree * gnu_asm_clobbers ();
 
339
  Puma::CTree * gnu_asm_spec ();
 
340
  Puma::CTree * gnu_asm_def ();
 
341
  Puma::CTree * gnu_asm_operands ();
 
342
  Puma::CTree * gnu_asm_operand ();
 
343
  Puma::CTree * gnu_asm_clobbers ();
305
344
};
306
345
 
307
 
slice CTree * Puma::ExtGnuAsmSyntax::gnu_asm_def () {
308
 
  return (parse (TOK_ASM) && opt (cv_qual ()) &&
309
 
          parse (TOK_OPEN_ROUND) && cmpd_str () &&
310
 
          opt (parse (&CSyntax::gnu_asm_operands) &&
311
 
               parse (&CSyntax::gnu_asm_operands) &&
312
 
               parse (&CSyntax::gnu_asm_clobbers)) &&
313
 
          parse (TOK_CLOSE_ROUND) && parse (TOK_SEMI_COLON)) ?
314
 
    builder ().gnu_asm_def () : (CTree*)0;
315
 
}
316
 
 
317
 
slice CTree * Puma::ExtGnuAsmSyntax::gnu_asm_operands () {
318
 
  return (parse (TOK_COLON) &&
319
 
          opt (list (&CSyntax::gnu_asm_operand, TOK_COMMA))) ?
320
 
    builder ().gnu_asm_operands () : (CTree*)0;
321
 
}
322
 
 
323
 
slice CTree * Puma::ExtGnuAsmSyntax::gnu_asm_operand () {
324
 
  return (cmpd_str () && parse (TOK_OPEN_ROUND) &&
325
 
          parse (&CSyntax::expr) && parse (TOK_CLOSE_ROUND)) ?
326
 
    builder ().gnu_asm_operand () : (CTree*)0;
327
 
}
328
 
 
329
 
slice CTree * Puma::ExtGnuAsmSyntax::gnu_asm_clobbers () {
330
 
  return (parse (TOK_COLON) && list (&CSyntax::cmpd_str, TOK_COMMA)) ?
331
 
    builder ().gnu_asm_clobbers () : (CTree*)0;
 
346
slice Puma::CTree * Puma::ExtGnuAsmSyntax::gnu_asm_spec () {
 
347
  return (parse (Puma::TOK_ASM) &&
 
348
          parse (Puma::TOK_OPEN_ROUND) &&
 
349
          cmpd_str () &&
 
350
          parse (Puma::TOK_CLOSE_ROUND)) ?
 
351
    builder ().gnu_asm_spec () : (Puma::CTree*)0;
 
352
}
 
353
 
 
354
slice Puma::CTree * Puma::ExtGnuAsmSyntax::gnu_asm_def () {
 
355
  return (parse (Puma::TOK_ASM) && opt (cv_qual ()) &&
 
356
          parse (Puma::TOK_OPEN_ROUND) && cmpd_str () &&
 
357
          opt (parse (&Puma::CSyntax::gnu_asm_operands) &&
 
358
               parse (&Puma::CSyntax::gnu_asm_operands) &&
 
359
               parse (&Puma::CSyntax::gnu_asm_clobbers)) &&
 
360
          parse (Puma::TOK_CLOSE_ROUND) && parse (Puma::TOK_SEMI_COLON)) ?
 
361
    builder ().gnu_asm_def () : (Puma::CTree*)0;
 
362
}
 
363
 
 
364
slice Puma::CTree * Puma::ExtGnuAsmSyntax::gnu_asm_operands () {
 
365
  return (parse (Puma::TOK_COLON) &&
 
366
          opt (list (&Puma::CSyntax::gnu_asm_operand, Puma::TOK_COMMA))) ?
 
367
    builder ().gnu_asm_operands () : (Puma::CTree*)0;
 
368
}
 
369
 
 
370
slice Puma::CTree * Puma::ExtGnuAsmSyntax::gnu_asm_operand () {
 
371
  return (cmpd_str () && parse (Puma::TOK_OPEN_ROUND) &&
 
372
          parse (&Puma::CSyntax::expr) && parse (Puma::TOK_CLOSE_ROUND)) ?
 
373
    builder ().gnu_asm_operand () : (Puma::CTree*)0;
 
374
}
 
375
 
 
376
slice Puma::CTree * Puma::ExtGnuAsmSyntax::gnu_asm_clobbers () {
 
377
  return (parse (Puma::TOK_COLON) && list (&Puma::CSyntax::cmpd_str, Puma::TOK_COMMA)) ?
 
378
    builder ().gnu_asm_clobbers () : (Puma::CTree*)0;
332
379
}
333
380
 
334
381
// extend the C Builder
335
382
slice class Puma::ExtGnuAsmBuilder {
336
383
public:
337
 
  CTree * gnu_asm_def ();
338
 
  CTree * gnu_asm_operands ();
339
 
  CTree * gnu_asm_operand ();
340
 
  CTree * gnu_asm_clobbers ();
 
384
  Puma::CTree * gnu_asm_spec ();
 
385
  Puma::CTree * gnu_asm_def ();
 
386
  Puma::CTree * gnu_asm_operands ();
 
387
  Puma::CTree * gnu_asm_operand ();
 
388
  Puma::CTree * gnu_asm_clobbers ();
341
389
};
342
390
 
343
 
slice CTree * Puma::ExtGnuAsmBuilder::gnu_asm_def () {
 
391
slice Puma::CTree * Puma::ExtGnuAsmBuilder::gnu_asm_spec () {
 
392
  return new Puma::CT_GnuAsmSpec (get_node (0), get_node (1), get_node (2),
 
393
    get_node (3));
 
394
}
 
395
 
 
396
slice Puma::CTree * Puma::ExtGnuAsmBuilder::gnu_asm_def () {
344
397
  // just copied: this is a wrong implementation!
345
 
  int have_cv = (get_node (1)->NodeName () == CT_Token::NodeId ()) ? 0 : 1;
 
398
  int have_cv = (get_node (1)->NodeName () == Puma::CT_Token::NodeId ()) ? 0 : 1;
346
399
  int gnu_nodes = nodes () - have_cv - 5;
347
400
  int gnu_first = 3 + have_cv;
348
 
  CTree *cv  = have_cv ? get_node (1) : (CTree*)0;
349
 
  CTree *op0 = (gnu_nodes >= 1) ? get_node (gnu_first) : (CTree*)0;
350
 
  CTree *op1 = (gnu_nodes >= 2) ? get_node (gnu_first + 1) : (CTree*)0;
351
 
  CTree *clb = (gnu_nodes >= 3) ? get_node (gnu_first + 2) : (CTree*)0;
352
 
  return new CT_GnuAsmDef (get_node (0), cv, get_node (1 + have_cv),
 
401
  Puma::CTree *cv  = have_cv ? get_node (1) : (Puma::CTree*)0;
 
402
  Puma::CTree *op0 = (gnu_nodes >= 1) ? get_node (gnu_first) : (Puma::CTree*)0;
 
403
  Puma::CTree *op1 = (gnu_nodes >= 2) ? get_node (gnu_first + 1) : (Puma::CTree*)0;
 
404
  Puma::CTree *clb = (gnu_nodes >= 3) ? get_node (gnu_first + 2) : (Puma::CTree*)0;
 
405
  return new Puma::CT_GnuAsmDef (get_node (0), cv, get_node (1 + have_cv),
353
406
                           get_node (2 + have_cv), op0, op1, clb,
354
407
                           get_node (nodes () - 2),get_node (nodes () - 1));
355
408
}
356
409
 
357
 
slice CTree * Puma::ExtGnuAsmBuilder::gnu_asm_operands () {
358
 
  return list (new CT_GnuAsmOperands);
 
410
slice Puma::CTree * Puma::ExtGnuAsmBuilder::gnu_asm_operands () {
 
411
  return list (new Puma::CT_GnuAsmOperands);
359
412
}
360
413
 
361
 
slice CTree * Puma::ExtGnuAsmBuilder::gnu_asm_operand () {
362
 
  return new CT_GnuAsmOperand (get_node (0), get_node (1), get_node (2),
 
414
slice Puma::CTree * Puma::ExtGnuAsmBuilder::gnu_asm_operand () {
 
415
  return new Puma::CT_GnuAsmOperand (get_node (0), get_node (1), get_node (2),
363
416
                               get_node (3));
364
417
}
365
418
        
366
 
slice CTree * Puma::ExtGnuAsmBuilder::gnu_asm_clobbers () {
367
 
  return list (new CT_GnuAsmClobbers);
 
419
slice Puma::CTree * Puma::ExtGnuAsmBuilder::gnu_asm_clobbers () {
 
420
  return list (new Puma::CT_GnuAsmClobbers);
368
421
}
369
422
 
370
423
// -------------------------
374
427
// C Builder extension
375
428
slice class Puma::ExtGnuStmtExprsBuilder {
376
429
public:
377
 
  CTree * gnu_statement_expr ();
 
430
  Puma::CTree * gnu_statement_expr ();
378
431
};
379
432
 
380
 
slice CTree * Puma::ExtGnuStmtExprsBuilder::gnu_statement_expr () {
381
 
  return new CT_GnuStatementExpr (get_node (0), get_node (1), get_node (2));
 
433
slice Puma::CTree * Puma::ExtGnuStmtExprsBuilder::gnu_statement_expr () {
 
434
  return new Puma::CT_GnuStatementExpr (get_node (0), get_node (1), get_node (2));
382
435
}
383
436
 
384
437
// C semantic extension
385
438
slice class Puma::ExtGnuStmtExprsCSemExpr {
386
439
public:
387
 
  CTypeInfo *resolve (CT_GnuStatementExpr *, CTree *);
 
440
  Puma::CTypeInfo *resolve (Puma::CT_GnuStatementExpr *, Puma::CTree *);
388
441
};
389
442
 
390
443
// the necessary #include "..CSemVisitor.h" in CSemExpr.cc will is inserted
391
444
// manually (for now)!
392
 
slice CTypeInfo *Puma::ExtGnuStmtExprsCSemExpr::resolve (
393
 
  CT_GnuStatementExpr *node, CTree *) {
 
445
slice Puma::CTypeInfo *Puma::ExtGnuStmtExprsCSemExpr::resolve (
 
446
  Puma::CT_GnuStatementExpr *node, Puma::CTree *) {
394
447
 
395
 
  CTypeInfo *result = &CTYPE_UNDEFINED;
 
448
  Puma::CTypeInfo *result = &Puma::CTYPE_UNDEFINED;
396
449
  
397
 
  if (! current_scope->LocalScope ())
 
450
  if (! current_scope->LocalScope ()) {
398
451
    SEM_ERROR (node,
399
452
               "braced-group within expression allowed only inside a function");
400
 
  else {
 
453
  } else {
401
454
 
402
455
    // first analyse the compound statement in this expression
403
 
    CSemVisitor csv (err);
 
456
    Puma::CSemVisitor csv (err);
404
457
    csv.run (node->Son (1), current_scope);
405
458
 
406
459
    // check the compound statement semantically
407
 
    CT_CmpdStmt *cmpd = node->CmpdStmt ();
 
460
    Puma::CT_CmpdStmt *cmpd = node->CmpdStmt ();
408
461
    if (cmpd->Entries () >= 1 &&
409
462
        cmpd->Entry (cmpd->Entries () - 1)->NodeName () ==
410
 
        CT_ExprStmt::NodeId ()) {
411
 
      CT_ExprStmt *expr_stmt = (CT_ExprStmt*)cmpd->Entry (cmpd->Entries () - 1);
 
463
        Puma::CT_ExprStmt::NodeId ()) {
 
464
      Puma::CT_ExprStmt *expr_stmt = (Puma::CT_ExprStmt*)cmpd->Entry (cmpd->Entries () - 1);
412
465
      result = expr_stmt->Expr ()->Type ();
413
466
    }
414
467
    else
415
468
      // an empty statement expression or one that does not end with a
416
469
      // statement expression has type void!
417
 
      result = &CTYPE_VOID;
 
470
      result = &Puma::CTYPE_VOID;
418
471
  }
419
472
 
420
473
  node->setTypeRef (result);
424
477
// C++ semantic extension
425
478
slice class Puma::ExtGnuStmtExprsCCSemExpr {
426
479
public:
427
 
  CTypeInfo *resolve (CT_GnuStatementExpr *, CTree *);
 
480
  Puma::CTypeInfo *resolve (Puma::CT_GnuStatementExpr *, Puma::CTree *);
428
481
};
429
482
 
430
483
// the necessary #include "..CCSemVisitor.h" in CCSemExpr.cc will is inserted
431
484
// manually (for now)!
432
 
slice CTypeInfo *Puma::ExtGnuStmtExprsCCSemExpr::resolve (
433
 
  CT_GnuStatementExpr *node, CTree *) {
 
485
slice Puma::CTypeInfo *Puma::ExtGnuStmtExprsCCSemExpr::resolve (
 
486
  Puma::CT_GnuStatementExpr *node, Puma::CTree *) {
434
487
 
435
 
  CTypeInfo *result = &CTYPE_UNDEFINED;
 
488
  Puma::CTypeInfo *result = &Puma::CTYPE_UNDEFINED;
436
489
  
437
 
  if (! current_scope->LocalScope ())
 
490
  if (! current_scope->LocalScope ()) {
438
491
    SEM_ERROR (node,
439
492
               "braced-group within expression allowed only inside a function");
440
 
  else {
 
493
  } else {
441
494
 
442
495
    // first analyse the compound statement in this expression
443
 
    CCSemVisitor csv (err);
 
496
    Puma::CCSemVisitor csv (err);
444
497
    csv.run (node->Son (1), current_scope);
445
498
 
446
499
    // check the compound statement semantically
447
 
    CT_CmpdStmt *cmpd = node->CmpdStmt ();
 
500
    Puma::CT_CmpdStmt *cmpd = node->CmpdStmt ();
448
501
    if (cmpd->Entries () >= 1 &&
449
502
        cmpd->Entry (cmpd->Entries () - 1)->NodeName () ==
450
 
        CT_ExprStmt::NodeId ()) {
451
 
      CT_ExprStmt *expr_stmt = (CT_ExprStmt*)cmpd->Entry (cmpd->Entries () - 1);
 
503
        Puma::CT_ExprStmt::NodeId ()) {
 
504
      Puma::CT_ExprStmt *expr_stmt = (Puma::CT_ExprStmt*)cmpd->Entry (cmpd->Entries () - 1);
452
505
      result = expr_stmt->Expr ()->Type ();
453
506
    }
454
507
    else
455
508
      // an empty statement expression or one that does not end with a
456
509
      // statement expression has type void!
457
 
      result = &CTYPE_VOID;
 
510
      result = &Puma::CTYPE_VOID;
458
511
  }
459
512
 
460
513
  node->setTypeRef (result);
468
521
// add rules to the C Syntax for the Gnu Typeof syntax
469
522
slice class Puma::ExtGnuTypeofSyntax {
470
523
public:
471
 
  CTree * gnu_typeof ();
 
524
  Puma::CTree * gnu_typeof ();
472
525
};
473
526
 
474
 
slice CTree * Puma::ExtGnuTypeofSyntax::gnu_typeof () {
475
 
  return (parse (TOK_TYPEOF) &&
476
 
          (parse (&CSyntax::unary_expr1) || parse (&CSyntax::unary_expr))) ?
477
 
    semantic ().gnu_typeof () : (CTree*)0;
 
527
slice Puma::CTree * Puma::ExtGnuTypeofSyntax::gnu_typeof () {
 
528
  return (parse (Puma::TOK_TYPEOF) &&
 
529
          (parse (&Puma::CSyntax::unary_expr1) || parse (&Puma::CSyntax::unary_expr))) ?
 
530
    semantic ().gnu_typeof () : (Puma::CTree*)0;
478
531
}
479
532
 
480
533
// add rules to the C Builder for the Gnu Typeof syntax
481
534
slice class Puma::ExtGnuTypeofBuilder {
482
535
public:
483
 
  CTree * gnu_typeof ();
 
536
  Puma::CTree * gnu_typeof ();
484
537
};
485
538
 
486
539
// builder extension
487
 
slice CTree * Puma::ExtGnuTypeofBuilder::gnu_typeof () {
488
 
  CTree *result;
489
 
  if (get_node (1)->NodeName () == Container::NodeId ()) {
490
 
    Container *c = (Container*) get_node (1);
491
 
    result = new CT_GnuTypeof (get_node (0), c->Son (0), c->Son (1), c->Son (2));
 
540
slice Puma::CTree * Puma::ExtGnuTypeofBuilder::gnu_typeof () {
 
541
  Puma::CTree *result;
 
542
  if (get_node (1)->NodeName () == Puma::Builder::Container::NodeId ()) {
 
543
    Puma::Builder::Container *c = (Puma::Builder::Container*) get_node (1);
 
544
    result = new Puma::CT_GnuTypeof (get_node (0), c->Son (0), c->Son (1), c->Son (2));
492
545
    delete c;
493
546
  } else {
494
 
    result = new CT_GnuTypeof (get_node (0), get_node (1));
 
547
    result = new Puma::CT_GnuTypeof (get_node (0), get_node (1));
495
548
  }
496
549
  return result;
497
550
}
499
552
// C semantic extension
500
553
slice class Puma::ExtGnuTypeofSemantic {
501
554
public:
502
 
  virtual CTree * gnu_typeof ();
 
555
  virtual Puma::CTree * gnu_typeof ();
503
556
};
504
557
 
505
 
slice CTree * Puma::ExtGnuTypeofSemantic::gnu_typeof () {
506
 
  CTree *result = builder ().gnu_typeof ();
 
558
slice Puma::CTree * Puma::ExtGnuTypeofSemantic::gnu_typeof () {
 
559
  Puma::CTree *result = builder ().gnu_typeof ();
507
560
  if (result) {
508
 
    CT_GnuTypeof *node = (CT_GnuTypeof*)result;
 
561
    Puma::CT_GnuTypeof *node = (Puma::CT_GnuTypeof*)result;
509
562
    // if the GnuTypeof node has an expression, resolve it to get the type
510
563
    if (node->Expr ()) {
511
 
      CSemVisitor sem_visitor (*_err);
512
 
      CTypeInfo *expr_type = sem_visitor.resolveExpr (node->Expr (), node);
 
564
      Puma::CSemVisitor sem_visitor (*_err, current_scope);
 
565
      Puma::CTypeInfo *expr_type = sem_visitor.resolveExpr (node->Expr (), node);
513
566
      node->setTypeRef (expr_type);
514
567
    }
515
 
    CT_NamedType *named_type = node->TypeName ();
 
568
    Puma::CT_NamedType *named_type = node->TypeName ();
516
569
    if (named_type && named_type->Object ()) {
517
570
      node->setTypeRef (named_type->Object ()->TypeInfo ());
518
571
    }
523
576
// C++ semantic extension
524
577
slice class Puma::ExtGnuTypeofCCSemantic {
525
578
public:
526
 
  virtual CTree * gnu_typeof ();
 
579
  virtual Puma::CTree * gnu_typeof ();
527
580
};
528
581
 
529
 
slice CTree * Puma::ExtGnuTypeofCCSemantic::gnu_typeof () {
530
 
  CTree *result = builder ().gnu_typeof ();
 
582
slice Puma::CTree * Puma::ExtGnuTypeofCCSemantic::gnu_typeof () {
 
583
  Puma::CTree *result = builder ().gnu_typeof ();
531
584
  if (result) {
532
 
    CT_GnuTypeof *node = (CT_GnuTypeof*)result;
 
585
    Puma::CT_GnuTypeof *node = (Puma::CT_GnuTypeof*)result;
533
586
    // if the GnuTypeof node has an expression, resolve it to get the type
534
587
    if (node->Expr ()) {
535
 
      CTypeInfo *expr_type = resolveExpr (node->Expr ());
 
588
      Puma::CTypeInfo *expr_type = resolveExpr (node->Expr ());
536
589
      node->setTypeRef (expr_type);
537
590
    }
538
 
    CT_NamedType *named_type = node->TypeName ();
 
591
    Puma::CT_NamedType *named_type = node->TypeName ();
539
592
    if (named_type && named_type->Object ()) {
540
593
      node->setTypeRef (named_type->Object ()->TypeInfo ());
541
594
    }
557
610
slice void Puma::ExtGnuBuiltinsSemantic::define_gnu_builtins () {
558
611
  // declare gnu-specific builtin functions
559
612
 
560
 
  CFunctionInfo *info;
561
 
  CTypeInfo *type;
562
 
  CTypeList *args;
 
613
  Puma::CFunctionInfo *info;
 
614
  Puma::CTypeInfo *type;
 
615
  Puma::CTypeList *args;
563
616
 
564
617
  // mem... functions
565
618
  
566
619
  // void *__builtin_memcpy(void *dest, const void *src, size_t n)
567
 
  args = new CTypeList (3);
568
 
  type = new CTypePointer (&CTYPE_VOID); // void*
 
620
  args = new Puma::CTypeList (3);
 
621
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID); // void*
569
622
  args->AddEntry (type);
570
 
  type = new CTypeQualified (&CTYPE_VOID, true, false, false);
571
 
  type = new CTypePointer (type);
 
623
  type = new Puma::CTypeQualified (&Puma::CTYPE_VOID, true, false, false);
 
624
  type = new Puma::CTypePointer (type);
572
625
  args->AddEntry (type); // const void*
573
 
  args->AddEntry (CTypeInfo::CTYPE_SIZE_T);
574
 
  type = new CTypePointer (&CTYPE_VOID); // void*
575
 
  type = new CTypeFunction (type, args, true);
 
626
  args->AddEntry (Puma::CTypeInfo::CTYPE_SIZE_T);
 
627
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID); // void*
 
628
  type = new Puma::CTypeFunction (type, args, true);
576
629
  info = createFunction ("__builtin_memcpy", current_scope, type);
577
630
  createParameter (info, args->Entry (0));
578
631
  createParameter (info, args->Entry (1));
581
634
  // string functions
582
635
 
583
636
  // char *__builtin_strchr(const char *s, int c);
584
 
  args = new CTypeList (2);
585
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
586
 
  type = new CTypePointer (type);
 
637
  args = new Puma::CTypeList (2);
 
638
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
639
  type = new Puma::CTypePointer (type);
587
640
  args->AddEntry (type); // const char*
588
 
  args->AddEntry (&CTYPE_INT); // int
589
 
  type = new CTypePointer (&CTYPE_CHAR);
590
 
  type = new CTypeFunction (type, args, true);
 
641
  args->AddEntry (&Puma::CTYPE_INT); // int
 
642
  type = new Puma::CTypePointer (&Puma::CTYPE_CHAR);
 
643
  type = new Puma::CTypeFunction (type, args, true);
591
644
  info = createFunction ("__builtin_strchr", current_scope, type);
592
645
  createParameter (info, args->Entry (0));
593
646
  createParameter (info, args->Entry (1));
594
647
 
595
648
  // char *__builtin_strrchr(const char *s, int c);
596
 
  args = new CTypeList (2);
597
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
598
 
  type = new CTypePointer (type);
 
649
  args = new Puma::CTypeList (2);
 
650
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
651
  type = new Puma::CTypePointer (type);
599
652
  args->AddEntry (type); // const char*
600
 
  args->AddEntry (&CTYPE_INT); // int
601
 
  type = new CTypePointer (&CTYPE_CHAR);
602
 
  type = new CTypeFunction (type, args, true);
 
653
  args->AddEntry (&Puma::CTYPE_INT); // int
 
654
  type = new Puma::CTypePointer (&Puma::CTYPE_CHAR);
 
655
  type = new Puma::CTypeFunction (type, args, true);
603
656
  info = createFunction ("__builtin_strrchr", current_scope, type);
604
657
  createParameter (info, args->Entry (0));
605
658
  createParameter (info, args->Entry (1));
606
659
 
607
660
  // char *__builtin_strpbrk(const char *s, const char *accept);
608
 
  args = new CTypeList (2);
609
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
610
 
  type = new CTypePointer (type);
611
 
  args->AddEntry (type); // const char*
612
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
613
 
  type = new CTypePointer (type);
614
 
  args->AddEntry (type); // const char*
615
 
  type = new CTypePointer (&CTYPE_CHAR);
616
 
  type = new CTypeFunction (type, args, true);
 
661
  args = new Puma::CTypeList (2);
 
662
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
663
  type = new Puma::CTypePointer (type);
 
664
  args->AddEntry (type); // const char*
 
665
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
666
  type = new Puma::CTypePointer (type);
 
667
  args->AddEntry (type); // const char*
 
668
  type = new Puma::CTypePointer (&Puma::CTYPE_CHAR);
 
669
  type = new Puma::CTypeFunction (type, args, true);
617
670
  info = createFunction ("__builtin_strpbrk", current_scope, type);
618
671
  createParameter (info, args->Entry (0));
619
672
  createParameter (info, args->Entry (1));
620
673
 
621
674
  // char *__builtin_strstr(const char *haystack, const char *needle);
622
 
  args = new CTypeList (2);
623
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
624
 
  type = new CTypePointer (type);
625
 
  args->AddEntry (type); // const char*
626
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
627
 
  type = new CTypePointer (type);
628
 
  args->AddEntry (type); // const char*
629
 
  type = new CTypePointer (&CTYPE_CHAR);
630
 
  type = new CTypeFunction (type, args, true);
 
675
  args = new Puma::CTypeList (2);
 
676
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
677
  type = new Puma::CTypePointer (type);
 
678
  args->AddEntry (type); // const char*
 
679
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
680
  type = new Puma::CTypePointer (type);
 
681
  args->AddEntry (type); // const char*
 
682
  type = new Puma::CTypePointer (&Puma::CTYPE_CHAR);
 
683
  type = new Puma::CTypeFunction (type, args, true);
631
684
  info = createFunction ("__builtin_strstr", current_scope, type);
632
685
  createParameter (info, args->Entry (0));
633
686
  createParameter (info, args->Entry (1));
635
688
  // math functions
636
689
  
637
690
  // double __builtin_fabs(double x)
638
 
  args = new CTypeList (1);
639
 
  args->AddEntry (&CTYPE_DOUBLE); // double
640
 
  type = new CTypeFunction (&CTYPE_DOUBLE, args, true);
 
691
  args = new Puma::CTypeList (1);
 
692
  args->AddEntry (&Puma::CTYPE_DOUBLE); // double
 
693
  type = new Puma::CTypeFunction (&Puma::CTYPE_DOUBLE, args, true);
641
694
  info = createFunction ("__builtin_fabs", current_scope, type);
642
695
  createParameter (info, args->Entry (0));
643
696
 
644
697
  // float __builtin_fabsf(float x)
645
 
  args = new CTypeList (1);
646
 
  args->AddEntry (&CTYPE_FLOAT); //double
647
 
  type = new CTypeFunction (&CTYPE_FLOAT, args, true);
 
698
  args = new Puma::CTypeList (1);
 
699
  args->AddEntry (&Puma::CTYPE_FLOAT); //double
 
700
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
648
701
  info = createFunction ("__builtin_fabsf", current_scope, type);
649
702
  createParameter (info, args->Entry (0));
650
703
 
651
704
  // long double __builtin_fabsl(long double x)
652
 
  args = new CTypeList (1);
653
 
  args->AddEntry (&CTYPE_LONG_DOUBLE); // double
654
 
  type = new CTypeFunction (&CTYPE_LONG_DOUBLE, args, true);
 
705
  args = new Puma::CTypeList (1);
 
706
  args->AddEntry (&Puma::CTYPE_LONG_DOUBLE); // double
 
707
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
655
708
  info = createFunction ("__builtin_fabsl", current_scope, type);
656
709
  createParameter (info, args->Entry (0));
657
710
 
658
711
  // float __builtin_cosf(float x)
659
 
  args = new CTypeList (1);
660
 
  args->AddEntry (&CTYPE_FLOAT); //double
661
 
  type = new CTypeFunction (&CTYPE_FLOAT, args, true);
 
712
  args = new Puma::CTypeList (1);
 
713
  args->AddEntry (&Puma::CTYPE_FLOAT); //double
 
714
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
662
715
  info = createFunction ("__builtin_cosf", current_scope, type);
663
716
  createParameter (info, args->Entry (0));
664
717
 
665
718
  // long double __builtin_cosl(long double x)
666
 
  args = new CTypeList (1);
667
 
  args->AddEntry (&CTYPE_LONG_DOUBLE); // double
668
 
  type = new CTypeFunction (&CTYPE_LONG_DOUBLE, args, true);
 
719
  args = new Puma::CTypeList (1);
 
720
  args->AddEntry (&Puma::CTYPE_LONG_DOUBLE); // double
 
721
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
669
722
  info = createFunction ("__builtin_cosl", current_scope, type);
670
723
  createParameter (info, args->Entry (0));
671
724
 
672
725
  // float __builtin_sinf(float x)
673
 
  args = new CTypeList (1);
674
 
  args->AddEntry (&CTYPE_FLOAT); //double
675
 
  type = new CTypeFunction (&CTYPE_FLOAT, args, true);
 
726
  args = new Puma::CTypeList (1);
 
727
  args->AddEntry (&Puma::CTYPE_FLOAT); //double
 
728
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
676
729
  info = createFunction ("__builtin_sinf", current_scope, type);
677
730
  createParameter (info, args->Entry (0));
678
731
 
679
732
  // long double __builtin_sinl(long double x)
680
 
  args = new CTypeList (1);
681
 
  args->AddEntry (&CTYPE_LONG_DOUBLE); // double
682
 
  type = new CTypeFunction (&CTYPE_LONG_DOUBLE, args, true);
 
733
  args = new Puma::CTypeList (1);
 
734
  args->AddEntry (&Puma::CTYPE_LONG_DOUBLE); // double
 
735
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
683
736
  info = createFunction ("__builtin_sinl", current_scope, type);
684
737
  createParameter (info, args->Entry (0));
685
738
 
686
739
  // float __builtin_sqrtf(float x)
687
 
  args = new CTypeList (1);
688
 
  args->AddEntry (&CTYPE_FLOAT); //double
689
 
  type = new CTypeFunction (&CTYPE_FLOAT, args, true);
 
740
  args = new Puma::CTypeList (1);
 
741
  args->AddEntry (&Puma::CTYPE_FLOAT); //double
 
742
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
690
743
  info = createFunction ("__builtin_sqrtf", current_scope, type);
691
744
  createParameter (info, args->Entry (0));
692
745
 
693
746
  // long double __builtin_sqrtl(long double x)
694
 
  args = new CTypeList (1);
695
 
  args->AddEntry (&CTYPE_LONG_DOUBLE); // double
696
 
  type = new CTypeFunction (&CTYPE_LONG_DOUBLE, args, true);
 
747
  args = new Puma::CTypeList (1);
 
748
  args->AddEntry (&Puma::CTYPE_LONG_DOUBLE); // double
 
749
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
697
750
  info = createFunction ("__builtin_sqrtl", current_scope, type);
698
751
  createParameter (info, args->Entry (0));
699
752
 
701
754
  // debug/frame access functions
702
755
 
703
756
  // void *__builtin_return_address(unsigned int c);
704
 
  args = new CTypeList (1);
705
 
  args->AddEntry (&CTYPE_UNSIGNED_INT); // inr
706
 
  type = new CTypePointer (&CTYPE_VOID);
707
 
  type = new CTypeFunction (type, args, true);
 
757
  args = new Puma::CTypeList (1);
 
758
  args->AddEntry (&Puma::CTYPE_UNSIGNED_INT); // inr
 
759
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
760
  type = new Puma::CTypeFunction (type, args, true);
708
761
  info = createFunction ("__builtin_return_address", current_scope, type);
709
762
  createParameter (info, args->Entry (0));
710
763
 
711
764
  // void *__builtin_frame_address(unsigned int c);
712
 
  args = new CTypeList (1);
713
 
  args->AddEntry (&CTYPE_UNSIGNED_INT); // inr
714
 
  type = new CTypePointer (&CTYPE_VOID);
715
 
  type = new CTypeFunction (type, args, true);
 
765
  args = new Puma::CTypeList (1);
 
766
  args->AddEntry (&Puma::CTYPE_UNSIGNED_INT); // inr
 
767
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
768
  type = new Puma::CTypeFunction (type, args, true);
716
769
  info = createFunction ("__builtin_frame_address", current_scope, type);
717
770
  createParameter (info, args->Entry (0));
718
771
 
720
773
  // limits
721
774
 
722
775
  // double __builtin_huge_val (void)
723
 
  args = new CTypeList (0);
724
 
  type = new CTypeFunction (&CTYPE_DOUBLE, args, true);
 
776
  args = new Puma::CTypeList (0);
 
777
  type = new Puma::CTypeFunction (&Puma::CTYPE_DOUBLE, args, true);
725
778
  info = createFunction ("__builtin_huge_val", current_scope, type);
726
779
 
727
780
  // float __builtin_huge_valf (void)
728
 
  args = new CTypeList (0);
729
 
  type = new CTypeFunction (&CTYPE_FLOAT, args, true);
 
781
  args = new Puma::CTypeList (0);
 
782
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
730
783
  info = createFunction ("__builtin_huge_valf", current_scope, type);
731
784
 
732
785
  // long double __builtin_huge_vall (void)
733
 
  args = new CTypeList (0);
734
 
  type = new CTypeFunction (&CTYPE_LONG_DOUBLE, args, true);
 
786
  args = new Puma::CTypeList (0);
 
787
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
735
788
  info = createFunction ("__builtin_huge_vall", current_scope, type);
736
789
 
737
790
  // double __builtin_inf (void)
738
 
  args = new CTypeList (0);
739
 
  type = new CTypeFunction (&CTYPE_DOUBLE, args, true);
 
791
  args = new Puma::CTypeList (0);
 
792
  type = new Puma::CTypeFunction (&Puma::CTYPE_DOUBLE, args, true);
740
793
  info = createFunction ("__builtin_inf", current_scope, type);
741
794
 
742
795
  // float __builtin_inff (void)
743
 
  args = new CTypeList (0);
744
 
  type = new CTypeFunction (&CTYPE_FLOAT, args, true);
 
796
  args = new Puma::CTypeList (0);
 
797
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
745
798
  info = createFunction ("__builtin_inff", current_scope, type);
746
799
 
747
800
  // long double __builtin_infl (void)
748
 
  args = new CTypeList (0);
749
 
  type = new CTypeFunction (&CTYPE_LONG_DOUBLE, args, true);
 
801
  args = new Puma::CTypeList (0);
 
802
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
750
803
  info = createFunction ("__builtin_infl", current_scope, type);
751
804
 
752
805
  // double __builtin_nan (const char *str)
753
 
  args = new CTypeList (1);
754
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
755
 
  type = new CTypePointer (type);
 
806
  args = new Puma::CTypeList (1);
 
807
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
808
  type = new Puma::CTypePointer (type);
756
809
  args->AddEntry (type); // const char*
757
 
  type = new CTypeFunction (&CTYPE_DOUBLE, args, true);
 
810
  type = new Puma::CTypeFunction (&Puma::CTYPE_DOUBLE, args, true);
758
811
  info = createFunction ("__builtin_nan", current_scope, type);
759
812
  createParameter (info, args->Entry (0));
760
813
 
761
814
  // float __builtin_nanf (const char *str)
762
 
  args = new CTypeList (1);
763
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
764
 
  type = new CTypePointer (type);
 
815
  args = new Puma::CTypeList (1);
 
816
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
817
  type = new Puma::CTypePointer (type);
765
818
  args->AddEntry (type); // const char*
766
 
  type = new CTypeFunction (&CTYPE_FLOAT, args, true);
 
819
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
767
820
  info = createFunction ("__builtin_nanf", current_scope, type);
768
821
  createParameter (info, args->Entry (0));
769
822
 
770
823
  // double __builtin_nanl (const char *str)
771
 
  args = new CTypeList (1);
772
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
773
 
  type = new CTypePointer (type);
 
824
  args = new Puma::CTypeList (1);
 
825
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
826
  type = new Puma::CTypePointer (type);
774
827
  args->AddEntry (type); // const char*
775
 
  type = new CTypeFunction (&CTYPE_LONG_DOUBLE, args, true);
 
828
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
776
829
  info = createFunction ("__builtin_nanl", current_scope, type);
777
830
  createParameter (info, args->Entry (0));
778
831
 
779
832
  // double __builtin_nans (const char *str)
780
 
  args = new CTypeList (1);
781
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
782
 
  type = new CTypePointer (type);
 
833
  args = new Puma::CTypeList (1);
 
834
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
835
  type = new Puma::CTypePointer (type);
783
836
  args->AddEntry (type); // const char*
784
 
  type = new CTypeFunction (&CTYPE_DOUBLE, args, true);
 
837
  type = new Puma::CTypeFunction (&Puma::CTYPE_DOUBLE, args, true);
785
838
  info = createFunction ("__builtin_nans", current_scope, type);
786
839
  createParameter (info, args->Entry (0));
787
840
 
788
841
  // float __builtin_nansf (const char *str)
789
 
  args = new CTypeList (1);
790
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
791
 
  type = new CTypePointer (type);
 
842
  args = new Puma::CTypeList (1);
 
843
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
844
  type = new Puma::CTypePointer (type);
792
845
  args->AddEntry (type); // const char*
793
 
  type = new CTypeFunction (&CTYPE_FLOAT, args, true);
 
846
  type = new Puma::CTypeFunction (&Puma::CTYPE_FLOAT, args, true);
794
847
  info = createFunction ("__builtin_nansf", current_scope, type);
795
848
  createParameter (info, args->Entry (0));
796
849
 
797
850
  // double __builtin_nansl (const char *str)
798
 
  args = new CTypeList (1);
799
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
800
 
  type = new CTypePointer (type);
 
851
  args = new Puma::CTypeList (1);
 
852
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
853
  type = new Puma::CTypePointer (type);
801
854
  args->AddEntry (type); // const char*
802
 
  type = new CTypeFunction (&CTYPE_LONG_DOUBLE, args, true);
 
855
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG_DOUBLE, args, true);
803
856
  info = createFunction ("__builtin_nansl", current_scope, type);
804
857
  createParameter (info, args->Entry (0));
805
858
 
807
860
  // allocation functions
808
861
 
809
862
  // void *__builtin_alloca(size_t size);
810
 
  args = new CTypeList (1);
811
 
  args->AddEntry (CTypeInfo::CTYPE_SIZE_T);
812
 
  type = new CTypePointer (&CTYPE_VOID);
813
 
  type = new CTypeFunction (type, args, true);
 
863
  args = new Puma::CTypeList (1);
 
864
  args->AddEntry (Puma::CTypeInfo::CTYPE_SIZE_T);
 
865
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
 
866
  type = new Puma::CTypeFunction (type, args, true);
814
867
  info = createFunction ("__builtin_alloca", current_scope, type);
815
868
  createParameter (info, args->Entry (0));
816
869
  
818
871
  // variable arguments access functions
819
872
 
820
873
  // void __builtin_stdarg_start(...)
821
 
  args = new CTypeList (1);
822
 
  args->AddEntry (&CTYPE_ELLIPSIS); // ...
823
 
  type = new CTypeFunction (&CTYPE_VOID, args, true);
 
874
  args = new Puma::CTypeList (1);
 
875
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
876
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
824
877
  info = createFunction ("__builtin_stdarg_start", current_scope, type);
825
878
  createParameter (info, args->Entry (0));
826
879
 
827
880
  // void __builtin_va_start(...)
828
 
  args = new CTypeList (1);
829
 
  args->AddEntry (&CTYPE_ELLIPSIS); // ...
830
 
  type = new CTypeFunction (&CTYPE_VOID, args, true);
 
881
  args = new Puma::CTypeList (1);
 
882
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
883
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
831
884
  info = createFunction ("__builtin_va_start", current_scope, type);
832
885
  createParameter (info, args->Entry (0));
833
886
 
834
887
  // hm, __builtin_va_arg is a problem as it has a variable result type
835
888
  // I use void __builtin_va_start_helper(...)
836
 
  args = new CTypeList (1);
837
 
  args->AddEntry (&CTYPE_ELLIPSIS); // ...
838
 
  type = new CTypeFunction (&CTYPE_INT, args, true);
 
889
  args = new Puma::CTypeList (1);
 
890
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
891
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
839
892
  info = createFunction ("__builtin_va_arg_helper", current_scope, type);
840
893
  createParameter (info, args->Entry (0));
841
894
  
842
895
  // void __builtin_va_end(...)
843
 
  args = new CTypeList (1);
844
 
  args->AddEntry (&CTYPE_ELLIPSIS); // ...
845
 
  type = new CTypeFunction (&CTYPE_VOID, args, true);
 
896
  args = new Puma::CTypeList (1);
 
897
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
898
  type = new Puma::CTypeFunction (&Puma::CTYPE_VOID, args, true);
846
899
  info = createFunction ("__builtin_va_end", current_scope, type);
847
900
  createParameter (info, args->Entry (0));
848
901
 
850
903
  // compiler optimization
851
904
  
852
905
  // long __builtin_expect (long exp, long c)
853
 
  args = new CTypeList (2);
854
 
  args->AddEntry (&CTYPE_LONG); // long
855
 
  args->AddEntry (&CTYPE_LONG); // long
856
 
  type = new CTypeFunction (&CTYPE_LONG, args, true);
 
906
  args = new Puma::CTypeList (2);
 
907
  args->AddEntry (&Puma::CTYPE_LONG); // long
 
908
  args->AddEntry (&Puma::CTYPE_LONG); // long
 
909
  type = new Puma::CTypeFunction (&Puma::CTYPE_LONG, args, true);
857
910
  info = createFunction ("__builtin_expect", current_scope, type);
858
911
  createParameter (info, args->Entry (0));
859
912
  createParameter (info, args->Entry (1));
860
913
  
861
914
  // int __builtin_constant_p (...)
862
 
  args = new CTypeList (1);
863
 
  args->AddEntry (&CTYPE_ELLIPSIS); // ...
864
 
  type = new CTypeFunction (&CTYPE_INT, args, true);
 
915
  args = new Puma::CTypeList (1);
 
916
  args->AddEntry (&Puma::CTYPE_ELLIPSIS); // ...
 
917
  type = new Puma::CTypeFunction (&Puma::CTYPE_INT, args, true);
865
918
  info = createFunction ("__builtin_constant_p", current_scope, type);
866
919
  createParameter (info, args->Entry (0));
867
920
  
869
922
  // builtin typedefs (shouldn't be here!)
870
923
  
871
924
  // typedef void *__builtin_va_list
872
 
  type = new CTypePointer (&CTYPE_VOID);
 
925
  type = new Puma::CTypePointer (&Puma::CTYPE_VOID);
873
926
  createTypedef ("__builtin_va_list", current_scope, type);
874
927
 
875
928
 
876
929
  // builtin attributes
877
 
  CAttributeInfo *attr;
 
930
  Puma::CAttributeInfo *attr;
878
931
 
879
932
  // static const char *__func__;
880
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
881
 
  type = new CTypePointer (type);
 
933
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
934
  type = new Puma::CTypePointer (type);
882
935
  attr = createAttribute ("__func__", current_scope, type, true);
883
936
 
884
937
  // static const char *__FUNCTION__;
885
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
886
 
  type = new CTypePointer (type);
 
938
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
939
  type = new Puma::CTypePointer (type);
887
940
  attr = createAttribute ("__FUNCTION__", current_scope, type, true);
888
941
 
889
942
  // static const char *__PRETTY_FUNCTION__;
890
 
  type = new CTypeQualified (&CTYPE_CHAR, true, false, false);
891
 
  type = new CTypePointer (type);
 
943
  type = new Puma::CTypeQualified (&Puma::CTYPE_CHAR, true, false, false);
 
944
  type = new Puma::CTypePointer (type);
892
945
  attr = createAttribute ("__PRETTY_FUNCTION__", current_scope, type, true);
893
946
 
894
947
}