~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: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

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