Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
[qt-netbsd.git] / tools / qdoc3 / qsakernelparser.cpp
blob9320a178cb6e7149004e5bbf0d9d5d417059fc53
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the tools applications of the Qt Toolkit.
8 **
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
14 ** this package.
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.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #include <qfile.h>
44 #include "qsakernelparser.h"
45 #include "tokenizer.h"
46 #include "tree.h"
48 QT_BEGIN_NAMESPACE
50 QsaKernelParser::QsaKernelParser( Tree *cppTree )
51 : cppTre( cppTree )
55 QsaKernelParser::~QsaKernelParser()
59 QString QsaKernelParser::language()
61 return "QSA Kernel C++";
64 QString QsaKernelParser::sourceFileNameFilter()
66 return "*.cpp";
69 void QsaKernelParser::parseSourceFile( const Location& location,
70 const QString& filePath,
71 Tree * /* tree */ )
73 FILE *in = fopen( QFile::encodeName(filePath), "r" );
74 if ( in == 0 ) {
75 location.error( tr("Cannot open QSA kernel file '%1'").arg(filePath) );
76 return;
79 Location fileLocation( filePath );
80 Tokenizer fileTokenizer( fileLocation, in );
81 tokenizer = &fileTokenizer;
82 readToken();
84 QString ident;
85 QString className;
86 int delimDepth = 0;
88 while ( tok != Tok_Eoi ) {
89 if ( tok == Tok_Ident ) {
90 ident = tokenizer->lexeme();
91 readToken();
92 if ( tok == Tok_Gulbrandsen && tokenizer->braceDepth() == 0 &&
93 tokenizer->parenDepth() == 0 ) {
94 className = ident;
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;
101 readToken();
102 if ( tok == Tok_String ) {
103 QString member = tokenizer->lexeme();
104 member = member.mid( 1, member.length() - 2 );
106 readToken();
107 if ( tok == Tok_Comma )
108 readToken();
109 if ( tok == Tok_Ident && tokenizer->lexeme() == "QSMember" )
110 readToken();
111 if ( tok == Tok_LeftParen ) {
112 delimDepth++;
113 readToken();
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" ) {
121 isProperty = true;
122 } else if ( ident == "AttributeNonWritable" ) {
123 isWritable = false;
124 } else if ( ident == "AttributeStatic" ) {
125 isStatic = true;
128 readToken();
131 ClassNode *classe =
132 (ClassNode *) cppTre->findNode( QStringList(className),
133 Node::Class );
134 if ( classe == 0 ) {
135 classe = new ClassNode( cppTre->root(), className );
136 classe->setLocation( tokenizer->location() );
139 if ( isProperty ) {
140 PropertyNode *property = new PropertyNode(classe, member);
141 property->setLocation( tokenizer->location() );
142 property->setDataType( "Object" );
143 #if 0
144 property->setGetter( member );
145 if ( isWritable ) {
146 QString setter = member;
147 setter[0] = setter[0].toUpper();
148 setter.prepend( "set" );
149 property->setSetter( setter );
151 #endif
152 } else {
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" );
162 } else {
163 func->setReturnType( "Object" );
164 func->addParameter( Parameter("...") );
166 func->setStatic( false ); // ###
170 } else {
171 readToken();
174 fclose( in );
177 void QsaKernelParser::doneParsingSourceFiles( Tree * /* tree */ )
181 void QsaKernelParser::readToken()
183 tok = tokenizer->getToken();
186 QT_END_NAMESPACE