source: trunk/tools/qdoc3/qsakernelparser.cpp@ 99

Last change on this file since 99 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <qfile.h>
43
44#include "qsakernelparser.h"
45#include "tokenizer.h"
46#include "tree.h"
47
48QT_BEGIN_NAMESPACE
49
50QsaKernelParser::QsaKernelParser( Tree *cppTree )
51 : cppTre( cppTree )
52{
53}
54
55QsaKernelParser::~QsaKernelParser()
56{
57}
58
59QString QsaKernelParser::language()
60{
61 return "QSA Kernel C++";
62}
63
64QString QsaKernelParser::sourceFileNameFilter()
65{
66 return "*.cpp";
67}
68
69void QsaKernelParser::parseSourceFile( const Location& location,
70 const QString& filePath,
71 Tree * /* tree */ )
72{
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;
77 }
78
79 Location fileLocation( filePath );
80 Tokenizer fileTokenizer( fileLocation, in );
81 tokenizer = &fileTokenizer;
82 readToken();
83
84 QString ident;
85 QString className;
86 int delimDepth = 0;
87
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;
100
101 readToken();
102 if ( tok == Tok_String ) {
103 QString member = tokenizer->lexeme();
104 member = member.mid( 1, member.length() - 2 );
105
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();
114 }
115
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;
126 }
127 }
128 readToken();
129 }
130
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() );
137 }
138
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 );
150 }
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("...") );
165 }
166 func->setStatic( false ); // ###
167 }
168 }
169 }
170 } else {
171 readToken();
172 }
173 }
174 fclose( in );
175}
176
177void QsaKernelParser::doneParsingSourceFiles( Tree * /* tree */ )
178{
179}
180
181void QsaKernelParser::readToken()
182{
183 tok = tokenizer->getToken();
184}
185
186QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.