forked from qt-creator/qt-creator
Obsoleted.
This commit is contained in:
@@ -1,866 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
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;
|
@@ -1,141 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
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;
|
@@ -1,91 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
@@ -1,90 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
@@ -1,99 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
||||
|
@@ -1,86 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
@@ -1,893 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
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;
|
||||
|
@@ -1,527 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
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;
|
@@ -1,77 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
@@ -1,68 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
@@ -1,168 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
@@ -1,109 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
@@ -1,150 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
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;
|
@@ -1,85 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
@@ -1,169 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
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;
|
@@ -1,95 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
@@ -1,204 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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;
|
||||
}
|
||||
|
@@ -1,94 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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
|
@@ -1,122 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
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;
|
||||
|
@@ -1,138 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
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;
|
@@ -1,89 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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;
|
||||
}
|
@@ -1,75 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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
|
@@ -1,62 +0,0 @@
|
||||
# #####################################################################
|
||||
# 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
|
@@ -1,204 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,72 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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
|
@@ -1,147 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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;
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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
|
@@ -1,81 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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"); */
|
||||
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,232 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
||||
|
@@ -1,68 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
Copyright 2006 Hamish Rodda <rodda@kde.org>
|
||||
|
||||
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;
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
Copyright 2006 Hamish Rodda <rodda@kde.org>
|
||||
|
||||
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
|
@@ -1,287 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
Copyright 2006 Hamish Rodda <rodda@kde.org>
|
||||
|
||||
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;
|
@@ -1,105 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
Copyright 2006 Hamish Rodda <rodda@kde.org>
|
||||
|
||||
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;
|
@@ -1,62 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
Copyright 2006 Hamish Rodda <rodda@kde.org>
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
@@ -1,78 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
|
||||
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;
|
@@ -1,289 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
Copyright 2006 Hamish Rodda <rodda@kde.org>
|
||||
|
||||
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;
|
||||
}
|
@@ -1,119 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <roberto@kdevelop.org>
|
||||
Copyright 2006 Hamish Rodda <rodda@kde.org>
|
||||
|
||||
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;
|
@@ -1,266 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <rodda@kde.org>
|
||||
|
||||
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);
|
||||
}
|
@@ -1,118 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <rodda@kde.org>
|
||||
|
||||
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 <rodda@kde.org>
|
||||
*/
|
||||
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
|
@@ -1,161 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <harry@kdevelop.org>
|
||||
Copyright 2006 Hamish Rodda <rodda@kde.org>
|
||||
|
||||
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);
|
||||
}
|
@@ -1,119 +0,0 @@
|
||||
/***************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** 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 <harry@kdevelop.org>
|
||||
Copyright 2006 Hamish Rodda <rodda@kde.org>
|
||||
|
||||
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
|
@@ -1,20 +0,0 @@
|
||||
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
|
Reference in New Issue
Block a user