author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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. |
|
15 |
** |
|
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. |
|
23 |
** |
|
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. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
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 |
||
48 |
QT_BEGIN_NAMESPACE |
|
49 |
||
50 |
QsaKernelParser::QsaKernelParser( Tree *cppTree ) |
|
51 |
: cppTre( cppTree ) |
|
52 |
{ |
|
53 |
} |
|
54 |
||
55 |
QsaKernelParser::~QsaKernelParser() |
|
56 |
{ |
|
57 |
} |
|
58 |
||
59 |
QString QsaKernelParser::language() |
|
60 |
{ |
|
61 |
return "QSA Kernel C++"; |
|
62 |
} |
|
63 |
||
64 |
QString QsaKernelParser::sourceFileNameFilter() |
|
65 |
{ |
|
66 |
return "*.cpp"; |
|
67 |
} |
|
68 |
||
69 |
void 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 |
||
177 |
void QsaKernelParser::doneParsingSourceFiles( Tree * /* tree */ ) |
|
178 |
{ |
|
179 |
} |
|
180 |
||
181 |
void QsaKernelParser::readToken() |
|
182 |
{ |
|
183 |
tok = tokenizer->getToken(); |
|
184 |
} |
|
185 |
||
186 |
QT_END_NAMESPACE |