Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/tools/moc/generator.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the tools applications of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
     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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4646#include <stdio.h>
    4747
     48#include <private/qmetaobject_p.h> //for the flags.
     49
    4850QT_BEGIN_NAMESPACE
    49 
    50 // if the flags change, you MUST to change it in qmetaobject.cpp too
    51 enum PropertyFlags  {
    52     Invalid = 0x00000000,
    53     Readable = 0x00000001,
    54     Writable = 0x00000002,
    55     Resettable = 0x00000004,
    56     EnumOrFlag = 0x00000008,
    57     StdCppSet = 0x00000100,
    58 //     Override = 0x00000200,
    59     Designable = 0x00001000,
    60     ResolveDesignable = 0x00002000,
    61     Scriptable = 0x00004000,
    62     ResolveScriptable = 0x00008000,
    63     Stored = 0x00010000,
    64     ResolveStored = 0x00020000,
    65     Editable = 0x00040000,
    66     ResolveEditable = 0x00080000,
    67     User = 0x00100000,
    68     ResolveUser = 0x00200000,
    69     Notify = 0x00400000
    70 };
    71 enum MethodFlags {
    72     AccessPrivate = 0x00,
    73     AccessProtected = 0x01,
    74     AccessPublic = 0x02,
    75     MethodMethod = 0x00,
    76     MethodSignal = 0x04,
    77     MethodSlot = 0x08,
    78     MethodConstructor = 0x0c,
    79     MethodCompatibility = 0x10,
    80     MethodCloned = 0x20,
    81     MethodScriptable = 0x40
    82 };
    8351
    8452uint qvariant_nameToType(const char* name)
     
    10876{
    10977    return qvariant_nameToType(type) != 0;
     78}
     79
     80/*!
     81  Returns true if the type is qreal.
     82*/
     83static bool isQRealType(const char *type)
     84{
     85    return strcmp(type, "qreal") == 0;
    11086}
    11187
     
    195171    qualifiedClassNameIdentifier.replace(':', '_');
    196172
    197     int index = 12;
     173    int index = 14;
    198174    fprintf(out, "static const uint qt_meta_data_%s[] = {\n", qualifiedClassNameIdentifier.constData());
    199175    fprintf(out, "\n // content:\n");
    200     fprintf(out, "    %4d,       // revision\n", 2);
     176    fprintf(out, "    %4d,       // revision\n", 4);
    201177    fprintf(out, "    %4d,       // classname\n", strreg(cdef->qualified));
    202178    fprintf(out, "    %4d, %4d, // classinfo\n", cdef->classInfoList.count(), cdef->classInfoList.count() ? index : 0);
     
    217193    fprintf(out, "    %4d, %4d, // constructors\n", isConstructible ? cdef->constructorList.count() : 0,
    218194            isConstructible ? index : 0);
     195
     196    fprintf(out, "    %4d,       // flags\n", 0);
     197    fprintf(out, "    %4d,       // signalCount\n", cdef->signalList.count());
     198
    219199
    220200//
     
    313293    for (int i = 0; i < cdef->propertyList.count(); ++i) {
    314294        const PropertyDef &p = cdef->propertyList.at(i);
    315         if (!isVariantType(p.type) && !metaTypes.contains(p.type)) {
     295        if (!isVariantType(p.type) && !metaTypes.contains(p.type) && !p.type.contains('*') &&
     296                !p.type.contains('<') && !p.type.contains('>')) {
    316297            int s = p.type.lastIndexOf("::");
    317298            if (s > 0) {
     
    323304    }
    324305    if (!extraList.isEmpty()) {
     306        fprintf(out, "#ifdef Q_NO_DATA_RELOCATION\n");
     307        fprintf(out, "static const QMetaObjectAccessor qt_meta_extradata_%s[] = {\n    ", qualifiedClassNameIdentifier.constData());
     308        for (int i = 0; i < extraList.count(); ++i) {
     309            fprintf(out, "    %s::getStaticMetaObject,\n", extraList.at(i).constData());
     310        }
     311        fprintf(out, "#else\n");
    325312        fprintf(out, "static const QMetaObject *qt_meta_extradata_%s[] = {\n    ", qualifiedClassNameIdentifier.constData());
    326313        for (int i = 0; i < extraList.count(); ++i) {
    327             if (i)
    328                 fprintf(out, ",\n    ");
    329             fprintf(out, "    &%s::staticMetaObject", extraList.at(i).constData());
    330         }
    331         fprintf(out, ",0\n};\n\n");
     314            fprintf(out, "    &%s::staticMetaObject,\n", extraList.at(i).constData());
     315        }
     316        fprintf(out, "#endif //Q_NO_DATA_RELOCATION\n");
     317        fprintf(out, "    0\n};\n\n");
    332318    }
    333319
     
    349335// Finally create and initialize the static meta object
    350336//
    351 
    352337    if (isQt)
    353338        fprintf(out, "const QMetaObject QObject::staticQtMetaObject = {\n");
     
    369354    fprintf(out, "};\n");
    370355
    371     if (isQt || !cdef->hasQObject)
     356    if(isQt)
    372357        return;
    373358
    374     fprintf(out, "\nconst QMetaObject *%s::metaObject() const\n{\n    return &staticMetaObject;\n}\n",
     359//
     360// Generate static meta object accessor (needed for symbian, because DLLs do not support data imports.
     361//
     362    fprintf(out, "\n#ifdef Q_NO_DATA_RELOCATION\n");
     363    fprintf(out, "const QMetaObject &%s::getStaticMetaObject() { return staticMetaObject; }\n", cdef->qualified.constData());
     364    fprintf(out, "#endif //Q_NO_DATA_RELOCATION\n");
     365
     366    if (!cdef->hasQObject)
     367        return;
     368
     369    fprintf(out, "\nconst QMetaObject *%s::metaObject() const\n{\n    return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;\n}\n",
    375370            cdef->qualified.constData());
     371
    376372//
    377373// Generate smart cast function
     
    546542        if (!isVariantType(p.type)) {
    547543            flags |= EnumOrFlag;
    548         } else {
     544        } else if (!isQRealType(p.type)) {
    549545            flags |= qvariant_nameToType(p.type) << 24;
    550546        }
     
    590586            flags |= Notify;
    591587
    592         fprintf(out, "    %4d, %4d, 0x%.8x,\n",
    593                  strreg(p.name),
    594                  strreg(p.type),
    595                  flags);
     588        if (p.constant)
     589            flags |= Constant;
     590        if (p.final)
     591            flags |= Final;
     592
     593        fprintf(out, "    %4d, %4d, ",
     594                strreg(p.name),
     595                strreg(p.type));
     596        if (!(flags >> 24) && isQRealType(p.type))
     597            fprintf(out, "(QMetaType::QReal << 24) | ");
     598        fprintf(out, "0x%.8x,\n", flags);
    596599    }
    597600
     
    723726            needUser |= p.user.endsWith(')');
    724727        }
    725         bool needAnything = needGet
    726                             | needSet
    727                             | needReset
    728                             | needDesignable
    729                             | needScriptable
    730                             | needStored
    731                             | needEditable
    732                             | needUser;
    733         if (!needAnything)
    734             goto skip_properties;
    735728        fprintf(out, "\n#ifndef QT_NO_PROPERTIES\n     ");
    736729
     
    902895        fprintf(out, "\n#endif // QT_NO_PROPERTIES");
    903896    }
    904  skip_properties:
    905897    if (methodList.size() || cdef->signalList.size() || cdef->propertyList.size())
    906898        fprintf(out, "\n    ");
     
    919911    for (int ctorindex = 0; ctorindex < cdef->constructorList.count(); ++ctorindex) {
    920912        fprintf(out, "        case %d: { %s *_r = new %s(", ctorindex,
    921                 cdef->classname.constData(), cdef->classname.constData());
     913                cdef->qualified.constData(), cdef->qualified.constData());
    922914        const FunctionDef &f = cdef->constructorList.at(ctorindex);
    923915        int offset = 1;
     
    937929
    938930    if (!isQObject)
    939         fprintf(out, "    _id = %s::staticMetaObject.superClass()->static_metacall(_c, _id, _a);\n", cdef->classname.constData());
     931        fprintf(out, "    _id = %s::staticMetaObject.superClass()->static_metacall(_c, _id, _a);\n", cdef->qualified.constData());
    940932
    941933    fprintf(out, "    if (_id < 0)\n        return _id;\n");
     
    996988            fprintf(out, ", const_cast<void*>(reinterpret_cast<const void*>(&_t%d))", i);
    997989    fprintf(out, " };\n");
    998     int n = 0;
    999     for (i = 0; i < def->arguments.count(); ++i)
    1000         if (def->arguments.at(i).isDefault)
    1001             ++n;
    1002     if (n)
    1003         fprintf(out, "    QMetaObject::activate(%s, &staticMetaObject, %d, %d, _a);\n", thisPtr.constData(), index, index + n);
    1004     else
    1005         fprintf(out, "    QMetaObject::activate(%s, &staticMetaObject, %d, _a);\n", thisPtr.constData(), index);
     990    fprintf(out, "    QMetaObject::activate(%s, &staticMetaObject, %d, _a);\n", thisPtr.constData(), index);
    1006991    if (def->normalizedType.size())
    1007992        fprintf(out, "    return _t0;\n");
     
    11621147            const ArgumentDef &a = f.arguments.at(j);
    11631148            if (j) {
    1164                 sig += ",";
    1165                 arguments += ",";
     1149                sig += ',';
     1150                arguments += ',';
    11661151            }
    11671152            sig += a.normalizedType;
Note: See TracChangeset for help on using the changeset viewer.