Alien-SmokeQt

 view release on metacpan or  search on metacpan

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

        return cache[klass];
    
    bool ctorFound = false, publicCtorFound = false, privatePureVirtualsFound = false;
    foreach (const Method& meth, klass->methods()) {
        if (meth.isConstructor()) {
            ctorFound = true;
            if (meth.access() != Access_private) {
                // this class can be instanstiated
                publicCtorFound = true;
            }
        } else if ((meth.flags() & Method::PureVirtual) && meth.access() == Access_private) {
            privatePureVirtualsFound = true;
        }
    }
    
    // The class can be instanstiated if it has a public constructor or no constructor at all
    // because then it has a default one generated by the compiler.
    // If it has private pure virtuals, then it can't be instanstiated either.
    bool ret = ((publicCtorFound || !ctorFound) && !privatePureVirtualsFound);
    cache[klass] = ret;
    return ret;

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

}

bool Util::hasClassVirtualDestructor(const Class* klass)
{
    static QHash<const Class*, bool> cache;
    if (cache.contains(klass))
        return cache[klass];

    bool virtualDtorFound = false;
    foreach (const Method& meth, klass->methods()) {
        if (meth.isDestructor() && meth.flags() & Method::Virtual) {
            virtualDtorFound = true;
            break;
        }
    }
    
    bool superClassHasVirtualDtor = false;
    foreach (const Class::BaseClassSpecifier& bspec, klass->baseClasses()) {
        if (hasClassVirtualDestructor(bspec.baseClass)) {
            superClassHasVirtualDtor = true;
            break;

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

    }
    return 0;
}

void Util::checkForAbstractClass(Class* klass)
{
    QList<const Method*> list;
    
    bool hasPrivatePureVirtuals = false;
    foreach (const Method& meth, klass->methods()) {
        if ((meth.flags() & Method::PureVirtual) && meth.access() == Access_private)
            hasPrivatePureVirtuals = true;
        if (meth.isConstructor())
            list << &meth;
    }
    
    // abstract classes can't be instanstiated - remove the constructors
    if (hasPrivatePureVirtuals) {
        foreach (const Method* ctor, list) {
            klass->methodsRef().removeOne(*ctor);
        }

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

        ret += '(' + var + ')';
        return ret;
    }
    return QString();
}

QList<const Method*> Util::collectVirtualMethods(const Class* klass)
{
    QList<const Method*> methods;
    foreach (const Method& meth, klass->methods()) {
        if ((meth.flags() & Method::Virtual || meth.flags() & Method::PureVirtual)
            && !meth.isDestructor() && meth.access() != Access_private)
        {
            methods << &meth;
        }
    }
    foreach (const Class::BaseClassSpecifier& baseClass, klass->baseClasses()) {
        methods += collectVirtualMethods(baseClass.baseClass);
    }
    return methods;
}

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

    Class* klass = field.getClass();
    Type* type = field.type();
    if (type->getClass() && type->pointerDepth() == 0) {
        Type newType = *type;
        newType.setIsRef(true);
        type = Type::registerType(newType);
    }
    (*usedTypes) << type;
    Method getter = Method(klass, field.name(), type, field.access());
    getter.setIsConst(true);
    if (field.flags() & Field::Static)
        getter.setFlag(Method::Static);
    klass->appendMethod(getter);
    fieldAccessors[&klass->methods().last()] = &field;
    
    // constant field? (i.e. no setter method)
    if (field.type()->isConst() && field.type()->pointerDepth() == 0)
        return;
    
    // foo => setFoo
    QString newName = field.name();
    newName[0] = newName[0].toUpper();
    Method setter = Method(klass, "set" + newName, const_cast<Type*>(Type::Void), field.access());
    if (field.flags() & Field::Static)
        setter.setFlag(Method::Static);
    
    // reset
    type = field.type();
    // to avoid copying around more stuff than necessary, convert setFoo(Bar) to setFoo(const Bar&)
    if (type->pointerDepth() == 0 && type->getClass() && !(ParserOptions::qtMode && type->getClass()->name() == "QFlags")) {
        Type newType = *type;
        newType.setIsRef(true);
        newType.setIsConst(true);
        type = Type::registerType(newType);

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

    ParameterList params;
    Class* klass = meth.getClass();
    
    for (int i = 0; i < meth.parameters().count(); i++) {
        const Parameter& param = meth.parameters()[i];
        if (!param.isDefault()) {
            params << param;
            continue;
        }
        Method overload = meth;
        if (meth.flags() & Method::PureVirtual) {
            overload.setFlag(Method::DynamicDispatch);
        }
        overload.removeFlag(Method::Virtual);
        overload.removeFlag(Method::PureVirtual);
        overload.setParameterList(params);
        if (klass->methods().contains(overload)) {
            // we already have that, skip it
            params << param;
            continue;
        }

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

        klass->appendMethod(overload);
        
        params << param;
    }
}

// checks if method meth is overriden in class klass or any of its superclasses
const Method* Util::isVirtualOverriden(const Method& meth, const Class* klass)
{
    // is the method virtual at all?
    if (!(meth.flags() & Method::Virtual) && !(meth.flags() & Method::PureVirtual))
        return 0;
    
    // if the method is defined in klass, it can't be overriden there or in any parent class
    if (meth.getClass() == klass)
        return 0;
    
    foreach (const Method& m, klass->methods()) {
        if (!(m.flags() & Method::Static) && m == meth)
            // the method m overrides meth
            return &m;
    }
    
    foreach (const Class::BaseClassSpecifier& base, klass->baseClasses()) {
        // we reached the class in which meth was defined and we still didn't find any overrides => return
        if (base.baseClass == meth.getClass())
            return 0;
        
        // recurse into the base classes

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

            includes.insert(func->fileName());

        if (meth.type()->getClass())
            includes.insert(meth.type()->getClass()->fileName());

        if (meth.type()->isFunctionPointer() || meth.type()->isArray())
            out << meth.type()->toString("xret") << " = ";
        else if (meth.type() != Type::Void)
            out << meth.type()->toString() << " xret = ";

        if (!(meth.flags() & Method::Static)) {
            if (meth.isConst()) {
                out << "((const " << smokeClassName << "*)this)->";
            } else {
                out << "this->";
            }
        }
        if (!dynamicDispatch && !func) {
            // dynamic dispatch not wanted, call with 'this->Foo::method()'
            out << className << "::";
        } else if (func) {

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

        out << indent << "(void)x; // noop (for compiler warning)\n";
    }

    return methodBody;
}

void SmokeClassFiles::generateMethod(QTextStream& out, const QString& className, const QString& smokeClassName,
                                     const Method& meth, int index, QSet<QString>& includes)
{
    out << "    ";
    if ((meth.flags() & Method::Static) || meth.isConstructor())
        out << "static ";
    out << QString("void x_%1(Smoke::Stack x) {\n").arg(index);
    out << "        // " << meth.toString() << "\n";

    bool dynamicDispatch = ((meth.flags() & Method::PureVirtual) || (meth.flags() & Method::DynamicDispatch));

    if (dynamicDispatch || !Util::virtualMethodsForClass(meth.getClass()).contains(&meth)) {
        // This is either already flagged as dynamic dispatch or just a normal method. We can generate a normal method call for it.

        out << generateMethodBody("        ",   // indent
                                  className, smokeClassName, meth, index, dynamicDispatch, includes);
    } else {
        // This is a virtual method. To know whether we should call with dynamic dispatch, we need a bit of RTTI magic.
        includes.insert("typeinfo");
        out << "        if (dynamic_cast<__internal_SmokeClass*>(static_cast<" << className << "*>(this))) {\n";   //
        out << generateMethodBody("            ",   // indent
                                  className, smokeClassName, meth, index, false, includes);
        out << "        } else {\n";

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

        }
        out << ") : " << meth.getClass()->name() << '(' << x_list.join(", ") << ") {}\n";
    }
}

void SmokeClassFiles::generateGetAccessor(QTextStream& out, const QString& className, const Field& field,
                                          const Type* type, int index)
{
    out << "    ";
    QString fieldName;
    if (field.flags() & Field::Static) {
        out << "static ";
    } else {
        fieldName = "this->";
    }
    fieldName += className + "::" + field.name();
    out << "void x_" << index << "(Smoke::Stack x) {\n"
        << "        // " << field.toString() << "\n"
        << "        x[0]." << Util::stackItemField(type) << " = "
            << Util::assignmentString(type, fieldName) << ";\n"
        << "    }\n";
}

void SmokeClassFiles::generateSetAccessor(QTextStream& out, const QString& className, const Field& field,
                                          const Type* type, int index)
{
    out << "    ";
    QString fieldName;
    if (field.flags() & Field::Static) {
        out << "static ";
    } else {
        fieldName = "this->";
    }
    fieldName += className + "::" + field.name();
    out << "void x_" << index << "(Smoke::Stack x) {\n"
        << "        // " << field.toString() << "=\n"
        << "        " << fieldName << " = ";
    QString unionField = Util::stackItemField(type);
    QString cast = type->toString();

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

        for (int i = 0; i < meth.exceptionTypes().count(); i++) {
            if (i > 0) out << ", ";
            out << meth.exceptionTypes()[i].toString();
        }
        out << ") ";
    }
    out << "{\n";
    out << QString("        Smoke::StackItem x[%1];\n").arg(meth.parameters().count() + 1);
    out << x_params;
    
    if (meth.flags() & Method::PureVirtual) {
        out << QString("        this->_binding->callMethod(%1, (void*)this, x, true /*pure virtual*/);\n").arg(m_smokeData->methodIdx[&meth]);
        if (meth.type() != Type::Void) {
            QString field = Util::stackItemField(meth.type());
            if (meth.type()->pointerDepth() == 0 && field == "s_class") {
                QString tmpType = type;
                if (meth.type()->isRef()) tmpType.replace('&', "");
                tmpType.append('*');
                out << "        " << tmpType << " xptr = (" << tmpType << ")x[0].s_class;\n";
                out << "        " << type << " xret(*xptr);\n";
                out << "        delete xptr;\n";

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

    int xcall_index = 1;
    const Method *destructor = 0;
    foreach (const Method& meth, klass->methods()) {
        if (meth.access() == Access_private)
            continue;
        if (meth.isDestructor()) {
            destructor = &meth;
            continue;
        }
        switchOut << "        case " << xcall_index << ": "
                  << (((meth.flags() & Method::Static) || meth.isConstructor()) ? smokeClassName + "::" : "xself->")
                  << "x_" << xcall_index << "(args);\tbreak;\n";
        if (Util::fieldAccessors.contains(&meth)) {
            // accessor method?
            const Field* field = Util::fieldAccessors[&meth];
            if (meth.name().startsWith("set")) {
                generateSetAccessor(out, className, *field, meth.parameters()[0].type(), xcall_index);
            } else {
                generateGetAccessor(out, className, *field, meth.type(), xcall_index);
            }
        } else {

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

    return false;
}

QString SmokeDataFile::getTypeFlags(const Type *t, int *classIdx)
{
    if (t->getTypedef()) {
        Type resolved = t->getTypedef()->resolve();
        return getTypeFlags(&resolved, classIdx);
    }

    QString flags = "0";
    if (Options::voidpTypes.contains(t->name())) {
        // support some of the weird quirks the kalyptus code has
        flags += "|Smoke::t_voidp";
    } else if (t->getClass()) {
        if (t->getClass()->isTemplate()) {
            if (Options::qtMode && t->getClass()->name() == "QFlags" && !t->isRef() && t->pointerDepth() == 0) {
                flags += "|Smoke::t_uint";
            } else {
                flags += "|Smoke::t_voidp";
            }
        } else {
            flags += "|Smoke::t_class";
            *classIdx = classIndex.value(t->getClass()->toString(), 0);
        }
    } else if (t->isIntegral() && t->name() != "void" && t->pointerDepth() == 0 && !t->isRef()) {
        flags += "|Smoke::t_";
        QString typeName = t->name();

        // replace the unsigned stuff, look the type up in Util::typeMap and if
        // necessary, add a 'u' for unsigned types at the beginning again
        bool _unsigned = false;
        if (typeName.startsWith("unsigned ")) {
            typeName.replace("unsigned ", "");
            _unsigned = true;
        }
        typeName.replace("signed ", "");
        typeName = Util::typeMap.value(typeName, typeName);
        if (_unsigned)
            typeName.prepend('u');

        flags += typeName;
    } else if (t->getEnum()) {
        flags += "|Smoke::t_enum";
        if (t->getEnum()->parent()) {
            *classIdx = classIndex.value(t->getEnum()->parent()->toString(), 0);
        } else if (!t->getEnum()->nameSpace().isEmpty()) {
            *classIdx = classIndex.value(t->getEnum()->nameSpace(), 0);
        } else {
            *classIdx = classIndex.value("QGlobalSpace", 0);
        }
    } else {
        flags += "|Smoke::t_voidp";
    }

    if (t->isRef())
        flags += "|Smoke::tf_ref";
    if (t->pointerDepth() > 0)
        flags += "|Smoke::tf_ptr";
    if (!t->isRef() && t->pointerDepth() == 0)
        flags += "|Smoke::tf_stack";
    if (t->isConst())
        flags += "|Smoke::tf_const";
    flags.replace("0|", "");

    return flags;
}

void SmokeDataFile::write()
{
    qDebug("writing out smokedata.cpp [%s]", qPrintable(Options::module));
    QFile smokedata(Options::outputDir.filePath("smokedata.cpp"));
    smokedata.open(QFile::ReadWrite | QFile::Truncate);
    QTextStream out(&smokedata);
    foreach (const QFileInfo& file, Options::headerList)
        out << "#include <" << file.fileName() << ">\n";

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

    for (QMap<QString, int>::const_iterator iter = classIndex.constBegin(); iter != classIndex.constEnd(); iter++) {
        Class& klass = classes[iter.key()];
        if (externalClasses.contains(&klass) || klass.isTemplate())
            continue;
        QString smokeClassName = QString(klass.toString()).replace("::", "__");
        out << "void xcall_" << smokeClassName << "(Smoke::Index, void*, Smoke::Stack);\n";
    }
    
    // classes table
    out << "\n// List of all classes\n";
    out << "// Name, external, index into inheritanceList, method dispatcher, enum dispatcher, class flags, size\n";
    out << "static Smoke::Class classes[] = {\n";
    out << "    { 0L, false, 0, 0, 0, 0, 0 },\t// 0 (no class)\n";
    int classCount = 0;
    for (QMap<QString, int>::const_iterator iter = classIndex.constBegin(); iter != classIndex.constEnd(); iter++) {
        if (!iter.value())
            continue;
        
        Class* klass = &classes[iter.key()];
        
        if (externalClasses.contains(klass)) {
            out << "    { \""  << iter.key() << "\", true, 0, 0, 0, 0, 0 },\t//" << iter.value() << "\n";
        } else {
            QString smokeClassName = QString(iter.key()).replace("::", "__");
            out << "    { \"" << iter.key() << "\", false" << ", "
                << inheritanceIndex.value(klass, 0) << ", xcall_" << smokeClassName << ", "
                << (enumClassesHandled.contains(iter.key()) ? QString("xenum_").append(smokeClassName) : "0") << ", ";
            QString flags = "0";
            if (!klass->isNameSpace()) {
                if (Util::canClassBeInstanciated(klass)) flags += "|Smoke::cf_constructor";
                if (Util::canClassBeCopied(klass)) flags += "|Smoke::cf_deepcopy";
                if (Util::hasClassVirtualDestructor(klass)) flags += "|Smoke::cf_virtual";
                flags.replace("0|", ""); // beautify
            } else {
                flags = "Smoke::cf_namespace";
            }
            out << flags << ", ";
            if (!klass->isNameSpace())
                out << "sizeof(" << iter.key() << ")";
            else
                out << '0';
            out << " },\t//" << iter.value() << "\n";
        }
        classCount = iter.value();
    }
    out << "};\n\n";
    

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

        }
    }
    
    int i = 1;
    for (QMap<QString, Type*>::const_iterator it = sortedTypes.constBegin(); it != sortedTypes.constEnd(); it++) {
        Type* t = it.value();
        // don't include void as a type
        if (t == Type::Void)
            continue;
        int classIdx = 0;
        QString flags = getTypeFlags(t, &classIdx);
        typeIndex[t] = i;
        out << "    { \"" << it.key() << "\", " << classIdx << ", " << flags << " },\t//" << i++ << "\n";
    }
    out << "};\n\n";
    
    out << "static Smoke::Index argumentList[] = {\n";
    out << "    0,\t//0  (void)\n";
    
    QHash<QVector<int>, int> parameterList;
    QHash<const Method*, int> parameterIndices;
    
    // munged name => index

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

    out << "// Raw list of all methods, using munged names\n";
    out << "static const char *methodNames[] = {\n";
    out << "    \"\",\t//0\n";
    i = 1;
    for (QMap<QString, int>::iterator it = methodNames.begin(); it != methodNames.end(); it++, i++) {
        it.value() = i;
        out << "    \"" << it.key() << "\",\t//" << i << "\n";
    }
    out << "};\n\n";
    
    out << "// (classId, name (index in methodNames), argumentList index, number of args, method flags, "
        << "return type (index in types), xcall() index)\n";
    out << "static Smoke::Method methods[] = {\n";
    out << "    { 0, 0, 0, 0, 0, 0, 0 },\t// (no method)\n";
    
    i = 1;
    int methodCount = 1;
    for (QMap<QString, int>::const_iterator iter = classIndex.constBegin(); iter != classIndex.constEnd(); iter++) {
        Class* klass = &classes[iter.key()];
        const Method* destructor = 0;
        bool isExternal = false;

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

                destructor = &meth;
                continue;
            }
            out << "    {" << iter.value() << ", " << methodNames[meth.name()] << ", ";
            int numArgs = meth.parameters().count();
            if (numArgs) {
                out << parameterIndices[&meth] << ", " << numArgs << ", ";
            } else {
                out << "0, 0, ";
            }
            QString flags = "0";
            if (meth.isConst())
                flags += "|Smoke::mf_const";
            if (meth.flags() & Method::Static)
                flags += "|Smoke::mf_static";
            if (meth.isConstructor())
                flags += "|Smoke::mf_ctor";
            if (meth.flags() & Method::Explicit)
                flags += "|Smoke::mf_explicit";
            if (meth.access() == Access_protected)
                flags += "|Smoke::mf_protected";
            if (meth.isConstructor() &&
                meth.parameters().count() == 1 &&
                meth.parameters()[0].type()->isConst() &&
                meth.parameters()[0].type()->getClass() == klass)
                flags += "|Smoke::mf_copyctor";
            if (Util::fieldAccessors.contains(&meth))
                flags += "|Smoke::mf_attribute";
            if (meth.isQPropertyAccessor())
                flags += "|Smoke::mf_property";
            
            // Simply checking for flags() & Method::Virtual won't be enough, because methods can override virtuals without being
            // declared 'virtual' themselves (and they're still virtual, then).
            if (virtualMethods.contains(&meth))
                flags += "|Smoke::mf_virtual";
            if (meth.flags() & Method::PureVirtual)
                flags += "|Smoke::mf_purevirtual";
            if (meth.isSignal())
                flags += "|Smoke::mf_signal";
            else if (meth.isSlot())
                flags += "|Smoke::mf_slot";

            flags.replace("0|", "");
            out << flags;
            if (meth.type() == Type::Void) {
                out << ", 0";
            } else if (!typeIndex.contains(meth.type())) {
                qFatal("missing type: %s in method %s (while writing out methods table)", qPrintable(meth.type()->toString()), qPrintable(meth.toString(false, true)));
            } else {
                out << ", " << typeIndex[meth.type()];
            }
            out << ", " << (isExternal ? 0 : xcall_index) << "},";
            
            // comment
            out << "\t//" << i << " " << klass->toString() << "::";
            out << meth.name() << '(';
            for (int j = 0; j < meth.parameters().count(); j++) {
                if (j > 0) out << ", ";
                out << meth.parameters()[j].toString();
            }
            out << ')';
            if (meth.isConst())
                out << " const";
            if (meth.flags() & Method::PureVirtual)
                out << " [pure virtual]";
            out << "\n";
            methodIdx[&meth] = i;
            xcall_index++;
            i++;
            methodCount++;
        }
        // enums
        foreach (BasicTypeDeclaration* decl, klass->children()) {
            const Enum* e = 0;

generator/generatorvisitor.cpp  view on Meta::CPAN

{
    QString _name = name;
    return resolveType(_name);
}

// TODO: this might have to be improved for cases like 'Typedef::Nested foo'
BasicTypeDeclaration* GeneratorVisitor::resolveType(QString & name)
{
    if (ParserOptions::qtMode && name.endsWith("::enum_type")) {
        // strip off "::enum_type"
        QString flags = name.left(name.length() - 11);
        QHash<QString, Typedef>::iterator it = typedefs.find(flags);
        if (it != typedefs.end()) {
            QString enumType = it.value().resolve().toString().replace(QRegExp("QFlags<(.*)>"), "\\1");
            QHash<QString, Enum>::iterator it = enums.find(enumType);
            if (it != enums.end()) {
                return &it.value();
            }
        }
    }

    // check for 'using type;'

generator/parser/tests/test_generator.cpp  view on Meta::CPAN

  }

  enum ParseFlag {
    FlagNone = 0,
    DumpAST = 1,
    PrintCode = 2,
    FlagAll = 3
  };
  Q_DECLARE_FLAGS(ParseFlags, ParseFlag)

  void parse(const QByteArray& unit, ParseFlags flags = static_cast<ParseFlags>(FlagNone))
  {
    TranslationUnitAST* ast = parseOriginal(unit);
    if (flags & DumpAST)
      dumper.dump(ast, lastSession->token_stream);

    CodeGenerator cg(lastSession);
    cg.visit(ast);
    if (flags & PrintCode) {
      qDebug() << unit;
      qDebug() << cg.output();
    }

    parseGenerated( cg.output().toUtf8() );

    compareTokenStreams();
  }

private slots:

generator/smoke.h  view on Meta::CPAN

    };
    /**
     * Describe one class.
     */
    struct Class {
	const char *className;	// Name of the class
	bool external;		// Whether the class is in another module
	Index parents;		// Index into inheritanceList
	ClassFn classFn;	// Calls any method in the class
	EnumFn enumFn;		// Handles enum pointers
        unsigned short flags;   // ClassFlags
        unsigned int size;
    };

    enum MethodFlags {
        mf_static = 0x01,
        mf_const = 0x02,
        mf_copyctor = 0x04,  // Copy constructor
        mf_internal = 0x08,   // For internal use only
        mf_enum = 0x10,   // An enum value
        mf_ctor = 0x20,

generator/smoke.h  view on Meta::CPAN

        mf_explicit = 0x4000    // method is an 'explicit' constructor
    };
    /**
     * Describe one method of one class.
     */
    struct Method {
	Index classId;		// Index into classes
	Index name;		// Index into methodNames; real name
	Index args;		// Index into argumentList
	unsigned char numArgs;	// Number of arguments
	unsigned short flags;	// MethodFlags (const/static/etc...)
	Index ret;		// Index into types for the return type
	Index method;		// Passed to Class.classFn, to call method
    };

    /**
     * One MethodMap entry maps the munged method prototype
     * to the Method entry.
     *
     * The munging works this way:
     * $ is a plain scalar

generator/smoke.h  view on Meta::CPAN

	Index classId;		// Index into classes
	Index name;		// Index into methodNames; munged name
	Index method;		// Index into methods
    };

    enum TypeFlags {
        // The first 4 bits indicate the TypeId value, i.e. which field
        // of the StackItem union is used.
        tf_elem = 0x0F,

	// Always only one of the next three flags should be set
	tf_stack = 0x10, 	// Stored on the stack, 'type'
	tf_ptr = 0x20,   	// Pointer, 'type*'
	tf_ref = 0x30,   	// Reference, 'type&'
	// Can | whatever ones of these apply
	tf_const = 0x40		// const argument
    };
    /**
     * One Type entry is one argument type needed by a method.
     * Type entries are shared, there is only one entry for "int" etc.
     */
    struct Type {
	const char *name;	// Stringified type name
	Index classId;		// Index into classes. -1 for none
        unsigned short flags;   // TypeFlags
    };

    // We could just pass everything around using void* (pass-by-reference)
    // I don't want to, though. -aw
    union StackItem {
	void* s_voidp;
	bool s_bool;
	signed char s_char;
	unsigned char s_uchar;
	short s_short;

generator/smokeapi/main.cpp  view on Meta::CPAN

    return *smoke;
}

static QString
methodToString(Smoke::ModuleIndex methodId)
{
    QString result;
    Smoke * smoke = methodId.smoke;
    Smoke::Method& methodRef = smoke->methods[methodId.index];
    
    if ((methodRef.flags & Smoke::mf_signal) != 0) {
        result.append("signal ");
    }
    
    if ((methodRef.flags & Smoke::mf_slot) != 0) {
        result.append("slot ");
    }
    
    const char * typeName = smoke->types[methodRef.ret].name;
    
    if ((methodRef.flags & Smoke::mf_enum) != 0) {
        result.append(QString("enum %1::%2")
                            .arg(smoke->classes[methodRef.classId].className)
                            .arg(smoke->methodNames[methodRef.name]) );
        return result;
    }
    
    if ((methodRef.flags & Smoke::mf_virtual) != 0) {
        result.append("virtual ");
    }
    
    if (	(methodRef.flags & Smoke::mf_static) != 0
            && (smoke->classes[methodRef.classId].flags & Smoke::cf_namespace) == 0 )
    {
        result.append("static ");
    }
    
    if ((methodRef.flags & Smoke::mf_ctor) == 0) {
        result.append((typeName != 0 ? typeName : "void"));
        result.append(" ");
    }
    
    result.append(  QString("%1::%2(")
                        .arg(smoke->classes[methodRef.classId].className)
                        .arg(smoke->methodNames[methodRef.name]) );
                        
    for (int i = 0; i < methodRef.numArgs; i++) {
        if (i > 0) {
            result.append(", ");
        }
        
        typeName = smoke->types[smoke->argumentList[methodRef.args+i]].name;
        result.append((typeName != 0 ? typeName : "void"));
    }
    
    result.append(")");
    
    if ((methodRef.flags & Smoke::mf_const) != 0) {
        result.append(" const");
    }
    
    if ((methodRef.flags & Smoke::mf_purevirtual) != 0) {
        result.append(" = 0");
    }
    
    return result;
}

static QList<ClassEntry>
getAllParents(const Smoke::ModuleIndex& classId, int indent)
{
    Smoke* smoke = classId.smoke;

generator/type.cpp  view on Meta::CPAN

{
    QString ret;
    if (withAccess) {
        if (m_access == Access_public)
            ret += "public ";
        else if (m_access == Access_protected)
            ret += "protected ";
        else if (m_access == Access_private)
            ret += "private ";
    }
    if (m_flags & Static)
        ret += "static ";
    if (m_flags & Virtual)
        ret += "virtual ";
    ret += m_type->toString() + " ";
    if (withClass)
        ret += m_typeDecl->toString() + "::";
    ret += m_name;
    return ret;
}

QString EnumMember::toString() const
{

generator/type.cpp  view on Meta::CPAN

QString Method::toString(bool withAccess, bool withClass, bool withInitializer) const
{
    QString ret = Member::toString(withAccess, withClass);
    ret += "(";
    for (int i = 0; i < m_params.count(); i++) {
        ret += m_params[i].toString();
        if (i < m_params.count() - 1) ret += ", ";
    }
    ret += ")";
    if (m_isConst) ret += " const";
    if ((m_flags & Member::PureVirtual) && withInitializer) ret += " = 0";
    return ret;
}

const Type* Type::Void = Type::registerType(Type("void"));

#ifdef Q_OS_WIN
Type* Type::registerType(const Type& type)
{
    QString typeString = type.toString();
    QHash<QString, Type>::iterator iter = types.insert(typeString, type);

generator/type.h  view on Meta::CPAN


    void setName(const QString& name) { m_name = name; }
    QString name() const { return m_name; }

    void setType(Type* type) { m_type = type; }
    Type* type() const { return m_type; }

    void setAccess(Access access) { m_access = access; }
    Access access() const { return m_access; }

    void setFlag(Flag flag) { m_flags |= flag; }
    void removeFlag(Flag flag) { m_flags &= ~flag; }
    Flags flags() const { return m_flags; }

    virtual QString toString(bool withAccess = false, bool withClass = false) const;

protected:
    BasicTypeDeclaration* m_typeDecl;
    QString m_name;
    Type* m_type;
    Access m_access;
    Flags m_flags;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Member::Flags)

class GENERATOR_EXPORT EnumMember : public Member
{
public:
    EnumMember(Enum* e = 0, const QString& name = QString(), const QString& value = QString(), Type* type = 0)
        : Member(e, name, type), m_value(value) {}



( run in 0.355 second using v1.01-cache-2.11-cpan-94b05bcf43c )