1
/* This file is part of KDevelop
2
Copyright 2006 Hamish Rodda <rodda@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
19
#include "parsesession.h"
21
#include "rpp/pp-location.h"
22
#include "rpp/pp-environment.h"
25
#include "memorypool.h"
26
#include <language/interfaces/iproblem.h>
27
#include <language/duchain/indexedstring.h>
28
#include <language/duchain/declaration.h>
33
#include "parentvisitor.h"
35
ParseSession::ParseSession()
43
ParseSession::~ParseSession()
47
delete m_locationTable;
50
TranslationUnitAST * ParseSession::topAstNode(void)
55
void ParseSession::topAstNode(TranslationUnitAST * node)
57
Q_ASSERT(!m_topAstNode);
62
void ParseSession::mapAstDuChain (AST * node , KDevelop::DeclarationPointer declaration)
64
//Duplicates shouldn't exist
65
Q_ASSERT(m_AstToDuchain.find(node) == m_AstToDuchain.end() ||
66
m_AstToDuchain[node] != declaration);
68
// NOTE: Don't call declaration->toString() here. It seems that you cannot
69
// assume at this point that the DUChain is at least locked for reading.
70
//kDebug() << "Mapping AST node: " << names[node->kind] <<
71
// "With Declaration: " << declaration->toString();
73
m_AstToDuchain[node] = declaration;
74
m_DuchainToAst[declaration] = node;
77
void ParseSession::mapAstUse(AST *node, const SimpleUse& use)
79
//Duplicates shouldn't exist(? Same for uses?)
80
if(m_AstToUse.contains(node) && m_AstToUse[node] != use)
81
kWarning() << "Found dupplicate use mapping for node" << node;
83
m_AstToUse[node] = use;
84
m_UseToAst[use] = node;
87
void ParseSession::setASTNodeParents()
89
ParentVisitor visitor(this);
90
visitor.visit(m_topAstNode);
93
void ParseSession::mapAstParent(AST* node, AST* parent)
95
m_AstToParent.insert(node, parent);
98
AST * ParseSession::astNodeFromDeclaration(KDevelop::DeclarationPointer declaration)
100
//declaration was not mapped
101
if(m_DuchainToAst.find(declaration) == m_DuchainToAst.end())
104
return m_DuchainToAst[declaration];
107
AST * ParseSession::astNodeFromDeclaration(KDevelop::Declaration * declaration)
109
return astNodeFromDeclaration(KDevelop::DeclarationPointer(declaration));
112
AST * ParseSession::astNodeFromUse(const SimpleUse &use) const
114
return m_UseToAst.value(use);
117
AST* ParseSession::parentAstNode(AST* node)
119
return m_AstToParent.value(node, 0);
122
KDevelop::DeclarationPointer ParseSession::declarationFromAstNode(AST * node)
124
//declaration was not mapped
125
if(m_AstToDuchain.find(node) == m_AstToDuchain.end())
126
return KDevelop::DeclarationPointer();
128
return m_AstToDuchain[node];
131
rpp::Anchor ParseSession::positionAt(std::size_t offset, bool collapseIfMacroExpansion) const
133
Q_ASSERT(m_locationTable);
135
return m_locationTable->positionAt(offset, m_contents, collapseIfMacroExpansion).first;
138
QPair<rpp::Anchor, uint> ParseSession::positionAndSpaceAt(std::size_t offset, bool collapseIfMacroExpansion) const
140
Q_ASSERT(m_locationTable);
142
return m_locationTable->positionAt(offset, m_contents, collapseIfMacroExpansion);
145
std::size_t ParseSession::size() const
147
return m_contents.size() + 1;
150
uint* ParseSession::contents()
152
return m_contents.data();
155
const uint* ParseSession::contents() const
157
return m_contents.data();
160
const PreprocessedContents& ParseSession::contentsVector() const
165
void ParseSession::setContents(const PreprocessedContents& contents, rpp::LocationTable* locationTable)
167
m_contents = contents;
168
m_locationTable = locationTable;
171
void ParseSession::setContentsAndGenerateLocationTable(const PreprocessedContents& contents)
173
m_contents = contents;
174
///@todo We need this in the lexer, the problem is that we copy the vector when doing this
175
m_contents.append(0);
176
m_contents.append(0);
177
m_contents.append(0);
178
m_contents.append(0);
180
m_locationTable = new rpp::LocationTable(m_contents);
183
void ParseSession::setUrl(const KDevelop::IndexedString& url)
188
const KDevelop::IndexedString& ParseSession::url() const