/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Script Generator project on Qt Labs. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "shellgenerator.h" #include "reporthandler.h" #include "metaqtscript.h" bool ShellGenerator::shouldGenerate(const AbstractMetaClass *meta_class) const { uint cg = meta_class->typeEntry()->codeGeneration(); return ((cg & TypeEntry::GenerateCode) != 0) && meta_class->generateShellClass(); } void ShellGenerator::writeTypeInfo(QTextStream &s, const AbstractMetaType *type, Option options) { if ((options & OriginalTypeDescription) && !type->originalTypeDescription().isEmpty()) { s << type->originalTypeDescription(); return; } if (type->isArray()) { writeTypeInfo(s, type->arrayElementType(), options); if (options & ArrayAsPointer) { s << "*"; } else { s << "[" << type->arrayElementCount() << "]"; } return; } const TypeEntry *te = type->typeEntry(); if (type->isConstant() && !(options & ExcludeConst)) s << "const "; if ((options & EnumAsInts) && (te->isEnum() || te->isFlags())) { s << "int"; } else if (te->isFlags()) { s << ((FlagsTypeEntry *) te)->originalName(); } else { s << fixCppTypeName(te->qualifiedCppName()); } if (type->instantiations().size() > 0 && (!type->isContainer() || (static_cast(te))->type() != ContainerTypeEntry::StringListContainer)) { s << '<'; QList args = type->instantiations(); bool nested_template = false; for (int i=0; iisContainer(); writeTypeInfo(s, args.at(i)); } if (nested_template) s << ' '; s << '>'; } s << QString(type->indirections(), '*'); if (type->isReference() && !(options & ExcludeReference)) s << "&"; if (!(options & SkipName)) s << ' '; } void ShellGenerator::writeFunctionArguments(QTextStream &s, const AbstractMetaArgumentList &arguments, Option option, int numArguments) { if (numArguments < 0) numArguments = arguments.size(); for (int i=0; itype(), option); if (!(option & SkipName)) s << " " << arg->argumentName(); if ((option & IncludeDefaultExpression) && !arg->originalDefaultValueExpression().isEmpty()) { s << " = "; QString expr = arg->originalDefaultValueExpression(); if (arg->type()->typeEntry()->isEnum() && expr.indexOf("::") < 0) s << ((EnumTypeEntry *)arg->type()->typeEntry())->qualifier() << "::"; s << expr; } } } /*! * Writes the function \a meta_function signature to the textstream \a s. * * The \a name_prefix can be used to give the function name a prefix, * like "__public_" or "__override_" and \a classname_prefix can * be used to give the class name a prefix. * * The \a option flags can be used to tweak various parameters, such as * showing static, original vs renamed name, underscores for space etc. * * The \a extra_arguments list is a list of extra arguments on the * form "bool static_call". */ void ShellGenerator::writeFunctionSignature(QTextStream &s, const AbstractMetaFunction *meta_function, const AbstractMetaClass *implementor, const QString &name_prefix, Option option, const QString &classname_prefix, const QStringList &extra_arguments, int numArguments) { // ### remove the implementor AbstractMetaType *function_type = meta_function->type(); if (meta_function->isStatic() && (option & ShowStatic)) s << "static "; if ((option & SkipReturnType) == 0) { if (function_type) { writeTypeInfo(s, function_type, option); s << " "; } else if (!meta_function->isConstructor()) { s << "void "; } } if (implementor) { if (classname_prefix.isEmpty()) s << shellClassName(implementor) << "::"; else s << classname_prefix << implementor->name() << "::"; } QString function_name; if (option & OriginalName) function_name = meta_function->originalName(); else function_name = meta_function->name(); if (option & UnderscoreSpaces) function_name = function_name.replace(' ', '_'); if (meta_function->isConstructor()) function_name = shellClassName(meta_function->ownerClass()); s << name_prefix << function_name; if (meta_function->attributes() & AbstractMetaAttributes::SetterFunction) s << "_setter"; else if (meta_function->attributes() & AbstractMetaAttributes::GetterFunction) s << "_getter"; s << "("; writeFunctionArguments(s, meta_function->arguments(), option, numArguments); // The extra arguments... for (int i=0; i 0 || meta_function->arguments().size() != 0) s << ", "; s << extra_arguments.at(i); } s << ")"; if (meta_function->isConstant()) s << " const"; if (!meta_function->exception().isEmpty()) s << " " << meta_function->exception(); }