umbrello API Documentation

parser.cpp

00001 /* This file is part of KDevelop
00002     Copyright (C) 2002,2003 Roberto Raggi <roberto@kdevelop.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017     Boston, MA 02111-1307, USA.
00018 */
00019 
00020 // c++ support
00021 #include "parser.h"
00022 #include "driver.h"
00023 #include "lexer.h"
00024 #include "errors.h"
00025 
00026 // qt
00027 #include <qstring.h>
00028 #include <qstringlist.h>
00029 #include <qasciidict.h>
00030 
00031 #include <kdebug.h>
00032 #include <klocale.h>
00033 
00034 using namespace std;
00035 
00036 #define ADVANCE(tk, descr) \
00037 { \
00038   const Token& token = lex->lookAhead( 0 ); \
00039   if( token != tk ){ \
00040       reportError( i18n("'%1' expected found '%2'").arg(descr).arg(token.text()) ); \
00041       return false; \
00042   } \
00043   lex->nextToken(); \
00044 }
00045 
00046 #define ADVANCE_NR(tk, descr) \
00047 { \
00048   const Token& token = lex->lookAhead( 0 ); \
00049   if( token != tk ){ \
00050       reportError( i18n("'%1' expected found '%2'").arg(descr).arg(token.text()) ); \
00051   } \
00052   else \
00053       lex->nextToken(); \
00054 }
00055 
00056 #define CHECK(tk, descr) \
00057 { \
00058   const Token& token = lex->lookAhead( 0 ); \
00059   if( token != tk ){ \
00060       return false; \
00061   } \
00062   lex->nextToken(); \
00063 }
00064 
00065 #define MATCH(tk, descr) \
00066 { \
00067   const Token& token = lex->lookAhead( 0 ); \
00068   if( token != tk ){ \
00069       reportError( Errors::SyntaxError ); \
00070       return false; \
00071   } \
00072 }
00073 
00074 #define UPDATE_POS(node, start, end) \
00075 { \
00076    int line, col; \
00077    const Token &a = lex->tokenAt(start); \
00078    const Token &b = lex->tokenAt( end!=start ? end-1 : end ); \
00079    a.getStartPosition( &line, &col ); \
00080    (node)->setStartPosition( line, col ); \
00081    b.getEndPosition( &line, &col ); \
00082    (node)->setEndPosition( line, col ); \
00083    if( (node)->nodeType() == NodeType_Generic ) { \
00084        if ((start) == (end) || (end) == (start)+1) \
00085            (node)->setSlice(lex->source(), a.position(), a.length()); \
00086        else \
00087            (node)->setText( toString((start),(end)) ); \
00088    } \
00089 }
00090 
00091 #define AST_FROM_TOKEN(node, tk) \
00092     AST::Node node = CreateNode<AST>(); \
00093     UPDATE_POS( node, (tk), (tk)+1 );
00094 
00095 
00096 //@todo remove me
00097 enum
00098 {
00099     OBJC_CLASS,
00100     OBJC_PROTOCOL,
00101     OBJC_ALIAS
00102 };
00103 
00104 struct ParserPrivateData
00105 {
00106     ParserPrivateData()
00107         {}
00108 };
00109 
00110 Parser::Parser( Driver* driver, Lexer* lexer )
00111     : m_driver( driver ),
00112       lex( lexer )
00113 {
00114     d = new ParserPrivateData();
00115 
00116     m_maxProblems = 5;
00117     objcp = false;
00118 }
00119 
00120 Parser::~Parser()
00121 {
00122     delete d;
00123     d = 0;
00124 }
00125 
00126 bool Parser::reportError( const Error& err )
00127 {
00128     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::reportError()" << endl;
00129     if( m_problems < m_maxProblems ){
00130     ++m_problems;
00131     int line=0, col=0;
00132     const Token& token = lex->lookAhead( 0 );
00133     lex->getTokenPosition( token, &line, &col );
00134 
00135     QString s = lex->lookAhead(0).text();
00136     s = s.left( 30 ).stripWhiteSpace();
00137     if( s.isEmpty() )
00138         s = i18n( "<eof>" );
00139 
00140     m_driver->addProblem( m_driver->currentFileName(), Problem(err.text.arg(s), line, col) );
00141     }
00142 
00143     return true;
00144 }
00145 
00146 bool Parser::reportError( const QString& msg )
00147 {
00148     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::reportError()" << endl;
00149     if( m_problems < m_maxProblems ){
00150     ++m_problems;
00151     int line=0, col=0;
00152     const Token& token = lex->lookAhead( 0 );
00153     lex->getTokenPosition( token, &line, &col );
00154 
00155     m_driver->addProblem( m_driver->currentFileName(), Problem(msg, line, col) );
00156     }
00157 
00158     return true;
00159 }
00160 
00161 void Parser::syntaxError()
00162 {
00163     (void) reportError( Errors::SyntaxError );
00164 }
00165 
00166 bool Parser::skipUntil( int token )
00167 {
00168     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipUntil()" << endl;
00169     while( !lex->lookAhead(0).isNull() ){
00170     if( lex->lookAhead(0) == token )
00171         return true;
00172 
00173     lex->nextToken();
00174     }
00175 
00176     return false;
00177 }
00178 
00179 bool Parser::skipUntilDeclaration()
00180 {
00181     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipUntilDeclaration()" << endl;
00182 
00183     while( !lex->lookAhead(0).isNull() ){
00184 
00185     switch( lex->lookAhead(0) ){
00186     case ';':
00187     case '~':
00188     case Token_scope:
00189     case Token_identifier:
00190     case Token_operator:
00191     case Token_char:
00192     case Token_wchar_t:
00193     case Token_bool:
00194     case Token_short:
00195     case Token_int:
00196     case Token_long:
00197     case Token_signed:
00198     case Token_unsigned:
00199     case Token_float:
00200     case Token_double:
00201     case Token_void:
00202     case Token_extern:
00203     case Token_namespace:
00204     case Token_using:
00205     case Token_typedef:
00206     case Token_asm:
00207     case Token_template:
00208     case Token_export:
00209 
00210     case Token_const:       // cv
00211     case Token_volatile:    // cv
00212 
00213     case Token_public:
00214     case Token_protected:
00215     case Token_private:
00216     case Token_signals:      // Qt
00217     case Token_slots:        // Qt
00218         return true;
00219 
00220     case '}':
00221         return false;
00222 
00223     default:
00224         lex->nextToken();
00225     }
00226     }
00227 
00228     return false;
00229 }
00230 
00231 bool Parser::skipUntilStatement()
00232 {
00233     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipUntilStatement() -- token = " << lex->lookAhead(0).text() << endl;
00234 
00235     while( !lex->lookAhead(0).isNull() ){
00236     switch( lex->lookAhead(0) ){
00237         case ';':
00238         case '{':
00239         case '}':
00240         case Token_const:
00241         case Token_volatile:
00242         case Token_identifier:
00243         case Token_case:
00244         case Token_default:
00245         case Token_if:
00246         case Token_switch:
00247         case Token_while:
00248         case Token_do:
00249         case Token_for:
00250         case Token_break:
00251         case Token_continue:
00252         case Token_return:
00253         case Token_goto:
00254         case Token_try:
00255         case Token_catch:
00256         case Token_throw:
00257         case Token_char:
00258         case Token_wchar_t:
00259         case Token_bool:
00260         case Token_short:
00261         case Token_int:
00262         case Token_long:
00263         case Token_signed:
00264         case Token_unsigned:
00265         case Token_float:
00266         case Token_double:
00267         case Token_void:
00268         case Token_class:
00269         case Token_struct:
00270         case Token_union:
00271         case Token_enum:
00272         case Token_scope:
00273         case Token_template:
00274         case Token_using:
00275             return true;
00276 
00277         default:
00278             lex->nextToken();
00279     }
00280     }
00281 
00282     return false;
00283 }
00284 
00285 bool Parser::skip( int l, int r )
00286 {
00287     int count = 0;
00288     while( !lex->lookAhead(0).isNull() ){
00289     int tk = lex->lookAhead( 0 );
00290 
00291     if( tk == l )
00292         ++count;
00293     else if( tk == r )
00294         --count;
00295     else if( l != '{' && (tk == '{' || tk == '}' || tk == ';') )
00296         return false;
00297 
00298     if( count == 0 )
00299         return true;
00300 
00301     lex->nextToken();
00302     }
00303 
00304     return false;
00305 }
00306 
00307 bool Parser::skipCommaExpression( AST::Node& node )
00308 {
00309     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipCommaExpression()" << endl;
00310 
00311     int start = lex->index();
00312 
00313     AST::Node expr;
00314     if( !skipExpression(expr) )
00315     return false;
00316 
00317     QString comment;
00318     while( lex->lookAhead(0) == ',' ){
00319     comment = QString::null;
00320     advanceAndCheckTrailingComment( comment );
00321 
00322     if( !skipExpression(expr) ){
00323         reportError( i18n("expression expected") );
00324         return false;
00325     }
00326     }
00327 
00328     AST::Node ast = CreateNode<AST>();
00329     UPDATE_POS( ast, start, lex->index() );
00330     node = ast;
00331 
00332     return true;
00333 }
00334 
00335 bool Parser::skipExpression( AST::Node& node )
00336 {
00337     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipExpression()" << endl;
00338 
00339     int start = lex->index();
00340 
00341     while( !lex->lookAhead(0).isNull() ){
00342     int tk = lex->lookAhead( 0 );
00343 
00344     switch( tk ){
00345     case '(':
00346         skip( '(', ')' );
00347         lex->nextToken();
00348         break;
00349 
00350     case '[':
00351         skip( '[', ']' );
00352         lex->nextToken();
00353         break;
00354 
00355 #if 0
00356     case Token_identifier:
00357         lex->nextToken();
00358         if( lex->lookAhead( 0 ) == Token_identifier )
00359         return true;
00360         break;
00361 #endif
00362 
00363     case ';':
00364     case ',':
00365     case ']':
00366     case ')':
00367     case '{':
00368     case '}':
00369     case Token_case:
00370     case Token_default:
00371     case Token_if:
00372     case Token_while:
00373     case Token_do:
00374     case Token_for:
00375     case Token_break:
00376     case Token_continue:
00377     case Token_return:
00378     case Token_goto:
00379     {
00380         AST::Node ast = CreateNode<AST>();
00381         UPDATE_POS( ast, start, lex->index() );
00382         node = ast;
00383     }
00384     return true;
00385 
00386     default:
00387         lex->nextToken();
00388     }
00389     }
00390 
00391     return false;
00392 }
00393 
00394 bool Parser::parseName( NameAST::Node& node )
00395 {
00396     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseName()" << endl;
00397 
00398     GroupAST::Node winDeclSpec;
00399     parseWinDeclSpec( winDeclSpec );
00400 
00401     int start = lex->index();
00402 
00403     NameAST::Node ast = CreateNode<NameAST>();
00404 
00405     if( lex->lookAhead(0) == Token_scope ){
00406         ast->setGlobal( true );
00407     lex->nextToken();
00408     }
00409 
00410     int idx = lex->index();
00411 
00412     while( true ){
00413         ClassOrNamespaceNameAST::Node n;
00414         if( !parseUnqualifiedName(n) ) {
00415         return false;
00416     }
00417 
00418     if( lex->lookAhead(0) == Token_scope ){
00419         lex->nextToken();
00420         ast->addClassOrNamespaceName( n );
00421         if( lex->lookAhead(0) == Token_template )
00422             lex->nextToken(); 
00423     } else {
00424         ast->setUnqualifiedName( n );
00425         break;
00426     }
00427     }
00428 
00429     if( idx == lex->index() )
00430         return false;
00431 
00432     UPDATE_POS( ast, start, lex->index() );
00433     node = ast;
00434 
00435     return true;
00436 }
00437 
00438 bool Parser::parseTranslationUnit( TranslationUnitAST::Node& node )
00439 {
00440     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTranslationUnit()" << endl;
00441 
00442     int start = lex->index();
00443 
00444     m_problems = 0;
00445     TranslationUnitAST::Node tun = CreateNode<TranslationUnitAST>();
00446     node = tun;
00447     while( !lex->lookAhead(0).isNull() ){
00448         DeclarationAST::Node def;
00449     int startDecl = lex->index();
00450         if( !parseDeclaration(def) ){
00451         // error recovery
00452         if( startDecl == lex->index() )
00453             lex->nextToken(); // skip at least one token
00454         skipUntilDeclaration();
00455     }
00456     node->addDeclaration( def );
00457     }
00458 
00459     UPDATE_POS( node, start, lex->index() );
00460 
00461     // force (0,0) as start position
00462     node->setStartPosition( 0, 0 );
00463 
00464     return m_problems == 0;
00465 }
00466 
00467 bool Parser::parseDeclaration( DeclarationAST::Node& node )
00468 {
00469     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclaration()" << endl;
00470 
00471     QString comment;
00472     while( lex->lookAhead(0) == Token_comment ) {
00473     comment += lex->lookAhead(0).text();
00474     lex->nextToken();
00475     }
00476     if( lex->lookAhead(0).isNull() )
00477     return false;
00478 
00479     int start = lex->index();
00480     bool success = false;
00481 
00482     switch( lex->lookAhead(0) ){
00483 
00484     case ';':
00485     lex->nextToken();
00486     return true;
00487 
00488     case Token_extern:
00489     success = parseLinkageSpecification( node );
00490     break;
00491 
00492     case Token_namespace:
00493     success = parseNamespace( node );
00494     break;
00495 
00496     case Token_using:
00497     success = parseUsing( node );
00498     break;
00499 
00500     case Token_typedef:
00501     success = parseTypedef( node );
00502     break;
00503 
00504     case Token_asm:
00505     success = parseAsmDefinition( node );
00506     break;
00507 
00508     case Token_template:
00509     case Token_export:
00510     success = parseTemplateDeclaration( node );
00511     break;
00512 
00513     default:
00514         {
00515         // lex->setIndex( start );
00516 
00517         if( objcp && parseObjcDef(node) )
00518         return true;
00519 
00520         lex->setIndex( start );
00521 
00522         GroupAST::Node storageSpec;
00523         parseStorageClassSpecifier( storageSpec );
00524 
00525         GroupAST::Node cv;
00526         parseCvQualify( cv );
00527 
00528         TypeSpecifierAST::Node spec;
00529         AST::Node declarator;
00530         if( parseEnumSpecifier(spec) || parseClassSpecifier(spec) ){
00531             spec->setCvQualify( cv );
00532 
00533             GroupAST::Node cv2;
00534             parseCvQualify( cv2 );
00535         spec->setCv2Qualify( cv2 );
00536 
00537         InitDeclaratorListAST::Node declarators;
00538         parseInitDeclaratorList(declarators);
00539             ADVANCE( ';', ";" );
00540 
00541         if( !comment.isEmpty() ) {
00542             //kdDebug(9007) << "Parser::parseDeclaration(spec): comment is " << comment << endl;
00543             spec->setComment( comment );
00544         }
00545 
00546         SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
00547         ast->setStorageSpecifier( storageSpec );
00548         ast->setTypeSpec( spec );
00549         ast->setInitDeclaratorList( declarators );
00550         UPDATE_POS( ast, start, lex->index() );
00551         node = ast;
00552 
00553             return true;
00554         }
00555 
00556         lex->setIndex( start );
00557         success = parseDeclarationInternal( node, comment );
00558     }
00559 
00560     } // end switch
00561 
00562     if( success && !comment.isEmpty() ) {
00563         //kdDebug(9007) << "Parser::parseDeclaration(): comment is " << comment << endl;
00564     node->setComment( comment );
00565     }
00566     return success;
00567 }
00568 
00569 bool Parser::parseLinkageSpecification( DeclarationAST::Node& node )
00570 {
00571     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseLinkageSpecification()" << endl;
00572 
00573     int start = lex->index();
00574 
00575     if( lex->lookAhead(0) != Token_extern ){
00576     return false;
00577     }
00578     lex->nextToken();
00579 
00580     LinkageSpecificationAST::Node ast = CreateNode<LinkageSpecificationAST>();
00581 
00582     int startExternType = lex->index();
00583     if( lex->lookAhead(0) == Token_string_literal ){
00584     lex->nextToken();
00585         AST::Node externType = CreateNode<AST>();
00586         UPDATE_POS( externType, startExternType, lex->index() );
00587 
00588         ast->setExternType( externType );
00589     }
00590 
00591     if( lex->lookAhead(0) == '{' ){
00592         LinkageBodyAST::Node linkageBody;
00593     parseLinkageBody( linkageBody );
00594     ast->setLinkageBody( linkageBody );
00595     } else {
00596         DeclarationAST::Node decl;
00597     if( !parseDeclaration(decl) ){
00598         reportError( i18n("Declaration syntax error") );
00599     }
00600     ast->setDeclaration( decl );
00601     }
00602 
00603     UPDATE_POS( ast, start, lex->index() );
00604 
00605     node = ast;
00606 
00607     return true;
00608 }
00609 
00610 bool Parser::parseLinkageBody( LinkageBodyAST::Node& node )
00611 {
00612     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseLinkageBody()" << endl;
00613 
00614     int start = lex->index();
00615 
00616     if( lex->lookAhead(0) != '{' ){
00617     return false;
00618     }
00619     lex->nextToken();
00620 
00621     LinkageBodyAST::Node lba = CreateNode<LinkageBodyAST>();
00622     node = lba;
00623 
00624     while( !lex->lookAhead(0).isNull() ){
00625     int tk = lex->lookAhead( 0 );
00626 
00627     if( tk == '}' )
00628         break;
00629 
00630     DeclarationAST::Node def;
00631     int startDecl = lex->index();
00632     if( parseDeclaration(def) ){
00633         node->addDeclaration( def );
00634     } else {
00635         // error recovery
00636         if( startDecl == lex->index() )
00637             lex->nextToken(); // skip at least one token
00638         skipUntilDeclaration();
00639     }
00640     }
00641 
00642     if( lex->lookAhead(0) != '}' ){
00643     reportError( i18n("} expected") );
00644     } else
00645     lex->nextToken();
00646 
00647     UPDATE_POS( node, start, lex->index() );
00648     return true;
00649 }
00650 
00651 bool Parser::parseNamespace( DeclarationAST::Node& node )
00652 {
00653     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseNamespace()" << endl;
00654 
00655     int start = lex->index();
00656 
00657     if( lex->lookAhead(0) != Token_namespace ){
00658     return false;
00659     }
00660     lex->nextToken();
00661 
00662     int startNamespaceName = lex->index();
00663     if( lex->lookAhead(0) == Token_identifier ){
00664     lex->nextToken();
00665     }
00666     AST::Node namespaceName = CreateNode<AST>();
00667     UPDATE_POS( namespaceName, startNamespaceName, lex->index() );
00668 
00669     if ( lex->lookAhead(0) == '=' ) {
00670     // namespace alias
00671     lex->nextToken();
00672 
00673     NameAST::Node name;
00674     if( parseName(name) ){
00675         ADVANCE( ';', ";" );
00676 
00677         NamespaceAliasAST::Node ast = CreateNode<NamespaceAliasAST>();
00678         ast->setNamespaceName( namespaceName );
00679         ast->setAliasName( name );
00680         UPDATE_POS( ast, start, lex->index() );
00681         node = ast;
00682         return true;
00683     } else {
00684         reportError( i18n("namespace expected") );
00685         return false;
00686     }
00687     } else if( lex->lookAhead(0) != '{' ){
00688     reportError( i18n("{ expected") );
00689     return false;
00690     }
00691 
00692     NamespaceAST::Node ast = CreateNode<NamespaceAST>();
00693     ast->setNamespaceName( namespaceName );
00694 
00695     LinkageBodyAST::Node linkageBody;
00696     parseLinkageBody( linkageBody );
00697 
00698     ast->setLinkageBody( linkageBody );
00699     UPDATE_POS( ast, start, lex->index() );
00700     node = ast;
00701 
00702     return true;
00703 }
00704 
00705 bool Parser::parseUsing( DeclarationAST::Node& node )
00706 {
00707     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseUsing()" << endl;
00708 
00709     int start = lex->index();
00710 
00711     if( lex->lookAhead(0) != Token_using ){
00712     return false;
00713     }
00714     lex->nextToken();
00715 
00716     if( lex->lookAhead(0) == Token_namespace ){
00717     if( !parseUsingDirective(node) ){
00718         return false;
00719     }
00720     UPDATE_POS( node, start, lex->index() );
00721     return true;
00722     }
00723 
00724     UsingAST::Node ast = CreateNode<UsingAST>();
00725 
00726     int startTypeName = lex->index();
00727     if( lex->lookAhead(0) == Token_typename ){
00728     lex->nextToken();
00729     AST::Node tn = CreateNode<AST>();
00730     UPDATE_POS( tn, startTypeName, lex->index() );
00731     ast->setTypeName( tn );
00732     }
00733 
00734     NameAST::Node name;
00735     if( !parseName(name) )
00736     return false;
00737 
00738     ast->setName( name );
00739 
00740     ADVANCE( ';', ";" );
00741 
00742     UPDATE_POS( ast, start, lex->index() );
00743     node = ast;
00744 
00745     return true;
00746 }
00747 
00748 bool Parser::parseUsingDirective( DeclarationAST::Node& node )
00749 {
00750     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseUsingDirective()" << endl;
00751 
00752     int start = lex->index();
00753 
00754     if( lex->lookAhead(0) != Token_namespace ){
00755     return false;
00756     }
00757     lex->nextToken();
00758 
00759     NameAST::Node name;
00760     if( !parseName(name) ){
00761     reportError( i18n("Namespace name expected") );
00762     return false;
00763     }
00764 
00765     ADVANCE( ';', ";" );
00766 
00767     UsingDirectiveAST::Node ast = CreateNode<UsingDirectiveAST>();
00768     ast->setName( name );
00769     UPDATE_POS( ast, start, lex->index() );
00770     node = ast;
00771 
00772     return true;
00773 }
00774 
00775 
00776 bool Parser::parseOperatorFunctionId( AST::Node& node )
00777 {
00778     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseOperatorFunctionId()" << endl;
00779 
00780     int start = lex->index();
00781 
00782     if( lex->lookAhead(0) != Token_operator ){
00783     return false;
00784     }
00785     lex->nextToken();
00786 
00787     AST::Node op;
00788     if( parseOperator(op) ){
00789     AST::Node asn = CreateNode<AST>();
00790     node = asn;
00791     UPDATE_POS( node, start, lex->index() );
00792     return true;
00793     } else {
00794     // parse cast operator
00795     GroupAST::Node cv;
00796         parseCvQualify(cv);
00797 
00798     TypeSpecifierAST::Node spec;
00799     if( !parseSimpleTypeSpecifier(spec) ){
00800         syntaxError();
00801         return false;
00802     }
00803         spec->setCvQualify( cv );
00804 
00805     GroupAST::Node cv2;
00806     parseCvQualify(cv2);
00807         spec->setCv2Qualify( cv2 );
00808 
00809     AST::Node ptrOp;
00810     while( parsePtrOperator(ptrOp) )
00811         ;
00812 
00813     AST::Node asn = CreateNode<AST>();
00814     node = asn;
00815     UPDATE_POS( node, start, lex->index() );
00816     return true;
00817     }
00818 }
00819 
00820 bool Parser::parseTemplateArgumentList( TemplateArgumentListAST::Node& node, bool reportError )
00821 {
00822     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTemplateArgumentList()" << endl;
00823 
00824     int start = lex->index();
00825 
00826     TemplateArgumentListAST::Node ast = CreateNode<TemplateArgumentListAST>();
00827 
00828     AST::Node templArg;
00829     if( !parseTemplateArgument(templArg) )
00830     return false;
00831     ast->addArgument( templArg );
00832 
00833     QString comment;
00834     while( lex->lookAhead(0) == ',' ){
00835     comment = QString::null;
00836     advanceAndCheckTrailingComment( comment );
00837 
00838     if( !parseTemplateArgument(templArg) ){
00839         if( reportError ){
00840            syntaxError();
00841            break;
00842         } else
00843            return false;
00844     }
00845     if (!comment.isEmpty())
00846         templArg->setComment(comment);
00847     ast->addArgument( templArg );
00848     }
00849 
00850     UPDATE_POS( ast, start, lex->index() );
00851     node = ast;
00852 
00853     return true;
00854 }
00855 
00856 bool Parser::parseTypedef( DeclarationAST::Node& node )
00857 {
00858     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTypedef()" << endl;
00859 
00860     int start = lex->index();
00861 
00862     if( lex->lookAhead(0) != Token_typedef ){
00863     return false;
00864     }
00865     lex->nextToken();
00866 
00867     TypeSpecifierAST::Node spec;
00868     if( !parseTypeSpecifierOrClassSpec(spec) ){
00869     reportError( i18n("Need a type specifier to declare") );
00870     return false;
00871     }
00872 
00873     InitDeclaratorListAST::Node declarators;
00874     if( !parseInitDeclaratorList(declarators) ){
00875     //reportError( i18n("Need an identifier to declare") );
00876     //return false;
00877     }
00878 
00879     ADVANCE( ';', ";" );
00880 
00881     TypedefAST::Node ast = CreateNode<TypedefAST>();
00882     ast->setTypeSpec( spec );
00883     ast->setInitDeclaratorList( declarators );
00884     UPDATE_POS( ast, start, lex->index() );
00885     node = ast;
00886 
00887     return true;
00888 }
00889 
00890 bool Parser::parseAsmDefinition( DeclarationAST::Node& /*node*/ )
00891 {
00892     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseAsmDefinition()" << endl;
00893 
00894     ADVANCE( Token_asm, "asm" );
00895 
00896     GroupAST::Node cv;
00897     parseCvQualify( cv );
00898 
00899     skip( '(', ')' );
00900     ADVANCE( ')', ")" );
00901     ADVANCE( ';', ';' );
00902 
00903     return true;
00904 }
00905 
00906 bool Parser::parseTemplateDeclaration( DeclarationAST::Node& node )
00907 {
00908     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTemplateDeclaration()" << endl;
00909 
00910     int start = lex->index();
00911 
00912     AST::Node exp;
00913 
00914     int startExport = lex->index();
00915     if( lex->lookAhead(0) == Token_export ){
00916     lex->nextToken();
00917     AST::Node n = CreateNode<AST>();
00918     UPDATE_POS( n, startExport, lex->index() );
00919     exp = n;
00920     }
00921 
00922     if( lex->lookAhead(0) != Token_template ){
00923     return false;
00924     }
00925     lex->nextToken();
00926 
00927     TemplateParameterListAST::Node params;
00928     if( lex->lookAhead(0) == '<' ){
00929     lex->nextToken();
00930     if (lex->lookAhead(0) != '>')
00931         parseTemplateParameterList( params );
00932 
00933     ADVANCE( '>', ">" );
00934     }
00935 
00936     DeclarationAST::Node def;
00937     if( !parseDeclaration(def) ){
00938     reportError( i18n("expected a declaration") );
00939     }
00940 
00941     TemplateDeclarationAST::Node ast = CreateNode<TemplateDeclarationAST>();
00942     ast->setExported( exp );
00943     ast->setTemplateParameterList( params );
00944     ast->setDeclaration( def );
00945     UPDATE_POS( ast, start, lex->index() );
00946     node = ast;
00947 
00948     return true;
00949 }
00950 
00951 bool Parser::parseOperator( AST::Node& /*node*/ )
00952 {
00953     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseOperator()" << endl;
00954     QString text = lex->lookAhead(0).text();
00955 
00956     switch( lex->lookAhead(0) ){
00957     case Token_new:
00958     case Token_delete:
00959     lex->nextToken();
00960     if( lex->lookAhead(0) == '[' && lex->lookAhead(1) == ']' ){
00961         lex->nextToken();
00962         lex->nextToken();
00963         text += "[]";
00964     }
00965     return true;
00966 
00967     case '+':
00968     case '-':
00969     case '*':
00970     case '/':
00971     case '%':
00972     case '^':
00973     case '&':
00974     case '|':
00975     case '~':
00976     case '!':
00977     case '=':
00978     case '<':
00979     case '>':
00980     case ',':
00981     case Token_assign:
00982     case Token_shift:
00983     case Token_eq:
00984     case Token_not_eq:
00985     case Token_leq:
00986     case Token_geq:
00987     case Token_and:
00988     case Token_or:
00989     case Token_incr:
00990     case Token_decr:
00991     case Token_ptrmem:
00992     case Token_arrow:
00993     lex->nextToken();
00994     return true;
00995 
00996     default:
00997     if( lex->lookAhead(0) == '(' && lex->lookAhead(1) == ')' ){
00998         lex->nextToken();
00999         lex->nextToken();
01000         return true;
01001     } else if( lex->lookAhead(0) == '[' && lex->lookAhead(1) == ']' ){
01002         lex->nextToken();
01003         lex->nextToken();
01004         return true;
01005     }
01006     }
01007 
01008     return false;
01009 }
01010 
01011 bool Parser::parseCvQualify( GroupAST::Node& node )
01012 {
01013     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCvQualify()" << endl;
01014 
01015     int start = lex->index();
01016 
01017     GroupAST::Node ast = CreateNode<GroupAST>();
01018 
01019     int n = 0;
01020     while( !lex->lookAhead(0).isNull() ){
01021     int tk = lex->lookAhead( 0 );
01022     if( tk == Token_const || tk == Token_volatile ){
01023         ++n;
01024         int startWord = lex->index();
01025         lex->nextToken();
01026             AST::Node word = CreateNode<AST>();
01027             UPDATE_POS( word, startWord, lex->index() );
01028         ast->addNode( word );
01029     } else
01030         break;
01031     }
01032 
01033     if( n == 0 )
01034         return false;
01035 
01036 
01037     //kdDebug(9007)<< "-----------------> token = " << lex->lookAhead(0).text() << endl;
01038     UPDATE_POS( ast, start, lex->index() );
01039 
01040     node = ast;
01041     return true;
01042 }
01043 
01044 bool Parser::parseSimpleTypeSpecifier( TypeSpecifierAST::Node& node )
01045 {
01046     int start = lex->index();
01047     bool isIntegral = false;
01048     bool done = false;
01049 
01050     while( !done ){
01051 
01052         switch( lex->lookAhead(0) ){
01053         case Token_char:
01054         case Token_wchar_t:
01055         case Token_bool:
01056         case Token_short:
01057         case Token_int:
01058         case Token_long:
01059         case Token_signed:
01060         case Token_unsigned:
01061         case Token_float:
01062         case Token_double:
01063         case Token_void:
01064             isIntegral = true;
01065             lex->nextToken();
01066             break;
01067 
01068         default:
01069             done = true;
01070     }
01071     }
01072 
01073     TypeSpecifierAST::Node ast = CreateNode<TypeSpecifierAST>();
01074     if( isIntegral ){
01075         ClassOrNamespaceNameAST::Node cl = CreateNode<ClassOrNamespaceNameAST>();
01076 
01077     AST::Node n = CreateNode<AST>();
01078     UPDATE_POS( n, start, lex->index() );
01079     cl->setName( n );
01080     UPDATE_POS( cl, start, lex->index() );
01081 
01082         NameAST::Node name = CreateNode<NameAST>();
01083     name->setUnqualifiedName( cl );
01084     UPDATE_POS( name, start, lex->index() );
01085     ast->setName( name );
01086 
01087     } else {
01088         NameAST::Node name;
01089         if( !parseName(name) ){
01090             lex->setIndex( start );
01091         return false;
01092         }
01093     ast->setName( name );
01094     }
01095 
01096     UPDATE_POS( ast, start, lex->index() );
01097     node = ast;
01098     return true;
01099 }
01100 
01101 bool Parser::parsePtrOperator( AST::Node& node )
01102 {
01103     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parsePtrOperator()" << endl;
01104 
01105     int start = lex->index();
01106 
01107     if( lex->lookAhead(0) == '&' ){
01108     lex->nextToken();
01109     } else if( lex->lookAhead(0) == '*' ){
01110     lex->nextToken();
01111     } else {
01112     int index = lex->index();
01113     AST::Node memPtr;
01114     if( !parsePtrToMember(memPtr) ){
01115         lex->setIndex( index );
01116         return false;
01117     }
01118     }
01119 
01120     GroupAST::Node cv;
01121     parseCvQualify( cv );
01122 
01123     AST::Node ast = CreateNode<AST>();
01124     UPDATE_POS( ast, start, lex->index() );
01125     node = ast;
01126 
01127     return true;
01128 }
01129 
01130 
01131 bool Parser::parseTemplateArgument( AST::Node& node )
01132 {
01133     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTemplateArgument()" << endl;
01134 
01135     int start = lex->index();
01136     if( parseTypeId(node) ){
01137         if( lex->lookAhead(0) == ',' || lex->lookAhead(0) == '>' )
01138         return true;
01139     }
01140 
01141     lex->setIndex( start );
01142     if( !parseLogicalOrExpression(node, true) ){
01143         return false;
01144     }
01145 
01146     return true;
01147 }
01148 
01149 bool Parser::parseTypeSpecifier( TypeSpecifierAST::Node& spec )
01150 {
01151     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTypeSpecifier()" << endl;
01152 
01153     GroupAST::Node cv;
01154     parseCvQualify( cv );
01155 
01156     if( parseElaboratedTypeSpecifier(spec) || parseSimpleTypeSpecifier(spec) ){
01157         spec->setCvQualify( cv );
01158 
01159         GroupAST::Node cv2;
01160     parseCvQualify( cv2 );
01161         spec->setCv2Qualify( cv2 );
01162 
01163     return true;
01164     }
01165 
01166     return false;
01167 }
01168 
01169 bool Parser::parseDeclarator( DeclaratorAST::Node& node )
01170 {
01171     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclarator()" << endl;
01172 
01173     int start = lex->index();
01174 
01175     DeclaratorAST::Node ast = CreateNode<DeclaratorAST>();
01176 
01177     DeclaratorAST::Node decl;
01178     NameAST::Node declId;
01179 
01180     AST::Node ptrOp;
01181     while( parsePtrOperator(ptrOp) ){
01182     ast->addPtrOp( ptrOp );
01183     }
01184 
01185     if( lex->lookAhead(0) == '(' ){
01186     lex->nextToken();
01187 
01188     if( !parseDeclarator(decl) ){
01189         return false;
01190     }
01191     ast->setSubDeclarator( decl );
01192 
01193     if( lex->lookAhead(0) != ')'){
01194         return false;
01195     }
01196     lex->nextToken();
01197     } else {
01198 
01199         if( lex->lookAhead(0) == ':' ){
01200              // unnamed bitfield
01201         } else if( parseDeclaratorId(declId) ){
01202         ast->setDeclaratorId( declId );
01203     } else {
01204         lex->setIndex( start );
01205         return false;
01206     }
01207 
01208     if( lex->lookAhead(0) == ':' ){
01209         lex->nextToken();
01210         AST::Node expr;
01211         if( !parseConstantExpression(expr) ){
01212         reportError( i18n("Constant expression expected") );
01213         }
01214         goto update_pos;
01215     }
01216     }
01217 
01218     {
01219     bool isVector = true;
01220 
01221     while( lex->lookAhead(0) == '[' ){
01222         int startArray = lex->index();
01223         lex->nextToken();
01224         AST::Node expr;
01225         parseCommaExpression( expr );
01226 
01227         ADVANCE( ']', "]" );
01228         AST::Node array = CreateNode<AST>();
01229         UPDATE_POS( array, startArray, lex->index() );
01230         ast->addArrayDimension( array );
01231         isVector = true;
01232     }
01233 
01234     bool skipParen = false;
01235     if( lex->lookAhead(0) == Token_identifier && lex->lookAhead(1) == '(' && lex->lookAhead(2) == '(' ){
01236         lex->nextToken();
01237         lex->nextToken();
01238         skipParen = true;
01239     }
01240 
01241     if( ast->subDeclarator() && (!isVector || lex->lookAhead(0) != '(') ){
01242         lex->setIndex( start );
01243         return false;
01244     }
01245 
01246     int index = lex->index();
01247     if( lex->lookAhead(0) == '(' ){
01248         lex->nextToken();
01249 
01250         ParameterDeclarationClauseAST::Node params;
01251         if( !parseParameterDeclarationClause(params) ){
01252         //kdDebug(9007)<< "----------------------> not a parameter declaration, maybe an initializer!?" << endl;
01253         lex->setIndex( index );
01254         goto update_pos;
01255         }
01256         ast->setParameterDeclarationClause( params );
01257 
01258         if( lex->lookAhead(0) != ')' ){
01259         lex->setIndex( index );
01260         goto update_pos;
01261         }
01262 
01263         lex->nextToken();  // skip ')'
01264 
01265         int startConstant = lex->index();
01266         if( lex->lookAhead(0) == Token_const ){
01267         lex->nextToken();
01268         AST::Node constant = CreateNode<AST>();
01269         UPDATE_POS( constant, startConstant, lex->index() );
01270         ast->setConstant( constant );
01271         }
01272 
01273         GroupAST::Node except;
01274         if( parseExceptionSpecification(except) ){
01275         ast->setExceptionSpecification( except );
01276         }
01277     }
01278 
01279     if( skipParen ){
01280         if( lex->lookAhead(0) != ')' ){
01281         reportError( i18n("')' expected") );
01282         } else
01283         lex->nextToken();
01284     }
01285 
01286     }
01287 
01288 update_pos:
01289     UPDATE_POS( ast, start, lex->index() );
01290     node = ast;
01291 
01292     return true;
01293 }
01294 
01295 bool Parser::parseAbstractDeclarator( DeclaratorAST::Node& node )
01296 {
01297     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclarator()" << endl;
01298     int start = lex->index();
01299 
01300     DeclaratorAST::Node ast = CreateNode<DeclaratorAST>();
01301 
01302     DeclaratorAST::Node decl;
01303     NameAST::Node declId;
01304 
01305     AST::Node ptrOp;
01306     while( parsePtrOperator(ptrOp) ){
01307     ast->addPtrOp( ptrOp );
01308     }
01309 
01310     if( lex->lookAhead(0) == '(' ){
01311     lex->nextToken();
01312 
01313     if( !parseAbstractDeclarator(decl) ){
01314         return false;
01315     }
01316     ast->setSubDeclarator( decl );
01317 
01318     if( lex->lookAhead(0) != ')'){
01319         return false;
01320     }
01321     lex->nextToken();
01322     }
01323 
01324     {
01325 
01326     while( lex->lookAhead(0) == '[' ){
01327         int startArray = lex->index();
01328     lex->nextToken();
01329     AST::Node expr;
01330     skipCommaExpression( expr );
01331 
01332     ADVANCE( ']', "]" );
01333     AST::Node array = CreateNode<AST>();
01334     UPDATE_POS( array, startArray, lex->index() );
01335     ast->addArrayDimension( array );
01336     }
01337 
01338     bool skipParen = false;
01339     if( lex->lookAhead(0) == Token_identifier && lex->lookAhead(1) == '(' && lex->lookAhead(2) == '(' ){
01340     lex->nextToken();
01341     lex->nextToken();
01342     skipParen = true;
01343     }
01344 
01345     int index = lex->index();
01346     if( lex->lookAhead(0) == '(' ){
01347     lex->nextToken();
01348 
01349     ParameterDeclarationClauseAST::Node params;
01350     if( !parseParameterDeclarationClause(params) ){
01351         lex->setIndex( index );
01352         goto UPDATE_POS;
01353     }
01354     ast->setParameterDeclarationClause( params );
01355 
01356     if( lex->lookAhead(0) != ')' ){
01357         lex->setIndex( index );
01358         goto UPDATE_POS;
01359     } else
01360         lex->nextToken();
01361 
01362     int startConstant = lex->index();
01363     if( lex->lookAhead(0) == Token_const ){
01364         lex->nextToken();
01365         AST::Node constant = CreateNode<AST>();
01366         UPDATE_POS( constant, startConstant, lex->index() );
01367         ast->setConstant( constant );
01368     }
01369 
01370     GroupAST::Node except;
01371     if( parseExceptionSpecification(except) ){
01372         ast->setExceptionSpecification( except );
01373     }
01374     }
01375 
01376     if( skipParen ){
01377     if( lex->lookAhead(0) != ')' ){
01378         reportError( i18n("')' expected") );
01379     } else
01380         lex->nextToken();
01381     }
01382 
01383     }
01384 
01385 UPDATE_POS:
01386     UPDATE_POS( ast, start, lex->index() );
01387     node = ast;
01388 
01389     return true;
01390 }
01391 
01392 
01393 bool Parser::parseEnumSpecifier( TypeSpecifierAST::Node& node )
01394 {
01395     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseEnumSpecifier()" << endl;
01396 
01397     QString comment;
01398     while( lex->lookAhead(0) == Token_comment ) {
01399     comment += lex->lookAhead(0).text();
01400     lex->nextToken();
01401     }
01402     if( lex->lookAhead(0).isNull() )
01403     return false;
01404 
01405     int start = lex->index();
01406 
01407     if( lex->lookAhead(0) != Token_enum ){
01408     return false;
01409     }
01410 
01411     lex->nextToken();
01412 
01413     NameAST::Node name;
01414     parseName( name );
01415 
01416     if( lex->lookAhead(0) != '{' ){
01417     lex->setIndex( start );
01418     return false;
01419     }
01420     lex->nextToken();
01421 
01422     EnumSpecifierAST::Node ast = CreateNode<EnumSpecifierAST>();
01423     ast->setName( name );
01424 
01425     EnumeratorAST::Node enumerator;
01426     if( parseEnumerator(enumerator) ){
01427     ast->addEnumerator( enumerator );
01428 
01429     QString comment;
01430     while( lex->lookAhead(0) == ',' ){
01431         comment = "";
01432         advanceAndCheckTrailingComment( comment );
01433         if ( !comment.isEmpty() ){
01434         EnumeratorAST *lastLit = ast->enumeratorList().last();
01435         if( lastLit )
01436             lastLit->setComment( comment );
01437         }
01438 
01439         if( !parseEnumerator(enumerator) ){
01440         //reportError( i18n("Enumerator expected") );
01441         break;
01442         }
01443 
01444         ast->addEnumerator( enumerator );
01445     }
01446     }
01447 
01448     if( lex->lookAhead(0) == Token_comment )
01449     lex->nextToken();
01450     if( lex->lookAhead(0) != '}' )
01451     reportError( i18n("} missing") );
01452     else
01453     lex->nextToken();
01454 
01455     UPDATE_POS( ast, start, lex->index() );
01456     node = ast;
01457 
01458     return true;
01459 }
01460 
01461 bool Parser::parseTemplateParameterList( TemplateParameterListAST::Node& node )
01462 {
01463     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTemplateParameterList()" << endl;
01464 
01465     int start = lex->index();
01466 
01467     TemplateParameterListAST::Node ast = CreateNode<TemplateParameterListAST>();
01468 
01469     TemplateParameterAST::Node param;
01470     if( !parseTemplateParameter(param) ){
01471     return false;
01472     }
01473     ast->addTemplateParameter( param );
01474 
01475     QString comment;
01476     while( lex->lookAhead(0) == ',' ){
01477     comment = QString::null;
01478     advanceAndCheckTrailingComment( comment );
01479 
01480     if( !parseTemplateParameter(param) ){
01481         syntaxError();
01482         break;
01483     } else {
01484         if (!comment.isEmpty())
01485         param->setComment(comment);
01486         ast->addTemplateParameter( param );
01487     }
01488     }
01489 
01490     UPDATE_POS( ast, start, lex->index() );
01491     node = ast;
01492 
01493     return true;
01494 }
01495 
01496 bool Parser::parseTemplateParameter( TemplateParameterAST::Node& node )
01497 {
01498     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTemplateParameter()" << endl;
01499 
01500     int start = lex->index();
01501     TemplateParameterAST::Node ast = CreateNode<TemplateParameterAST>();
01502 
01503     TypeParameterAST::Node typeParameter;
01504     ParameterDeclarationAST::Node param;
01505 
01506     int tk = lex->lookAhead( 0 );
01507 
01508     if( (tk == Token_class || tk == Token_typename || tk == Token_template) && parseTypeParameter(typeParameter) ){
01509     ast->setTypeParameter( typeParameter );
01510     goto ok;
01511     }
01512 
01513     if( !parseParameterDeclaration(param) )
01514         return false;
01515     ast->setTypeValueParameter( param );
01516 
01517 ok:
01518     UPDATE_POS( ast, start, lex->index() );
01519     node = ast;
01520 
01521     return true;
01522 }
01523 
01524 bool Parser::parseTypeParameter( TypeParameterAST::Node& node )
01525 {
01526     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTypeParameter()" << endl;
01527 
01528     int start = lex->index();
01529     TypeParameterAST::Node ast = CreateNode<TypeParameterAST>();
01530 
01531     AST_FROM_TOKEN( kind, lex->index() );
01532     ast->setKind( kind );
01533 
01534     switch( lex->lookAhead(0) ){
01535 
01536     case Token_class:
01537     case Token_typename:
01538     {
01539         lex->nextToken(); // skip class
01540 
01541         // parse optional name
01542         NameAST::Node name;
01543         if( parseName(name) ){
01544         ast->setName( name );
01545         if( lex->lookAhead(0) == '=' ){
01546             lex->nextToken();
01547 
01548             AST::Node typeId;
01549             if( !parseTypeId(typeId) ){
01550             syntaxError();
01551             return false;
01552             }
01553             ast->setTypeId( typeId );
01554         }
01555         }
01556     }
01557     break;
01558 
01559     case Token_template:
01560     {
01561         lex->nextToken(); // skip template
01562         ADVANCE( '<', '<' );
01563 
01564         TemplateParameterListAST::Node params;
01565         if( !parseTemplateParameterList(params) ){
01566         return false;
01567         }
01568         ast->setTemplateParameterList( params );
01569 
01570         ADVANCE( '>', ">" );
01571 
01572         if( lex->lookAhead(0) == Token_class )
01573         lex->nextToken();
01574 
01575         // parse optional name
01576         NameAST::Node name;
01577         if( parseName(name) ){
01578         ast->setName( name );
01579         if( lex->lookAhead(0) == '=' ){
01580             lex->nextToken();
01581 
01582             AST::Node typeId;
01583             if( !parseTypeId(typeId) ){
01584             syntaxError();
01585             return false;
01586             }
01587             ast->setTypeId( typeId );
01588         }
01589         }
01590 
01591         if( lex->lookAhead(0) == '=' ){
01592         lex->nextToken();
01593 
01594         NameAST::Node templ_name;
01595         parseName( templ_name );
01596         }
01597     }
01598     break;
01599 
01600     default:
01601     return false;
01602 
01603     } // end switch
01604 
01605 
01606     UPDATE_POS( ast, start, lex->index() );
01607     node = ast;
01608     return true;
01609 }
01610 
01611 bool Parser::parseStorageClassSpecifier( GroupAST::Node& node )
01612 {
01613     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseStorageClassSpecifier()" << endl;
01614 
01615     int start = lex->index();
01616     GroupAST::Node ast = CreateNode<GroupAST>();
01617 
01618     while( !lex->lookAhead(0).isNull() ){
01619         int tk = lex->lookAhead( 0 );
01620         if( tk == Token_friend || tk == Token_auto || tk == Token_register || tk == Token_static ||
01621         tk == Token_extern || tk == Token_mutable ){
01622         int startNode = lex->index();
01623         lex->nextToken();
01624 
01625         AST::Node n = CreateNode<AST>();
01626         UPDATE_POS( n, startNode, lex->index() );
01627         ast->addNode( n );
01628     } else
01629         break;
01630     }
01631 
01632     if( ast->nodeList().count() == 0 )
01633        return false;
01634 
01635     UPDATE_POS( ast, start, lex->index() );
01636     node = ast;
01637     return true;
01638 }
01639 
01640 bool Parser::parseFunctionSpecifier( GroupAST::Node& node )
01641 {
01642     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseFunctionSpecifier()" << endl;
01643 
01644     int start = lex->index();
01645     GroupAST::Node ast = CreateNode<GroupAST>();
01646 
01647     while( !lex->lookAhead(0).isNull() ){
01648         int tk = lex->lookAhead( 0 );
01649         if( tk == Token_inline || tk == Token_virtual || tk == Token_explicit ){
01650         int startNode = lex->index();
01651         lex->nextToken();
01652 
01653         AST::Node n = CreateNode<AST>();
01654         UPDATE_POS( n, startNode, lex->index() );
01655         ast->addNode( n );
01656     } else {
01657         break;
01658     }
01659     }
01660 
01661     if( ast->nodeList().count() == 0 )
01662        return false;
01663 
01664     UPDATE_POS( ast, start, lex->index() );
01665     node = ast;
01666     return true;
01667 }
01668 
01669 bool Parser::parseTypeId( AST::Node& node )
01670 {
01671     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTypeId()" << endl;
01672 
01674     int start = lex->index();
01675     AST::Node ast = CreateNode<AST>();
01676 
01677     TypeSpecifierAST::Node spec;
01678     if( !parseTypeSpecifier(spec) ){
01679     return false;
01680     }
01681 
01682     DeclaratorAST::Node decl;
01683     parseAbstractDeclarator( decl );
01684 
01685     UPDATE_POS( ast, start, lex->index() );
01686     node = ast;
01687 
01688     return true;
01689 }
01690 
01691 bool Parser::parseInitDeclaratorList( InitDeclaratorListAST::Node& node )
01692 {
01693     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInitDeclaratorList()" << endl;
01694 
01695     int start = lex->index();
01696 
01697     InitDeclaratorListAST::Node ast = CreateNode<InitDeclaratorListAST>();
01698     InitDeclaratorAST::Node decl;
01699 
01700     if( !parseInitDeclarator(decl) ){
01701     return false;
01702     }
01703     ast->addInitDeclarator( decl );
01704 
01705     QString comment;
01706     while( lex->lookAhead(0) == ',' ){
01707     comment = "";
01708     advanceAndCheckTrailingComment( comment );
01709 
01710     if( !parseInitDeclarator(decl) ){
01711         syntaxError();
01712         break;
01713     }
01714     if ( !comment.isEmpty() )
01715         decl->setComment( comment );
01716     ast->addInitDeclarator( decl );
01717     }
01718     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInitDeclaratorList() -- end" << endl;
01719 
01720     UPDATE_POS( ast, start, lex->index() );
01721     node = ast;
01722 
01723     return true;
01724 }
01725 
01726 bool Parser::parseParameterDeclarationClause( ParameterDeclarationClauseAST::Node& node )
01727 {
01728     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseParameterDeclarationClause()" << endl;
01729 
01730     int start = lex->index();
01731 
01732     ParameterDeclarationClauseAST::Node ast = CreateNode<ParameterDeclarationClauseAST>();
01733 
01734     ParameterDeclarationListAST::Node params;
01735     if( !parseParameterDeclarationList(params) ){
01736 
01737     if ( lex->lookAhead(0) == ')' )
01738         goto good;
01739 
01740     if( lex->lookAhead(0) == Token_ellipsis && lex->lookAhead(1) == ')' ){
01741         AST_FROM_TOKEN( ellipsis, lex->index() );
01742         ast->setEllipsis( ellipsis );
01743         lex->nextToken();
01744         goto good;
01745     }
01746     return false;
01747     }
01748 
01749     if( lex->lookAhead(0) == Token_ellipsis ){
01750     AST_FROM_TOKEN( ellipsis, lex->index() );
01751     ast->setEllipsis( ellipsis );
01752     lex->nextToken();
01753     }
01754 
01755 good:
01756     ast->setParameterDeclarationList( params );
01757 
01759     UPDATE_POS( ast, start, lex->index() );
01760     node = ast;
01761 
01762     return true;
01763 }
01764 
01765 bool Parser::parseParameterDeclarationList( ParameterDeclarationListAST::Node& node )
01766 {
01767     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseParameterDeclarationList()" << endl;
01768 
01769     int start = lex->index();
01770 
01771     ParameterDeclarationListAST::Node ast = CreateNode<ParameterDeclarationListAST>();
01772 
01773     ParameterDeclarationAST::Node param;
01774     if( !parseParameterDeclaration(param) ){
01775     lex->setIndex( start );
01776     return false;
01777     }
01778     ast->addParameter( param );
01779 
01780     QString comment;
01781     while( lex->lookAhead(0) == ',' ){
01782     comment = QString::null;
01783     advanceAndCheckTrailingComment( comment );
01784 
01785     if( lex->lookAhead(0) == Token_ellipsis )
01786         break;
01787 
01788     if( !parseParameterDeclaration(param) ){
01789         lex->setIndex( start );
01790         return false;
01791     }
01792     if (!comment.isEmpty())
01793         param->setComment(comment);
01794         ast->addParameter( param );
01795     }
01796 
01797     UPDATE_POS( ast, start, lex->index() );
01798     node = ast;
01799 
01800     return true;
01801 }
01802 
01803 bool Parser::parseParameterDeclaration( ParameterDeclarationAST::Node& node )
01804 {
01805     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseParameterDeclaration()" << endl;
01806 
01807     int start = lex->index();
01808 
01809     // parse decl spec
01810     TypeSpecifierAST::Node spec;
01811     if( !parseTypeSpecifier(spec) ){
01812     lex->setIndex( start );
01813     return false;
01814     }
01815 
01816     int index = lex->index();
01817 
01818     DeclaratorAST::Node decl;
01819     if( !parseDeclarator(decl) ){
01820     lex->setIndex( index );
01821 
01822     // try with abstract declarator
01823     if( !parseAbstractDeclarator(decl) )
01824         return false;
01825     }
01826 
01827     AST::Node expr;
01828     if( lex->lookAhead(0) == '=' ){
01829     lex->nextToken();
01830     if( !parseLogicalOrExpression(expr,true) ){
01831         //reportError( i18n("Expression expected") );
01832         }
01833     }
01834 
01835     ParameterDeclarationAST::Node ast = CreateNode<ParameterDeclarationAST>();
01836     ast->setTypeSpec( spec );
01837     ast->setDeclarator( decl );
01838     ast->setExpression( expr );
01839 
01840     UPDATE_POS( ast, start, lex->index() );
01841     node = ast;
01842 
01843     return true;
01844 }
01845 
01846 bool Parser::parseClassSpecifier( TypeSpecifierAST::Node& node )
01847 {
01848     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseClassSpecifier()" << endl;
01849 
01850     int start = lex->index();
01851 
01852     AST::Node classKey;
01853     int classKeyStart = lex->index();
01854 
01855     int kind = lex->lookAhead( 0 );
01856     if( kind == Token_class || kind == Token_struct || kind == Token_union ){
01857     AST::Node asn = CreateNode<AST>();
01858         classKey = asn;
01859     lex->nextToken();
01860     UPDATE_POS( classKey, classKeyStart, lex->index() );
01861     } else {
01862     return false;
01863     }
01864 
01865     GroupAST::Node winDeclSpec;
01866     parseWinDeclSpec( winDeclSpec );
01867 
01868     while( lex->lookAhead(0) == Token_identifier && lex->lookAhead(1) == Token_identifier )
01869     lex->nextToken();
01870 
01871     NameAST::Node name;
01872     parseName( name );
01873 
01874     BaseClauseAST::Node bases;
01875     if( lex->lookAhead(0) == ':' ){
01876     if( !parseBaseClause(bases) ){
01877         skipUntil( '{' );
01878     }
01879     }
01880 
01881     QString comment;
01882     while (lex->lookAhead(0) == Token_comment) {
01883     comment += lex->lookAhead(0).text();
01884     lex->nextToken();
01885     }
01886     if( lex->lookAhead(0) != '{' ){
01887     lex->setIndex( start );
01888     return false;
01889     }
01890 
01891     ADVANCE( '{', '{' );
01892 
01893     ClassSpecifierAST::Node ast = CreateNode<ClassSpecifierAST>();
01894     ast->setWinDeclSpec( winDeclSpec );
01895     ast->setClassKey( classKey );
01896     ast->setName( name );
01897     ast->setBaseClause( bases );
01898 
01899     while( !lex->lookAhead(0).isNull() ){
01900     if( lex->lookAhead(0) == '}' )
01901         break;
01902 
01903     DeclarationAST::Node memSpec = CreateNode<DeclarationAST>();
01904     int startDecl = lex->index();
01905     if( !parseMemberSpecification(memSpec) ){
01906         if( startDecl == lex->index() )
01907             lex->nextToken(); // skip at least one token
01908         skipUntilDeclaration();
01909     } else
01910         ast->addDeclaration( memSpec );
01911     }
01912 
01913     if( lex->lookAhead(0) != '}' ){
01914     reportError( i18n("} missing") );
01915     } else
01916     lex->nextToken();
01917 
01918     UPDATE_POS( ast, start, lex->index() );
01919     node = ast;
01920 
01921     return true;
01922 }
01923 
01924 bool Parser::parseAccessSpecifier( AST::Node& node )
01925 {
01926     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseAccessSpecifier()" << endl;
01927 
01928     int start = lex->index();
01929 
01930     switch( lex->lookAhead(0) ){
01931     case Token_public:
01932     case Token_protected:
01933     case Token_private: {
01934         AST::Node asn = CreateNode<AST>();
01935     node = asn;
01936     lex->nextToken();
01937     UPDATE_POS( node, start, lex->index() );
01938     return true;
01939         }
01940     }
01941 
01942     return false;
01943 }
01944 
01945 void Parser::advanceAndCheckTrailingComment(QString& comment)
01946 {
01947     Token t = lex->tokenAt( lex->index() );
01948     int previousTokenEndLine = 0;
01949     t.getEndPosition( &previousTokenEndLine, 0 );
01950     lex->nextToken();
01951     if( lex->lookAhead(0) != Token_comment )
01952     return;
01953     t = lex->tokenAt( lex->index() );
01954     int commentStartLine = 0;
01955     t.getStartPosition( &commentStartLine, 0 );
01956     if( commentStartLine != previousTokenEndLine )
01957     return;
01958     comment += lex->lookAhead(0).text();
01959     lex->nextToken();
01960 }
01961 
01962 bool Parser::parseMemberSpecification( DeclarationAST::Node& node )
01963 {
01964     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseMemberSpecification()" << endl;
01965 
01966     QString comment;
01967     while( lex->lookAhead(0) == Token_comment ) {
01968     comment += lex->lookAhead(0).text();
01969     lex->nextToken();
01970     }
01971     if( lex->lookAhead(0).isNull() )
01972     return false;
01973 
01974     int start = lex->index();
01975 
01976     AST::Node access;
01977 
01978     if( lex->lookAhead(0) == ';' ){
01979     advanceAndCheckTrailingComment( comment );
01980     if ( !comment.isEmpty() )
01981         node->setComment( comment );
01982     return true;
01983     } else if( lex->lookAhead(0) == Token_Q_OBJECT || lex->lookAhead(0) == Token_K_DCOP ){
01984     lex->nextToken();
01985     return true;
01986     } else if( lex->lookAhead(0) == Token_signals || lex->lookAhead(0) == Token_k_dcop || lex->lookAhead(0) == Token_k_dcop_signals ){
01987         AccessDeclarationAST::Node ast = CreateNode<AccessDeclarationAST>();
01988     lex->nextToken();
01989     AST::Node n = CreateNode<AST>();
01990     UPDATE_POS( n, start, lex->index() );
01991     ast->addAccess( n );
01992     ADVANCE( ':', ":" );
01993     UPDATE_POS( ast, start, lex->index() );
01994     node = ast;
01995     return true;
01996     } else if( parseTypedef(node) ){
01997     return true;
01998     } else if( parseUsing(node) ){
01999     return true;
02000     } else if( parseTemplateDeclaration(node) ){
02001     return true;
02002     } else if( parseAccessSpecifier(access) ){
02003         AccessDeclarationAST::Node ast = CreateNode<AccessDeclarationAST>();
02004     ast->addAccess( access );
02005 
02006         int startSlot = lex->index();
02007     if( lex->lookAhead(0) == Token_slots ){
02008         lex->nextToken();
02009         AST::Node sl = CreateNode<AST>();
02010         UPDATE_POS( sl, startSlot, lex->index() );
02011         ast->addAccess( sl );
02012     }
02013     ADVANCE( ':', ":" );
02014     UPDATE_POS( ast, start, lex->index() );
02015     node = ast;
02016     return true;
02017     }
02018 
02019     lex->setIndex( start );
02020 
02021     GroupAST::Node storageSpec;
02022     parseStorageClassSpecifier( storageSpec );
02023 
02024     GroupAST::Node cv;
02025     parseCvQualify( cv );
02026 
02027     TypeSpecifierAST::Node spec;
02028     if( parseEnumSpecifier(spec) || parseClassSpecifier(spec) ){
02029         spec->setCvQualify( cv );
02030 
02031         GroupAST::Node cv2;
02032         parseCvQualify( cv2 );
02033         spec->setCv2Qualify( cv2 );
02034 
02035     InitDeclaratorListAST::Node declarators;
02036     parseInitDeclaratorList( declarators );
02037     ADVANCE( ';', ";" );
02038 
02039     if( !comment.isEmpty() ) {
02040             //kdDebug(9007) << "Parser::parseMemberSpecification(spec): comment is " << comment << endl;
02041         spec->setComment( comment );
02042     }
02043 
02044     SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
02045     ast->setTypeSpec( spec );
02046     ast->setInitDeclaratorList( declarators );
02047     UPDATE_POS( ast, start, lex->index() );
02048     node = ast;
02049 
02050     return true;
02051     }
02052 
02053     lex->setIndex( start );
02054 
02055     bool success = parseDeclarationInternal(node, comment);
02056     if( success && !comment.isEmpty() ) {
02057     node->setComment( comment );
02058         //kdDebug(9007) << "Parser::parseMemberSpecification(): comment is " << comment << endl;
02059     }
02060     return success;
02061 }
02062 
02063 bool Parser::parseCtorInitializer( AST::Node& /*node*/ )
02064 {
02065     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCtorInitializer()" << endl;
02066 
02067     if( lex->lookAhead(0) != ':' ){
02068     return false;
02069     }
02070     lex->nextToken();
02071 
02072     AST::Node inits;
02073     if( !parseMemInitializerList(inits) ){
02074     reportError( i18n("Member initializers expected") );
02075     }
02076 
02077     return true;
02078 }
02079 
02080 bool Parser::parseElaboratedTypeSpecifier( TypeSpecifierAST::Node& node )
02081 {
02082     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseElaboratedTypeSpecifier()" << endl;
02083 
02084     int start = lex->index();
02085 
02086     int tk = lex->lookAhead( 0 );
02087     if( tk == Token_class  ||
02088     tk == Token_struct ||
02089     tk == Token_union  ||
02090     tk == Token_enum   ||
02091     tk == Token_typename )
02092     {
02093         AST::Node kind = CreateNode<AST>();
02094     lex->nextToken();
02095     UPDATE_POS( kind, start, lex->index() );
02096 
02097     NameAST::Node name;
02098 
02099     if( parseName(name) ){
02100         ElaboratedTypeSpecifierAST::Node ast = CreateNode<ElaboratedTypeSpecifierAST>();
02101         ast->setKind( kind );
02102         ast->setName( name );
02103         UPDATE_POS( ast, start, lex->index() );
02104         node = ast;
02105 
02106         return true;
02107     }
02108     }
02109 
02110     lex->setIndex( start );
02111     return false;
02112 }
02113 
02114 bool Parser::parseDeclaratorId( NameAST::Node& node )
02115 {
02116     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclaratorId()" << endl;
02117     return parseName( node );
02118 }
02119 
02120 bool Parser::parseExceptionSpecification( GroupAST::Node& node )
02121 {
02122     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseExceptionSpecification()" << endl;
02123 
02124     if( lex->lookAhead(0) != Token_throw ){
02125     return false;
02126     }
02127     lex->nextToken();
02128 
02129     ADVANCE( '(', "(" );
02130     if( lex->lookAhead(0) == Token_ellipsis ){
02131         // extension found in MSVC++ 7.x headers
02132         int start = lex->index();
02133         GroupAST::Node ast = CreateNode<GroupAST>();
02134         AST_FROM_TOKEN( ellipsis, lex->index() );
02135         ast->addNode( ellipsis );
02136         lex->nextToken();
02137         UPDATE_POS( ast, start, lex->index() );
02138         node = ast;
02139     } else {
02140         parseTypeIdList( node );
02141     }
02142     ADVANCE( ')', ")" );
02143 
02144     return true;
02145 }
02146 
02147 bool Parser::parseEnumerator( EnumeratorAST::Node& node )
02148 {
02149     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseEnumerator()" << endl;
02150 
02151     QString comment;
02152     while( lex->lookAhead(0) == Token_comment ) {
02153     comment += lex->lookAhead(0).text();
02154     lex->nextToken();
02155     }
02156     if( lex->lookAhead(0).isNull() )
02157     return false;
02158 
02159     int start = lex->index();
02160 
02161     if( lex->lookAhead(0) != Token_identifier ){
02162     return false;
02163     }
02164     lex->nextToken();
02165 
02166     EnumeratorAST::Node ena = CreateNode<EnumeratorAST>();
02167     node = ena;
02168 
02169     AST::Node id = CreateNode<AST>();
02170     UPDATE_POS( id, start, lex->index() );
02171     node->setId( id );
02172 
02173     if( lex->lookAhead(0) == '=' ){
02174     lex->nextToken();
02175 
02176     AST::Node expr;
02177     if( !parseConstantExpression(expr) ){
02178         reportError( i18n("Constant expression expected") );
02179     }
02180     node->setExpr( expr );
02181     }
02182 
02183     UPDATE_POS( node, start, lex->index() );
02184 
02185     return true;
02186 }
02187 
02188 bool Parser::parseInitDeclarator( InitDeclaratorAST::Node& node )
02189 {
02190     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInitDeclarator()" << endl;
02191 
02192     int start = lex->index();
02193 
02194     DeclaratorAST::Node decl;
02195     AST::Node init;
02196     if( !parseDeclarator(decl) ){
02197     return false;
02198     }
02199 
02200     parseInitializer( init );
02201 
02202     InitDeclaratorAST::Node ast = CreateNode<InitDeclaratorAST>();
02203     ast->setDeclarator( decl );
02204     ast->setInitializer( init );
02205     UPDATE_POS( ast, start, lex->index() );
02206     node = ast;
02207 
02208     return true;
02209 }
02210 
02211 
02212 
02213 bool Parser::parseBaseClause( BaseClauseAST::Node& node )
02214 {
02215     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseBaseClause()" << endl;
02216 
02217     int start = lex->index();
02218     if( lex->lookAhead(0) != ':' ){
02219     return false;
02220     }
02221     lex->nextToken();
02222 
02223     BaseClauseAST::Node bca = CreateNode<BaseClauseAST>();
02224 
02225     BaseSpecifierAST::Node baseSpec;
02226     if( parseBaseSpecifier(baseSpec) ){
02227         bca->addBaseSpecifier( baseSpec );
02228 
02229     QString comment;
02230     while( lex->lookAhead(0) == ',' ){
02231         comment = QString::null;
02232         advanceAndCheckTrailingComment( comment );
02233 
02234         if( !parseBaseSpecifier(baseSpec) ){
02235             reportError( i18n("Base class specifier expected") );
02236             return false;
02237         }
02238         if (!comment.isEmpty())
02239         baseSpec->setComment(comment);
02240         bca->addBaseSpecifier( baseSpec );
02241         }
02242     } else
02243         return false;
02244 
02245     UPDATE_POS( bca, start, lex->index() );
02246     node = bca;
02247 
02248     return true;
02249 }
02250 
02251 bool Parser::parseInitializer( AST::Node& node )
02252 {
02253     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInitializer()" << endl;
02254 
02255     if( lex->lookAhead(0) == '=' ){
02256     lex->nextToken();
02257 
02258     AST::Node init;
02259     if( !parseInitializerClause(node) ){
02260         reportError( i18n("Initializer clause expected") );
02261         return false;
02262     }
02263     } else if( lex->lookAhead(0) == '(' ){
02264     lex->nextToken();
02265     AST::Node expr;
02266     skipCommaExpression( expr );
02267 
02268     ADVANCE( ')', ")" );
02269     }
02270 
02271     return false;
02272 }
02273 
02274 bool Parser::parseMemInitializerList( AST::Node& /*node*/ )
02275 {
02276     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseMemInitializerList()" << endl;
02277 
02278     AST::Node init;
02279     if( !parseMemInitializer(init) ){
02280     return false;
02281     }
02282 
02283     QString comment;
02284     while( lex->lookAhead(0) == ',' ){
02285     comment = QString::null;
02286     advanceAndCheckTrailingComment( comment );
02287 
02288     if( parseMemInitializer(init) ){
02289     } else {
02290         break;
02291     }
02292     }
02293 
02294     return true;
02295 }
02296 
02297 bool Parser::parseMemInitializer( AST::Node& /*node*/ )
02298 {
02299     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseMemInitializer()" << endl;
02300 
02301     NameAST::Node initId;
02302     if( !parseMemInitializerId(initId) ){
02303     reportError( i18n("Identifier expected") );
02304     return false;
02305     }
02306     ADVANCE( '(', '(' );
02307     AST::Node expr;
02308     skipCommaExpression( expr );
02309     ADVANCE( ')', ')' );
02310 
02311     return true;
02312 }
02313 
02314 bool Parser::parseTypeIdList( GroupAST::Node& node )
02315 {
02316     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTypeIdList()" << endl;
02317 
02318     int start = lex->index();
02319 
02320     AST::Node typeId;
02321     if( !parseTypeId(typeId) ){
02322     return false;
02323     }
02324 
02325     GroupAST::Node ast = CreateNode<GroupAST>();
02326     ast->addNode( typeId );
02327 
02328     QString comment;
02329     while( lex->lookAhead(0) == ',' ){
02330     comment = QString::null;
02331     advanceAndCheckTrailingComment( comment );
02332     if( parseTypeId(typeId) ){
02333         if (!comment.isEmpty())
02334         typeId->setComment(comment);
02335         ast->addNode( typeId );
02336     } else {
02337         reportError( i18n("Type id expected") );
02338         break;
02339     }
02340     }
02341 
02342     UPDATE_POS( ast, start, lex->index() );
02343     node = ast;
02344     return true;
02345 }
02346 
02347 bool Parser::parseBaseSpecifier( BaseSpecifierAST::Node& node )
02348 {
02349     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseBaseSpecifier()" << endl;
02350 
02351     int start = lex->index();
02352     BaseSpecifierAST::Node ast = CreateNode<BaseSpecifierAST>();
02353 
02354     AST::Node access;
02355     if( lex->lookAhead(0) == Token_virtual ){
02356     AST_FROM_TOKEN( virt, lex->index() );
02357     ast->setIsVirtual( virt );
02358 
02359     lex->nextToken();
02360 
02361     parseAccessSpecifier( access );
02362     } else {
02363         parseAccessSpecifier( access );
02364 
02365     if( lex->lookAhead(0) == Token_virtual ){
02366         AST_FROM_TOKEN( virt, lex->index() );
02367         ast->setIsVirtual( virt );
02368         lex->nextToken();
02369     }
02370     }
02371 
02372     NameAST::Node name;
02373     if( !parseName(name) ){
02374     reportError( i18n("Class name expected") );
02375     }
02376 
02377     ast->setAccess( access );
02378     ast->setName( name );
02379     UPDATE_POS( ast, start, lex->index() );
02380     node = ast;
02381 
02382     return true;
02383 }
02384 
02385 
02386 bool Parser::parseInitializerClause( AST::Node& node )
02387 {
02388     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInitializerClause()" << endl;
02389 
02390     if( lex->lookAhead(0) == '{' ){
02391     if( !skip('{','}') ){
02392         reportError( i18n("} missing") );
02393     } else
02394         lex->nextToken();
02395     } else {
02396     if( !parseAssignmentExpression(node) ){
02397         //reportError( i18n("Expression expected") );
02398     }
02399     }
02400 
02401     return true;
02402 }
02403 
02404 bool Parser::parseMemInitializerId( NameAST::Node& node )
02405 {
02406     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseMemInitializerId()" << endl;
02407 
02408     return parseName( node );
02409 }
02410 
02411 bool Parser::parsePtrToMember( AST::Node& /*node*/ )
02412 {
02413     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parsePtrToMember()" << endl;
02414 
02415     if( lex->lookAhead(0) == Token_scope ){
02416     lex->nextToken();
02417     }
02418 
02419     while( lex->lookAhead(0) == Token_identifier ){
02420     lex->nextToken();
02421 
02422     if( lex->lookAhead(0) == Token_scope && lex->lookAhead(1) == '*' ){
02423         lex->nextToken(); // skip ::
02424         lex->nextToken(); // skip *
02425         return true;
02426     } else
02427         break;
02428     }
02429 
02430     return false;
02431 }
02432 
02433 bool Parser::parseUnqualifiedName( ClassOrNamespaceNameAST::Node& node )
02434 {
02435     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseUnqualifiedName()" << endl;
02436 
02437     int start = lex->index();
02438     bool isDestructor = false;
02439 
02440     ClassOrNamespaceNameAST::Node ast = CreateNode<ClassOrNamespaceNameAST>();
02441 
02442     if( lex->lookAhead(0) == Token_identifier ){
02443         int startName = lex->index();
02444         AST::Node n = CreateNode<AST>();
02445     lex->nextToken();
02446     UPDATE_POS( n, startName, lex->index() );
02447     ast->setName( n );
02448     } else if( lex->lookAhead(0) == '~' && lex->lookAhead(1) == Token_identifier ){
02449         int startName = lex->index();
02450         AST::Node n = CreateNode<AST>();
02451     lex->nextToken(); // skip ~
02452     lex->nextToken(); // skip classname
02453     UPDATE_POS( n, startName, lex->index() );
02454     ast->setName( n );
02455     isDestructor = true;
02456     } else if( lex->lookAhead(0) == Token_operator ){
02457         AST::Node n;
02458     if( !parseOperatorFunctionId(n) )
02459         return false;
02460     ast->setName( n );
02461     } else {
02462     return false;
02463     }
02464 
02465     if( !isDestructor ){
02466 
02467     int index = lex->index();
02468 
02469     if( lex->lookAhead(0) == '<' ){
02470         lex->nextToken();
02471 
02472         // optional template arguments
02473         TemplateArgumentListAST::Node args;
02474         parseTemplateArgumentList( args );
02475 
02476         if( lex->lookAhead(0) != '>' ){
02477         lex->setIndex( index );
02478         } else {
02479         lex->nextToken();
02480             ast->setTemplateArgumentList( args );
02481         }
02482     }
02483     }
02484 
02485     UPDATE_POS( ast, start, lex->index() );
02486     node = ast;
02487 
02488     return true;
02489 }
02490 
02491 bool Parser::parseStringLiteral( AST::Node& /*node*/ )
02492 {
02493     while( !lex->lookAhead(0).isNull() ) {
02494     if( lex->lookAhead(0) == Token_identifier &&
02495         lex->lookAhead(0).text() == "L" && lex->lookAhead(1) == Token_string_literal ) {
02496 
02497         lex->nextToken();
02498         lex->nextToken();
02499     } else if( lex->lookAhead(0) == Token_string_literal ) {
02500         lex->nextToken();
02501     } else
02502         return false;
02503     }
02504     return true;
02505 }
02506 
02507 bool Parser::skipExpressionStatement( StatementAST::Node& node )
02508 {
02509     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::skipExpressionStatement()" << endl;
02510 
02511     int start = lex->index();
02512 
02513     AST::Node expr;
02514     skipCommaExpression( expr );
02515 
02516     ADVANCE( ';', ";" );
02517 
02518     ExpressionStatementAST::Node ast = CreateNode<ExpressionStatementAST>();
02519     ast->setExpression( expr );
02520     UPDATE_POS( ast, start, lex->index() );
02521     node = ast;
02522 
02523     return true;
02524 }
02525 
02526 bool Parser::parseStatement( StatementAST::Node& node ) // thanks to fiore@8080.it ;)
02527 {
02528     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseStatement()" << endl;
02529     switch( lex->lookAhead(0) ){
02530 
02531     case Token_while:
02532     return parseWhileStatement( node );
02533 
02534     case Token_do:
02535     return parseDoStatement( node );
02536 
02537     case Token_for:
02538     return parseForStatement( node );
02539 
02540     case Token_if:
02541     return parseIfStatement( node );
02542 
02543     case Token_switch:
02544     return parseSwitchStatement( node );
02545 
02546     case Token_try:
02547     return parseTryBlockStatement( node );
02548 
02549     case Token_case:
02550     case Token_default:
02551     return parseLabeledStatement( node );
02552 
02553     case Token_break:
02554     case Token_continue:
02555     lex->nextToken();
02556     ADVANCE( ';', ";" );
02557     return true;
02558 
02559     case Token_goto:
02560     lex->nextToken();
02561     ADVANCE( Token_identifier, "identifier" );
02562     ADVANCE( ';', ";" );
02563     return true;
02564 
02565     case Token_return:
02566     {
02567     lex->nextToken();
02568     AST::Node expr;
02569     skipCommaExpression( expr );
02570     ADVANCE( ';', ";" );
02571     }
02572     return true;
02573 
02574     case '{':
02575     return parseCompoundStatement( node );
02576 
02577     case Token_identifier:
02578     if( parseLabeledStatement(node) )
02579         return true;
02580     break;
02581     }
02582 
02583     //kdDebug(9007)<< "------------> try with declaration statement" << endl;
02584     if ( parseDeclarationStatement(node) )
02585     return true;
02586 
02587     return skipExpressionStatement( node );
02588 }
02589 
02590 bool Parser::parseCondition( ConditionAST::Node& node )
02591 {
02592     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCondition()" << endl;
02593 
02594     int start = lex->index();
02595 
02596     ConditionAST::Node ast = CreateNode<ConditionAST>();
02597 
02598     TypeSpecifierAST::Node spec;
02599     if( parseTypeSpecifier(spec) ){
02600     DeclaratorAST::Node decl;
02601     if( parseDeclarator(decl) && lex->lookAhead(0) == '=' ) {
02602         lex->nextToken();
02603 
02604         AST::Node expr;
02605         if( skipExpression(expr) ){
02606                 ast->setTypeSpec( spec );
02607                 ast->setDeclarator( decl );
02608                 ast->setExpression( expr );
02609 
02610                 UPDATE_POS( ast, start, lex->index() );
02611                 node = ast;
02612 
02613         return true;
02614             }
02615     }
02616     }
02617 
02618     lex->setIndex( start );
02619 
02620     AST::Node expr;
02621     if( !skipCommaExpression(expr) )
02622         return false;
02623 
02624     ast->setExpression( expr );
02625     UPDATE_POS( ast, start, lex->index() );
02626     node = ast;
02627     return true;
02628 }
02629 
02630 
02631 bool Parser::parseWhileStatement( StatementAST::Node& node )
02632 {
02633     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseWhileStatement()" << endl;
02634     int start = lex->index();
02635 
02636     ADVANCE( Token_while, "while" );
02637     ADVANCE( '(' , "(" );
02638 
02639     ConditionAST::Node cond;
02640     if( !parseCondition(cond) ){
02641     reportError( i18n("condition expected") );
02642     return false;
02643     }
02644     ADVANCE( ')', ")" );
02645 
02646     StatementAST::Node body;
02647     if( !parseStatement(body) ){
02648     reportError( i18n("statement expected") );
02649     return false;
02650     }
02651 
02652     WhileStatementAST::Node ast = CreateNode<WhileStatementAST>();
02653     ast->setCondition( cond );
02654     ast->setStatement( body );
02655     UPDATE_POS( ast, start, lex->index() );
02656     node = ast;
02657 
02658     return true;
02659 }
02660 
02661 bool Parser::parseDoStatement( StatementAST::Node& node )
02662 {
02663     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDoStatement()" << endl;
02664     int start = lex->index();
02665 
02666     ADVANCE( Token_do, "do" );
02667 
02668     StatementAST::Node body;
02669     if( !parseStatement(body) ){
02670     reportError( i18n("statement expected") );
02671     //return false;
02672     }
02673 
02674     ADVANCE_NR( Token_while, "while" );
02675     ADVANCE_NR( '(' , "(" );
02676 
02677     AST::Node expr;
02678     if( !skipCommaExpression(expr) ){
02679     reportError( i18n("expression expected") );
02680     //return false;
02681     }
02682 
02683     ADVANCE_NR( ')', ")" );
02684     ADVANCE_NR( ';', ";" );
02685 
02686     DoStatementAST::Node ast = CreateNode<DoStatementAST>();
02687     ast->setStatement( body );
02688     //ast->setCondition( condition );
02689     UPDATE_POS( ast, start, lex->index() );
02690     node = ast;
02691 
02692     return true;
02693 }
02694 
02695 bool Parser::parseForStatement( StatementAST::Node& node )
02696 {
02697     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseForStatement()" << endl;
02698     int start = lex->index();
02699 
02700     ADVANCE( Token_for, "for" );
02701     ADVANCE( '(', "(" );
02702 
02703     StatementAST::Node init;
02704     if( !parseForInitStatement(init) ){
02705     reportError( i18n("for initialization expected") );
02706     return false;
02707     }
02708 
02709     ConditionAST::Node cond;
02710     parseCondition( cond );
02711     ADVANCE( ';', ";" );
02712 
02713     AST::Node expr;
02714     skipCommaExpression( expr );
02715     ADVANCE( ')', ")" );
02716 
02717     StatementAST::Node body;
02718     if( !parseStatement(body) )
02719     return false;
02720 
02721     ForStatementAST::Node ast = CreateNode<ForStatementAST>();
02722     ast->setInitStatement( init );
02723     ast->setCondition( cond );
02724     // ast->setExpression( expression );
02725     ast->setStatement( body );
02726     UPDATE_POS( ast, start, lex->index() );
02727     node = ast;
02728 
02729     return true;
02730 }
02731 
02732 bool Parser::parseForInitStatement( StatementAST::Node& node )
02733 {
02734     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseForInitStatement()" << endl;
02735 
02736     if ( parseDeclarationStatement(node) )
02737     return true;
02738 
02739     return skipExpressionStatement( node );
02740 }
02741 
02742 bool Parser::parseCompoundStatement( StatementAST::Node& node )
02743 {
02744     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCompoundStatement()" << endl;
02745     int start = lex->index();
02746 
02747     if( lex->lookAhead(0) != '{' ){
02748     return false;
02749     }
02750     lex->nextToken();
02751 
02752     StatementListAST::Node ast = CreateNode<StatementListAST>();
02753 
02754     while( !lex->lookAhead(0).isNull() ){
02755     if( lex->lookAhead(0) == '}' )
02756         break;
02757 
02758     StatementAST::Node stmt;
02759     int startStmt = lex->index();
02760     if( !parseStatement(stmt) ){
02761         if( startStmt == lex->index() )
02762             lex->nextToken();
02763         skipUntilStatement();
02764     } else {
02765         ast->addStatement( stmt );
02766     }
02767     }
02768 
02769     if( lex->lookAhead(0) != '}' ){
02770         reportError( i18n("} expected") );
02771     } else {
02772         lex->nextToken();
02773     }
02774 
02775     UPDATE_POS( ast, start, lex->index() );
02776     node = ast;
02777 
02778     return true;
02779 }
02780 
02781 bool Parser::parseIfStatement( StatementAST::Node& node )
02782 {
02783     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseIfStatement()" << endl;
02784 
02785     int start = lex->index();
02786 
02787     ADVANCE( Token_if, "if" );
02788 
02789     ADVANCE( '(' , "(" );
02790 
02791     IfStatementAST::Node ast = CreateNode<IfStatementAST>();
02792 
02793     ConditionAST::Node cond;
02794     if( !parseCondition(cond) ){
02795     reportError( i18n("condition expected") );
02796     return false;
02797     }
02798     ADVANCE( ')', ")" );
02799 
02800     StatementAST::Node stmt;
02801     if( !parseStatement(stmt) ){
02802     reportError( i18n("statement expected") );
02803     return false;
02804     }
02805 
02806     ast->setCondition( cond );
02807     ast->setStatement( stmt );
02808 
02809     if( lex->lookAhead(0) == Token_else ){
02810     lex->nextToken();
02811     StatementAST::Node elseStmt;
02812     if( !parseStatement(elseStmt) ) {
02813         reportError( i18n("statement expected") );
02814         return false;
02815     }
02816     ast->setElseStatement( elseStmt );
02817     }
02818 
02819     UPDATE_POS( ast, start, lex->index() );
02820     node = ast;
02821 
02822     return true;
02823 }
02824 
02825 bool Parser::parseSwitchStatement( StatementAST::Node& node )
02826 {
02827     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseSwitchStatement()" << endl;
02828     int start = lex->index();
02829     ADVANCE( Token_switch, "switch" );
02830 
02831     ADVANCE( '(' , "(" );
02832 
02833     ConditionAST::Node cond;
02834     if( !parseCondition(cond) ){
02835     reportError( i18n("condition expected") );
02836     return false;
02837     }
02838     ADVANCE( ')', ")" );
02839 
02840     StatementAST::Node stmt;
02841     if( !parseCompoundStatement(stmt) ){
02842     syntaxError();
02843     return false;
02844     }
02845 
02846     SwitchStatementAST::Node ast = CreateNode<SwitchStatementAST>();
02847     ast->setCondition( cond );
02848     ast->setStatement( stmt );
02849     UPDATE_POS( ast, start, lex->index() );
02850     node = ast;
02851 
02852     return true;
02853 }
02854 
02855 bool Parser::parseLabeledStatement( StatementAST::Node& node )
02856 {
02857     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseLabeledStatement()" << endl;
02858     switch( lex->lookAhead(0) ){
02859     case Token_identifier:
02860     case Token_default:
02861     if( lex->lookAhead(1) == ':' ){
02862         lex->nextToken();
02863         lex->nextToken();
02864 
02865         StatementAST::Node stmt;
02866         if( parseStatement(stmt) ){
02867                 node = stmt;
02868             return true;
02869         }
02870     }
02871     break;
02872 
02873     case Token_case:
02874     {
02875     lex->nextToken();
02876     AST::Node expr;
02877     if( !parseConstantExpression(expr) ){
02878         reportError( i18n("expression expected") );
02879     } else if( lex->lookAhead(0) == Token_ellipsis ){
02880         lex->nextToken();
02881 
02882         AST::Node expr2;
02883         if( !parseConstantExpression(expr2) ){
02884             reportError( i18n("expression expected") );
02885         }
02886     }
02887     ADVANCE( ':', ":" );
02888 
02889     StatementAST::Node stmt;
02890     if( parseStatement(stmt) ){
02891             node = stmt;
02892         return true;
02893     }
02894     }
02895     break;
02896 
02897     }
02898 
02899     return false;
02900 }
02901 
02902 bool Parser::parseBlockDeclaration( DeclarationAST::Node& node )
02903 {
02904     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseBlockDeclaration()" << endl;
02905     switch( lex->lookAhead(0) ) {
02906     case Token_typedef:
02907     return parseTypedef( node );
02908     case Token_using:
02909     return parseUsing( node );
02910     case Token_asm:
02911     return parseAsmDefinition( node );
02912     case Token_namespace:
02913     return parseNamespaceAliasDefinition( node );
02914     }
02915 
02916     int start = lex->index();
02917 
02918     GroupAST::Node storageSpec;
02919     parseStorageClassSpecifier( storageSpec );
02920 
02921     GroupAST::Node cv;
02922     parseCvQualify( cv );
02923 
02924     TypeSpecifierAST::Node spec;
02925     if ( !parseTypeSpecifierOrClassSpec(spec) ) { // replace with simpleTypeSpecifier?!?!
02926     lex->setIndex( start );
02927     return false;
02928     }
02929     spec->setCvQualify( cv );
02930 
02931     GroupAST::Node cv2;
02932     parseCvQualify( cv2 );
02933     spec->setCv2Qualify( cv2 );
02934 
02935     InitDeclaratorListAST::Node declarators;
02936     parseInitDeclaratorList( declarators );
02937 
02938     if( lex->lookAhead(0) != ';' ){
02939         lex->setIndex( start );
02940     return false;
02941     }
02942     lex->nextToken();
02943 
02944     SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
02945     ast->setTypeSpec( spec );
02946     ast->setInitDeclaratorList( declarators );
02947     UPDATE_POS( ast, start, lex->index() );
02948     node = ast;
02949 
02950     return true;
02951 }
02952 
02953 bool Parser::parseNamespaceAliasDefinition( DeclarationAST::Node& /*node*/ )
02954 {
02955     if ( lex->lookAhead(0) != Token_namespace ) {
02956     return false;
02957     }
02958     lex->nextToken();
02959 
02960     ADVANCE( Token_identifier,  "identifier" );
02961     ADVANCE( '=', "=" );
02962 
02963     NameAST::Node name;
02964     if( !parseName(name) ){
02965     reportError( i18n("Namespace name expected") );
02966     }
02967 
02968     ADVANCE( ';', ";" );
02969 
02970     return true;
02971 
02972 }
02973 
02974 bool Parser::parseDeclarationStatement( StatementAST::Node& node )
02975 {
02976     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclarationStatement()" << endl;
02977 
02978     int start = lex->index();
02979 
02980     DeclarationAST::Node decl;
02981     if ( !parseBlockDeclaration(decl) ){
02982     return false;
02983     }
02984 
02985     DeclarationStatementAST::Node ast = CreateNode<DeclarationStatementAST>();
02986     ast->setDeclaration( decl );
02987     UPDATE_POS( ast, start, lex->index() );
02988     node = ast;
02989 
02990     //kdDebug(9007)<< "---------------------> found a block declaration" << endl;
02991     return true;
02992 }
02993 
02994 bool Parser::parseDeclarationInternal( DeclarationAST::Node& node, QString& comment )
02995 {
02996     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeclarationInternal()" << endl;
02997 
02998     int start = lex->index();
02999 
03000     // that is for the case '__declspec(dllexport) int ...' or
03001     // '__declspec(dllexport) inline int ...', etc.
03002     GroupAST::Node winDeclSpec;
03003     parseWinDeclSpec( winDeclSpec );
03004 
03005     GroupAST::Node funSpec;
03006     bool hasFunSpec = parseFunctionSpecifier( funSpec );
03007 
03008     GroupAST::Node storageSpec;
03009     bool hasStorageSpec = parseStorageClassSpecifier( storageSpec );
03010 
03011     if( hasStorageSpec && !hasFunSpec )
03012         hasFunSpec = parseFunctionSpecifier( funSpec );
03013 
03014     // that is for the case 'friend __declspec(dllexport) ....'
03015     GroupAST::Node winDeclSpec2;
03016     parseWinDeclSpec( winDeclSpec2 );
03017 
03018     GroupAST::Node cv;
03019     parseCvQualify( cv );
03020 
03021     int index = lex->index();
03022     NameAST::Node name;
03023     if( parseName(name) && lex->lookAhead(0) == '(' ){
03024     // no type specifier, maybe a constructor or a cast operator??
03025 
03026     lex->setIndex( index );
03027 
03028     InitDeclaratorAST::Node declarator;
03029     if( parseInitDeclarator(declarator) ){
03030         int endSignature = lex->index();
03031 
03032         switch( lex->lookAhead(0) ){
03033         case ';':
03034             {
03035             lex->nextToken();
03036 
03037             InitDeclaratorListAST::Node declarators = CreateNode<InitDeclaratorListAST>();
03038 
03039             // update declarators position
03040             int startLine, startColumn, endLine, endColumn;
03041             if( declarator.get() ){
03042                 declarator->getStartPosition( &startLine, &startColumn );
03043                 declarator->getEndPosition( &endLine, &endColumn );
03044                 declarators->setStartPosition( startLine, startColumn );
03045                 declarators->setEndPosition( endLine, endColumn );
03046             }
03047             declarators->addInitDeclarator( declarator );
03048 
03049             SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
03050             ast->setInitDeclaratorList( declarators );
03051             ast->setText( toString(start, endSignature) );
03052             node = ast;
03053             UPDATE_POS( node, start, lex->index() );
03054             return true;
03055 
03056         }
03057         break;
03058 
03059         case ':':
03060             {
03061             AST::Node ctorInit;
03062             StatementListAST::Node funBody;
03063             if( parseCtorInitializer(ctorInit) && parseFunctionBody(funBody) ){
03064             FunctionDefinitionAST::Node ast = CreateNode<FunctionDefinitionAST>();
03065             ast->setStorageSpecifier( storageSpec );
03066             ast->setFunctionSpecifier( funSpec );
03067             ast->setInitDeclarator( declarator );
03068             ast->setFunctionBody( funBody );
03069             ast->setText( toString(start, endSignature) );
03070             node = ast;
03071             UPDATE_POS( node, start, lex->index() );
03072                 return true;
03073             }
03074         }
03075         break;
03076 
03077         case '{':
03078             {
03079             StatementListAST::Node funBody;
03080             if( parseFunctionBody(funBody) ){
03081             FunctionDefinitionAST::Node ast = CreateNode<FunctionDefinitionAST>();
03082             ast->setStorageSpecifier( storageSpec );
03083             ast->setFunctionSpecifier( funSpec );
03084             ast->setInitDeclarator( declarator );
03085             ast->setText( toString(start, endSignature) );
03086             ast->setFunctionBody( funBody );
03087             node = ast;
03088             UPDATE_POS( node, start, lex->index() );
03089                 return true;
03090             }
03091         }
03092         break;
03093 
03094         case '(':
03095         case '[':
03096             // ops!! it seems a declarator
03097         goto start_decl;
03098         break;
03099         }
03100 
03101     }
03102 
03103     syntaxError();
03104     return false;
03105     }
03106 
03107 start_decl:
03108     lex->setIndex( index );
03109 
03110     if( lex->lookAhead(0) == Token_const && lex->lookAhead(1) == Token_identifier && lex->lookAhead(2) == '=' ){
03111     // constant definition
03112     lex->nextToken();
03113     InitDeclaratorListAST::Node declarators;
03114     if( parseInitDeclaratorList(declarators) ){
03115         ADVANCE( ';', ";" );
03116         DeclarationAST::Node ast = CreateNode<DeclarationAST>();
03117         node = ast;
03118         UPDATE_POS( node, start, lex->index() );
03119         return true;
03120     }
03121     syntaxError();
03122     return false;
03123     }
03124 
03125     TypeSpecifierAST::Node spec;
03126     if( parseTypeSpecifier(spec) ){
03127     if ( !hasFunSpec )
03128         parseFunctionSpecifier( funSpec );  // e.g. "void inline"
03129         spec->setCvQualify( cv );
03130 
03131     InitDeclaratorListAST::Node declarators;
03132 
03133     InitDeclaratorAST::Node decl;
03134     int startDeclarator = lex->index();
03135     bool maybeFunctionDefinition = false;
03136 
03137         if( lex->lookAhead(0) != ';' ){
03138             if( parseInitDeclarator(decl) && lex->lookAhead(0) == '{' ){
03139                 // function definition
03140                 maybeFunctionDefinition = true;
03141             } else {
03142                 lex->setIndex( startDeclarator );
03143                 if( !parseInitDeclaratorList(declarators) ){
03144                     syntaxError();
03145                     return false;
03146                 }
03147             }
03148         }
03149 
03150     int endSignature = lex->index();
03151     switch( lex->lookAhead(0) ){
03152     case ';':
03153         {
03154         advanceAndCheckTrailingComment( comment );
03155         SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
03156         ast->setStorageSpecifier( storageSpec );
03157         ast->setFunctionSpecifier( funSpec );
03158         ast->setText( toString(start, endSignature) );
03159         ast->setTypeSpec( spec );
03160         ast->setWinDeclSpec( winDeclSpec );
03161         ast->setInitDeclaratorList( declarators );
03162         node = ast;
03163         UPDATE_POS( node, start, lex->index() );
03164         }
03165         return true;
03166 
03167     case '{':
03168         {
03169             if( !maybeFunctionDefinition ){
03170             syntaxError();
03171             return false;
03172         }
03173             StatementListAST::Node funBody;
03174             if ( parseFunctionBody(funBody) ) {
03175             FunctionDefinitionAST::Node ast = CreateNode<FunctionDefinitionAST>();
03176             ast->setWinDeclSpec( winDeclSpec );
03177             ast->setStorageSpecifier( storageSpec );
03178             ast->setFunctionSpecifier( funSpec );
03179             ast->setText( toString(start, endSignature) );
03180             ast->setTypeSpec( spec );
03181             ast->setFunctionBody( funBody );
03182             ast->setInitDeclarator( decl );
03183             node = ast;
03184             UPDATE_POS( node, start, lex->index() );
03185             return true;
03186             }
03187         }
03188         break;
03189 
03190     }
03191     }
03192 
03193     syntaxError();
03194     return false;
03195 }
03196 
03197 bool Parser::parseFunctionBody( StatementListAST::Node& node )
03198 {
03199     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseFunctionBody()" << endl;
03200 
03201     int start = lex->index();
03202     if( lex->lookAhead(0) != '{' ){
03203     return false;
03204     }
03205     lex->nextToken();
03206 
03207     StatementListAST::Node ast = CreateNode<StatementListAST>();
03208 
03209     while( !lex->lookAhead(0).isNull() ){
03210     if( lex->lookAhead(0) == '}' )
03211         break;
03212 
03213     StatementAST::Node stmt;
03214     int startStmt = lex->index();
03215     if( !parseStatement(stmt) ){
03216         if( startStmt == lex->index() )
03217             lex->nextToken();
03218         skipUntilStatement();
03219     } else
03220         ast->addStatement( stmt );
03221     }
03222 
03223     if( lex->lookAhead(0) != '}' ){
03224     reportError( i18n("} expected") );
03225     } else
03226     lex->nextToken();
03227 
03228     UPDATE_POS( ast, start, lex->index() );
03229     node = ast;
03230 
03231     return true;
03232 }
03233 
03234 QString Parser::toString( int start, int end, const QString& sep ) const
03235 {
03236     QStringList l;
03237 
03238     for( int i=start; i<end; ++i ){
03239     l << lex->tokenAt(i).text();
03240     }
03241 
03242     return l.join( sep ).stripWhiteSpace();
03243 }
03244 
03245 bool Parser::parseTypeSpecifierOrClassSpec( TypeSpecifierAST::Node& node )
03246 {
03247     if( parseClassSpecifier(node) )
03248     return true;
03249     else if( parseEnumSpecifier(node) )
03250     return true;
03251     else if( parseTypeSpecifier(node) )
03252     return true;
03253 
03254     return false;
03255 }
03256 
03257 bool Parser::parseTryBlockStatement( StatementAST::Node& node )
03258 {
03259     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseTryBlockStatement()" << endl;
03260 
03261     if( lex->lookAhead(0) != Token_try ){
03262     return false;
03263     }
03264     lex->nextToken();
03265 
03266     StatementAST::Node stmt;
03267     if( !parseCompoundStatement(stmt) ){
03268     syntaxError();
03269     return false;
03270     }
03271 
03272     if( lex->lookAhead(0) != Token_catch ){
03273     reportError( i18n("catch expected") );
03274     return false;
03275     }
03276 
03277     while( lex->lookAhead(0) == Token_catch ){
03278     lex->nextToken();
03279     ADVANCE( '(', "(" );
03280     ConditionAST::Node cond;
03281     if( !parseCondition(cond) ){
03282         reportError( i18n("condition expected") );
03283         return false;
03284     }
03285     ADVANCE( ')', ")" );
03286 
03287     StatementAST::Node body;
03288     if( !parseCompoundStatement(body) ){
03289         syntaxError();
03290         return false;
03291     }
03292     }
03293 
03294     node = stmt;
03295     return true;
03296 }
03297 
03298 bool Parser::parsePrimaryExpression( AST::Node& /*node*/ )
03299 {
03300     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parsePrimarExpression()" << endl;
03301 
03302 
03303     switch( lex->lookAhead(0) ){
03304         case Token_string_literal:
03305     {
03306         AST::Node lit;
03307         parseStringLiteral( lit );
03308     }
03309     return true;
03310 
03311         case Token_number_literal:
03312         case Token_char_literal:
03313         case Token_true:
03314         case Token_false:
03315             lex->nextToken();
03316             return true;
03317 
03318         case Token_this:
03319             lex->nextToken();
03320             return true;
03321 
03322     case Token_dynamic_cast:
03323         case Token_static_cast:
03324         case Token_reinterpret_cast:
03325         case Token_const_cast:
03326         {
03327         lex->nextToken();
03328 
03329         CHECK( '<', "<" );
03330         AST::Node typeId;
03331         parseTypeId( typeId );
03332         CHECK( '>', ">" );
03333 
03334         CHECK( '(', "(" );
03335         AST::Node expr;
03336         parseCommaExpression( expr );
03337         CHECK( ')', ")" );
03338         }
03339         return true;
03340 
03341     case Token_typeid:
03342         {
03343         lex->nextToken();
03344         CHECK( '(', "(" );
03345         AST::Node expr;
03346         parseCommaExpression( expr );
03347         CHECK( ')', ")" );
03348         }
03349         return true;
03350 
03351     case '(':
03352         {
03353         lex->nextToken();
03354         //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "token = " << lex->lookAhead(0).text() << endl;
03355         AST::Node expr;
03356         if( !parseExpression(expr) ){
03357             return false;
03358         }
03359         CHECK( ')', ")" );
03360         }
03361         return true;
03362 
03363     default:
03364         {
03365         int start = lex->index();
03366         TypeSpecifierAST::Node typeSpec;
03367         if( parseSimpleTypeSpecifier(typeSpec) && lex->lookAhead(0) == '(' ){
03368             lex->nextToken();
03369             AST::Node expr;
03370             parseCommaExpression( expr );
03371             CHECK( ')', ")" );
03372             return true;
03373         }
03374 
03375         lex->setIndex( start );
03376         NameAST::Node name;
03377         if( parseName(name) )
03378             return true;
03379         }
03380     }
03381 
03382     return false;
03383 }
03384 
03385 bool Parser::parsePostfixExpression( AST::Node& /*node*/ )
03386 {
03387     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parsePostfixExpression()" << endl;
03388 
03389     AST::Node expr;
03390     if( !parsePrimaryExpression(expr) )
03391     return false;
03392 
03393     while( true ){
03394     switch(lex->lookAhead(0))
03395     {
03396     case '[':
03397         {
03398         lex->nextToken();
03399         AST::Node e;
03400         parseCommaExpression( e );
03401         CHECK( ']', "]" );
03402         }
03403         break;
03404 
03405     case '(':
03406         {
03407         lex->nextToken();
03408         AST::Node funArgs;
03409         parseCommaExpression( funArgs );
03410         CHECK( ')', ")" );
03411         }
03412         break;
03413 
03414     case Token_incr:
03415     case Token_decr:
03416         lex->nextToken();
03417         break;
03418 
03419     case '.':
03420     case Token_arrow:
03421         {
03422                 lex->nextToken();
03423                 if( lex->lookAhead(0) == Token_template )
03424                     lex->nextToken();
03425 
03426                 NameAST::Node name;
03427                 if( !parseName(name) ){
03428                     return false;
03429                 }
03430             }
03431             break;
03432 
03433     case Token_typename:
03434         {
03435         lex->nextToken();
03436 
03437         NameAST::Node name;
03438         if( !parseName(name) ){
03439             return false;
03440         }
03441 
03442         CHECK( '(', "(" );
03443         AST::Node expr;
03444         parseCommaExpression(expr);
03445         CHECK( ')', ")" );
03446         }
03447         return true;
03448 
03449     default:
03450         return true;
03451 
03452     } // end switch
03453 
03454     } // end while
03455 
03456     return true;
03457 }
03458 
03459 bool Parser::parseUnaryExpression( AST::Node& node )
03460 {
03461     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseUnaryExpression()" << endl;
03462 
03463     switch( lex->lookAhead(0) ){
03464         case Token_incr:
03465         case Token_decr:
03466         case '*':
03467         case '&':
03468         case '+':
03469         case '-':
03470         case '!':
03471         case '~':
03472     {
03473             lex->nextToken();
03474         AST::Node expr;
03475             return parseCastExpression( expr );
03476     }
03477 
03478         case Token_sizeof:
03479     {
03480             lex->nextToken();
03481         int index = lex->index();
03482             if( lex->lookAhead(0) == '(' ){
03483                 lex->nextToken();
03484         AST::Node typeId;
03485         if( parseTypeId(typeId) && lex->lookAhead(0) == ')' ){
03486             lex->nextToken();
03487             return true;
03488         }
03489         lex->setIndex( index );
03490             }
03491         AST::Node expr;
03492         return parseUnaryExpression( expr );
03493     }
03494 
03495         case Token_new:
03496             return parseNewExpression( node );
03497 
03498         case Token_delete:
03499             return parseDeleteExpression( node );
03500     }
03501 
03502     return parsePostfixExpression( node );
03503 }
03504 
03505 bool Parser::parseNewExpression( AST::Node& /*node*/ )
03506 {
03507     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseNewExpression()" << endl;
03508     if( lex->lookAhead(0) == Token_scope && lex->lookAhead(1) == Token_new )
03509         lex->nextToken();
03510 
03511     CHECK( Token_new, "new");
03512 
03513     if( lex->lookAhead(0) == '(' ){
03514         lex->nextToken();
03515     AST::Node expr;
03516         parseCommaExpression( expr );
03517         CHECK( ')', ")" );
03518     }
03519 
03520     if( lex->lookAhead(0) == '(' ){
03521         lex->nextToken();
03522     AST::Node typeId;
03523         parseTypeId( typeId );
03524         CHECK( ')', ")" );
03525     } else {
03526     AST::Node typeId;
03527         parseNewTypeId( typeId );
03528     }
03529 
03530     AST::Node init;
03531     parseNewInitializer( init );
03532     return true;
03533 }
03534 
03535 bool Parser::parseNewTypeId( AST::Node& /*node*/ )
03536 {
03537     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseNewTypeId()" << endl;
03538     TypeSpecifierAST::Node typeSpec;
03539     if( parseTypeSpecifier(typeSpec) ){
03540     AST::Node declarator;
03541         parseNewDeclarator( declarator );
03542         return true;
03543     }
03544 
03545     return false;
03546 }
03547 
03548 bool Parser::parseNewDeclarator( AST::Node& /*node*/ )
03549 {
03550     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseNewDeclarator()" << endl;
03551     AST::Node ptrOp;
03552     if( parsePtrOperator(ptrOp) ){
03553     AST::Node declarator;
03554         parseNewDeclarator( declarator );
03555         return true;
03556     }
03557 
03558     if( lex->lookAhead(0) == '[' ){
03559         while( lex->lookAhead(0) == '[' ){
03560             lex->nextToken();
03561         AST::Node expr;
03562             parseExpression( expr );
03563             ADVANCE( ']', "]" );
03564         }
03565         return true;
03566     }
03567 
03568     return false;
03569 }
03570 
03571 bool Parser::parseNewInitializer( AST::Node& /*node*/ )
03572 {
03573     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseNewInitializer()" << endl;
03574     if( lex->lookAhead(0) != '(' )
03575         return false;
03576 
03577     lex->nextToken();
03578     AST::Node expr;
03579     parseCommaExpression( expr );
03580     CHECK( ')', ")" );
03581 
03582     return true;
03583 }
03584 
03585 bool Parser::parseDeleteExpression( AST::Node& /*node*/ )
03586 {
03587     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseDeleteExpression()" << endl;
03588     if( lex->lookAhead(0) == Token_scope && lex->lookAhead(1) == Token_delete )
03589         lex->nextToken();
03590 
03591     CHECK( Token_delete, "delete" );
03592 
03593     if( lex->lookAhead(0) == '[' ){
03594         lex->nextToken();
03595         CHECK( ']', "]" );
03596     }
03597 
03598     AST::Node expr;
03599     return parseCastExpression( expr );
03600 }
03601 
03602 bool Parser::parseCastExpression( AST::Node& /*node*/ )
03603 {
03604     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCastExpression()" << endl;
03605 
03606     int index = lex->index();
03607 
03608     if( lex->lookAhead(0) == '(' ){
03609         lex->nextToken();
03610     AST::Node typeId;
03611         if ( parseTypeId(typeId) ) {
03612             if ( lex->lookAhead(0) == ')' ) {
03613                 lex->nextToken();
03614         AST::Node expr;
03615                 if( parseCastExpression(expr) )
03616             return true;
03617             }
03618         }
03619     }
03620 
03621     lex->setIndex( index );
03622 
03623     AST::Node expr;
03624     return parseUnaryExpression( expr );
03625 }
03626 
03627 bool Parser::parsePmExpression( AST::Node& /*node*/ )
03628 {
03629     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser:parsePmExpression()" << endl;
03630     AST::Node expr;
03631     if( !parseCastExpression(expr) )
03632         return false;
03633 
03634     while( lex->lookAhead(0) == Token_ptrmem ){
03635         lex->nextToken();
03636 
03637         if( !parseCastExpression(expr) )
03638             return false;
03639     }
03640 
03641     return true;
03642 }
03643 
03644 bool Parser::parseMultiplicativeExpression( AST::Node& /*node*/ )
03645 {
03646     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseMultiplicativeExpression()" << endl;
03647     AST::Node expr;
03648     if( !parsePmExpression(expr) )
03649         return false;
03650 
03651     while( lex->lookAhead(0) == '*' || lex->lookAhead(0) == '/' || lex->lookAhead(0) == '%' ){
03652         lex->nextToken();
03653 
03654         if( !parsePmExpression(expr) )
03655             return false;
03656     }
03657 
03658     return true;
03659 }
03660 
03661 
03662 bool Parser::parseAdditiveExpression( AST::Node& /*node*/ )
03663 {
03664     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseAdditiveExpression()" << endl;
03665     AST::Node expr;
03666     if( !parseMultiplicativeExpression(expr) )
03667         return false;
03668 
03669     while( lex->lookAhead(0) == '+' || lex->lookAhead(0) == '-' ){
03670         lex->nextToken();
03671 
03672         if( !parseMultiplicativeExpression(expr) )
03673             return false;
03674     }
03675 
03676     return true;
03677 }
03678 
03679 bool Parser::parseShiftExpression( AST::Node& /*node*/ )
03680 {
03681     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseShiftExpression()" << endl;
03682     AST::Node expr;
03683     if( !parseAdditiveExpression(expr) )
03684         return false;
03685 
03686     while( lex->lookAhead(0) == Token_shift ){
03687         lex->nextToken();
03688 
03689         if( !parseAdditiveExpression(expr) )
03690             return false;
03691     }
03692 
03693     return true;
03694 }
03695 
03696 bool Parser::parseRelationalExpression( AST::Node& /*node*/, bool templArgs )
03697 {
03698     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseRelationalExpression()" << endl;
03699     AST::Node expr;
03700     if( !parseShiftExpression(expr) )
03701         return false;
03702 
03703     while( lex->lookAhead(0) == '<' || (lex->lookAhead(0) == '>' && !templArgs) ||
03704            lex->lookAhead(0) == Token_leq || lex->lookAhead(0) == Token_geq ){
03705         lex->nextToken();
03706 
03707         if( !parseShiftExpression(expr) )
03708             return false;
03709     }
03710 
03711     return true;
03712 }
03713 
03714 bool Parser::parseEqualityExpression( AST::Node& /*node*/, bool templArgs )
03715 {
03716     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseEqualityExpression()" << endl;
03717     AST::Node expr;
03718     if( !parseRelationalExpression(expr, templArgs) )
03719         return false;
03720 
03721     while( lex->lookAhead(0) == Token_eq || lex->lookAhead(0) == Token_not_eq ){
03722         lex->nextToken();
03723 
03724         if( !parseRelationalExpression(expr, templArgs) )
03725             return false;
03726     }
03727 
03728     return true;
03729 }
03730 
03731 bool Parser::parseAndExpression( AST::Node& /*node*/, bool templArgs )
03732 {
03733     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseAndExpression()" << endl;
03734     AST::Node expr;
03735     if( !parseEqualityExpression(expr, templArgs) )
03736         return false;
03737 
03738     while( lex->lookAhead(0) == '&' ){
03739         lex->nextToken();
03740 
03741         if( !parseEqualityExpression(expr, templArgs) )
03742             return false;
03743     }
03744 
03745     return true;
03746 }
03747 
03748 bool Parser::parseExclusiveOrExpression( AST::Node& /*node*/, bool templArgs )
03749 {
03750     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseExclusiveOrExpression()" << endl;
03751     AST::Node expr;
03752     if( !parseAndExpression(expr, templArgs) )
03753         return false;
03754 
03755     while( lex->lookAhead(0) == '^' ){
03756         lex->nextToken();
03757 
03758         if( !parseAndExpression(expr, templArgs) )
03759             return false;
03760     }
03761 
03762     return true;
03763 }
03764 
03765 bool Parser::parseInclusiveOrExpression( AST::Node& /*node*/, bool templArgs )
03766 {
03767     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseInclusiveOrExpression()" << endl;
03768     AST::Node expr;
03769     if( !parseExclusiveOrExpression(expr, templArgs) )
03770         return false;
03771 
03772     while( lex->lookAhead(0) == '|' ){
03773         lex->nextToken();
03774 
03775         if( !parseExclusiveOrExpression(expr, templArgs) )
03776             return false;
03777     }
03778 
03779     return true;
03780 }
03781 
03782 bool Parser::parseLogicalAndExpression( AST::Node& /*node*/, bool templArgs )
03783 {
03784     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseLogicalAndExpression()" << endl;
03785 
03786     AST::Node expr;
03787     if( !parseInclusiveOrExpression(expr, templArgs) )
03788         return false;
03789 
03790     while( lex->lookAhead(0) == Token_and ){
03791         lex->nextToken();
03792 
03793         if( !parseInclusiveOrExpression(expr, templArgs) )
03794             return false;
03795     }
03796 
03797     return true;
03798 }
03799 
03800 bool Parser::parseLogicalOrExpression( AST::Node& node, bool templArgs )
03801 {
03802     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseLogicalOrExpression()" << endl;
03803 
03804     int start = lex->index();
03805 
03806     AST::Node expr;
03807     if( !parseLogicalAndExpression(expr, templArgs) )
03808         return false;
03809 
03810     while( lex->lookAhead(0) == Token_or ){
03811         lex->nextToken();
03812 
03813         if( !parseLogicalAndExpression(expr, templArgs) )
03814             return false;
03815     }
03816 
03817     AST::Node ast = CreateNode<AST>();
03818     UPDATE_POS( ast, start, lex->index() );
03819     node = ast;
03820     return true;
03821 }
03822 
03823 bool Parser::parseConditionalExpression( AST::Node& /*node*/ )
03824 {
03825     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseConditionalExpression()" << endl;
03826     AST::Node expr;
03827     if( !parseLogicalOrExpression(expr) )
03828         return false;
03829 
03830     if( lex->lookAhead(0) == '?' ){
03831         lex->nextToken();
03832 
03833         if( !parseExpression(expr) )
03834         return false;
03835 
03836         CHECK( ':', ":" );
03837 
03838         if( !parseAssignmentExpression(expr) )
03839         return false;
03840     }
03841 
03842     return true;
03843 }
03844 
03845 bool Parser::parseAssignmentExpression( AST::Node& node )
03846 {
03847     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseAssignmentExpression()" << endl;
03848     int start = lex->index();
03849     AST::Node expr;
03850     if( lex->lookAhead(0) == Token_throw && !parseThrowExpression(expr) )
03851         return false;
03852     else if( !parseConditionalExpression(expr) )
03853         return false;
03854 
03855     while( lex->lookAhead(0) == Token_assign || lex->lookAhead(0) == '=' ){
03856         lex->nextToken();
03857 
03858         if( !parseConditionalExpression(expr) )
03859             return false;
03860     }
03861 
03862     AST::Node ast = CreateNode<AST>();
03863     UPDATE_POS( ast, start, lex->index() );
03864     node = ast;
03865     return true;
03866 }
03867 
03868 bool Parser::parseConstantExpression( AST::Node& node )
03869 {
03870     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseConstantExpression()" << endl;
03871     int start = lex->index();
03872     if( parseConditionalExpression(node) ){
03873     AST::Node ast = CreateNode<AST>();
03874     UPDATE_POS( ast, start, lex->index() );
03875     node = ast;
03876     return true;
03877     }
03878     return false;
03879 }
03880 
03881 bool Parser::parseExpression( AST::Node& node )
03882 {
03883     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseExpression()" << endl;
03884 
03885     int start = lex->index();
03886 
03887     if( !parseCommaExpression(node) )
03888         return false;
03889 
03890     AST::Node ast = CreateNode<AST>();
03891     UPDATE_POS( ast, start, lex->index() );
03892     node = ast;
03893     return true;
03894 }
03895 
03896 bool Parser::parseCommaExpression( AST::Node& node )
03897 {
03898     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseCommaExpression()" << endl;
03899     int start = lex->index();
03900 
03901     AST::Node expr;
03902     if( !parseAssignmentExpression(expr) )
03903         return false;
03904 
03905     QString comment;
03906     while( lex->lookAhead(0) == ',' ){
03907     comment = QString::null;
03908     advanceAndCheckTrailingComment( comment );
03909 
03910         if( !parseAssignmentExpression(expr) )
03911             return false;
03912     if (!comment.isEmpty())
03913         expr->setComment(comment);
03914     }
03915 
03916     AST::Node ast = CreateNode<AST>();
03917     UPDATE_POS( ast, start, lex->index() );
03918     node = ast;
03919     return true;
03920 }
03921 
03922 bool Parser::parseThrowExpression( AST::Node& /*node*/ )
03923 {
03924     //kdDebug(9007)<< "--- tok = " << lex->lookAhead(0).text() << " -- "  << "Parser::parseThrowExpression()" << endl;
03925     if( lex->lookAhead(0) != Token_throw )
03926         return false;
03927 
03928     CHECK( Token_throw, "throw" );
03929     AST::Node expr;
03930     if( !parseAssignmentExpression(expr) )
03931         return false;
03932 
03933     return true;
03934 }
03935 
03936 bool Parser::parseIvarDeclList( AST::Node & node )
03937 {
03938     Q_UNUSED( node );
03939     return false;
03940 }
03941 
03942 bool Parser::parseIvarDecls( AST::Node & node )
03943 {
03944     Q_UNUSED( node );
03945     return false;
03946 }
03947 
03948 bool Parser::parseIvarDecl( AST::Node & node )
03949 {
03950     Q_UNUSED( node );
03951     return false;
03952 }
03953 
03954 bool Parser::parseIvars( AST::Node & node )
03955 {
03956     Q_UNUSED( node );
03957     return false;
03958 }
03959 
03960 bool Parser::parseIvarDeclarator( AST::Node & node )
03961 {
03962     Q_UNUSED( node );
03963     return false;
03964 }
03965 
03966 bool Parser::parseMethodDecl( AST::Node & node )
03967 {
03968     Q_UNUSED( node );
03969     return false;
03970 }
03971 
03972 bool Parser::parseUnarySelector( AST::Node & node )
03973 {
03974     Q_UNUSED( node );
03975     return false;
03976 }
03977 
03978 bool Parser::parseKeywordSelector( AST::Node & node )
03979 {
03980     Q_UNUSED( node );
03981     return false;
03982 }
03983 
03984 bool Parser::parseSelector( AST::Node & node )
03985 {
03986     Q_UNUSED( node );
03987     return false;
03988 }
03989 
03990 bool Parser::parseKeywordDecl( AST::Node & node )
03991 {
03992     Q_UNUSED( node );
03993     return false;
03994 }
03995 
03996 bool Parser::parseReceiver( AST::Node & node )
03997 {
03998     Q_UNUSED( node );
03999     return false;
04000 }
04001 
04002 bool Parser::parseObjcMessageExpr( AST::Node & node )
04003 {
04004     Q_UNUSED( node );
04005     return false;
04006 }
04007 
04008 bool Parser::parseMessageArgs( AST::Node & node )
04009 {
04010     Q_UNUSED( node );
04011     return false;
04012 }
04013 
04014 bool Parser::parseKeywordExpr( AST::Node & node )
04015 {
04016     Q_UNUSED( node );
04017     return false;
04018 }
04019 
04020 bool Parser::parseKeywordArgList( AST::Node & node )
04021 {
04022     Q_UNUSED( node );
04023     return false;
04024 }
04025 
04026 bool Parser::parseKeywordArg( AST::Node & node )
04027 {
04028     Q_UNUSED( node );
04029     return false;
04030 }
04031 
04032 bool Parser::parseReservedWord( AST::Node & node )
04033 {
04034     Q_UNUSED( node );
04035     return false;
04036 }
04037 
04038 bool Parser::parseMyParms( AST::Node & node )
04039 {
04040     Q_UNUSED( node );
04041     return false;
04042 }
04043 
04044 bool Parser::parseMyParm( AST::Node & node )
04045 {
04046     Q_UNUSED( node );
04047     return false;
04048 }
04049 
04050 bool Parser::parseOptParmList( AST::Node & node )
04051 {
04052     Q_UNUSED( node );
04053     return false;
04054 }
04055 
04056 bool Parser::parseObjcSelectorExpr( AST::Node & node )
04057 {
04058     Q_UNUSED( node );
04059     return false;
04060 }
04061 
04062 bool Parser::parseSelectorArg( AST::Node & node )
04063 {
04064     Q_UNUSED( node );
04065     return false;
04066 }
04067 
04068 bool Parser::parseKeywordNameList( AST::Node & node )
04069 {
04070     Q_UNUSED( node );
04071     return false;
04072 }
04073 
04074 bool Parser::parseKeywordName( AST::Node & node )
04075 {
04076     Q_UNUSED( node );
04077     return false;
04078 }
04079 
04080 bool Parser::parseObjcEncodeExpr( AST::Node & node )
04081 {
04082     Q_UNUSED( node );
04083     return false;
04084 }
04085 
04086 bool Parser::parseObjcString( AST::Node & node )
04087 {
04088     Q_UNUSED( node );
04089     return false;
04090 }
04091 
04092 bool Parser::parseProtocolRefs( AST::Node & node )
04093 {
04094     Q_UNUSED( node );
04095     return false;
04096 }
04097 
04098 bool Parser::parseIdentifierList( GroupAST::Node & node )
04099 {
04100     int start = lex->index();
04101 
04102     if( lex->lookAhead(0) != Token_identifier )
04103     return false;
04104 
04105     GroupAST::Node ast = CreateNode<GroupAST>();
04106 
04107     AST_FROM_TOKEN( tk, lex->index() );
04108     ast->addNode( tk );
04109     lex->nextToken();
04110 
04111     QString comment;
04112     while( lex->lookAhead(0) == ',' ){
04113     comment = QString::null;
04114     advanceAndCheckTrailingComment( comment );
04115     if( lex->lookAhead(0) == Token_identifier ){
04116         AST_FROM_TOKEN( tk, lex->index() );
04117         ast->addNode( tk );
04118         lex->nextToken();
04119     }
04120     ADVANCE( Token_identifier, "identifier" );
04121     }
04122 
04123     node = ast;
04124     UPDATE_POS( node, start, lex->index() );
04125     return true;
04126 }
04127 
04128 bool Parser::parseIdentifierColon( AST::Node & node )
04129 {
04130     Q_UNUSED( node );
04131 
04132     if( lex->lookAhead(0) == Token_identifier && lex->lookAhead(1) == ':' ){
04133     lex->nextToken();
04134     lex->nextToken();
04135     return true;
04136     } // ### else if PTYPENAME -> return true ;
04137 
04138     return false;
04139 }
04140 
04141 bool Parser::parseObjcProtocolExpr( AST::Node & node )
04142 {
04143     Q_UNUSED( node );
04144     return false;
04145 }
04146 
04147 bool Parser::parseObjcOpenBracketExpr( AST::Node & node )
04148 {
04149     Q_UNUSED( node );
04150     return false;
04151 }
04152 
04153 bool Parser::parseObjcCloseBracket( AST::Node & node )
04154 {
04155     Q_UNUSED( node );
04156     return false;
04157 }
04158 
04159 bool Parser::parseObjcDef( DeclarationAST::Node & node )
04160 {
04161     Q_UNUSED( node );
04162     return false;
04163 }
04164 
04165 bool Parser::parseObjcClassDef( DeclarationAST::Node & node )
04166 {
04167     Q_UNUSED( node );
04168     return false;
04169 }
04170 
04171 bool Parser::parseObjcClassDecl( DeclarationAST::Node & node )
04172 {
04173     Q_UNUSED( node );
04174 
04175     ADVANCE( OBJC_CLASS, "@class" );
04176 
04177     GroupAST::Node idList;
04178     parseIdentifierList( idList );
04179     ADVANCE( ';', ";" );
04180 
04181     return true;
04182 }
04183 
04184 bool Parser::parseObjcProtocolDecl( DeclarationAST::Node & node )
04185 {
04186     Q_UNUSED( node );
04187 
04188     ADVANCE( OBJC_PROTOCOL, "@protocol" );
04189 
04190     GroupAST::Node idList;
04191     parseIdentifierList( idList );
04192     ADVANCE( ';', ";" );
04193 
04194     return true;
04195 }
04196 
04197 bool Parser::parseObjcAliasDecl( DeclarationAST::Node & node )
04198 {
04199     Q_UNUSED( node );
04200 
04201     ADVANCE( OBJC_ALIAS, "@alias" );
04202 
04203     GroupAST::Node idList;
04204     parseIdentifierList( idList );
04205     ADVANCE( ';', ";" );
04206 
04207     return true;
04208 }
04209 
04210 bool Parser::parseObjcProtocolDef( DeclarationAST::Node & node )
04211 {
04212     Q_UNUSED( node );
04213     return false;
04214 }
04215 
04216 bool Parser::parseObjcMethodDef( DeclarationAST::Node & node )
04217 {
04218     Q_UNUSED( node );
04219     return false;
04220 }
04221 
04222 bool Parser::parseWinDeclSpec( GroupAST::Node & node )
04223 {
04224     if( lex->lookAhead(0) == Token_identifier && lex->lookAhead(0).text() == "__declspec" && lex->lookAhead(1) == '(' ){
04225     int start = lex->index();
04226     lex->nextToken();
04227     lex->nextToken(); // skip '('
04228 
04229     parseIdentifierList( node );
04230     ADVANCE( ')', ")" );
04231 
04232     UPDATE_POS( node, start, lex->index() );
04233     return true;
04234     }
04235 
04236     return false;
04237 }
04238 
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:59 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003