@@ -1,377 +1,380 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 | ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Script Generator project on Qt Labs. |
|
7 | ** This file is part of the Qt Script Generator project on Qt Labs. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE:LGPL$ |
|
9 | ** $QT_BEGIN_LICENSE:LGPL$ | |
10 | ** No Commercial Usage |
|
10 | ** No Commercial Usage | |
11 | ** This file contains pre-release code and may not be distributed. |
|
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 |
|
12 | ** You may use this file in accordance with the terms and conditions | |
13 | ** contained in the Technology Preview License Agreement accompanying |
|
13 | ** contained in the Technology Preview License Agreement accompanying | |
14 | ** this package. |
|
14 | ** this package. | |
15 | ** |
|
15 | ** | |
16 | ** GNU Lesser General Public License Usage |
|
16 | ** GNU Lesser General Public License Usage | |
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
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 |
|
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 |
|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | |
20 | ** packaging of this file. Please review the following information to |
|
20 | ** packaging of this file. Please review the following information to | |
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
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. |
|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
23 | ** |
|
23 | ** | |
24 | ** In addition, as a special exception, Nokia gives you certain additional |
|
24 | ** In addition, as a special exception, Nokia gives you certain additional | |
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
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. |
|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
27 | ** |
|
27 | ** | |
28 | ** If you have questions regarding the use of this file, please contact |
|
28 | ** If you have questions regarding the use of this file, please contact | |
29 | ** Nokia at qt-info@nokia.com. |
|
29 | ** Nokia at qt-info@nokia.com. | |
30 | ** |
|
30 | ** | |
31 | ** |
|
31 | ** | |
32 | ** |
|
32 | ** | |
33 | ** |
|
33 | ** | |
34 | ** |
|
34 | ** | |
35 | ** |
|
35 | ** | |
36 | ** |
|
36 | ** | |
37 | ** |
|
37 | ** | |
38 | ** $QT_END_LICENSE$ |
|
38 | ** $QT_END_LICENSE$ | |
39 | ** |
|
39 | ** | |
40 | ****************************************************************************/ |
|
40 | ****************************************************************************/ | |
41 |
|
41 | |||
42 | #include "shellgenerator.h" |
|
42 | #include "shellgenerator.h" | |
43 | #include "reporthandler.h" |
|
43 | #include "reporthandler.h" | |
44 |
|
44 | |||
45 | #include "metaqtscript.h" |
|
45 | #include "metaqtscript.h" | |
46 |
|
46 | |||
47 | bool ShellGenerator::shouldGenerate(const AbstractMetaClass *meta_class) const |
|
47 | bool ShellGenerator::shouldGenerate(const AbstractMetaClass *meta_class) const | |
48 | { |
|
48 | { | |
49 | uint cg = meta_class->typeEntry()->codeGeneration(); |
|
49 | uint cg = meta_class->typeEntry()->codeGeneration(); | |
50 | if (meta_class->name().startsWith("QtScript")) return false; |
|
50 | if (meta_class->name().startsWith("QtScript")) return false; | |
51 | if (meta_class->name().startsWith("QFuture")) return false; |
|
51 | if (meta_class->name().startsWith("QFuture")) return false; | |
52 | if (meta_class->name().startsWith("Global")) return false; |
|
52 | if (meta_class->name().startsWith("Global")) return false; | |
53 | if (meta_class->name().startsWith("QStyleOptionComplex")) return false; |
|
53 | if (meta_class->name().startsWith("QStyleOptionComplex")) return false; | |
54 | if (meta_class->name().startsWith("QTextLayout")) return false; |
|
54 | if (meta_class->name().startsWith("QTextLayout")) return false; | |
55 | //if (meta_class->name().startsWith("QTextStream")) return false; // because of >> operators |
|
55 | //if (meta_class->name().startsWith("QTextStream")) return false; // because of >> operators | |
56 | //if (meta_class->name().startsWith("QDataStream")) return false; // " |
|
56 | //if (meta_class->name().startsWith("QDataStream")) return false; // " | |
57 | return ((cg & TypeEntry::GenerateCode) != 0); |
|
57 | return ((cg & TypeEntry::GenerateCode) != 0); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void ShellGenerator::writeTypeInfo(QTextStream &s, const AbstractMetaType *type, Option options) |
|
60 | void ShellGenerator::writeTypeInfo(QTextStream &s, const AbstractMetaType *type, Option options) | |
61 | { |
|
61 | { | |
62 | if ((options & OriginalTypeDescription) && !type->originalTypeDescription().isEmpty()) { |
|
62 | if ((options & OriginalTypeDescription) && !type->originalTypeDescription().isEmpty()) { | |
63 | s << type->originalTypeDescription(); |
|
63 | s << type->originalTypeDescription(); | |
64 | return; |
|
64 | return; | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | if (type->isArray()) { |
|
67 | if (type->isArray()) { | |
68 | writeTypeInfo(s, type->arrayElementType(), options); |
|
68 | writeTypeInfo(s, type->arrayElementType(), options); | |
69 | if (options & ArrayAsPointer) { |
|
69 | if (options & ArrayAsPointer) { | |
70 | s << "*"; |
|
70 | s << "*"; | |
71 | } else { |
|
71 | } else { | |
72 | s << "[" << type->arrayElementCount() << "]"; |
|
72 | s << "[" << type->arrayElementCount() << "]"; | |
73 | } |
|
73 | } | |
74 | return; |
|
74 | return; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | const TypeEntry *te = type->typeEntry(); |
|
77 | const TypeEntry *te = type->typeEntry(); | |
78 |
|
78 | |||
79 | if (type->isConstant() && !(options & ExcludeConst)) |
|
79 | if (type->isConstant() && !(options & ExcludeConst)) | |
80 | s << "const "; |
|
80 | s << "const "; | |
81 |
|
81 | |||
82 | if ((options & EnumAsInts) && (te->isEnum() || te->isFlags())) { |
|
82 | if ((options & EnumAsInts) && (te->isEnum() || te->isFlags())) { | |
83 | s << "int"; |
|
83 | s << "int"; | |
84 | } else if (te->isFlags()) { |
|
84 | } else if (te->isFlags()) { | |
85 | s << ((FlagsTypeEntry *) te)->originalName(); |
|
85 | s << ((FlagsTypeEntry *) te)->originalName(); | |
86 | } else { |
|
86 | } else { | |
87 | s << fixCppTypeName(te->qualifiedCppName()); |
|
87 | s << fixCppTypeName(te->qualifiedCppName()); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | if (type->instantiations().size() > 0 |
|
90 | if (type->instantiations().size() > 0 | |
91 | && (!type->isContainer() |
|
91 | && (!type->isContainer() | |
92 | || (static_cast<const ContainerTypeEntry *>(te))->type() != ContainerTypeEntry::StringListContainer)) { |
|
92 | || (static_cast<const ContainerTypeEntry *>(te))->type() != ContainerTypeEntry::StringListContainer)) { | |
93 | s << '<'; |
|
93 | s << '<'; | |
94 | QList<AbstractMetaType *> args = type->instantiations(); |
|
94 | QList<AbstractMetaType *> args = type->instantiations(); | |
95 | bool nested_template = false; |
|
95 | bool nested_template = false; | |
96 | for (int i=0; i<args.size(); ++i) { |
|
96 | for (int i=0; i<args.size(); ++i) { | |
97 | if (i != 0) |
|
97 | if (i != 0) | |
98 | s << ", "; |
|
98 | s << ", "; | |
99 | nested_template |= args.at(i)->isContainer(); |
|
99 | nested_template |= args.at(i)->isContainer(); | |
100 | writeTypeInfo(s, args.at(i)); |
|
100 | writeTypeInfo(s, args.at(i)); | |
101 | } |
|
101 | } | |
102 | if (nested_template) |
|
102 | if (nested_template) | |
103 | s << ' '; |
|
103 | s << ' '; | |
104 | s << '>'; |
|
104 | s << '>'; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | s << QString(type->indirections(), '*'); |
|
107 | s << QString(type->indirections(), '*'); | |
108 |
|
108 | |||
109 | if (type->isReference() && !(options & ExcludeReference) && !(options & ConvertReferenceToPtr)) |
|
109 | if (type->isReference() && !(options & ExcludeReference) && !(options & ConvertReferenceToPtr)) | |
110 | s << "&"; |
|
110 | s << "&"; | |
111 |
|
111 | |||
112 | if (type->isReference() && (options & ConvertReferenceToPtr)) { |
|
112 | if (type->isReference() && (options & ConvertReferenceToPtr)) { | |
113 | s << "*"; |
|
113 | s << "*"; | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 |
|
116 | |||
117 | if (!(options & SkipName)) |
|
117 | if (!(options & SkipName)) | |
118 | s << ' '; |
|
118 | s << ' '; | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 |
|
121 | |||
122 | void ShellGenerator::writeFunctionArguments(QTextStream &s, const AbstractMetaClass* owner, |
|
122 | void ShellGenerator::writeFunctionArguments(QTextStream &s, const AbstractMetaClass* owner, | |
123 | const AbstractMetaArgumentList &arguments, |
|
123 | const AbstractMetaArgumentList &arguments, | |
124 | Option option, |
|
124 | Option option, | |
125 | int numArguments) |
|
125 | int numArguments) | |
126 | { |
|
126 | { | |
127 | if (numArguments < 0) numArguments = arguments.size(); |
|
127 | if (numArguments < 0) numArguments = arguments.size(); | |
128 |
|
128 | |||
129 | for (int i=0; i<numArguments; ++i) { |
|
129 | for (int i=0; i<numArguments; ++i) { | |
130 | if (i != 0) |
|
130 | if (i != 0) | |
131 | s << ", "; |
|
131 | s << ", "; | |
132 | AbstractMetaArgument *arg = arguments.at(i); |
|
132 | AbstractMetaArgument *arg = arguments.at(i); | |
133 | writeTypeInfo(s, arg->type(), option); |
|
133 | writeTypeInfo(s, arg->type(), option); | |
134 | if (!(option & SkipName)) |
|
134 | if (!(option & SkipName)) | |
135 | s << " " << arg->argumentName(); |
|
135 | s << " " << arg->argumentName(); | |
136 | if ((option & IncludeDefaultExpression) && !arg->originalDefaultValueExpression().isEmpty()) { |
|
136 | if ((option & IncludeDefaultExpression) && !arg->originalDefaultValueExpression().isEmpty()) { | |
137 | s << " = "; |
|
137 | s << " = "; | |
138 |
|
138 | |||
139 | QString expr = arg->originalDefaultValueExpression(); |
|
139 | QString expr = arg->originalDefaultValueExpression(); | |
140 | if (expr != "0") { |
|
140 | if (expr != "0") { | |
141 | QString qualifier; |
|
141 | QString qualifier; | |
142 | if (arg->type()->typeEntry()->isEnum() && expr.indexOf("::") < 0) { |
|
142 | if (arg->type()->typeEntry()->isEnum() && expr.indexOf("::") < 0) { | |
143 | qualifier = ((EnumTypeEntry *)arg->type()->typeEntry())->qualifier(); |
|
143 | qualifier = ((EnumTypeEntry *)arg->type()->typeEntry())->qualifier(); | |
144 | } else if (arg->type()->typeEntry()->isFlags() && expr.indexOf("::") < 0) { |
|
144 | } else if (arg->type()->typeEntry()->isFlags() && expr.indexOf("::") < 0) { | |
145 | qualifier = ((FlagsTypeEntry *)arg->type()->typeEntry())->originator()->qualifier(); |
|
145 | qualifier = ((FlagsTypeEntry *)arg->type()->typeEntry())->originator()->qualifier(); | |
146 | } |
|
146 | } | |
147 | if (!qualifier.isEmpty()) { |
|
147 | if (!qualifier.isEmpty()) { | |
148 | s << qualifier << "::"; |
|
148 | s << qualifier << "::"; | |
149 | } |
|
149 | } | |
150 | } |
|
150 | } | |
151 | if (expr.contains("defaultConnection")) { |
|
151 | if (expr.contains("defaultConnection")) { | |
152 | expr.replace("defaultConnection","QSqlDatabase::defaultConnection"); |
|
152 | expr.replace("defaultConnection","QSqlDatabase::defaultConnection"); | |
153 | } |
|
153 | } | |
154 | if (expr == "MediaSource()") { |
|
154 | if (expr == "MediaSource()") { | |
155 | expr = "Phonon::MediaSource()"; |
|
155 | expr = "Phonon::MediaSource()"; | |
156 | } |
|
156 | } | |
157 | s << expr; |
|
157 | s << expr; | |
158 | } |
|
158 | } | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | * Writes the function \a meta_function signature to the textstream \a s. |
|
163 | * Writes the function \a meta_function signature to the textstream \a s. | |
164 | * |
|
164 | * | |
165 | * The \a name_prefix can be used to give the function name a prefix, |
|
165 | * The \a name_prefix can be used to give the function name a prefix, | |
166 | * like "__public_" or "__override_" and \a classname_prefix can |
|
166 | * like "__public_" or "__override_" and \a classname_prefix can | |
167 | * be used to give the class name a prefix. |
|
167 | * be used to give the class name a prefix. | |
168 | * |
|
168 | * | |
169 | * The \a option flags can be used to tweak various parameters, such as |
|
169 | * The \a option flags can be used to tweak various parameters, such as | |
170 | * showing static, original vs renamed name, underscores for space etc. |
|
170 | * showing static, original vs renamed name, underscores for space etc. | |
171 | * |
|
171 | * | |
172 | * The \a extra_arguments list is a list of extra arguments on the |
|
172 | * The \a extra_arguments list is a list of extra arguments on the | |
173 | * form "bool static_call". |
|
173 | * form "bool static_call". | |
174 | */ |
|
174 | */ | |
175 |
|
175 | |||
176 | void ShellGenerator::writeFunctionSignature(QTextStream &s, |
|
176 | void ShellGenerator::writeFunctionSignature(QTextStream &s, | |
177 | const AbstractMetaFunction *meta_function, |
|
177 | const AbstractMetaFunction *meta_function, | |
178 | const AbstractMetaClass *implementor, |
|
178 | const AbstractMetaClass *implementor, | |
179 | const QString &name_prefix, |
|
179 | const QString &name_prefix, | |
180 | Option option, |
|
180 | Option option, | |
181 | const QString &classname_prefix, |
|
181 | const QString &classname_prefix, | |
182 | const QStringList &extra_arguments, |
|
182 | const QStringList &extra_arguments, | |
183 | int numArguments) |
|
183 | int numArguments) | |
184 | { |
|
184 | { | |
185 | // ### remove the implementor |
|
185 | // ### remove the implementor | |
186 | AbstractMetaType *function_type = meta_function->type(); |
|
186 | AbstractMetaType *function_type = meta_function->type(); | |
187 |
|
187 | |||
188 |
|
188 | |||
189 | if ((option & SkipReturnType) == 0) { |
|
189 | if ((option & SkipReturnType) == 0) { | |
190 | if (function_type) { |
|
190 | if (function_type) { | |
191 | writeTypeInfo(s, function_type, option); |
|
191 | writeTypeInfo(s, function_type, option); | |
192 | s << " "; |
|
192 | s << " "; | |
193 | } else if (!meta_function->isConstructor()) { |
|
193 | } else if (!meta_function->isConstructor()) { | |
194 | s << "void "; |
|
194 | s << "void "; | |
195 | } |
|
195 | } | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | if (implementor) { |
|
198 | if (implementor) { | |
199 | if (classname_prefix.isEmpty()) |
|
199 | if (classname_prefix.isEmpty()) | |
200 | s << wrapperClassName(implementor) << "::"; |
|
200 | s << wrapperClassName(implementor) << "::"; | |
201 | else |
|
201 | else | |
202 | s << classname_prefix << implementor->name() << "::"; |
|
202 | s << classname_prefix << implementor->name() << "::"; | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 |
|
205 | |||
206 | QString function_name; |
|
206 | QString function_name; | |
207 | if (option & OriginalName) |
|
207 | if (option & OriginalName) | |
208 | function_name = meta_function->originalName(); |
|
208 | function_name = meta_function->originalName(); | |
209 | else |
|
209 | else | |
210 | function_name = meta_function->name(); |
|
210 | function_name = meta_function->name(); | |
211 |
|
211 | |||
212 | if (option & UnderscoreSpaces) |
|
212 | if (option & UnderscoreSpaces) | |
213 | function_name = function_name.replace(' ', '_'); |
|
213 | function_name = function_name.replace(' ', '_'); | |
214 |
|
214 | |||
215 | if (meta_function->isConstructor()) |
|
215 | if (meta_function->isConstructor()) | |
216 | function_name = meta_function->ownerClass()->name(); |
|
216 | function_name = meta_function->ownerClass()->name(); | |
217 |
|
217 | |||
218 | if (meta_function->isStatic() && (option & ShowStatic)) { |
|
218 | if (meta_function->isStatic() && (option & ShowStatic)) { | |
219 | function_name = "static_" + meta_function->ownerClass()->name() + "_" + function_name; |
|
219 | function_name = "static_" + meta_function->ownerClass()->name() + "_" + function_name; | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | if (function_name.startsWith("operator")) { |
|
222 | if (function_name.startsWith("operator")) { | |
223 | function_name = meta_function->name(); |
|
223 | function_name = meta_function->name(); | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | s << name_prefix << function_name; |
|
226 | s << name_prefix << function_name; | |
227 |
|
227 | |||
228 | if (meta_function->attributes() & AbstractMetaAttributes::SetterFunction) |
|
228 | if (meta_function->attributes() & AbstractMetaAttributes::SetterFunction) | |
229 | s << "_setter"; |
|
229 | s << "_setter"; | |
230 | else if (meta_function->attributes() & AbstractMetaAttributes::GetterFunction) |
|
230 | else if (meta_function->attributes() & AbstractMetaAttributes::GetterFunction) | |
231 | s << "_getter"; |
|
231 | s << "_getter"; | |
232 |
|
232 | |||
233 | s << "("; |
|
233 | s << "("; | |
234 |
|
234 | |||
235 | if ((option & FirstArgIsWrappedObject) && meta_function->ownerClass() && !meta_function->isConstructor() && !meta_function->isStatic()) { |
|
235 | if ((option & FirstArgIsWrappedObject) && meta_function->ownerClass() && !meta_function->isConstructor() && !meta_function->isStatic()) { | |
236 | s << meta_function->ownerClass()->qualifiedCppName() << "* theWrappedObject"; |
|
236 | s << meta_function->ownerClass()->qualifiedCppName() << "* theWrappedObject"; | |
237 | if (meta_function->arguments().size() != 0) { |
|
237 | if (meta_function->arguments().size() != 0) { | |
238 | s << ", "; |
|
238 | s << ", "; | |
239 | } |
|
239 | } | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | writeFunctionArguments(s, meta_function->ownerClass(), meta_function->arguments(), Option(option & Option(~ConvertReferenceToPtr)), numArguments); |
|
242 | writeFunctionArguments(s, meta_function->ownerClass(), meta_function->arguments(), Option(option & Option(~ConvertReferenceToPtr)), numArguments); | |
243 |
|
243 | |||
244 | // The extra arguments... |
|
244 | // The extra arguments... | |
245 | for (int i=0; i<extra_arguments.size(); ++i) { |
|
245 | for (int i=0; i<extra_arguments.size(); ++i) { | |
246 | if (i > 0 || meta_function->arguments().size() != 0) |
|
246 | if (i > 0 || meta_function->arguments().size() != 0) | |
247 | s << ", "; |
|
247 | s << ", "; | |
248 | s << extra_arguments.at(i); |
|
248 | s << extra_arguments.at(i); | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | s << ")"; |
|
251 | s << ")"; | |
252 | if (meta_function->isConstant()) |
|
252 | if (meta_function->isConstant()) | |
253 | s << " const"; |
|
253 | s << " const"; | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | AbstractMetaFunctionList ShellGenerator::getFunctionsToWrap(const AbstractMetaClass* meta_class) |
|
256 | AbstractMetaFunctionList ShellGenerator::getFunctionsToWrap(const AbstractMetaClass* meta_class) | |
257 | { |
|
257 | { | |
258 | AbstractMetaFunctionList functions = meta_class->queryFunctions( |
|
258 | AbstractMetaFunctionList functions = meta_class->queryFunctions( | |
259 | AbstractMetaClass::NormalFunctions | AbstractMetaClass::WasPublic |
|
259 | AbstractMetaClass::NormalFunctions | AbstractMetaClass::WasPublic | |
260 | | AbstractMetaClass::NotRemovedFromTargetLang | AbstractMetaClass::ClassImplements |
|
260 | | AbstractMetaClass::NotRemovedFromTargetLang | AbstractMetaClass::ClassImplements | |
261 | ); |
|
261 | ); | |
262 | AbstractMetaFunctionList functions2 = meta_class->queryFunctions( |
|
262 | AbstractMetaFunctionList functions2 = meta_class->queryFunctions( | |
263 | AbstractMetaClass::VirtualFunctions | AbstractMetaClass::WasVisible |
|
263 | AbstractMetaClass::VirtualFunctions | AbstractMetaClass::WasVisible | |
264 | | AbstractMetaClass::NotRemovedFromTargetLang | AbstractMetaClass::ClassImplements |
|
264 | | AbstractMetaClass::NotRemovedFromTargetLang | AbstractMetaClass::ClassImplements | |
265 | ); |
|
265 | ); | |
266 | QSet<AbstractMetaFunction*> set1 = QSet<AbstractMetaFunction*>::fromList(functions); |
|
266 | QSet<AbstractMetaFunction*> set1 = QSet<AbstractMetaFunction*>::fromList(functions); | |
267 | foreach(AbstractMetaFunction* func, functions2) { |
|
267 | foreach(AbstractMetaFunction* func, functions2) { | |
268 | set1.insert(func); |
|
268 | set1.insert(func); | |
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | AbstractMetaFunctionList resultFunctions; |
|
271 | AbstractMetaFunctionList resultFunctions; | |
272 |
|
272 | |||
273 | foreach(AbstractMetaFunction* func, set1.toList()) { |
|
273 | foreach(AbstractMetaFunction* func, set1.toList()) { | |
274 | if (!func->isAbstract() && func->implementingClass()==meta_class) { |
|
274 | if (!func->isAbstract() && func->implementingClass()==meta_class) { | |
275 | resultFunctions << func; |
|
275 | resultFunctions << func; | |
276 | } |
|
276 | } | |
277 | } |
|
277 | } | |
|
278 | qStableSort(resultFunctions); | |||
278 | return resultFunctions; |
|
279 | return resultFunctions; | |
279 | } |
|
280 | } | |
280 |
|
281 | |||
281 | AbstractMetaFunctionList ShellGenerator::getVirtualFunctionsForShell(const AbstractMetaClass* meta_class) |
|
282 | AbstractMetaFunctionList ShellGenerator::getVirtualFunctionsForShell(const AbstractMetaClass* meta_class) | |
282 | { |
|
283 | { | |
283 | AbstractMetaFunctionList functions = meta_class->queryFunctions( |
|
284 | AbstractMetaFunctionList functions = meta_class->queryFunctions( | |
284 | AbstractMetaClass::VirtualFunctions | AbstractMetaClass::WasVisible |
|
285 | AbstractMetaClass::VirtualFunctions | AbstractMetaClass::WasVisible | |
285 | // | AbstractMetaClass::NotRemovedFromTargetLang |
|
286 | // | AbstractMetaClass::NotRemovedFromTargetLang | |
286 | ); |
|
287 | ); | |
|
288 | qStableSort(functions); | |||
287 | return functions; |
|
289 | return functions; | |
288 | } |
|
290 | } | |
289 |
|
291 | |||
290 | AbstractMetaFunctionList ShellGenerator::getProtectedFunctionsThatNeedPromotion(const AbstractMetaClass* meta_class) |
|
292 | AbstractMetaFunctionList ShellGenerator::getProtectedFunctionsThatNeedPromotion(const AbstractMetaClass* meta_class) | |
291 | { |
|
293 | { | |
292 | AbstractMetaFunctionList functions; |
|
294 | AbstractMetaFunctionList functions; | |
293 | AbstractMetaFunctionList functions1 = getFunctionsToWrap(meta_class); |
|
295 | AbstractMetaFunctionList functions1 = getFunctionsToWrap(meta_class); | |
294 | foreach(AbstractMetaFunction* func, functions1) { |
|
296 | foreach(AbstractMetaFunction* func, functions1) { | |
295 | if (!func->isPublic() || func->isVirtual()) { |
|
297 | if (!func->isPublic() || func->isVirtual()) { | |
296 | functions << func; |
|
298 | functions << func; | |
297 | } |
|
299 | } | |
298 | } |
|
300 | } | |
|
301 | qStableSort(functions); | |||
299 | return functions; |
|
302 | return functions; | |
300 | } |
|
303 | } | |
301 |
|
304 | |||
302 | /*! |
|
305 | /*! | |
303 | Writes the include defined by \a inc to \a stream. |
|
306 | Writes the include defined by \a inc to \a stream. | |
304 | */ |
|
307 | */ | |
305 | void ShellGenerator::writeInclude(QTextStream &stream, const Include &inc) |
|
308 | void ShellGenerator::writeInclude(QTextStream &stream, const Include &inc) | |
306 | { |
|
309 | { | |
307 | if (inc.name.isEmpty()) |
|
310 | if (inc.name.isEmpty()) | |
308 | return; |
|
311 | return; | |
309 | if (inc.type == Include::TargetLangImport) |
|
312 | if (inc.type == Include::TargetLangImport) | |
310 | return; |
|
313 | return; | |
311 | stream << "#include "; |
|
314 | stream << "#include "; | |
312 | if (inc.type == Include::IncludePath) |
|
315 | if (inc.type == Include::IncludePath) | |
313 | stream << "<"; |
|
316 | stream << "<"; | |
314 | else |
|
317 | else | |
315 | stream << "\""; |
|
318 | stream << "\""; | |
316 | stream << inc.name; |
|
319 | stream << inc.name; | |
317 | if (inc.type == Include::IncludePath) |
|
320 | if (inc.type == Include::IncludePath) | |
318 | stream << ">"; |
|
321 | stream << ">"; | |
319 | else |
|
322 | else | |
320 | stream << "\""; |
|
323 | stream << "\""; | |
321 | stream << endl; |
|
324 | stream << endl; | |
322 | } |
|
325 | } | |
323 |
|
326 | |||
324 | /*! |
|
327 | /*! | |
325 | Returns true if the given function \a fun is operator>>() or |
|
328 | Returns true if the given function \a fun is operator>>() or | |
326 | operator<<() that streams from/to a Q{Data,Text}Stream, false |
|
329 | operator<<() that streams from/to a Q{Data,Text}Stream, false | |
327 | otherwise. |
|
330 | otherwise. | |
328 | */ |
|
331 | */ | |
329 | bool ShellGenerator::isSpecialStreamingOperator(const AbstractMetaFunction *fun) |
|
332 | bool ShellGenerator::isSpecialStreamingOperator(const AbstractMetaFunction *fun) | |
330 | { |
|
333 | { | |
331 | return ((fun->functionType() == AbstractMetaFunction::GlobalScopeFunction) |
|
334 | return ((fun->functionType() == AbstractMetaFunction::GlobalScopeFunction) | |
332 | && (fun->arguments().size() == 1) |
|
335 | && (fun->arguments().size() == 1) | |
333 | && (((fun->originalName() == "operator>>") && (fun->modifiedName() == "readFrom")) |
|
336 | && (((fun->originalName() == "operator>>") && (fun->modifiedName() == "readFrom")) | |
334 | || ((fun->originalName() == "operator<<") && (fun->modifiedName() == "writeTo")))); |
|
337 | || ((fun->originalName() == "operator<<") && (fun->modifiedName() == "writeTo")))); | |
335 | } |
|
338 | } | |
336 |
|
339 | |||
337 | bool ShellGenerator::isBuiltIn(const QString& name) { |
|
340 | bool ShellGenerator::isBuiltIn(const QString& name) { | |
338 |
|
341 | |||
339 | static QSet<QString> builtIn; |
|
342 | static QSet<QString> builtIn; | |
340 | if (builtIn.isEmpty()) { |
|
343 | if (builtIn.isEmpty()) { | |
341 | builtIn.insert("Qt"); |
|
344 | builtIn.insert("Qt"); | |
342 | builtIn.insert("QFont"); |
|
345 | builtIn.insert("QFont"); | |
343 | builtIn.insert("QPixmap"); |
|
346 | builtIn.insert("QPixmap"); | |
344 | builtIn.insert("QBrush"); |
|
347 | builtIn.insert("QBrush"); | |
345 | builtIn.insert("QBitArray"); |
|
348 | builtIn.insert("QBitArray"); | |
346 | builtIn.insert("QPalette"); |
|
349 | builtIn.insert("QPalette"); | |
347 | builtIn.insert("QPen"); |
|
350 | builtIn.insert("QPen"); | |
348 | builtIn.insert("QIcon"); |
|
351 | builtIn.insert("QIcon"); | |
349 | builtIn.insert("QImage"); |
|
352 | builtIn.insert("QImage"); | |
350 | builtIn.insert("QPolygon"); |
|
353 | builtIn.insert("QPolygon"); | |
351 | builtIn.insert("QRegion"); |
|
354 | builtIn.insert("QRegion"); | |
352 | builtIn.insert("QBitmap"); |
|
355 | builtIn.insert("QBitmap"); | |
353 | builtIn.insert("QCursor"); |
|
356 | builtIn.insert("QCursor"); | |
354 | builtIn.insert("QColor"); |
|
357 | builtIn.insert("QColor"); | |
355 | builtIn.insert("QSizePolicy"); |
|
358 | builtIn.insert("QSizePolicy"); | |
356 | builtIn.insert("QKeySequence"); |
|
359 | builtIn.insert("QKeySequence"); | |
357 | builtIn.insert("QTextLength"); |
|
360 | builtIn.insert("QTextLength"); | |
358 | builtIn.insert("QTextFormat"); |
|
361 | builtIn.insert("QTextFormat"); | |
359 | builtIn.insert("QMatrix"); |
|
362 | builtIn.insert("QMatrix"); | |
360 | builtIn.insert("QDate"); |
|
363 | builtIn.insert("QDate"); | |
361 | builtIn.insert("QTime"); |
|
364 | builtIn.insert("QTime"); | |
362 | builtIn.insert("QDateTime"); |
|
365 | builtIn.insert("QDateTime"); | |
363 | builtIn.insert("QUrl"); |
|
366 | builtIn.insert("QUrl"); | |
364 | builtIn.insert("QLocale"); |
|
367 | builtIn.insert("QLocale"); | |
365 | builtIn.insert("QRect"); |
|
368 | builtIn.insert("QRect"); | |
366 | builtIn.insert("QRectF"); |
|
369 | builtIn.insert("QRectF"); | |
367 | builtIn.insert("QSize"); |
|
370 | builtIn.insert("QSize"); | |
368 | builtIn.insert("QSizeF"); |
|
371 | builtIn.insert("QSizeF"); | |
369 | builtIn.insert("QLine"); |
|
372 | builtIn.insert("QLine"); | |
370 | builtIn.insert("QLineF"); |
|
373 | builtIn.insert("QLineF"); | |
371 | builtIn.insert("QPoint"); |
|
374 | builtIn.insert("QPoint"); | |
372 | builtIn.insert("QPointF"); |
|
375 | builtIn.insert("QPointF"); | |
373 | builtIn.insert("QRegExp"); |
|
376 | builtIn.insert("QRegExp"); | |
374 | } |
|
377 | } | |
375 | return builtIn.contains(name); |
|
378 | return builtIn.contains(name); | |
376 | } |
|
379 | } | |
377 |
|
380 |
General Comments 0
You need to be logged in to leave comments.
Login now