Commit 910bdfed authored by Kevin Funk's avatar Kevin Funk

Move most of clangtypes.{cpp,h} to util/

Cleans up the duchain target a bit
parent 9d133626
......@@ -37,9 +37,10 @@
#include "duchain/clanghelpers.h"
#include "duchain/clangpch.h"
#include "duchain/clangtypes.h"
#include "duchain/tuduchain.h"
#include "duchain/parsesession.h"
#include "duchain/clangindex.h"
#include "util/clangtypes.h"
#include "debug.h"
#include "clangsupport.h"
......
......@@ -25,7 +25,7 @@
#include "clangparsejob.h"
#include "version.h"
#include "duchain/clangtypes.h"
#include "util/clangtypes.h"
#include "codecompletion/model.h"
......@@ -40,6 +40,7 @@
#include "codegen/simplerefactoring.h"
#include "codegen/adaptsignatureassistant.h"
#include "duchain/clangindex.h"
#include <language/assistant/staticassistantsmanager.h>
#include <language/assistant/renameassistant.h>
......
......@@ -21,9 +21,9 @@
#include "completionhelper.h"
#include "../duchain/clangtypes.h"
#include "../duchain/cursorkindtraits.h"
#include "../duchain/parsesession.h"
#include "../util/clangtypes.h"
#include <language/duchain/stringhelpers.h>
#include <language/editor/simplecursor.h>
......
......@@ -33,7 +33,7 @@
#include <language/codecompletion/normaldeclarationcompletionitem.h>
#include "../duchain/parsesession.h"
#include "../duchain/clangtypes.h"
#include "../util/clangtypes.h"
#include "../duchain/cursorkindtraits.h"
#include "../duchain/navigationwidget.h"
......
......@@ -38,10 +38,10 @@
#include <interfaces/icore.h>
#include "../duchain/parsesession.h"
#include "../duchain/clangtypes.h"
#include "../duchain/cursorkindtraits.h"
#include "../util/clangutils.h"
#include "../util/clangtypes.h"
using namespace KDevelop;
......
......@@ -32,7 +32,7 @@
#include <language/editor/documentcursor.h>
#include "../duchain/parsesession.h"
#include "../duchain/clangtypes.h"
#include "../util/clangtypes.h"
#include <interfaces/iassistant.h>
......
......@@ -2,8 +2,8 @@ kde4_add_library(kdevclangduchain SHARED
parsesession.cpp
clangdiagnosticevaluator.cpp
clangducontext.cpp
clangindex.cpp
clangproblem.cpp
clangtypes.cpp
debugvisitor.cpp
duchainutils.cpp
tuduchain.cpp
......
......@@ -20,9 +20,9 @@
*/
#include "clangdiagnosticevaluator.h"
#include "clangtypes.h"
#include "unknowndeclarationproblem.h"
#include "missingincludepathproblem.h"
#include "util/clangtypes.h"
#include <QString>
......
......@@ -26,10 +26,11 @@
#include <language/duchain/parsingenvironment.h>
#include <language/backgroundparser/urlparselock.h>
#include "clangtypes.h"
#include "tuduchain.h"
#include "parsesession.h"
#include "util/clangtypes.h"
using namespace KDevelop;
namespace {
......
/*
* This file is part of KDevelop
*
* Copyright 2013 Olivier de Gaalon <olivier.jg@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* 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 Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "clangindex.h"
#include "clangpch.h"
#include <util/path.h>
#include <language/backgroundparser/urlparselock.h>
#include <clang-c/Index.h>
using namespace KDevelop;
ClangIndex::ClangIndex()
: m_index(clang_createIndex(1 /*Exclude PCH Decls*/, qgetenv("KDEV_CLANG_DISPLAY_DIAGS") == "1" /*Display diags*/))
{
}
CXIndex ClangIndex::index() const
{
return m_index;
}
QSharedPointer<const ClangPCH> ClangIndex::pch(const Path& pchInclude, const Path::List& includePaths, const QHash<QString, QString>& defines)
{
if (!pchInclude.isValid()) {
return {};
}
UrlParseLock pchLock(IndexedString(pchInclude.pathOrUrl()));
static const QString pchExt = QString::fromLatin1(".pch");
if (QFile::exists(pchInclude.toLocalFile() + pchExt)) {
QReadLocker lock(&m_pchLock);
auto pch = m_pch.constFind(pchInclude);
if (pch != m_pch.constEnd()) {
return pch.value();
}
}
QSharedPointer<const ClangPCH> pch(new ClangPCH(pchInclude, includePaths, defines, this));
QWriteLocker lock(&m_pchLock);
m_pch.insert(pchInclude, pch);
return pch;
}
ClangIndex::~ClangIndex()
{
clang_disposeIndex(m_index);
}
/*
* This file is part of KDevelop
*
* Copyright 2013 Olivier de Gaalon <olivier.jg@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* 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 Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef CLANGINDEX_H
#define CLANGINDEX_H
#include "duchainexport.h"
#include <util/path.h>
#include <QReadWriteLock>
#include <QSharedPointer>
#include <clang-c/Index.h>
class ClangPCH;
class KDEVCLANGDUCHAIN_EXPORT ClangIndex
{
public:
ClangIndex();
~ClangIndex();
CXIndex index() const;
/**
* @returns the existing ClangPCH for the @param pchInclude
* The PCH is created using @param includePaths and @param defines if it doesn't exist
* This function is thread safe.
*/
QSharedPointer<const ClangPCH> pch(const KDevelop::Path& pchInclude,
const KDevelop::Path::List& includePaths,
const QHash<QString, QString>& defines);
private:
CXIndex m_index;
QReadWriteLock m_pchLock;
QHash<KDevelop::Path, QSharedPointer<const ClangPCH>> m_pch;
};
#endif //CLANGINDEX_H
......@@ -22,8 +22,8 @@
#include <language/duchain/duchain.h>
#include "clangtypes.h"
#include "clanghelpers.h"
#include "util/clangtypes.h"
using namespace KDevelop;
......
......@@ -21,7 +21,7 @@
#include "clangproblem.h"
#include "clangtypes.h"
#include "util/clangtypes.h"
#include <language/duchain/duchainlock.h>
#include <language/codegen/documentchangeset.h>
......
......@@ -20,7 +20,7 @@
*/
#include "debugvisitor.h"
#include "clangtypes.h"
#include "util/clangtypes.h"
namespace {
......
......@@ -23,11 +23,12 @@
#include "parsesession.h"
#include "clangproblem.h"
#include "clangtypes.h"
#include "clangdiagnosticevaluator.h"
#include "todoextractor.h"
#include "clanghelpers.h"
#include "clangindex.h"
#include "debug.h"
#include "util/clangtypes.h"
#include <KLocale>
#include <KMimeType>
......
......@@ -21,7 +21,7 @@
#include "todoextractor.h"
#include "clangtypes.h"
#include "../util/clangtypes.h"
#include <language/duchain/problem.h>
#include <language/duchain/stringhelpers.h>
......
......@@ -26,9 +26,9 @@
#include "templatehelpers.h"
#include "cursorkindtraits.h"
#include "clanghelpers.h"
#include "clangtypes.h"
#include "clangducontext.h"
#include "util/clangutils.h"
#include "util/clangtypes.h"
#include <util/pushvalue.h>
......
......@@ -23,9 +23,9 @@
#include "unknowndeclarationproblem.h"
#include "clanghelpers.h"
#include "clangtypes.h"
#include "../debug.h"
#include "../util/clangutils.h"
#include "../util/clangtypes.h"
#include <interfaces/icore.h>
#include <interfaces/iprojectcontroller.h>
......
......@@ -52,7 +52,7 @@ kde4_add_unit_test(test_clangutils
target_link_libraries(test_clangutils
${KDEVPLATFORM_TESTS_LIBRARIES}
${QT_QTTEST_LIBRARY}
kdevclangduchain
${CLANG_CLANG_LIB}
)
########### next target ###############
......
......@@ -24,8 +24,9 @@
#include <language/util/debuglanguageparserhelper.h>
#include "../duchain/parsesession.h"
#include "../duchain/clangtypes.h"
#include "../duchain/debugvisitor.h"
#include "../duchain/clangindex.h"
#include "../util/clangtypes.h"
using namespace KDevelop;
using namespace KDevelopUtils;
......
......@@ -21,7 +21,7 @@
#include "test_clangutils.h"
#include "../util/clangutils.h"
#include "../duchain/clangtypes.h" // TODO: Move this to util/
#include "../util/clangtypes.h"
#include <language/editor/simplerange.h>
......@@ -33,6 +33,8 @@
#include <qtest_kde.h>
#include <QtTest>
#include <memory>
QTEST_KDEMAIN(TestClangUtils, GUI)
namespace {
......@@ -63,11 +65,11 @@ void runVisitor(const QByteArray& code, CXCursorVisitor visitor, CXClientData da
tempFile.write(code);
tempFile.flush();
ClangIndex index;
std::unique_ptr<void, void(*)(CXIndex)> index(clang_createIndex(1, 1), clang_disposeIndex);
const QVector<const char*> args = {"-std=c++11", "-xc++", "-Wall", "-nostdinc", "-nostdinc++"};
CXTranslationUnit unit;
const CXErrorCode errorCode = clang_parseTranslationUnit2(
index.index(), qPrintable(tempFile.fileName()),
index.get(), qPrintable(tempFile.fileName()),
args.data(), args.size(),
nullptr, 0,
CXTranslationUnit_None,
......
......@@ -28,7 +28,7 @@
#include <tests/testfile.h>
#include <duchain/parsesession.h>
#include <duchain/clangtypes.h>
#include <util/clangtypes.h>
#include <language/codecompletion/codecompletiontesthelper.h>
#include <codecompletion/completionhelper.h>
#include <codecompletion/context.h>
......
......@@ -18,10 +18,11 @@
#include "test_problems.h"
#include "../duchain/clangindex.h"
#include "../duchain/clangproblem.h"
#include "../duchain/clangtypes.h"
#include "../duchain/parsesession.h"
#include "../duchain/unknowndeclarationproblem.h"
#include "../util/clangtypes.h"
#include <language/duchain/duchain.h>
#include <language/duchain/duchainutils.h>
......
......@@ -5,5 +5,6 @@ include_directories(
add_library(kdevclangutil OBJECT
clangutils.cpp
clangtypes.cpp
)
set_target_properties(kdevclangutil PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
......@@ -27,11 +27,8 @@
#include <language/editor/documentcursor.h>
#include <language/editor/documentrange.h>
#include <language/backgroundparser/urlparselock.h>
#include <util/path.h>
#include "clangpch.h"
using namespace KDevelop;
namespace {
......@@ -47,45 +44,6 @@ inline T cursorForCXSrcLoc(CXSourceLocation loc)
}
ClangIndex::ClangIndex()
: m_index(clang_createIndex(1 /*Exclude PCH Decls*/, qgetenv("KDEV_CLANG_DISPLAY_DIAGS") == "1" /*Display diags*/))
{
}
CXIndex ClangIndex::index() const
{
return m_index;
}
QSharedPointer<const ClangPCH> ClangIndex::pch(const Path& pchInclude, const Path::List& includePaths, const QHash<QString, QString>& defines)
{
if (!pchInclude.isValid()) {
return {};
}
UrlParseLock pchLock(IndexedString(pchInclude.pathOrUrl()));
static const QString pchExt = QString::fromLatin1(".pch");
if (QFile::exists(pchInclude.toLocalFile() + pchExt)) {
QReadLocker lock(&m_pchLock);
auto pch = m_pch.constFind(pchInclude);
if (pch != m_pch.constEnd()) {
return pch.value();
}
}
QSharedPointer<const ClangPCH> pch(new ClangPCH(pchInclude, includePaths, defines, this));
QWriteLocker lock(&m_pchLock);
m_pch.insert(pchInclude, pch);
return pch;
}
ClangIndex::~ClangIndex()
{
clang_disposeIndex(m_index);
}
ClangString::ClangString(CXString string)
: string(string)
{
......
......@@ -24,14 +24,9 @@
#define CLANGTYPES_H
#include <clang-c/Index.h>
#include <QHash>
#include <QSharedPointer>
#include <QReadWriteLock>
#include <util/path.h>
#include "duchainexport.h"
namespace KDevelop {
class DocumentCursor;
class DocumentRange;
......@@ -41,33 +36,7 @@ class CursorInRevision;
class RangeInRevision;
}
class ClangPCH;
class KDEVCLANGDUCHAIN_EXPORT ClangIndex
{
public:
ClangIndex();
~ClangIndex();
CXIndex index() const;
/**
* @returns the existing ClangPCH for the @param pchInclude
* The PCH is created using @param includePaths and @param defines if it doesn't exist
* This function is thread safe.
*/
QSharedPointer<const ClangPCH> pch(const KDevelop::Path& pchInclude,
const KDevelop::Path::List& includePaths,
const QHash<QString, QString>& defines);
private:
CXIndex m_index;
QReadWriteLock m_pchLock;
QHash<KDevelop::Path, QSharedPointer<const ClangPCH>> m_pch;
};
class KDEVCLANGDUCHAIN_EXPORT ClangString
class ClangString
{
public:
ClangString(CXString string);
......@@ -89,7 +58,7 @@ private:
CXString string;
};
class KDEVCLANGDUCHAIN_EXPORT ClangLocation
class ClangLocation
{
public:
ClangLocation(CXSourceLocation cursor);
......@@ -107,7 +76,7 @@ private:
CXSourceLocation location;
};
class KDEVCLANGDUCHAIN_EXPORT ClangRange
class ClangRange
{
public:
ClangRange(CXSourceRange range);
......
......@@ -21,7 +21,7 @@
#include "clangutils.h"
#include "../duchain/clangtypes.h"
#include "../util/clangtypes.h"
#include "../duchain/cursorkindtraits.h"
#include <language/duchain/indexedstring.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment