1
/***************************************************************************
2
* This file is part of KDevelop *
3
* Copyright 2008 Milian Wolff <mail@milianw.de> *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU Library General Public License as *
7
* published by the Free Software Foundation; either version 2 of the *
8
* License, or (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU Library General Public *
16
* License along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
21
#include "predeclarationbuilder.h"
25
#include <ktexteditor/smartrange.h>
26
#include <ktexteditor/smartinterface.h>
28
#include <language/duchain/stringhelpers.h>
29
#include <language/duchain/types/functiontype.h>
31
#include <klocalizedstring.h>
34
#include "parsesession.h"
36
#include "classdeclaration.h"
37
#include "functiondeclaration.h"
38
#include "variabledeclaration.h"
39
#include "structuretype.h"
41
using namespace KTextEditor;
42
using namespace KDevelop;
47
PreDeclarationBuilder::~PreDeclarationBuilder()
51
void PreDeclarationBuilder::visitClassDeclarationStatement(ClassDeclarationStatementAst * node)
53
setComment(formatComment(node, editor()));
55
IdentifierPair ids = identifierPairForNode(node->className);
56
DUChainWriteLocker lock(DUChain::lock());
57
ClassDeclaration* dec = openDefinition<ClassDeclaration>(ids.second, editorFindRange(node->className, node->className));
58
dec->setPrettyName(ids.first);
59
dec->setKind(KDevelop::Declaration::Type);
60
dec->clearBaseClasses();
61
dec->setClassType(ClassDeclarationData::Class);
63
switch (node->modifier->modifier) {
65
dec->setClassModifier(ClassDeclarationData::None);
68
dec->setClassModifier(ClassDeclarationData::Final);
71
dec->setClassModifier(ClassDeclarationData::Abstract);
75
dec->setClassModifier(ClassDeclarationData::None);
78
// build the type as well, to make this declaration usable
79
StructureType::Ptr type(new StructureType());
80
type->setPrettyName(ids.first);
81
type->setDeclaration(dec);
84
m_types->insert(node->className->string, dec);
87
PreDeclarationBuilderBase::visitClassDeclarationStatement(node);
92
void PreDeclarationBuilder::visitInterfaceDeclarationStatement(InterfaceDeclarationStatementAst *node)
94
setComment(formatComment(node, editor()));
96
IdentifierPair ids = identifierPairForNode(node->interfaceName);
97
DUChainWriteLocker lock(DUChain::lock());
98
ClassDeclaration* dec = openDefinition<ClassDeclaration>(ids.second, editorFindRange(node->interfaceName, node->interfaceName));
99
dec->setPrettyName(ids.first);
100
dec->setKind(KDevelop::Declaration::Type);
101
dec->clearBaseClasses();
102
dec->setClassType(ClassDeclarationData::Interface);
104
// build the type as well, to make this declaration usable
105
StructureType::Ptr type(new StructureType());
106
type->setPrettyName(ids.first);
107
type->setDeclaration(dec);
110
m_types->insert(node->interfaceName->string, dec);
113
PreDeclarationBuilderBase::visitInterfaceDeclarationStatement(node);
118
void PreDeclarationBuilder::visitClassVariable(ClassVariableAst* node)
120
m_upcomingClassVariables->append(identifierForNode(node->variable));
123
void PreDeclarationBuilder::visitFunctionDeclarationStatement(FunctionDeclarationStatementAst* node)
125
setComment(formatComment(node, editor()));
127
IdentifierPair ids = identifierPairForNode(node->functionName);
128
DUChainWriteLocker lock(DUChain::lock());
129
FunctionDeclaration *dec = openDefinition<FunctionDeclaration>(ids.second, editorFindRange(node->functionName, node->functionName));
130
dec->setPrettyName(ids.first);
131
dec->setKind(Declaration::Type);
132
dec->clearDefaultParameters();
134
FunctionType::Ptr type = FunctionType::Ptr(new FunctionType());
138
m_functions->insert(node->functionName->string, dec);
141
PreDeclarationBuilderBase::visitFunctionDeclarationStatement(node);
146
void PreDeclarationBuilder::closeContext()
148
// we don't want to cleanup here, see DeclarationBuilder::closeContext()
149
setCompilingContexts(false);
150
PreDeclarationBuilderBase::closeContext();
151
setCompilingContexts(true);