##// END OF EJS Templates
added comparison to classes and sorted them...
florianlink -
r100:fcc1d92aaafa
parent child
Show More
@@ -1,940 +1,944
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
4 4 ** All rights reserved.
5 5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 6 **
7 7 ** This file is part of the Qt Script Generator project on Qt Labs.
8 8 **
9 9 ** $QT_BEGIN_LICENSE:LGPL$
10 10 ** No Commercial Usage
11 11 ** This file contains pre-release code and may not be distributed.
12 12 ** You may use this file in accordance with the terms and conditions
13 13 ** contained in the Technology Preview License Agreement accompanying
14 14 ** this package.
15 15 **
16 16 ** GNU Lesser General Public License Usage
17 17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 18 ** General Public License version 2.1 as published by the Free Software
19 19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 20 ** packaging of this file. Please review the following information to
21 21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 23 **
24 24 ** In addition, as a special exception, Nokia gives you certain additional
25 25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 27 **
28 28 ** If you have questions regarding the use of this file, please contact
29 29 ** Nokia at qt-info@nokia.com.
30 30 **
31 31 **
32 32 **
33 33 **
34 34 **
35 35 **
36 36 **
37 37 **
38 38 ** $QT_END_LICENSE$
39 39 **
40 40 ****************************************************************************/
41 41
42 42 #ifndef ABSTRACTMETALANG_H
43 43 #define ABSTRACTMETALANG_H
44 44
45 45 #include "codemodel.h"
46 46
47 47 #include "typesystem.h"
48 48
49 49 #include <QSet>
50 50 #include <QStringList>
51 51 #include <QTextStream>
52 52
53 53
54 54 class AbstractMeta;
55 55 class AbstractMetaClass;
56 56 class AbstractMetaField;
57 57 class AbstractMetaFunction;
58 58 class AbstractMetaType;
59 59 class AbstractMetaVariable;
60 60 class AbstractMetaArgument;
61 61 class AbstractMetaEnumValue;
62 62 class AbstractMetaEnum;
63 63 class QPropertySpec;
64 64
65 65 typedef QList<AbstractMetaField *> AbstractMetaFieldList;
66 66 typedef QList<AbstractMetaArgument *> AbstractMetaArgumentList;
67 67 typedef QList<AbstractMetaFunction *> AbstractMetaFunctionList;
68 68 class AbstractMetaClassList : public QList<AbstractMetaClass *>
69 69 {
70 70 public:
71 71 AbstractMetaClass *findClass(const QString &name) const;
72 72 AbstractMetaEnumValue *findEnumValue(const QString &string) const;
73 73 AbstractMetaEnum *findEnum(const EnumTypeEntry *entry) const;
74 74
75 75 };
76 76
77 77
78 78
79 79 class AbstractMetaAttributes
80 80 {
81 81 public:
82 82 AbstractMetaAttributes() : m_attributes(0) { };
83 83
84 84 enum Attribute {
85 85 None = 0x00000000,
86 86
87 87 Private = 0x00000001,
88 88 Protected = 0x00000002,
89 89 Public = 0x00000004,
90 90 Friendly = 0x00000008,
91 91 Visibility = 0x0000000f,
92 92
93 93 Native = 0x00000010,
94 94 Abstract = 0x00000020,
95 95 Static = 0x00000040,
96 96
97 97 FinalInTargetLang = 0x00000080,
98 98 FinalInCpp = 0x00000100,
99 99 ForceShellImplementation = 0x00000200,
100 100
101 101 GetterFunction = 0x00000400,
102 102 SetterFunction = 0x00000800,
103 103
104 104 FinalOverload = 0x00001000,
105 105 InterfaceFunction = 0x00002000,
106 106
107 107 PropertyReader = 0x00004000,
108 108 PropertyWriter = 0x00008000,
109 109 PropertyResetter = 0x00010000,
110 110
111 111 Fake = 0x00020000,
112 112
113 113 Invokable = 0x00040000,
114 114
115 115 Final = FinalInTargetLang | FinalInCpp
116 116 };
117 117
118 118 uint attributes() const { return m_attributes; }
119 119 void setAttributes(uint attributes) { m_attributes = attributes; }
120 120
121 121 uint originalAttributes() const { return m_originalAttributes; }
122 122 void setOriginalAttributes(uint attributes) { m_originalAttributes = attributes; }
123 123
124 124 uint visibility() const { return m_attributes & Visibility; }
125 125 void setVisibility(uint visi) { m_attributes = (m_attributes & ~Visibility) | visi; }
126 126
127 127 void operator+=(Attribute attribute) { m_attributes |= attribute; }
128 128 void operator-=(Attribute attribute) { m_attributes &= ~attribute; }
129 129
130 130 bool isNative() const { return m_attributes & Native; }
131 131 bool isFinal() const { return (m_attributes & Final) == Final; }
132 132 bool isFinalInTargetLang() const { return m_attributes & FinalInTargetLang; }
133 133 bool isFinalInCpp() const { return m_attributes & FinalInCpp; }
134 134 bool isAbstract() const { return m_attributes & Abstract; }
135 135 bool isStatic() const { return m_attributes & Static; }
136 136 bool isForcedShellImplementation() const { return m_attributes & ForceShellImplementation; }
137 137 bool isInterfaceFunction() const { return m_attributes & InterfaceFunction; }
138 138 bool isFinalOverload() const { return m_attributes & FinalOverload; }
139 139 bool isInvokable() const { return m_attributes & Invokable; }
140 140
141 141 bool isPropertyReader() const { return m_attributes & PropertyReader; }
142 142 bool isPropertyWriter() const { return m_attributes & PropertyWriter; }
143 143 bool isPropertyResetter() const { return m_attributes & PropertyResetter; }
144 144
145 145 bool isPrivate() const { return m_attributes & Private; }
146 146 bool isProtected() const { return m_attributes & Protected; }
147 147 bool isPublic() const { return m_attributes & Public; }
148 148 bool isFriendly() const { return m_attributes & Friendly; }
149 149
150 150 bool wasPrivate() const { return m_originalAttributes & Private; }
151 151 bool wasProtected() const { return m_originalAttributes & Protected; }
152 152 bool wasPublic() const { return m_originalAttributes & Public; }
153 153 bool wasFriendly() const { return m_originalAttributes & Friendly; }
154 154
155 155 private:
156 156 uint m_attributes;
157 157 uint m_originalAttributes;
158 158 };
159 159
160 160
161 161 class AbstractMetaType
162 162 {
163 163 public:
164 164 enum TypeUsagePattern {
165 165 InvalidPattern,
166 166 PrimitivePattern,
167 167 FlagsPattern,
168 168 EnumPattern,
169 169 ValuePattern,
170 170 StringPattern,
171 171 CharPattern,
172 172 ObjectPattern,
173 173 QObjectPattern,
174 174 NativePointerPattern,
175 175 ContainerPattern,
176 176 VariantPattern,
177 177 JObjectWrapperPattern,
178 178 ArrayPattern,
179 179 ThreadPattern
180 180 };
181 181
182 182 AbstractMetaType() :
183 183 m_type_entry(0),
184 184 m_array_element_count(0),
185 185 m_array_element_type(0),
186 186 m_original_template_type(0),
187 187 m_pattern(InvalidPattern),
188 188 m_constant(false),
189 189 m_reference(false),
190 190 m_cpp_instantiation(true),
191 191 m_indirections(0),
192 192 m_reserved(0)
193 193 {
194 194 }
195 195
196 196 QString package() const { return m_type_entry->javaPackage(); }
197 197 QString name() const { return m_type_entry->targetLangName(); }
198 198 QString fullName() const { return m_type_entry->qualifiedTargetLangName(); }
199 199
200 200 void setTypeUsagePattern(TypeUsagePattern pattern) { m_pattern = pattern; }
201 201 TypeUsagePattern typeUsagePattern() const { return m_pattern; }
202 202
203 203 // true when use pattern is container
204 204 bool hasInstantiations() const { return !m_instantiations.isEmpty(); }
205 205 void addInstantiation(AbstractMetaType *inst) { m_instantiations << inst; }
206 206 void setInstantiations(const QList<AbstractMetaType *> &insts) { m_instantiations = insts; }
207 207 QList<AbstractMetaType *> instantiations() const { return m_instantiations; }
208 208 void setInstantiationInCpp(bool incpp) { m_cpp_instantiation = incpp; }
209 209 bool hasInstantiationInCpp() const { return hasInstantiations() && m_cpp_instantiation; }
210 210
211 211 QString minimalSignature() const;
212 212
213 213 // true when the type is a QtJambiObject subclass
214 214 bool hasNativeId() const;
215 215
216 216 // returns true if the typs is used as a non complex primitive, no & or *'s
217 217 bool isPrimitive() const { return m_pattern == PrimitivePattern; }
218 218
219 219 // returns true if the type is used as an enum
220 220 bool isEnum() const { return m_pattern == EnumPattern; }
221 221
222 222 // returns true if the type is used as a QObject *
223 223 bool isQObject() const { return m_pattern == QObjectPattern; }
224 224
225 225 // returns true if the type is used as an object, e.g. Xxx *
226 226 bool isObject() const { return m_pattern == ObjectPattern; }
227 227
228 228 // returns true if the type is used as an array, e.g. Xxx[42]
229 229 bool isArray() const { return m_pattern == ArrayPattern; }
230 230
231 231 // returns true if the type is used as a value type (X or const X &)
232 232 bool isValue() const { return m_pattern == ValuePattern; }
233 233
234 234 // returns true for more complex types...
235 235 bool isNativePointer() const { return m_pattern == NativePointerPattern; }
236 236
237 237 // returns true if the type was originally a QString or const QString & or equivalent for QLatin1String
238 238 bool isTargetLangString() const { return m_pattern == StringPattern; }
239 239
240 240 // returns true if the type was originally a QChar or const QChar &
241 241 bool isTargetLangChar() const { return m_pattern == CharPattern; }
242 242
243 243 // return true if the type was originally a QVariant or const QVariant &
244 244 bool isVariant() const { return m_pattern == VariantPattern; }
245 245
246 246 // return true if the type was originally a JObjectWrapper or const JObjectWrapper &
247 247 bool isJObjectWrapper() const { return m_pattern == JObjectWrapperPattern; }
248 248
249 249 // returns true if the type was used as a container
250 250 bool isContainer() const { return m_pattern == ContainerPattern; }
251 251
252 252 // returns true if the type was used as a flag
253 253 bool isFlags() const { return m_pattern == FlagsPattern; }
254 254
255 255 // returns true if the type was used as a thread
256 256 bool isThread() const { return m_pattern == ThreadPattern; }
257 257
258 258 bool isConstant() const { return m_constant; }
259 259 void setConstant(bool constant) { m_constant = constant; }
260 260
261 261 bool isReference() const { return m_reference; }
262 262 void setReference(bool ref) { m_reference = ref; }
263 263
264 264 // Returns true if the type is to be implemented using Java enums, e.g. not plain ints.
265 265 bool isTargetLangEnum() const { return isEnum() && !((EnumTypeEntry *) typeEntry())->forceInteger(); }
266 266 bool isIntegerEnum() const { return isEnum() && !isTargetLangEnum(); }
267 267
268 268 // Returns true if the type is to be implemented using Java QFlags, e.g. not plain ints.
269 269 bool isTargetLangFlags() const {
270 270 return isFlags() && !((FlagsTypeEntry *) typeEntry())->forceInteger(); }
271 271 bool isIntegerFlags() const { return isFlags() && !isTargetLangFlags(); }
272 272
273 273 int actualIndirections() const { return m_indirections + (isReference() ? 1 : 0); }
274 274 int indirections() const { return m_indirections; }
275 275 void setIndirections(int indirections) { m_indirections = indirections; }
276 276
277 277 void setArrayElementCount(int n) { m_array_element_count = n; }
278 278 int arrayElementCount() const { return m_array_element_count; }
279 279
280 280 AbstractMetaType *arrayElementType() const { return m_array_element_type; }
281 281 void setArrayElementType(AbstractMetaType *t) { m_array_element_type = t; }
282 282
283 283 QString cppSignature() const;
284 284
285 285 AbstractMetaType *copy() const;
286 286
287 287 const TypeEntry *typeEntry() const { return m_type_entry; }
288 288 void setTypeEntry(const TypeEntry *type) { m_type_entry = type; }
289 289
290 290 void setOriginalTypeDescription(const QString &otd) { m_original_type_description = otd; }
291 291 QString originalTypeDescription() const { return m_original_type_description; }
292 292
293 293 void setOriginalTemplateType(const AbstractMetaType *type) { m_original_template_type = type; }
294 294 const AbstractMetaType *originalTemplateType() const { return m_original_template_type; }
295 295
296 296 private:
297 297 const TypeEntry *m_type_entry;
298 298 QList <AbstractMetaType *> m_instantiations;
299 299 QString m_package;
300 300 QString m_original_type_description;
301 301
302 302 int m_array_element_count;
303 303 AbstractMetaType *m_array_element_type;
304 304 const AbstractMetaType *m_original_template_type;
305 305
306 306 TypeUsagePattern m_pattern;
307 307 uint m_constant : 1;
308 308 uint m_reference : 1;
309 309 uint m_cpp_instantiation : 1;
310 310 int m_indirections : 4;
311 311 uint m_reserved : 25; // unused
312 312 };
313 313
314 314 class AbstractMetaVariable
315 315 {
316 316 public:
317 317 AbstractMetaVariable() : m_type(0) { }
318 318
319 319 AbstractMetaType *type() const { return m_type; }
320 320 void setType(AbstractMetaType *type) { m_type = type; }
321 321
322 322 QString name() const { return m_name; }
323 323 void setName(const QString &name) { m_name = name; }
324 324
325 325 private:
326 326 QString m_name;
327 327 AbstractMetaType *m_type;
328 328 };
329 329
330 330
331 331
332 332 class AbstractMetaArgument : public AbstractMetaVariable
333 333 {
334 334 public:
335 335 AbstractMetaArgument() : m_argument_index(0) { };
336 336
337 337 QString defaultValueExpression() const { return m_expression; }
338 338 void setDefaultValueExpression(const QString &expr) { m_expression = expr; }
339 339
340 340 QString originalDefaultValueExpression() const { return m_original_expression; }
341 341 void setOriginalDefaultValueExpression(const QString &expr) { m_original_expression = expr; }
342 342
343 343 QString toString() const { return type()->name() + " " + AbstractMetaVariable::name() +
344 344 (m_expression.isEmpty() ? "" : " = " + m_expression); }
345 345
346 346 int argumentIndex() const { return m_argument_index; }
347 347 void setArgumentIndex(int argIndex) { m_argument_index = argIndex; }
348 348
349 349 QString argumentName() const;
350 350 QString indexedName() const;
351 351
352 352 AbstractMetaArgument *copy() const;
353 353
354 354 private:
355 355 // Just to force people to call argumentName() And indexedName();
356 356 QString name() const;
357 357
358 358 QString m_expression;
359 359 QString m_original_expression;
360 360 int m_argument_index;
361 361 };
362 362
363 363
364 364 class AbstractMetaField : public AbstractMetaVariable, public AbstractMetaAttributes
365 365 {
366 366 public:
367 367 AbstractMetaField();
368 368 ~AbstractMetaField();
369 369
370 370 const AbstractMetaClass *enclosingClass() const { return m_class; }
371 371 void setEnclosingClass(const AbstractMetaClass *cls) { m_class = cls; }
372 372
373 373 const AbstractMetaFunction *getter() const;
374 374 const AbstractMetaFunction *setter() const;
375 375
376 376 FieldModificationList modifications() const;
377 377
378 378 AbstractMetaField *copy() const;
379 379
380 380 private:
381 381 mutable AbstractMetaFunction *m_getter;
382 382 mutable AbstractMetaFunction *m_setter;
383 383 const AbstractMetaClass *m_class;
384 384 };
385 385
386 386
387 387 class AbstractMetaFunction : public AbstractMetaAttributes
388 388 {
389 389 public:
390 390 enum FunctionType {
391 391 ConstructorFunction,
392 392 DestructorFunction,
393 393 NormalFunction,
394 394 SignalFunction,
395 395 EmptyFunction,
396 396 SlotFunction,
397 397 GlobalScopeFunction
398 398 };
399 399
400 400 enum CompareResult {
401 401 EqualName = 0x00000001,
402 402 EqualArguments = 0x00000002,
403 403 EqualAttributes = 0x00000004,
404 404 EqualImplementor = 0x00000008,
405 405 EqualReturnType = 0x00000010,
406 406 EqualDefaultValueOverload = 0x00000020,
407 407 EqualModifiedName = 0x00000040,
408 408
409 409 NameLessThan = 0x00001000,
410 410
411 411 PrettySimilar = EqualName | EqualArguments,
412 412 Equal = 0x0000001f,
413 413 NotEqual = 0x00001000
414 414 };
415 415
416 416 AbstractMetaFunction()
417 417 : m_function_type(NormalFunction),
418 418 m_type(0),
419 419 m_class(0),
420 420 m_implementing_class(0),
421 421 m_declaring_class(0),
422 422 m_interface_class(0),
423 423 m_property_spec(0),
424 424 m_constant(false),
425 425 m_invalid(false)
426 426 {
427 427 }
428 428
429 429 ~AbstractMetaFunction();
430 430
431 431 QString name() const { return m_name; }
432 432 void setName(const QString &name) { m_name = name; }
433 433
434 434 QString originalName() const { return m_original_name.isEmpty() ? name() : m_original_name; }
435 435 void setOriginalName(const QString &name) { m_original_name = name; }
436 436
437 437 QString modifiedName() const;
438 438
439 439 QString minimalSignature() const;
440 440 QStringList possibleIntrospectionCompatibleSignatures() const;
441 441
442 442 QString marshalledName() const;
443 443
444 444 // true if one or more of the arguments are of QtJambiObject subclasses
445 445 bool argumentsHaveNativeId() const
446 446 {
447 447 foreach (const AbstractMetaArgument *arg, m_arguments) {
448 448 if (arg->type()->hasNativeId())
449 449 return true;
450 450 }
451 451
452 452 return false;
453 453 }
454 454
455 455 bool isModifiedRemoved(int types = TypeSystem::All) const;
456 456
457 457 AbstractMetaType *type() const { return m_type; }
458 458 void setType(AbstractMetaType *type) { m_type = type; }
459 459
460 460 // The class that has this function as a member.
461 461 const AbstractMetaClass *ownerClass() const { return m_class; }
462 462 void setOwnerClass(const AbstractMetaClass *cls) { m_class = cls; }
463 463
464 464 // The first class in a hierarchy that declares the function
465 465 const AbstractMetaClass *declaringClass() const { return m_declaring_class; }
466 466 void setDeclaringClass(const AbstractMetaClass *cls) { m_declaring_class = cls; }
467 467
468 468 // The class that actually implements this function
469 469 const AbstractMetaClass *implementingClass() const { return m_implementing_class; }
470 470 void setImplementingClass(const AbstractMetaClass *cls) { m_implementing_class = cls; }
471 471
472 472 bool needsCallThrough() const;
473 473
474 474 AbstractMetaArgumentList arguments() const { return m_arguments; }
475 475 void setArguments(const AbstractMetaArgumentList &arguments) { m_arguments = arguments; }
476 476 void addArgument(AbstractMetaArgument *argument) { m_arguments << argument; }
477 477 int actualMinimumArgumentCount() const;
478 478
479 479 void setInvalid(bool on) { m_invalid = on; }
480 480 bool isInvalid() const { return m_invalid; }
481 481 bool isDeprecated() const;
482 482 bool isDestructor() const { return functionType() == DestructorFunction; }
483 483 bool isConstructor() const { return functionType() == ConstructorFunction; }
484 484 bool isNormal() const { return functionType() == NormalFunction || isSlot() || isInGlobalScope(); }
485 485 bool isInGlobalScope() const { return functionType() == GlobalScopeFunction; }
486 486 bool isSignal() const { return functionType() == SignalFunction; }
487 487 bool isSlot() const { return functionType() == SlotFunction; }
488 488 bool isEmptyFunction() const { return functionType() == EmptyFunction; }
489 489 FunctionType functionType() const { return m_function_type; }
490 490 void setFunctionType(FunctionType type) { m_function_type = type; }
491 491
492 492 bool isVirtual() { return !(isFinal() || isSignal() || isStatic()); }
493 493
494 494 QStringList introspectionCompatibleSignatures(const QStringList &resolvedArguments = QStringList()) const;
495 495 QString signature() const;
496 496 QString targetLangSignature(bool minimal = false) const;
497 497 bool shouldReturnThisObject() const { return QLatin1String("this") == argumentReplaced(0); }
498 498 bool shouldIgnoreReturnValue() const { return QLatin1String("void") == argumentReplaced(0); }
499 499
500 500 bool isConstant() const { return m_constant; }
501 501 void setConstant(bool constant) { m_constant = constant; }
502 502
503 503 QString toString() const { return m_name; }
504 504
505 505 uint compareTo(const AbstractMetaFunction *other) const;
506 506
507 507 bool operator <(const AbstractMetaFunction &a) const;
508 508
509 509 AbstractMetaFunction *copy() const;
510 510
511 511 QString replacedDefaultExpression(const AbstractMetaClass *cls, int idx) const;
512 512 bool removedDefaultExpression(const AbstractMetaClass *cls, int idx) const;
513 513 QString conversionRule(TypeSystem::Language language, int idx) const;
514 514 QList<ReferenceCount> referenceCounts(const AbstractMetaClass *cls, int idx = -2) const;
515 515
516 516 bool nullPointersDisabled(const AbstractMetaClass *cls = 0, int argument_idx = 0) const;
517 517 QString nullPointerDefaultValue(const AbstractMetaClass *cls = 0, int argument_idx = 0) const;
518 518
519 519 bool resetObjectAfterUse(int argument_idx) const;
520 520
521 521 // Returns whether garbage collection is disabled for the argument in any context
522 522 bool disabledGarbageCollection(const AbstractMetaClass *cls, int key) const;
523 523
524 524 // Returns the ownership rules for the given argument in the given context
525 525 TypeSystem::Ownership ownership(const AbstractMetaClass *cls, TypeSystem::Language language, int idx) const;
526 526
527 527 bool isVirtualSlot() const;
528 528
529 529 QString typeReplaced(int argument_index) const;
530 530 bool isRemovedFromAllLanguages(const AbstractMetaClass *) const;
531 531 bool isRemovedFrom(const AbstractMetaClass *, TypeSystem::Language language) const;
532 532 bool argumentRemoved(int) const;
533 533
534 534 QString argumentReplaced(int key) const;
535 535 bool needsSuppressUncheckedWarning() const;
536 536
537 537 bool hasModifications(const AbstractMetaClass *implementor) const;
538 538 FunctionModificationList modifications(const AbstractMetaClass *implementor) const;
539 539
540 540 // If this function stems from an interface, this returns the
541 541 // interface that declares it.
542 542 const AbstractMetaClass *interfaceClass() const { return m_interface_class; }
543 543 void setInterfaceClass(const AbstractMetaClass *cl) { m_interface_class = cl; }
544 544
545 545 void setPropertySpec(QPropertySpec *spec) { m_property_spec = spec; }
546 546 QPropertySpec *propertySpec() const { return m_property_spec; }
547 547
548 548 private:
549 549 QString m_name;
550 550 QString m_original_name;
551 551 mutable QString m_cached_minimal_signature;
552 552 mutable QString m_cached_modified_name;
553 553
554 554 FunctionType m_function_type;
555 555 AbstractMetaType *m_type;
556 556 const AbstractMetaClass *m_class;
557 557 const AbstractMetaClass *m_implementing_class;
558 558 const AbstractMetaClass *m_declaring_class;
559 559 const AbstractMetaClass *m_interface_class;
560 560 QPropertySpec *m_property_spec;
561 561 AbstractMetaArgumentList m_arguments;
562 562 uint m_constant : 1;
563 563 uint m_invalid : 1;
564 564 };
565 565
566 566
567 567 class AbstractMetaEnumValue
568 568 {
569 569 public:
570 570 AbstractMetaEnumValue()
571 571 : m_value_set(false), m_value(0)
572 572 {
573 573 }
574 574
575 575 int value() const { return m_value; }
576 576 void setValue(int value) { m_value_set = true; m_value = value; }
577 577
578 578 QString stringValue() const { return m_string_value; }
579 579 void setStringValue(const QString &v) { m_string_value = v; }
580 580
581 581 QString name() const { return m_name; }
582 582 void setName(const QString &name) { m_name = name; }
583 583
584 584 bool isValueSet() const { return m_value_set; }
585 585
586 586 private:
587 587 QString m_name;
588 588 QString m_string_value;
589 589
590 590 bool m_value_set;
591 591 int m_value;
592 592 };
593 593
594 594
595 595 class AbstractMetaEnumValueList : public QList<AbstractMetaEnumValue *>
596 596 {
597 597 public:
598 598 AbstractMetaEnumValue *find(const QString &name) const;
599 599 };
600 600
601 601 class AbstractMetaEnum : public AbstractMetaAttributes
602 602 {
603 603 public:
604 604 AbstractMetaEnum() : m_type_entry(0), m_class(0), m_has_qenums_declaration(false) {}
605 605
606 606 AbstractMetaEnumValueList values() const { return m_enum_values; }
607 607 void addEnumValue(AbstractMetaEnumValue *enumValue) { m_enum_values << enumValue; }
608 608
609 609 QString name() const { return m_type_entry->targetLangName(); }
610 610 QString qualifier() const { return m_type_entry->javaQualifier(); }
611 611 QString package() const { return m_type_entry->javaPackage(); }
612 612 QString fullName() const { return package() + "." + qualifier() + "." + name(); }
613 613
614 614 // Has the enum been declared inside a Q_ENUMS() macro in its enclosing class?
615 615 void setHasQEnumsDeclaration(bool on) { m_has_qenums_declaration = on; }
616 616 bool hasQEnumsDeclaration() const { return m_has_qenums_declaration; }
617 617
618 618 EnumTypeEntry *typeEntry() const { return m_type_entry; }
619 619 void setTypeEntry(EnumTypeEntry *entry) { m_type_entry = entry; }
620 620
621 621 AbstractMetaClass *enclosingClass() const { return m_class; }
622 622 void setEnclosingClass(AbstractMetaClass *c) { m_class = c; }
623 623
624 624 private:
625 625 AbstractMetaEnumValueList m_enum_values;
626 626 EnumTypeEntry *m_type_entry;
627 627 AbstractMetaClass *m_class;
628 628
629 629 uint m_has_qenums_declaration : 1;
630 630 uint m_reserved : 31;
631 631 };
632 632
633 633 typedef QList<AbstractMetaEnum *> AbstractMetaEnumList;
634 634
635 635 class AbstractMetaClass : public AbstractMetaAttributes
636 636 {
637 637 public:
638 638 enum FunctionQueryOption {
639 639 Constructors = 0x000001, // Only constructors
640 640 //Destructors = 0x000002, // Only destructors. Not included in class.
641 641 VirtualFunctions = 0x000004, // Only virtual functions (virtual in both TargetLang and C++)
642 642 FinalInTargetLangFunctions = 0x000008, // Only functions that are non-virtual in TargetLang
643 643 FinalInCppFunctions = 0x000010, // Only functions that are non-virtual in C++
644 644 ClassImplements = 0x000020, // Only functions implemented by the current class
645 645 Inconsistent = 0x000040, // Only inconsistent functions (inconsistent virtualness in TargetLang/C++)
646 646 StaticFunctions = 0x000080, // Only static functions
647 647 Signals = 0x000100, // Only signals
648 648 NormalFunctions = 0x000200, // Only functions that aren't signals
649 649 Visible = 0x000400, // Only public and protected functions
650 650 ForcedShellFunctions = 0x000800, // Only functions that are overridden to be implemented in the shell class
651 651 WasPublic = 0x001000, // Only functions that were originally public
652 652 WasProtected = 0x002000, // Only functions that were originally protected
653 653 NonStaticFunctions = 0x004000, // No static functions
654 654 Empty = 0x008000, // Empty overrides of abstract functions
655 655 Invisible = 0x010000, // Only private functions
656 656 VirtualInCppFunctions = 0x020000, // Only functions that are virtual in C++
657 657 NonEmptyFunctions = 0x040000, // Only functions with JNI implementations
658 658 VirtualInTargetLangFunctions = 0x080000, // Only functions which are virtual in TargetLang
659 659 AbstractFunctions = 0x100000, // Only abstract functions
660 660 WasVisible = 0x200000, // Only functions that were public or protected in the original code
661 661 NotRemovedFromTargetLang = 0x400000, // Only functions that have not been removed from TargetLang
662 662 NotRemovedFromShell = 0x800000, // Only functions that have not been removed from the shell class
663 663 VirtualSlots = 0x1000000 // Only functions that are set as virtual slots in the type system
664 664 };
665 665
666 666 AbstractMetaClass()
667 667 : m_namespace(false),
668 668 m_qobject(false),
669 669 m_has_virtuals(false),
670 670 m_has_nonpublic(false),
671 671 m_has_virtual_slots(false),
672 672 m_has_nonprivateconstructor(false),
673 673 m_functions_fixed(false),
674 674 m_has_public_destructor(true),
675 675 m_force_shell_class(false),
676 676 m_has_hash_function(false),
677 677 m_has_equals_operator(false),
678 678 m_has_clone_operator(false),
679 679 m_is_type_alias(false),
680 680 m_enclosing_class(0),
681 681 m_base_class(0),
682 682 m_template_base_class(0),
683 683 m_extracted_interface(0),
684 684 m_primary_interface_implementor(0),
685 685 m_type_entry(0),
686 686 m_qDebug_stream_function(0)
687 687 {
688 688 }
689 689
690 690 virtual ~AbstractMetaClass();
691 691
692 692 AbstractMetaClass *extractInterface();
693 693 void fixFunctions();
694 694
695 695 AbstractMetaFunctionList functions() const { return m_functions; }
696 696 void setFunctions(const AbstractMetaFunctionList &functions);
697 697 void addFunction(AbstractMetaFunction *function);
698 698 bool hasFunction(const AbstractMetaFunction *f) const;
699 699 bool hasFunction(const QString &str) const;
700 700 bool hasSignal(const AbstractMetaFunction *f) const;
701 701
702 702 bool hasConstructors() const;
703 703
704 704 void addDefaultConstructor();
705 705
706 706 bool hasNonPrivateConstructor() const { return m_has_nonprivateconstructor; }
707 707 void setHasNonPrivateConstructor(bool on) { m_has_nonprivateconstructor = on; }
708 708 bool hasPublicDestructor() const { return m_has_public_destructor; }
709 709 void setHasPublicDestructor(bool on) { m_has_public_destructor = on; }
710 710
711 711 AbstractMetaFunctionList queryFunctionsByName(const QString &name) const;
712 712 AbstractMetaFunctionList queryFunctions(uint query) const;
713 713 inline AbstractMetaFunctionList allVirtualFunctions() const;
714 714 inline AbstractMetaFunctionList allFinalFunctions() const;
715 715 AbstractMetaFunctionList functionsInTargetLang() const;
716 716 AbstractMetaFunctionList functionsInShellClass() const;
717 717 inline AbstractMetaFunctionList cppInconsistentFunctions() const;
718 718 inline AbstractMetaFunctionList cppSignalFunctions() const;
719 719 AbstractMetaFunctionList publicOverrideFunctions() const;
720 720 AbstractMetaFunctionList virtualOverrideFunctions() const;
721 721 AbstractMetaFunctionList virtualFunctions() const;
722 722 AbstractMetaFunctionList nonVirtualShellFunctions() const;
723 723
724 724 AbstractMetaFieldList fields() const { return m_fields; }
725 725 void setFields(const AbstractMetaFieldList &fields) { m_fields = fields; }
726 726 void addField(AbstractMetaField *field) { m_fields << field; }
727 727
728 728 AbstractMetaEnumList enums() const { return m_enums; }
729 729 void setEnums(const AbstractMetaEnumList &enums) { m_enums = enums; }
730 730 void addEnum(AbstractMetaEnum *e) { m_enums << e; }
731 731
732 732 AbstractMetaEnum *findEnum(const QString &enumName);
733 733 AbstractMetaEnum *findEnumForValue(const QString &enumName);
734 734 AbstractMetaEnumValue *findEnumValue(const QString &enumName, AbstractMetaEnum *meta_enum);
735 735
736 736 AbstractMetaClassList interfaces() const { return m_interfaces; }
737 737 void addInterface(AbstractMetaClass *interface);
738 738 void setInterfaces(const AbstractMetaClassList &interface);
739 739
740 740 QString fullName() const { return package() + "." + name(); }
741 741 QString name() const;
742 742
743 743 QString baseClassName() const { return m_base_class ? m_base_class->name() : QString(); }
744 744
745 745 AbstractMetaClass *baseClass() const { return m_base_class; }
746 746 void setBaseClass(AbstractMetaClass *base_class) { m_base_class = base_class; }
747 747
748 748 const AbstractMetaClass *enclosingClass() const { return m_enclosing_class; }
749 749 void setEnclosingClass(AbstractMetaClass *cl) { m_enclosing_class = cl; }
750 750
751 751 QString package() const { return m_type_entry->javaPackage(); }
752 752 bool isInterface() const { return m_type_entry->isInterface(); }
753 753 bool isNamespace() const { return m_type_entry->isNamespace(); }
754 754 bool isQObject() const { return m_type_entry->isQObject(); }
755 755 bool isQtNamespace() const { return isNamespace() && name() == "Qt"; }
756 756 QString qualifiedCppName() const { return m_type_entry->qualifiedCppName(); }
757 757
758 758 bool hasInconsistentFunctions() const;
759 759 bool hasSignals() const;
760 760 bool inheritsFrom(const AbstractMetaClass *other) const;
761 761
762 762 void setForceShellClass(bool on) { m_force_shell_class = on; }
763 763 bool generateShellClass() const;
764 764
765 765 bool hasVirtualSlots() const { return m_has_virtual_slots; }
766 766 bool hasVirtualFunctions() const { return !isFinal() && m_has_virtuals; }
767 767 bool hasProtectedFunctions() const;
768 768
769 769 QList<TypeEntry *> templateArguments() const { return m_template_args; }
770 770 void setTemplateArguments(const QList<TypeEntry *> &args) { m_template_args = args; }
771 771
772 772 bool hasFieldAccessors() const;
773 773
774 774 // only valid during metajavabuilder's run
775 775 QStringList baseClassNames() const { return m_base_class_names; }
776 776 void setBaseClassNames(const QStringList &names) { m_base_class_names = names; }
777 777
778 778 AbstractMetaClass *primaryInterfaceImplementor() const { return m_primary_interface_implementor; }
779 779 void setPrimaryInterfaceImplementor(AbstractMetaClass *cl) { m_primary_interface_implementor = cl; }
780 780
781 781 const ComplexTypeEntry *typeEntry() const { return m_type_entry; }
782 782 ComplexTypeEntry *typeEntry() { return m_type_entry; }
783 783 void setTypeEntry(ComplexTypeEntry *type) { m_type_entry = type; }
784 784
785 785 void setHasHashFunction(bool on) { m_has_hash_function = on; }
786 786 bool hasHashFunction() const { return m_has_hash_function; }
787 787
788 788 void setToStringCapability(FunctionModelItem fun) { m_qDebug_stream_function= fun; }
789 789 FunctionModelItem hasToStringCapability() const { return m_qDebug_stream_function; }
790 790
791 791 virtual bool hasDefaultToStringFunction() const;
792 792
793 793 void setHasEqualsOperator(bool on) { m_has_equals_operator = on; }
794 794 bool hasEqualsOperator() const { return m_has_equals_operator; }
795 795
796 796 void setHasCloneOperator(bool on) { m_has_clone_operator = on; }
797 797 bool hasCloneOperator() const { return m_has_clone_operator; }
798 798
799 799 void addPropertySpec(QPropertySpec *spec) { m_property_specs << spec; }
800 800 QList<QPropertySpec *> propertySpecs() const { return m_property_specs; }
801 801
802 802 QPropertySpec *propertySpecForRead(const QString &name) const;
803 803 QPropertySpec *propertySpecForWrite(const QString &name) const;
804 804 QPropertySpec *propertySpecForReset(const QString &name) const;
805 805
806 806 QList<ReferenceCount> referenceCounts() const;
807 807
808 808 void setEqualsFunctions(const AbstractMetaFunctionList &lst) { m_equals_functions = lst; }
809 809 AbstractMetaFunctionList equalsFunctions() const { return m_equals_functions; }
810 810
811 811 void setNotEqualsFunctions(const AbstractMetaFunctionList &lst) { m_nequals_functions = lst; }
812 812 AbstractMetaFunctionList notEqualsFunctions() const { return m_nequals_functions; }
813 813
814 814 void setLessThanFunctions(const AbstractMetaFunctionList &lst) { m_less_than_functions = lst; }
815 815 AbstractMetaFunctionList lessThanFunctions() const { return m_less_than_functions; }
816 816
817 817 void setGreaterThanFunctions(const AbstractMetaFunctionList &lst) { m_greater_than_functions = lst; }
818 818 AbstractMetaFunctionList greaterThanFunctions() const { return m_greater_than_functions; }
819 819
820 820 void setLessThanEqFunctions(const AbstractMetaFunctionList &lst) { m_less_than_eq_functions = lst; }
821 821 AbstractMetaFunctionList lessThanEqFunctions() const { return m_less_than_eq_functions; }
822 822
823 823 void setGreaterThanEqFunctions(const AbstractMetaFunctionList &lst) { m_greater_than_eq_functions = lst; }
824 824 AbstractMetaFunctionList greaterThanEqFunctions() const { return m_greater_than_eq_functions; }
825 825
826 826 void sortFunctions();
827 827
828 828 const AbstractMetaClass *templateBaseClass() const { return m_template_base_class; }
829 829 void setTemplateBaseClass(const AbstractMetaClass *cls) { m_template_base_class = cls; }
830 830
831 831 void setTypeAlias(bool typeAlias) { m_is_type_alias = typeAlias; }
832 832 bool isTypeAlias() const { return m_is_type_alias; }
833 833
834 bool operator <(const AbstractMetaClass &a) const {
835 return qualifiedCppName() < a.qualifiedCppName();
836 }
837
834 838 private:
835 839 uint m_namespace : 1;
836 840 uint m_qobject : 1;
837 841 uint m_has_virtuals : 1;
838 842 uint m_has_nonpublic : 1;
839 843 uint m_has_virtual_slots : 1;
840 844 uint m_has_nonprivateconstructor : 1;
841 845 uint m_functions_fixed : 1;
842 846 uint m_has_public_destructor : 1;
843 847 uint m_force_shell_class : 1;
844 848 uint m_has_hash_function : 1;
845 849 uint m_has_equals_operator : 1;
846 850 uint m_has_clone_operator :1;
847 851 uint m_is_type_alias : 1;
848 852 uint m_reserved : 19;
849 853
850 854 const AbstractMetaClass *m_enclosing_class;
851 855 AbstractMetaClass *m_base_class;
852 856 const AbstractMetaClass *m_template_base_class;
853 857 AbstractMetaFunctionList m_functions;
854 858 AbstractMetaFieldList m_fields;
855 859 AbstractMetaEnumList m_enums;
856 860 AbstractMetaClassList m_interfaces;
857 861 AbstractMetaClass *m_extracted_interface;
858 862 AbstractMetaClass *m_primary_interface_implementor;
859 863 QList<QPropertySpec *> m_property_specs;
860 864 AbstractMetaFunctionList m_equals_functions;
861 865 AbstractMetaFunctionList m_nequals_functions;
862 866
863 867 AbstractMetaFunctionList m_less_than_functions;
864 868 AbstractMetaFunctionList m_greater_than_functions;
865 869 AbstractMetaFunctionList m_less_than_eq_functions;
866 870 AbstractMetaFunctionList m_greater_than_eq_functions;
867 871
868 872 QStringList m_base_class_names;
869 873 QList<TypeEntry *> m_template_args;
870 874 ComplexTypeEntry *m_type_entry;
871 875 FunctionModelItem m_qDebug_stream_function;
872 876 };
873 877
874 878 class QPropertySpec {
875 879 public:
876 880 QPropertySpec(const TypeEntry *type)
877 881 : m_type(type),
878 882 m_index(-1)
879 883 {
880 884 }
881 885
882 886 const TypeEntry *type() const { return m_type; }
883 887
884 888 QString name() const { return m_name; }
885 889 void setName(const QString &name) { m_name = name; }
886 890
887 891 QString read() const { return m_read; }
888 892 void setRead(const QString &read) { m_read = read; }
889 893
890 894 QString write() const { return m_write; }
891 895 void setWrite(const QString &write) { m_write = write; }
892 896
893 897 QString designable() const { return m_designable; }
894 898 void setDesignable(const QString &designable) { m_designable = designable; }
895 899
896 900 QString reset() const { return m_reset; }
897 901 void setReset(const QString &reset) { m_reset = reset; }
898 902
899 903 int index() const { return m_index; }
900 904 void setIndex(int index) { m_index = index; }
901 905
902 906 private:
903 907 QString m_name;
904 908 QString m_read;
905 909 QString m_write;
906 910 QString m_designable;
907 911 QString m_reset;
908 912 const TypeEntry *m_type;
909 913 int m_index;
910 914 };
911 915
912 916 inline AbstractMetaFunctionList AbstractMetaClass::allVirtualFunctions() const
913 917 {
914 918 return queryFunctions(VirtualFunctions
915 919 | NotRemovedFromTargetLang);
916 920 }
917 921
918 922 inline AbstractMetaFunctionList AbstractMetaClass::allFinalFunctions() const
919 923 {
920 924 return queryFunctions(FinalInTargetLangFunctions
921 925 | FinalInCppFunctions
922 926 | NotRemovedFromTargetLang);
923 927 }
924 928
925 929 inline AbstractMetaFunctionList AbstractMetaClass::cppInconsistentFunctions() const
926 930 {
927 931 return queryFunctions(Inconsistent
928 932 | NormalFunctions
929 933 | Visible
930 934 | NotRemovedFromTargetLang);
931 935 }
932 936
933 937 inline AbstractMetaFunctionList AbstractMetaClass::cppSignalFunctions() const
934 938 {
935 939 return queryFunctions(Signals
936 940 | Visible
937 941 | NotRemovedFromTargetLang);
938 942 }
939 943
940 944 #endif // ABSTRACTMETALANG_H
@@ -1,141 +1,142
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
4 4 ** All rights reserved.
5 5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 6 **
7 7 ** This file is part of the Qt Script Generator project on Qt Labs.
8 8 **
9 9 ** $QT_BEGIN_LICENSE:LGPL$
10 10 ** No Commercial Usage
11 11 ** This file contains pre-release code and may not be distributed.
12 12 ** You may use this file in accordance with the terms and conditions
13 13 ** contained in the Technology Preview License Agreement accompanying
14 14 ** this package.
15 15 **
16 16 ** GNU Lesser General Public License Usage
17 17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 18 ** General Public License version 2.1 as published by the Free Software
19 19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 20 ** packaging of this file. Please review the following information to
21 21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 23 **
24 24 ** In addition, as a special exception, Nokia gives you certain additional
25 25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 27 **
28 28 ** If you have questions regarding the use of this file, please contact
29 29 ** Nokia at qt-info@nokia.com.
30 30 **
31 31 **
32 32 **
33 33 **
34 34 **
35 35 **
36 36 **
37 37 **
38 38 ** $QT_END_LICENSE$
39 39 **
40 40 ****************************************************************************/
41 41
42 42 #include "generator.h"
43 43 #include "reporthandler.h"
44 44 #include "fileout.h"
45 45
46 46 #include <QDir>
47 47 #include <QFile>
48 48 #include <QFileInfo>
49 49
50 50 Generator::Generator()
51 51 {
52 52 m_num_generated = 0;
53 53 m_num_generated_written = 0;
54 54 m_out_dir = ".";
55 55 }
56 56
57 57 void Generator::generate()
58 58 {
59 59 if (m_classes.size() == 0) {
60 60 ReportHandler::warning(QString("%1: no java classes, skipping")
61 61 .arg(metaObject()->className()));
62 62 return;
63 63 }
64 64
65 qStableSort(m_classes);
65 66
66 67 foreach (AbstractMetaClass *cls, m_classes) {
67 68 if (!shouldGenerate(cls))
68 69 continue;
69 70
70 71 QString fileName = fileNameForClass(cls);
71 72 ReportHandler::debugSparse(QString("generating: %1").arg(fileName));
72 73
73 74 FileOut fileOut(outputDirectory() + "/" + subDirectoryForClass(cls) + "/" + fileName);
74 75 write(fileOut.stream, cls);
75 76
76 77 if( fileOut.done() )
77 78 ++m_num_generated_written;
78 79 ++m_num_generated;
79 80 }
80 81 }
81 82
82 83
83 84 void Generator::printClasses()
84 85 {
85 86 QTextStream s(stdout);
86 87
87 88 AbstractMetaClassList classes = m_classes;
88 89 qSort(classes);
89 90
90 91 foreach (AbstractMetaClass *cls, classes) {
91 92 if (!shouldGenerate(cls))
92 93 continue;
93 94 write(s, cls);
94 95 s << endl << endl;
95 96 }
96 97 }
97 98
98 99 void Generator::verifyDirectoryFor(const QFile &file)
99 100 {
100 101 QDir dir = QFileInfo(file).dir();
101 102 if (!dir.exists()) {
102 103 if (!dir.mkpath(dir.absolutePath()))
103 104 ReportHandler::warning(QString("unable to create directory '%1'")
104 105 .arg(dir.absolutePath()));
105 106 }
106 107 }
107 108
108 109 QString Generator::subDirectoryForClass(const AbstractMetaClass *) const
109 110 {
110 111 Q_ASSERT(false);
111 112 return QString();
112 113 }
113 114
114 115 QString Generator::fileNameForClass(const AbstractMetaClass *) const
115 116 {
116 117 Q_ASSERT(false);
117 118 return QString();
118 119 }
119 120
120 121 void Generator::write(QTextStream &, const AbstractMetaClass *)
121 122 {
122 123 Q_ASSERT(false);
123 124 }
124 125
125 126 bool Generator::hasDefaultConstructor(const AbstractMetaType *type)
126 127 {
127 128 QString full_name = type->typeEntry()->qualifiedTargetLangName();
128 129 QString class_name = type->typeEntry()->targetLangName();
129 130
130 131 foreach (const AbstractMetaClass *java_class, m_classes) {
131 132 if (java_class->typeEntry()->qualifiedTargetLangName() == full_name) {
132 133 AbstractMetaFunctionList functions = java_class->functions();
133 134 foreach (const AbstractMetaFunction *function, functions) {
134 135 if (function->arguments().size() == 0 && function->name() == class_name)
135 136 return true;
136 137 }
137 138 return false;
138 139 }
139 140 }
140 141 return false;
141 142 }
General Comments 0
You need to be logged in to leave comments. Login now