Alien-SmokeQt

 view release on metacpan or  search on metacpan

generator/generators/smoke/writeSmokeDataFile.cpp  view on Meta::CPAN

/*
    Generator for the SMOKE sources
    Copyright (C) 2009 Arno Rehn <arno@arnorehn.de>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QMap>
#include <QTextStream>

#include <type.h>

#include "globals.h"
#include "../../options.h"

uint qHash(const QVector<int> intList)
{
    const char *byteArray = (const char*) intList.constData();
    int length = sizeof(int) * intList.count();
    return qHash(QByteArray::fromRawData(byteArray, length));
}

SmokeDataFile::SmokeDataFile()
{
    qDebug("preparing SMOKE data [%s]", qPrintable(Options::module));
    
    for (QHash<QString, Class>::const_iterator iter = ::classes.constBegin(); iter != ::classes.constEnd(); iter++) {
        if (Options::classList.contains(iter.key()) && !iter.value().isForwardDecl()) {
            classIndex[iter.key()] = 1;
        }
    }
    
    // superclasses might be in different modules, still they need to be indexed for inheritanceList to work properly
    QSet<const Class*> superClasses;
    includedClasses = classIndex.keys();
    Util::preparse(&usedTypes, &superClasses, includedClasses);  // collect all used types, add c'tors.. etc.
    
    // Collect the classes that are inherited by classes in this smoke module and provide virtual methods.
    // These classes need to be indexed as well.
    foreach (const QString& className, includedClasses) {
        const Class* klass = &classes[className];
        QList<const Method*> list = Util::virtualMethodsForClass(klass);
        foreach (const Method* meth, list) {
            usedTypes << meth->type();
            foreach (const Parameter& param, meth->parameters()) {
                usedTypes << param.type();
            }
            declaredVirtualMethods[meth->getClass()] << meth;
        }
    }
    
    // if a class is used somewhere but not listed in the class list, mark it external
    for (QHash<QString, Class>::iterator iter = ::classes.begin(); iter != ::classes.end(); iter++) {
        if (iter.value().isTemplate() || Options::voidpTypes.contains(iter.key()))
            continue;
        
        if (   (isClassUsed(&iter.value()) && iter.value().access() != Access_private)
            || superClasses.contains(&iter.value())
            || declaredVirtualMethods.contains(&iter.value()))
        {
            classIndex[iter.key()] = 1;
            
            if (!Options::classList.contains(iter.key()) || iter.value().isForwardDecl())
                externalClasses << &iter.value();
            else if (!includedClasses.contains(iter.key()))
                includedClasses << iter.key();
        } else if (iter.value().isNameSpace() && (Options::classList.contains(iter.key()) || iter.key() == "QGlobalSpace")) {
            // wanted namespace or QGlobalSpace
            classIndex[iter.key()] = 1;
            includedClasses << iter.key();
        }
    }
    



( run in 2.908 seconds using v1.01-cache-2.11-cpan-13bb782fe5a )