~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to lib/cppparser/parser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of KDevelop
 
2
    Copyright (C) 2002,2003 Roberto Raggi <roberto@kdevelop.org>
 
3
 
 
4
    This library is free software; you can redistribute it and/or
 
5
    modify it under the terms of the GNU Library General Public
 
6
    License as published by the Free Software Foundation; either
 
7
    version 2 of the License, or (at your option) any later version.
 
8
 
 
9
    This library is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
    Library General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Library General Public License
 
15
    along with this library; see the file COPYING.LIB.  If not, write to
 
16
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
    Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
// c++ support
 
21
#include "parser.h"
 
22
#include "driver.h"
 
23
#include "lexer.h"
 
24
#include "errors.h"
 
25
 
 
26
// qt
 
27
#include <qstring.h>
 
28
#include <qstringlist.h>
 
29
#include <qasciidict.h>
 
30
 
 
31
#include <kdebug.h>
 
32
#include <klocale.h>
 
33
 
 
34
using namespace std;
 
35
 
 
36
#define ADVANCE(tk, descr) \
 
37
{ \
 
38
  const Token& token = lex->lookAhead( 0 ); \
 
39
  if( token != tk ){ \
 
40
      reportError( i18n("'%1' expected found '%2'").arg(descr).arg(token.text()) ); \
 
41
      return false; \
 
42
  } \
 
43
  lex->nextToken(); \
 
44
}
 
45
 
 
46
#define ADVANCE_NR(tk, descr) \
 
47
{ \
 
48
  const Token& token = lex->lookAhead( 0 ); \
 
49
  if( token != tk ){ \
 
50
      reportError( i18n("'%1' expected found '%2'").arg(descr).arg(token.text()) ); \
 
51
  } \
 
52
  else \
 
53
      lex->nextToken(); \
 
54
}
 
55
 
 
56
#define CHECK(tk, descr) \
 
57
{ \
 
58
  const Token& token = lex->lookAhead( 0 ); \
 
59
  if( token != tk ){ \
 
60
      return false; \
 
61
  } \
 
62
  lex->nextToken(); \
 
63
}
 
64
 
 
65
#define MATCH(tk, descr) \
 
66
{ \
 
67
  const Token& token = lex->lookAhead( 0 ); \
 
68
  if( token != tk ){ \
 
69
      reportError( Errors::SyntaxError ); \
 
70
      return false; \
 
71
  } \
 
72
}
 
73
 
 
74
#define UPDATE_POS(node, start, end) \
 
75
{ \
 
76
   int line, col; \
 
77
   const Token &a = lex->tokenAt(start); \
 
78
   const Token &b = lex->tokenAt( end!=start ? end-1 : end ); \
 
79
   a.getStartPosition( &line, &col ); \
 
80
   (node)->setStartPosition( line, col ); \
 
81
   b.getEndPosition( &line, &col ); \
 
82
   (node)->setEndPosition( line, col ); \
 
83
   if( (node)->nodeType() == NodeType_Generic ) { \
 
84
       if ((start) == (end) || (end) == (start)+1) \
 
85
           (node)->setSlice(lex->source(), a.position(), a.length()); \
 
86
       else \
 
87
           (node)->setText( toString((start),(end)) ); \
 
88
   } \
 
89
}
 
90
 
 
91
#define AST_FROM_TOKEN(node, tk) \
 
92
    AST::Node node = CreateNode<AST>(); \
 
93
    UPDATE_POS( node, (tk), (tk)+1 );
 
94
 
 
95
 
 
96
//@todo remove me
 
97
enum
 
98
{
 
99
    OBJC_CLASS,
 
100
    OBJC_PROTOCOL,
 
101
    OBJC_ALIAS
 
102
};
 
103
 
 
104
struct ParserPrivateData
 
105
{
 
106
    ParserPrivateData()
 
107
        {}
 
108
};
 
109
 
 
110
Parser::Parser( Driver* driver, Lexer* lexer )
 
111
    : m_driver( driver ),
 
112
      lex( lexer )
 
113
{
 
114
    d = new ParserPrivateData();
 
115
 
 
116
    m_maxProblems = 5;
 
117
    objcp = false;
 
118
}
 
119
 
 
120
Parser::~Parser()
 
121
{
 
122
    delete d;
 
123
    d = 0;
 
124
}
 
125
 
 
126
bool Parser::reportError( const Error& err )
 
127
{
 
128
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::reportError()" << endl;
 
129
    if( m_problems < m_maxProblems ){
 
130
        ++m_problems;
 
131
        int line=0, col=0;
 
132
        const Token& token = lex->lookAhead( 0 );
 
133
        lex->getTokenPosition( token, &line, &col );
 
134
 
 
135
        QString s = lex->lookAhead(0).text();
 
136
        s = s.left( 30 ).stripWhiteSpace();
 
137
        if( s.isEmpty() )
 
138
            s = i18n( "<eof>" );
 
139
 
 
140
        m_driver->addProblem( m_driver->currentFileName(), Problem(err.text.arg(s), line, col) );
 
141
    }
 
142
 
 
143
    return true;
 
144
}
 
145
 
 
146
bool Parser::reportError( const QString& msg )
 
147
{
 
148
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::reportError()" << endl;
 
149
    if( m_problems < m_maxProblems ){
 
150
        ++m_problems;
 
151
        int line=0, col=0;
 
152
        const Token& token = lex->lookAhead( 0 );
 
153
        lex->getTokenPosition( token, &line, &col );
 
154
 
 
155
        m_driver->addProblem( m_driver->currentFileName(), Problem(msg, line, col) );
 
156
    }
 
157
 
 
158
    return true;
 
159
}
 
160
 
 
161
void Parser::syntaxError()
 
162
{
 
163
    (void) reportError( Errors::SyntaxError );
 
164
}
 
165
 
 
166
bool Parser::skipUntil( int token )
 
167
{
 
168
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipUntil()" << endl;
 
169
    while( !lex->lookAhead(0).isNull() ){
 
170
        if( lex->lookAhead(0) == token )
 
171
            return true;
 
172
 
 
173
        lex->nextToken();
 
174
    }
 
175
 
 
176
    return false;
 
177
}
 
178
 
 
179
bool Parser::skipUntilDeclaration()
 
180
{
 
181
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipUntilDeclaration()" << endl;
 
182
 
 
183
    while( !lex->lookAhead(0).isNull() ){
 
184
 
 
185
        switch( lex->lookAhead(0) ){
 
186
        case ';':
 
187
        case '~':
 
188
        case Token_scope:
 
189
        case Token_identifier:
 
190
        case Token_operator:
 
191
        case Token_char:
 
192
        case Token_wchar_t:
 
193
        case Token_bool:
 
194
        case Token_short:
 
195
        case Token_int:
 
196
        case Token_long:
 
197
        case Token_signed:
 
198
        case Token_unsigned:
 
199
        case Token_float:
 
200
        case Token_double:
 
201
        case Token_void:
 
202
        case Token_extern:
 
203
        case Token_namespace:
 
204
        case Token_using:
 
205
        case Token_typedef:
 
206
        case Token_asm:
 
207
        case Token_template:
 
208
        case Token_export:
 
209
 
 
210
        case Token_const:       // cv
 
211
        case Token_volatile:    // cv
 
212
 
 
213
        case Token_public:
 
214
        case Token_protected:
 
215
        case Token_private:
 
216
        case Token_signals:      // Qt
 
217
        case Token_slots:        // Qt
 
218
            return true;
 
219
 
 
220
        default:
 
221
            lex->nextToken();
 
222
        }
 
223
    }
 
224
 
 
225
    return false;
 
226
}
 
227
 
 
228
bool Parser::skipUntilStatement()
 
229
{
 
230
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipUntilStatement() -- token = " << lex->lookAhead(0).text() << endl;
 
231
 
 
232
    while( !lex->lookAhead(0).isNull() ){
 
233
        switch( lex->lookAhead(0) ){
 
234
                case ';':
 
235
                case '{':
 
236
                case '}':
 
237
                case Token_const:
 
238
                case Token_volatile:
 
239
                case Token_identifier:
 
240
                case Token_case:
 
241
                case Token_default:
 
242
                case Token_if:
 
243
                case Token_switch:
 
244
                case Token_while:
 
245
                case Token_do:
 
246
                case Token_for:
 
247
                case Token_break:
 
248
                case Token_continue:
 
249
                case Token_return:
 
250
                case Token_goto:
 
251
                case Token_try:
 
252
                case Token_catch:
 
253
                case Token_throw:
 
254
                case Token_char:
 
255
                case Token_wchar_t:
 
256
                case Token_bool:
 
257
                case Token_short:
 
258
                case Token_int:
 
259
                case Token_long:
 
260
                case Token_signed:
 
261
                case Token_unsigned:
 
262
                case Token_float:
 
263
                case Token_double:
 
264
                case Token_void:
 
265
                case Token_class:
 
266
                case Token_struct:
 
267
                case Token_union:
 
268
                case Token_enum:
 
269
                case Token_scope:
 
270
                case Token_template:
 
271
                case Token_using:
 
272
                    return true;
 
273
 
 
274
            default:
 
275
                lex->nextToken();
 
276
        }
 
277
    }
 
278
 
 
279
    return false;
 
280
}
 
281
 
 
282
bool Parser::skip( int l, int r )
 
283
{
 
284
    int count = 0;
 
285
    while( !lex->lookAhead(0).isNull() ){
 
286
        int tk = lex->lookAhead( 0 );
 
287
 
 
288
        if( tk == l )
 
289
            ++count;
 
290
        else if( tk == r )
 
291
            --count;
 
292
        else if( l != '{' && (tk == '{' || tk == '}' || tk == ';') )
 
293
            return false;
 
294
 
 
295
        if( count == 0 )
 
296
            return true;
 
297
 
 
298
        lex->nextToken();
 
299
    }
 
300
 
 
301
    return false;
 
302
}
 
303
 
 
304
bool Parser::skipCommaExpression( AST::Node& node )
 
305
{
 
306
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipCommaExpression()" << endl;
 
307
 
 
308
    int start = lex->index();
 
309
 
 
310
    AST::Node expr;
 
311
    if( !skipExpression(expr) )
 
312
        return false;
 
313
 
 
314
    while( lex->lookAhead(0) == ',' ){
 
315
        lex->nextToken();
 
316
 
 
317
        if( !skipExpression(expr) ){
 
318
            reportError( i18n("expression expected") );
 
319
            return false;
 
320
        }
 
321
    }
 
322
 
 
323
    AST::Node ast = CreateNode<AST>();
 
324
    UPDATE_POS( ast, start, lex->index() );
 
325
    node = ast;
 
326
 
 
327
    return true;
 
328
}
 
329
 
 
330
bool Parser::skipExpression( AST::Node& node )
 
331
{
 
332
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipExpression()" << endl;
 
333
 
 
334
    int start = lex->index();
 
335
 
 
336
    while( !lex->lookAhead(0).isNull() ){
 
337
        int tk = lex->lookAhead( 0 );
 
338
 
 
339
        switch( tk ){
 
340
        case '(':
 
341
            skip( '(', ')' );
 
342
            lex->nextToken();
 
343
            break;
 
344
 
 
345
        case '[':
 
346
            skip( '[', ']' );
 
347
            lex->nextToken();
 
348
            break;
 
349
 
 
350
#if 0
 
351
        case Token_identifier:
 
352
            lex->nextToken();
 
353
            if( lex->lookAhead( 0 ) == Token_identifier )
 
354
                return true;
 
355
            break;
 
356
#endif
 
357
 
 
358
        case ';':
 
359
        case ',':
 
360
        case ']':
 
361
        case ')':
 
362
        case '{':
 
363
        case '}':
 
364
        case Token_case:
 
365
        case Token_default:
 
366
        case Token_if:
 
367
        case Token_while:
 
368
        case Token_do:
 
369
        case Token_for:
 
370
        case Token_break:
 
371
        case Token_continue:
 
372
        case Token_return:
 
373
        case Token_goto:
 
374
        {
 
375
            AST::Node ast = CreateNode<AST>();
 
376
            UPDATE_POS( ast, start, lex->index() );
 
377
            node = ast;
 
378
        }
 
379
        return true;
 
380
 
 
381
        default:
 
382
            lex->nextToken();
 
383
        }
 
384
    }
 
385
 
 
386
    return false;
 
387
}
 
388
 
 
389
bool Parser::parseName( NameAST::Node& node )
 
390
{
 
391
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseName()" << endl;
 
392
 
 
393
    GroupAST::Node winDeclSpec;
 
394
    parseWinDeclSpec( winDeclSpec );
 
395
 
 
396
    int start = lex->index();
 
397
 
 
398
    NameAST::Node ast = CreateNode<NameAST>();
 
399
 
 
400
    if( lex->lookAhead(0) == Token_scope ){
 
401
        ast->setGlobal( true );
 
402
        lex->nextToken();
 
403
    }
 
404
 
 
405
    int idx = lex->index();
 
406
 
 
407
    while( true ){
 
408
        ClassOrNamespaceNameAST::Node n;
 
409
        if( !parseUnqualifiedName(n) ) {
 
410
            return false;
 
411
        }
 
412
 
 
413
        if( lex->lookAhead(0) == Token_scope ){
 
414
            lex->nextToken();
 
415
            ast->addClassOrNamespaceName( n );
 
416
            if( lex->lookAhead(0) == Token_template )
 
417
                lex->nextToken(); /// skip optional template     #### @todo CHECK
 
418
        } else {
 
419
            ast->setUnqualifiedName( n );
 
420
            break;
 
421
        }
 
422
    }
 
423
 
 
424
    if( idx == lex->index() )
 
425
        return false;
 
426
 
 
427
    UPDATE_POS( ast, start, lex->index() );
 
428
    node = ast;
 
429
 
 
430
    return true;
 
431
}
 
432
 
 
433
bool Parser::parseTranslationUnit( TranslationUnitAST::Node& node )
 
434
{
 
435
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTranslationUnit()" << endl;
 
436
 
 
437
    int start = lex->index();
 
438
 
 
439
    m_problems = 0;
 
440
    TranslationUnitAST::Node tun = CreateNode<TranslationUnitAST>();
 
441
    node = tun;
 
442
    while( !lex->lookAhead(0).isNull() ){
 
443
        DeclarationAST::Node def;
 
444
        int startDecl = lex->index();
 
445
        if( !parseDeclaration(def) ){
 
446
            // error recovery
 
447
            if( startDecl == lex->index() )
 
448
                lex->nextToken(); // skip at least one token
 
449
            skipUntilDeclaration();
 
450
        }
 
451
        node->addDeclaration( def );
 
452
    }
 
453
 
 
454
    UPDATE_POS( node, start, lex->index() );
 
455
 
 
456
    // force (0,0) as start position
 
457
    node->setStartPosition( 0, 0 );
 
458
 
 
459
    return m_problems == 0;
 
460
}
 
461
 
 
462
bool Parser::parseDeclaration( DeclarationAST::Node& node )
 
463
{
 
464
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclaration()" << endl;
 
465
 
 
466
    int start = lex->index();
 
467
 
 
468
    switch( lex->lookAhead(0) ){
 
469
 
 
470
    case ';':
 
471
        lex->nextToken();
 
472
        return true;
 
473
 
 
474
    case Token_extern:
 
475
        return parseLinkageSpecification( node );
 
476
 
 
477
    case Token_namespace:
 
478
        return parseNamespace( node );
 
479
 
 
480
    case Token_using:
 
481
        return parseUsing( node );
 
482
 
 
483
    case Token_typedef:
 
484
        return parseTypedef( node );
 
485
 
 
486
    case Token_asm:
 
487
        return parseAsmDefinition( node );
 
488
 
 
489
    case Token_template:
 
490
    case Token_export:
 
491
        return parseTemplateDeclaration( node );
 
492
 
 
493
    default:
 
494
        {
 
495
            // lex->setIndex( start );
 
496
 
 
497
            if( objcp && parseObjcDef(node) )
 
498
                return true;
 
499
 
 
500
            lex->setIndex( start );
 
501
 
 
502
            GroupAST::Node storageSpec;
 
503
            parseStorageClassSpecifier( storageSpec );
 
504
 
 
505
            GroupAST::Node cv;
 
506
            parseCvQualify( cv );
 
507
 
 
508
            TypeSpecifierAST::Node spec;
 
509
            AST::Node declarator;
 
510
            if( parseEnumSpecifier(spec) || parseClassSpecifier(spec) ){
 
511
                spec->setCvQualify( cv );
 
512
 
 
513
                GroupAST::Node cv2;
 
514
                parseCvQualify( cv2 );
 
515
                spec->setCv2Qualify( cv2 );
 
516
 
 
517
                InitDeclaratorListAST::Node declarators;
 
518
                parseInitDeclaratorList(declarators);
 
519
                ADVANCE( ';', ";" );
 
520
 
 
521
                SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
 
522
                ast->setStorageSpecifier( storageSpec );
 
523
                ast->setTypeSpec( spec );
 
524
                ast->setInitDeclaratorList( declarators );
 
525
                UPDATE_POS( ast, start, lex->index() );
 
526
                node = ast;
 
527
 
 
528
                return true;
 
529
            }
 
530
 
 
531
            lex->setIndex( start );
 
532
            return parseDeclarationInternal( node );
 
533
        }
 
534
 
 
535
    } // end switch
 
536
}
 
537
 
 
538
bool Parser::parseLinkageSpecification( DeclarationAST::Node& node )
 
539
{
 
540
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseLinkageSpecification()" << endl;
 
541
 
 
542
    int start = lex->index();
 
543
 
 
544
    if( lex->lookAhead(0) != Token_extern ){
 
545
        return false;
 
546
    }
 
547
    lex->nextToken();
 
548
 
 
549
    LinkageSpecificationAST::Node ast = CreateNode<LinkageSpecificationAST>();
 
550
 
 
551
    int startExternType = lex->index();
 
552
    if( lex->lookAhead(0) == Token_string_literal ){
 
553
        lex->nextToken();
 
554
        AST::Node externType = CreateNode<AST>();
 
555
        UPDATE_POS( externType, startExternType, lex->index() );
 
556
 
 
557
        ast->setExternType( externType );
 
558
    }
 
559
 
 
560
    if( lex->lookAhead(0) == '{' ){
 
561
        LinkageBodyAST::Node linkageBody;
 
562
        parseLinkageBody( linkageBody );
 
563
        ast->setLinkageBody( linkageBody );
 
564
    } else {
 
565
        DeclarationAST::Node decl;
 
566
        if( !parseDeclaration(decl) ){
 
567
            reportError( i18n("Declaration syntax error") );
 
568
        }
 
569
        ast->setDeclaration( decl );
 
570
    }
 
571
 
 
572
    UPDATE_POS( ast, start, lex->index() );
 
573
 
 
574
    node = ast;
 
575
 
 
576
    return true;
 
577
}
 
578
 
 
579
bool Parser::parseLinkageBody( LinkageBodyAST::Node& node )
 
580
{
 
581
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseLinkageBody()" << endl;
 
582
 
 
583
    int start = lex->index();
 
584
 
 
585
    if( lex->lookAhead(0) != '{' ){
 
586
        return false;
 
587
    }
 
588
    lex->nextToken();
 
589
 
 
590
    LinkageBodyAST::Node lba = CreateNode<LinkageBodyAST>();
 
591
    node = lba;
 
592
 
 
593
    while( !lex->lookAhead(0).isNull() ){
 
594
        int tk = lex->lookAhead( 0 );
 
595
 
 
596
        if( tk == '}' )
 
597
            break;
 
598
 
 
599
        DeclarationAST::Node def;
 
600
        int startDecl = lex->index();
 
601
        if( parseDeclaration(def) ){
 
602
            node->addDeclaration( def );
 
603
        } else {
 
604
            // error recovery
 
605
            if( startDecl == lex->index() )
 
606
                lex->nextToken(); // skip at least one token
 
607
            skipUntilDeclaration();
 
608
        }
 
609
    }
 
610
 
 
611
    if( lex->lookAhead(0) != '}' ){
 
612
        reportError( i18n("} expected") );
 
613
    } else
 
614
        lex->nextToken();
 
615
 
 
616
    UPDATE_POS( node, start, lex->index() );
 
617
    return true;
 
618
}
 
619
 
 
620
bool Parser::parseNamespace( DeclarationAST::Node& node )
 
621
{
 
622
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseNamespace()" << endl;
 
623
 
 
624
    int start = lex->index();
 
625
 
 
626
    if( lex->lookAhead(0) != Token_namespace ){
 
627
        return false;
 
628
    }
 
629
    lex->nextToken();
 
630
 
 
631
    int startNamespaceName = lex->index();
 
632
    if( lex->lookAhead(0) == Token_identifier ){
 
633
        lex->nextToken();
 
634
    }
 
635
    AST::Node namespaceName = CreateNode<AST>();
 
636
    UPDATE_POS( namespaceName, startNamespaceName, lex->index() );
 
637
 
 
638
    if ( lex->lookAhead(0) == '=' ) {
 
639
        // namespace alias
 
640
        lex->nextToken();
 
641
 
 
642
        NameAST::Node name;
 
643
        if( parseName(name) ){
 
644
            ADVANCE( ';', ";" );
 
645
 
 
646
            NamespaceAliasAST::Node ast = CreateNode<NamespaceAliasAST>();
 
647
            ast->setNamespaceName( namespaceName );
 
648
            ast->setAliasName( name );
 
649
            UPDATE_POS( ast, start, lex->index() );
 
650
            node = ast;
 
651
            return true;
 
652
        } else {
 
653
            reportError( i18n("namespace expected") );
 
654
            return false;
 
655
        }
 
656
    } else if( lex->lookAhead(0) != '{' ){
 
657
        reportError( i18n("{ expected") );
 
658
        return false;
 
659
    }
 
660
 
 
661
    NamespaceAST::Node ast = CreateNode<NamespaceAST>();
 
662
    ast->setNamespaceName( namespaceName );
 
663
 
 
664
    LinkageBodyAST::Node linkageBody;
 
665
    parseLinkageBody( linkageBody );
 
666
 
 
667
    ast->setLinkageBody( linkageBody );
 
668
    UPDATE_POS( ast, start, lex->index() );
 
669
    node = ast;
 
670
 
 
671
    return true;
 
672
}
 
673
 
 
674
bool Parser::parseUsing( DeclarationAST::Node& node )
 
675
{
 
676
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseUsing()" << endl;
 
677
 
 
678
    int start = lex->index();
 
679
 
 
680
    if( lex->lookAhead(0) != Token_using ){
 
681
        return false;
 
682
    }
 
683
    lex->nextToken();
 
684
 
 
685
    if( lex->lookAhead(0) == Token_namespace ){
 
686
        if( !parseUsingDirective(node) ){
 
687
            return false;
 
688
        }
 
689
        UPDATE_POS( node, start, lex->index() );
 
690
        return true;
 
691
    }
 
692
 
 
693
    UsingAST::Node ast = CreateNode<UsingAST>();
 
694
 
 
695
    int startTypeName = lex->index();
 
696
    if( lex->lookAhead(0) == Token_typename ){
 
697
        lex->nextToken();
 
698
        AST::Node tn = CreateNode<AST>();
 
699
        UPDATE_POS( tn, startTypeName, lex->index() );
 
700
        ast->setTypeName( tn );
 
701
    }
 
702
 
 
703
    NameAST::Node name;
 
704
    if( !parseName(name) )
 
705
        return false;
 
706
 
 
707
    ast->setName( name );
 
708
 
 
709
    ADVANCE( ';', ";" );
 
710
 
 
711
    UPDATE_POS( ast, start, lex->index() );
 
712
    node = ast;
 
713
 
 
714
    return true;
 
715
}
 
716
 
 
717
bool Parser::parseUsingDirective( DeclarationAST::Node& node )
 
718
{
 
719
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseUsingDirective()" << endl;
 
720
 
 
721
    int start = lex->index();
 
722
 
 
723
    if( lex->lookAhead(0) != Token_namespace ){
 
724
        return false;
 
725
    }
 
726
    lex->nextToken();
 
727
 
 
728
    NameAST::Node name;
 
729
    if( !parseName(name) ){
 
730
        reportError( i18n("Namespace name expected") );
 
731
        return false;
 
732
    }
 
733
 
 
734
    ADVANCE( ';', ";" );
 
735
 
 
736
    UsingDirectiveAST::Node ast = CreateNode<UsingDirectiveAST>();
 
737
    ast->setName( name );
 
738
    UPDATE_POS( ast, start, lex->index() );
 
739
    node = ast;
 
740
 
 
741
    return true;
 
742
}
 
743
 
 
744
 
 
745
bool Parser::parseOperatorFunctionId( AST::Node& node )
 
746
{
 
747
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseOperatorFunctionId()" << endl;
 
748
 
 
749
    int start = lex->index();
 
750
 
 
751
    if( lex->lookAhead(0) != Token_operator ){
 
752
        return false;
 
753
    }
 
754
    lex->nextToken();
 
755
 
 
756
    AST::Node op;
 
757
    if( parseOperator(op) ){
 
758
        AST::Node asn = CreateNode<AST>();
 
759
        node = asn;
 
760
        UPDATE_POS( node, start, lex->index() );
 
761
        return true;
 
762
    } else {
 
763
        // parse cast operator
 
764
        GroupAST::Node cv;
 
765
        parseCvQualify(cv);
 
766
 
 
767
        TypeSpecifierAST::Node spec;
 
768
        if( !parseSimpleTypeSpecifier(spec) ){
 
769
            syntaxError();
 
770
            return false;
 
771
        }
 
772
        spec->setCvQualify( cv );
 
773
 
 
774
        GroupAST::Node cv2;
 
775
        parseCvQualify(cv2);
 
776
        spec->setCv2Qualify( cv2 );
 
777
 
 
778
        AST::Node ptrOp;
 
779
        while( parsePtrOperator(ptrOp) )
 
780
            ;
 
781
 
 
782
        AST::Node asn = CreateNode<AST>();
 
783
        node = asn;
 
784
        UPDATE_POS( node, start, lex->index() );
 
785
        return true;
 
786
    }
 
787
}
 
788
 
 
789
bool Parser::parseTemplateArgumentList( TemplateArgumentListAST::Node& node, bool reportError )
 
790
{
 
791
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTemplateArgumentList()" << endl;
 
792
 
 
793
    int start = lex->index();
 
794
 
 
795
    TemplateArgumentListAST::Node ast = CreateNode<TemplateArgumentListAST>();
 
796
 
 
797
    AST::Node templArg;
 
798
    if( !parseTemplateArgument(templArg) )
 
799
        return false;
 
800
    ast->addArgument( templArg );
 
801
 
 
802
    while( lex->lookAhead(0) == ',' ){
 
803
        lex->nextToken();
 
804
 
 
805
        if( !parseTemplateArgument(templArg) ){
 
806
            if( reportError ){
 
807
               syntaxError();
 
808
               break;
 
809
            } else
 
810
               return false;
 
811
        }
 
812
        ast->addArgument( templArg );
 
813
    }
 
814
 
 
815
    UPDATE_POS( ast, start, lex->index() );
 
816
    node = ast;
 
817
 
 
818
    return true;
 
819
}
 
820
 
 
821
bool Parser::parseTypedef( DeclarationAST::Node& node )
 
822
{
 
823
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTypedef()" << endl;
 
824
 
 
825
    int start = lex->index();
 
826
 
 
827
    if( lex->lookAhead(0) != Token_typedef ){
 
828
        return false;
 
829
    }
 
830
    lex->nextToken();
 
831
 
 
832
    TypeSpecifierAST::Node spec;
 
833
    if( !parseTypeSpecifierOrClassSpec(spec) ){
 
834
        reportError( i18n("Need a type specifier to declare") );
 
835
        return false;
 
836
    }
 
837
 
 
838
    InitDeclaratorListAST::Node declarators;
 
839
    if( !parseInitDeclaratorList(declarators) ){
 
840
        //reportError( i18n("Need an identifier to declare") );
 
841
        //return false;
 
842
    }
 
843
 
 
844
    ADVANCE( ';', ";" );
 
845
 
 
846
    TypedefAST::Node ast = CreateNode<TypedefAST>();
 
847
    ast->setTypeSpec( spec );
 
848
    ast->setInitDeclaratorList( declarators );
 
849
    UPDATE_POS( ast, start, lex->index() );
 
850
    node = ast;
 
851
 
 
852
    return true;
 
853
}
 
854
 
 
855
bool Parser::parseAsmDefinition( DeclarationAST::Node& /*node*/ )
 
856
{
 
857
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseAsmDefinition()" << endl;
 
858
 
 
859
    ADVANCE( Token_asm, "asm" );
 
860
 
 
861
    GroupAST::Node cv;
 
862
    parseCvQualify( cv );
 
863
 
 
864
    skip( '(', ')' );
 
865
    ADVANCE( ')', ")" );
 
866
    ADVANCE( ';', ';' );
 
867
 
 
868
    return true;
 
869
}
 
870
 
 
871
bool Parser::parseTemplateDeclaration( DeclarationAST::Node& node )
 
872
{
 
873
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTemplateDeclaration()" << endl;
 
874
 
 
875
    int start = lex->index();
 
876
 
 
877
    AST::Node exp;
 
878
 
 
879
    int startExport = lex->index();
 
880
    if( lex->lookAhead(0) == Token_export ){
 
881
        lex->nextToken();
 
882
        AST::Node n = CreateNode<AST>();
 
883
        UPDATE_POS( n, startExport, lex->index() );
 
884
        exp = n;
 
885
    }
 
886
 
 
887
    if( lex->lookAhead(0) != Token_template ){
 
888
        return false;
 
889
    }
 
890
    lex->nextToken();
 
891
 
 
892
    TemplateParameterListAST::Node params;
 
893
    if( lex->lookAhead(0) == '<' ){
 
894
        lex->nextToken();
 
895
        parseTemplateParameterList( params );
 
896
 
 
897
        ADVANCE( '>', ">" );
 
898
    }
 
899
 
 
900
    DeclarationAST::Node def;
 
901
    if( !parseDeclaration(def) ){
 
902
        reportError( i18n("expected a declaration") );
 
903
    }
 
904
 
 
905
    TemplateDeclarationAST::Node ast = CreateNode<TemplateDeclarationAST>();
 
906
    ast->setExported( exp );
 
907
    ast->setTemplateParameterList( params );
 
908
    ast->setDeclaration( def );
 
909
    UPDATE_POS( ast, start, lex->index() );
 
910
    node = ast;
 
911
 
 
912
    return true;
 
913
}
 
914
 
 
915
bool Parser::parseOperator( AST::Node& /*node*/ )
 
916
{
 
917
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseOperator()" << endl;
 
918
    QString text = lex->lookAhead(0).text();
 
919
 
 
920
    switch( lex->lookAhead(0) ){
 
921
    case Token_new:
 
922
    case Token_delete:
 
923
        lex->nextToken();
 
924
        if( lex->lookAhead(0) == '[' && lex->lookAhead(1) == ']' ){
 
925
            lex->nextToken();
 
926
            lex->nextToken();
 
927
            text += "[]";
 
928
        }
 
929
        return true;
 
930
 
 
931
    case '+':
 
932
    case '-':
 
933
    case '*':
 
934
    case '/':
 
935
    case '%':
 
936
    case '^':
 
937
    case '&':
 
938
    case '|':
 
939
    case '~':
 
940
    case '!':
 
941
    case '=':
 
942
    case '<':
 
943
    case '>':
 
944
    case ',':
 
945
    case Token_assign:
 
946
    case Token_shift:
 
947
    case Token_eq:
 
948
    case Token_not_eq:
 
949
    case Token_leq:
 
950
    case Token_geq:
 
951
    case Token_and:
 
952
    case Token_or:
 
953
    case Token_incr:
 
954
    case Token_decr:
 
955
    case Token_ptrmem:
 
956
    case Token_arrow:
 
957
        lex->nextToken();
 
958
        return true;
 
959
 
 
960
    default:
 
961
        if( lex->lookAhead(0) == '(' && lex->lookAhead(1) == ')' ){
 
962
            lex->nextToken();
 
963
            lex->nextToken();
 
964
            return true;
 
965
        } else if( lex->lookAhead(0) == '[' && lex->lookAhead(1) == ']' ){
 
966
            lex->nextToken();
 
967
            lex->nextToken();
 
968
            return true;
 
969
        }
 
970
    }
 
971
 
 
972
    return false;
 
973
}
 
974
 
 
975
bool Parser::parseCvQualify( GroupAST::Node& node )
 
976
{
 
977
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCvQualify()" << endl;
 
978
 
 
979
    int start = lex->index();
 
980
 
 
981
    GroupAST::Node ast = CreateNode<GroupAST>();
 
982
 
 
983
    int n = 0;
 
984
    while( !lex->lookAhead(0).isNull() ){
 
985
        int tk = lex->lookAhead( 0 );
 
986
        if( tk == Token_const || tk == Token_volatile ){
 
987
            ++n;
 
988
            int startWord = lex->index();
 
989
            lex->nextToken();
 
990
            AST::Node word = CreateNode<AST>();
 
991
            UPDATE_POS( word, startWord, lex->index() );
 
992
            ast->addNode( word );
 
993
        } else
 
994
            break;
 
995
    }
 
996
 
 
997
    if( n == 0 )
 
998
        return false;
 
999
 
 
1000
 
 
1001
    //kdDebug(9007)<< "-----------------> token = " << lex->lookAhead(0).text() << endl;
 
1002
    UPDATE_POS( ast, start, lex->index() );
 
1003
 
 
1004
    node = ast;
 
1005
    return true;
 
1006
}
 
1007
 
 
1008
bool Parser::parseSimpleTypeSpecifier( TypeSpecifierAST::Node& node )
 
1009
{
 
1010
    int start = lex->index();
 
1011
    bool isIntegral = false;
 
1012
    bool done = false;
 
1013
 
 
1014
    while( !done ){
 
1015
 
 
1016
        switch( lex->lookAhead(0) ){
 
1017
            case Token_char:
 
1018
            case Token_wchar_t:
 
1019
            case Token_bool:
 
1020
            case Token_short:
 
1021
            case Token_int:
 
1022
            case Token_long:
 
1023
            case Token_signed:
 
1024
            case Token_unsigned:
 
1025
            case Token_float:
 
1026
            case Token_double:
 
1027
            case Token_void:
 
1028
                isIntegral = true;
 
1029
                lex->nextToken();
 
1030
                break;
 
1031
 
 
1032
            default:
 
1033
                done = true;
 
1034
        }
 
1035
    }
 
1036
 
 
1037
    TypeSpecifierAST::Node ast = CreateNode<TypeSpecifierAST>();
 
1038
    if( isIntegral ){
 
1039
        ClassOrNamespaceNameAST::Node cl = CreateNode<ClassOrNamespaceNameAST>();
 
1040
 
 
1041
        AST::Node n = CreateNode<AST>();
 
1042
        UPDATE_POS( n, start, lex->index() );
 
1043
        cl->setName( n );
 
1044
        UPDATE_POS( cl, start, lex->index() );
 
1045
 
 
1046
        NameAST::Node name = CreateNode<NameAST>();
 
1047
        name->setUnqualifiedName( cl );
 
1048
        UPDATE_POS( name, start, lex->index() );
 
1049
        ast->setName( name );
 
1050
 
 
1051
    } else {
 
1052
        NameAST::Node name;
 
1053
        if( !parseName(name) ){
 
1054
            lex->setIndex( start );
 
1055
            return false;
 
1056
        }
 
1057
        ast->setName( name );
 
1058
    }
 
1059
 
 
1060
    UPDATE_POS( ast, start, lex->index() );
 
1061
    node = ast;
 
1062
    return true;
 
1063
}
 
1064
 
 
1065
bool Parser::parsePtrOperator( AST::Node& node )
 
1066
{
 
1067
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parsePtrOperator()" << endl;
 
1068
 
 
1069
    int start = lex->index();
 
1070
 
 
1071
    if( lex->lookAhead(0) == '&' ){
 
1072
        lex->nextToken();
 
1073
    } else if( lex->lookAhead(0) == '*' ){
 
1074
        lex->nextToken();
 
1075
    } else {
 
1076
        int index = lex->index();
 
1077
        AST::Node memPtr;
 
1078
        if( !parsePtrToMember(memPtr) ){
 
1079
            lex->setIndex( index );
 
1080
            return false;
 
1081
        }
 
1082
    }
 
1083
 
 
1084
    GroupAST::Node cv;
 
1085
    parseCvQualify( cv );
 
1086
 
 
1087
    AST::Node ast = CreateNode<AST>();
 
1088
    UPDATE_POS( ast, start, lex->index() );
 
1089
    node = ast;
 
1090
 
 
1091
    return true;
 
1092
}
 
1093
 
 
1094
 
 
1095
bool Parser::parseTemplateArgument( AST::Node& node )
 
1096
{
 
1097
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTemplateArgument()" << endl;
 
1098
 
 
1099
    int start = lex->index();
 
1100
    if( parseTypeId(node) ){
 
1101
        if( lex->lookAhead(0) == ',' || lex->lookAhead(0) == '>' )
 
1102
            return true;
 
1103
    }
 
1104
 
 
1105
    lex->setIndex( start );
 
1106
    if( !parseLogicalOrExpression(node, true) ){
 
1107
        return false;
 
1108
    }
 
1109
 
 
1110
    return true;
 
1111
}
 
1112
 
 
1113
bool Parser::parseTypeSpecifier( TypeSpecifierAST::Node& spec )
 
1114
{
 
1115
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTypeSpecifier()" << endl;
 
1116
 
 
1117
    GroupAST::Node cv;
 
1118
    parseCvQualify( cv );
 
1119
 
 
1120
    if( parseElaboratedTypeSpecifier(spec) || parseSimpleTypeSpecifier(spec) ){
 
1121
        spec->setCvQualify( cv );
 
1122
 
 
1123
        GroupAST::Node cv2;
 
1124
        parseCvQualify( cv2 );
 
1125
        spec->setCv2Qualify( cv2 );
 
1126
 
 
1127
        return true;
 
1128
    }
 
1129
 
 
1130
    return false;
 
1131
}
 
1132
 
 
1133
bool Parser::parseDeclarator( DeclaratorAST::Node& node )
 
1134
{
 
1135
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclarator()" << endl;
 
1136
 
 
1137
    int start = lex->index();
 
1138
 
 
1139
    DeclaratorAST::Node ast = CreateNode<DeclaratorAST>();
 
1140
 
 
1141
    DeclaratorAST::Node decl;
 
1142
    NameAST::Node declId;
 
1143
 
 
1144
    AST::Node ptrOp;
 
1145
    while( parsePtrOperator(ptrOp) ){
 
1146
        ast->addPtrOp( ptrOp );
 
1147
    }
 
1148
 
 
1149
    if( lex->lookAhead(0) == '(' ){
 
1150
        lex->nextToken();
 
1151
 
 
1152
        if( !parseDeclarator(decl) ){
 
1153
            return false;
 
1154
        }
 
1155
        ast->setSubDeclarator( decl );
 
1156
 
 
1157
        if( lex->lookAhead(0) != ')'){
 
1158
            return false;
 
1159
        }
 
1160
        lex->nextToken();
 
1161
    } else {
 
1162
 
 
1163
        if( lex->lookAhead(0) == ':' ){
 
1164
             // unnamed bitfield
 
1165
        } else if( parseDeclaratorId(declId) ){
 
1166
            ast->setDeclaratorId( declId );
 
1167
        } else {
 
1168
            lex->setIndex( start );
 
1169
            return false;
 
1170
        }
 
1171
 
 
1172
        if( lex->lookAhead(0) == ':' ){
 
1173
            lex->nextToken();
 
1174
            AST::Node expr;
 
1175
            if( !parseConstantExpression(expr) ){
 
1176
                reportError( i18n("Constant expression expected") );
 
1177
            }
 
1178
            goto update_pos;
 
1179
        }
 
1180
    }
 
1181
 
 
1182
    {
 
1183
        bool isVector = true;
 
1184
 
 
1185
        while( lex->lookAhead(0) == '[' ){
 
1186
            int startArray = lex->index();
 
1187
            lex->nextToken();
 
1188
            AST::Node expr;
 
1189
            parseCommaExpression( expr );
 
1190
 
 
1191
            ADVANCE( ']', "]" );
 
1192
            AST::Node array = CreateNode<AST>();
 
1193
            UPDATE_POS( array, startArray, lex->index() );
 
1194
            ast->addArrayDimension( array );
 
1195
            isVector = true;
 
1196
        }
 
1197
 
 
1198
        bool skipParen = false;
 
1199
        if( lex->lookAhead(0) == Token_identifier && lex->lookAhead(1) == '(' && lex->lookAhead(2) == '(' ){
 
1200
            lex->nextToken();
 
1201
            lex->nextToken();
 
1202
            skipParen = true;
 
1203
        }
 
1204
 
 
1205
        if( ast->subDeclarator() && (!isVector || lex->lookAhead(0) != '(') ){
 
1206
            lex->setIndex( start );
 
1207
            return false;
 
1208
        }
 
1209
 
 
1210
        int index = lex->index();
 
1211
        if( lex->lookAhead(0) == '(' ){
 
1212
            lex->nextToken();
 
1213
 
 
1214
            ParameterDeclarationClauseAST::Node params;
 
1215
            if( !parseParameterDeclarationClause(params) ){
 
1216
                //kdDebug(9007)<< "----------------------> not a parameter declaration, maybe an initializer!?" << endl;
 
1217
                lex->setIndex( index );
 
1218
                goto update_pos;
 
1219
            }
 
1220
            ast->setParameterDeclarationClause( params );
 
1221
 
 
1222
            if( lex->lookAhead(0) != ')' ){
 
1223
                lex->setIndex( index );
 
1224
                goto update_pos;
 
1225
            }
 
1226
 
 
1227
            lex->nextToken();  // skip ')'
 
1228
 
 
1229
            int startConstant = lex->index();
 
1230
            if( lex->lookAhead(0) == Token_const ){
 
1231
                lex->nextToken();
 
1232
                AST::Node constant = CreateNode<AST>();
 
1233
                UPDATE_POS( constant, startConstant, lex->index() );
 
1234
                ast->setConstant( constant );
 
1235
            }
 
1236
 
 
1237
            GroupAST::Node except;
 
1238
            if( parseExceptionSpecification(except) ){
 
1239
                ast->setExceptionSpecification( except );
 
1240
            }
 
1241
        }
 
1242
 
 
1243
        if( skipParen ){
 
1244
            if( lex->lookAhead(0) != ')' ){
 
1245
                reportError( i18n("')' expected") );
 
1246
            } else
 
1247
                lex->nextToken();
 
1248
        }
 
1249
 
 
1250
    }
 
1251
 
 
1252
update_pos:
 
1253
    UPDATE_POS( ast, start, lex->index() );
 
1254
    node = ast;
 
1255
 
 
1256
    return true;
 
1257
}
 
1258
 
 
1259
bool Parser::parseAbstractDeclarator( DeclaratorAST::Node& node )
 
1260
{
 
1261
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclarator()" << endl;
 
1262
    int start = lex->index();
 
1263
 
 
1264
    DeclaratorAST::Node ast = CreateNode<DeclaratorAST>();
 
1265
 
 
1266
    DeclaratorAST::Node decl;
 
1267
    NameAST::Node declId;
 
1268
 
 
1269
    AST::Node ptrOp;
 
1270
    while( parsePtrOperator(ptrOp) ){
 
1271
        ast->addPtrOp( ptrOp );
 
1272
    }
 
1273
 
 
1274
    if( lex->lookAhead(0) == '(' ){
 
1275
        lex->nextToken();
 
1276
 
 
1277
        if( !parseAbstractDeclarator(decl) ){
 
1278
            return false;
 
1279
        }
 
1280
        ast->setSubDeclarator( decl );
 
1281
 
 
1282
        if( lex->lookAhead(0) != ')'){
 
1283
            return false;
 
1284
        }
 
1285
        lex->nextToken();
 
1286
    }
 
1287
 
 
1288
    {
 
1289
 
 
1290
    while( lex->lookAhead(0) == '[' ){
 
1291
        int startArray = lex->index();
 
1292
        lex->nextToken();
 
1293
        AST::Node expr;
 
1294
        skipCommaExpression( expr );
 
1295
 
 
1296
        ADVANCE( ']', "]" );
 
1297
        AST::Node array = CreateNode<AST>();
 
1298
        UPDATE_POS( array, startArray, lex->index() );
 
1299
        ast->addArrayDimension( array );
 
1300
    }
 
1301
 
 
1302
    bool skipParen = false;
 
1303
    if( lex->lookAhead(0) == Token_identifier && lex->lookAhead(1) == '(' && lex->lookAhead(2) == '(' ){
 
1304
        lex->nextToken();
 
1305
        lex->nextToken();
 
1306
        skipParen = true;
 
1307
    }
 
1308
 
 
1309
    int index = lex->index();
 
1310
    if( lex->lookAhead(0) == '(' ){
 
1311
        lex->nextToken();
 
1312
 
 
1313
        ParameterDeclarationClauseAST::Node params;
 
1314
        if( !parseParameterDeclarationClause(params) ){
 
1315
            lex->setIndex( index );
 
1316
            goto UPDATE_POS;
 
1317
        }
 
1318
        ast->setParameterDeclarationClause( params );
 
1319
 
 
1320
        if( lex->lookAhead(0) != ')' ){
 
1321
            lex->setIndex( index );
 
1322
            goto UPDATE_POS;
 
1323
        } else
 
1324
            lex->nextToken();
 
1325
 
 
1326
        int startConstant = lex->index();
 
1327
        if( lex->lookAhead(0) == Token_const ){
 
1328
            lex->nextToken();
 
1329
            AST::Node constant = CreateNode<AST>();
 
1330
            UPDATE_POS( constant, startConstant, lex->index() );
 
1331
            ast->setConstant( constant );
 
1332
        }
 
1333
 
 
1334
        GroupAST::Node except;
 
1335
        if( parseExceptionSpecification(except) ){
 
1336
            ast->setExceptionSpecification( except );
 
1337
        }
 
1338
    }
 
1339
 
 
1340
    if( skipParen ){
 
1341
        if( lex->lookAhead(0) != ')' ){
 
1342
            reportError( i18n("')' expected") );
 
1343
        } else
 
1344
            lex->nextToken();
 
1345
    }
 
1346
 
 
1347
    }
 
1348
 
 
1349
UPDATE_POS:
 
1350
    UPDATE_POS( ast, start, lex->index() );
 
1351
    node = ast;
 
1352
 
 
1353
    return true;
 
1354
}
 
1355
 
 
1356
 
 
1357
bool Parser::parseEnumSpecifier( TypeSpecifierAST::Node& node )
 
1358
{
 
1359
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseEnumSpecifier()" << endl;
 
1360
 
 
1361
    int start = lex->index();
 
1362
 
 
1363
    if( lex->lookAhead(0) != Token_enum ){
 
1364
        return false;
 
1365
    }
 
1366
 
 
1367
    lex->nextToken();
 
1368
 
 
1369
    NameAST::Node name;
 
1370
    parseName( name );
 
1371
 
 
1372
    if( lex->lookAhead(0) != '{' ){
 
1373
        lex->setIndex( start );
 
1374
        return false;
 
1375
    }
 
1376
    lex->nextToken();
 
1377
 
 
1378
    EnumSpecifierAST::Node ast = CreateNode<EnumSpecifierAST>();
 
1379
    ast->setName( name );
 
1380
 
 
1381
    EnumeratorAST::Node enumerator;
 
1382
    if( parseEnumerator(enumerator) ){
 
1383
        ast->addEnumerator( enumerator );
 
1384
 
 
1385
        while( lex->lookAhead(0) == ',' ){
 
1386
            lex->nextToken();
 
1387
 
 
1388
            if( !parseEnumerator(enumerator) ){
 
1389
                //reportError( i18n("Enumerator expected") );
 
1390
                break;
 
1391
            }
 
1392
 
 
1393
            ast->addEnumerator( enumerator );
 
1394
        }
 
1395
    }
 
1396
 
 
1397
    if( lex->lookAhead(0) != '}' )
 
1398
        reportError( i18n("} missing") );
 
1399
    else
 
1400
        lex->nextToken();
 
1401
 
 
1402
    UPDATE_POS( ast, start, lex->index() );
 
1403
    node = ast;
 
1404
 
 
1405
    return true;
 
1406
}
 
1407
 
 
1408
bool Parser::parseTemplateParameterList( TemplateParameterListAST::Node& node )
 
1409
{
 
1410
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTemplateParameterList()" << endl;
 
1411
 
 
1412
    int start = lex->index();
 
1413
 
 
1414
    TemplateParameterListAST::Node ast = CreateNode<TemplateParameterListAST>();
 
1415
 
 
1416
    TemplateParameterAST::Node param;
 
1417
    if( !parseTemplateParameter(param) ){
 
1418
        return false;
 
1419
    }
 
1420
    ast->addTemplateParameter( param );
 
1421
 
 
1422
    while( lex->lookAhead(0) == ',' ){
 
1423
        lex->nextToken();
 
1424
 
 
1425
        if( !parseTemplateParameter(param) ){
 
1426
            syntaxError();
 
1427
            break;
 
1428
        } else {
 
1429
            ast->addTemplateParameter( param );
 
1430
        }
 
1431
    }
 
1432
 
 
1433
    UPDATE_POS( ast, start, lex->index() );
 
1434
    node = ast;
 
1435
 
 
1436
    return true;
 
1437
}
 
1438
 
 
1439
bool Parser::parseTemplateParameter( TemplateParameterAST::Node& node )
 
1440
{
 
1441
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTemplateParameter()" << endl;
 
1442
 
 
1443
    int start = lex->index();
 
1444
    TemplateParameterAST::Node ast = CreateNode<TemplateParameterAST>();
 
1445
 
 
1446
    TypeParameterAST::Node typeParameter;
 
1447
    ParameterDeclarationAST::Node param;
 
1448
 
 
1449
    int tk = lex->lookAhead( 0 );
 
1450
 
 
1451
    if( (tk == Token_class || tk == Token_typename || tk == Token_template) && parseTypeParameter(typeParameter) ){
 
1452
        ast->setTypeParameter( typeParameter );
 
1453
        goto ok;
 
1454
    }
 
1455
 
 
1456
    if( !parseParameterDeclaration(param) )
 
1457
        return false;
 
1458
    ast->setTypeValueParameter( param );
 
1459
 
 
1460
ok:
 
1461
    UPDATE_POS( ast, start, lex->index() );
 
1462
    node = ast;
 
1463
 
 
1464
    return true;
 
1465
}
 
1466
 
 
1467
bool Parser::parseTypeParameter( TypeParameterAST::Node& node )
 
1468
{
 
1469
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTypeParameter()" << endl;
 
1470
 
 
1471
    int start = lex->index();
 
1472
    TypeParameterAST::Node ast = CreateNode<TypeParameterAST>();
 
1473
 
 
1474
    AST_FROM_TOKEN( kind, lex->index() );
 
1475
    ast->setKind( kind );
 
1476
 
 
1477
    switch( lex->lookAhead(0) ){
 
1478
 
 
1479
    case Token_class:
 
1480
    case Token_typename:
 
1481
        {
 
1482
            lex->nextToken(); // skip class
 
1483
 
 
1484
            // parse optional name
 
1485
            NameAST::Node name;
 
1486
            if( parseName(name) ){
 
1487
                ast->setName( name );
 
1488
                if( lex->lookAhead(0) == '=' ){
 
1489
                    lex->nextToken();
 
1490
 
 
1491
                    AST::Node typeId;
 
1492
                    if( !parseTypeId(typeId) ){
 
1493
                        syntaxError();
 
1494
                        return false;
 
1495
                    }
 
1496
                    ast->setTypeId( typeId );
 
1497
                }
 
1498
            }
 
1499
        }
 
1500
        break;
 
1501
 
 
1502
    case Token_template:
 
1503
        {
 
1504
            lex->nextToken(); // skip template
 
1505
            ADVANCE( '<', '<' );
 
1506
 
 
1507
            TemplateParameterListAST::Node params;
 
1508
            if( !parseTemplateParameterList(params) ){
 
1509
                return false;
 
1510
            }
 
1511
            ast->setTemplateParameterList( params );
 
1512
 
 
1513
            ADVANCE( '>', ">" );
 
1514
 
 
1515
            if( lex->lookAhead(0) == Token_class )
 
1516
                lex->nextToken();
 
1517
 
 
1518
            // parse optional name
 
1519
            NameAST::Node name;
 
1520
            if( parseName(name) ){
 
1521
                ast->setName( name );
 
1522
                if( lex->lookAhead(0) == '=' ){
 
1523
                    lex->nextToken();
 
1524
 
 
1525
                    AST::Node typeId;
 
1526
                    if( !parseTypeId(typeId) ){
 
1527
                        syntaxError();
 
1528
                        return false;
 
1529
                    }
 
1530
                    ast->setTypeId( typeId );
 
1531
                }
 
1532
            }
 
1533
 
 
1534
            if( lex->lookAhead(0) == '=' ){
 
1535
                lex->nextToken();
 
1536
 
 
1537
                NameAST::Node templ_name;
 
1538
                parseName( templ_name );
 
1539
            }
 
1540
        }
 
1541
        break;
 
1542
 
 
1543
    default:
 
1544
        return false;
 
1545
 
 
1546
    } // end switch
 
1547
 
 
1548
 
 
1549
    UPDATE_POS( ast, start, lex->index() );
 
1550
    node = ast;
 
1551
    return true;
 
1552
}
 
1553
 
 
1554
bool Parser::parseStorageClassSpecifier( GroupAST::Node& node )
 
1555
{
 
1556
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseStorageClassSpecifier()" << endl;
 
1557
 
 
1558
    int start = lex->index();
 
1559
    GroupAST::Node ast = CreateNode<GroupAST>();
 
1560
 
 
1561
    while( !lex->lookAhead(0).isNull() ){
 
1562
        int tk = lex->lookAhead( 0 );
 
1563
        if( tk == Token_friend || tk == Token_auto || tk == Token_register || tk == Token_static ||
 
1564
                tk == Token_extern || tk == Token_mutable ){
 
1565
            int startNode = lex->index();
 
1566
            lex->nextToken();
 
1567
 
 
1568
            AST::Node n = CreateNode<AST>();
 
1569
            UPDATE_POS( n, startNode, lex->index() );
 
1570
            ast->addNode( n );
 
1571
        } else
 
1572
            break;
 
1573
    }
 
1574
 
 
1575
    if( ast->nodeList().count() == 0 )
 
1576
       return false;
 
1577
 
 
1578
    UPDATE_POS( ast, start, lex->index() );
 
1579
    node = ast;
 
1580
    return true;
 
1581
}
 
1582
 
 
1583
bool Parser::parseFunctionSpecifier( GroupAST::Node& node )
 
1584
{
 
1585
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseFunctionSpecifier()" << endl;
 
1586
 
 
1587
    int start = lex->index();
 
1588
    GroupAST::Node ast = CreateNode<GroupAST>();
 
1589
 
 
1590
    while( !lex->lookAhead(0).isNull() ){
 
1591
        int tk = lex->lookAhead( 0 );
 
1592
        if( tk == Token_inline || tk == Token_virtual || tk == Token_explicit ){
 
1593
            int startNode = lex->index();
 
1594
            lex->nextToken();
 
1595
 
 
1596
            AST::Node n = CreateNode<AST>();
 
1597
            UPDATE_POS( n, startNode, lex->index() );
 
1598
            ast->addNode( n );
 
1599
        } else {
 
1600
            break;
 
1601
    }
 
1602
    }
 
1603
 
 
1604
    if( ast->nodeList().count() == 0 )
 
1605
       return false;
 
1606
 
 
1607
    UPDATE_POS( ast, start, lex->index() );
 
1608
    node = ast;
 
1609
    return true;
 
1610
}
 
1611
 
 
1612
bool Parser::parseTypeId( AST::Node& node )
 
1613
{
 
1614
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTypeId()" << endl;
 
1615
 
 
1616
    /// @todo implement the AST for typeId
 
1617
    int start = lex->index();
 
1618
    AST::Node ast = CreateNode<AST>();
 
1619
 
 
1620
    TypeSpecifierAST::Node spec;
 
1621
    if( !parseTypeSpecifier(spec) ){
 
1622
        return false;
 
1623
    }
 
1624
 
 
1625
    DeclaratorAST::Node decl;
 
1626
    parseAbstractDeclarator( decl );
 
1627
 
 
1628
    UPDATE_POS( ast, start, lex->index() );
 
1629
    node = ast;
 
1630
 
 
1631
    return true;
 
1632
}
 
1633
 
 
1634
bool Parser::parseInitDeclaratorList( InitDeclaratorListAST::Node& node )
 
1635
{
 
1636
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInitDeclaratorList()" << endl;
 
1637
 
 
1638
    int start = lex->index();
 
1639
 
 
1640
    InitDeclaratorListAST::Node ast = CreateNode<InitDeclaratorListAST>();
 
1641
    InitDeclaratorAST::Node decl;
 
1642
 
 
1643
    if( !parseInitDeclarator(decl) ){
 
1644
        return false;
 
1645
    }
 
1646
    ast->addInitDeclarator( decl );
 
1647
 
 
1648
    while( lex->lookAhead(0) == ',' ){
 
1649
        lex->nextToken();
 
1650
 
 
1651
        if( !parseInitDeclarator(decl) ){
 
1652
            syntaxError();
 
1653
            break;
 
1654
        }
 
1655
        ast->addInitDeclarator( decl );
 
1656
    }
 
1657
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInitDeclaratorList() -- end" << endl;
 
1658
 
 
1659
    UPDATE_POS( ast, start, lex->index() );
 
1660
    node = ast;
 
1661
 
 
1662
    return true;
 
1663
}
 
1664
 
 
1665
bool Parser::parseParameterDeclarationClause( ParameterDeclarationClauseAST::Node& node )
 
1666
{
 
1667
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseParameterDeclarationClause()" << endl;
 
1668
 
 
1669
    int start = lex->index();
 
1670
 
 
1671
    ParameterDeclarationClauseAST::Node ast = CreateNode<ParameterDeclarationClauseAST>();
 
1672
 
 
1673
    ParameterDeclarationListAST::Node params;
 
1674
    if( !parseParameterDeclarationList(params) ){
 
1675
 
 
1676
        if ( lex->lookAhead(0) == ')' )
 
1677
            goto good;
 
1678
 
 
1679
        if( lex->lookAhead(0) == Token_ellipsis && lex->lookAhead(1) == ')' ){
 
1680
            AST_FROM_TOKEN( ellipsis, lex->index() );
 
1681
            ast->setEllipsis( ellipsis );
 
1682
            lex->nextToken();
 
1683
            goto good;
 
1684
        }
 
1685
        return false;
 
1686
    }
 
1687
 
 
1688
    if( lex->lookAhead(0) == Token_ellipsis ){
 
1689
        AST_FROM_TOKEN( ellipsis, lex->index() );
 
1690
        ast->setEllipsis( ellipsis );
 
1691
        lex->nextToken();
 
1692
    }
 
1693
 
 
1694
good:
 
1695
    ast->setParameterDeclarationList( params );
 
1696
 
 
1697
    /// @todo add ellipsis
 
1698
    UPDATE_POS( ast, start, lex->index() );
 
1699
    node = ast;
 
1700
 
 
1701
    return true;
 
1702
}
 
1703
 
 
1704
bool Parser::parseParameterDeclarationList( ParameterDeclarationListAST::Node& node )
 
1705
{
 
1706
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseParameterDeclarationList()" << endl;
 
1707
 
 
1708
    int start = lex->index();
 
1709
 
 
1710
    ParameterDeclarationListAST::Node ast = CreateNode<ParameterDeclarationListAST>();
 
1711
 
 
1712
    ParameterDeclarationAST::Node param;
 
1713
    if( !parseParameterDeclaration(param) ){
 
1714
        lex->setIndex( start );
 
1715
        return false;
 
1716
    }
 
1717
    ast->addParameter( param );
 
1718
 
 
1719
    while( lex->lookAhead(0) == ',' ){
 
1720
        lex->nextToken();
 
1721
 
 
1722
        if( lex->lookAhead(0) == Token_ellipsis )
 
1723
            break;
 
1724
 
 
1725
        if( !parseParameterDeclaration(param) ){
 
1726
            lex->setIndex( start );
 
1727
            return false;
 
1728
        }
 
1729
        ast->addParameter( param );
 
1730
    }
 
1731
 
 
1732
    UPDATE_POS( ast, start, lex->index() );
 
1733
    node = ast;
 
1734
 
 
1735
    return true;
 
1736
}
 
1737
 
 
1738
bool Parser::parseParameterDeclaration( ParameterDeclarationAST::Node& node )
 
1739
{
 
1740
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseParameterDeclaration()" << endl;
 
1741
 
 
1742
    int start = lex->index();
 
1743
 
 
1744
    // parse decl spec
 
1745
    TypeSpecifierAST::Node spec;
 
1746
    if( !parseTypeSpecifier(spec) ){
 
1747
        lex->setIndex( start );
 
1748
        return false;
 
1749
    }
 
1750
 
 
1751
    int index = lex->index();
 
1752
 
 
1753
    DeclaratorAST::Node decl;
 
1754
    if( !parseDeclarator(decl) ){
 
1755
        lex->setIndex( index );
 
1756
 
 
1757
        // try with abstract declarator
 
1758
        if( !parseAbstractDeclarator(decl) )
 
1759
            return false;
 
1760
    }
 
1761
 
 
1762
    AST::Node expr;
 
1763
    if( lex->lookAhead(0) == '=' ){
 
1764
        lex->nextToken();
 
1765
        if( !parseLogicalOrExpression(expr,true) ){
 
1766
            //reportError( i18n("Expression expected") );
 
1767
        }
 
1768
    }
 
1769
 
 
1770
    ParameterDeclarationAST::Node ast = CreateNode<ParameterDeclarationAST>();
 
1771
    ast->setTypeSpec( spec );
 
1772
    ast->setDeclarator( decl );
 
1773
    ast->setExpression( expr );
 
1774
 
 
1775
    UPDATE_POS( ast, start, lex->index() );
 
1776
    node = ast;
 
1777
 
 
1778
    return true;
 
1779
}
 
1780
 
 
1781
bool Parser::parseClassSpecifier( TypeSpecifierAST::Node& node )
 
1782
{
 
1783
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseClassSpecifier()" << endl;
 
1784
 
 
1785
    int start = lex->index();
 
1786
 
 
1787
    AST::Node classKey;
 
1788
    int classKeyStart = lex->index();
 
1789
 
 
1790
    int kind = lex->lookAhead( 0 );
 
1791
    if( kind == Token_class || kind == Token_struct || kind == Token_union ){
 
1792
        AST::Node asn = CreateNode<AST>();
 
1793
        classKey = asn;
 
1794
        lex->nextToken();
 
1795
        UPDATE_POS( classKey, classKeyStart, lex->index() );
 
1796
    } else {
 
1797
        return false;
 
1798
    }
 
1799
 
 
1800
    GroupAST::Node winDeclSpec;
 
1801
    parseWinDeclSpec( winDeclSpec );
 
1802
 
 
1803
    while( lex->lookAhead(0) == Token_identifier && lex->lookAhead(1) == Token_identifier )
 
1804
        lex->nextToken();
 
1805
 
 
1806
    NameAST::Node name;
 
1807
    parseName( name );
 
1808
 
 
1809
    BaseClauseAST::Node bases;
 
1810
    if( lex->lookAhead(0) == ':' ){
 
1811
        if( !parseBaseClause(bases) ){
 
1812
            skipUntil( '{' );
 
1813
        }
 
1814
    }
 
1815
 
 
1816
    if( lex->lookAhead(0) != '{' ){
 
1817
        lex->setIndex( start );
 
1818
        return false;
 
1819
    }
 
1820
 
 
1821
    ADVANCE( '{', '{' );
 
1822
 
 
1823
    ClassSpecifierAST::Node ast = CreateNode<ClassSpecifierAST>();
 
1824
    ast->setWinDeclSpec( winDeclSpec );
 
1825
    ast->setClassKey( classKey );
 
1826
    ast->setName( name );
 
1827
    ast->setBaseClause( bases );
 
1828
 
 
1829
    while( !lex->lookAhead(0).isNull() ){
 
1830
        if( lex->lookAhead(0) == '}' )
 
1831
            break;
 
1832
 
 
1833
        DeclarationAST::Node memSpec;
 
1834
        int startDecl = lex->index();
 
1835
        if( !parseMemberSpecification(memSpec) ){
 
1836
            if( startDecl == lex->index() )
 
1837
                lex->nextToken(); // skip at least one token
 
1838
            skipUntilDeclaration();
 
1839
        } else
 
1840
            ast->addDeclaration( memSpec );
 
1841
    }
 
1842
 
 
1843
    if( lex->lookAhead(0) != '}' ){
 
1844
        reportError( i18n("} missing") );
 
1845
    } else
 
1846
        lex->nextToken();
 
1847
 
 
1848
    UPDATE_POS( ast, start, lex->index() );
 
1849
    node = ast;
 
1850
 
 
1851
    return true;
 
1852
}
 
1853
 
 
1854
bool Parser::parseAccessSpecifier( AST::Node& node )
 
1855
{
 
1856
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseAccessSpecifier()" << endl;
 
1857
 
 
1858
    int start = lex->index();
 
1859
 
 
1860
    switch( lex->lookAhead(0) ){
 
1861
    case Token_public:
 
1862
    case Token_protected:
 
1863
    case Token_private: {
 
1864
        AST::Node asn = CreateNode<AST>();
 
1865
        node = asn;
 
1866
        lex->nextToken();
 
1867
        UPDATE_POS( node, start, lex->index() );
 
1868
        return true;
 
1869
        }
 
1870
    }
 
1871
 
 
1872
    return false;
 
1873
}
 
1874
 
 
1875
bool Parser::parseMemberSpecification( DeclarationAST::Node& node )
 
1876
{
 
1877
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseMemberSpecification()" << endl;
 
1878
 
 
1879
    int start = lex->index();
 
1880
 
 
1881
    AST::Node access;
 
1882
 
 
1883
    if( lex->lookAhead(0) == ';' ){
 
1884
        lex->nextToken();
 
1885
        return true;
 
1886
    } else if( lex->lookAhead(0) == Token_Q_OBJECT || lex->lookAhead(0) == Token_K_DCOP ){
 
1887
        lex->nextToken();
 
1888
        return true;
 
1889
    } else if( lex->lookAhead(0) == Token_signals || lex->lookAhead(0) == Token_k_dcop || lex->lookAhead(0) == Token_k_dcop_signals ){
 
1890
        AccessDeclarationAST::Node ast = CreateNode<AccessDeclarationAST>();
 
1891
        lex->nextToken();
 
1892
        AST::Node n = CreateNode<AST>();
 
1893
        UPDATE_POS( n, start, lex->index() );
 
1894
        ast->addAccess( n );
 
1895
        ADVANCE( ':', ":" );
 
1896
        UPDATE_POS( ast, start, lex->index() );
 
1897
        node = ast;
 
1898
        return true;
 
1899
    } else if( parseTypedef(node) ){
 
1900
        return true;
 
1901
    } else if( parseUsing(node) ){
 
1902
        return true;
 
1903
    } else if( parseTemplateDeclaration(node) ){
 
1904
        return true;
 
1905
    } else if( parseAccessSpecifier(access) ){
 
1906
        AccessDeclarationAST::Node ast = CreateNode<AccessDeclarationAST>();
 
1907
        ast->addAccess( access );
 
1908
 
 
1909
        int startSlot = lex->index();
 
1910
        if( lex->lookAhead(0) == Token_slots ){
 
1911
            lex->nextToken();
 
1912
            AST::Node sl = CreateNode<AST>();
 
1913
            UPDATE_POS( sl, startSlot, lex->index() );
 
1914
            ast->addAccess( sl );
 
1915
        }
 
1916
        ADVANCE( ':', ":" );
 
1917
        UPDATE_POS( ast, start, lex->index() );
 
1918
        node = ast;
 
1919
        return true;
 
1920
    }
 
1921
 
 
1922
    lex->setIndex( start );
 
1923
 
 
1924
    GroupAST::Node storageSpec;
 
1925
    parseStorageClassSpecifier( storageSpec );
 
1926
 
 
1927
    GroupAST::Node cv;
 
1928
    parseCvQualify( cv );
 
1929
 
 
1930
    TypeSpecifierAST::Node spec;
 
1931
    if( parseEnumSpecifier(spec) || parseClassSpecifier(spec) ){
 
1932
        spec->setCvQualify( cv );
 
1933
 
 
1934
        GroupAST::Node cv2;
 
1935
        parseCvQualify( cv2 );
 
1936
        spec->setCv2Qualify( cv2 );
 
1937
 
 
1938
        InitDeclaratorListAST::Node declarators;
 
1939
        parseInitDeclaratorList( declarators );
 
1940
        ADVANCE( ';', ";" );
 
1941
 
 
1942
        SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
 
1943
        ast->setTypeSpec( spec );
 
1944
        ast->setInitDeclaratorList( declarators );
 
1945
        UPDATE_POS( ast, start, lex->index() );
 
1946
        node = ast;
 
1947
 
 
1948
        return true;
 
1949
    }
 
1950
 
 
1951
    lex->setIndex( start );
 
1952
    return parseDeclarationInternal( node );
 
1953
}
 
1954
 
 
1955
bool Parser::parseCtorInitializer( AST::Node& /*node*/ )
 
1956
{
 
1957
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCtorInitializer()" << endl;
 
1958
 
 
1959
    if( lex->lookAhead(0) != ':' ){
 
1960
        return false;
 
1961
    }
 
1962
    lex->nextToken();
 
1963
 
 
1964
    AST::Node inits;
 
1965
    if( !parseMemInitializerList(inits) ){
 
1966
        reportError( i18n("Member initializers expected") );
 
1967
    }
 
1968
 
 
1969
    return true;
 
1970
}
 
1971
 
 
1972
bool Parser::parseElaboratedTypeSpecifier( TypeSpecifierAST::Node& node )
 
1973
{
 
1974
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseElaboratedTypeSpecifier()" << endl;
 
1975
 
 
1976
    int start = lex->index();
 
1977
 
 
1978
    int tk = lex->lookAhead( 0 );
 
1979
    if( tk == Token_class  ||
 
1980
        tk == Token_struct ||
 
1981
        tk == Token_union  ||
 
1982
        tk == Token_enum   ||
 
1983
        tk == Token_typename )
 
1984
    {
 
1985
        AST::Node kind = CreateNode<AST>();
 
1986
        lex->nextToken();
 
1987
        UPDATE_POS( kind, start, lex->index() );
 
1988
 
 
1989
        NameAST::Node name;
 
1990
 
 
1991
        if( parseName(name) ){
 
1992
            ElaboratedTypeSpecifierAST::Node ast = CreateNode<ElaboratedTypeSpecifierAST>();
 
1993
            ast->setKind( kind );
 
1994
            ast->setName( name );
 
1995
            UPDATE_POS( ast, start, lex->index() );
 
1996
            node = ast;
 
1997
 
 
1998
            return true;
 
1999
        }
 
2000
    }
 
2001
 
 
2002
    lex->setIndex( start );
 
2003
    return false;
 
2004
}
 
2005
 
 
2006
bool Parser::parseDeclaratorId( NameAST::Node& node )
 
2007
{
 
2008
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclaratorId()" << endl;
 
2009
    return parseName( node );
 
2010
}
 
2011
 
 
2012
bool Parser::parseExceptionSpecification( GroupAST::Node& node )
 
2013
{
 
2014
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseExceptionSpecification()" << endl;
 
2015
 
 
2016
    if( lex->lookAhead(0) != Token_throw ){
 
2017
        return false;
 
2018
    }
 
2019
    lex->nextToken();
 
2020
 
 
2021
    ADVANCE( '(', "(" );
 
2022
    if( lex->lookAhead(0) == Token_ellipsis ){
 
2023
        // extension found in MSVC++ 7.x headers
 
2024
        int start = lex->index();
 
2025
        GroupAST::Node ast = CreateNode<GroupAST>();
 
2026
        AST_FROM_TOKEN( ellipsis, lex->index() );
 
2027
        ast->addNode( ellipsis );
 
2028
        lex->nextToken();
 
2029
        UPDATE_POS( ast, start, lex->index() );
 
2030
        node = ast;
 
2031
    } else {
 
2032
        parseTypeIdList( node );
 
2033
    }
 
2034
    ADVANCE( ')', ")" );
 
2035
 
 
2036
    return true;
 
2037
}
 
2038
 
 
2039
bool Parser::parseEnumerator( EnumeratorAST::Node& node )
 
2040
{
 
2041
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseEnumerator()" << endl;
 
2042
 
 
2043
    int start = lex->index();
 
2044
 
 
2045
    if( lex->lookAhead(0) != Token_identifier ){
 
2046
        return false;
 
2047
    }
 
2048
    lex->nextToken();
 
2049
 
 
2050
    EnumeratorAST::Node ena = CreateNode<EnumeratorAST>();
 
2051
    node = ena;
 
2052
 
 
2053
    AST::Node id = CreateNode<AST>();
 
2054
    UPDATE_POS( id, start, lex->index() );
 
2055
    node->setId( id );
 
2056
 
 
2057
    if( lex->lookAhead(0) == '=' ){
 
2058
        lex->nextToken();
 
2059
 
 
2060
        AST::Node expr;
 
2061
        if( !parseConstantExpression(expr) ){
 
2062
            reportError( i18n("Constant expression expected") );
 
2063
        }
 
2064
        node->setExpr( expr );
 
2065
    }
 
2066
 
 
2067
    UPDATE_POS( node, start, lex->index() );
 
2068
 
 
2069
    return true;
 
2070
}
 
2071
 
 
2072
bool Parser::parseInitDeclarator( InitDeclaratorAST::Node& node )
 
2073
{
 
2074
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInitDeclarator()" << endl;
 
2075
 
 
2076
    int start = lex->index();
 
2077
 
 
2078
    DeclaratorAST::Node decl;
 
2079
    AST::Node init;
 
2080
    if( !parseDeclarator(decl) ){
 
2081
        return false;
 
2082
    }
 
2083
 
 
2084
    parseInitializer( init );
 
2085
 
 
2086
    InitDeclaratorAST::Node ast = CreateNode<InitDeclaratorAST>();
 
2087
    ast->setDeclarator( decl );
 
2088
    ast->setInitializer( init );
 
2089
    UPDATE_POS( ast, start, lex->index() );
 
2090
    node = ast;
 
2091
 
 
2092
    return true;
 
2093
}
 
2094
 
 
2095
 
 
2096
 
 
2097
bool Parser::parseBaseClause( BaseClauseAST::Node& node )
 
2098
{
 
2099
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseBaseClause()" << endl;
 
2100
 
 
2101
    int start = lex->index();
 
2102
    if( lex->lookAhead(0) != ':' ){
 
2103
        return false;
 
2104
    }
 
2105
    lex->nextToken();
 
2106
 
 
2107
    BaseClauseAST::Node bca = CreateNode<BaseClauseAST>();
 
2108
 
 
2109
    BaseSpecifierAST::Node baseSpec;
 
2110
    if( parseBaseSpecifier(baseSpec) ){
 
2111
        bca->addBaseSpecifier( baseSpec );
 
2112
 
 
2113
        while( lex->lookAhead(0) == ',' ){
 
2114
            lex->nextToken();
 
2115
 
 
2116
            if( !parseBaseSpecifier(baseSpec) ){
 
2117
                reportError( i18n("Base class specifier expected") );
 
2118
                return false;
 
2119
            }
 
2120
            bca->addBaseSpecifier( baseSpec );
 
2121
        }
 
2122
    } else
 
2123
        return false;
 
2124
 
 
2125
    UPDATE_POS( bca, start, lex->index() );
 
2126
    node = bca;
 
2127
 
 
2128
    return true;
 
2129
}
 
2130
 
 
2131
bool Parser::parseInitializer( AST::Node& node )
 
2132
{
 
2133
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInitializer()" << endl;
 
2134
 
 
2135
    if( lex->lookAhead(0) == '=' ){
 
2136
        lex->nextToken();
 
2137
 
 
2138
        AST::Node init;
 
2139
        if( !parseInitializerClause(node) ){
 
2140
            reportError( i18n("Initializer clause expected") );
 
2141
            return false;
 
2142
        }
 
2143
    } else if( lex->lookAhead(0) == '(' ){
 
2144
        lex->nextToken();
 
2145
        AST::Node expr;
 
2146
        skipCommaExpression( expr );
 
2147
 
 
2148
        ADVANCE( ')', ")" );
 
2149
    }
 
2150
 
 
2151
    return false;
 
2152
}
 
2153
 
 
2154
bool Parser::parseMemInitializerList( AST::Node& /*node*/ )
 
2155
{
 
2156
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseMemInitializerList()" << endl;
 
2157
 
 
2158
    AST::Node init;
 
2159
    if( !parseMemInitializer(init) ){
 
2160
        return false;
 
2161
    }
 
2162
 
 
2163
    while( lex->lookAhead(0) == ',' ){
 
2164
        lex->nextToken();
 
2165
 
 
2166
        if( parseMemInitializer(init) ){
 
2167
        } else {
 
2168
            break;
 
2169
        }
 
2170
    }
 
2171
 
 
2172
    return true;
 
2173
}
 
2174
 
 
2175
bool Parser::parseMemInitializer( AST::Node& /*node*/ )
 
2176
{
 
2177
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseMemInitializer()" << endl;
 
2178
 
 
2179
    NameAST::Node initId;
 
2180
    if( !parseMemInitializerId(initId) ){
 
2181
        reportError( i18n("Identifier expected") );
 
2182
        return false;
 
2183
    }
 
2184
    ADVANCE( '(', '(' );
 
2185
    AST::Node expr;
 
2186
    skipCommaExpression( expr );
 
2187
    ADVANCE( ')', ')' );
 
2188
 
 
2189
    return true;
 
2190
}
 
2191
 
 
2192
bool Parser::parseTypeIdList( GroupAST::Node& node )
 
2193
{
 
2194
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTypeIdList()" << endl;
 
2195
 
 
2196
    int start = lex->index();
 
2197
 
 
2198
    AST::Node typeId;
 
2199
    if( !parseTypeId(typeId) ){
 
2200
        return false;
 
2201
    }
 
2202
 
 
2203
    GroupAST::Node ast = CreateNode<GroupAST>();
 
2204
    ast->addNode( typeId );
 
2205
 
 
2206
    while( lex->lookAhead(0) == ',' ){
 
2207
        lex->nextToken();
 
2208
        if( parseTypeId(typeId) ){
 
2209
            ast->addNode( typeId );
 
2210
        } else {
 
2211
            reportError( i18n("Type id expected") );
 
2212
            break;
 
2213
        }
 
2214
    }
 
2215
 
 
2216
    UPDATE_POS( ast, start, lex->index() );
 
2217
    node = ast;
 
2218
    return true;
 
2219
}
 
2220
 
 
2221
bool Parser::parseBaseSpecifier( BaseSpecifierAST::Node& node )
 
2222
{
 
2223
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseBaseSpecifier()" << endl;
 
2224
 
 
2225
    int start = lex->index();
 
2226
    BaseSpecifierAST::Node ast = CreateNode<BaseSpecifierAST>();
 
2227
 
 
2228
    AST::Node access;
 
2229
    if( lex->lookAhead(0) == Token_virtual ){
 
2230
        AST_FROM_TOKEN( virt, lex->index() );
 
2231
        ast->setIsVirtual( virt );
 
2232
 
 
2233
        lex->nextToken();
 
2234
 
 
2235
        parseAccessSpecifier( access );
 
2236
    } else {
 
2237
        parseAccessSpecifier( access );
 
2238
 
 
2239
        if( lex->lookAhead(0) == Token_virtual ){
 
2240
            AST_FROM_TOKEN( virt, lex->index() );
 
2241
            ast->setIsVirtual( virt );
 
2242
            lex->nextToken();
 
2243
        }
 
2244
    }
 
2245
 
 
2246
    NameAST::Node name;
 
2247
    if( !parseName(name) ){
 
2248
        reportError( i18n("Class name expected") );
 
2249
    }
 
2250
 
 
2251
    ast->setAccess( access );
 
2252
    ast->setName( name );
 
2253
    UPDATE_POS( ast, start, lex->index() );
 
2254
    node = ast;
 
2255
 
 
2256
    return true;
 
2257
}
 
2258
 
 
2259
 
 
2260
bool Parser::parseInitializerClause( AST::Node& node )
 
2261
{
 
2262
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInitializerClause()" << endl;
 
2263
 
 
2264
    if( lex->lookAhead(0) == '{' ){
 
2265
        if( !skip('{','}') ){
 
2266
            reportError( i18n("} missing") );
 
2267
        } else
 
2268
            lex->nextToken();
 
2269
    } else {
 
2270
        if( !parseAssignmentExpression(node) ){
 
2271
            //reportError( i18n("Expression expected") );
 
2272
        }
 
2273
    }
 
2274
 
 
2275
    return true;
 
2276
}
 
2277
 
 
2278
bool Parser::parseMemInitializerId( NameAST::Node& node )
 
2279
{
 
2280
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseMemInitializerId()" << endl;
 
2281
 
 
2282
    return parseName( node );
 
2283
}
 
2284
 
 
2285
bool Parser::parsePtrToMember( AST::Node& /*node*/ )
 
2286
{
 
2287
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parsePtrToMember()" << endl;
 
2288
 
 
2289
    if( lex->lookAhead(0) == Token_scope ){
 
2290
        lex->nextToken();
 
2291
    }
 
2292
 
 
2293
    while( lex->lookAhead(0) == Token_identifier ){
 
2294
        lex->nextToken();
 
2295
 
 
2296
        if( lex->lookAhead(0) == Token_scope && lex->lookAhead(1) == '*' ){
 
2297
            lex->nextToken(); // skip ::
 
2298
            lex->nextToken(); // skip *
 
2299
            return true;
 
2300
        } else
 
2301
            break;
 
2302
    }
 
2303
 
 
2304
    return false;
 
2305
}
 
2306
 
 
2307
bool Parser::parseUnqualifiedName( ClassOrNamespaceNameAST::Node& node )
 
2308
{
 
2309
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseUnqualifiedName()" << endl;
 
2310
 
 
2311
    int start = lex->index();
 
2312
    bool isDestructor = false;
 
2313
 
 
2314
    ClassOrNamespaceNameAST::Node ast = CreateNode<ClassOrNamespaceNameAST>();
 
2315
 
 
2316
    if( lex->lookAhead(0) == Token_identifier ){
 
2317
        int startName = lex->index();
 
2318
        AST::Node n = CreateNode<AST>();
 
2319
        lex->nextToken();
 
2320
        UPDATE_POS( n, startName, lex->index() );
 
2321
        ast->setName( n );
 
2322
    } else if( lex->lookAhead(0) == '~' && lex->lookAhead(1) == Token_identifier ){
 
2323
        int startName = lex->index();
 
2324
        AST::Node n = CreateNode<AST>();
 
2325
        lex->nextToken(); // skip ~
 
2326
        lex->nextToken(); // skip classname
 
2327
        UPDATE_POS( n, startName, lex->index() );
 
2328
        ast->setName( n );
 
2329
        isDestructor = true;
 
2330
    } else if( lex->lookAhead(0) == Token_operator ){
 
2331
        AST::Node n;
 
2332
        if( !parseOperatorFunctionId(n) )
 
2333
            return false;
 
2334
        ast->setName( n );
 
2335
    } else {
 
2336
        return false;
 
2337
    }
 
2338
 
 
2339
    if( !isDestructor ){
 
2340
 
 
2341
        int index = lex->index();
 
2342
 
 
2343
        if( lex->lookAhead(0) == '<' ){
 
2344
            lex->nextToken();
 
2345
 
 
2346
            // optional template arguments
 
2347
            TemplateArgumentListAST::Node args;
 
2348
            parseTemplateArgumentList( args );
 
2349
 
 
2350
            if( lex->lookAhead(0) != '>' ){
 
2351
                lex->setIndex( index );
 
2352
            } else {
 
2353
                lex->nextToken();
 
2354
                ast->setTemplateArgumentList( args );
 
2355
            }
 
2356
        }
 
2357
    }
 
2358
 
 
2359
    UPDATE_POS( ast, start, lex->index() );
 
2360
    node = ast;
 
2361
 
 
2362
    return true;
 
2363
}
 
2364
 
 
2365
bool Parser::parseStringLiteral( AST::Node& /*node*/ )
 
2366
{
 
2367
    while( !lex->lookAhead(0).isNull() ) {
 
2368
        if( lex->lookAhead(0) == Token_identifier &&
 
2369
            lex->lookAhead(0).text() == "L" && lex->lookAhead(1) == Token_string_literal ) {
 
2370
 
 
2371
            lex->nextToken();
 
2372
            lex->nextToken();
 
2373
        } else if( lex->lookAhead(0) == Token_string_literal ) {
 
2374
            lex->nextToken();
 
2375
        } else
 
2376
            return false;
 
2377
    }
 
2378
    return true;
 
2379
}
 
2380
 
 
2381
bool Parser::skipExpressionStatement( StatementAST::Node& node )
 
2382
{
 
2383
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipExpressionStatement()" << endl;
 
2384
 
 
2385
    int start = lex->index();
 
2386
 
 
2387
    AST::Node expr;
 
2388
    skipCommaExpression( expr );
 
2389
 
 
2390
    ADVANCE( ';', ";" );
 
2391
 
 
2392
    ExpressionStatementAST::Node ast = CreateNode<ExpressionStatementAST>();
 
2393
    ast->setExpression( expr );
 
2394
    UPDATE_POS( ast, start, lex->index() );
 
2395
    node = ast;
 
2396
 
 
2397
    return true;
 
2398
}
 
2399
 
 
2400
bool Parser::parseStatement( StatementAST::Node& node ) // thanks to fiore@8080.it ;)
 
2401
{
 
2402
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseStatement()" << endl;
 
2403
    switch( lex->lookAhead(0) ){
 
2404
 
 
2405
    case Token_while:
 
2406
        return parseWhileStatement( node );
 
2407
 
 
2408
    case Token_do:
 
2409
        return parseDoStatement( node );
 
2410
 
 
2411
    case Token_for:
 
2412
        return parseForStatement( node );
 
2413
 
 
2414
    case Token_foreach:
 
2415
        return parseForEachStatement( node );
 
2416
    
 
2417
    case Token_if:
 
2418
        return parseIfStatement( node );
 
2419
 
 
2420
    case Token_switch:
 
2421
        return parseSwitchStatement( node );
 
2422
 
 
2423
    case Token_try:
 
2424
        return parseTryBlockStatement( node );
 
2425
 
 
2426
    case Token_case:
 
2427
    case Token_default:
 
2428
        return parseLabeledStatement( node );
 
2429
 
 
2430
    case Token_break:
 
2431
    case Token_continue:
 
2432
        lex->nextToken();
 
2433
        ADVANCE( ';', ";" );
 
2434
        return true;
 
2435
 
 
2436
    case Token_goto:
 
2437
        lex->nextToken();
 
2438
        ADVANCE( Token_identifier, "identifier" );
 
2439
        ADVANCE( ';', ";" );
 
2440
        return true;
 
2441
 
 
2442
    case Token_return:
 
2443
    {
 
2444
        lex->nextToken();
 
2445
        AST::Node expr;
 
2446
        skipCommaExpression( expr );
 
2447
        ADVANCE( ';', ";" );
 
2448
    }
 
2449
    return true;
 
2450
 
 
2451
    case '{':
 
2452
        return parseCompoundStatement( node );
 
2453
 
 
2454
    case Token_identifier:
 
2455
        if( parseLabeledStatement(node) )
 
2456
            return true;
 
2457
        break;
 
2458
    }
 
2459
 
 
2460
    //kdDebug(9007)<< "------------> try with declaration statement" << endl;
 
2461
    if ( parseDeclarationStatement(node) )
 
2462
        return true;
 
2463
 
 
2464
    return skipExpressionStatement( node );
 
2465
}
 
2466
 
 
2467
bool Parser::parseCondition( ConditionAST::Node& node )
 
2468
{
 
2469
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCondition()" << endl;
 
2470
 
 
2471
    int start = lex->index();
 
2472
 
 
2473
    ConditionAST::Node ast = CreateNode<ConditionAST>();
 
2474
 
 
2475
    TypeSpecifierAST::Node spec;
 
2476
    if( parseTypeSpecifier(spec) ){
 
2477
        DeclaratorAST::Node decl;
 
2478
        if( parseDeclarator(decl) && lex->lookAhead(0) == '=' ) {
 
2479
            lex->nextToken();
 
2480
 
 
2481
            AST::Node expr;
 
2482
            if( skipExpression(expr) ){
 
2483
                ast->setTypeSpec( spec );
 
2484
                ast->setDeclarator( decl );
 
2485
                ast->setExpression( expr );
 
2486
 
 
2487
                UPDATE_POS( ast, start, lex->index() );
 
2488
                node = ast;
 
2489
 
 
2490
                return true;
 
2491
            }
 
2492
        }
 
2493
    }
 
2494
 
 
2495
    lex->setIndex( start );
 
2496
 
 
2497
    AST::Node expr;
 
2498
    if( !skipCommaExpression(expr) )
 
2499
        return false;
 
2500
 
 
2501
    ast->setExpression( expr );
 
2502
    UPDATE_POS( ast, start, lex->index() );
 
2503
    node = ast;
 
2504
    return true;
 
2505
}
 
2506
 
 
2507
 
 
2508
bool Parser::parseWhileStatement( StatementAST::Node& node )
 
2509
{
 
2510
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseWhileStatement()" << endl;
 
2511
    int start = lex->index();
 
2512
 
 
2513
    ADVANCE( Token_while, "while" );
 
2514
    ADVANCE( '(' , "(" );
 
2515
 
 
2516
    ConditionAST::Node cond;
 
2517
    if( !parseCondition(cond) ){
 
2518
        reportError( i18n("condition expected") );
 
2519
        return false;
 
2520
    }
 
2521
    ADVANCE( ')', ")" );
 
2522
 
 
2523
    StatementAST::Node body;
 
2524
    if( !parseStatement(body) ){
 
2525
        reportError( i18n("statement expected") );
 
2526
    }
 
2527
 
 
2528
    WhileStatementAST::Node ast = CreateNode<WhileStatementAST>();
 
2529
    ast->setCondition( cond );
 
2530
    ast->setStatement( body );
 
2531
    UPDATE_POS( ast, start, lex->index() );
 
2532
    node = ast;
 
2533
 
 
2534
    return true;
 
2535
}
 
2536
 
 
2537
bool Parser::parseDoStatement( StatementAST::Node& node )
 
2538
{
 
2539
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDoStatement()" << endl;
 
2540
    int start = lex->index();
 
2541
 
 
2542
    ADVANCE( Token_do, "do" );
 
2543
 
 
2544
    StatementAST::Node body;
 
2545
    if( !parseStatement(body) ){
 
2546
        reportError( i18n("statement expected") );
 
2547
        //return false;
 
2548
    }
 
2549
 
 
2550
    ADVANCE_NR( Token_while, "while" );
 
2551
    ADVANCE_NR( '(' , "(" );
 
2552
 
 
2553
    AST::Node expr;
 
2554
    if( !skipCommaExpression(expr) ){
 
2555
        reportError( i18n("expression expected") );
 
2556
        //return false;
 
2557
    }
 
2558
 
 
2559
    ADVANCE_NR( ')', ")" );
 
2560
    ADVANCE_NR( ';', ";" );
 
2561
 
 
2562
    DoStatementAST::Node ast = CreateNode<DoStatementAST>();
 
2563
    ast->setStatement( body );
 
2564
    //ast->setCondition( condition );
 
2565
    UPDATE_POS( ast, start, lex->index() );
 
2566
    node = ast;
 
2567
 
 
2568
    return true;
 
2569
}
 
2570
 
 
2571
bool Parser::parseForStatement( StatementAST::Node& node )
 
2572
{
 
2573
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseForStatement()" << endl;
 
2574
    int start = lex->index();
 
2575
 
 
2576
    ADVANCE( Token_for, "for" );
 
2577
    ADVANCE( '(', "(" );
 
2578
 
 
2579
    StatementAST::Node init;
 
2580
    if( !parseForInitStatement(init) ){
 
2581
        reportError( i18n("for initialization expected") );
 
2582
        return false;
 
2583
    }
 
2584
 
 
2585
    ConditionAST::Node cond;
 
2586
    parseCondition( cond );
 
2587
    ADVANCE( ';', ";" );
 
2588
 
 
2589
    AST::Node expr;
 
2590
    skipCommaExpression( expr );
 
2591
    ADVANCE( ')', ")" );
 
2592
 
 
2593
    StatementAST::Node body;
 
2594
    parseStatement(body);
 
2595
 
 
2596
    ForStatementAST::Node ast = CreateNode<ForStatementAST>();
 
2597
    ast->setInitStatement( init );
 
2598
    ast->setCondition( cond );
 
2599
    // ast->setExpression( expression );
 
2600
    ast->setStatement( body );
 
2601
    UPDATE_POS( ast, start, lex->index() );
 
2602
    node = ast;
 
2603
 
 
2604
    return true;
 
2605
}
 
2606
 
 
2607
// qt4 [erbsland]
 
2608
///@todo add the right parsing for the foreach statement
 
2609
bool Parser::parseForEachStatement( StatementAST::Node& node )
 
2610
{
 
2611
    int start = lex->index();
 
2612
 
 
2613
    ADVANCE( Token_foreach, "foreach" );
 
2614
    ADVANCE( '(', "(" );
 
2615
    
 
2616
    AST::Node expr;
 
2617
    // replace with the right parsing
 
2618
    skipCommaExpression( expr );
 
2619
    ADVANCE( ')', ")" );
 
2620
 
 
2621
    StatementAST::Node body;
 
2622
    parseStatement(body);
 
2623
 
 
2624
    ForEachStatementAST::Node ast = CreateNode<ForEachStatementAST>();
 
2625
    // add here the parser results
 
2626
    ast->setStatement( body );
 
2627
    UPDATE_POS( ast, start, lex->index() );
 
2628
    node = ast;
 
2629
 
 
2630
    return true;
 
2631
}
 
2632
 
 
2633
bool Parser::parseForInitStatement( StatementAST::Node& node )
 
2634
{
 
2635
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseForInitStatement()" << endl;
 
2636
 
 
2637
    if ( parseDeclarationStatement(node) )
 
2638
        return true;
 
2639
 
 
2640
    return skipExpressionStatement( node );
 
2641
}
 
2642
 
 
2643
bool Parser::parseCompoundStatement( StatementAST::Node& node )
 
2644
{
 
2645
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCompoundStatement()" << endl;
 
2646
    int start = lex->index();
 
2647
 
 
2648
    if( lex->lookAhead(0) != '{' ){
 
2649
        return false;
 
2650
    }
 
2651
    lex->nextToken();
 
2652
 
 
2653
    StatementListAST::Node ast = CreateNode<StatementListAST>();
 
2654
 
 
2655
    while( !lex->lookAhead(0).isNull() ){
 
2656
        if( lex->lookAhead(0) == '}' )
 
2657
            break;
 
2658
 
 
2659
        StatementAST::Node stmt;
 
2660
        int startStmt = lex->index();
 
2661
        if( !parseStatement(stmt) ){
 
2662
            if( startStmt == lex->index() )
 
2663
                lex->nextToken();
 
2664
            skipUntilStatement();
 
2665
        } else {
 
2666
            ast->addStatement( stmt );
 
2667
        }
 
2668
    }
 
2669
 
 
2670
    if( lex->lookAhead(0) != '}' ){
 
2671
        reportError( i18n("} expected") );
 
2672
    } else {
 
2673
        lex->nextToken();
 
2674
    }
 
2675
 
 
2676
    UPDATE_POS( ast, start, lex->index() );
 
2677
    node = ast;
 
2678
 
 
2679
    return true;
 
2680
}
 
2681
 
 
2682
bool Parser::parseIfStatement( StatementAST::Node& node )
 
2683
{
 
2684
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseIfStatement()" << endl;
 
2685
 
 
2686
    int start = lex->index();
 
2687
 
 
2688
    ADVANCE( Token_if, "if" );
 
2689
 
 
2690
    ADVANCE( '(' , "(" );
 
2691
 
 
2692
    IfStatementAST::Node ast = CreateNode<IfStatementAST>();
 
2693
 
 
2694
    ConditionAST::Node cond;
 
2695
    if( !parseCondition(cond) ){
 
2696
        reportError( i18n("condition expected") );
 
2697
        return false;
 
2698
    }
 
2699
    ADVANCE( ')', ")" );
 
2700
 
 
2701
    StatementAST::Node stmt;
 
2702
    if( !parseStatement(stmt) ){
 
2703
        reportError( i18n("statement expected") );
 
2704
    }
 
2705
 
 
2706
    ast->setCondition( cond );
 
2707
    ast->setStatement( stmt );
 
2708
 
 
2709
    if( lex->lookAhead(0) == Token_else ){
 
2710
        lex->nextToken();
 
2711
        StatementAST::Node elseStmt;
 
2712
        if( !parseStatement(elseStmt) ) {
 
2713
        reportError( i18n("statement expected") );
 
2714
        }
 
2715
        ast->setElseStatement( elseStmt );
 
2716
    }
 
2717
 
 
2718
    UPDATE_POS( ast, start, lex->index() );
 
2719
    node = ast;
 
2720
 
 
2721
    return true;
 
2722
}
 
2723
 
 
2724
bool Parser::parseSwitchStatement( StatementAST::Node& node )
 
2725
{
 
2726
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseSwitchStatement()" << endl;
 
2727
    int start = lex->index();
 
2728
    ADVANCE( Token_switch, "switch" );
 
2729
 
 
2730
    ADVANCE( '(' , "(" );
 
2731
 
 
2732
    ConditionAST::Node cond;
 
2733
    if( !parseCondition(cond) ){
 
2734
        reportError( i18n("condition expected") );
 
2735
        return false;
 
2736
    }
 
2737
    ADVANCE( ')', ")" );
 
2738
 
 
2739
    StatementAST::Node stmt;
 
2740
    if( !parseCompoundStatement(stmt) ){
 
2741
        syntaxError();
 
2742
        return false;
 
2743
    }
 
2744
 
 
2745
    SwitchStatementAST::Node ast = CreateNode<SwitchStatementAST>();
 
2746
    ast->setCondition( cond );
 
2747
    ast->setStatement( stmt );
 
2748
    UPDATE_POS( ast, start, lex->index() );
 
2749
    node = ast;
 
2750
 
 
2751
    return true;
 
2752
}
 
2753
 
 
2754
bool Parser::parseLabeledStatement( StatementAST::Node& node )
 
2755
{
 
2756
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseLabeledStatement()" << endl;
 
2757
    switch( lex->lookAhead(0) ){
 
2758
    case Token_identifier:
 
2759
    case Token_default:
 
2760
        if( lex->lookAhead(1) == ':' ){
 
2761
            lex->nextToken();
 
2762
            lex->nextToken();
 
2763
 
 
2764
            StatementAST::Node stmt;
 
2765
            if( parseStatement(stmt) ){
 
2766
                node = stmt;
 
2767
                return true;
 
2768
            }
 
2769
        }
 
2770
        break;
 
2771
 
 
2772
    case Token_case:
 
2773
    {
 
2774
        lex->nextToken();
 
2775
        AST::Node expr;
 
2776
        if( !parseConstantExpression(expr) ){
 
2777
            reportError( i18n("expression expected") );
 
2778
        } else if( lex->lookAhead(0) == Token_ellipsis ){
 
2779
            lex->nextToken();
 
2780
            
 
2781
            AST::Node expr2;
 
2782
            if( !parseConstantExpression(expr2) ){
 
2783
                reportError( i18n("expression expected") );
 
2784
            }
 
2785
        }
 
2786
        ADVANCE( ':', ":" );
 
2787
 
 
2788
        StatementAST::Node stmt;
 
2789
        if( parseStatement(stmt) ){
 
2790
            node = stmt;
 
2791
            return true;
 
2792
        }
 
2793
    }
 
2794
    break;
 
2795
 
 
2796
    }
 
2797
 
 
2798
    return false;
 
2799
}
 
2800
 
 
2801
bool Parser::parseBlockDeclaration( DeclarationAST::Node& node )
 
2802
{
 
2803
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseBlockDeclaration()" << endl;
 
2804
    switch( lex->lookAhead(0) ) {
 
2805
    case Token_typedef:
 
2806
        return parseTypedef( node );
 
2807
    case Token_using:
 
2808
        return parseUsing( node );
 
2809
    case Token_asm:
 
2810
        return parseAsmDefinition( node );
 
2811
    case Token_namespace:
 
2812
        return parseNamespaceAliasDefinition( node );
 
2813
    }
 
2814
 
 
2815
    int start = lex->index();
 
2816
 
 
2817
    GroupAST::Node storageSpec;
 
2818
    parseStorageClassSpecifier( storageSpec );
 
2819
 
 
2820
    GroupAST::Node cv;
 
2821
    parseCvQualify( cv );
 
2822
 
 
2823
    TypeSpecifierAST::Node spec;
 
2824
    if ( !parseTypeSpecifierOrClassSpec(spec) ) { // replace with simpleTypeSpecifier?!?!
 
2825
        lex->setIndex( start );
 
2826
        return false;
 
2827
    }
 
2828
    spec->setCvQualify( cv );
 
2829
 
 
2830
    GroupAST::Node cv2;
 
2831
    parseCvQualify( cv2 );
 
2832
    spec->setCv2Qualify( cv2 );
 
2833
 
 
2834
    InitDeclaratorListAST::Node declarators;
 
2835
    parseInitDeclaratorList( declarators );
 
2836
 
 
2837
    if( lex->lookAhead(0) != ';' ){
 
2838
        lex->setIndex( start );
 
2839
        return false;
 
2840
    }
 
2841
    lex->nextToken();
 
2842
 
 
2843
    SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
 
2844
    ast->setTypeSpec( spec );
 
2845
    ast->setInitDeclaratorList( declarators );
 
2846
    UPDATE_POS( ast, start, lex->index() );
 
2847
    node = ast;
 
2848
 
 
2849
    return true;
 
2850
}
 
2851
 
 
2852
bool Parser::parseNamespaceAliasDefinition( DeclarationAST::Node& /*node*/ )
 
2853
{
 
2854
    if ( lex->lookAhead(0) != Token_namespace ) {
 
2855
        return false;
 
2856
    }
 
2857
    lex->nextToken();
 
2858
 
 
2859
    ADVANCE( Token_identifier,  "identifier" );
 
2860
    ADVANCE( '=', "=" );
 
2861
 
 
2862
    NameAST::Node name;
 
2863
    if( !parseName(name) ){
 
2864
        reportError( i18n("Namespace name expected") );
 
2865
    }
 
2866
 
 
2867
    ADVANCE( ';', ";" );
 
2868
 
 
2869
    return true;
 
2870
 
 
2871
}
 
2872
 
 
2873
bool Parser::parseDeclarationStatement( StatementAST::Node& node )
 
2874
{
 
2875
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclarationStatement()" << endl;
 
2876
 
 
2877
    int start = lex->index();
 
2878
 
 
2879
    DeclarationAST::Node decl;
 
2880
    if ( !parseBlockDeclaration(decl) ){
 
2881
        return false;
 
2882
    }
 
2883
 
 
2884
    DeclarationStatementAST::Node ast = CreateNode<DeclarationStatementAST>();
 
2885
    ast->setDeclaration( decl );
 
2886
    UPDATE_POS( ast, start, lex->index() );
 
2887
    node = ast;
 
2888
 
 
2889
    //kdDebug(9007)<< "---------------------> found a block declaration" << endl;
 
2890
    return true;
 
2891
}
 
2892
 
 
2893
bool Parser::parseDeclarationInternal( DeclarationAST::Node& node )
 
2894
{
 
2895
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclarationInternal()" << endl;
 
2896
 
 
2897
    int start = lex->index();
 
2898
 
 
2899
    // that is for the case '__declspec(dllexport) int ...' or
 
2900
    // '__declspec(dllexport) inline int ...', etc.
 
2901
    GroupAST::Node winDeclSpec;
 
2902
    parseWinDeclSpec( winDeclSpec );
 
2903
 
 
2904
    GroupAST::Node funSpec;
 
2905
    bool hasFunSpec = parseFunctionSpecifier( funSpec );
 
2906
 
 
2907
    GroupAST::Node storageSpec;
 
2908
    bool hasStorageSpec = parseStorageClassSpecifier( storageSpec );
 
2909
 
 
2910
    if( hasStorageSpec && !hasFunSpec )
 
2911
        hasFunSpec = parseFunctionSpecifier( funSpec );
 
2912
 
 
2913
    // that is for the case 'friend __declspec(dllexport) ....'
 
2914
    GroupAST::Node winDeclSpec2;
 
2915
    parseWinDeclSpec( winDeclSpec2 );
 
2916
 
 
2917
    GroupAST::Node cv;
 
2918
    parseCvQualify( cv );
 
2919
 
 
2920
    int index = lex->index();
 
2921
    NameAST::Node name;
 
2922
    if( parseName(name) && lex->lookAhead(0) == '(' ){
 
2923
        // no type specifier, maybe a constructor or a cast operator??
 
2924
 
 
2925
        lex->setIndex( index );
 
2926
 
 
2927
        InitDeclaratorAST::Node declarator;
 
2928
        if( parseInitDeclarator(declarator) ){
 
2929
            int endSignature = lex->index();
 
2930
 
 
2931
            switch( lex->lookAhead(0) ){
 
2932
            case ';':
 
2933
                {
 
2934
                    lex->nextToken();
 
2935
 
 
2936
                    InitDeclaratorListAST::Node declarators = CreateNode<InitDeclaratorListAST>();
 
2937
 
 
2938
                    // update declarators position
 
2939
                    int startLine, startColumn, endLine, endColumn;
 
2940
                    if( declarator.get() ){
 
2941
                        declarator->getStartPosition( &startLine, &startColumn );
 
2942
                        declarator->getEndPosition( &endLine, &endColumn );
 
2943
                        declarators->setStartPosition( startLine, startColumn );
 
2944
                        declarators->setEndPosition( endLine, endColumn );
 
2945
                    }
 
2946
                    declarators->addInitDeclarator( declarator );
 
2947
 
 
2948
                    SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
 
2949
                    ast->setInitDeclaratorList( declarators );
 
2950
                    ast->setText( toString(start, endSignature) );
 
2951
                    node = ast;
 
2952
                    UPDATE_POS( node, start, lex->index() );
 
2953
                    return true;
 
2954
 
 
2955
                }
 
2956
                break;
 
2957
 
 
2958
            case ':':
 
2959
                {
 
2960
                    AST::Node ctorInit;
 
2961
                    StatementListAST::Node funBody;
 
2962
                    if( parseCtorInitializer(ctorInit) && parseFunctionBody(funBody) ){
 
2963
                        FunctionDefinitionAST::Node ast = CreateNode<FunctionDefinitionAST>();
 
2964
                        ast->setStorageSpecifier( storageSpec );
 
2965
                        ast->setFunctionSpecifier( funSpec );
 
2966
                        ast->setInitDeclarator( declarator );
 
2967
                        ast->setFunctionBody( funBody );
 
2968
                        ast->setText( toString(start, endSignature) );
 
2969
                        node = ast;
 
2970
                        UPDATE_POS( node, start, lex->index() );
 
2971
                        return true;
 
2972
                    }
 
2973
                }
 
2974
                break;
 
2975
 
 
2976
            case '{':
 
2977
                {
 
2978
                    StatementListAST::Node funBody;
 
2979
                    if( parseFunctionBody(funBody) ){
 
2980
                        FunctionDefinitionAST::Node ast = CreateNode<FunctionDefinitionAST>();
 
2981
                        ast->setStorageSpecifier( storageSpec );
 
2982
                        ast->setFunctionSpecifier( funSpec );
 
2983
                        ast->setInitDeclarator( declarator );
 
2984
                        ast->setText( toString(start, endSignature) );
 
2985
                        ast->setFunctionBody( funBody );
 
2986
                        node = ast;
 
2987
                        UPDATE_POS( node, start, lex->index() );
 
2988
                        return true;
 
2989
                    }
 
2990
                }
 
2991
                break;
 
2992
 
 
2993
            case '(':
 
2994
            case '[':
 
2995
                // ops!! it seems a declarator
 
2996
                goto start_decl;
 
2997
                break;
 
2998
            }
 
2999
 
 
3000
        }
 
3001
 
 
3002
        syntaxError();
 
3003
        return false;
 
3004
    }
 
3005
 
 
3006
start_decl:
 
3007
    lex->setIndex( index );
 
3008
 
 
3009
    if( lex->lookAhead(0) == Token_const && lex->lookAhead(1) == Token_identifier && lex->lookAhead(2) == '=' ){
 
3010
        // constant definition
 
3011
        lex->nextToken();
 
3012
        InitDeclaratorListAST::Node declarators;
 
3013
        if( parseInitDeclaratorList(declarators) ){
 
3014
            ADVANCE( ';', ";" );
 
3015
            DeclarationAST::Node ast = CreateNode<DeclarationAST>();
 
3016
            node = ast;
 
3017
            UPDATE_POS( node, start, lex->index() );
 
3018
            return true;
 
3019
        }
 
3020
        syntaxError();
 
3021
        return false;
 
3022
    }
 
3023
 
 
3024
    TypeSpecifierAST::Node spec;
 
3025
    if( parseTypeSpecifier(spec) ){
 
3026
        if ( !hasFunSpec )
 
3027
            parseFunctionSpecifier( funSpec );  // e.g. "void inline"
 
3028
        spec->setCvQualify( cv );
 
3029
 
 
3030
        InitDeclaratorListAST::Node declarators;
 
3031
 
 
3032
        InitDeclaratorAST::Node decl;
 
3033
        int startDeclarator = lex->index();
 
3034
        bool maybeFunctionDefinition = false;
 
3035
 
 
3036
        if( lex->lookAhead(0) != ';' ){
 
3037
            if( parseInitDeclarator(decl) && lex->lookAhead(0) == '{' ){
 
3038
                // function definition
 
3039
                maybeFunctionDefinition = true;
 
3040
            } else {
 
3041
                lex->setIndex( startDeclarator );
 
3042
                if( !parseInitDeclaratorList(declarators) ){
 
3043
                    syntaxError();
 
3044
                    return false;
 
3045
                }
 
3046
            }
 
3047
        }
 
3048
 
 
3049
        int endSignature = lex->index();
 
3050
        switch( lex->lookAhead(0) ){
 
3051
        case ';':
 
3052
            {
 
3053
                lex->nextToken();
 
3054
                SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
 
3055
                ast->setStorageSpecifier( storageSpec );
 
3056
                ast->setFunctionSpecifier( funSpec );
 
3057
                ast->setText( toString(start, endSignature) );
 
3058
                ast->setTypeSpec( spec );
 
3059
                ast->setWinDeclSpec( winDeclSpec );
 
3060
                ast->setInitDeclaratorList( declarators );
 
3061
                node = ast;
 
3062
                UPDATE_POS( node, start, lex->index() );
 
3063
            }
 
3064
            return true;
 
3065
 
 
3066
        case '{':
 
3067
            {
 
3068
                if( !maybeFunctionDefinition ){
 
3069
                    syntaxError();
 
3070
                    return false;
 
3071
                }
 
3072
                StatementListAST::Node funBody;
 
3073
                if ( parseFunctionBody(funBody) ) {
 
3074
                    FunctionDefinitionAST::Node ast = CreateNode<FunctionDefinitionAST>();
 
3075
                    ast->setWinDeclSpec( winDeclSpec );
 
3076
                    ast->setStorageSpecifier( storageSpec );
 
3077
                    ast->setFunctionSpecifier( funSpec );
 
3078
                    ast->setText( toString(start, endSignature) );
 
3079
                    ast->setTypeSpec( spec );
 
3080
                    ast->setFunctionBody( funBody );
 
3081
                    ast->setInitDeclarator( decl );
 
3082
                    node = ast;
 
3083
                    UPDATE_POS( node, start, lex->index() );
 
3084
                    return true;
 
3085
                }
 
3086
            }
 
3087
            break;
 
3088
 
 
3089
        }
 
3090
    }
 
3091
 
 
3092
    syntaxError();
 
3093
    return false;
 
3094
}
 
3095
 
 
3096
bool Parser::parseFunctionBody( StatementListAST::Node& node )
 
3097
{
 
3098
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseFunctionBody()" << endl;
 
3099
 
 
3100
    int start = lex->index();
 
3101
    if( lex->lookAhead(0) != '{' ){
 
3102
        return false;
 
3103
    }
 
3104
    lex->nextToken();
 
3105
 
 
3106
    StatementListAST::Node ast = CreateNode<StatementListAST>();
 
3107
 
 
3108
    while( !lex->lookAhead(0).isNull() ){
 
3109
        if( lex->lookAhead(0) == '}' )
 
3110
            break;
 
3111
 
 
3112
        StatementAST::Node stmt;
 
3113
        int startStmt = lex->index();
 
3114
        if( !parseStatement(stmt) ){
 
3115
            if( startStmt == lex->index() )
 
3116
                lex->nextToken();
 
3117
            skipUntilStatement();
 
3118
        } else
 
3119
            ast->addStatement( stmt );
 
3120
    }
 
3121
 
 
3122
    if( lex->lookAhead(0) != '}' ){
 
3123
        reportError( i18n("} expected") );
 
3124
    } else
 
3125
        lex->nextToken();
 
3126
 
 
3127
    UPDATE_POS( ast, start, lex->index() );
 
3128
    node = ast;
 
3129
 
 
3130
    return true;
 
3131
}
 
3132
 
 
3133
QString Parser::toString( int start, int end, const QString& sep ) const
 
3134
{
 
3135
    QStringList l;
 
3136
 
 
3137
    for( int i=start; i<end; ++i ){
 
3138
        l << lex->tokenAt(i).text();
 
3139
    }
 
3140
 
 
3141
    return l.join( sep ).stripWhiteSpace();
 
3142
}
 
3143
 
 
3144
bool Parser::parseTypeSpecifierOrClassSpec( TypeSpecifierAST::Node& node )
 
3145
{
 
3146
    if( parseClassSpecifier(node) )
 
3147
        return true;
 
3148
    else if( parseEnumSpecifier(node) )
 
3149
        return true;
 
3150
    else if( parseTypeSpecifier(node) )
 
3151
        return true;
 
3152
 
 
3153
    return false;
 
3154
}
 
3155
 
 
3156
bool Parser::parseTryBlockStatement( StatementAST::Node& node )
 
3157
{
 
3158
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTryBlockStatement()" << endl;
 
3159
 
 
3160
    int start = lex->index();
 
3161
    if( lex->lookAhead(0) != Token_try ){
 
3162
        return false;
 
3163
    }
 
3164
    lex->nextToken();
 
3165
 
 
3166
    StatementAST::Node stmt;
 
3167
    if( !parseCompoundStatement(stmt) ){
 
3168
        syntaxError();
 
3169
    }
 
3170
 
 
3171
    if( lex->lookAhead(0) != Token_catch ){
 
3172
        reportError( i18n("catch expected") );
 
3173
    }
 
3174
 
 
3175
    CatchStatementListAST::Node list = CreateNode<CatchStatementListAST>();
 
3176
 
 
3177
    while( lex->lookAhead(0) == Token_catch ){
 
3178
 
 
3179
        lex->nextToken();
 
3180
        ADVANCE( '(', "(" );
 
3181
        ConditionAST::Node cond;
 
3182
        if( !parseCondition(cond) ){
 
3183
            reportError( i18n("condition expected") );
 
3184
            return false;
 
3185
        }
 
3186
        ADVANCE( ')', ")" );
 
3187
 
 
3188
        StatementAST::Node body;
 
3189
        if( !parseCompoundStatement(body) ){
 
3190
            syntaxError();
 
3191
        }
 
3192
 
 
3193
        CatchStatementAST::Node cstmt = CreateNode<CatchStatementAST>();
 
3194
        cstmt->setCondition( cond );
 
3195
        cstmt->setStatement( body );
 
3196
        list->addStatement( cstmt );
 
3197
    }
 
3198
 
 
3199
    TryBlockStatementAST::Node ast = CreateNode<TryBlockStatementAST>();
 
3200
    ast->setStatement( stmt );
 
3201
    ast->setCatchStatementList( list );
 
3202
    UPDATE_POS( ast, start, lex->index() );
 
3203
    node = ast;
 
3204
 
 
3205
    return true;
 
3206
}
 
3207
 
 
3208
bool Parser::parsePrimaryExpression( AST::Node& /*node*/ )
 
3209
{
 
3210
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parsePrimarExpression()" << endl;
 
3211
 
 
3212
 
 
3213
    switch( lex->lookAhead(0) ){
 
3214
        case Token_string_literal:
 
3215
        {
 
3216
            AST::Node lit;
 
3217
            parseStringLiteral( lit );
 
3218
        }
 
3219
        return true;
 
3220
 
 
3221
        case Token_number_literal:
 
3222
        case Token_char_literal:
 
3223
        case Token_true:
 
3224
        case Token_false:
 
3225
            lex->nextToken();
 
3226
            return true;
 
3227
 
 
3228
        case Token_this:
 
3229
            lex->nextToken();
 
3230
            return true;
 
3231
 
 
3232
        case Token_dynamic_cast:
 
3233
        case Token_static_cast:
 
3234
        case Token_reinterpret_cast:
 
3235
        case Token_const_cast:
 
3236
            {
 
3237
                lex->nextToken();
 
3238
 
 
3239
                CHECK( '<', "<" );
 
3240
                AST::Node typeId;
 
3241
                parseTypeId( typeId );
 
3242
                CHECK( '>', ">" );
 
3243
 
 
3244
                CHECK( '(', "(" );
 
3245
                AST::Node expr;
 
3246
                parseCommaExpression( expr );
 
3247
                CHECK( ')', ")" );
 
3248
            }
 
3249
            return true;
 
3250
 
 
3251
        case Token_typeid:
 
3252
            {
 
3253
                lex->nextToken();
 
3254
                CHECK( '(', "(" );
 
3255
                AST::Node expr;
 
3256
                parseCommaExpression( expr );
 
3257
                CHECK( ')', ")" );
 
3258
            }
 
3259
            return true;
 
3260
 
 
3261
        case '(':
 
3262
            {
 
3263
                lex->nextToken();
 
3264
                //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "token = " << lex->lookAhead(0).text() << endl;
 
3265
                AST::Node expr;
 
3266
                if( !parseExpression(expr) ){
 
3267
                    return false;
 
3268
                }
 
3269
                CHECK( ')', ")" );
 
3270
            }
 
3271
            return true;
 
3272
 
 
3273
        default:
 
3274
            {
 
3275
                int start = lex->index();
 
3276
                TypeSpecifierAST::Node typeSpec;
 
3277
                if( parseSimpleTypeSpecifier(typeSpec) && lex->lookAhead(0) == '(' ){
 
3278
                    lex->nextToken();
 
3279
                    AST::Node expr;
 
3280
                    parseCommaExpression( expr );
 
3281
                    CHECK( ')', ")" );
 
3282
                    return true;
 
3283
                }
 
3284
 
 
3285
                lex->setIndex( start );
 
3286
                NameAST::Node name;
 
3287
                if( parseName(name) )
 
3288
                    return true;
 
3289
            }
 
3290
        }
 
3291
 
 
3292
    return false;
 
3293
}
 
3294
 
 
3295
bool Parser::parsePostfixExpression( AST::Node& /*node*/ )
 
3296
{
 
3297
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parsePostfixExpression()" << endl;
 
3298
 
 
3299
    AST::Node expr;
 
3300
    if( !parsePrimaryExpression(expr) )
 
3301
        return false;
 
3302
 
 
3303
    while( true ){
 
3304
        switch(lex->lookAhead(0))
 
3305
        {
 
3306
        case '[':
 
3307
            {
 
3308
                lex->nextToken();
 
3309
                AST::Node e;
 
3310
                parseCommaExpression( e );
 
3311
                CHECK( ']', "]" );
 
3312
            }
 
3313
            break;
 
3314
 
 
3315
        case '(':
 
3316
            {
 
3317
                lex->nextToken();
 
3318
                AST::Node funArgs;
 
3319
                parseCommaExpression( funArgs );
 
3320
                CHECK( ')', ")" );
 
3321
            }
 
3322
            break;
 
3323
 
 
3324
        case Token_incr:
 
3325
        case Token_decr:
 
3326
            lex->nextToken();
 
3327
            break;
 
3328
 
 
3329
        case '.':
 
3330
        case Token_arrow:
 
3331
            {
 
3332
                lex->nextToken();
 
3333
                if( lex->lookAhead(0) == Token_template )
 
3334
                    lex->nextToken();
 
3335
 
 
3336
                NameAST::Node name;
 
3337
                if( !parseName(name) ){
 
3338
                    return false;
 
3339
                }
 
3340
            }
 
3341
            break;
 
3342
 
 
3343
        case Token_typename:
 
3344
            {
 
3345
                lex->nextToken();
 
3346
 
 
3347
                NameAST::Node name;
 
3348
                if( !parseName(name) ){
 
3349
                    return false;
 
3350
                }
 
3351
 
 
3352
                CHECK( '(', "(" );
 
3353
                AST::Node expr;
 
3354
                parseCommaExpression(expr);
 
3355
                CHECK( ')', ")" );
 
3356
            }
 
3357
            return true;
 
3358
 
 
3359
        default:
 
3360
            return true;
 
3361
 
 
3362
        } // end switch
 
3363
 
 
3364
    } // end while
 
3365
 
 
3366
    return true;
 
3367
}
 
3368
 
 
3369
bool Parser::parseUnaryExpression( AST::Node& node )
 
3370
{
 
3371
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseUnaryExpression()" << endl;
 
3372
 
 
3373
    switch( lex->lookAhead(0) ){
 
3374
        case Token_incr:
 
3375
        case Token_decr:
 
3376
        case '*':
 
3377
        case '&':
 
3378
        case '+':
 
3379
        case '-':
 
3380
        case '!':
 
3381
        case '~':
 
3382
        {
 
3383
            lex->nextToken();
 
3384
            AST::Node expr;
 
3385
            return parseCastExpression( expr );
 
3386
        }
 
3387
 
 
3388
        case Token_sizeof:
 
3389
        {
 
3390
            lex->nextToken();
 
3391
            int index = lex->index();
 
3392
            if( lex->lookAhead(0) == '(' ){
 
3393
                lex->nextToken();
 
3394
                AST::Node typeId;
 
3395
                if( parseTypeId(typeId) && lex->lookAhead(0) == ')' ){
 
3396
                    lex->nextToken();
 
3397
                    return true;
 
3398
                }
 
3399
                lex->setIndex( index );
 
3400
            }
 
3401
            AST::Node expr;
 
3402
            return parseUnaryExpression( expr );
 
3403
        }
 
3404
 
 
3405
        case Token_new:
 
3406
            return parseNewExpression( node );
 
3407
 
 
3408
        case Token_delete:
 
3409
            return parseDeleteExpression( node );
 
3410
    }
 
3411
 
 
3412
    return parsePostfixExpression( node );
 
3413
}
 
3414
 
 
3415
bool Parser::parseNewExpression( AST::Node& /*node*/ )
 
3416
{
 
3417
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseNewExpression()" << endl;
 
3418
    if( lex->lookAhead(0) == Token_scope && lex->lookAhead(1) == Token_new )
 
3419
        lex->nextToken();
 
3420
 
 
3421
    CHECK( Token_new, "new");
 
3422
 
 
3423
    if( lex->lookAhead(0) == '(' ){
 
3424
        lex->nextToken();
 
3425
        AST::Node expr;
 
3426
        parseCommaExpression( expr );
 
3427
        CHECK( ')', ")" );
 
3428
    }
 
3429
 
 
3430
    if( lex->lookAhead(0) == '(' ){
 
3431
        lex->nextToken();
 
3432
        AST::Node typeId;
 
3433
        parseTypeId( typeId );
 
3434
        CHECK( ')', ")" );
 
3435
    } else {
 
3436
        AST::Node typeId;
 
3437
        parseNewTypeId( typeId );
 
3438
    }
 
3439
 
 
3440
    AST::Node init;
 
3441
    parseNewInitializer( init );
 
3442
    return true;
 
3443
}
 
3444
 
 
3445
bool Parser::parseNewTypeId( AST::Node& /*node*/ )
 
3446
{
 
3447
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseNewTypeId()" << endl;
 
3448
    TypeSpecifierAST::Node typeSpec;
 
3449
    if( parseTypeSpecifier(typeSpec) ){
 
3450
        AST::Node declarator;
 
3451
        parseNewDeclarator( declarator );
 
3452
        return true;
 
3453
    }
 
3454
 
 
3455
    return false;
 
3456
}
 
3457
 
 
3458
bool Parser::parseNewDeclarator( AST::Node& /*node*/ )
 
3459
{
 
3460
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseNewDeclarator()" << endl;
 
3461
    AST::Node ptrOp;
 
3462
    if( parsePtrOperator(ptrOp) ){
 
3463
        AST::Node declarator;
 
3464
        parseNewDeclarator( declarator );
 
3465
        return true;
 
3466
    }
 
3467
 
 
3468
    if( lex->lookAhead(0) == '[' ){
 
3469
        while( lex->lookAhead(0) == '[' ){
 
3470
            lex->nextToken();
 
3471
            AST::Node expr;
 
3472
            parseExpression( expr );
 
3473
            ADVANCE( ']', "]" );
 
3474
        }
 
3475
        return true;
 
3476
    }
 
3477
 
 
3478
    return false;
 
3479
}
 
3480
 
 
3481
bool Parser::parseNewInitializer( AST::Node& /*node*/ )
 
3482
{
 
3483
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseNewInitializer()" << endl;
 
3484
    if( lex->lookAhead(0) != '(' )
 
3485
        return false;
 
3486
 
 
3487
    lex->nextToken();
 
3488
    AST::Node expr;
 
3489
    parseCommaExpression( expr );
 
3490
    CHECK( ')', ")" );
 
3491
 
 
3492
    return true;
 
3493
}
 
3494
 
 
3495
bool Parser::parseDeleteExpression( AST::Node& /*node*/ )
 
3496
{
 
3497
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeleteExpression()" << endl;
 
3498
    if( lex->lookAhead(0) == Token_scope && lex->lookAhead(1) == Token_delete )
 
3499
        lex->nextToken();
 
3500
 
 
3501
    CHECK( Token_delete, "delete" );
 
3502
 
 
3503
    if( lex->lookAhead(0) == '[' ){
 
3504
        lex->nextToken();
 
3505
        CHECK( ']', "]" );
 
3506
    }
 
3507
 
 
3508
    AST::Node expr;
 
3509
    return parseCastExpression( expr );
 
3510
}
 
3511
 
 
3512
bool Parser::parseCastExpression( AST::Node& /*node*/ )
 
3513
{
 
3514
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCastExpression()" << endl;
 
3515
 
 
3516
    int index = lex->index();
 
3517
 
 
3518
    if( lex->lookAhead(0) == '(' ){
 
3519
        lex->nextToken();
 
3520
        AST::Node typeId;
 
3521
        if ( parseTypeId(typeId) ) {
 
3522
            if ( lex->lookAhead(0) == ')' ) {
 
3523
                lex->nextToken();
 
3524
                AST::Node expr;
 
3525
                if( parseCastExpression(expr) )
 
3526
                    return true;
 
3527
            }
 
3528
        }
 
3529
    }
 
3530
 
 
3531
    lex->setIndex( index );
 
3532
 
 
3533
    AST::Node expr;
 
3534
    return parseUnaryExpression( expr );
 
3535
}
 
3536
 
 
3537
bool Parser::parsePmExpression( AST::Node& /*node*/ )
 
3538
{
 
3539
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser:parsePmExpression()" << endl;
 
3540
    AST::Node expr;
 
3541
    if( !parseCastExpression(expr) )
 
3542
        return false;
 
3543
 
 
3544
    while( lex->lookAhead(0) == Token_ptrmem ){
 
3545
        lex->nextToken();
 
3546
 
 
3547
        if( !parseCastExpression(expr) )
 
3548
            return false;
 
3549
    }
 
3550
 
 
3551
    return true;
 
3552
}
 
3553
 
 
3554
bool Parser::parseMultiplicativeExpression( AST::Node& /*node*/ )
 
3555
{
 
3556
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseMultiplicativeExpression()" << endl;
 
3557
    AST::Node expr;
 
3558
    if( !parsePmExpression(expr) )
 
3559
        return false;
 
3560
 
 
3561
    while( lex->lookAhead(0) == '*' || lex->lookAhead(0) == '/' || lex->lookAhead(0) == '%' ){
 
3562
        lex->nextToken();
 
3563
 
 
3564
        if( !parsePmExpression(expr) )
 
3565
            return false;
 
3566
    }
 
3567
 
 
3568
    return true;
 
3569
}
 
3570
 
 
3571
 
 
3572
bool Parser::parseAdditiveExpression( AST::Node& /*node*/ )
 
3573
{
 
3574
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseAdditiveExpression()" << endl;
 
3575
    AST::Node expr;
 
3576
    if( !parseMultiplicativeExpression(expr) )
 
3577
        return false;
 
3578
 
 
3579
    while( lex->lookAhead(0) == '+' || lex->lookAhead(0) == '-' ){
 
3580
        lex->nextToken();
 
3581
 
 
3582
        if( !parseMultiplicativeExpression(expr) )
 
3583
            return false;
 
3584
    }
 
3585
 
 
3586
    return true;
 
3587
}
 
3588
 
 
3589
bool Parser::parseShiftExpression( AST::Node& /*node*/ )
 
3590
{
 
3591
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseShiftExpression()" << endl;
 
3592
    AST::Node expr;
 
3593
    if( !parseAdditiveExpression(expr) )
 
3594
        return false;
 
3595
 
 
3596
    while( lex->lookAhead(0) == Token_shift ){
 
3597
        lex->nextToken();
 
3598
 
 
3599
        if( !parseAdditiveExpression(expr) )
 
3600
            return false;
 
3601
    }
 
3602
 
 
3603
    return true;
 
3604
}
 
3605
 
 
3606
bool Parser::parseRelationalExpression( AST::Node& /*node*/, bool templArgs )
 
3607
{
 
3608
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseRelationalExpression()" << endl;
 
3609
    AST::Node expr;
 
3610
    if( !parseShiftExpression(expr) )
 
3611
        return false;
 
3612
 
 
3613
    while( lex->lookAhead(0) == '<' || (lex->lookAhead(0) == '>' && !templArgs) ||
 
3614
           lex->lookAhead(0) == Token_leq || lex->lookAhead(0) == Token_geq ){
 
3615
        lex->nextToken();
 
3616
 
 
3617
        if( !parseShiftExpression(expr) )
 
3618
            return false;
 
3619
    }
 
3620
 
 
3621
    return true;
 
3622
}
 
3623
 
 
3624
bool Parser::parseEqualityExpression( AST::Node& /*node*/, bool templArgs )
 
3625
{
 
3626
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseEqualityExpression()" << endl;
 
3627
    AST::Node expr;
 
3628
    if( !parseRelationalExpression(expr, templArgs) )
 
3629
        return false;
 
3630
 
 
3631
    while( lex->lookAhead(0) == Token_eq || lex->lookAhead(0) == Token_not_eq ){
 
3632
        lex->nextToken();
 
3633
 
 
3634
        if( !parseRelationalExpression(expr, templArgs) )
 
3635
            return false;
 
3636
    }
 
3637
 
 
3638
    return true;
 
3639
}
 
3640
 
 
3641
bool Parser::parseAndExpression( AST::Node& /*node*/, bool templArgs )
 
3642
{
 
3643
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseAndExpression()" << endl;
 
3644
    AST::Node expr;
 
3645
    if( !parseEqualityExpression(expr, templArgs) )
 
3646
        return false;
 
3647
 
 
3648
    while( lex->lookAhead(0) == '&' ){
 
3649
        lex->nextToken();
 
3650
 
 
3651
        if( !parseEqualityExpression(expr, templArgs) )
 
3652
            return false;
 
3653
    }
 
3654
 
 
3655
    return true;
 
3656
}
 
3657
 
 
3658
bool Parser::parseExclusiveOrExpression( AST::Node& /*node*/, bool templArgs )
 
3659
{
 
3660
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseExclusiveOrExpression()" << endl;
 
3661
    AST::Node expr;
 
3662
    if( !parseAndExpression(expr, templArgs) )
 
3663
        return false;
 
3664
 
 
3665
    while( lex->lookAhead(0) == '^' ){
 
3666
        lex->nextToken();
 
3667
 
 
3668
        if( !parseAndExpression(expr, templArgs) )
 
3669
            return false;
 
3670
    }
 
3671
 
 
3672
    return true;
 
3673
}
 
3674
 
 
3675
bool Parser::parseInclusiveOrExpression( AST::Node& /*node*/, bool templArgs )
 
3676
{
 
3677
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInclusiveOrExpression()" << endl;
 
3678
    AST::Node expr;
 
3679
    if( !parseExclusiveOrExpression(expr, templArgs) )
 
3680
        return false;
 
3681
 
 
3682
    while( lex->lookAhead(0) == '|' ){
 
3683
        lex->nextToken();
 
3684
 
 
3685
        if( !parseExclusiveOrExpression(expr, templArgs) )
 
3686
            return false;
 
3687
    }
 
3688
 
 
3689
    return true;
 
3690
}
 
3691
 
 
3692
bool Parser::parseLogicalAndExpression( AST::Node& /*node*/, bool templArgs )
 
3693
{
 
3694
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseLogicalAndExpression()" << endl;
 
3695
 
 
3696
    AST::Node expr;
 
3697
    if( !parseInclusiveOrExpression(expr, templArgs) )
 
3698
        return false;
 
3699
 
 
3700
    while( lex->lookAhead(0) == Token_and ){
 
3701
        lex->nextToken();
 
3702
 
 
3703
        if( !parseInclusiveOrExpression(expr, templArgs) )
 
3704
            return false;
 
3705
    }
 
3706
 
 
3707
    return true;
 
3708
}
 
3709
 
 
3710
bool Parser::parseLogicalOrExpression( AST::Node& node, bool templArgs )
 
3711
{
 
3712
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseLogicalOrExpression()" << endl;
 
3713
 
 
3714
    int start = lex->index();
 
3715
 
 
3716
    AST::Node expr;
 
3717
    if( !parseLogicalAndExpression(expr, templArgs) )
 
3718
        return false;
 
3719
 
 
3720
    while( lex->lookAhead(0) == Token_or ){
 
3721
        lex->nextToken();
 
3722
 
 
3723
        if( !parseLogicalAndExpression(expr, templArgs) )
 
3724
            return false;
 
3725
    }
 
3726
 
 
3727
    AST::Node ast = CreateNode<AST>();
 
3728
    UPDATE_POS( ast, start, lex->index() );
 
3729
    node = ast;
 
3730
    return true;
 
3731
}
 
3732
 
 
3733
bool Parser::parseConditionalExpression( AST::Node& /*node*/ )
 
3734
{
 
3735
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseConditionalExpression()" << endl;
 
3736
    AST::Node expr;
 
3737
    if( !parseLogicalOrExpression(expr) )
 
3738
        return false;
 
3739
 
 
3740
    if( lex->lookAhead(0) == '?' ){
 
3741
        lex->nextToken();
 
3742
 
 
3743
        if( !parseExpression(expr) )
 
3744
            return false;
 
3745
 
 
3746
        CHECK( ':', ":" );
 
3747
 
 
3748
        if( !parseAssignmentExpression(expr) )
 
3749
            return false;
 
3750
    }
 
3751
 
 
3752
    return true;
 
3753
}
 
3754
 
 
3755
bool Parser::parseAssignmentExpression( AST::Node& node )
 
3756
{
 
3757
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseAssignmentExpression()" << endl;
 
3758
    int start = lex->index();
 
3759
    AST::Node expr;
 
3760
    if( lex->lookAhead(0) == Token_throw && !parseThrowExpression(expr) )
 
3761
        return false;
 
3762
    else if( !parseConditionalExpression(expr) )
 
3763
        return false;
 
3764
 
 
3765
    while( lex->lookAhead(0) == Token_assign || lex->lookAhead(0) == '=' ){
 
3766
        lex->nextToken();
 
3767
 
 
3768
        if( !parseConditionalExpression(expr) )
 
3769
            return false;
 
3770
    }
 
3771
 
 
3772
    AST::Node ast = CreateNode<AST>();
 
3773
    UPDATE_POS( ast, start, lex->index() );
 
3774
    node = ast;
 
3775
    return true;
 
3776
}
 
3777
 
 
3778
bool Parser::parseConstantExpression( AST::Node& node )
 
3779
{
 
3780
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseConstantExpression()" << endl;
 
3781
    int start = lex->index();
 
3782
    if( parseConditionalExpression(node) ){
 
3783
        AST::Node ast = CreateNode<AST>();
 
3784
        UPDATE_POS( ast, start, lex->index() );
 
3785
        node = ast;
 
3786
        return true;
 
3787
    }
 
3788
    return false;
 
3789
}
 
3790
 
 
3791
bool Parser::parseExpression( AST::Node& node )
 
3792
{
 
3793
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseExpression()" << endl;
 
3794
 
 
3795
    int start = lex->index();
 
3796
 
 
3797
    if( !parseCommaExpression(node) )
 
3798
        return false;
 
3799
 
 
3800
    AST::Node ast = CreateNode<AST>();
 
3801
    UPDATE_POS( ast, start, lex->index() );
 
3802
    node = ast;
 
3803
    return true;
 
3804
}
 
3805
 
 
3806
bool Parser::parseCommaExpression( AST::Node& node )
 
3807
{
 
3808
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCommaExpression()" << endl;
 
3809
    int start = lex->index();
 
3810
 
 
3811
    AST::Node expr;
 
3812
    if( !parseAssignmentExpression(expr) )
 
3813
        return false;
 
3814
 
 
3815
    while( lex->lookAhead(0) == ',' ){
 
3816
        lex->nextToken();
 
3817
 
 
3818
        if( !parseAssignmentExpression(expr) )
 
3819
            return false;
 
3820
    }
 
3821
 
 
3822
    AST::Node ast = CreateNode<AST>();
 
3823
    UPDATE_POS( ast, start, lex->index() );
 
3824
    node = ast;
 
3825
    return true;
 
3826
}
 
3827
 
 
3828
bool Parser::parseThrowExpression( AST::Node& /*node*/ )
 
3829
{
 
3830
    //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseThrowExpression()" << endl;
 
3831
    if( lex->lookAhead(0) != Token_throw )
 
3832
        return false;
 
3833
 
 
3834
    CHECK( Token_throw, "throw" );
 
3835
    AST::Node expr;
 
3836
    if( !parseAssignmentExpression(expr) )
 
3837
        return false;
 
3838
 
 
3839
    return true;
 
3840
}
 
3841
 
 
3842
bool Parser::parseIvarDeclList( AST::Node & node )
 
3843
{
 
3844
    Q_UNUSED( node );
 
3845
    return false;
 
3846
}
 
3847
 
 
3848
bool Parser::parseIvarDecls( AST::Node & node )
 
3849
{
 
3850
    Q_UNUSED( node );
 
3851
    return false;
 
3852
}
 
3853
 
 
3854
bool Parser::parseIvarDecl( AST::Node & node )
 
3855
{
 
3856
    Q_UNUSED( node );
 
3857
    return false;
 
3858
}
 
3859
 
 
3860
bool Parser::parseIvars( AST::Node & node )
 
3861
{
 
3862
    Q_UNUSED( node );
 
3863
    return false;
 
3864
}
 
3865
 
 
3866
bool Parser::parseIvarDeclarator( AST::Node & node )
 
3867
{
 
3868
    Q_UNUSED( node );
 
3869
    return false;
 
3870
}
 
3871
 
 
3872
bool Parser::parseMethodDecl( AST::Node & node )
 
3873
{
 
3874
    Q_UNUSED( node );
 
3875
    return false;
 
3876
}
 
3877
 
 
3878
bool Parser::parseUnarySelector( AST::Node & node )
 
3879
{
 
3880
    Q_UNUSED( node );
 
3881
    return false;
 
3882
}
 
3883
 
 
3884
bool Parser::parseKeywordSelector( AST::Node & node )
 
3885
{
 
3886
    Q_UNUSED( node );
 
3887
    return false;
 
3888
}
 
3889
 
 
3890
bool Parser::parseSelector( AST::Node & node )
 
3891
{
 
3892
    Q_UNUSED( node );
 
3893
    return false;
 
3894
}
 
3895
 
 
3896
bool Parser::parseKeywordDecl( AST::Node & node )
 
3897
{
 
3898
    Q_UNUSED( node );
 
3899
    return false;
 
3900
}
 
3901
 
 
3902
bool Parser::parseReceiver( AST::Node & node )
 
3903
{
 
3904
    Q_UNUSED( node );
 
3905
    return false;
 
3906
}
 
3907
 
 
3908
bool Parser::parseObjcMessageExpr( AST::Node & node )
 
3909
{
 
3910
    Q_UNUSED( node );
 
3911
    return false;
 
3912
}
 
3913
 
 
3914
bool Parser::parseMessageArgs( AST::Node & node )
 
3915
{
 
3916
    Q_UNUSED( node );
 
3917
    return false;
 
3918
}
 
3919
 
 
3920
bool Parser::parseKeywordExpr( AST::Node & node )
 
3921
{
 
3922
    Q_UNUSED( node );
 
3923
    return false;
 
3924
}
 
3925
 
 
3926
bool Parser::parseKeywordArgList( AST::Node & node )
 
3927
{
 
3928
    Q_UNUSED( node );
 
3929
    return false;
 
3930
}
 
3931
 
 
3932
bool Parser::parseKeywordArg( AST::Node & node )
 
3933
{
 
3934
    Q_UNUSED( node );
 
3935
    return false;
 
3936
}
 
3937
 
 
3938
bool Parser::parseReservedWord( AST::Node & node )
 
3939
{
 
3940
    Q_UNUSED( node );
 
3941
    return false;
 
3942
}
 
3943
 
 
3944
bool Parser::parseMyParms( AST::Node & node )
 
3945
{
 
3946
    Q_UNUSED( node );
 
3947
    return false;
 
3948
}
 
3949
 
 
3950
bool Parser::parseMyParm( AST::Node & node )
 
3951
{
 
3952
    Q_UNUSED( node );
 
3953
    return false;
 
3954
}
 
3955
 
 
3956
bool Parser::parseOptParmList( AST::Node & node )
 
3957
{
 
3958
    Q_UNUSED( node );
 
3959
    return false;
 
3960
}
 
3961
 
 
3962
bool Parser::parseObjcSelectorExpr( AST::Node & node )
 
3963
{
 
3964
    Q_UNUSED( node );
 
3965
    return false;
 
3966
}
 
3967
 
 
3968
bool Parser::parseSelectorArg( AST::Node & node )
 
3969
{
 
3970
    Q_UNUSED( node );
 
3971
    return false;
 
3972
}
 
3973
 
 
3974
bool Parser::parseKeywordNameList( AST::Node & node )
 
3975
{
 
3976
    Q_UNUSED( node );
 
3977
    return false;
 
3978
}
 
3979
 
 
3980
bool Parser::parseKeywordName( AST::Node & node )
 
3981
{
 
3982
    Q_UNUSED( node );
 
3983
    return false;
 
3984
}
 
3985
 
 
3986
bool Parser::parseObjcEncodeExpr( AST::Node & node )
 
3987
{
 
3988
    Q_UNUSED( node );
 
3989
    return false;
 
3990
}
 
3991
 
 
3992
bool Parser::parseObjcString( AST::Node & node )
 
3993
{
 
3994
    Q_UNUSED( node );
 
3995
    return false;
 
3996
}
 
3997
 
 
3998
bool Parser::parseProtocolRefs( AST::Node & node )
 
3999
{
 
4000
    Q_UNUSED( node );
 
4001
    return false;
 
4002
}
 
4003
 
 
4004
bool Parser::parseIdentifierList( GroupAST::Node & node )
 
4005
{
 
4006
    int start = lex->index();
 
4007
 
 
4008
    if( lex->lookAhead(0) != Token_identifier )
 
4009
        return false;
 
4010
 
 
4011
    GroupAST::Node ast = CreateNode<GroupAST>();
 
4012
 
 
4013
    AST_FROM_TOKEN( tk, lex->index() );
 
4014
    ast->addNode( tk );
 
4015
    lex->nextToken();
 
4016
 
 
4017
    while( lex->lookAhead(0) == ',' ){
 
4018
        lex->nextToken();
 
4019
        if( lex->lookAhead(0) == Token_identifier ){
 
4020
            AST_FROM_TOKEN( tk, lex->index() );
 
4021
            ast->addNode( tk );
 
4022
            lex->nextToken();
 
4023
        }
 
4024
        ADVANCE( Token_identifier, "identifier" );
 
4025
    }
 
4026
 
 
4027
    node = ast;
 
4028
    UPDATE_POS( node, start, lex->index() );
 
4029
    return true;
 
4030
}
 
4031
 
 
4032
bool Parser::parseIdentifierColon( AST::Node & node )
 
4033
{
 
4034
    Q_UNUSED( node );
 
4035
 
 
4036
    if( lex->lookAhead(0) == Token_identifier && lex->lookAhead(1) == ':' ){
 
4037
        lex->nextToken();
 
4038
        lex->nextToken();
 
4039
        return true;
 
4040
    } // ### else if PTYPENAME -> return true ;
 
4041
 
 
4042
    return false;
 
4043
}
 
4044
 
 
4045
bool Parser::parseObjcProtocolExpr( AST::Node & node )
 
4046
{
 
4047
    Q_UNUSED( node );
 
4048
    return false;
 
4049
}
 
4050
 
 
4051
bool Parser::parseObjcOpenBracketExpr( AST::Node & node )
 
4052
{
 
4053
    Q_UNUSED( node );
 
4054
    return false;
 
4055
}
 
4056
 
 
4057
bool Parser::parseObjcCloseBracket( AST::Node & node )
 
4058
{
 
4059
    Q_UNUSED( node );
 
4060
    return false;
 
4061
}
 
4062
 
 
4063
bool Parser::parseObjcDef( DeclarationAST::Node & node )
 
4064
{
 
4065
    Q_UNUSED( node );
 
4066
    return false;
 
4067
}
 
4068
 
 
4069
bool Parser::parseObjcClassDef( DeclarationAST::Node & node )
 
4070
{
 
4071
    Q_UNUSED( node );
 
4072
    return false;
 
4073
}
 
4074
 
 
4075
bool Parser::parseObjcClassDecl( DeclarationAST::Node & node )
 
4076
{
 
4077
    Q_UNUSED( node );
 
4078
 
 
4079
    ADVANCE( OBJC_CLASS, "@class" );
 
4080
 
 
4081
    GroupAST::Node idList;
 
4082
    parseIdentifierList( idList );
 
4083
    ADVANCE( ';', ";" );
 
4084
 
 
4085
    return true;
 
4086
}
 
4087
 
 
4088
bool Parser::parseObjcProtocolDecl( DeclarationAST::Node & node )
 
4089
{
 
4090
    Q_UNUSED( node );
 
4091
 
 
4092
    ADVANCE( OBJC_PROTOCOL, "@protocol" );
 
4093
 
 
4094
    GroupAST::Node idList;
 
4095
    parseIdentifierList( idList );
 
4096
    ADVANCE( ';', ";" );
 
4097
 
 
4098
    return true;
 
4099
}
 
4100
 
 
4101
bool Parser::parseObjcAliasDecl( DeclarationAST::Node & node )
 
4102
{
 
4103
    Q_UNUSED( node );
 
4104
 
 
4105
    ADVANCE( OBJC_ALIAS, "@alias" );
 
4106
 
 
4107
    GroupAST::Node idList;
 
4108
    parseIdentifierList( idList );
 
4109
    ADVANCE( ';', ";" );
 
4110
 
 
4111
    return true;
 
4112
}
 
4113
 
 
4114
bool Parser::parseObjcProtocolDef( DeclarationAST::Node & node )
 
4115
{
 
4116
    Q_UNUSED( node );
 
4117
    return false;
 
4118
}
 
4119
 
 
4120
bool Parser::parseObjcMethodDef( DeclarationAST::Node & node )
 
4121
{
 
4122
    Q_UNUSED( node );
 
4123
    return false;
 
4124
}
 
4125
 
 
4126
bool Parser::parseWinDeclSpec( GroupAST::Node & node )
 
4127
{
 
4128
    if( lex->lookAhead(0) == Token_identifier && lex->lookAhead(0).text() == "__declspec" && lex->lookAhead(1) == '(' ){
 
4129
        int start = lex->index();
 
4130
        lex->nextToken();
 
4131
        lex->nextToken(); // skip '('
 
4132
 
 
4133
        parseIdentifierList( node );
 
4134
        ADVANCE( ')', ")" );
 
4135
 
 
4136
        UPDATE_POS( node, start, lex->index() );
 
4137
        return true;
 
4138
    }
 
4139
 
 
4140
    return false;
 
4141
}
 
4142