2015-08-31 16:28:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-08-31 16:28:26 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:14 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-08-31 16:28:26 +02:00
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-08-31 16:28:26 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "sourcelocation.h"
|
|
|
|
|
|
2016-09-07 10:42:12 +02:00
|
|
|
#include "clangdocument.h"
|
2016-07-01 15:07:32 +02:00
|
|
|
#include "clangfilepath.h"
|
2015-08-31 16:28:26 +02:00
|
|
|
#include "clangstring.h"
|
|
|
|
|
|
|
|
|
|
#include <utf8string.h>
|
|
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
|
#include <sourcelocationcontainer.h>
|
|
|
|
|
|
|
|
|
|
namespace ClangBackEnd {
|
|
|
|
|
|
2015-11-17 13:33:31 +01:00
|
|
|
SourceLocation::SourceLocation()
|
|
|
|
|
: cxSourceLocation(clang_getNullLocation())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 16:28:26 +02:00
|
|
|
const Utf8String &SourceLocation::filePath() const
|
|
|
|
|
{
|
2016-07-01 15:07:32 +02:00
|
|
|
if (isFilePathNormalized_)
|
|
|
|
|
return filePath_;
|
|
|
|
|
|
|
|
|
|
isFilePathNormalized_ = true;
|
|
|
|
|
filePath_ = FilePath::fromNativeSeparators(filePath_);
|
|
|
|
|
|
2015-08-31 16:28:26 +02:00
|
|
|
return filePath_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint SourceLocation::line() const
|
|
|
|
|
{
|
|
|
|
|
return line_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint SourceLocation::column() const
|
|
|
|
|
{
|
|
|
|
|
return column_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint SourceLocation::offset() const
|
|
|
|
|
{
|
|
|
|
|
return offset_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceLocationContainer SourceLocation::toSourceLocationContainer() const
|
|
|
|
|
{
|
2016-07-01 15:07:32 +02:00
|
|
|
return SourceLocationContainer(filePath(), line_, column_);
|
2015-08-31 16:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceLocation::SourceLocation(CXSourceLocation cxSourceLocation)
|
2015-11-17 13:33:31 +01:00
|
|
|
: cxSourceLocation(cxSourceLocation)
|
2015-08-31 16:28:26 +02:00
|
|
|
{
|
|
|
|
|
CXFile cxFile;
|
|
|
|
|
|
|
|
|
|
clang_getFileLocation(cxSourceLocation,
|
|
|
|
|
&cxFile,
|
|
|
|
|
&line_,
|
|
|
|
|
&column_,
|
|
|
|
|
&offset_);
|
|
|
|
|
|
|
|
|
|
filePath_ = ClangString(clang_getFileName(cxFile));
|
2016-07-01 15:07:32 +02:00
|
|
|
isFilePathNormalized_ = false;
|
2015-08-31 16:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-17 13:33:31 +01:00
|
|
|
SourceLocation::SourceLocation(CXTranslationUnit cxTranslationUnit,
|
|
|
|
|
const Utf8String &filePath,
|
|
|
|
|
uint line,
|
|
|
|
|
uint column)
|
|
|
|
|
: cxSourceLocation(clang_getLocation(cxTranslationUnit,
|
|
|
|
|
clang_getFile(cxTranslationUnit,
|
|
|
|
|
filePath.constData()),
|
|
|
|
|
line,
|
|
|
|
|
column)),
|
|
|
|
|
filePath_(filePath),
|
2015-12-02 20:07:29 +01:00
|
|
|
line_(line),
|
2016-07-01 15:07:32 +02:00
|
|
|
column_(column),
|
|
|
|
|
isFilePathNormalized_(true)
|
2015-11-17 13:33:31 +01:00
|
|
|
{
|
2016-01-11 15:20:04 +01:00
|
|
|
clang_getFileLocation(cxSourceLocation, 0, 0, 0, &offset_);
|
2015-11-17 13:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator==(const SourceLocation &first, const SourceLocation &second)
|
|
|
|
|
{
|
|
|
|
|
return clang_equalLocations(first.cxSourceLocation, second.cxSourceLocation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceLocation::operator CXSourceLocation() const
|
|
|
|
|
{
|
|
|
|
|
return cxSourceLocation;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 18:23:05 +02:00
|
|
|
std::ostream &operator<<(std::ostream &os, const SourceLocation &sourceLocation)
|
2015-08-31 16:28:26 +02:00
|
|
|
{
|
2015-11-17 13:33:31 +01:00
|
|
|
auto filePath = sourceLocation.filePath();
|
|
|
|
|
if (filePath.hasContent())
|
2017-06-13 18:23:05 +02:00
|
|
|
os << filePath << ", ";
|
2015-11-17 13:33:31 +01:00
|
|
|
|
2017-06-13 18:23:05 +02:00
|
|
|
os << "line: " << sourceLocation.line()
|
|
|
|
|
<< ", column: "<< sourceLocation.column()
|
|
|
|
|
<< ", offset: "<< sourceLocation.offset();
|
|
|
|
|
|
|
|
|
|
return os;
|
2015-08-31 16:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ClangBackEnd
|
|
|
|
|
|