1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the tools applications of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
44 #include "qsakernelparser.h"
45 #include "tokenizer.h"
50 QsaKernelParser::QsaKernelParser( Tree
*cppTree
)
55 QsaKernelParser::~QsaKernelParser()
59 QString
QsaKernelParser::language()
61 return "QSA Kernel C++";
64 QString
QsaKernelParser::sourceFileNameFilter()
69 void QsaKernelParser::parseSourceFile( const Location
& location
,
70 const QString
& filePath
,
73 FILE *in
= fopen( QFile::encodeName(filePath
), "r" );
75 location
.error( tr("Cannot open QSA kernel file '%1'").arg(filePath
) );
79 Location
fileLocation( filePath
);
80 Tokenizer
fileTokenizer( fileLocation
, in
);
81 tokenizer
= &fileTokenizer
;
88 while ( tok
!= Tok_Eoi
) {
89 if ( tok
== Tok_Ident
) {
90 ident
= tokenizer
->lexeme();
92 if ( tok
== Tok_Gulbrandsen
&& tokenizer
->braceDepth() == 0 &&
93 tokenizer
->parenDepth() == 0 ) {
95 } else if ( ident
.startsWith("add") && ident
.endsWith("Member") &&
96 tok
== Tok_LeftParen
) {
97 bool isProperty
= ident
.endsWith( "VariableMember" );
98 bool isStatic
= ident
.startsWith( "addStatic" );
99 bool isWritable
= !isStatic
;
102 if ( tok
== Tok_String
) {
103 QString member
= tokenizer
->lexeme();
104 member
= member
.mid( 1, member
.length() - 2 );
107 if ( tok
== Tok_Comma
)
109 if ( tok
== Tok_Ident
&& tokenizer
->lexeme() == "QSMember" )
111 if ( tok
== Tok_LeftParen
) {
116 while ( tok
!= Tok_Eoi
&& tok
!= Tok_RightParen
&&
117 tok
!= Tok_Semicolon
) {
118 if ( tok
== Tok_Ident
) {
119 ident
= tokenizer
->lexeme();
120 if ( ident
== "Custom" ) {
122 } else if ( ident
== "AttributeNonWritable" ) {
124 } else if ( ident
== "AttributeStatic" ) {
132 (ClassNode
*) cppTre
->findNode( QStringList(className
),
135 classe
= new ClassNode( cppTre
->root(), className
);
136 classe
->setLocation( tokenizer
->location() );
140 PropertyNode
*property
= new PropertyNode(classe
, member
);
141 property
->setLocation( tokenizer
->location() );
142 property
->setDataType( "Object" );
144 property
->setGetter( member
);
146 QString setter
= member
;
147 setter
[0] = setter
[0].toUpper();
148 setter
.prepend( "set" );
149 property
->setSetter( setter
);
153 FunctionNode
*func
= new FunctionNode( classe
, member
);
154 func
->setLocation( tokenizer
->location() );
155 func
->setAccess( FunctionNode::Public
);
156 func
->setMetaness( FunctionNode::Slot
);
157 if ( member
== "toLocaleString" ||
158 member
== "toString" ) {
159 func
->setReturnType( "QString" );
160 } else if ( member
== "valueOf" ) {
161 func
->setReturnType( "Object" );
163 func
->setReturnType( "Object" );
164 func
->addParameter( Parameter("...") );
166 func
->setStatic( false ); // ###
177 void QsaKernelParser::doneParsingSourceFiles( Tree
* /* tree */ )
181 void QsaKernelParser::readToken()
183 tok
= tokenizer
->getToken();