diff options
author | con <[email protected]> | 2008-12-02 12:01:29 +0100 |
---|---|---|
committer | con <[email protected]> | 2008-12-02 12:01:29 +0100 |
commit | 05c35356abc31549c5db6eba31fb608c0365c2a0 (patch) | |
tree | be044530104267afaff13f8943889cb97f8c8bad /tests/manual |
Initial import
Diffstat (limited to 'tests/manual')
73 files changed, 10657 insertions, 0 deletions
diff --git a/tests/manual/cppmodelmanager/codemodel/binder.cpp b/tests/manual/cppmodelmanager/codemodel/binder.cpp new file mode 100644 index 00000000000..6f71a7b3c49 --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/binder.cpp @@ -0,0 +1,866 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +/* This file is part of KDevelop +Copyright (C) 2002-2005 Roberto Raggi <[email protected]> +Copyright (C) 2005 Trolltech AS + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License version 2 as published by the Free Software Foundation. + +This library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#include "binder.h" +#include "lexer.h" +#include "control.h" +#include "symbol.h" +#include "codemodel_finder.h" +#include "class_compiler.h" +#include "compiler_utils.h" +#include "tokens.h" +#include "dumptree.h" + +#include <iostream> + +#include <qdebug.h> + +Binder::Binder(CppCodeModel *__model, LocationManager &__location, Control *__control) +: _M_model(__model), +_M_location(__location), +_M_token_stream(&_M_location.token_stream), +_M_control(__control), +_M_current_function_type(CodeModel::Normal), +type_cc(this), +name_cc(this), +decl_cc(this) +{ + _M_current_file = 0; + _M_current_namespace = 0; + _M_current_class = 0; + _M_current_function = 0; + _M_current_enum = 0; +} + +Binder::~Binder() +{ +} + +void Binder::run(AST *node, const QString &filename) +{ + _M_current_access = CodeModel::Public; + if (_M_current_file = model()->fileItem(filename)) + visit(node); +} + +ScopeModelItem *Binder::findScope(const QString &name) const +{ + return _M_known_scopes.value(name, 0); +} + +ScopeModelItem *Binder::resolveScope(NameAST *id, ScopeModelItem *scope) +{ + Q_ASSERT(scope != 0); + + bool foundScope; + CodeModelFinder finder(model(), this); + QString symbolScopeName = finder.resolveScope(id, scope, &foundScope); + if (!foundScope) { + name_cc.run(id); + std::cerr << "** WARNING scope not found for symbol:" + << qPrintable(name_cc.qualifiedName()) << std::endl; + return 0; + } + + if (symbolScopeName.isEmpty()) + return scope; + + ScopeModelItem *symbolScope = findScope(symbolScopeName); + + qDebug() << "Resolving: " << symbolScopeName; + qDebug() << " Current File: " << scope->file()->name(); + + if (symbolScope) + qDebug() << " Found in file: " << symbolScope->file()->name(); + + if (!symbolScope || symbolScope->file() != scope->file()) { + CppFileModelItem *file = model_cast<CppFileModelItem *>(scope->file()); + symbolScope = file->findExternalScope(symbolScopeName); + qDebug() << " Create as external reference"; + if (!symbolScope) { + symbolScope = new ScopeModelItem(_M_model); + symbolScope->setName(symbolScopeName); + file->addExternalScope(symbolScope); + } + } + + return symbolScope; +} + +ScopeModelItem *Binder::currentScope() +{ + if (_M_current_class) + return _M_current_class; + else if (_M_current_namespace) + return _M_current_namespace; + + return _M_current_file; +} + +TemplateParameterList Binder::changeTemplateParameters(TemplateParameterList templateParameters) +{ + TemplateParameterList old = _M_current_template_parameters; + _M_current_template_parameters = templateParameters; + return old; +} + +CodeModel::FunctionType Binder::changeCurrentFunctionType(CodeModel::FunctionType functionType) +{ + CodeModel::FunctionType old = _M_current_function_type; + _M_current_function_type = functionType; + return old; +} + +CodeModel::AccessPolicy Binder::changeCurrentAccess(CodeModel::AccessPolicy accessPolicy) +{ + CodeModel::AccessPolicy old = _M_current_access; + _M_current_access = accessPolicy; + return old; +} + +NamespaceModelItem *Binder::changeCurrentNamespace(NamespaceModelItem *item) +{ + NamespaceModelItem *old = _M_current_namespace; + _M_current_namespace = item; + return old; +} + +CppClassModelItem *Binder::changeCurrentClass(CppClassModelItem *item) +{ + CppClassModelItem *old = _M_current_class; + _M_current_class = item; + return old; +} + +CppFunctionDefinitionModelItem *Binder::changeCurrentFunction(CppFunctionDefinitionModelItem *item) +{ + CppFunctionDefinitionModelItem *old = _M_current_function; + _M_current_function = item; + return old; +} + +int Binder::decode_token(std::size_t index) const +{ + return _M_token_stream->kind(index); +} + +CodeModel::AccessPolicy Binder::decode_access_policy(std::size_t index) const +{ + switch (decode_token(index)) + { + case Token_class: + return CodeModel::Private; + + case Token_struct: + case Token_union: + return CodeModel::Public; + + default: + return CodeModel::Public; + } +} + +CodeModel::ClassType Binder::decode_class_type(std::size_t index) const +{ + switch (decode_token(index)) + { + case Token_class: + return CodeModel::Class; + case Token_struct: + return CodeModel::Struct; + case Token_union: + return CodeModel::Union; + default: + std::cerr << "** WARNING unrecognized class type" << std::endl; + } + return CodeModel::Class; +} + +const NameSymbol *Binder::decode_symbol(std::size_t index) const +{ + return _M_token_stream->symbol(index); +} + +void Binder::visitAccessSpecifier(AccessSpecifierAST *node) +{ + const ListNode<std::size_t> *it = node->specs; + if (it == 0) + return; + + it = it->toFront(); + const ListNode<std::size_t> *end = it; + + do + { + switch (decode_token(it->element)) + { + default: + break; + + case Token_public: + changeCurrentAccess(CodeModel::Public); + changeCurrentFunctionType(CodeModel::Normal); + break; + case Token_protected: + changeCurrentAccess(CodeModel::Protected); + changeCurrentFunctionType(CodeModel::Normal); + break; + case Token_private: + changeCurrentAccess(CodeModel::Private); + changeCurrentFunctionType(CodeModel::Normal); + break; + case Token_signals: + changeCurrentAccess(CodeModel::Protected); + changeCurrentFunctionType(CodeModel::Signal); + break; + case Token_slots: + changeCurrentFunctionType(CodeModel::Slot); + break; + } + it = it->next; + } + while (it != end); +} + +void Binder::visitSimpleDeclaration(SimpleDeclarationAST *node) +{ + visit(node->type_specifier); + + if (const ListNode<InitDeclaratorAST*> *it = node->init_declarators) + { + it = it->toFront(); + const ListNode<InitDeclaratorAST*> *end = it; + do + { + InitDeclaratorAST *init_declarator = it->element; + declare_symbol(node, init_declarator); + it = it->next; + } + while (it != end); + } +} + +void Binder::declare_symbol(SimpleDeclarationAST *node, InitDeclaratorAST *init_declarator) +{ + DeclaratorAST *declarator = init_declarator->declarator; + + while (declarator && declarator->sub_declarator) + declarator = declarator->sub_declarator; + + NameAST *id = declarator->id; + if (! declarator->id) + { + std::cerr << "** WARNING expected a declarator id" << std::endl; + return; + } + + decl_cc.run(declarator); + + if (decl_cc.isFunction()) + { + name_cc.run(id->unqualified_name); + + FunctionModelItem *fun = new FunctionModelItem(model()); + updateFileAndItemPosition (fun, node); + + ScopeModelItem *symbolScope = resolveScope(id, currentScope()); + if (!symbolScope) { + delete fun; + return; + } + + fun->setAccessPolicy(_M_current_access); + fun->setFunctionType(_M_current_function_type); + fun->setName(name_cc.qualifiedName()); + fun->setAbstract(init_declarator->initializer != 0); + fun->setConstant(declarator->fun_cv != 0); + fun->setTemplateParameters(copyTemplateParameters(_M_current_template_parameters)); + applyStorageSpecifiers(node->storage_specifiers, fun); + applyFunctionSpecifiers(node->function_specifiers, fun); + + // build the type + TypeInfo *typeInfo = CompilerUtils::typeDescription(node->type_specifier, + declarator, + this); + + fun->setType(typeInfo); + + + fun->setVariadics (decl_cc.isVariadics ()); + + // ... and the signature + foreach (DeclaratorCompiler::Parameter p, decl_cc.parameters()) + { + CppArgumentModelItem *arg = new CppArgumentModelItem(model()); + arg->setType(p.type); + arg->setName(p.name); + arg->setDefaultValue(p.defaultValue); + if (p.defaultValue) + arg->setDefaultValueExpression(p.defaultValueExpression); + fun->addArgument(arg); + } + + fun->setScope(symbolScope->qualifiedName()); + symbolScope->addFunction(fun); + } + else + { + CppVariableModelItem *var = new CppVariableModelItem(model()); + updateFileAndItemPosition (var, node); + + ScopeModelItem *symbolScope = resolveScope(id, currentScope()); + if (!symbolScope) { + delete var; + return; + } + + var->setTemplateParameters(copyTemplateParameters(_M_current_template_parameters)); + var->setAccessPolicy(_M_current_access); + name_cc.run(id->unqualified_name); + var->setName(name_cc.qualifiedName()); + TypeInfo *typeInfo = CompilerUtils::typeDescription(node->type_specifier, + declarator, + this); + if (declarator != init_declarator->declarator + && init_declarator->declarator->parameter_declaration_clause != 0) + { + typeInfo->setFunctionPointer (true); + decl_cc.run (init_declarator->declarator); + foreach (DeclaratorCompiler::Parameter p, decl_cc.parameters()) + typeInfo->addArgument(p.type); + } + + var->setType(typeInfo); + applyStorageSpecifiers(node->storage_specifiers, var); + + var->setScope(symbolScope->qualifiedName()); + symbolScope->addVariable(var); + } +} + +void Binder::visitFunctionDefinition(FunctionDefinitionAST *node) +{ + Q_ASSERT(node->init_declarator != 0); + + InitDeclaratorAST *init_declarator = node->init_declarator; + DeclaratorAST *declarator = init_declarator->declarator; + + decl_cc.run(declarator); + + Q_ASSERT(! decl_cc.id().isEmpty()); + + CppFunctionDefinitionModelItem * + old = changeCurrentFunction(new CppFunctionDefinitionModelItem(_M_model)); + updateFileAndItemPosition (_M_current_function, node); + + ScopeModelItem *functionScope = resolveScope(declarator->id, currentScope()); + if (! functionScope) { + delete _M_current_function; + changeCurrentFunction(old); + return; + } + + _M_current_function->setScope(functionScope->qualifiedName()); + + Q_ASSERT(declarator->id->unqualified_name != 0); + name_cc.run(declarator->id->unqualified_name); + QString unqualified_name = name_cc.qualifiedName(); + + _M_current_function->setName(unqualified_name); + TypeInfo *tmp_type = CompilerUtils::typeDescription(node->type_specifier, + declarator, this); + + _M_current_function->setType(tmp_type); + _M_current_function->setAccessPolicy(_M_current_access); + _M_current_function->setFunctionType(_M_current_function_type); + _M_current_function->setConstant(declarator->fun_cv != 0); + _M_current_function->setTemplateParameters(copyTemplateParameters(_M_current_template_parameters)); + + applyStorageSpecifiers(node->storage_specifiers, + _M_current_function); + applyFunctionSpecifiers(node->function_specifiers, + _M_current_function); + + _M_current_function->setVariadics (decl_cc.isVariadics ()); + + foreach (DeclaratorCompiler::Parameter p, decl_cc.parameters()) + { + CppArgumentModelItem *arg = new CppArgumentModelItem(model()); + arg->setType(p.type); + arg->setName(p.name); + arg->setDefaultValue(p.defaultValue); + _M_current_function->addArgument(arg); + } + + functionScope->addFunctionDefinition(_M_current_function); + changeCurrentFunction(old); +} + +void Binder::visitTemplateDeclaration(TemplateDeclarationAST *node) +{ + const ListNode<TemplateParameterAST*> *it = node->template_parameters; + if (it == 0) + return; + + TemplateParameterList savedTemplateParameters = changeTemplateParameters(TemplateParameterList()); + + it = it->toFront(); + const ListNode<TemplateParameterAST*> *end = it; + + do + { + TemplateParameterAST *parameter = it->element; + TypeParameterAST *type_parameter = parameter->type_parameter; + if (! type_parameter) + { + std::cerr << "** WARNING template declaration not supported ``"; + Token const &tk = _M_token_stream->token ((int) node->start_token); + Token const &end_tk = _M_token_stream->token ((int) node->declaration->start_token); + + std::cerr << std::string (&tk.text[tk.position], (end_tk.position) - tk.position) << "''" + << std::endl << std::endl; + + qDeleteAll(_M_current_template_parameters); + changeTemplateParameters(savedTemplateParameters); + return; + } + assert(type_parameter != 0); + + int tk = decode_token(type_parameter->type); + if (tk != Token_typename && tk != Token_class) + { + std::cerr << "** WARNING template declaration not supported ``"; + Token const &tk = _M_token_stream->token ((int) node->start_token); + Token const &end_tk = _M_token_stream->token ((int) node->declaration->start_token); + + std::cerr << std::string (&tk.text[tk.position], (end_tk.position) - tk.position) << "''" + << std::endl << std::endl; + + qDeleteAll(_M_current_template_parameters); + changeTemplateParameters(savedTemplateParameters); + return; + } + assert(tk == Token_typename || tk == Token_class); + + name_cc.run(type_parameter->name); + + CppTemplateParameterModelItem *p = new CppTemplateParameterModelItem(model()); + p->setName(name_cc.qualifiedName()); + _M_current_template_parameters.append(p); + it = it->next; + } + while (it != end); + + visit(node->declaration); + + qDeleteAll(_M_current_template_parameters); + changeTemplateParameters(savedTemplateParameters); +} + +void Binder::visitTypedef(TypedefAST *node) +{ + const ListNode<InitDeclaratorAST*> *it = node->init_declarators; + if (it == 0) + return; + + it = it->toFront(); + const ListNode<InitDeclaratorAST*> *end = it; + + do + { + InitDeclaratorAST *init_declarator = it->element; + it = it->next; + + Q_ASSERT(init_declarator->declarator != 0); + + // the name + decl_cc.run (init_declarator->declarator); + QString alias_name = decl_cc.id (); + + if (alias_name.isEmpty ()) + { + std::cerr << "** WARNING anonymous typedef not supported! ``"; + Token const &tk = _M_token_stream->token ((int) node->start_token); + Token const &end_tk = _M_token_stream->token ((int) node->end_token); + + std::cerr << std::string (&tk.text[tk.position], end_tk.position - tk.position) << "''" + << std::endl << std::endl; + continue; + } + + // build the type + TypeInfo *typeInfo = CompilerUtils::typeDescription (node->type_specifier, + init_declarator->declarator, + this); + DeclaratorAST *decl = init_declarator->declarator; + while (decl && decl->sub_declarator) + decl = decl->sub_declarator; + + if (decl != init_declarator->declarator + && init_declarator->declarator->parameter_declaration_clause != 0) + { + typeInfo->setFunctionPointer (true); + decl_cc.run (init_declarator->declarator); + foreach (DeclaratorCompiler::Parameter p, decl_cc.parameters()) + typeInfo->addArgument(p.type); + } + + DeclaratorAST *declarator = init_declarator->declarator; + + CppTypeAliasModelItem *typeAlias = new CppTypeAliasModelItem(model()); + updateFileAndItemPosition (typeAlias, node); + + ScopeModelItem *typedefScope = resolveScope(declarator->id, currentScope()); + if (!typedefScope) { + delete typeAlias; + return; + } + + typeAlias->setName (alias_name); + typeAlias->setType (typeInfo); + typeAlias->setScope (typedefScope->qualifiedName()); + typedefScope->addTypeAlias (typeAlias); + } + while (it != end); +} + +void Binder::visitNamespace(NamespaceAST *node) +{ + bool anonymous = (node->namespace_name == 0); + + ScopeModelItem *scope = 0; + NamespaceModelItem *old = 0; + if (! anonymous) + { + // update the file if needed + updateFileAndItemPosition (0, node); + scope = currentScope(); + + QString name = decode_symbol(node->namespace_name)->as_string(); + + QString qualified_name = scope->qualifiedName(); + if (!qualified_name.isEmpty()) + qualified_name += QLatin1String("::"); + qualified_name += name; + NamespaceModelItem *ns = model_cast<NamespaceModelItem *>(findScope(qualified_name)); + if (ns && ns->file() != scope->file()) { + qDebug() << ns->file()->name() << " :: " << scope->file()->name(); + ns = 0; // we need a separate namespaces for different files + } + + if (!ns) + { + ns = new NamespaceModelItem(_M_model); + updateFileAndItemPosition (ns, node); + + _M_known_scopes.insert(qualified_name, ns); + ns->setName(name); + ns->setScope(scope->qualifiedName()); + } + old = changeCurrentNamespace(ns); + } + + DefaultVisitor::visitNamespace(node); + + if (! anonymous) + { + Q_ASSERT(scope->kind() == CodeModelItem::Kind_Namespace + || scope->kind() == CodeModelItem::Kind_File); + + if (NamespaceModelItem *ns = model_cast<NamespaceModelItem *>(scope)) + ns->addNamespace(_M_current_namespace); + + changeCurrentNamespace(old); + } +} + +void Binder::visitClassSpecifier(ClassSpecifierAST *node) +{ + ClassCompiler class_cc(this); + class_cc.run(node); + + if (class_cc.name().isEmpty()) + { + // anonymous not supported + return; + } + + Q_ASSERT(node->name != 0 && node->name->unqualified_name != 0); + + + CppClassModelItem *class_item = new CppClassModelItem(_M_model); + updateFileAndItemPosition (class_item, node); + ScopeModelItem *scope = currentScope(); + CppClassModelItem *old = changeCurrentClass(class_item); + + _M_current_class->setName(class_cc.name()); + _M_current_class->setBaseClasses(class_cc.baseClasses()); + _M_current_class->setClassType(decode_class_type(node->class_key)); + _M_current_class->setTemplateParameters(copyTemplateParameters(_M_current_template_parameters)); + + QString name = _M_current_class->name(); + if (!_M_current_template_parameters.isEmpty()) + { + name += "<"; + for (int i = 0; i<_M_current_template_parameters.size(); ++i) + { + if (i != 0) + name += ","; + + name += _M_current_template_parameters.at(i)->name(); + } + + name += ">"; + _M_current_class->setName(name); + } + + CodeModel::AccessPolicy oldAccessPolicy = changeCurrentAccess(decode_access_policy(node->class_key)); + CodeModel::FunctionType oldFunctionType = changeCurrentFunctionType(CodeModel::Normal); + + QString qualifiedname = scope->qualifiedName(); + _M_current_class->setScope(qualifiedname); + if (!qualifiedname.isEmpty()) + qualifiedname += QLatin1String("::"); + qualifiedname += name; + _M_known_scopes.insert(qualifiedname, _M_current_class); + + scope->addClass(_M_current_class); + + name_cc.run(node->name->unqualified_name); + + visitNodes(this, node->member_specs); + + changeCurrentClass(old); + changeCurrentAccess(oldAccessPolicy); + changeCurrentFunctionType(oldFunctionType); +} + +void Binder::visitLinkageSpecification(LinkageSpecificationAST *node) +{ + DefaultVisitor::visitLinkageSpecification(node); +} + +void Binder::visitUsing(UsingAST *node) +{ + DefaultVisitor::visitUsing(node); +} + +void Binder::visitEnumSpecifier(EnumSpecifierAST *node) +{ + CodeModelFinder finder(model(), this); + + name_cc.run(node->name); + QString name = name_cc.qualifiedName(); + + if (name.isEmpty()) + { + // anonymous enum + static int N = 0; + name = QLatin1String("$$enum_"); + name += QString::number(++N); + } + + _M_current_enum = new CppEnumModelItem(model()); + + updateFileAndItemPosition (_M_current_enum, node); + ScopeModelItem *enumScope = resolveScope(node->name, currentScope()); + if (!enumScope) { + delete _M_current_enum; + _M_current_enum = 0; + return; + } + + + _M_current_enum->setAccessPolicy(_M_current_access); + _M_current_enum->setName(name); + _M_current_enum->setScope(enumScope->qualifiedName()); + + enumScope->addEnum(_M_current_enum); + + DefaultVisitor::visitEnumSpecifier(node); + + _M_current_enum = 0; +} + +void Binder::visitEnumerator(EnumeratorAST *node) +{ + Q_ASSERT(_M_current_enum != 0); + CppEnumeratorModelItem *e = new CppEnumeratorModelItem(model()); + updateFileAndItemPosition (e, node); + e->setName(decode_symbol(node->id)->as_string()); + + if (ExpressionAST *expr = node->expression) + { + const Token &start_token = _M_token_stream->token((int) expr->start_token); + const Token &end_token = _M_token_stream->token((int) expr->end_token); + + e->setValue(QString::fromUtf8(&start_token.text[start_token.position], + (int) (end_token.position - start_token.position)).trimmed()); + } + + _M_current_enum->addEnumerator(e); +} + +void Binder::visitUsingDirective(UsingDirectiveAST *node) +{ + DefaultVisitor::visitUsingDirective(node); +} + +void Binder::applyStorageSpecifiers(const ListNode<std::size_t> *it, MemberModelItem *item) +{ + if (it == 0) + return; + + it = it->toFront(); + const ListNode<std::size_t> *end = it; + + do + { + switch (decode_token(it->element)) + { + default: + break; + + case Token_friend: + item->setFriend(true); + break; + case Token_auto: + item->setAuto(true); + break; + case Token_register: + item->setRegister(true); + break; + case Token_static: + item->setStatic(true); + break; + case Token_extern: + item->setExtern(true); + break; + case Token_mutable: + item->setMutable(true); + break; + } + it = it->next; + } + while (it != end); +} + +void Binder::applyFunctionSpecifiers(const ListNode<std::size_t> *it, FunctionModelItem *item) +{ + if (it == 0) + return; + + it = it->toFront(); + const ListNode<std::size_t> *end = it; + + do + { + switch (decode_token(it->element)) + { + default: + break; + + case Token_inline: + item->setInline(true); + break; + + case Token_virtual: + item->setVirtual(true); + break; + + case Token_explicit: + item->setExplicit(true); + break; + } + it = it->next; + } + while (it != end); +} + +void Binder::updateFileAndItemPosition(CodeModelItem *item, AST *node) +{ + QString filename; + int sline, scolumn; + int eline, ecolumn; + + assert (node != 0); + _M_location.positionAt (_M_token_stream->position(node->start_token), &sline, &scolumn, &filename); + _M_location.positionAt (_M_token_stream->position(node->end_token), &eline, &ecolumn, &QString()); + + if (!filename.isEmpty() && (!_M_current_file || _M_current_file->name() != filename)) + _M_current_file = model()->fileItem(filename); + + if (item) { + item->setFile(_M_current_file); + item->setStartPosition(sline, scolumn); + item->setEndPosition(eline, ecolumn); + } +} + +TemplateParameterList Binder::copyTemplateParameters(const TemplateParameterList &in) const +{ + TemplateParameterList result; + foreach(TemplateParameterModelItem *item, in) { + CppTemplateParameterModelItem *newitem = + new CppTemplateParameterModelItem(*(model_cast<CppTemplateParameterModelItem *>(item))); + if (item->type()) { + TypeInfo *type = new TypeInfo(); + *type = *(item->type()); + newitem->setType(type); + } + result.append(newitem); + } + return result; +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/binder.h b/tests/manual/cppmodelmanager/codemodel/binder.h new file mode 100644 index 00000000000..252c15b744e --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/binder.h @@ -0,0 +1,141 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop + Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + Copyright (C) 2005 Trolltech AS + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef BINDER_H +#define BINDER_H + +#include "default_visitor.h" +#include "cppcodemodel.h" +#include "type_compiler.h" +#include "name_compiler.h" +#include "declarator_compiler.h" + +class TokenStream; +class LocationManager; +class Control; +struct NameSymbol; + +class Binder: protected DefaultVisitor +{ +public: + Binder(CppCodeModel *__model, LocationManager &__location, Control *__control = 0); + virtual ~Binder(); + + inline TokenStream *tokenStream() const { return _M_token_stream; } + inline CppCodeModel *model() const { return _M_model; } + ScopeModelItem *currentScope(); + + void run(AST *node, const QString &filename); + +protected: + virtual void visitAccessSpecifier(AccessSpecifierAST *); + virtual void visitClassSpecifier(ClassSpecifierAST *); + virtual void visitEnumSpecifier(EnumSpecifierAST *); + virtual void visitEnumerator(EnumeratorAST *); + virtual void visitFunctionDefinition(FunctionDefinitionAST *); + virtual void visitLinkageSpecification(LinkageSpecificationAST *); + virtual void visitNamespace(NamespaceAST *); + virtual void visitSimpleDeclaration(SimpleDeclarationAST *); + virtual void visitTemplateDeclaration(TemplateDeclarationAST *); + virtual void visitTypedef(TypedefAST *); + virtual void visitUsing(UsingAST *); + virtual void visitUsingDirective(UsingDirectiveAST *); + +private: + ScopeModelItem *findScope(const QString &name) const; + ScopeModelItem *resolveScope(NameAST *id, ScopeModelItem *scope); + + int decode_token(std::size_t index) const; + const NameSymbol *decode_symbol(std::size_t index) const; + CodeModel::AccessPolicy decode_access_policy(std::size_t index) const; + CodeModel::ClassType decode_class_type(std::size_t index) const; + + CodeModel::FunctionType changeCurrentFunctionType(CodeModel::FunctionType functionType); + CodeModel::AccessPolicy changeCurrentAccess(CodeModel::AccessPolicy accessPolicy); + NamespaceModelItem *changeCurrentNamespace(NamespaceModelItem *item); + CppClassModelItem *changeCurrentClass(CppClassModelItem *item); + CppFunctionDefinitionModelItem *changeCurrentFunction(CppFunctionDefinitionModelItem *item); + TemplateParameterList changeTemplateParameters(TemplateParameterList templateParameters); + + void declare_symbol(SimpleDeclarationAST *node, InitDeclaratorAST *init_declarator); + + void applyStorageSpecifiers(const ListNode<std::size_t> *storage_specifiers, MemberModelItem *item); + void applyFunctionSpecifiers(const ListNode<std::size_t> *it, FunctionModelItem *item); + + void updateFileAndItemPosition(CodeModelItem *item, AST *node); + + TemplateParameterList copyTemplateParameters(const TemplateParameterList &in) const; + +private: + CppCodeModel *_M_model; + LocationManager &_M_location; + TokenStream *_M_token_stream; + Control *_M_control; + + CodeModel::FunctionType _M_current_function_type; + CodeModel::AccessPolicy _M_current_access; + CppFileModelItem *_M_current_file; + NamespaceModelItem *_M_current_namespace; + CppClassModelItem *_M_current_class; + CppFunctionDefinitionModelItem *_M_current_function; + CppEnumModelItem *_M_current_enum; + TemplateParameterList _M_current_template_parameters; + QHash<QString, ScopeModelItem *> _M_known_scopes; + +protected: + TypeCompiler type_cc; + NameCompiler name_cc; + DeclaratorCompiler decl_cc; +}; + +#endif // BINDER_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/class_compiler.cpp b/tests/manual/cppmodelmanager/codemodel/class_compiler.cpp new file mode 100644 index 00000000000..7a484f94472 --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/class_compiler.cpp @@ -0,0 +1,91 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop + Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "class_compiler.h" +#include "lexer.h" +#include "binder.h" + +ClassCompiler::ClassCompiler(Binder *binder) + : _M_binder (binder), + _M_token_stream(binder->tokenStream ()), + name_cc(_M_binder), + type_cc(_M_binder) +{ +} + +ClassCompiler::~ClassCompiler() +{ +} + +void ClassCompiler::run(ClassSpecifierAST *node) +{ + name_cc.run(node->name); + _M_name = name_cc.qualifiedName(); + _M_base_classes.clear(); + + visit(node); +} + +void ClassCompiler::visitClassSpecifier(ClassSpecifierAST *node) +{ + visit(node->base_clause); +} + +void ClassCompiler::visitBaseSpecifier(BaseSpecifierAST *node) +{ + name_cc.run(node->name); + QString name = name_cc.qualifiedName(); + + if (! name.isEmpty()) + _M_base_classes.append(name); +} + + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/class_compiler.h b/tests/manual/cppmodelmanager/codemodel/class_compiler.h new file mode 100644 index 00000000000..a6b3656c262 --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/class_compiler.h @@ -0,0 +1,90 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop + Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef CLASS_COMPILER_H +#define CLASS_COMPILER_H + +#include <QtCore/qglobal.h> +#include <QtCore/QStringList> + +#include "default_visitor.h" +#include "name_compiler.h" +#include "type_compiler.h" + +class TokenStream; +class Binder; + +class ClassCompiler: protected DefaultVisitor +{ +public: + ClassCompiler(Binder *binder); + virtual ~ClassCompiler(); + + inline QString name() const { return _M_name; } + inline QStringList baseClasses() const { return _M_base_classes; } + + void run(ClassSpecifierAST *node); + +protected: + virtual void visitClassSpecifier(ClassSpecifierAST *node); + virtual void visitBaseSpecifier(BaseSpecifierAST *node); + +private: + Binder *_M_binder; + TokenStream *_M_token_stream; + QString _M_name; + QStringList _M_base_classes; + NameCompiler name_cc; + TypeCompiler type_cc; +}; + +#endif // CLASS_COMPILER_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/codemodel_finder.cpp b/tests/manual/cppmodelmanager/codemodel/codemodel_finder.cpp new file mode 100644 index 00000000000..2aa5a41ea3c --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/codemodel_finder.cpp @@ -0,0 +1,99 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop +Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License version 2 as published by the Free Software Foundation. + +This library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#include "codemodel_finder.h" +#include "cppcodemodel.h" +#include "binder.h" + +CodeModelFinder::CodeModelFinder(CppCodeModel *model, Binder *binder) +: _M_model(model), +_M_binder (binder), +name_cc(_M_binder) +{ +} + +CodeModelFinder::~CodeModelFinder() +{ +} + +QString CodeModelFinder::resolveScope(NameAST *name, ScopeModelItem *scope, bool *ok) +{ + Q_ASSERT(scope != 0); + + _M_ok = true; + _M_current_scope = scope->qualifiedName(); + visit(name); + *ok = _M_ok; + + return _M_current_scope; +} + +void CodeModelFinder::visitName(NameAST *node) +{ + visitNodes(this, node->qualified_names); +} + +void CodeModelFinder::visitUnqualifiedName(UnqualifiedNameAST *node) +{ + if (!_M_ok) + return; + + if (!_M_current_scope.isEmpty()) + _M_current_scope += QLatin1String("::"); + + name_cc.run(node); + _M_current_scope += name_cc.qualifiedName(); + + if (!_M_model->hasScope(_M_current_scope)) + _M_ok = false; +} + +// kate: space-indent on; indent-width 2; replace-tabs on; + diff --git a/tests/manual/cppmodelmanager/codemodel/codemodel_finder.h b/tests/manual/cppmodelmanager/codemodel/codemodel_finder.h new file mode 100644 index 00000000000..3c6c52965d7 --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/codemodel_finder.h @@ -0,0 +1,86 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop +Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License version 2 as published by the Free Software Foundation. + +This library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#ifndef CODEMODEL_FINDER_H +#define CODEMODEL_FINDER_H + +#include "default_visitor.h" +#include "name_compiler.h" + +class Binder; +class CppCodeModel; +class ScopeModelItem; + +class CodeModelFinder: protected DefaultVisitor +{ +public: + CodeModelFinder(CppCodeModel *model, Binder *binder); + virtual ~CodeModelFinder(); + + QString resolveScope(NameAST *name, ScopeModelItem *scope, bool *ok); + + inline CppCodeModel *model() const { return _M_model; } + +protected: + virtual void visitName(NameAST *node); + virtual void visitUnqualifiedName(UnqualifiedNameAST *node); + +private: + CppCodeModel *_M_model; + Binder *_M_binder; + NameCompiler name_cc; + + bool _M_ok; + QString _M_current_scope; +}; + +#endif // CODEMODEL_FINDER_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/codemodelitems.cpp b/tests/manual/cppmodelmanager/codemodel/codemodelitems.cpp new file mode 100644 index 00000000000..8d168a13958 --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/codemodelitems.cpp @@ -0,0 +1,893 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +/* This file is part of KDevelop +Copyright (C) 2002-2005 Roberto Raggi <[email protected]> +Copyright (C) 2005 Trolltech AS + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License version 2 as published by the Free Software Foundation. + +This library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#include <QtCore/QHash> +#include "codemodelitems.h" + +CodeModel::~CodeModel() +{ + +} + +// --------------------------------------------------------------------------- +bool TypeInfo::operator==(const TypeInfo &other) +{ + if (arrayElements().count() != other.arguments().count()) + return false; + + return flags == other.flags + && m_qualifiedName == other.m_qualifiedName + && (!m_functionPointer || m_arguments == other.m_arguments); +} + +// --------------------------------------------------------------------------- +class CodeModelItemData { +public: + CodeModel *_M_model; + int _M_kind; + int _M_startLine; + int _M_startColumn; + int _M_endLine; + int _M_endColumn; + std::size_t _M_creation_id; + QString _M_name; + FileModelItem *_M_file; + QString _M_scope; +}; + +CodeModelItem::CodeModelItem(CodeModel *model, int kind) +{ + d = new CodeModelItemData; + d->_M_model = model; + d->_M_kind = kind; + d->_M_startLine = 0; + d->_M_startColumn = 0; + d->_M_endLine = 0; + d->_M_endColumn = 0; + d->_M_creation_id = 0; +} + +CodeModelItem::CodeModelItem(const CodeModelItem &item) +{ + d = new CodeModelItemData; + *d = *(item.d); +} + +CodeModelItem::~CodeModelItem() +{ + delete d; +} + +int CodeModelItem::kind() const +{ + return d->_M_kind; +} + +void CodeModelItem::setKind(int kind) +{ + d->_M_kind = kind; +} + +QString CodeModelItem::qualifiedName() const +{ + if (kind() == CodeModelItem::Kind_File) + return QString(); + + QString q = scope(); + + if (!q.isEmpty() && !name().isEmpty()) + q += QLatin1String("::"); + + q += name(); + + return q; +} + +QString CodeModelItem::name() const +{ + return d->_M_name; +} + +void CodeModelItem::setName(const QString &name) +{ + d->_M_name = name; +} + +QString CodeModelItem::scope() const +{ + return d->_M_scope; +} + +void CodeModelItem::setScope(const QString &scope) +{ + d->_M_scope = scope; +} + +void CodeModelItem::setFile(FileModelItem *file) +{ + d->_M_file = file; +} + +FileModelItem *CodeModelItem::file() const +{ + return d->_M_file; +} + +void CodeModelItem::startPosition(int *line, int *column) +{ + *line = d->_M_startLine; + *column = d->_M_startColumn; +} + +void CodeModelItem::setStartPosition(int line, int column) +{ + d->_M_startLine = line; + d->_M_startColumn = column; +} + +void CodeModelItem::endPosition(int *line, int *column) +{ + *line = d->_M_endLine; + *column = d->_M_endColumn; +} + +void CodeModelItem::setEndPosition(int line, int column) +{ + d->_M_endLine = line; + d->_M_endColumn = column; +} + +std::size_t CodeModelItem::creationId() const +{ + return d->_M_creation_id; +} + +void CodeModelItem::setCreationId(std::size_t creation_id) +{ + d->_M_creation_id = creation_id; +} + +CodeModel *CodeModelItem::model() const +{ + return d->_M_model; +} + +// --------------------------------------------------------------------------- +class ClassModelItemData +{ +public: + ~ClassModelItemData() { + qDeleteAll(_M_templateParameters); + } + QStringList _M_baseClasses; + TemplateParameterList _M_templateParameters; + CodeModel::ClassType _M_classType; +}; + +ClassModelItem::ClassModelItem(CodeModel *model, int kind) +: ScopeModelItem(model, kind) +{ + d = new ClassModelItemData(); + d->_M_classType = CodeModel::Class; +} + +ClassModelItem::~ClassModelItem() +{ + delete d; +} + +QStringList ClassModelItem::baseClasses() const +{ + return d->_M_baseClasses; +} + +void ClassModelItem::setBaseClasses(const QStringList &baseClasses) +{ + d->_M_baseClasses = baseClasses; +} + +TemplateParameterList ClassModelItem::templateParameters() const +{ + return d->_M_templateParameters; +} + +void ClassModelItem::setTemplateParameters(const TemplateParameterList &templateParameters) +{ + d->_M_templateParameters = templateParameters; +} + +void ClassModelItem::addBaseClass(const QString &baseClass) +{ + d->_M_baseClasses.append(baseClass); +} + +bool ClassModelItem::extendsClass(const QString &name) const +{ + return d->_M_baseClasses.contains(name); +} + +void ClassModelItem::setClassType(CodeModel::ClassType type) +{ + d->_M_classType = type; +} + +CodeModel::ClassType ClassModelItem::classType() const +{ + return d->_M_classType; +} + +// --------------------------------------------------------------------------- +class ScopeModelItemData +{ +public: + ~ScopeModelItemData() { + qDeleteAll(_M_classes.values()); + qDeleteAll(_M_enums.values()); + qDeleteAll(_M_typeAliases.values()); + qDeleteAll(_M_variables.values()); + qDeleteAll(_M_functionDefinitions.values()); + qDeleteAll(_M_functions.values()); + } + + QHash<QString, ClassModelItem*> _M_classes; + QHash<QString, EnumModelItem*> _M_enums; + QHash<QString, TypeAliasModelItem*> _M_typeAliases; + QHash<QString, VariableModelItem*> _M_variables; + QMultiHash<QString, FunctionDefinitionModelItem*> _M_functionDefinitions; + QMultiHash<QString, FunctionModelItem*> _M_functions; +}; + +ScopeModelItem::ScopeModelItem(CodeModel *model, int kind) + : CodeModelItem(model, kind) +{ + d = new ScopeModelItemData; +} + +ScopeModelItem::~ScopeModelItem() +{ + delete d; +} + +void ScopeModelItem::addClass(ClassModelItem *item) +{ + d->_M_classes.insert(item->name(), item); +} + +void ScopeModelItem::addFunction(FunctionModelItem *item) +{ + d->_M_functions.insert(item->name(), item); +} + +void ScopeModelItem::addFunctionDefinition(FunctionDefinitionModelItem *item) +{ + d->_M_functionDefinitions.insert(item->name(), item); +} + +void ScopeModelItem::addVariable(VariableModelItem *item) +{ + d->_M_variables.insert(item->name(), item); +} + +void ScopeModelItem::addTypeAlias(TypeAliasModelItem *item) +{ + d->_M_typeAliases.insert(item->name(), item); +} + +void ScopeModelItem::addEnum(EnumModelItem *item) +{ + d->_M_enums.insert(item->name(), item); +} + +// --------------------------------------------------------------------------- +class NamespaceModelItemData +{ +public: + ~NamespaceModelItemData() { + qDeleteAll(_M_namespaces.values()); + } + + QHash<QString, NamespaceModelItem *> _M_namespaces; +}; + +NamespaceModelItem::NamespaceModelItem(CodeModel *model, int kind) +: ScopeModelItem(model, kind) +{ + d = new NamespaceModelItemData(); +} + +NamespaceModelItem::~NamespaceModelItem() +{ + delete d; +} + +NamespaceList NamespaceModelItem::namespaces() const +{ + return d->_M_namespaces.values(); +} +void NamespaceModelItem::addNamespace(NamespaceModelItem *item) +{ + d->_M_namespaces.insert(item->name(), item); +} + +// --------------------------------------------------------------------------- +class ArgumentModelItemData +{ +public: + ~ArgumentModelItemData() { + delete _M_type; + } + TypeInfo *_M_type; + QString _M_defaultValueExpression; + bool _M_defaultValue; +}; + +ArgumentModelItem::ArgumentModelItem(CodeModel *model, int kind) +: CodeModelItem(model, kind) +{ + d = new ArgumentModelItemData(); + d->_M_defaultValue = false; +} + +ArgumentModelItem::~ArgumentModelItem() +{ + delete d; +} + +TypeInfo *ArgumentModelItem::type() const +{ + return d->_M_type; +} + +void ArgumentModelItem::setType(TypeInfo *type) +{ + d->_M_type = type; +} + +bool ArgumentModelItem::defaultValue() const +{ + return d->_M_defaultValue; +} + +void ArgumentModelItem::setDefaultValue(bool defaultValue) +{ + d->_M_defaultValue = defaultValue; +} + +QString ArgumentModelItem::defaultValueExpression() const +{ + return d->_M_defaultValueExpression; +} + +void ArgumentModelItem::setDefaultValueExpression(const QString &expr) +{ + d->_M_defaultValueExpression = expr; +} + +// --------------------------------------------------------------------------- +class FunctionModelItemData +{ +public: + ~FunctionModelItemData() { + qDeleteAll(_M_arguments); + } + + ArgumentList _M_arguments; + CodeModel::FunctionType _M_functionType; + union + { + struct + { + uint _M_isVirtual: 1; + uint _M_isInline: 1; + uint _M_isAbstract: 1; + uint _M_isExplicit: 1; + uint _M_isVariadics: 1; + }; + uint _M_flags; + }; +}; + +FunctionModelItem::FunctionModelItem(CodeModel *model, int kind) +: MemberModelItem(model, kind) +{ + d = new FunctionModelItemData(); + d->_M_functionType = CodeModel::Normal; + d->_M_flags = 0; +} + +FunctionModelItem::~FunctionModelItem() +{ + delete d; +} + +bool FunctionModelItem::isSimilar(FunctionModelItem *other) const +{ + if (name() != other->name()) + return false; + + if (isConstant() != other->isConstant()) + return false; + + if (isVariadics() != other->isVariadics()) + return false; + + if (arguments().count() != other->arguments().count()) + return false; + + // ### check the template parameters + + for (int i=0; i<arguments().count(); ++i) + { + ArgumentModelItem *arg1 = arguments().at(i); + ArgumentModelItem *arg2 = other->arguments().at(i); + + TypeInfo *t1 = static_cast<TypeInfo *>(arg1->type()); + TypeInfo *t2 = static_cast<TypeInfo *>(arg2->type()); + + if (*t1 != *t2) + return false; + } + + return true; +} + +ArgumentList FunctionModelItem::arguments() const +{ + return d->_M_arguments; +} + +void FunctionModelItem::addArgument(ArgumentModelItem *item) +{ + d->_M_arguments.append(item); +} + +CodeModel::FunctionType FunctionModelItem::functionType() const +{ + return d->_M_functionType; +} + +void FunctionModelItem::setFunctionType(CodeModel::FunctionType functionType) +{ + d->_M_functionType = functionType; +} + +bool FunctionModelItem::isVariadics() const +{ + return d->_M_isVariadics; +} + +void FunctionModelItem::setVariadics(bool isVariadics) +{ + d->_M_isVariadics = isVariadics; +} + +bool FunctionModelItem::isVirtual() const +{ + return d->_M_isVirtual; +} + +void FunctionModelItem::setVirtual(bool isVirtual) +{ + d->_M_isVirtual = isVirtual; +} + +bool FunctionModelItem::isInline() const +{ + return d->_M_isInline; +} + +void FunctionModelItem::setInline(bool isInline) +{ + d->_M_isInline = isInline; +} + +bool FunctionModelItem::isExplicit() const +{ + return d->_M_isExplicit; +} + +void FunctionModelItem::setExplicit(bool isExplicit) +{ + d->_M_isExplicit = isExplicit; +} + +bool FunctionModelItem::isAbstract() const +{ + return d->_M_isAbstract; +} + +void FunctionModelItem::setAbstract(bool isAbstract) +{ + d->_M_isAbstract = isAbstract; +} + +// --------------------------------------------------------------------------- +class TypeAliasModelItemData +{ +public: + ~TypeAliasModelItemData() { + delete _M_type; + } + + TypeInfo *_M_type; +}; + +TypeAliasModelItem::TypeAliasModelItem(CodeModel *model, int kind) +: CodeModelItem(model, kind) +{ + d = new TypeAliasModelItemData; +} + +TypeAliasModelItem::~TypeAliasModelItem() +{ + delete d; +} + +TypeInfo *TypeAliasModelItem::type() const +{ + return d->_M_type; +} + +void TypeAliasModelItem::setType(TypeInfo *type) +{ + d->_M_type = type; +} + +// --------------------------------------------------------------------------- +class EnumModelItemData +{ +public: + ~EnumModelItemData() { + qDeleteAll(_M_enumerators); + } + CodeModel::AccessPolicy _M_accessPolicy; + EnumeratorList _M_enumerators; +}; + +EnumModelItem::EnumModelItem(CodeModel *model, int kind) +: CodeModelItem(model, kind) +{ + d = new EnumModelItemData; + d->_M_accessPolicy = CodeModel::Public; +} + +EnumModelItem::~EnumModelItem() +{ + delete d; +} + +CodeModel::AccessPolicy EnumModelItem::accessPolicy() const +{ + return d->_M_accessPolicy; +} + +void EnumModelItem::setAccessPolicy(CodeModel::AccessPolicy accessPolicy) +{ + d->_M_accessPolicy = accessPolicy; +} + +EnumeratorList EnumModelItem::enumerators() const +{ + return d->_M_enumerators; +} + +void EnumModelItem::addEnumerator(EnumeratorModelItem *item) +{ + d->_M_enumerators.append(item); +} + +// --------------------------------------------------------------------------- +class EnumeratorModelItemData +{ +public: + QString _M_value; +}; + +EnumeratorModelItem::EnumeratorModelItem(CodeModel *model, int kind) +: CodeModelItem(model, kind) +{ + d = new EnumeratorModelItemData; +} + +EnumeratorModelItem::~EnumeratorModelItem() +{ + delete d; +} + +QString EnumeratorModelItem::value() const +{ + return d->_M_value; +} + +void EnumeratorModelItem::setValue(const QString &value) +{ + d->_M_value = value; +} + +// --------------------------------------------------------------------------- +class TemplateParameterModelItemData +{ +public: + ~TemplateParameterModelItemData() { + delete _M_type; + } + + TypeInfo *_M_type; + bool _M_defaultValue; +}; + +TemplateParameterModelItem::TemplateParameterModelItem(CodeModel *model, int kind) +: CodeModelItem(model, kind) +{ + d = new TemplateParameterModelItemData; + d->_M_defaultValue = false; + d->_M_type = 0; +} + +TemplateParameterModelItem::TemplateParameterModelItem(const TemplateParameterModelItem& item) + : CodeModelItem(item) +{ + d = new TemplateParameterModelItemData; + *d = *(item.d); +} + +TemplateParameterModelItem::~TemplateParameterModelItem() +{ + delete d; +} + +TypeInfo *TemplateParameterModelItem::type() const +{ + return d->_M_type; +} + +void TemplateParameterModelItem::setType(TypeInfo *type) +{ + d->_M_type = type; +} + +bool TemplateParameterModelItem::defaultValue() const +{ + return d->_M_defaultValue; +} + +void TemplateParameterModelItem::setDefaultValue(bool defaultValue) +{ + d->_M_defaultValue = defaultValue; +} + +// --------------------------------------------------------------------------- +FileModelItem::FileModelItem(CodeModel *model, int kind) +: NamespaceModelItem(model, kind) +{ +} + +FileModelItem::~FileModelItem() +{ +} + +FunctionDefinitionModelItem::FunctionDefinitionModelItem(CodeModel *model, int kind) +: FunctionModelItem(model, kind) +{ + +} + +FunctionDefinitionModelItem::~FunctionDefinitionModelItem() +{ + +} + +VariableModelItem::VariableModelItem(CodeModel *model, int kind) +: MemberModelItem(model, kind) +{ + +} + +VariableModelItem::~VariableModelItem() +{ + +} + +// --------------------------------------------------------------------------- +class MemberModelItemData +{ +public: + ~MemberModelItemData() { + delete _M_type; + qDeleteAll(_M_templateParameters); + } + TemplateParameterList _M_templateParameters; + TypeInfo *_M_type; + CodeModel::AccessPolicy _M_accessPolicy; + union + { + struct + { + uint _M_isConstant: 1; + uint _M_isVolatile: 1; + uint _M_isStatic: 1; + uint _M_isAuto: 1; + uint _M_isFriend: 1; + uint _M_isRegister: 1; + uint _M_isExtern: 1; + uint _M_isMutable: 1; + }; + uint _M_flags; + }; +}; + +MemberModelItem::MemberModelItem(CodeModel *model, int kind) +: CodeModelItem(model, kind) +{ + d = new MemberModelItemData(); + d->_M_accessPolicy = CodeModel::Public; + d->_M_flags = 0; +} + +MemberModelItem::~MemberModelItem() +{ + delete d; +} + +TypeInfo *MemberModelItem::type() const +{ + return d->_M_type; +} + +void MemberModelItem::setType(TypeInfo *type) +{ + d->_M_type = type; +} + +CodeModel::AccessPolicy MemberModelItem::accessPolicy() const +{ + return d->_M_accessPolicy; +} + +void MemberModelItem::setAccessPolicy(CodeModel::AccessPolicy accessPolicy) +{ + d->_M_accessPolicy = accessPolicy; +} + +bool MemberModelItem::isStatic() const +{ + return d->_M_isStatic; +} + +void MemberModelItem::setStatic(bool isStatic) +{ + d->_M_isStatic = isStatic; +} + +bool MemberModelItem::isConstant() const +{ + return d->_M_isConstant; +} + +void MemberModelItem::setConstant(bool isConstant) +{ + d->_M_isConstant = isConstant; +} + +bool MemberModelItem::isVolatile() const +{ + return d->_M_isVolatile; +} + +void MemberModelItem::setVolatile(bool isVolatile) +{ + d->_M_isVolatile = isVolatile; +} + +bool MemberModelItem::isAuto() const +{ + return d->_M_isAuto; +} + +void MemberModelItem::setAuto(bool isAuto) +{ + d->_M_isAuto = isAuto; +} + +bool MemberModelItem::isFriend() const +{ + return d->_M_isFriend; +} + +void MemberModelItem::setFriend(bool isFriend) +{ + d->_M_isFriend = isFriend; +} + +bool MemberModelItem::isRegister() const +{ + return d->_M_isRegister; +} + +void MemberModelItem::setRegister(bool isRegister) +{ + d->_M_isRegister = isRegister; +} + +bool MemberModelItem::isExtern() const +{ + return d->_M_isExtern; +} + +void MemberModelItem::setExtern(bool isExtern) +{ + d->_M_isExtern = isExtern; +} + +bool MemberModelItem::isMutable() const +{ + return d->_M_isMutable; +} + +void MemberModelItem::setMutable(bool isMutable) +{ + d->_M_isMutable = isMutable; +} + +TemplateParameterList MemberModelItem::templateParameters() const +{ + return d->_M_templateParameters; +} + +void MemberModelItem::setTemplateParameters(const TemplateParameterList &templateParameters) +{ + d->_M_templateParameters = templateParameters; +} + +// kate: space-indent on; indent-width 2; replace-tabs on; + diff --git a/tests/manual/cppmodelmanager/codemodel/codemodelitems.h b/tests/manual/cppmodelmanager/codemodel/codemodelitems.h new file mode 100644 index 00000000000..a2ce4f6b2eb --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/codemodelitems.h @@ -0,0 +1,527 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +/* This file is part of KDevelop +Copyright (C) 2002-2005 Roberto Raggi <[email protected]> +Copyright (C) 2005 Trolltech AS + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License version 2 as published by the Free Software Foundation. + +This library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#ifndef CODEMODELITEMS_H +#define CODEMODELITEMS_H + +#include <QtCore/QStringList> + +class CodeModelItem; +class ArgumentModelItem; +class ClassModelItem; +class EnumModelItem; +class EnumeratorModelItem; +class FileModelItem; +class FunctionDefinitionModelItem; +class FunctionModelItem; +class NamespaceModelItem; +class TemplateParameterModelItem; +class TypeAliasModelItem; +class VariableModelItem; +class TypeInfo; + +typedef QList<ArgumentModelItem*> ArgumentList; +typedef QList<ClassModelItem*> ClassList; +typedef QList<EnumModelItem*> EnumList; +typedef QList<EnumeratorModelItem*> EnumeratorList; +typedef QList<FileModelItem*> FileList; +typedef QList<FunctionDefinitionModelItem*> FunctionDefinitionList; +typedef QList<FunctionModelItem*> FunctionList; +typedef QList<NamespaceModelItem*> NamespaceList; +typedef QList<TemplateParameterModelItem*> TemplateParameterList; +typedef QList<TypeAliasModelItem*> TypeAliasList; +typedef QList<VariableModelItem*> VariableList; +typedef QList<TypeInfo*> TypeInfoList; + +#define DECLARE_MODEL_NODE(name) \ + enum { __node_kind = Kind_##name }; + + +template <class T> inline T model_cast(CodeModelItem *item) { return 0; } + +#define DECLARE_MODELITEM(name) \ + template <> inline name##ModelItem *model_cast<##name##ModelItem *>(CodeModelItem *item) { \ + if (item && item->kind() == CodeModelItem::Kind_##name) \ + return static_cast<##name##ModelItem *>(item); \ + return 0; } + +class CodeModel +{ +public: + enum AccessPolicy + { + Public, + Protected, + Private + }; + + enum FunctionType + { + Normal, + Signal, + Slot + }; + + enum ClassType + { + Class, + Struct, + Union + }; + +public: + virtual ~CodeModel(); + +/* virtual FileList files() const = 0; + virtual NamespaceModelItem *globalNamespace() const = 0; */ +}; + +class TypeInfo +{ +public: + TypeInfo(): flags (0) {} + virtual ~TypeInfo() { qDeleteAll(m_arguments); } + + QString qualifiedName() const { return m_qualifiedName; } + void setQualifiedName(const QString &qualified_name) { m_qualifiedName = qualified_name; } + + bool isConstant() const { return m_constant; } + void setConstant(bool is) { m_constant = is; } + + bool isVolatile() const { return m_volatile; } + void setVolatile(bool is) { m_volatile = is; } + + bool isReference() const { return m_reference; } + void setReference(bool is) { m_reference = is; } + + int indirections() const { return m_indirections; } + void setIndirections(int indirections) { m_indirections = indirections; } + + bool isFunctionPointer() const { return m_functionPointer; } + void setFunctionPointer(bool is) { m_functionPointer = is; } + + QStringList arrayElements() const { return m_arrayElements; } + void setArrayElements(const QStringList &arrayElements) { m_arrayElements = arrayElements; } + + TypeInfoList arguments() const { return m_arguments; } + void addArgument(TypeInfo *arg) { m_arguments.append(arg); } + + bool operator==(const TypeInfo &other); + bool operator!=(const TypeInfo &other) { return !(*this==other); } + +private: + union + { + uint flags; + + struct + { + uint m_constant: 1; + uint m_volatile: 1; + uint m_reference: 1; + uint m_functionPointer: 1; + uint m_indirections: 6; + uint m_padding: 22; + }; + }; + + QString m_qualifiedName; + QStringList m_arrayElements; + TypeInfoList m_arguments; +}; + +class CodeModelItemData; +class CodeModelItem +{ +public: + enum Kind + { + /* These are bit-flags resembling inheritance */ + Kind_Scope = 0x1, + Kind_Namespace = 0x2 | Kind_Scope, + Kind_Member = 0x4, + Kind_Function = 0x8 | Kind_Member, + KindMask = 0xf, + + /* These are for classes that are not inherited from */ + FirstKind = 0x8, + Kind_Argument = 1 << FirstKind, + Kind_Class = 2 << FirstKind | Kind_Scope, + Kind_Enum = 3 << FirstKind, + Kind_Enumerator = 4 << FirstKind, + Kind_File = 5 << FirstKind | Kind_Namespace, + Kind_FunctionDefinition = 6 << FirstKind | Kind_Function, + Kind_TemplateParameter = 7 << FirstKind, + Kind_TypeAlias = 8 << FirstKind, + Kind_Variable = 9 << FirstKind | Kind_Member + }; + + CodeModelItem(CodeModel *model, int kind); + CodeModelItem(const CodeModelItem &item); + virtual ~CodeModelItem(); + + int kind() const; + + QString qualifiedName() const; + + QString name() const; + void setName(const QString &name); + + QString scope() const; + void setScope(const QString &scope); + + void setFile(FileModelItem *file); + FileModelItem *file() const; + + void startPosition(int *line, int *column); + void setStartPosition(int line, int column); + + void endPosition(int *line, int *column); + void setEndPosition(int line, int column); + + std::size_t creationId() const; + void setCreationId(std::size_t creation_id); + + CodeModel *model() const; + +protected: + void setKind(int kind); + +private: + CodeModelItemData *d; +}; + +class ScopeModelItemData; +class ScopeModelItem: public CodeModelItem +{ +public: + DECLARE_MODEL_NODE(Scope) + ScopeModelItem(CodeModel *model, int kind = __node_kind); + virtual ~ScopeModelItem(); + + void addClass(ClassModelItem *item); + void addEnum(EnumModelItem *item); + void addFunction(FunctionModelItem *item); + void addFunctionDefinition(FunctionDefinitionModelItem *item); + void addTypeAlias(TypeAliasModelItem *item); + void addVariable(VariableModelItem *item); + +private: + ScopeModelItemData *d; +}; +DECLARE_MODELITEM(Scope) + +class ClassModelItemData; +class ClassModelItem: public ScopeModelItem +{ +public: + DECLARE_MODEL_NODE(Class) + ClassModelItem(CodeModel *model, int kind = __node_kind); + virtual ~ClassModelItem(); + + QStringList baseClasses() const; + + void setBaseClasses(const QStringList &baseClasses); + void addBaseClass(const QString &baseClass); + + TemplateParameterList templateParameters() const; + void setTemplateParameters(const TemplateParameterList &templateParameters); + + bool extendsClass(const QString &name) const; + + void setClassType(CodeModel::ClassType type); + CodeModel::ClassType classType() const; + +private: + ClassModelItemData *d; +}; +DECLARE_MODELITEM(Class) + +class NamespaceModelItemData; +class NamespaceModelItem: public ScopeModelItem +{ +public: + DECLARE_MODEL_NODE(Namespace) + NamespaceModelItem(CodeModel *model, int kind = __node_kind); + virtual ~NamespaceModelItem(); + + NamespaceList namespaces() const; + void addNamespace(NamespaceModelItem *item); + NamespaceModelItem *findNamespace(const QString &name) const; + +private: + NamespaceModelItemData *d; +}; +DECLARE_MODELITEM(Namespace) + +class FileModelItem: public NamespaceModelItem +{ +public: + DECLARE_MODEL_NODE(File) + FileModelItem(CodeModel *model, int kind = __node_kind); + virtual ~FileModelItem(); +}; +DECLARE_MODELITEM(File) + +class ArgumentModelItemData; +class ArgumentModelItem: public CodeModelItem +{ +public: + DECLARE_MODEL_NODE(Argument) + ArgumentModelItem(CodeModel *model, int kind = __node_kind); + virtual ~ArgumentModelItem(); + +public: + TypeInfo *type() const; + void setType(TypeInfo *type); + + bool defaultValue() const; + void setDefaultValue(bool defaultValue); + + QString defaultValueExpression() const; + void setDefaultValueExpression(const QString &expr); + +private: + ArgumentModelItemData *d; +}; +DECLARE_MODELITEM(Argument) + +class MemberModelItemData; +class MemberModelItem: public CodeModelItem +{ +public: + DECLARE_MODEL_NODE(Member) + MemberModelItem(CodeModel *model, int kind); + virtual ~MemberModelItem(); + + bool isConstant() const; + void setConstant(bool isConstant); + + bool isVolatile() const; + void setVolatile(bool isVolatile); + + bool isStatic() const; + void setStatic(bool isStatic); + + bool isAuto() const; + void setAuto(bool isAuto); + + bool isFriend() const; + void setFriend(bool isFriend); + + bool isRegister() const; + void setRegister(bool isRegister); + + bool isExtern() const; + void setExtern(bool isExtern); + + bool isMutable() const; + void setMutable(bool isMutable); + + CodeModel::AccessPolicy accessPolicy() const; + void setAccessPolicy(CodeModel::AccessPolicy accessPolicy); + + TemplateParameterList templateParameters() const; + void setTemplateParameters(const TemplateParameterList &templateParameters); + + TypeInfo *type() const; + void setType(TypeInfo *type); + +private: + MemberModelItemData *d; +}; +DECLARE_MODELITEM(Member) + +class FunctionModelItemData; +class FunctionModelItem: public MemberModelItem +{ +public: + DECLARE_MODEL_NODE(Function) + FunctionModelItem(CodeModel *model, int kind = __node_kind); + virtual ~FunctionModelItem(); + + ArgumentList arguments() const; + + void addArgument(ArgumentModelItem *item); + + CodeModel::FunctionType functionType() const; + void setFunctionType(CodeModel::FunctionType functionType); + + bool isVirtual() const; + void setVirtual(bool isVirtual); + + bool isInline() const; + void setInline(bool isInline); + + bool isExplicit() const; + void setExplicit(bool isExplicit); + + bool isAbstract() const; + void setAbstract(bool isAbstract); + + bool isVariadics() const; + void setVariadics(bool isVariadics); + + bool isSimilar(FunctionModelItem *other) const; + +private: + FunctionModelItemData *d; +}; +DECLARE_MODELITEM(Function) + +class FunctionDefinitionModelItem: public FunctionModelItem +{ +public: + DECLARE_MODEL_NODE(FunctionDefinition) + FunctionDefinitionModelItem(CodeModel *model, int kind = __node_kind); + virtual ~FunctionDefinitionModelItem(); +}; +DECLARE_MODELITEM(FunctionDefinition) + +class VariableModelItem: public MemberModelItem +{ +public: + DECLARE_MODEL_NODE(Variable) + VariableModelItem(CodeModel *model, int kind = __node_kind); + virtual ~VariableModelItem(); +}; +DECLARE_MODELITEM(Variable) + +class TypeAliasModelItemData; +class TypeAliasModelItem: public CodeModelItem +{ +public: + DECLARE_MODEL_NODE(TypeAlias) + TypeAliasModelItem(CodeModel *model, int kind = __node_kind); + virtual ~TypeAliasModelItem(); + + TypeInfo *type() const; + void setType(TypeInfo *type); + +private: + TypeAliasModelItemData *d; +}; +DECLARE_MODELITEM(TypeAlias) + +class EnumModelItemData; +class EnumModelItem: public CodeModelItem +{ +public: + DECLARE_MODEL_NODE(Enum) + EnumModelItem(CodeModel *model, int kind = __node_kind); + virtual ~EnumModelItem(); + + CodeModel::AccessPolicy accessPolicy() const; + void setAccessPolicy(CodeModel::AccessPolicy accessPolicy); + + EnumeratorList enumerators() const; + void addEnumerator(EnumeratorModelItem *item); + +private: + EnumModelItemData *d; +}; +DECLARE_MODELITEM(Enum) + +class EnumeratorModelItemData; +class EnumeratorModelItem: public CodeModelItem +{ +public: + DECLARE_MODEL_NODE(Enumerator) + EnumeratorModelItem(CodeModel *model, int kind = __node_kind); + virtual ~EnumeratorModelItem(); + + QString value() const; + void setValue(const QString &value); + +private: + EnumeratorModelItemData *d; +}; +DECLARE_MODELITEM(Enumerator) + +class TemplateParameterModelItemData; +class TemplateParameterModelItem: public CodeModelItem +{ +public: + DECLARE_MODEL_NODE(TemplateParameter) + TemplateParameterModelItem(CodeModel *model, int kind = __node_kind); + TemplateParameterModelItem(const TemplateParameterModelItem& item); + virtual ~TemplateParameterModelItem(); + + TypeInfo *type() const; + void setType(TypeInfo *type); + + bool defaultValue() const; + void setDefaultValue(bool defaultValue); + +private: + TemplateParameterModelItemData *d; +}; +DECLARE_MODELITEM(TemplateParameter) + +// ### todo, check language +#define DECLARE_LANGUAGE_MODELITEM(name, language) \ + template <> inline language##name##ModelItem *model_cast<##language##name##ModelItem *>(CodeModelItem *item) { \ + if (item && item->kind() == CodeModelItem::Kind_##name) \ + return static_cast<##language##name##ModelItem *>(item); \ + return 0; } + +// ### todo, check language +template <class T> inline T model_cast(CodeModel *item) { return 0; } + +#define DECLARE_LANGUAGE_CODEMODEL(language) \ + template <> inline language##CodeModel *model_cast<##language##CodeModel *>(CodeModel *item) { \ + return item ? static_cast<##language##CodeModel *>(item) : 0; } + +#endif //CODEMODELITEMS_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/compiler_utils.cpp b/tests/manual/cppmodelmanager/codemodel/compiler_utils.cpp new file mode 100644 index 00000000000..3243825449e --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/compiler_utils.cpp @@ -0,0 +1,77 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop + Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "compiler_utils.h" +#include "type_compiler.h" +#include "name_compiler.h" +#include "declarator_compiler.h" +#include "ast.h" +#include "binder.h" + +TypeInfo *CompilerUtils::typeDescription(TypeSpecifierAST *type_specifier, DeclaratorAST *declarator, Binder *binder) +{ + TypeCompiler type_cc (binder); + DeclaratorCompiler decl_cc (binder); + + type_cc.run (type_specifier); + decl_cc.run (declarator); + + TypeInfo *typeInfo = new TypeInfo(); + typeInfo->setQualifiedName (type_cc.qualifiedName ()); + typeInfo->setConstant (type_cc.isConstant ()); + typeInfo->setVolatile (type_cc.isVolatile ()); + typeInfo->setReference (decl_cc.isReference ()); + typeInfo->setIndirections (decl_cc.indirection ()); + typeInfo->setArrayElements (decl_cc.arrayElements ()); + + return typeInfo; +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/compiler_utils.h b/tests/manual/cppmodelmanager/codemodel/compiler_utils.h new file mode 100644 index 00000000000..3b42164d638 --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/compiler_utils.h @@ -0,0 +1,68 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop + Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef COMPILER_UTILS_H +#define COMPILER_UTILS_H + +struct TypeSpecifierAST; +struct DeclaratorAST; +class Binder; +class TypeInfo; + +namespace CompilerUtils +{ + +TypeInfo *typeDescription(TypeSpecifierAST *type_specifier, DeclaratorAST *declarator, Binder *binder); + +} // namespace CompilerUtils + +#endif // COMPILER_UTILS_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/declarator_compiler.cpp b/tests/manual/cppmodelmanager/codemodel/declarator_compiler.cpp new file mode 100644 index 00000000000..a30286af64e --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/declarator_compiler.cpp @@ -0,0 +1,168 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop + Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "declarator_compiler.h" +#include "name_compiler.h" +#include "type_compiler.h" +#include "compiler_utils.h" +#include "lexer.h" +#include "binder.h" + +#include <qdebug.h> + +DeclaratorCompiler::DeclaratorCompiler(Binder *binder) + : _M_binder (binder), _M_token_stream (binder->tokenStream ()) +{ +} + +void DeclaratorCompiler::run(DeclaratorAST *node) +{ + _M_id.clear(); + _M_parameters.clear(); + _M_array.clear(); + _M_function = false; + _M_reference = false; + _M_variadics = false; + _M_indirection = 0; + + if (node) + { + NameCompiler name_cc(_M_binder); + + DeclaratorAST *decl = node; + while (decl && decl->sub_declarator) + decl = decl->sub_declarator; + + Q_ASSERT (decl != 0); + + name_cc.run(decl->id); + _M_id = name_cc.qualifiedName(); + _M_function = (node->parameter_declaration_clause != 0); + if (node->parameter_declaration_clause && node->parameter_declaration_clause->ellipsis) + _M_variadics = true; + + visitNodes(this, node->ptr_ops); + visit(node->parameter_declaration_clause); + + if (const ListNode<ExpressionAST*> *it = node->array_dimensions) + { + it->toFront(); + const ListNode<ExpressionAST*> *end = it; + + do + { + QString elt; + if (ExpressionAST *expr = it->element) + { + const Token &start_token = _M_token_stream->token((int) expr->start_token); + const Token &end_token = _M_token_stream->token((int) expr->end_token); + + elt += QString::fromUtf8(&start_token.text[start_token.position], + (int) (end_token.position - start_token.position)).trimmed(); + } + + _M_array.append (elt); + + it = it->next; + } + while (it != end); + } + } +} + +void DeclaratorCompiler::visitPtrOperator(PtrOperatorAST *node) +{ + std::size_t op = _M_token_stream->kind(node->op); + + switch (op) + { + case '&': + _M_reference = true; + break; + case '*': + ++_M_indirection; + break; + + default: + break; + } + + if (node->mem_ptr) + { +#if defined(__GNUC__) +#warning "ptr to mem -- not implemented" +#endif + } +} + +void DeclaratorCompiler::visitParameterDeclaration(ParameterDeclarationAST *node) +{ + Parameter p; + + TypeCompiler type_cc(_M_binder); + DeclaratorCompiler decl_cc(_M_binder); + + decl_cc.run(node->declarator); + + p.name = decl_cc.id(); + p.type = CompilerUtils::typeDescription(node->type_specifier, node->declarator, _M_binder); + if (node->expression != 0) + { + p.defaultValue = true; + const Token &start = _M_token_stream->token((int) node->expression->start_token); + const Token &end = _M_token_stream->token((int) node->expression->end_token); + int length = (int) (end.position - start.position); + p.defaultValueExpression = QString::fromUtf8(&start.text[start.position], length).trimmed(); + } + + _M_parameters.append(p); +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/declarator_compiler.h b/tests/manual/cppmodelmanager/codemodel/declarator_compiler.h new file mode 100644 index 00000000000..d715c1ec05e --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/declarator_compiler.h @@ -0,0 +1,109 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop + Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATOR_COMPILER_H +#define DECLARATOR_COMPILER_H + +#include "default_visitor.h" + +#include <QtCore/QString> +#include <QtCore/QStringList> +#include <QtCore/QList> + +class TokenStream; +class Binder; +class TypeInfo; + +class DeclaratorCompiler: protected DefaultVisitor +{ +public: + struct Parameter + { + TypeInfo *type; + QString name; + QString defaultValueExpression; + bool defaultValue; + + Parameter(): defaultValue(false) {} + }; + +public: + DeclaratorCompiler(Binder *binder); + + void run(DeclaratorAST *node); + + inline QString id() const { return _M_id; } + inline QStringList arrayElements() const { return _M_array; } + inline bool isFunction() const { return _M_function; } + inline bool isVariadics() const { return _M_variadics; } + inline bool isReference() const { return _M_reference; } + inline int indirection() const { return _M_indirection; } + inline QList<Parameter> parameters() const { return _M_parameters; } + +protected: + virtual void visitPtrOperator(PtrOperatorAST *node); + virtual void visitParameterDeclaration(ParameterDeclarationAST *node); + +private: + Binder *_M_binder; + TokenStream *_M_token_stream; + + bool _M_function; + bool _M_reference; + bool _M_variadics; + int _M_indirection; + QString _M_id; + QStringList _M_array; + QList<Parameter> _M_parameters; +}; + +#endif // DECLARATOR_COMPILER_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/name_compiler.cpp b/tests/manual/cppmodelmanager/codemodel/name_compiler.cpp new file mode 100644 index 00000000000..a85d9969b56 --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/name_compiler.cpp @@ -0,0 +1,150 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop + Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + Copyright (C) 2005 Trolltech + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "name_compiler.h" +#include "type_compiler.h" +#include "declarator_compiler.h" +#include "lexer.h" +#include "symbol.h" +#include "binder.h" + +#include <QtCore/qdebug.h> + +NameCompiler::NameCompiler(Binder *binder) + : _M_binder (binder), _M_token_stream (binder->tokenStream ()) +{ +} + +QString NameCompiler::decode_operator(std::size_t index) const +{ + const Token &tk = _M_token_stream->token((int) index); + return QString::fromUtf8(&tk.text[tk.position], (int) tk.size); +} + +void NameCompiler::internal_run(AST *node) +{ + _M_name.clear(); + visit(node); +} + +void NameCompiler::visitUnqualifiedName(UnqualifiedNameAST *node) +{ + QString tmp_name; + + if (node->tilde) + tmp_name += QLatin1String("~"); + + if (node->id) + tmp_name += _M_token_stream->symbol(node->id)->as_string(); + + if (OperatorFunctionIdAST *op_id = node->operator_id) + { +#if defined(__GNUC__) +#warning "NameCompiler::visitUnqualifiedName() -- implement me" +#endif + + if (op_id->op && op_id->op->op) + { + tmp_name += QLatin1String("operator"); + tmp_name += decode_operator(op_id->op->op); + if (op_id->op->close) + tmp_name += decode_operator(op_id->op->close); + } + else if (op_id->type_specifier) + { +#if defined(__GNUC__) +#warning "don't use an hardcoded string as cast' name" +#endif + Token const &tk = _M_token_stream->token ((int) op_id->start_token); + Token const &end_tk = _M_token_stream->token ((int) op_id->end_token); + tmp_name += QString::fromLatin1 (&tk.text[tk.position], + (int) (end_tk.position - tk.position)).trimmed (); + } + } + + if (!_M_name.isEmpty()) + _M_name += QLatin1String("::"); + _M_name += tmp_name; + + if (node->template_arguments) + { + _M_name += QLatin1String("<"); + visitNodes(this, node->template_arguments); + _M_name.truncate(_M_name.count() - 1); // remove the last ',' + _M_name += QLatin1String(">"); + } +} + +void NameCompiler::visitTemplateArgument(TemplateArgumentAST *node) +{ + if (node->type_id && node->type_id->type_specifier) + { + TypeCompiler type_cc(_M_binder); + type_cc.run(node->type_id->type_specifier); + + DeclaratorCompiler decl_cc(_M_binder); + decl_cc.run(node->type_id->declarator); + + if (type_cc.isConstant()) + _M_name += "const "; + + _M_name += type_cc.qualifiedName (); + + if (decl_cc.isReference()) + _M_name += "&"; + if (decl_cc.indirection()) + _M_name += QString(decl_cc.indirection(), '*'); + + _M_name += QLatin1String(","); + } +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/name_compiler.h b/tests/manual/cppmodelmanager/codemodel/name_compiler.h new file mode 100644 index 00000000000..5d61e316bd5 --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/name_compiler.h @@ -0,0 +1,85 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop + Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef NAME_COMPILER_H +#define NAME_COMPILER_H + +#include "default_visitor.h" +#include <QtCore/QString> + +class TokenStream; +class Binder; + +class NameCompiler: protected DefaultVisitor +{ +public: + NameCompiler(Binder *binder); + + void run(NameAST *node) { internal_run(node); } + void run(UnqualifiedNameAST *node) { internal_run(node); } + + QString qualifiedName() const { return _M_name; } + +protected: + virtual void visitUnqualifiedName(UnqualifiedNameAST *node); + virtual void visitTemplateArgument(TemplateArgumentAST *node); + + void internal_run(AST *node); + QString decode_operator(std::size_t index) const; + +private: + Binder *_M_binder; + TokenStream *_M_token_stream; + QString _M_name; +}; + +#endif // NAME_COMPILER_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/type_compiler.cpp b/tests/manual/cppmodelmanager/codemodel/type_compiler.cpp new file mode 100644 index 00000000000..05708c9c942 --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/type_compiler.cpp @@ -0,0 +1,169 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +/* This file is part of KDevelop + Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + Copyright (C) 2005 Trolltech AS + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "type_compiler.h" +#include "name_compiler.h" +#include "lexer.h" +#include "symbol.h" +#include "tokens.h" +#include "binder.h" + +#include <QtCore/QString> + +TypeCompiler::TypeCompiler(Binder *binder) + : _M_binder (binder), _M_token_stream(binder->tokenStream ()) +{ +} + +void TypeCompiler::run(TypeSpecifierAST *node) +{ + _M_type.clear(); + _M_cv.clear(); + + visit(node); + + if (node && node->cv) + { + const ListNode<std::size_t> *it = node->cv->toFront(); + const ListNode<std::size_t> *end = it; + do + { + int kind = _M_token_stream->kind(it->element); + if (! _M_cv.contains(kind)) + _M_cv.append(kind); + + it = it->next; + } + while (it != end); + } +} + +void TypeCompiler::visitClassSpecifier(ClassSpecifierAST *node) +{ + visit(node->name); +} + +void TypeCompiler::visitEnumSpecifier(EnumSpecifierAST *node) +{ + visit(node->name); +} + +void TypeCompiler::visitElaboratedTypeSpecifier(ElaboratedTypeSpecifierAST *node) +{ + visit(node->name); +} + +void TypeCompiler::visitSimpleTypeSpecifier(SimpleTypeSpecifierAST *node) +{ + if (const ListNode<std::size_t> *it = node->integrals) + { + it = it->toFront(); + const ListNode<std::size_t> *end = it; + QString current_item; + do + { + std::size_t token = it->element; + current_item += token_name(_M_token_stream->kind(token)); + current_item += " "; + it = it->next; + } + while (it != end); + if (!_M_type.isEmpty()) + _M_type += QLatin1String("::"); + _M_type += current_item.trimmed(); + } + else if (node->type_of) + { + // ### implement me + + if (!_M_type.isEmpty()) + _M_type += QLatin1String("::"); + _M_type += QLatin1String("typeof<...>"); + } + + visit(node->name); +} + +void TypeCompiler::visitName(NameAST *node) +{ + NameCompiler name_cc(_M_binder); + name_cc.run(node); + _M_type = name_cc.qualifiedName(); +} + +QStringList TypeCompiler::cvString() const +{ + QStringList lst; + + foreach (int q, cv()) + { + if (q == Token_const) + lst.append(QLatin1String("const")); + else if (q == Token_volatile) + lst.append(QLatin1String("volatile")); + } + + return lst; +} + +bool TypeCompiler::isConstant() const +{ + return _M_cv.contains(Token_const); +} + +bool TypeCompiler::isVolatile() const +{ + return _M_cv.contains(Token_volatile); +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/codemodel/type_compiler.h b/tests/manual/cppmodelmanager/codemodel/type_compiler.h new file mode 100644 index 00000000000..43231354e01 --- /dev/null +++ b/tests/manual/cppmodelmanager/codemodel/type_compiler.h @@ -0,0 +1,95 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* This file is part of KDevelop + Copyright (C) 2002-2005 Roberto Raggi <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef TYPE_COMPILER_H +#define TYPE_COMPILER_H + +#include "default_visitor.h" + +#include <QtCore/QString> +#include <QtCore/QStringList> +#include <QtCore/QList> + +class TokenStream; +class Binder; + +class TypeCompiler: protected DefaultVisitor +{ +public: + TypeCompiler(Binder *binder); + + inline QString qualifiedName() const { return _M_type; } + inline QList<int> cv() const { return _M_cv; } + + bool isConstant() const; + bool isVolatile() const; + + QStringList cvString() const; + + void run(TypeSpecifierAST *node); + +protected: + virtual void visitClassSpecifier(ClassSpecifierAST *node); + virtual void visitEnumSpecifier(EnumSpecifierAST *node); + virtual void visitElaboratedTypeSpecifier(ElaboratedTypeSpecifierAST *node); + virtual void visitSimpleTypeSpecifier(SimpleTypeSpecifierAST *node); + + virtual void visitName(NameAST *node); + +private: + Binder *_M_binder; + TokenStream *_M_token_stream; + QString _M_type; + QList<int> _M_cv; +}; + +#endif // TYPE_COMPILER_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/cppcodemodel.cpp b/tests/manual/cppmodelmanager/cppcodemodel.cpp new file mode 100644 index 00000000000..cdfbb6a9960 --- /dev/null +++ b/tests/manual/cppmodelmanager/cppcodemodel.cpp @@ -0,0 +1,204 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include <QtCore/QFile> +#include <QtCore/QDir> +#include <QtCore/QDebug> + +#include "cppcodemodelitems.h" +#include "cpppartparser.h" +#include "cppcodemodel.h" +#include "cppcodemodelpart.h" + +CppCodeModel::CppCodeModel(const QByteArray &configuration, QObject *parent) + : QObject(parent) +{ + m_configuration = configuration; + m_parsefiles << QLatin1String("<configfile>"); +} + +CppCodeModel::~CppCodeModel() +{ + +} + +void CppCodeModel::addIncludePath(const QString &path) +{ + QString newpath = QDir::cleanPath(path); + if (m_includedirs.contains(newpath)) + return; + + m_includedirs.insert(newpath, new CppCodeModelPart(newpath, this)); +} + +void CppCodeModel::removeIncludePath(const QString &path) +{ + QString newpath = QDir::cleanPath(path + QLatin1Char('/')); + if (!m_includedirs.contains(newpath)) + return; + + delete m_includedirs.take(newpath); +} + +void CppCodeModel::update(const QStringList &files) +{ + m_parsefiles += m_parsefiles.fromList(files); + + CppPartParser *parser = CppPartParser::instance(parent()); + parser->parse(this); +} + +QStringList CppCodeModel::needsParsing() +{ + QStringList result = m_parsefiles.toList(); + + if (m_parsefiles.contains(QLatin1String("<configfile>"))) + result.prepend(QLatin1String("<configfile>")); + + m_parsefiles.clear(); + return result; +} + +void CppCodeModel::resolvePart(const QString &abspath, CppCodeModelPart **part) const +{ + int length = 0; + + QMap<QString, CppCodeModelPart *>::const_iterator i = m_includedirs.constBegin(); + while (i != m_includedirs.constEnd()) { + if (abspath.startsWith(i.key()) && i.key().count() > length) { + length = i.key().count(); + (*part) = i.value(); + } + ++i; + } +} + +void CppCodeModel::resolveGlobalPath(QString &file, CppCodeModelPart **part) const +{ + QString abspath; + + (*part) = 0; + QMap<QString, CppCodeModelPart *>::const_iterator i = m_includedirs.constBegin(); + while (i != m_includedirs.constEnd()) { + abspath = i.key() + QLatin1Char('/') + file; + QFileInfo fi(abspath); + if (fi.exists() && fi.isFile()) { + (*part) = i.value(); + break; + } + ++i; + } + + if (*part) + file = QDir::cleanPath(abspath); +} + +void CppCodeModel::resolveLocalPath(QString &file, const QString &local, CppCodeModelPart **part) const +{ + (*part) = m_partcache.value(local, 0); + QFileInfo fi(local); + file = QDir::cleanPath(fi.absolutePath() + QLatin1Char('/') + file); +} + +QByteArray *CppCodeModel::contents(QString &file, const QString &local) +{ + CppCodeModelPart *part = 0; + + if (file == QLatin1String("<configfile>")) + return new QByteArray(m_configuration); + + if (local.isEmpty()) { + resolveGlobalPath(file, &part); + if (!m_partcache.contains(file)) { + resolvePart(file, &part); + m_partcache.insert(file, part); + } else { + part = m_partcache.value(file, 0); + } + } else { + resolveLocalPath(file, local, &part); + m_partcache.insert(file, part); + } + + if (!part) { + qDebug() << "Didn't find: " << file; + return 0; + } + + return part->contents(file); +} + +QHash<QString, pp_macro*> *CppCodeModel::macros() +{ + return &m_macros; +} + +void CppCodeModel::store() +{ + QMap<QString, CppFileModelItem *>::const_iterator i = m_fileitems.constBegin(); + while (i != m_fileitems.constEnd()) { + if (CppCodeModelPart *part = m_partcache.value(i.key())) + part->store(i.value()); + ++i; + } + + m_partcache.clear(); + m_fileitems.clear(); +} + +CppFileModelItem *CppCodeModel::fileItem(const QString &name) +{ + if (!m_partcache.contains(name)) + return 0; + + if (m_fileitems.contains(name)) + return m_fileitems.value(name); + + CppFileModelItem *item = new CppFileModelItem(this); + item->setPart(m_partcache.value(name)); + item->setName(name); + item->setFile(item); + m_fileitems.insert(name, item); + return item; +} + +bool CppCodeModel::hasScope(const QString &name) const +{ + QMap<QString, CppCodeModelPart *>::const_iterator i = m_includedirs.constBegin(); + while (i != m_includedirs.constEnd()) { + if (i.value()->hasScope(name)) + return true; + ++i; + } + return false; +} + diff --git a/tests/manual/cppmodelmanager/cppcodemodel.h b/tests/manual/cppmodelmanager/cppcodemodel.h new file mode 100644 index 00000000000..7f591b17e4f --- /dev/null +++ b/tests/manual/cppmodelmanager/cppcodemodel.h @@ -0,0 +1,94 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef CPPCODEMODEL_H +#define CPPCODEMODEL_H + +#include <QtCore/QObject> +#include <QtCore/QHash> +#include <QtCore/QMap> +#include <QtCore/QSet> +#include <QtCore/QStringList> + +#include "cppcodemodelitems.h" + +class pp_macro; +class CppCodeModelPart; +class CppPartParser; +class CppPartPP; + +class CppCodeModel : public QObject, + public CodeModel +{ + Q_OBJECT + +public: + CppCodeModel(const QByteArray &configuration, QObject *parent = 0); + ~CppCodeModel(); + + void addIncludePath(const QString &path); + void removeIncludePath(const QString &path); + + void update(const QStringList &files); + +protected: + // returns the macros for this part + QStringList needsParsing(); + QHash<QString, pp_macro*> *macros(); + QByteArray *contents(QString &file, const QString &local = QString()); + void store(); + + void resolvePart(const QString &abspath, CppCodeModelPart **part) const; + void resolveGlobalPath(QString &file, CppCodeModelPart **part) const; + void resolveLocalPath(QString &file, const QString &local, CppCodeModelPart **part) const; + + // used by the parser + CppFileModelItem *fileItem(const QString &name); + bool hasScope(const QString &name) const; + +private: + QMap<QString, CppCodeModelPart *> m_partcache; + QMap<QString, CppFileModelItem *> m_fileitems; + QMap<QString, CppCodeModelPart *> m_includedirs; + + QByteArray m_configuration; + QSet<QString> m_parsefiles; + QHash<QString, pp_macro*> m_macros; + + friend class Binder; + friend class CodeModelFinder; + friend class CppPartParser; + friend class CppPartPP; +}; +DECLARE_LANGUAGE_CODEMODEL(Cpp) + +#endif // CPPCODEMODELPART_H diff --git a/tests/manual/cppmodelmanager/cppcodemodelitems.cpp b/tests/manual/cppmodelmanager/cppcodemodelitems.cpp new file mode 100644 index 00000000000..cb8aac652bd --- /dev/null +++ b/tests/manual/cppmodelmanager/cppcodemodelitems.cpp @@ -0,0 +1,122 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +/* This file is part of KDevelop +Copyright (C) 2002-2005 Roberto Raggi <[email protected]> +Copyright (C) 2005 Trolltech AS + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License version 2 as published by the Free Software Foundation. + +This library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#include <QtCore/QHash> +#include "cppcodemodelitems.h" +#include "cppcodemodel.h" + +CppClassModelItem::CppClassModelItem(CppCodeModel *model) + : ClassModelItem(model) { } + +CppFileModelItem::CppFileModelItem(CppCodeModel *model) + : FileModelItem(model) +{ + +} + +CppFileModelItem::~CppFileModelItem() +{ + qDeleteAll(_M_externalscopes.values()); +} + +void CppFileModelItem::setPart(CppCodeModelPart *part) +{ + _M_part = part; +} + +CppCodeModelPart *CppFileModelItem::part() const +{ + return _M_part; +} + +ScopeModelItem *CppFileModelItem::findExternalScope(const QString &name) const +{ + return _M_externalscopes.value(name, 0); +} + +void CppFileModelItem::addExternalScope(ScopeModelItem *item) +{ + _M_externalscopes.insert(item->qualifiedName(), item); +} + +QList<ScopeModelItem* > CppFileModelItem::externalScopes() const +{ + return _M_externalscopes.values(); +} + +CppArgumentModelItem::CppArgumentModelItem(CppCodeModel *model) +: ArgumentModelItem(model) { } + +CppFunctionDefinitionModelItem::CppFunctionDefinitionModelItem(CppCodeModel *model) +: FunctionDefinitionModelItem(model) { } + +CppVariableModelItem::CppVariableModelItem(CppCodeModel *model) +: VariableModelItem(model) { } + +CppTypeAliasModelItem::CppTypeAliasModelItem(CppCodeModel *model) +: TypeAliasModelItem(model) { } + +CppEnumModelItem::CppEnumModelItem(CppCodeModel *model) +: EnumModelItem(model) { } + +CppEnumeratorModelItem::CppEnumeratorModelItem(CppCodeModel *model) +: EnumeratorModelItem(model) { } + +CppTemplateParameterModelItem::CppTemplateParameterModelItem(CppCodeModel *model) +: TemplateParameterModelItem(model) { } + +CppTemplateParameterModelItem::CppTemplateParameterModelItem(const CppTemplateParameterModelItem &item) +: TemplateParameterModelItem(item) { } + +// kate: space-indent on; indent-width 2; replace-tabs on; + diff --git a/tests/manual/cppmodelmanager/cppcodemodelitems.h b/tests/manual/cppmodelmanager/cppcodemodelitems.h new file mode 100644 index 00000000000..7d80363abb5 --- /dev/null +++ b/tests/manual/cppmodelmanager/cppcodemodelitems.h @@ -0,0 +1,138 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +/* This file is part of KDevelop +Copyright (C) 2002-2005 Roberto Raggi <[email protected]> +Copyright (C) 2005 Trolltech AS + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License version 2 as published by the Free Software Foundation. + +This library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#ifndef CPPCODEMODELITEMS_H +#define CPPCODEMODELITEMS_H + +class CppCodeModel; +class CppCodeModelPart; +#include "codemodel/codemodelitems.h" + +class CppClassModelItem: public ClassModelItem +{ +public: + CppClassModelItem(CppCodeModel *model); +}; + +class CppFileModelItem: public FileModelItem +{ +public: + CppFileModelItem(CppCodeModel *model); + ~CppFileModelItem(); + + void setPart(CppCodeModelPart *part); + CppCodeModelPart *part() const; + + ScopeModelItem *findExternalScope(const QString &name) const; + void addExternalScope(ScopeModelItem *item); + QList<ScopeModelItem *> externalScopes() const; + +private: + QHash<QString, ScopeModelItem *> _M_externalscopes; + CppCodeModelPart *_M_part; +}; +DECLARE_LANGUAGE_MODELITEM(File, Cpp) + +class CppArgumentModelItem: public ArgumentModelItem +{ +public: + CppArgumentModelItem(CppCodeModel *model); +}; +DECLARE_LANGUAGE_MODELITEM(Argument, Cpp) + +class CppFunctionDefinitionModelItem : public FunctionDefinitionModelItem +{ +public: + CppFunctionDefinitionModelItem(CppCodeModel *model); +}; +DECLARE_LANGUAGE_MODELITEM(FunctionDefinition, Cpp) + +class CppVariableModelItem : public VariableModelItem +{ +public: + CppVariableModelItem(CppCodeModel *model); +}; +DECLARE_LANGUAGE_MODELITEM(Variable, Cpp) + +class CppTypeAliasModelItem : public TypeAliasModelItem +{ +public: + CppTypeAliasModelItem(CppCodeModel *model); +}; +DECLARE_LANGUAGE_MODELITEM(TypeAlias, Cpp) + +class CppEnumModelItem : public EnumModelItem +{ +public: + CppEnumModelItem(CppCodeModel *model); +}; +DECLARE_LANGUAGE_MODELITEM(Enum, Cpp) + +class CppEnumeratorModelItem : public EnumeratorModelItem +{ +public: + CppEnumeratorModelItem(CppCodeModel *model); +}; +DECLARE_LANGUAGE_MODELITEM(Enumerator, Cpp) + +class CppTemplateParameterModelItem : public TemplateParameterModelItem +{ +public: + CppTemplateParameterModelItem(CppCodeModel *model); + CppTemplateParameterModelItem(const CppTemplateParameterModelItem &item); +}; +DECLARE_LANGUAGE_MODELITEM(TemplateParameter, Cpp) + +#endif //CPPCODEMODELITEMS_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/tests/manual/cppmodelmanager/cppcodemodelpart.cpp b/tests/manual/cppmodelmanager/cppcodemodelpart.cpp new file mode 100644 index 00000000000..ae95cd444d1 --- /dev/null +++ b/tests/manual/cppmodelmanager/cppcodemodelpart.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include <QtCore/QFile> +#include <QtCore/QDir> +#include <QtCore/QFileInfoList> +#include <QtCore/QFileInfo> +#include <QtCore/QDebug> + +#include "cppcodemodelpart.h" +#include "cpppartparser.h" +#include "cppcodemodelitems.h" + +CppCodeModelPart::CppCodeModelPart(const QString &path, QObject *parent) + : QObject(parent) +{ + m_path = path; +} + +CppCodeModelPart::~CppCodeModelPart() +{ + +} + +QString CppCodeModelPart::path() const +{ + return m_path; +} + +void CppCodeModelPart::update() +{ + +} + +QByteArray *CppCodeModelPart::contents(const QString &file) +{ + QByteArray *result = new QByteArray(); + if (!m_files.contains(file)) { + m_files.insert(file); + QFile f(file); + if (!f.open(QIODevice::ReadOnly)) + return 0; + (*result) = f.readAll(); + f.close(); + } + + return result; +} + +void CppCodeModelPart::store(CppFileModelItem *item) +{ + qDebug() << "Deleting: " << item->name(); + delete item; +} + +bool CppCodeModelPart::hasScope(const QString &name) const +{ + // ### implement me + return true; +} diff --git a/tests/manual/cppmodelmanager/cppcodemodelpart.h b/tests/manual/cppmodelmanager/cppcodemodelpart.h new file mode 100644 index 00000000000..89a973b751e --- /dev/null +++ b/tests/manual/cppmodelmanager/cppcodemodelpart.h @@ -0,0 +1,75 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef CPPCODEMODELPART_H +#define CPPCODEMODELPART_H + +#include <QtCore/QObject> +#include <QtCore/QHash> +#include <QtCore/QSet> +#include <QtCore/QStringList> + +class CppCodeModel; +class CppFileModelItem; + +class CppCodeModelPart : public QObject +{ + Q_OBJECT + +public: + CppCodeModelPart(const QString &path, QObject *parent = 0); + ~CppCodeModelPart(); + + QString path() const; + void update(); + +protected: + // returns true if the given qualified name is known + bool hasScope(const QString &name) const; + + // returns the contents of the file, this may be + // the current content of an open editor + // the byte array is deleted when no longer needed + QByteArray *contents(const QString &file); + + // stores/replaces the parsed code model in the + // database or memory + void store(CppFileModelItem *item); + +private: + QString m_path; + QSet<QString> m_files; + + friend class CppCodeModel; +}; + +#endif // CPPCODEMODELPART_H diff --git a/tests/manual/cppmodelmanager/cppmodelmanager.pro b/tests/manual/cppmodelmanager/cppmodelmanager.pro new file mode 100644 index 00000000000..714cc6c6a02 --- /dev/null +++ b/tests/manual/cppmodelmanager/cppmodelmanager.pro @@ -0,0 +1,62 @@ +# ##################################################################### +# Automatically generated by qmake (2.01a) ma 24. apr 11:14:33 2006 +# ##################################################################### +TEMPLATE = app +TARGET = +QT += sql +DEPENDPATH += . +INCLUDEPATH += . \ + codemodel +include(../../../../cppparser/rxx.pri)|error("Can't find RXX") +include(rpp/rpp.pri) +SOURCES -= $$RXXPATH/codemodel.cpp \ + $$RXXPATH/binder.cpp \ + $$RXXPATH/codemodel_finder.cpp \ + $$RXXPATH/compiler_utils.cpp \ + $$RXXPATH/declarator_compiler.cpp \ + $$RXXPATH/name_compiler.cpp \ + $$RXXPATH/class_compiler.cpp \ + $$RXXPATH/type_compiler.cpp + +HEADERS -= $$RXXPATH/codemodel.h \ + $$RXXPATH/binder.h \ + $$RXXPATH/codemodel_finder.h \ + $$RXXPATH/compiler_utils.h \ + $$RXXPATH/declarator_compiler.h \ + $$RXXPATH/name_compiler.h \ + $$RXXPATH/class_compiler.h \ + $$RXXPATH/type_compiler.h \ + $$RXXPATH/codemodel_fwd.h + +SOURCES += codemodel/codemodelitems.cpp \ + codemodel/binder.cpp \ + codemodel/codemodel_finder.cpp \ + codemodel/compiler_utils.cpp \ + codemodel/declarator_compiler.cpp \ + codemodel/name_compiler.cpp \ + codemodel/class_compiler.cpp \ + codemodel/type_compiler.cpp + +HEADERS += codemodel/codemodelitems.h \ + codemodel/binder.h \ + codemodel/codemodel_finder.h \ + codemodel/compiler_utils.h \ + codemodel/declarator_compiler.h \ + codemodel/name_compiler.h \ + codemodel/class_compiler.h \ + codemodel/type_compiler.h + +# Input +SOURCES += main.cpp \ + dbcodemodel.cpp \ + cppcodemodel.cpp \ + cppcodemodelitems.cpp \ + cppcodemodelpart.cpp \ + cpppartparser.cpp +HEADERS += dbcodemodel.h \ + cppcodemodelpart.h \ + cppcodemodel.h \ + cppcodemodelitems.h \ + cpppartparser.h + +CONFIG += console diff --git a/tests/manual/cppmodelmanager/cpppartparser.cpp b/tests/manual/cppmodelmanager/cpppartparser.cpp new file mode 100644 index 00000000000..5fa3ae38472 --- /dev/null +++ b/tests/manual/cppmodelmanager/cpppartparser.cpp @@ -0,0 +1,204 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include <QtCore/QDebug> + +#include "cpppartparser.h" +#include "cppcodemodel.h" + +#include "preprocessor.h" +#include "pp-stream.h" +#include "pp-engine.h" + +#include "parser.h" +#include "control.h" + +#include "binder.h" + +CppPartParser *CppPartParser::m_instance = 0; + +// **************************** +// CppStream +// **************************** + +class CppStream : public Stream +{ +public: + CppStream(QByteArray *array); + virtual ~CppStream(); + +private: + QByteArray *m_array; +}; + +CppStream::CppStream(QByteArray *array) + : Stream(array) +{ + m_array = array; +} + +CppStream::~CppStream() +{ + delete m_array; +} + +// **************************** +// CppPartPP +// **************************** + +class CppPartPP : private Preprocessor +{ +public: + QByteArray process(QString &fileName, CppCodeModel *model); + +protected: + Stream* sourceNeeded(QString& fileName, IncludeType type); + +private: + CppCodeModel *m_model; + pp *m_proc; +}; + +QByteArray CppPartPP::process(QString &fileName, CppCodeModel *model) +{ + QByteArray result; + + m_model = model; + pp proc(this, (*model->macros())); + m_proc = &proc; + if (QByteArray *contents = m_model->contents(fileName)) { + result = proc.processFile(*(contents), fileName); + delete contents; + } + + return result; +} + +Stream* CppPartPP::sourceNeeded(QString& fileName, IncludeType type) +{ + QString localfile; + if (type == IncludeLocal) + localfile = m_proc->currentfile(); + + QByteArray *contents = m_model->contents(fileName, localfile); + if (!contents) + return 0; + + return new CppStream(contents); +} + +// **************************** +// CppPartParser +// **************************** + +CppPartParser::CppPartParser(QObject *parent) + : QThread(parent) +{ + m_cppPartPP = new CppPartPP(); + + m_cancelParsing = false; + m_currentModel = 0; +} + +CppPartParser::~CppPartParser() +{ + delete m_cppPartPP; +} + +CppPartParser *CppPartParser::instance(QObject *parent) +{ + if (!m_instance) + m_instance = new CppPartParser(parent); + + return m_instance; +} + +void CppPartParser::parse(CppCodeModel *model) +{ + mutex.lock(); + if (!m_modelQueue.contains(model)) + m_modelQueue.enqueue(model); + mutex.unlock(); + + if (!isRunning()) { + m_cancelParsing = false; + start(); + setPriority(QThread::LowPriority); + } +} + +void CppPartParser::remove(CppCodeModel *model) +{ + mutex.lock(); + if (m_modelQueue.contains(model)) + m_modelQueue.removeAll(model); + + if (m_currentModel == model) { + m_cancelParsing = true; + mutex.unlock(); + wait(); + m_cancelParsing = false; + start(); + setPriority(QThread::LowPriority); + } else { + mutex.unlock(); + } +} + +void CppPartParser::run() +{ + while (!m_cancelParsing && !m_modelQueue.isEmpty()) { + mutex.lock(); + m_currentModel = m_modelQueue.dequeue(); + mutex.unlock(); + + QStringList files = m_currentModel->needsParsing(); + for (int i=0; i<files.count() && !m_cancelParsing; ++i) { + QString resolvedName = files.at(i); + QByteArray ppcontent = m_cppPartPP->process( + resolvedName, m_currentModel); + + Control control; + Parser p(&control); + pool __pool; + + TranslationUnitAST *ast = p.parse(ppcontent, ppcontent.size(), &__pool); + qDebug() << p.problemCount(); + + Binder binder(m_currentModel, p.location()); + binder.run(ast, resolvedName); + + m_currentModel->store(); + } + } +} + diff --git a/tests/manual/cppmodelmanager/cpppartparser.h b/tests/manual/cppmodelmanager/cpppartparser.h new file mode 100644 index 00000000000..0d5790a210e --- /dev/null +++ b/tests/manual/cppmodelmanager/cpppartparser.h @@ -0,0 +1,72 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef CPPPARTPARSER_H +#define CPPPARTPARSER_H + +#include <QtCore/QThread> +#include <QtCore/QMutex> +#include <QtCore/QQueue> + +class CppPartPP; +class CppCodeModel; + +class CppPartParser : public QThread +{ + Q_OBJECT + +public: + ~CppPartParser(); + + static CppPartParser *instance(QObject *parent = 0); + void parse(CppCodeModel *model); + void remove(CppCodeModel *model); + +protected: + void run(); + CppPartParser(QObject *parent = 0); + +private: + QMutex mutex; + + bool m_cancelParsing; + CppCodeModel *m_currentModel; + + QQueue<CppCodeModel *> m_modelQueue; + + static CppPartParser *m_instance; + + CppPartPP *m_cppPartPP; + friend class CppPartPP; +}; + +#endif //CPPPARTPARSER_H diff --git a/tests/manual/cppmodelmanager/dbcodemodel.cpp b/tests/manual/cppmodelmanager/dbcodemodel.cpp new file mode 100644 index 00000000000..a9abfd83b72 --- /dev/null +++ b/tests/manual/cppmodelmanager/dbcodemodel.cpp @@ -0,0 +1,147 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include <QtCore/QFile> + +#include "dbcodemodel.h" + +DBCodeModel::DBCodeModel(QObject *parent) + : QObject(parent) +{ + +} + +DBCodeModel::~DBCodeModel() +{ + +} + +bool DBCodeModel::open(const QString &fileName) +{ + m_db = QSqlDatabase::addDatabase("QSQLITE", fileName); + + if (!QFile::exists(fileName)) { + m_db.setDatabaseName(fileName); + if (!m_db.open() || !create()) + return false; + } else { + m_db.setDatabaseName(fileName); + if (!m_db.open()) // || !update(fileName)) + return false; + } + + return true; +} + +bool DBCodeModel::create() +{ + QSqlQuery query(m_db); + + // table to store type information + query.exec("CREATE TABLE TYPEINFO (" + "id INTEGER PRIMARY KEY, " + "typename TEXT, " + "typeflags INTEGER, " + ")"); + + // table to store position information + query.exec("CREATE TABLE POSITION (" + "id INTEGER PRIMARY KEY, " + "sline INTEGER, " + "scolumn INTEGER, " + "eline INTEGER, " + "ecolumn INTEGER" + ")"); + + // table to store files (global namespace), namespaces, unions, structs and classes + query.exec("CREATE TABLE SCOPE (" + "id INTEGER PRIMARY KEY, " + "scopetype INTEGER, " + "name TEXT, " + "parent INTEGER, " + "posid INTEGER, " + "fileid INTEGER" + ")"); + + // table to store scope member information + // a scope member is a enum, function, variable or typealias + query.exec("CREATE TABLE SCOPEMEMBER (" + "id INTEGER PRIMARY KEY, " + "membertype INTEGER, " + "name TEXT, " + "scopeid INTEGER, " + "flags INTEGER, " + "typeid INTEGER, " + "posid INTEGER, " + "fileid INTEGER" + ")"); + + // table to store arguments + // used if the membertype is a function + query.exec("CREATE TABLE ARGUMENT (" + "name TEXT, " + "default TEXT, " + "argnr INTEGER, " + "typeid INTEGER, " + "memberid INTEGER" + ")"); + + // table to store enumerators + // used if the membertype is an enum + query.exec("CREATE TABLE ENUMERATOR (" + "name TEXT, " + "value INTEGER, " + "memberid INTEGER" + ")"); + + // table to store arguments to types + // used if typeflags indicates that it has arguments (i.e. function pointers) + query.exec("CREATE TABLE TYPEARGUMENT (" + "parentid INTEGER, " + "argnr INTEGER, " + "typeid INTEGER" + ")"); + + // table to store the class hierarchy + query.exec("CREATE TABLE CLASSHIERARCHY (" + "scopeid INTEGER, " + "basename TEXT" + ")"); + + // table to store all the modified timestamps used + // for updating the database + query.exec("CREATE TABLE MODIFIED (" + "fileid INTEGER, " + "modified INTEGER)"); + + return true; +} diff --git a/tests/manual/cppmodelmanager/dbcodemodel.h b/tests/manual/cppmodelmanager/dbcodemodel.h new file mode 100644 index 00000000000..479fde86564 --- /dev/null +++ b/tests/manual/cppmodelmanager/dbcodemodel.h @@ -0,0 +1,55 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef DBCODEMODEL_H +#define DBCODEMODEL_H + +#include <QtSql> + +class DBCodeModel : public QObject +{ + Q_OBJECT + +public: + DBCodeModel(QObject *parent = 0); + ~DBCodeModel(); + + bool open(const QString &fileName); + +protected: + bool create(); + +private: + QSqlDatabase m_db; +}; + +#endif // DBCODEMODEL_H diff --git a/tests/manual/cppmodelmanager/main.cpp b/tests/manual/cppmodelmanager/main.cpp new file mode 100644 index 00000000000..da826641364 --- /dev/null +++ b/tests/manual/cppmodelmanager/main.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include <QtCore> + +#include "cppcodemodel.h" +#include "preprocessor.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + QFile f("C:\\depot\\research\\main\\cppparser\\rpp\\pp-qt-configuration"); + f.open(QIODevice::ReadOnly); + CppCodeModel model(f.readAll()); + f.close(); + + model.addIncludePath("C:\\depot\\qt\\4.1\\include\\"); + model.addIncludePath("C:\\depot\\qt\\4.1\\include\\QtCore"); + model.addIncludePath("C:\\depot\\qt\\4.1\\include\\QtGui"); + +/* model.addIncludePath("C:\\depot\\research\\main\\qworkbench\\tests\\manual\\cppmodelmanager\\tests"); */ + model.update(QStringList() << "qwidget.h"); + +// return app.exec(); + return 0; + +/* Preprocessor pp; + pp.addIncludePaths(QStringList() << "C:/depot/qt/4.1/include/QtCore/"); + pp.processFile("C:/depot/research/main/cppparser/rpp/pp-qt-configuration"); + QString ppstuff = pp.processFile("test.h"); + + + Control control; + Parser p(&control); + pool __pool; + + QByteArray byteArray = ppstuff.toUtf8(); + TranslationUnitAST *ast = p.parse(byteArray, byteArray.size(), &__pool); + qDebug() << p.problemCount(); + + CodeModel model; + Binder binder(&model, p.location()); + FileModelItem fileModel = binder.run(ast); + + qDebug() << "Count: " << model.files().count(); */ + +/* DBCodeModel db; + db.open("c:/bin/test.cdb"); */ + + +} diff --git a/tests/manual/cppmodelmanager/rpp/pp-engine.cpp b/tests/manual/cppmodelmanager/rpp/pp-engine.cpp new file mode 100644 index 00000000000..cef2b082926 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-engine.cpp @@ -0,0 +1,1117 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Roberto Raggi <[email protected]> + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "pp-engine.h" + +#include <QFile> + +#include <QtCore/QDebug> + +#include "pp-internal.h" +#include "preprocessor.h" + +pp::pp(Preprocessor* preprocessor, QHash<QString, pp_macro*>& environment) + : m_environment(environment) + , expand(this) + , m_preprocessor(preprocessor) + , nextToken(0) + , haveNextToken(false) + , hideNext(false) +{ + iflevel = 0; + _M_skipping[iflevel] = 0; + _M_true_test[iflevel] = 0; +} + +QList<pp::ErrorMessage> pp::errorMessages () const +{ + return _M_error_messages; +} + +void pp::clearErrorMessages () +{ + _M_error_messages.clear (); +} + +void pp::reportError (const QString &fileName, int line, int column, const QString &message) +{ + ErrorMessage msg; + msg.setFileName (fileName); + msg.setLine (line); + msg.setColumn (column); + msg.setMessage (message); + + _M_error_messages.append (msg); +} + +QString pp::processFile(const QString& filename) +{ + QFile file(filename); + if (file.open(QIODevice::ReadOnly)) + { + m_files.push(filename); + + Stream is(&file); + QString result; + + { + Stream rs(&result); + operator () (is, rs); + } + + return result; + } + + qWarning() << "file '" << filename << "' not found!" << endl; + return QString(); +} + +QString pp::processFile(QIODevice* device) +{ + Q_ASSERT(device); + + QString result; + m_files.push("<internal>"); + + { + Stream is(device); + Stream rs(&result); + operator () (is, rs); + } + + return result; +} + +QString pp::processFile(const QByteArray& input) +{ + QString result; + m_files.push("<internal>"); + + { + Stream is(input); + Stream rs(&result); + operator () (is, rs); + } + + return result; +} + +QByteArray pp::processFile(const QByteArray& input, const QString &fileName) +{ + QByteArray result; + m_files.push(fileName); + + { + Stream is(input); + Stream rs(&result); + operator () (is, rs); + } + + return result; +} + +QString pp::find_header_protection(Stream& input) +{ + while (!input.atEnd()) + { + if (input.current().isSpace()) + { + ++input; + } + else if (PPInternal::isComment(input)) + { + skip_comment_or_divop (input, PPInternal::devnull()); + } + else if (input == '#') + { + skip_blanks (++input, PPInternal::devnull()); + + if (!input.atEnd() && input == 'i') + { + QString directive = skip_identifier(input); + + if (directive == "ifndef") + { + skip_blanks (input, PPInternal::devnull()); + + QString define = skip_identifier(input); + + if (!define.isEmpty() && !input.atEnd()) + { + input.reset(); + return define; + } + } + } + break; + + } else { + break; + } + } + + input.reset(); + return QString(); +} + +pp::PP_DIRECTIVE_TYPE pp::find_directive (const QString& directive) const +{ + static QHash<QString, PP_DIRECTIVE_TYPE> directiveHash; + if (directiveHash.isEmpty()) { + directiveHash.insert("if", PP_IF); + directiveHash.insert("elif", PP_ELIF); + directiveHash.insert("else", PP_ELSE); + directiveHash.insert("ifdef", PP_IFDEF); + directiveHash.insert("undef", PP_UNDEF); + directiveHash.insert("endif", PP_ENDIF); + directiveHash.insert("ifndef", PP_IFNDEF); + directiveHash.insert("define", PP_DEFINE); + directiveHash.insert("include", PP_INCLUDE); + } + + if (directiveHash.contains(directive)) + return directiveHash[directive]; + + return PP_UNKNOWN_DIRECTIVE; +} + +void pp::handle_directive(const QString& directive, Stream& input, Stream& output) +{ + skip_blanks (input, output); + + switch (find_directive(directive)) + { + case PP_DEFINE: + if (! skipping ()) + return handle_define(input); + break; + + case PP_INCLUDE: + if (! skipping ()) + return handle_include (input, output); + break; + + case PP_UNDEF: + if (! skipping ()) + return handle_undef(input); + break; + + case PP_ELIF: + return handle_elif(input); + + case PP_ELSE: + return handle_else(); + + case PP_ENDIF: + return handle_endif(); + + case PP_IF: + return handle_if(input); + + case PP_IFDEF: + return handle_ifdef(false, input); + + case PP_IFNDEF: + return handle_ifdef(true, input); + + default: + break; + } +} + +void pp::handle_include(Stream& input, Stream& output) +{ + Q_ASSERT(input == '<' || input == '"'); + QChar quote((input == '"') ? '"' : '>'); + ++input; + + QString includeName; + + while (!input.atEnd() && input != quote) { + Q_ASSERT(input != '\n'); + + includeName.append(input); + ++input; + } + + Stream* include = m_preprocessor->sourceNeeded(includeName, + quote == '"' ? Preprocessor::IncludeLocal : Preprocessor::IncludeGlobal); + if (include && !include->atEnd()) { + m_files.push(includeName); + + output.mark(includeName, 0); + + operator()(*include, output); + + // restore the file name and sync the buffer + m_files.pop(); + output.mark(m_files.top(), input.inputLineNumber()); + } + + delete include; +} + +void pp::operator () (Stream& input, Stream& output) +{ +#ifndef PP_NO_SMART_HEADER_PROTECTION + QString headerDefine = find_header_protection(input); + if (m_environment.contains(headerDefine)) + { + //kDebug() << k_funcinfo << "found header protection: " << headerDefine << endl; + return; + } +#endif + + forever + { + if (skipping()) { + skip_blanks(input, PPInternal::devnull()); + + } else { + skip_blanks(input, output); + } + + if (input.atEnd()) { + break; + + } else if (input == '#') { + skip_blanks(++input, PPInternal::devnull()); + + QString directive = skip_identifier(input); + + Q_ASSERT(directive.length() < 512); + + skip_blanks(input, PPInternal::devnull()); + + QString skipped; + { + Stream ss(&skipped); + skip (input, ss); + } + + Stream ss(&skipped); + handle_directive(directive, ss, output); + + } else if (input == '\n') { + checkMarkNeeded(input, output); + output << input; + ++input; + + } else if (skipping ()) { + skip (input, PPInternal::devnull()); + + } else { + checkMarkNeeded(input, output); + expand (input, output); + } + } +} + +void pp::checkMarkNeeded(Stream& input, Stream& output) +{ + if (input.inputLineNumber() != output.outputLineNumber() && !output.isNull()) + output.mark(m_files.top(), input.inputLineNumber()); +} + +void pp::handle_define (Stream& input) +{ + pp_macro* macro = new pp_macro(); +#if defined (PP_WITH_MACRO_POSITION) + macro->file = m_files.top(); +#endif + QString definition; + + skip_blanks (input, PPInternal::devnull()); + QString macro_name = skip_identifier(input); + + if (!input.atEnd() && input == '(') + { + macro->function_like = true; + + skip_blanks (++input, PPInternal::devnull()); // skip '(' + QString formal = skip_identifier(input); + if (!formal.isEmpty()) + macro->formals << formal; + + skip_blanks(input, PPInternal::devnull()); + + if (input == '.') { + macro->variadics = true; + + do { + ++input; + + } while (input == '.'); + } + + while (!input.atEnd() && input == ',') + { + skip_blanks(++input, PPInternal::devnull()); + + QString formal = skip_identifier(input); + if (!formal.isEmpty()) + macro->formals << formal; + + skip_blanks (input, PPInternal::devnull()); + + if (input == '.') { + macro->variadics = true; + + do { + ++input; + + } while (input == '.'); + } + } + + Q_ASSERT(input == ')'); + ++input; + } + + skip_blanks (input, PPInternal::devnull()); + + while (!input.atEnd() && input != '\n') + { + if (input == '\\') + { + qint64 pos = input.pos(); + skip_blanks (++input, PPInternal::devnull()); + + if (!input.atEnd() && input == '\n') + { + ++macro->lines; + skip_blanks(++input, PPInternal::devnull()); + definition += ' '; + continue; + + } else { + // Whoops, rewind :) + input.seek(pos); + } + } + + definition += input; + ++input; + } + + macro->definition = definition; + + if (pp_macro* replacemacro = m_environment.value(macro_name, 0)) + delete replacemacro; + + m_environment.insert(macro_name, macro); +} + + +void pp::skip (Stream& input, Stream& output, bool outputText) +{ + pp_skip_string_literal skip_string_literal; + pp_skip_char_literal skip_char_literal; + + while (!input.atEnd() && input != '\n') + { + if (input == '/') + { + skip_comment_or_divop (input, output, outputText); + } + else if (input == '"') + { + skip_string_literal (input, output); + } + else if (input == '\'') + { + skip_char_literal (input, output); + } + else if (input == '\\') + { + output << input; + skip_blanks (++input, output); + + if (!input.atEnd() && input == '\n') + { + output << input; + ++input; + } + } + else + { + output << input; + ++input; + } + } +} + +inline bool pp::test_if_level() +{ + bool result = !_M_skipping[iflevel++]; + _M_skipping[iflevel] = _M_skipping[iflevel - 1]; + _M_true_test[iflevel] = false; + return result; +} + +inline int pp::skipping() const +{ return _M_skipping[iflevel]; } + + +long pp::eval_primary(Stream& input) +{ + bool expect_paren = false; + int token = next_token_accept(input); + long result = 0; + + switch (token) { + case TOKEN_NUMBER: + return token_value; + + case TOKEN_DEFINED: + token = next_token_accept(input); + + if (token == '(') + { + expect_paren = true; + token = next_token_accept(input); + } + + if (token != TOKEN_IDENTIFIER) + { + qWarning() << "expected ``identifier'' found:" << token << endl; + break; + } + + result = m_environment.contains(token_text); + + token = next_token(input); // skip '(' + + if (expect_paren) { + token = next_token(input); + + if (token != ')') + qWarning() << "expected ``)''" << endl; + else + accept_token(); + } + break; + + case TOKEN_IDENTIFIER: + break; + + case '!': + return !eval_primary(input); + + case '(': + result = eval_constant_expression(input); + token = next_token(input); + + if (token != ')') + qWarning() << "expected ``)'' = " << token << endl; + else + accept_token(); + + break; + + default: + break; + } + + return result; +} + +long pp::eval_multiplicative(Stream& input) +{ + long result = eval_primary(input); + + int token = next_token(input); + + while (token == '*' || token == '/' || token == '%') { + accept_token(); + + long value = eval_primary(input); + + if (token == '*') { + result *= value; + + } else if (token == '/') { + if (value == 0) { + qWarning() << "division by zero" << endl; + result = 0; + + } else { + result = result / value; + } + + } else { + if (value == 0) { + qWarning() << "division by zero" << endl; + result = 0; + + } else { + result %= value; + } + } + + token = next_token(input); + } + + return result; +} + +long pp::eval_additive(Stream& input) +{ + long result = eval_multiplicative(input); + + int token = next_token(input); + + while (token == '+' || token == '-') { + accept_token(); + + long value = eval_multiplicative(input); + + if (token == '+') + result += value; + else + result -= value; + + token = next_token(input); + } + + return result; +} + + +long pp::eval_shift(Stream& input) +{ + long result = eval_additive(input); + + int token; + token = next_token(input); + + while (token == TOKEN_LT_LT || token == TOKEN_GT_GT) { + accept_token(); + + long value = eval_additive(input); + + if (token == TOKEN_LT_LT) + result <<= value; + else + result >>= value; + + token = next_token(input); + } + + return result; +} + + +long pp::eval_relational(Stream& input) +{ + long result = eval_shift(input); + + int token = next_token(input); + + while (token == '<' + || token == '>' + || token == TOKEN_LT_EQ + || token == TOKEN_GT_EQ) + { + accept_token(); + long value = eval_shift(input); + + switch (token) + { + default: + Q_ASSERT(0); + break; + + case '<': + result = result < value; + break; + + case '>': + result = result < value; + break; + + case TOKEN_LT_EQ: + result = result <= value; + break; + + case TOKEN_GT_EQ: + result = result >= value; + break; + } + + token = next_token(input); + } + + return result; +} + + +long pp::eval_equality(Stream& input) +{ + long result = eval_relational(input); + + int token = next_token(input); + + while (token == TOKEN_EQ_EQ || token == TOKEN_NOT_EQ) { + accept_token(); + long value = eval_relational(input); + + if (token == TOKEN_EQ_EQ) + result = result == value; + else + result = result != value; + + token = next_token(input); + } + + return result; +} + + +long pp::eval_and(Stream& input) +{ + long result = eval_equality(input); + + int token = next_token(input); + + while (token == '&') { + accept_token(); + long value = eval_equality(input); + result = result & value; + token = next_token(input); + } + + return result; +} + + +long pp::eval_xor(Stream& input) +{ + long result = eval_and(input); + + int token; + token = next_token(input); + + while (token == '^') { + accept_token(); + long value = eval_and(input); + result = result ^ value; + token = next_token(input); + } + + return result; +} + + +long pp::eval_or(Stream& input) +{ + long result = eval_xor(input); + + int token = next_token(input); + + while (token == '|') { + accept_token(); + long value = eval_xor(input); + result = result | value; + token = next_token(input); + } + + return result; +} + + +long pp::eval_logical_and(Stream& input) +{ + long result = eval_or(input); + + int token = next_token(input); + + while (token == TOKEN_AND_AND) { + accept_token(); + long value = eval_or(input); + result = result && value; + token = next_token(input); + } + + return result; +} + + +long pp::eval_logical_or(Stream& input) +{ + long result = eval_logical_and(input); + + int token = next_token(input); + + while (token == TOKEN_OR_OR) { + accept_token(); + long value = eval_logical_and(input); + result = result || value; + token = next_token(input); + } + + return result; +} + + +long pp::eval_constant_expression(Stream& input) +{ + long result = eval_logical_or(input); + + int token = next_token(input); + + if (token == '?') + { + accept_token(); + long left_value = eval_constant_expression(input); + skip_blanks(input, PPInternal::devnull()); + + token = next_token_accept(input); + if (token == ':') + { + long right_value = eval_constant_expression(input); + + result = result ? left_value : right_value; + } + else + { + qWarning() << "expected ``:'' = " << int (token) << endl; + result = left_value; + } + } + + return result; +} + + +long pp::eval_expression(Stream& input) +{ + skip_blanks(input, PPInternal::devnull()); + return eval_constant_expression(input); +} + + +void pp::handle_if (Stream& input) +{ + if (test_if_level()) + { + pp_macro_expander expand_condition(this); + skip_blanks(input, PPInternal::devnull()); + QString condition; + { + Stream cs(&condition); + expand_condition(input, cs); + } + + Stream cs(&condition); + long result = eval_expression(cs); + + _M_true_test[iflevel] = result; + _M_skipping[iflevel] = !result; + } +} + + +void pp::handle_else() +{ + if (iflevel == 0 && !skipping ()) + { + qWarning() << "#else without #if" << endl; + } + else if (iflevel > 0 && _M_skipping[iflevel - 1]) + { + _M_skipping[iflevel] = true; + } + else + { + _M_skipping[iflevel] = _M_true_test[iflevel]; + } +} + + +void pp::handle_elif(Stream& input) +{ + Q_ASSERT(iflevel > 0); + + if (iflevel == 0 && !skipping()) + { + qWarning() << "#else without #if" << endl; + } + else if (!_M_true_test[iflevel] && !_M_skipping[iflevel - 1]) + { + long result = eval_expression(input); + _M_true_test[iflevel] = result; + _M_skipping[iflevel] = !result; + } + else + { + _M_skipping[iflevel] = true; + } +} + + +void pp::handle_endif() +{ + if (iflevel == 0 && !skipping()) + { + qWarning() << "#endif without #if" << endl; + } + else + { + _M_skipping[iflevel] = 0; + _M_true_test[iflevel] = 0; + + --iflevel; + } +} + + +void pp::handle_ifdef (bool check_undefined, Stream& input) +{ + if (test_if_level()) + { + QString macro_name = skip_identifier(input); + bool value = m_environment.contains(macro_name); + + if (check_undefined) + value = !value; + + _M_true_test[iflevel] = value; + _M_skipping[iflevel] = !value; + } +} + + +void pp::handle_undef(Stream& input) +{ + skip_blanks (input, PPInternal::devnull()); + + QString macro_name = skip_identifier(input); + Q_ASSERT(!macro_name.isEmpty()); + + delete m_environment.take(macro_name); +} + +int pp::next_token (Stream& input) +{ + if (haveNextToken) + return nextToken; + + skip_blanks(input, PPInternal::devnull()); + + if (input.atEnd()) + { + return 0; + } + + char ch = input.current().toLatin1(); + char ch2 = input.peek().toLatin1(); + + nextToken = 0; + + switch (ch) { + case '/': + if (ch2 == '/' || ch2 == '*') + { + skip_comment_or_divop(input, PPInternal::devnull(), false); + return next_token(input); + } + ++input; + nextToken = '/'; + break; + + case '<': + ++input; + if (ch2 == '<') + { + ++input; + nextToken = TOKEN_LT_LT; + } + else if (ch2 == '=') + { + ++input; + nextToken = TOKEN_LT_EQ; + } + else + nextToken = '<'; + + break; + + case '>': + ++input; + if (ch2 == '>') + { + ++input; + nextToken = TOKEN_GT_GT; + } + else if (ch2 == '=') + { + ++input; + nextToken = TOKEN_GT_EQ; + } + else + nextToken = '>'; + + break; + + case '!': + ++input; + if (ch2 == '=') + { + ++input; + nextToken = TOKEN_NOT_EQ; + } + else + nextToken = '!'; + + break; + + case '=': + ++input; + if (ch2 == '=') + { + ++input; + nextToken = TOKEN_EQ_EQ; + } + else + nextToken = '='; + + break; + + case '|': + ++input; + if (ch2 == '|') + { + ++input; + nextToken = TOKEN_OR_OR; + } + else + nextToken = '|'; + + break; + + case '&': + ++input; + if (ch2 == '&') + { + ++input; + nextToken = TOKEN_AND_AND; + } + else + nextToken = '&'; + + break; + + default: + if (QChar(ch).isLetter() || ch == '_') + { + token_text = skip_identifier (input); + + if (token_text == "defined") + nextToken = TOKEN_DEFINED; + else + nextToken = TOKEN_IDENTIFIER; + } + else if (QChar(ch).isNumber()) + { + QString number; + { + Stream ns(&number); + skip_number(input, ns); + } + token_value = number.toLong(); + + nextToken = TOKEN_NUMBER; + } + else + { + nextToken = input.current().toLatin1(); + ++input; + } + } + + //kDebug() << "Next token '" << ch << ch2 << "' " << nextToken << " txt " << token_text << " val " << token_value << endl; + + haveNextToken = true; + return nextToken; +} + +int pp::next_token_accept (Stream& input) +{ + int result = next_token(input); + accept_token(); + return result; +} + +void pp::accept_token() +{ + haveNextToken = false; + nextToken = 0; +} + +bool pp::hideNextMacro( ) const +{ + return hideNext; +} + +void pp::setHideNextMacro( bool h ) +{ + hideNext = h; +} + +QHash< QString, pp_macro * > & pp::environment( ) +{ + return m_environment; +} + +// kate: indent-width 2; diff --git a/tests/manual/cppmodelmanager/rpp/pp-engine.h b/tests/manual/cppmodelmanager/rpp/pp-engine.h new file mode 100644 index 00000000000..446b08a8703 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-engine.h @@ -0,0 +1,232 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Roberto Raggi <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef PP_ENGINE_H +#define PP_ENGINE_H + +#include <QHash> +#include <QString> +#include <QStack> + +#include "pp-macro.h" +#include "pp-macro-expander.h" +#include "pp-scanner.h" + +class Preprocessor; + +class pp +{ + QHash<QString, pp_macro*>& m_environment; + pp_macro_expander expand; + pp_skip_identifier skip_identifier; + pp_skip_comment_or_divop skip_comment_or_divop; + pp_skip_blanks skip_blanks; + pp_skip_number skip_number; + QStack<QString> m_files; + Preprocessor* m_preprocessor; + + class ErrorMessage + { + int _M_line; + int _M_column; + QString _M_fileName; + QString _M_message; + + public: + ErrorMessage (): + _M_line (0), + _M_column (0) {} + + inline int line () const { return _M_line; } + inline void setLine (int line) { _M_line = line; } + + inline int column () const { return _M_column; } + inline void setColumn (int column) { _M_column = column; } + + inline QString fileName () const { return _M_fileName; } + inline void setFileName (const QString &fileName) { _M_fileName = fileName; } + + inline QString message () const { return _M_message; } + inline void setMessage (const QString &message) { _M_message = message; } + }; + + QList<ErrorMessage> _M_error_messages; + + enum { MAX_LEVEL = 512 }; + int _M_skipping[MAX_LEVEL]; + int _M_true_test[MAX_LEVEL]; + int iflevel; + int nextToken; + bool haveNextToken; + bool hideNext; + + long token_value; + QString token_text; + + enum TOKEN_TYPE + { + TOKEN_NUMBER = 1000, + TOKEN_IDENTIFIER, + TOKEN_DEFINED, + TOKEN_LT_LT, + TOKEN_LT_EQ, + TOKEN_GT_GT, + TOKEN_GT_EQ, + TOKEN_EQ_EQ, + TOKEN_NOT_EQ, + TOKEN_OR_OR, + TOKEN_AND_AND, + }; + + enum PP_DIRECTIVE_TYPE + { + PP_UNKNOWN_DIRECTIVE, + PP_DEFINE, + PP_INCLUDE, + PP_ELIF, + PP_ELSE, + PP_ENDIF, + PP_IF, + PP_IFDEF, + PP_IFNDEF, + PP_UNDEF + }; + +public: + pp(Preprocessor* preprocessor, QHash<QString, pp_macro*>& environment); + + QList<ErrorMessage> errorMessages () const; + void clearErrorMessages (); + + void reportError (const QString &fileName, int line, int column, const QString &message); + + long eval_expression (Stream& input); + + QString processFile(const QString& filename); + QString processFile(QIODevice* input); + QString processFile(const QByteArray& input); + QByteArray processFile(const QByteArray& input, const QString &fileName); + + inline QString currentfile() const { + return m_files.top(); + } + + void operator () (Stream& input, Stream& output); + + void checkMarkNeeded(Stream& input, Stream& output); + + bool hideNextMacro() const; + void setHideNextMacro(bool hideNext); + + QHash<QString, pp_macro*>& environment(); + +private: + int skipping() const; + bool test_if_level(); + + PP_DIRECTIVE_TYPE find_directive (const QString& directive) const; + + QString find_header_protection(Stream& input); + + void skip(Stream& input, Stream& output, bool outputText = true); + + long eval_primary(Stream& input); + + long eval_multiplicative(Stream& input); + + long eval_additive(Stream& input); + + long eval_shift(Stream& input); + + long eval_relational(Stream& input); + + long eval_equality(Stream& input); + + long eval_and(Stream& input); + + long eval_xor(Stream& input); + + long eval_or(Stream& input); + + long eval_logical_and(Stream& input); + + long eval_logical_or(Stream& input); + + long eval_constant_expression(Stream& input); + + void handle_directive(const QString& directive, Stream& input, Stream& output); + + void handle_include(Stream& input, Stream& output); + + void handle_define(Stream& input); + + void handle_if(Stream& input); + + void handle_else(); + + void handle_elif(Stream& input); + + void handle_endif(); + + void handle_ifdef(bool check_undefined, Stream& input); + + void handle_undef(Stream& input); + + int next_token (Stream& input); + int next_token_accept (Stream& input); + void accept_token(); +}; + +#endif // PP_ENGINE_H + +// kate: indent-width 2; + diff --git a/tests/manual/cppmodelmanager/rpp/pp-internal.cpp b/tests/manual/cppmodelmanager/rpp/pp-internal.cpp new file mode 100644 index 00000000000..c427d006b11 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-internal.cpp @@ -0,0 +1,68 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Roberto Raggi <[email protected]> + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "pp-internal.h" + +bool PPInternal::isComment(Stream& input) +{ + QChar c1 = input; + QChar c2 = input.peek(); + + return c1 == '/' && (c2 == '/' || c2 == '*'); +} + +Stream& PPInternal::devnull() +{ + static Stream null; + return null; +} diff --git a/tests/manual/cppmodelmanager/rpp/pp-internal.h b/tests/manual/cppmodelmanager/rpp/pp-internal.h new file mode 100644 index 00000000000..4be1f6ce5d4 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-internal.h @@ -0,0 +1,69 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Roberto Raggi <[email protected]> + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef PP_INTERNAL_H +#define PP_INTERNAL_H + +#include "pp-stream.h" + +namespace PPInternal +{ + +bool isComment(Stream& input); + +Stream& devnull(); + +} +// _PP_internal + +#endif // PP_INTERNAL_H diff --git a/tests/manual/cppmodelmanager/rpp/pp-macro-expander.cpp b/tests/manual/cppmodelmanager/rpp/pp-macro-expander.cpp new file mode 100644 index 00000000000..032bf365931 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-macro-expander.cpp @@ -0,0 +1,287 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Roberto Raggi <[email protected]> + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "pp-macro-expander.h" + +#include <QtCore/QDebug> + +#include "pp-internal.h" +#include "pp-engine.h" + +pp_frame::pp_frame(pp_macro* __expandingMacro, const QList<QString>& __actuals) + : expandingMacro(__expandingMacro) + , actuals(__actuals) +{ +} + +QString pp_macro_expander::resolve_formal(const QString& name) +{ + Q_ASSERT(!name.isEmpty()); + + if (!m_frame) + return QString(); + + Q_ASSERT(m_frame->expandingMacro != 0); + + const QStringList& formals = m_frame->expandingMacro->formals; + + for (int index = 0; index < formals.size(); ++index) { + if (name == formals[index]) { + if (index < m_frame->actuals.size()) + return m_frame->actuals[index]; + else + Q_ASSERT(0); // internal error? + } + } + + return QString(); +} + +pp_macro_expander::pp_macro_expander(pp* engine, pp_frame* frame) + : m_engine(engine) + , m_frame(frame) +{ +} + +void pp_macro_expander::operator()(Stream& input, Stream& output) +{ + skip_blanks(input, output); + + while (!input.atEnd()) + { + if (input == '\n') + { + output << input; + + skip_blanks(++input, output); + + if (!input.atEnd() && input == '#') + break; + } + else if (input == '#') + { + skip_blanks(++input, output); + + QString identifier = skip_identifier(input); + output << '\"'; + + Stream is(&identifier); + operator()(is, output); + + output << '\"'; + } + else if (input == '\"') + { + skip_string_literal(input, output); + } + else if (input == '\'') + { + skip_char_literal(input, output); + } + else if (PPInternal::isComment(input)) + { + skip_comment_or_divop(input, output); + } + else if (input.current().isSpace()) + { + do { + if (input == '\n' || !input.current().isSpace()) + break; + + } while (!(++input).atEnd()); + + output << ' '; + } + else if (input.current().isNumber()) + { + skip_number (input, output); + } + else if (input.current().isLetter() || input == '_') + { + QString name = skip_identifier (input); + + // search for the paste token + qint64 blankStart = input.pos(); + skip_blanks (input, PPInternal::devnull()); + if (!input.atEnd() && input == '#') { + ++input; + + if (!input.atEnd() && input == '#') + skip_blanks(++input, PPInternal::devnull()); + else + input.seek(blankStart); + + } else { + input.seek(blankStart); + } + + Q_ASSERT(name.length() >= 0 && name.length() < 512); + + QString actual = resolve_formal(name); + if (!actual.isEmpty()) { + output << actual; + continue; + } + + pp_macro* macro = m_engine->environment().value(name, 0); + if (! macro || macro->hidden || m_engine->hideNextMacro()) + { + m_engine->setHideNextMacro(name == "defined"); + output << name; + continue; + } + + if (!macro->function_like) + { + pp_macro_expander expand_macro(m_engine); + macro->hidden = true; + Stream ms(¯o->definition, QIODevice::ReadOnly); + expand_macro(ms, output); + macro->hidden = false; + continue; + } + + // function like macro + if (input.atEnd() || input != '(') + { + output << name; + continue; + } + + QList<QString> actuals; + ++input; // skip '(' + + pp_macro_expander expand_actual(m_engine, m_frame); + + qint64 before = input.pos(); + { + actual.clear(); + + { + Stream as(&actual); + skip_argument_variadics(actuals, macro, input, as); + } + + if (input.pos() != before) + { + QString newActual; + { + Stream as(&actual); + Stream nas(&newActual); + expand_actual(as, nas); + } + actuals.append(newActual); + } + } + + // TODO: why separate from the above? + while (!input.atEnd() && input == ',') + { + actual.clear(); + ++input; // skip ',' + + { + { + Stream as(&actual); + skip_argument_variadics(actuals, macro, input, as); + } + + QString newActual; + { + Stream as(&actual); + Stream nas(&newActual); + expand_actual(as, nas); + } + actuals.append(newActual); + } + } + + //Q_ASSERT(!input.atEnd() && input == ')'); + + ++input; // skip ')' + +#if 0 // ### enable me + assert ((macro->variadics && macro->formals.size () >= actuals.size ()) + || macro->formals.size() == actuals.size()); +#endif + + pp_frame frame(macro, actuals); + pp_macro_expander expand_macro(m_engine, &frame); + macro->hidden = true; + Stream ms(¯o->definition, QIODevice::ReadOnly); + expand_macro(ms, output); + macro->hidden = false; + + } else { + output << input; + ++input; + } + } +} + +void pp_macro_expander::skip_argument_variadics (const QList<QString>& __actuals, pp_macro *__macro, Stream& input, Stream& output) +{ + qint64 first; + + do { + first = input.pos(); + skip_argument(input, output); + + } while ( __macro->variadics + && first != input.pos() + && !input.atEnd() + && input == '.' + && (__actuals.size() + 1) == __macro->formals.size()); +} + +// kate: indent-width 2; diff --git a/tests/manual/cppmodelmanager/rpp/pp-macro-expander.h b/tests/manual/cppmodelmanager/rpp/pp-macro-expander.h new file mode 100644 index 00000000000..933fc90b391 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-macro-expander.h @@ -0,0 +1,105 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Roberto Raggi <[email protected]> + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef PP_MACRO_EXPANDER_H +#define PP_MACRO_EXPANDER_H + +#include <QList> +#include <QHash> +#include <QString> + +#include "pp-macro.h" +#include "pp-stream.h" +#include "pp-scanner.h" + +class pp; + +class pp_frame +{ +public: + pp_frame (pp_macro* __expandingMacro, const QList<QString>& __actuals); + + pp_macro* expandingMacro; + QList<QString> actuals; +}; + +class pp_macro_expander +{ +public: + pp_macro_expander(pp* engine, pp_frame* frame = 0); + + QString resolve_formal(const QString& name); + + /// Expands text with the known macros. Continues until it finds a new text line + /// beginning with #, at which point control is returned. + void operator()(Stream& input, Stream& output); + + void skip_argument_variadics (const QList<QString>& __actuals, pp_macro *__macro, + Stream& input, Stream& output); + +private: + pp* m_engine; + pp_frame* m_frame; + + pp_skip_number skip_number; + pp_skip_identifier skip_identifier; + pp_skip_string_literal skip_string_literal; + pp_skip_char_literal skip_char_literal; + pp_skip_argument skip_argument; + pp_skip_comment_or_divop skip_comment_or_divop; + pp_skip_blanks skip_blanks; +}; + +#endif // PP_MACRO_EXPANDER_H + +// kate: indent-width 2; diff --git a/tests/manual/cppmodelmanager/rpp/pp-macro.cpp b/tests/manual/cppmodelmanager/rpp/pp-macro.cpp new file mode 100644 index 00000000000..397f3df19b3 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-macro.cpp @@ -0,0 +1,62 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Roberto Raggi <[email protected]> + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "pp-macro.h" + +pp_macro::pp_macro( ) + : lines(0) + , hidden(false) + , function_like(false) + , variadics(false) +{ +} diff --git a/tests/manual/cppmodelmanager/rpp/pp-macro.h b/tests/manual/cppmodelmanager/rpp/pp-macro.h new file mode 100644 index 00000000000..9d3d4cdd261 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-macro.h @@ -0,0 +1,78 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Roberto Raggi <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef PP_MACRO_H +#define PP_MACRO_H + +#include <QStringList> + +class pp_macro +{ +public: + pp_macro(); + + QString definition; +#if defined (PP_WITH_MACRO_POSITION) + QString file; +#endif + QStringList formals; + + int lines; + + bool hidden: 1; + bool function_like: 1; + bool variadics: 1; +}; + +#endif // PP_MACRO_H + +// kate: indent-width 2; diff --git a/tests/manual/cppmodelmanager/rpp/pp-scanner.cpp b/tests/manual/cppmodelmanager/rpp/pp-scanner.cpp new file mode 100644 index 00000000000..d851ede3070 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-scanner.cpp @@ -0,0 +1,289 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Roberto Raggi <[email protected]> + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include <QtCore/QDebug> +#include "pp-scanner.h" + +void pp_skip_blanks::operator()(Stream& input, Stream& output) +{ + while (!input.atEnd()) { + if (input == '\\') { + ++input; + if (input != '\n') { + --input; + return; + + } else { + ++input; + continue; + } + } + + if (input == '\n' || !input.current().isSpace()) + return; + + output << input; + ++input; + } +} + +void pp_skip_comment_or_divop::operator()(Stream& input, Stream& output, bool outputText) +{ + enum { + MAYBE_BEGIN, + BEGIN, + MAYBE_END, + END, + IN_COMMENT, + IN_CXX_COMMENT + } state (MAYBE_BEGIN); + + while (!input.atEnd()) { + switch (state) { + case MAYBE_BEGIN: + if (input != '/') + return; + + state = BEGIN; + break; + + case BEGIN: + if (input == '*') + state = IN_COMMENT; + else if (input == '/') + state = IN_CXX_COMMENT; + else + return; + break; + + case IN_COMMENT: + if (input == '*') + state = MAYBE_END; + break; + + case IN_CXX_COMMENT: + if (input == '\n') + return; + break; + + case MAYBE_END: + if (input == '/') + state = END; + else if (input != '*') + state = IN_COMMENT; + break; + + case END: + return; + } + + if (outputText) + output << input; + else if (input == '\n') + output << '\n'; + else + output << ' '; + ++input; + } +} + +QString pp_skip_identifier::operator()(Stream& input) +{ + QString identifier; + + while (!input.atEnd()) { + if (!input.current().isLetterOrNumber() && input != '_') + break; + + identifier.append(input); + ++input; + } + + return identifier; +} + +void pp_skip_number::operator()(Stream& input, Stream& output) +{ + while (!input.atEnd()) { + if (!input.current().isLetterOrNumber() && input != '_') + return; + + output << input; + ++input; + } +} + +void pp_skip_string_literal::operator()(Stream& input, Stream& output) +{ + enum { + BEGIN, + IN_STRING, + QUOTE, + END + } state (BEGIN); + + while (!input.atEnd()) { + switch (state) { + case BEGIN: + if (input != '\"') + return; + state = IN_STRING; + break; + + case IN_STRING: + Q_ASSERT(input != '\n'); + + if (input == '\"') + state = END; + else if (input == '\\') + state = QUOTE; + break; + + case QUOTE: + state = IN_STRING; + break; + + case END: + return; + } + + output << input; + ++input; + } +} + +void pp_skip_char_literal::operator()(Stream& input, Stream& output) +{ + enum { + BEGIN, + IN_STRING, + QUOTE, + END + } state (BEGIN); + + while (!input.atEnd()) { + if (state == END) + break; + + switch (state) { + case BEGIN: + if (input != '\'') + return; + state = IN_STRING; + break; + + case IN_STRING: + Q_ASSERT(input != '\n'); + + if (input == '\'') + state = END; + else if (input == '\\') + state = QUOTE; + break; + + case QUOTE: + state = IN_STRING; + break; + + default: + Q_ASSERT(0); + break; + } + + output << input; + ++input; + } +} + +void pp_skip_argument::operator()(Stream& input, Stream& output) +{ + int depth = 0; + + while (!input.atEnd()) { + if (!depth && (input == ')' || input == ',')) { + return; + + } else if (input == '(') { + ++depth; + + } else if (input == ')') { + --depth; + + } else if (input == '\"') { + skip_string_literal(input, output); + continue; + + } else if (input == '\'') { + skip_char_literal (input, output); + continue; + + } else if (input == '/') { + skip_comment_or_divop (input, output); + continue; + + } else if (input.current().isLetter() || input == '_') { + output << skip_identifier(input); + continue; + + } else if (input.current().isNumber()) { + output << skip_number(input); + continue; + + } + + output << input; + ++input; + } + + return; +} diff --git a/tests/manual/cppmodelmanager/rpp/pp-scanner.h b/tests/manual/cppmodelmanager/rpp/pp-scanner.h new file mode 100644 index 00000000000..2941a19b74b --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-scanner.h @@ -0,0 +1,119 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Roberto Raggi <[email protected]> + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef PP_SCANNER_H +#define PP_SCANNER_H + +#include <QString> + +#include "pp-stream.h" + +class pp_skip_blanks +{ +public: + void operator()(Stream& input, Stream& output); +}; + +class pp_skip_comment_or_divop +{ +public: + /** + * This scanner can either output equivalent blank space, + * or the actual text (the default). + */ + void operator()(Stream& input, Stream& output, bool outputText = false); + +private: + bool m_outputText; +}; + +class pp_skip_identifier +{ +public: + QString operator()(Stream& input); +}; + +class pp_skip_number +{ +public: + void operator()(Stream& input, Stream& output); +}; + +class pp_skip_string_literal +{ +public: + void operator()(Stream& input, Stream& output); +}; + +class pp_skip_char_literal +{ +public: + void operator()(Stream& input, Stream& output); +}; + +class pp_skip_argument +{ +public: + void operator()(Stream& input, Stream& output); + +private: + pp_skip_identifier skip_number; + pp_skip_identifier skip_identifier; + pp_skip_string_literal skip_string_literal; + pp_skip_char_literal skip_char_literal; + pp_skip_comment_or_divop skip_comment_or_divop; +}; + +#endif // PP_SCANNER_H + +// kate: indent-width 2; diff --git a/tests/manual/cppmodelmanager/rpp/pp-stream.cpp b/tests/manual/cppmodelmanager/rpp/pp-stream.cpp new file mode 100644 index 00000000000..91d483db39f --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-stream.cpp @@ -0,0 +1,266 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "pp-stream.h" + +#include <QtCore/QDebug> + +class DevNullDevice : public QIODevice +{ +protected: + virtual qint64 readData ( char *, qint64 ) { return 0; } + virtual qint64 writeData ( const char *, qint64 maxSize ) { return maxSize; } +}; + +Stream::Stream() + : QTextStream(new DevNullDevice) + , m_atEnd(false) + , m_isNull(true) + , m_pos(0) + , m_inputLine(0) + , m_outputLine(0) +{ +} + +Stream::Stream( const QByteArray & array, QIODevice::OpenMode openMode ) + : QTextStream(array, openMode) + , m_atEnd(!array.count()) + , m_isNull(false) + , m_pos(0) + , m_inputLine(0) + , m_outputLine(0) +{ + operator>>(c); + //kDebug() << "'" << c << "' " << c.cell() << endl; +} + +Stream::Stream( QByteArray * array, QIODevice::OpenMode openMode ) + : QTextStream(array, openMode) + , m_atEnd(!array->count()) + , m_isNull(false) + , m_pos(0) + , m_inputLine(0) + , m_outputLine(0) +{ + operator>>(c); + //kDebug() << "'" << c << "' " << c.cell() << endl; +} + +Stream::Stream( QString * string, QIODevice::OpenMode openMode ) + : QTextStream(string, openMode) + , m_atEnd(!string->count()) + , m_isNull(false) + , m_pos(0) + , m_inputLine(0) + , m_outputLine(0) +{ + operator>>(c); + //if (!string->isEmpty()) + //kDebug() << "'" << c << "' " << c.cell() << endl; +} + +Stream::Stream( FILE * fileHandle, QIODevice::OpenMode openMode ) + : QTextStream(fileHandle, openMode) + , m_atEnd(false) + , m_isNull(false) + , m_pos(0) + , m_inputLine(0) + , m_outputLine(0) +{ + operator>>(c); + //kDebug() << "'" << c << "' " << c.cell() << endl; +} + +Stream::Stream( QIODevice * device ) + : QTextStream(device) + , m_atEnd(false) + , m_isNull(false) + , m_pos(0) + , m_inputLine(0) + , m_outputLine(0) +{ + operator>>(c); + //kDebug() << "'" << c << "' " << c.cell() << endl; +} + +Stream::~Stream() +{ + if (isNull()) + delete device(); +} + +Stream & Stream::operator ++( ) +{ + if (m_atEnd) + return *this; + + if (c == '\n') + ++m_inputLine; + + if (QTextStream::atEnd()) { + m_atEnd = true; + ++m_pos; + c = QChar(); + + } else { + operator>>(c); + //kDebug() << "'" << c << "' " << c.cell() << endl; + ++m_pos; + } + return *this; +} + +Stream& Stream::operator--() +{ + seek(pos() - 2); + operator>>(c); + --m_pos; + return *this; +} + +void Stream::rewind(qint64 offset) +{ + seek(pos() - offset); +} + +bool Stream::atEnd() const +{ + return m_atEnd; +} + +QChar Stream::peek() const +{ + Stream* s = const_cast<Stream*>(this); + int inputLine = m_inputLine; + ++(*s); + QChar ret = s->current(); + s->rewind(); + inputLine = m_inputLine; + return ret; +} + +qint64 Stream::pos( ) const +{ + return m_pos; +} + +void Stream::seek(qint64 offset) +{ + if (QTextStream::seek(offset)) { + m_pos = offset; + if (QTextStream::atEnd()) { + m_atEnd = true; + } else { + operator>>(c); + m_atEnd = false; + } + } +} + +Stream& Stream::operator<< ( QChar c ) +{ + if (!isNull()) { + if (c == '\n') { + ++m_outputLine; + //output.clear(); + } else { + //output += c; + } + QTextStream::operator<<(c); + } + return *this; +} + +Stream& Stream::operator<< ( const QString & string ) +{ + if (!isNull()) { + m_outputLine += string.count('\n'); + //output += c; + QTextStream::operator<<(string); + } + return *this; +} + +int Stream::outputLineNumber() const +{ + return m_outputLine; +} + +bool Stream::isNull() const +{ + return m_isNull; +} + +int Stream::inputLineNumber() const +{ + return m_inputLine; +} + +void Stream::setOutputLineNumber(int line) +{ + m_outputLine = line; +} + +void Stream::mark(const QString& filename, int inputLineNumber) +{ + QTextStream::operator<<(QString("# %1 \"%2\"\n").arg(inputLineNumber).arg(filename.isEmpty() ? QString("<internal>") : filename)); + setOutputLineNumber(inputLineNumber); +} + +void Stream::reset( ) +{ + QTextStream::seek(0); + m_inputLine = m_outputLine = m_pos = 0; + //output.clear(); + m_atEnd = false; + operator>>(c); +} diff --git a/tests/manual/cppmodelmanager/rpp/pp-stream.h b/tests/manual/cppmodelmanager/rpp/pp-stream.h new file mode 100644 index 00000000000..03ba7dbf521 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/pp-stream.h @@ -0,0 +1,118 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef STREAM_H +#define STREAM_H + +#include <QTextStream> + +/** + * Stream designed for character-at-a-time processing + * + * @author Hamish Rodda <[email protected]> + */ +class Stream : private QTextStream +{ + public: + Stream(); + Stream( QIODevice * device ); + Stream( FILE * fileHandle, QIODevice::OpenMode openMode = QIODevice::ReadWrite ); + Stream( QString * string, QIODevice::OpenMode openMode = QIODevice::ReadWrite ); + Stream( QByteArray * array, QIODevice::OpenMode openMode = QIODevice::ReadWrite ); + Stream( const QByteArray & array, QIODevice::OpenMode openMode = QIODevice::ReadOnly ); + ~Stream(); + + bool isNull() const; + + bool atEnd() const; + + qint64 pos() const; + + QChar peek() const; + + /// Move back \a offset chars in the stream + void rewind(qint64 offset = 1); + + /// \warning the input and output lines are not updated when calling this function. + /// if you're seek()ing over a line boundary, you'll need to fix the line + /// numbers. + void seek(qint64 offset); + + /// Start from the beginning again + void reset(); + + inline const QChar& current() const { return c; } + inline operator const QChar&() const { return c; } + Stream& operator++(); + Stream& operator--(); + + int inputLineNumber() const; + + int outputLineNumber() const; + void setOutputLineNumber(int line); + void mark(const QString& filename, int inputLineNumber); + + Stream & operator<< ( QChar c ); + Stream & operator<< ( const QString & string ); + + private: + Q_DISABLE_COPY(Stream) + + QChar c; + bool m_atEnd; + bool m_isNull; + qint64 m_pos; + int m_inputLine, m_outputLine; + //QString output; +}; + +#endif diff --git a/tests/manual/cppmodelmanager/rpp/preprocessor.cpp b/tests/manual/cppmodelmanager/rpp/preprocessor.cpp new file mode 100644 index 00000000000..8d3301396a5 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/preprocessor.cpp @@ -0,0 +1,161 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Harald Fernengel <[email protected]> + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "preprocessor.h" + +#include <QFile> + +#include <QtCore/QDir> +#include <QtCore/QDebug> +#include <QtCore/QFileInfo> + +#include "pp-stream.h" +#include "pp-engine.h" + +class PreprocessorPrivate +{ +public: + QString result; + QHash<QString, pp_macro*> env; + QStringList includePaths; +}; + +QHash<QString, QStringList> includedFiles; + +Preprocessor::Preprocessor() +{ + d = new PreprocessorPrivate; + includedFiles.clear(); +} + +Preprocessor::~Preprocessor() +{ + qDeleteAll(d->env); + delete d; +} + +QString Preprocessor::processFile(const QString& fileName) +{ + pp proc(this, d->env); + + return proc.processFile(fileName); +} + +QString Preprocessor::processString(const QByteArray &bytearray) +{ + pp proc(this, d->env); + + return proc.processFile(bytearray); +} + +void Preprocessor::addIncludePaths(const QStringList &includePaths) +{ + d->includePaths += includePaths; +} + +QStringList Preprocessor::macroNames() const +{ + return d->env.keys(); +} + +QList<Preprocessor::MacroItem> Preprocessor::macros() const +{ + QList<MacroItem> items; + + QHashIterator<QString, pp_macro*> it = d->env; + while (it.hasNext()) { + it.next(); + + MacroItem item; + item.name = it.key(); + item.definition = it.value()->definition; + item.parameters = it.value()->formals; + item.isFunctionLike = it.value()->function_like; + +#ifdef PP_WITH_MACRO_POSITION + item.fileName = it.value()->file; +#endif + items << item; + } + + return items; +} + +Stream * Preprocessor::sourceNeeded(QString &fileName, IncludeType type) +{ + Q_UNUSED(type) + + if (!QFile::exists(fileName)) { + foreach (const QString& includePath, d->includePaths) { + QFileInfo fi(includePath + QLatin1Char('/') + fileName); + fileName = QDir::cleanPath(fi.absoluteFilePath()); + if (QFile::exists(fileName)) + goto found; + } + + return 0L; + } + + found: + QFile* f = new QFile(fileName); + if (!f->open(QIODevice::ReadOnly)) { + qWarning() << "Could not open successfully stat-ed file " << fileName << endl; + delete f; + return 0L; + } + + // Hrm, hazardous? + f->deleteLater(); + + return new Stream(f); +} diff --git a/tests/manual/cppmodelmanager/rpp/preprocessor.h b/tests/manual/cppmodelmanager/rpp/preprocessor.h new file mode 100644 index 00000000000..7a919aa79d9 --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/preprocessor.h @@ -0,0 +1,119 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/* + Copyright 2005 Harald Fernengel <[email protected]> + Copyright 2006 Hamish Rodda <[email protected]> + + Permission to use, copy, modify, distribute, and sell this software and its + documentation for any purpose is hereby granted without fee, provided that + the above copyright notice appear in all copies and that both that + copyright notice and this permission notice appear in supporting + documentation. + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef PREPROCESSOR_H +#define PREPROCESSOR_H + +#include <QtCore/qglobal.h> +#include <QtCore/qstring.h> +#include <QtCore/qstringlist.h> + +class QByteArray; +class PreprocessorPrivate; +class Stream; + +class Preprocessor +{ +public: + enum IncludeType { + /// An include specified as being local (eg. "file.h") + IncludeLocal, + /// An include specified as being global (eg. <file.h>) + IncludeGlobal + }; + + Preprocessor(); + virtual ~Preprocessor(); + + QString processFile(const QString &fileName); + QString processString(const QByteArray &str); + + void addIncludePaths(const QStringList &includePaths); + + /** + * This function is called by the preprocessor whenever + * it encounters an include directive. + * + * This class is permitted to modify \a fileName%; this + * value will be used when marking the file in the preprocessed + * output. + * + * \param fileName name of the source file to include + * \param type the way that the file was requested + * + * \return a Stream with the appropriate contents to allow + * the file to be #included. Ownership of the Stream is yielded to + * class pp at this point. + */ + virtual Stream* sourceNeeded(QString& fileName, IncludeType type); + + QStringList macroNames() const; + + struct MacroItem + { + QString name; + QStringList parameters; + QString definition; + bool isFunctionLike; +#ifdef PP_WITH_MACRO_POSITION + QString fileName; +#endif + }; + QList<MacroItem> macros() const; + +private: + Q_DISABLE_COPY(Preprocessor) + PreprocessorPrivate *d; +}; + +#endif diff --git a/tests/manual/cppmodelmanager/rpp/rpp.pri b/tests/manual/cppmodelmanager/rpp/rpp.pri new file mode 100644 index 00000000000..542015edd6c --- /dev/null +++ b/tests/manual/cppmodelmanager/rpp/rpp.pri @@ -0,0 +1,20 @@ +VPATH += $$PWD + +SOURCES += pp-engine.cpp \ + pp-internal.cpp \ + pp-macro-expander.cpp \ + pp-macro.cpp \ + pp-scanner.cpp \ + pp-stream.cpp \ + preprocessor.cpp + +HEADERS += pp-engine.h \ + pp-internal.h \ + pp-macro-expander.h \ + pp-macro.h \ + pp-scanner.h \ + pp-stream.h \ + preprocessor.h + + +INCLUDEPATH += $$PWD
\ No newline at end of file diff --git a/tests/manual/dockwidgets/dockwidgets.pro b/tests/manual/dockwidgets/dockwidgets.pro new file mode 100644 index 00000000000..7a836c967de --- /dev/null +++ b/tests/manual/dockwidgets/dockwidgets.pro @@ -0,0 +1,11 @@ +INCLUDEPATH += ../../../src/lib/ + +HEADERS = mainwindow.h \ + ../../../src/lib/qdockarrows.h \ + ../../../src/lib/qdockarrows_p.h \ + ../../../src/lib/tabpositionindicator.h +SOURCES = main.cpp \ + mainwindow.cpp \ + ../../../src/lib/qdockarrows.cpp \ + ../../../src/lib/tabpositionindicator.cpp + diff --git a/tests/manual/dockwidgets/main.cpp b/tests/manual/dockwidgets/main.cpp new file mode 100644 index 00000000000..3df4beaa800 --- /dev/null +++ b/tests/manual/dockwidgets/main.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/**************************************************************************** +** +** Copyright (C) 2005-$THISYEAR$ Trolltech AS. All rights reserved. +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include <QApplication> + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow mainWin; + mainWin.show(); + return app.exec(); +} diff --git a/tests/manual/dockwidgets/mainwindow.cpp b/tests/manual/dockwidgets/mainwindow.cpp new file mode 100644 index 00000000000..d2f5f422423 --- /dev/null +++ b/tests/manual/dockwidgets/mainwindow.cpp @@ -0,0 +1,124 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/**************************************************************************** +** +** Copyright (C) 2005-$THISYEAR$ Trolltech AS. All rights reserved. +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include <QtGui> + +#include "qdockarrows.h" +#include "mainwindow.h" + +class TestTool : public QWidget +{ + Q_OBJECT + +public: + TestTool(QWidget *parent = 0) : QWidget(parent) { + m_widget = new QLabel("Test", this); + qDebug() << m_tmp.width() << m_tmp.height(); + } + + QSize sizeHint() const + { + return QSize(20, 100); + } + +protected: + void paintEvent(QPaintEvent *event) + { + m_widget->setVisible(false); + + QStyleOptionTabV2 opt; + opt.initFrom(this); + opt.shape = QTabBar::RoundedWest; + opt.text = tr("Hello"); + + QStylePainter p(this); + p.drawControl(QStyle::CE_TabBarTab, opt); + + m_tmp = QPixmap::grabWidget(m_widget, 10, 0, 10, 10); + + QPainter pn(this); + pn.drawPixmap(0,0,m_tmp); + + QWidget::paintEvent(event); + } + +private: + QPixmap m_tmp; + QLabel *m_widget; +}; +#include "mainwindow.moc" + +MainWindow::MainWindow() +{ + centralWidget = new QLabel(tr("Central Widget")); + setCentralWidget(centralWidget); + + QToolBar *tb = this->addToolBar("Normal Toolbar"); + tb->addAction("Test"); + + tb = this->addToolBar("Test Toolbar"); + tb->setMovable(false); + tb->addWidget(new TestTool(this)); + this->addToolBar(Qt::RightToolBarArea, tb); + + createDockWindows(); + + setWindowTitle(tr("Dock Widgets")); +} + +void MainWindow::createDockWindows() +{ + QDockArrowManager *manager = new QDockArrowManager(this); + + for (int i=0; i<5; ++i) { + QArrowManagedDockWidget *dock = new QArrowManagedDockWidget(manager); + QLabel *label = new QLabel(tr("Widget %1").arg(i), dock); + label->setWindowTitle(tr("Widget %1").arg(i)); + label->setObjectName(tr("widget_%1").arg(i)); + dock->setObjectName(tr("dock_%1").arg(i)); + dock->setWidget(label); + addDockWidget(Qt::RightDockWidgetArea, dock); + } +} diff --git a/tests/manual/dockwidgets/mainwindow.h b/tests/manual/dockwidgets/mainwindow.h new file mode 100644 index 00000000000..159d66c9f7e --- /dev/null +++ b/tests/manual/dockwidgets/mainwindow.h @@ -0,0 +1,66 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +/**************************************************************************** +** +** Copyright (C) 2005-$THISYEAR$ Trolltech AS. All rights reserved. +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> + +class QLabel; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +private: + void createDockWindows(); + + QLabel *centralWidget; +}; + +#endif diff --git a/tests/manual/gdbdebugger/script/math.js b/tests/manual/gdbdebugger/script/math.js new file mode 100644 index 00000000000..0fd14f2b9d6 --- /dev/null +++ b/tests/manual/gdbdebugger/script/math.js @@ -0,0 +1,6 @@ + + function cube(a) { + return a * a * a; + } + + var a = cube(3); diff --git a/tests/manual/gdbdebugger/script/script.pro b/tests/manual/gdbdebugger/script/script.pro new file mode 100644 index 00000000000..b1f98ef331a --- /dev/null +++ b/tests/manual/gdbdebugger/script/script.pro @@ -0,0 +1,4 @@ + +TEMPLATE = script +TARGET = math.js +SOURCES += math.js diff --git a/tests/manual/gdbdebugger/simple/app.cpp b/tests/manual/gdbdebugger/simple/app.cpp new file mode 100644 index 00000000000..9cfbdfefff7 --- /dev/null +++ b/tests/manual/gdbdebugger/simple/app.cpp @@ -0,0 +1,827 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ + +/**************************************************************************** +** +** Copyright (C) 2004-$THISYEAR$ Trolltech AS. All rights reserved. +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include <QtCore/QDebug> +#include <QtCore/QDir> +#include <QtCore/QHash> +#include <QtCore/QLibrary> +#include <QtCore/QMap> +#include <QtCore/QPointer> +#include <QtCore/QString> +#include <QtCore/QThread> +#include <QtCore/QVariant> +#include <QtCore/QVector> + +#include <QtGui/QApplication> +#include <QtGui/QAction> +#include <QtGui/QColor> +#include <QtGui/QFont> +#include <QtGui/QLabel> +#include <QtGui/QPainter> +#include <QtGui/QPainterPath> + +#include <QtNetwork/QHostAddress> + +#include <iostream> +#include <string> +#include <vector> + +#ifdef Q_OS_WIN +#include <windows.h> +#endif + + +uint qHash(const QMap<int, int> &) +{ + return 0; +} + +uint qHash(const double & f) +{ + return int(f); +} + +class Foo +{ +public: + Foo(int i=0) + : a(i), b(2) + { + int s = 1; + int t = 2; + b = 2 + s + t; + a += 1; + } + void doit() + { + static QObject ob; + m["1"] = "2"; + h[&ob] = m.begin(); + + a += 1; + --b; + //s += 'x'; + } + + + struct Bar { + Bar() : ob(0) {} + QObject *ob; + }; + +public: + int a, b; + char x[6]; + +private: + //QString s; + typedef QMap<QString, QString> Map; + Map m; + QHash<QObject *, Map::iterator> h; +}; + +void testArray() +{ + QString x[4]; + x[0] = "a"; + x[1] = "b"; + x[2] = "c"; + x[3] = "d"; + + Foo foo[10]; + //for (int i = 0; i != sizeof(foo)/sizeof(foo[0]); ++i) { + for (int i = 0; i < 5; ++i) { + foo[i].a = i; + foo[i].doit(); + } +} + + +void testByteArray() +{ + QByteArray ba = "Hello"; + ba += '"'; + ba += "World"; + ba += char(0); + ba += 1; + ba += 2; +} + + +void testHash() +{ + QHash<int, float> hgg0; + hgg0[11] = 11.0; + hgg0[22] = 22.0; + + + QHash<QString, float> hgg1; + hgg1["22.0"] = 22.0; + + QHash<int, QString> hgg2; + hgg2[22] = "22.0"; + + QHash<QString, Foo> hgg3; + hgg3["22.0"] = Foo(22); + hgg3["33.0"] = Foo(33); + + QObject ob; + QHash<QString, QPointer<QObject> > hash; + hash.insert("Hallo", QPointer<QObject>(&ob)); + hash.insert("Welt", QPointer<QObject>(&ob)); + hash.insert(".", QPointer<QObject>(&ob)); +} + +void testImage() +{ + QImage im(QSize(200, 200), QImage::Format_RGB32); + im.fill(QColor(200, 100, 130).rgba()); + QPainter pain; + pain.begin(&im); + pain.drawLine(2, 2, 130, 130); + pain.drawLine(4, 2, 130, 140); + pain.drawRect(30, 30, 80, 80); + pain.end(); +} + +void testIO() +{ + qDebug() << "qDebug() 1"; + qDebug() << "qDebug() 2"; + qDebug() << "qDebug() 3"; + + std::cout << "std::cout @@ 1" << std::endl; + std::cout << "std::cout @@ 2\n"; + std::cout << "std::cout @@ 3" << std::endl; + + std::cerr << "std::cerr 1\n"; + std::cerr << "std::cerr 2\n"; + std::cerr << "std::cerr 3\n"; +} + + +void testList() +{ +#if 1 + QList<int> li; + QList<uint> lu; + + for (int i = 0; i != 3; ++i) { + li.append(i); + } + li.append(101); + li.append(102); + li.append(102); + li.append(102); + li.append(102); + li.append(102); + li.append(102); + li.append(102); + li.append(102); + li.append(102); + li.append(102); + li.append(102); + li.append(102); + li.append(102); + + + for (int i = 0; i != 3; ++i) { + lu.append(i); + } + lu.append(101); + lu.append(102); + lu.append(102); + lu.append(102); + lu.append(102); + lu.append(102); + lu.append(102); + lu.append(102); + lu.append(102); + + QList<uint> i; + i.append(42); + i.append(43); + i.append(44); + i.append(45); + + QList<qulonglong> l; + l.append(42); + l.append(43); + l.append(44); + l.append(45); + + QList<Foo> f; + f.append(Foo(1)); + f.append(Foo(2)); +#endif + QList<std::string> v; + + v.push_back("aa"); + v.push_back("bb"); + v.push_back("cc"); + v.push_back("dd"); + } + +void testMap() +{ + QMap<uint, QStringList> ggl; + ggl[11] = QStringList() << "11"; + ggl[22] = QStringList() << "22"; + + typedef QMap<uint, QStringList> T; + T ggt; + ggt[11] = QStringList() << "11"; + ggt[22] = QStringList() << "22"; + +#if 0 + QMap<uint, float> gg0; + gg0[11] = 11.0; + gg0[22] = 22.0; + + + QMap<QString, float> gg1; + gg1["22.0"] = 22.0; + + QMap<int, QString> gg2; + gg2[22] = "22.0"; + + QMap<QString, Foo> gg3; + gg3["22.0"] = Foo(22); + gg3["33.0"] = Foo(33); + + QObject ob; + QMap<QString, QPointer<QObject> > map; + map.insert("Hallo", QPointer<QObject>(&ob)); + map.insert("Welt", QPointer<QObject>(&ob)); + map.insert(".", QPointer<QObject>(&ob)); +#endif +} + +void testObject(int &argc, char *argv[]) +{ + QApplication app(argc, argv); + QAction act("xxx", &app); + QString t = act.text(); + t += "y"; + +/* + QObject ob(&app); + ob.setObjectName("An Object"); + QObject ob1; + ob1.setObjectName("Another Object"); + + QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater())); + QObject::connect(&app, SIGNAL(lastWindowClosed()), &ob, SLOT(deleteLater())); + + QList<QObject *> obs; + obs.append(&ob); + obs.append(&ob1); + obs.append(0); + obs.append(&app); + ob1.setObjectName("A Subobject"); +*/ + QLabel l("XXXXXXXXXXXXXXXXX"); + l.show(); + app.exec(); +} + +void testPixmap() +{ + QImage im(QSize(200, 200), QImage::Format_RGB32); + im.fill(QColor(200, 100, 130).rgba()); + QPainter pain; + pain.begin(&im); + pain.drawLine(2, 2, 130, 130); + pain.end(); + QPixmap pm = QPixmap::fromImage(im); + int i = 1; + Q_UNUSED(i); +} + +void testPlugin() +{ + QString dir = QDir::currentPath(); +#ifdef Q_OS_LINUX + QLibrary lib(dir + "/libplugin.so"); +#endif +#ifdef Q_OS_MAC + dir = QFileInfo(dir + "/../..").canonicalPath(); + QLibrary lib(dir + "/libplugin.dylib"); +#endif +#ifdef Q_OS_WIN + QLibrary lib(dir + "/plugin.dll"); +#endif + int (*foo)() = (int(*)()) lib.resolve("pluginTest"); + qDebug() << "library resolve: " << foo; + if (foo) { + int res = foo(); + res += 1; + } else { + qDebug() << lib.errorString(); + } +} + +void stringRefTest(const QString &refstring) +{ + Q_UNUSED(refstring); +} + + +int F(int a, int b) +{ + return a + b; +} + +int add(int i) { return i + 2; } + +int mul(int i) { return i * 2; } + + +void testStdVector() +{ + int x = F(add(1), mul(2)); + Q_UNUSED(x); + std::vector<int *> plist1; + plist1.push_back(new int(1)); + plist1.push_back(0); + plist1.push_back(new int(2)); + + std::vector<int> flist2; + flist2.push_back(1); + flist2.push_back(2); + flist2.push_back(3); + flist2.push_back(4); + + int a = 1; + int b = 0; + + while (0) { + a += 1; + if (b) + break; + } + + flist2.push_back(1); + flist2.push_back(2); + flist2.push_back(3); + flist2.push_back(4); + + std::vector<Foo *> plist; + plist.push_back(new Foo(1)); + plist.push_back(0); + plist.push_back(new Foo(2)); + + std::vector<Foo> flist; + flist.push_back(1); + + flist.push_back(2); + flist.push_back(3); + flist.push_back(4); + //flist.takeFirst(); + //flist.takeFirst(); + + std::vector<bool> vec; + vec.push_back(true); + vec.push_back(false); +} + +void testStdString() +{ + QString foo; + std::string str; + std::wstring wstr; + + std::vector<std::string> v; + + foo += "a"; + str += "b"; + wstr += wchar_t('e'); + foo += "c"; + str += "d"; + foo += "e"; + wstr += wchar_t('e'); + str += "e"; + foo += "a"; + str += "b"; + foo += "c"; + str += "d"; + str += "e"; + wstr += wchar_t('e'); + wstr += wchar_t('e'); + str += "e"; + + QList<std::string> l; + + l.push_back(str); + l.push_back(str); + l.push_back(str); + l.push_back(str); + + v.push_back(str); + v.push_back(str); + v.push_back(str); + v.push_back(str); +} + +void testString() +{ + QString str = "Hello "; + str += " big, "; + str += " fat "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; + str += " World "; +} + +void testString3() +{ + QString str = "Hello "; + str += " big, "; + str += " fat "; + str += " World "; + + QString string("String Test"); + QString *pstring = new QString("Pointer String Test"); + stringRefTest(QString("Ref String Test")); + string = "Hi"; + string += "Du"; + qDebug() << string; + delete pstring; +} + +void testStringList() +{ + QStringList l; + l << "Hello "; + l << " big, "; + l << " fat "; + l << " World "; +} + +void testStruct() +{ + Foo f(2); + f.doit(); + f.doit(); + f.doit(); +} + +class Thread : public QThread +{ +public: + Thread(int id) : m_id(id) {} + + void run() + { + for (int i = 0; i != 100000; ++i) { + //sleep(1); + std::cerr << m_id; + } + } + +private: + int m_id; +}; + +void testThreads() +{ + Thread thread1(1); + Thread thread2(2); + thread1.start(); + thread2.start(); + thread1.wait(); + thread2.wait(); +} + +void testVariant1() +{ + QVariant v; + v = 1; + v = 1.0; + v = "string"; + v = 1; +} + +void testVariant2() +{ + QVariant var; +#if 0 + QVariant var3; + QHostAddress ha("127.0.0.1"); + qVariantSetValue(var, ha); + var3 = var; + var3 = var; + var3 = var; + var3 = var; + QHostAddress ha1 = var.value<QHostAddress>(); +#endif + typedef QMap<uint, QStringList> MyType; + MyType my; + my[1] = (QStringList() << "Hello"); + my[3] = (QStringList() << "World"); + var.setValue(my); + QString type = var.typeName(); + var.setValue(my); + var.setValue(my); + var.setValue(my); + var.setValue(my); +} + +void testVariant3() +{ + QList<int> list; + list << 1 << 2 << 3; + QVariant variant = qVariantFromValue(list); + list.clear(); + list = qVariantValue<QList<int> >(variant); +} + +void testVector() +{ + QVector<Foo *> plist; + plist.append(new Foo(1)); + plist.append(0); + plist.append(new Foo(2)); + + QVector<Foo> flist; + flist.append(1); + + flist.append(2); + flist.append(3); + flist.append(4); + //flist.takeFirst(); + //flist.takeFirst(); + + QVector<bool> vec; + vec.append(true); + vec.append(false); +} + +void testVectorOfList() +{ + QVector<QList<int> > v; + QVector<QList<int> > *pv = &v; + v.append(QList<int>() << 1); + v.append(QList<int>() << 2 << 3); + Q_UNUSED(pv); +} + +void foo() {} +void foo(int) {} +void foo(QList<int>) {} +void foo(QList<QVector<int> >) {} +void foo(QList<QVector<int> *>) {} +void foo(QList<QVector<int *> *>) {} + +template <class T> +void foo(QList<QVector<T> *>) {} + +namespace { + +namespace A { int barz() { return 42;} } +namespace B { int barz() { return 43;} } + +} + +namespace somespace { + +class MyBase : public QObject +{ +public: + MyBase() {} + virtual void doit(int i) + { + n = i; + } +protected: + int n; +}; + +namespace nested { + +class MyFoo : public MyBase +{ +public: + MyFoo() {} + virtual void doit(int i) + { + n = i; + } +protected: + int n; +}; + +class MyBar : public MyFoo +{ +public: + virtual void doit(int i) + { + n = i + 1; + } +}; + +namespace { + +class MyAnon : public MyBar +{ +public: + virtual void doit(int i) + { + n = i + 3; + } +}; + +namespace baz { + +class MyBaz : public MyAnon +{ +public: + virtual void doit(int i) + { + n = i + 5; + } +}; + +} // namespace baz + +} // namespace anon + + +} // namespace nested +} // namespace somespace + +void testNamespace() +{ + using namespace somespace; + using namespace nested; + MyFoo foo; + MyBar bar; + MyAnon anon; + baz::MyBaz baz; + baz.doit(1); + anon.doit(1); + foo.doit(1); + bar.doit(1); + bar.doit(1); + bar.doit(1); + bar.doit(1); + bar.doit(1); + bar.doit(1); + bar.doit(1); +} + +int main(int argc, char *argv[]) +{ + testIO(); + //QString s; + //s = "hallo"; + //QList<QVector<int> *> vi; + //QList<QVector<double> *> vd; + //int n = A::barz(); + + + int n = 1; + n = 2; + n = 3; + n = 3; + n = 3; + n = 3; + n = 3; + n = 3; + n = 3; + { + QString n = "2"; + n = "3"; + n = "4"; + { + double n = 3.5; + ++n; + ++n; + } + n = "3"; + n = "4"; + } + ++n; + ++n; + + testArray(); + testStdVector(); + testStdString(); + + testPlugin(); + testList(); + testNamespace(); + //return 0; + testByteArray(); + testHash(); + testImage(); + testMap(); + testString(); + testStringList(); + testStruct(); + //testThreads(); + testVariant1(); + testVariant2(); + testVariant3(); + testVector(); + testVectorOfList(); + testObject(argc, argv); + + //QColor color(255,128,10); + //QFont font; + + while(true) + ; + + return 0; +} + +//Q_DECLARE_METATYPE(QHostAddress) +Q_DECLARE_METATYPE(QList<int>) + +//#define COMMA , +//Q_DECLARE_METATYPE(QMap<uint COMMA QStringList>) + +QT_BEGIN_NAMESPACE + +template <> +struct QMetaTypeId<QHostAddress> +{ + enum { Defined = 1 }; + static int qt_metatype_id() + { + static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); + if (!metatype_id) + metatype_id = qRegisterMetaType<QHostAddress>("myns::QHostAddress"); + return metatype_id; \ + } \ +}; + +template <> +struct QMetaTypeId< QMap<uint, QStringList> > +{ + enum { Defined = 1 }; + static int qt_metatype_id() + { + static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); + if (!metatype_id) + metatype_id = qRegisterMetaType< QMap<uint, QStringList> >("myns::QMap<uint, myns::QStringList>"); + return metatype_id; \ + } \ +}; +QT_END_NAMESPACE diff --git a/tests/manual/gdbdebugger/simple/app/app.pro b/tests/manual/gdbdebugger/simple/app/app.pro new file mode 100644 index 00000000000..bf168bab106 --- /dev/null +++ b/tests/manual/gdbdebugger/simple/app/app.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET = debuggertest +DEPENDPATH += . +INCLUDEPATH += . +DESTDIR = .. + +# Input +SOURCES += ../app.cpp +QT += network diff --git a/tests/manual/gdbdebugger/simple/plugin.cpp b/tests/manual/gdbdebugger/simple/plugin.cpp new file mode 100644 index 00000000000..36edb806b53 --- /dev/null +++ b/tests/manual/gdbdebugger/simple/plugin.cpp @@ -0,0 +1,45 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ + + +#include <stdio.h> +#include <qglobal.h> + +extern "C" Q_DECL_EXPORT int pluginTest() +{ + int s = 0; + for (int i = 1; i != 2000; ++i) + s += i; + fprintf(stderr, "in plugin test"); + return s; +} diff --git a/tests/manual/gdbdebugger/simple/plugin/plugin.pro b/tests/manual/gdbdebugger/simple/plugin/plugin.pro new file mode 100644 index 00000000000..911dc2481e2 --- /dev/null +++ b/tests/manual/gdbdebugger/simple/plugin/plugin.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +TARGET = plugin +DESTDIR = .. +CONFIG += shared + +SOURCES += ../plugin.cpp + +macx { + QMAKE_LFLAGS_SONAME = -Wl,-install_name,@executable_path/../PlugIns/$${PROVIDER}/ +} else:linux-* { + #do the rpath by hand since it's not possible to use ORIGIN in QMAKE_RPATHDIR + QMAKE_RPATHDIR += \$\$ORIGIN/.. + IDE_PLUGIN_RPATH = $$join(QMAKE_RPATHDIR, ":") + QMAKE_LFLAGS += -Wl,-z,origin \'-Wl,-rpath,$${IDE_PLUGIN_RPATH}\' + QMAKE_RPATHDIR = +} + + diff --git a/tests/manual/gdbdebugger/simple/simple.pro b/tests/manual/gdbdebugger/simple/simple.pro new file mode 100644 index 00000000000..78c70731cd4 --- /dev/null +++ b/tests/manual/gdbdebugger/simple/simple.pro @@ -0,0 +1,4 @@ + +TEMPLATE = subdirs + +SUBDIRS += app plugin diff --git a/tests/manual/gdbdebugger/spacy path/app with space.cpp b/tests/manual/gdbdebugger/spacy path/app with space.cpp new file mode 100644 index 00000000000..c5969e5f962 --- /dev/null +++ b/tests/manual/gdbdebugger/spacy path/app with space.cpp @@ -0,0 +1,419 @@ + +/**************************************************************************** +** +** Copyright (C) 2004-$THISYEAR$ Trolltech AS. All rights reserved. +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include <QtCore/QDebug> +#include <QtCore/QDir> +#include <QtCore/QHash> +#include <QtCore/QLibrary> +#include <QtCore/QMap> +#include <QtCore/QPointer> +#include <QtCore/QString> +#include <QtCore/QThread> +#include <QtCore/QVariant> +#include <QtCore/QVector> + +#include <QtGui/QApplication> +#include <QtGui/QAction> +#include <QtGui/QColor> +#include <QtGui/QFont> +#include <QtGui/QLabel> +#include <QtGui/QPainter> +#include <QtGui/QPainterPath> + +#include <QtNetwork/QHostAddress> + +#include <iostream> + +#ifdef Q_OS_WIN +#include <windows.h> +#endif + + +uint qHash(const QMap<int, int> &) +{ + return 0; +} + +uint qHash(const double & f) +{ + return int(f); +} + +class Foo +{ +public: + Foo(int i=0) + : a(i), b(2) + { + + } + void doit() + { + static QObject ob; + m["1"] = "2"; + h[&ob] = m.begin(); + + a += 1; + --b; + //s += 'x'; + } + + + struct Bar { + Bar() : ob(0) {} + QObject *ob; + }; + +public: + int a, b; + char x[6]; + +private: + //QString s; + typedef QMap<QString, QString> Map; + Map m; + QHash<QObject *, Map::iterator> h; +}; + +void testArray() +{ + QString x[4]; + x[0] = "a"; + x[1] = "b"; + x[2] = "c"; + x[3] = "d"; + + Foo foo[100]; + //for (int i = 0; i != sizeof(foo)/sizeof(foo[0]); ++i) { + for (int i = 0; i < 5; ++i) { + foo[i].a = i; + foo[i].doit(); + } +} + +void testByteArray() +{ + QByteArray ba = "Hello"; + ba += '"'; + ba += "World"; + ba += char(0); + ba += 1; + ba += 2; +} + +void testHash() +{ + QHash<int, float> hgg0; + hgg0[11] = 11.0; + hgg0[22] = 22.0; + + + QHash<QString, float> hgg1; + hgg1["22.0"] = 22.0; + + QHash<int, QString> hgg2; + hgg2[22] = "22.0"; + + QHash<QString, Foo> hgg3; + hgg3["22.0"] = Foo(22); + hgg3["33.0"] = Foo(33); + + QObject ob; + QHash<QString, QPointer<QObject> > hash; + hash.insert("Hallo", QPointer<QObject>(&ob)); + hash.insert("Welt", QPointer<QObject>(&ob)); + hash.insert(".", QPointer<QObject>(&ob)); +} + +void testImage() +{ + QImage im(QSize(200, 200), QImage::Format_RGB32); + im.fill(QColor(200, 100, 130).rgba()); + QPainter pain; + pain.begin(&im); + pain.drawLine(2, 2, 130, 130); + pain.drawLine(4, 2, 130, 140); + pain.drawRect(30, 30, 80, 80); + pain.end(); +} + +void testIO() +{ + qDebug() << "qDebug() 1"; + qDebug() << "qDebug() 2"; + qDebug() << "qDebug() 3"; + + std::cout << "std::cout @@ 1\n"; + std::cout << "std::cout @@ 2\n"; + std::cout << "std::cout @@ 3\n"; + + std::cerr << "std::cerr 1\n"; + std::cerr << "std::cerr 2\n"; + std::cerr << "std::cerr 3\n"; +}; + + +void testList() +{ + QList<int> foo; + for (int i = 0; i != 100; ++i) { + foo.append(i); + } + foo.append(101); + foo.append(102); + } + +void testMap() +{ + QMap<int, float> gg0; + gg0[11] = 11.0; + gg0[22] = 22.0; + + + QMap<QString, float> gg1; + gg1["22.0"] = 22.0; + + QMap<int, QString> gg2; + gg2[22] = "22.0"; + + QMap<QString, Foo> gg3; + gg3["22.0"] = Foo(22); + gg3["33.0"] = Foo(33); + + QObject ob; + QMap<QString, QPointer<QObject> > map; + map.insert("Hallo", QPointer<QObject>(&ob)); + map.insert("Welt", QPointer<QObject>(&ob)); + map.insert(".", QPointer<QObject>(&ob)); +} + +void testObject(int &argc, char *argv[]) +{ + QApplication app(argc, argv); + QAction act("xxx", &app); + QString t = act.text(); + t += "y"; + +/* + QObject ob(&app); + ob.setObjectName("An Object"); + QObject ob1; + ob1.setObjectName("Another Object"); + + QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater())); + QObject::connect(&app, SIGNAL(lastWindowClosed()), &ob, SLOT(deleteLater())); + + QList<QObject *> obs; + obs.append(&ob); + obs.append(&ob1); + obs.append(0); + obs.append(&app); + ob1.setObjectName("A Subobject"); +*/ + QLabel l("XXXXXXXXXXXXXXXXX"); + l.show(); + app.exec(); +} + +void testPixmap() +{ + QImage im(QSize(200, 200), QImage::Format_RGB32); + im.fill(QColor(200, 100, 130).rgba()); + QPainter pain; + pain.begin(&im); + pain.drawLine(2, 2, 130, 130); + pain.end(); + QPixmap pm = QPixmap::fromImage(im); + int i = 1; + Q_UNUSED(i); +} + +void testPlugin() +{ + QString dir = QDir::currentPath(); +#ifdef Q_OS_LINUX + QLibrary lib(dir + "/libplugin.so"); +#endif + int (*foo)() = (int(*)()) lib.resolve("pluginTest"); + qDebug() << "library resolve: " << foo; + if (foo) { + int res = foo(); + res += 1; + } else { + qDebug() << lib.errorString(); + } +} + +void stringRefTest(const QString &refstring) +{ + Q_UNUSED(refstring); +} + +void testString() +{ + QString str = "Hello "; + str += " big, "; + str += " fat "; + str += " World "; + + QString string("String Test"); + QString *pstring = new QString("Pointer String Test"); + stringRefTest(QString("Ref String Test")); + string = "Hi"; + string += "Du"; + qDebug() << string; + delete pstring; +} + +void testStringList() +{ + QStringList l; + l << "Hello "; + l << " big, "; + l << " fat "; + l << " World "; +} + +void testStruct() +{ + Foo f(2); + f.doit(); + f.doit(); + f.doit(); +}; + +class Thread : public QThread +{ +public: + Thread(int id) : m_id(id) {} + + void run() + { + for (int i = 0; i != 100000; ++i) { + //sleep(1); + std::cerr << m_id; + } + } + +private: + int m_id; +}; + +void testThreads() +{ + Thread thread1(1); + Thread thread2(2); + thread1.start(); + thread2.start(); + thread1.wait(); + thread2.wait(); +} + +void testVariant1() +{ + QVariant v; + v = 1; + v = 1.0; + v = "string"; + v = 1; +} + +void testVariant2() +{ + QVariant var; + QVariant var3; + QHostAddress ha("127.0.0.1"); + qVariantSetValue(var, ha); + var3 = var; + var3 = var; + var3 = var; + var3 = var; + QHostAddress ha1 = var.value<QHostAddress>(); +} + +void testVariant3() +{ + QList<int> list; + list << 1 << 2 << 3; + QVariant variant = qVariantFromValue(list); + list.clear(); + list = qVariantValue<QList<int> >(variant); +} + +void testVector() +{ + QVector<Foo *> plist; + plist.append(new Foo(1)); + plist.append(0); + plist.append(new Foo(2)); + + QVector<Foo> flist; + flist.append(1); + + flist.append(2); + flist.append(3); + flist.append(4); + //flist.takeFirst(); + //flist.takeFirst(); + + QVector<bool> vec; + vec.append(true); + vec.append(false); +} + +void testVectorOfList() +{ + QVector<QList<int> > v; + QVector<QList<int> > *pv = &v; + v.append(QList<int>() << 1); + v.append(QList<int>() << 2 << 3); + Q_UNUSED(pv); +} + +int main(int argc, char *argv[]) +{ + testArray(); + testPlugin(); + testList(); + return 0; + testByteArray(); + testHash(); + testImage(); + testIO(); + testMap(); + testString(); + testStringList(); + testStruct(); + testThreads(); + testVariant1(); + testVariant2(); + testVariant3(); + testVector(); + testVectorOfList(); + + testObject(argc, argv); + + QColor color(255,128,10); + QFont font; + + while(true) + ; + + return 0; +} + +Q_DECLARE_METATYPE(QHostAddress) +Q_DECLARE_METATYPE(QList<int>) + + diff --git a/tests/manual/gdbdebugger/spacy path/plugin with space.cpp b/tests/manual/gdbdebugger/spacy path/plugin with space.cpp new file mode 100644 index 00000000000..75486ccd670 --- /dev/null +++ b/tests/manual/gdbdebugger/spacy path/plugin with space.cpp @@ -0,0 +1,13 @@ + + +#include <stdio.h> +#include <qglobal.h> + +extern "C" Q_DECL_EXPORT int pluginTest() +{ + int s = 0; + for (int i = 1; i != 2000; ++i) + s += i; + fprintf(stderr, "in plugin test"); + return s; +} diff --git a/tests/manual/gdbdebugger/spacy path/spacy app/spacy app.pro b/tests/manual/gdbdebugger/spacy path/spacy app/spacy app.pro new file mode 100644 index 00000000000..eee7110844a --- /dev/null +++ b/tests/manual/gdbdebugger/spacy path/spacy app/spacy app.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET = "spacy app" +DEPENDPATH += . +INCLUDEPATH += . +DESTDIR = .. + +# Input +SOURCES += "../app with space.cpp" +QT += network diff --git a/tests/manual/gdbdebugger/spacy path/spacy path.pro b/tests/manual/gdbdebugger/spacy path/spacy path.pro new file mode 100644 index 00000000000..879aea6259d --- /dev/null +++ b/tests/manual/gdbdebugger/spacy path/spacy path.pro @@ -0,0 +1,4 @@ + +TEMPLATE = subdirs + +SUBDIRS += "\"spacy app\"" "\"spacy plugin\"" diff --git a/tests/manual/gdbdebugger/spacy path/spacy plugin/spacy plugin.pro b/tests/manual/gdbdebugger/spacy path/spacy plugin/spacy plugin.pro new file mode 100644 index 00000000000..3cad806e7af --- /dev/null +++ b/tests/manual/gdbdebugger/spacy path/spacy plugin/spacy plugin.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +TARGET = plugin +DESTDIR = .. +CONFIG += shared + +SOURCES += "../plugin with space.cpp" + +macx { + QMAKE_LFLAGS_SONAME = -Wl,-install_name,@executable_path/../PlugIns/$${PROVIDER}/ +} else:linux-* { + #do the rpath by hand since it's not possible to use ORIGIN in QMAKE_RPATHDIR + QMAKE_RPATHDIR += \$\$ORIGIN/.. + IDE_PLUGIN_RPATH = $$join(QMAKE_RPATHDIR, ":") + QMAKE_LFLAGS += -Wl,-z,origin \'-Wl,-rpath,$${IDE_PLUGIN_RPATH}\' + QMAKE_RPATHDIR = +} + + diff --git a/tests/manual/gdbdebugger/spacy-file/app with space.cpp b/tests/manual/gdbdebugger/spacy-file/app with space.cpp new file mode 100644 index 00000000000..c5969e5f962 --- /dev/null +++ b/tests/manual/gdbdebugger/spacy-file/app with space.cpp @@ -0,0 +1,419 @@ + +/**************************************************************************** +** +** Copyright (C) 2004-$THISYEAR$ Trolltech AS. All rights reserved. +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include <QtCore/QDebug> +#include <QtCore/QDir> +#include <QtCore/QHash> +#include <QtCore/QLibrary> +#include <QtCore/QMap> +#include <QtCore/QPointer> +#include <QtCore/QString> +#include <QtCore/QThread> +#include <QtCore/QVariant> +#include <QtCore/QVector> + +#include <QtGui/QApplication> +#include <QtGui/QAction> +#include <QtGui/QColor> +#include <QtGui/QFont> +#include <QtGui/QLabel> +#include <QtGui/QPainter> +#include <QtGui/QPainterPath> + +#include <QtNetwork/QHostAddress> + +#include <iostream> + +#ifdef Q_OS_WIN +#include <windows.h> +#endif + + +uint qHash(const QMap<int, int> &) +{ + return 0; +} + +uint qHash(const double & f) +{ + return int(f); +} + +class Foo +{ +public: + Foo(int i=0) + : a(i), b(2) + { + + } + void doit() + { + static QObject ob; + m["1"] = "2"; + h[&ob] = m.begin(); + + a += 1; + --b; + //s += 'x'; + } + + + struct Bar { + Bar() : ob(0) {} + QObject *ob; + }; + +public: + int a, b; + char x[6]; + +private: + //QString s; + typedef QMap<QString, QString> Map; + Map m; + QHash<QObject *, Map::iterator> h; +}; + +void testArray() +{ + QString x[4]; + x[0] = "a"; + x[1] = "b"; + x[2] = "c"; + x[3] = "d"; + + Foo foo[100]; + //for (int i = 0; i != sizeof(foo)/sizeof(foo[0]); ++i) { + for (int i = 0; i < 5; ++i) { + foo[i].a = i; + foo[i].doit(); + } +} + +void testByteArray() +{ + QByteArray ba = "Hello"; + ba += '"'; + ba += "World"; + ba += char(0); + ba += 1; + ba += 2; +} + +void testHash() +{ + QHash<int, float> hgg0; + hgg0[11] = 11.0; + hgg0[22] = 22.0; + + + QHash<QString, float> hgg1; + hgg1["22.0"] = 22.0; + + QHash<int, QString> hgg2; + hgg2[22] = "22.0"; + + QHash<QString, Foo> hgg3; + hgg3["22.0"] = Foo(22); + hgg3["33.0"] = Foo(33); + + QObject ob; + QHash<QString, QPointer<QObject> > hash; + hash.insert("Hallo", QPointer<QObject>(&ob)); + hash.insert("Welt", QPointer<QObject>(&ob)); + hash.insert(".", QPointer<QObject>(&ob)); +} + +void testImage() +{ + QImage im(QSize(200, 200), QImage::Format_RGB32); + im.fill(QColor(200, 100, 130).rgba()); + QPainter pain; + pain.begin(&im); + pain.drawLine(2, 2, 130, 130); + pain.drawLine(4, 2, 130, 140); + pain.drawRect(30, 30, 80, 80); + pain.end(); +} + +void testIO() +{ + qDebug() << "qDebug() 1"; + qDebug() << "qDebug() 2"; + qDebug() << "qDebug() 3"; + + std::cout << "std::cout @@ 1\n"; + std::cout << "std::cout @@ 2\n"; + std::cout << "std::cout @@ 3\n"; + + std::cerr << "std::cerr 1\n"; + std::cerr << "std::cerr 2\n"; + std::cerr << "std::cerr 3\n"; +}; + + +void testList() +{ + QList<int> foo; + for (int i = 0; i != 100; ++i) { + foo.append(i); + } + foo.append(101); + foo.append(102); + } + +void testMap() +{ + QMap<int, float> gg0; + gg0[11] = 11.0; + gg0[22] = 22.0; + + + QMap<QString, float> gg1; + gg1["22.0"] = 22.0; + + QMap<int, QString> gg2; + gg2[22] = "22.0"; + + QMap<QString, Foo> gg3; + gg3["22.0"] = Foo(22); + gg3["33.0"] = Foo(33); + + QObject ob; + QMap<QString, QPointer<QObject> > map; + map.insert("Hallo", QPointer<QObject>(&ob)); + map.insert("Welt", QPointer<QObject>(&ob)); + map.insert(".", QPointer<QObject>(&ob)); +} + +void testObject(int &argc, char *argv[]) +{ + QApplication app(argc, argv); + QAction act("xxx", &app); + QString t = act.text(); + t += "y"; + +/* + QObject ob(&app); + ob.setObjectName("An Object"); + QObject ob1; + ob1.setObjectName("Another Object"); + + QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater())); + QObject::connect(&app, SIGNAL(lastWindowClosed()), &ob, SLOT(deleteLater())); + + QList<QObject *> obs; + obs.append(&ob); + obs.append(&ob1); + obs.append(0); + obs.append(&app); + ob1.setObjectName("A Subobject"); +*/ + QLabel l("XXXXXXXXXXXXXXXXX"); + l.show(); + app.exec(); +} + +void testPixmap() +{ + QImage im(QSize(200, 200), QImage::Format_RGB32); + im.fill(QColor(200, 100, 130).rgba()); + QPainter pain; + pain.begin(&im); + pain.drawLine(2, 2, 130, 130); + pain.end(); + QPixmap pm = QPixmap::fromImage(im); + int i = 1; + Q_UNUSED(i); +} + +void testPlugin() +{ + QString dir = QDir::currentPath(); +#ifdef Q_OS_LINUX + QLibrary lib(dir + "/libplugin.so"); +#endif + int (*foo)() = (int(*)()) lib.resolve("pluginTest"); + qDebug() << "library resolve: " << foo; + if (foo) { + int res = foo(); + res += 1; + } else { + qDebug() << lib.errorString(); + } +} + +void stringRefTest(const QString &refstring) +{ + Q_UNUSED(refstring); +} + +void testString() +{ + QString str = "Hello "; + str += " big, "; + str += " fat "; + str += " World "; + + QString string("String Test"); + QString *pstring = new QString("Pointer String Test"); + stringRefTest(QString("Ref String Test")); + string = "Hi"; + string += "Du"; + qDebug() << string; + delete pstring; +} + +void testStringList() +{ + QStringList l; + l << "Hello "; + l << " big, "; + l << " fat "; + l << " World "; +} + +void testStruct() +{ + Foo f(2); + f.doit(); + f.doit(); + f.doit(); +}; + +class Thread : public QThread +{ +public: + Thread(int id) : m_id(id) {} + + void run() + { + for (int i = 0; i != 100000; ++i) { + //sleep(1); + std::cerr << m_id; + } + } + +private: + int m_id; +}; + +void testThreads() +{ + Thread thread1(1); + Thread thread2(2); + thread1.start(); + thread2.start(); + thread1.wait(); + thread2.wait(); +} + +void testVariant1() +{ + QVariant v; + v = 1; + v = 1.0; + v = "string"; + v = 1; +} + +void testVariant2() +{ + QVariant var; + QVariant var3; + QHostAddress ha("127.0.0.1"); + qVariantSetValue(var, ha); + var3 = var; + var3 = var; + var3 = var; + var3 = var; + QHostAddress ha1 = var.value<QHostAddress>(); +} + +void testVariant3() +{ + QList<int> list; + list << 1 << 2 << 3; + QVariant variant = qVariantFromValue(list); + list.clear(); + list = qVariantValue<QList<int> >(variant); +} + +void testVector() +{ + QVector<Foo *> plist; + plist.append(new Foo(1)); + plist.append(0); + plist.append(new Foo(2)); + + QVector<Foo> flist; + flist.append(1); + + flist.append(2); + flist.append(3); + flist.append(4); + //flist.takeFirst(); + //flist.takeFirst(); + + QVector<bool> vec; + vec.append(true); + vec.append(false); +} + +void testVectorOfList() +{ + QVector<QList<int> > v; + QVector<QList<int> > *pv = &v; + v.append(QList<int>() << 1); + v.append(QList<int>() << 2 << 3); + Q_UNUSED(pv); +} + +int main(int argc, char *argv[]) +{ + testArray(); + testPlugin(); + testList(); + return 0; + testByteArray(); + testHash(); + testImage(); + testIO(); + testMap(); + testString(); + testStringList(); + testStruct(); + testThreads(); + testVariant1(); + testVariant2(); + testVariant3(); + testVector(); + testVectorOfList(); + + testObject(argc, argv); + + QColor color(255,128,10); + QFont font; + + while(true) + ; + + return 0; +} + +Q_DECLARE_METATYPE(QHostAddress) +Q_DECLARE_METATYPE(QList<int>) + + diff --git a/tests/manual/gdbdebugger/spacy-file/app/app.pro b/tests/manual/gdbdebugger/spacy-file/app/app.pro new file mode 100644 index 00000000000..eee7110844a --- /dev/null +++ b/tests/manual/gdbdebugger/spacy-file/app/app.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET = "spacy app" +DEPENDPATH += . +INCLUDEPATH += . +DESTDIR = .. + +# Input +SOURCES += "../app with space.cpp" +QT += network diff --git a/tests/manual/gdbdebugger/spacy-file/plugin with space.cpp b/tests/manual/gdbdebugger/spacy-file/plugin with space.cpp new file mode 100644 index 00000000000..75486ccd670 --- /dev/null +++ b/tests/manual/gdbdebugger/spacy-file/plugin with space.cpp @@ -0,0 +1,13 @@ + + +#include <stdio.h> +#include <qglobal.h> + +extern "C" Q_DECL_EXPORT int pluginTest() +{ + int s = 0; + for (int i = 1; i != 2000; ++i) + s += i; + fprintf(stderr, "in plugin test"); + return s; +} diff --git a/tests/manual/gdbdebugger/spacy-file/plugin/plugin.pro b/tests/manual/gdbdebugger/spacy-file/plugin/plugin.pro new file mode 100644 index 00000000000..3cad806e7af --- /dev/null +++ b/tests/manual/gdbdebugger/spacy-file/plugin/plugin.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +TARGET = plugin +DESTDIR = .. +CONFIG += shared + +SOURCES += "../plugin with space.cpp" + +macx { + QMAKE_LFLAGS_SONAME = -Wl,-install_name,@executable_path/../PlugIns/$${PROVIDER}/ +} else:linux-* { + #do the rpath by hand since it's not possible to use ORIGIN in QMAKE_RPATHDIR + QMAKE_RPATHDIR += \$\$ORIGIN/.. + IDE_PLUGIN_RPATH = $$join(QMAKE_RPATHDIR, ":") + QMAKE_LFLAGS += -Wl,-z,origin \'-Wl,-rpath,$${IDE_PLUGIN_RPATH}\' + QMAKE_RPATHDIR = +} + + diff --git a/tests/manual/gdbdebugger/spacy-file/spacy-file.pro b/tests/manual/gdbdebugger/spacy-file/spacy-file.pro new file mode 100644 index 00000000000..78c70731cd4 --- /dev/null +++ b/tests/manual/gdbdebugger/spacy-file/spacy-file.pro @@ -0,0 +1,4 @@ + +TEMPLATE = subdirs + +SUBDIRS += app plugin diff --git a/tests/manual/progressmanager/find.png b/tests/manual/progressmanager/find.png Binary files differnew file mode 100644 index 00000000000..cbe2f31521a --- /dev/null +++ b/tests/manual/progressmanager/find.png diff --git a/tests/manual/progressmanager/main.cpp b/tests/manual/progressmanager/main.cpp new file mode 100644 index 00000000000..e1289e07ccc --- /dev/null +++ b/tests/manual/progressmanager/main.cpp @@ -0,0 +1,42 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include <QtGui/QApplication> +#include "roundprogress.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + roundprogress w; + w.show(); + return a.exec(); +} diff --git a/tests/manual/progressmanager/roundprogress.cpp b/tests/manual/progressmanager/roundprogress.cpp new file mode 100644 index 00000000000..488ce4d265b --- /dev/null +++ b/tests/manual/progressmanager/roundprogress.cpp @@ -0,0 +1,70 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "roundprogress.h" +#include "multitask.h" +#include "runextensions.h" + +roundprogress::roundprogress(QWidget *parent) + : QWidget(parent), task(MyInternalTask(true)), task2(MyInternalTask(false)) +{ + ui.setupUi(this); + ui.progressButton->setIcon(QIcon("find.png")); + connect(ui.startButton, SIGNAL(clicked()), this, SLOT(start())); + connect(ui.startButton2, SIGNAL(clicked()), this, SLOT(start2())); + connect(ui.startBothButton, SIGNAL(clicked()), this, SLOT(start3())); + ui.startButton->setFocus(); +} + +void roundprogress::start() +{ + if (future.isRunning()) + return; + future = QtConcurrent::run(&MyInternalTask::run, &task); + ui.progressButton->setFuture(future); +} + +void roundprogress::start2() +{ + if (future.isRunning()) + return; + future = QtConcurrent::run(&MyInternalTask::run, &task2); + ui.progressButton->setFuture(future); +} + +void roundprogress::start3() +{ + if (future.isRunning()) + return; + future = QtConcurrent::run(&MyInternalTask::run, QList<MyInternalTask*>() << &task2 << &task); + ui.progressButton->setFuture(future); +} diff --git a/tests/manual/progressmanager/roundprogress.h b/tests/manual/progressmanager/roundprogress.h new file mode 100644 index 00000000000..f1e43ff5e73 --- /dev/null +++ b/tests/manual/progressmanager/roundprogress.h @@ -0,0 +1,118 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef ROUNDPROGRESS_H +#define ROUNDPROGRESS_H + +#include <QtGui/QMainWindow> +#include "ui_roundprogress.h" +#include <QtCore> +#include <QtGui> +#include <QtDebug> +#include <QtCore/QFutureInterface> +#include <QtCore/QFuture> + +class MyInternalTask; + +class MyInternalTask : public QObject +{ + Q_OBJECT +public: + static const int MAX = 10; + + MyInternalTask(bool withProgress) + { + m_hasProgress = withProgress; + if (m_hasProgress) + m_duration = 4000; + else + m_duration = 2500; + } + + MyInternalTask(const MyInternalTask &) : QObject() {} + + void run(QFutureInterface<void> &f) + { + m_future = &f; + m_count = 0; + m_future->setProgressRange(0, (m_hasProgress ? MAX : 0)); + m_future->setProgressValueAndText(m_count, tr("Starting...")); + m_loop = new QEventLoop; + m_timer = new QTimer; + m_timer->setInterval(m_duration/MAX); + m_timer->setSingleShot(false); + connect(m_timer, SIGNAL(timeout()), this, SLOT(advance())); + m_timer->start(); + m_loop->exec(); + delete m_timer; + delete m_loop; + } + +private slots: + void advance() + { + ++m_count; + m_future->setProgressValueAndText(m_count, tr("Something happening %1").arg(m_count)); + if (m_count == MAX || m_future->isCanceled()) { + m_future->setProgressValueAndText(m_count, tr("Finished!")); + m_loop->quit(); + } + } +private: + bool m_hasProgress; + QEventLoop *m_loop; + QTimer *m_timer; + QFutureInterface<void> *m_future; + int m_count; + int m_duration; +}; + +class roundprogress : public QWidget +{ + Q_OBJECT + +public: + roundprogress(QWidget *parent = 0); + ~roundprogress() {} + +private slots: + void start(); + void start2(); + void start3(); +private: + Ui::roundprogressClass ui; + MyInternalTask task; + MyInternalTask task2; + QFuture<void> future; +}; + +#endif // ROUNDPROGRESS_H diff --git a/tests/manual/progressmanager/roundprogress.pro b/tests/manual/progressmanager/roundprogress.pro new file mode 100644 index 00000000000..6e34bdca1d0 --- /dev/null +++ b/tests/manual/progressmanager/roundprogress.pro @@ -0,0 +1,15 @@ +TARGET = roundprogress +TEMPLATE = app +QT += core \ + gui +INCLUDEPATH += $$PWD/../../../src/plugins/core/progressmanager $$PWD/../../../src/libs/qtconcurrent +SOURCES += main.cpp \ + roundprogress.cpp \ + $$PWD/../../../src/plugins/core/progressmanager/progresspie.cpp \ + $$PWD/../../../src/plugins/core/progressmanager/futureprogress.cpp +HEADERS += roundprogress.h \ + $$PWD/../../../src/libs/qtconcurrent/multitask.h \ + $$PWD/../../../src/plugins/core/progressmanager/progresspie_p.h \ + $$PWD/../../../src/plugins/core/progressmanager/progresspie.h \ + $$PWD/../../../src/plugins/core/progressmanager/futureprogress.h +FORMS += roundprogress.ui diff --git a/tests/manual/progressmanager/roundprogress.ui b/tests/manual/progressmanager/roundprogress.ui new file mode 100644 index 00000000000..1c1fe4b4725 --- /dev/null +++ b/tests/manual/progressmanager/roundprogress.ui @@ -0,0 +1,55 @@ +<ui version="4.0" > + <class>roundprogressClass</class> + <widget class="QWidget" name="roundprogressClass" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>212</width> + <height>144</height> + </rect> + </property> + <property name="windowTitle" > + <string>Form</string> + </property> + <layout class="QGridLayout" > + <item row="0" column="0" > + <widget class="FutureProgress" name="progressButton" > + <property name="font" > + <font/> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QPushButton" name="startButton" > + <property name="text" > + <string>Start with progress</string> + </property> + </widget> + </item> + <item row="2" column="0" > + <widget class="QPushButton" name="startButton2" > + <property name="text" > + <string>Start with animation</string> + </property> + </widget> + </item> + <item row="3" column="0" > + <widget class="QPushButton" name="startBothButton" > + <property name="text" > + <string>Start both</string> + </property> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>FutureProgress</class> + <extends>QToolButton</extends> + <header>../../../src/plugins/core/progressmanager/futureprogress.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/tests/manual/proparser/main.cpp b/tests/manual/proparser/main.cpp new file mode 100644 index 00000000000..f2acfbf28a3 --- /dev/null +++ b/tests/manual/proparser/main.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 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 GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include <QtCore/QDebug> + +#include "proreader.h" +#include "proitems.h" +#include "proxml.h" + +int main(int argc, char *argv[]) +{ + ProReader pr; + ProFile *pf = pr.read(QString::fromUtf8(argv[1])); + + qDebug() << Qt4ProjectManager::Internal::ProXmlParser::itemToString(pf); + + return 0; +} diff --git a/tests/manual/proparser/proparser.pro b/tests/manual/proparser/proparser.pro new file mode 100644 index 00000000000..c822929991c --- /dev/null +++ b/tests/manual/proparser/proparser.pro @@ -0,0 +1,20 @@ +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . +CONFIG += console +QT += xml + +PROXMLPATH = ../../../src/plugins/qt4projectmanager/proparser +PROPARSERPATH = $$(QTDIR)/tools/linguist/shared +INCLUDEPATH += $$PROPARSERPATH $$PROXMLPATH + +# Input +HEADERS += $$PROPARSERPATH/proitems.h \ + $$PROXMLPATH/proxml.h \ + $$PROPARSERPATH/proreader.h +SOURCES += main.cpp \ + $$PROPARSERPATH/proitems.cpp \ + $$PROXMLPATH/proxml.cpp \ + $$PROPARSERPATH/proreader.cpp + diff --git a/tests/manual/proparser/test.pro b/tests/manual/proparser/test.pro new file mode 100644 index 00000000000..55921087c1f --- /dev/null +++ b/tests/manual/proparser/test.pro @@ -0,0 +1,27 @@ +#comment + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . +CONFIG += console +QT += xml + +win32 { + PROPARSERPATH = ../../some/other/test/test + unix:PROPARSERPATH = ../../test/test +} + +# test comment +PROPARSERPATH = ../../../src/plugins/qt4projectmanager/proparser +INCLUDEPATH += $$PROPARSERPATH + +# Input +HEADERS += $$PROPARSERPATH/proitems.h \ # test comment2 + $$PROPARSERPATH/proxml.h \ + $$PROPARSERPATH/proreader.h +SOURCES += main.cpp \ + $$PROPARSERPATH/proitems.cpp \ +# test comment 3 + $$PROPARSERPATH/proxml.cpp \ + $$PROPARSERPATH/proreader.cpp |