id
int64 0
755k
| file_name
stringlengths 3
109
| file_path
stringlengths 13
185
| content
stringlengths 31
9.38M
| size
int64 31
9.38M
| language
stringclasses 1
value | extension
stringclasses 11
values | total_lines
int64 1
340k
| avg_line_length
float64 2.18
149k
| max_line_length
int64 7
2.22M
| alphanum_fraction
float64 0
1
| repo_name
stringlengths 6
65
| repo_stars
int64 100
47.3k
| repo_forks
int64 0
12k
| repo_open_issues
int64 0
3.4k
| repo_license
stringclasses 9
values | repo_extraction_date
stringclasses 92
values | exact_duplicates_redpajama
bool 2
classes | near_duplicates_redpajama
bool 2
classes | exact_duplicates_githubcode
bool 2
classes | exact_duplicates_stackv2
bool 1
class | exact_duplicates_stackv1
bool 2
classes | near_duplicates_githubcode
bool 2
classes | near_duplicates_stackv1
bool 2
classes | near_duplicates_stackv2
bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
749,050
|
document_p.h
|
KDE_gwenview/lib/document/document_p.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2013 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef DOCUMENT_P_H
#define DOCUMENT_P_H
// STL
#include <memory>
// Local
#include <document/documentjob.h>
#include <imagemetainfomodel.h>
// KF
// Qt
#include <QImage>
#include <QPointer>
#include <QQueue>
#include <QUndoStack>
#include <QUrl>
namespace Exiv2
{
class Image;
}
namespace Gwenview
{
using DocumentJobQueue = QQueue<DocumentJob *>;
struct DocumentPrivate {
Document *q;
AbstractDocumentImpl *mImpl;
QUrl mUrl;
bool mKeepRawData;
QPointer<DocumentJob> mCurrentJob;
DocumentJobQueue mJobQueue;
/**
* @defgroup imagedata should be reset in reload()
* @{
*/
QSize mSize;
QImage mImage;
QMap<int, QImage> mDownSampledImageMap;
std::unique_ptr<Exiv2::Image> mExiv2Image;
MimeTypeUtils::Kind mKind;
QByteArray mFormat;
ImageMetaInfoModel mImageMetaInfoModel;
QUndoStack mUndoStack;
QString mErrorString;
Cms::Profile::Ptr mCmsProfile;
/** @} */
void scheduleImageLoading(int invertedZoom);
void scheduleImageDownSampling(int invertedZoom);
void downSampleImage(int invertedZoom);
};
class DownSamplingJob : public DocumentJob
{
Q_OBJECT
public:
DownSamplingJob(int invertedZoom)
: mInvertedZoom(invertedZoom)
{
}
void doStart() override;
int mInvertedZoom;
};
} // namespace
#endif /* DOCUMENT_P_H */
| 2,171
|
C++
|
.h
| 76
| 25.592105
| 81
| 0.760597
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,051
|
savejob.h
|
KDE_gwenview/lib/document/savejob.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2010 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef SAVEJOB_H
#define SAVEJOB_H
#include <lib/gwenviewlib_export.h>
// Qt
// KF
// Local
#include <lib/document/documentjob.h>
class QByteArray;
class QUrl;
namespace Gwenview
{
class DocumentLoadedImpl;
struct SaveJobPrivate;
class GWENVIEWLIB_EXPORT SaveJob : public DocumentJob
{
Q_OBJECT
public:
SaveJob(DocumentLoadedImpl *impl, const QUrl &url, const QByteArray &format);
~SaveJob() override;
void saveInternal();
QUrl oldUrl() const;
QUrl newUrl() const;
protected Q_SLOTS:
void doStart() override;
void slotResult(KJob *) override;
protected:
bool doKill() override;
private Q_SLOTS:
void finishSave();
private:
SaveJobPrivate *const d;
};
} // namespace
#endif /* SAVEJOB_H */
| 1,563
|
C++
|
.h
| 50
| 28.98
| 81
| 0.780308
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,052
|
baloosemanticinfobackend.h
|
KDE_gwenview/lib/semanticinfo/baloosemanticinfobackend.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
Copyright 2014 Vishesh Handa <me@vhanda.in>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef BALOOSEMANTICINFOBACKEND_H
#define BALOOSEMANTICINFOBACKEND_H
#include <lib/gwenviewlib_export.h>
// Qt
// KF
// Local
#include "abstractsemanticinfobackend.h"
namespace Gwenview
{
/**
* A real metadata backend using Baloo to store and retrieve metadata.
*/
class GWENVIEWLIB_EXPORT BalooSemanticInfoBackend : public AbstractSemanticInfoBackEnd
{
Q_OBJECT
public:
explicit BalooSemanticInfoBackend(QObject *parent);
~BalooSemanticInfoBackend() override;
TagSet allTags() const override;
void refreshAllTags() override;
void storeSemanticInfo(const QUrl &, const SemanticInfo &) override;
void retrieveSemanticInfo(const QUrl &) override;
QString labelForTag(const SemanticInfoTag &) const override;
SemanticInfoTag tagForLabel(const QString &) override;
private:
struct Private;
Private *const d;
};
} // namespace
#endif /* BALOOSEMANTICINFOBACKEND_H */
| 1,782
|
C++
|
.h
| 47
| 35.510638
| 86
| 0.798251
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,053
|
fakesemanticinfobackend.h
|
KDE_gwenview/lib/semanticinfo/fakesemanticinfobackend.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef FAKESEMANTICINFOBACKEND_H
#define FAKESEMANTICINFOBACKEND_H
#include <lib/gwenviewlib_export.h>
// Qt
#include <QHash>
#include <QUrl>
// KF
// Local
#include "abstractsemanticinfobackend.h"
namespace Gwenview
{
/**
* A fake metadata backend, useful to test the ui layer.
* It provides fake rating values based on the image url.
*/
class GWENVIEWLIB_EXPORT FakeSemanticInfoBackEnd : public AbstractSemanticInfoBackEnd
{
Q_OBJECT
public:
enum InitializeMode {
InitializeEmpty,
InitializeRandom,
};
FakeSemanticInfoBackEnd(QObject *parent, InitializeMode initializeMode);
TagSet allTags() const override;
void refreshAllTags() override;
void storeSemanticInfo(const QUrl &, const SemanticInfo &) override;
void retrieveSemanticInfo(const QUrl &) override;
QString labelForTag(const SemanticInfoTag &) const override;
SemanticInfoTag tagForLabel(const QString &) override;
private:
void mergeTagsWithAllTags(const TagSet &);
QHash<QUrl, SemanticInfo> mSemanticInfoForUrl;
InitializeMode mInitializeMode;
TagSet mAllTags;
};
} // namespace
#endif /* FAKESEMANTICINFOBACKEND_H */
| 1,988
|
C++
|
.h
| 54
| 34.037037
| 85
| 0.789859
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,055
|
tagwidget.h
|
KDE_gwenview/lib/semanticinfo/tagwidget.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef TAGWIDGET_H
#define TAGWIDGET_H
#include <lib/gwenviewlib_export.h>
// Qt
#include <QMap>
#include <QWidget>
// KF
// Local
#include <lib/semanticinfo/abstractsemanticinfobackend.h>
namespace Gwenview
{
using TagInfo = QMap<SemanticInfoTag, bool>;
struct TagWidgetPrivate;
class GWENVIEWLIB_EXPORT TagWidget : public QWidget
{
Q_OBJECT
public:
explicit TagWidget(QWidget *parent = nullptr);
~TagWidget() override;
void setTagInfo(const TagInfo &);
void setSemanticInfoBackEnd(AbstractSemanticInfoBackEnd *);
Q_SIGNALS:
void tagAssigned(const SemanticInfoTag &);
void tagRemoved(const SemanticInfoTag &);
private Q_SLOTS:
void addTagFromComboBox();
void assignTag(const SemanticInfoTag &tag);
void removeTag(const SemanticInfoTag &);
private:
TagWidgetPrivate *const d;
};
} // namespace
#endif /* TAGWIDGET_H */
| 1,690
|
C++
|
.h
| 49
| 32.244898
| 81
| 0.790025
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,056
|
semanticinfodirmodel.h
|
KDE_gwenview/lib/semanticinfo/semanticinfodirmodel.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef SEMANTICINFODIRMODEL_H
#define SEMANTICINFODIRMODEL_H
// Qt
// KF
#include <KDirModel>
// Local
class QUrl;
namespace Gwenview
{
class AbstractSemanticInfoBackEnd;
struct SemanticInfo;
struct SemanticInfoDirModelPrivate;
/**
* Extends KDirModel by providing read/write access to image metadata such as
* rating, tags and descriptions.
*/
class SemanticInfoDirModel : public KDirModel
{
Q_OBJECT
public:
enum {
RatingRole = 0x21a43a51,
DescriptionRole = 0x26FB33FA,
TagsRole = 0x0462F0A8,
};
SemanticInfoDirModel(QObject *parent);
~SemanticInfoDirModel() override;
void clearSemanticInfoCache();
bool semanticInfoAvailableForIndex(const QModelIndex &) const;
void retrieveSemanticInfoForIndex(const QModelIndex &);
SemanticInfo semanticInfoForIndex(const QModelIndex &) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &data, int role = Qt::EditRole) override;
AbstractSemanticInfoBackEnd *semanticInfoBackEnd() const;
Q_SIGNALS:
void semanticInfoRetrieved(const QUrl &, const SemanticInfo &);
private:
SemanticInfoDirModelPrivate *const d;
private Q_SLOTS:
void slotSemanticInfoRetrieved(const QUrl &url, const SemanticInfo &);
void slotRowsAboutToBeRemoved(const QModelIndex &, int, int);
void slotModelAboutToBeReset();
};
} // namespace
#endif /* SEMANTICINFODIRMODEL_H */
| 2,308
|
C++
|
.h
| 61
| 34.885246
| 99
| 0.788124
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,057
|
abstractsemanticinfobackend.h
|
KDE_gwenview/lib/semanticinfo/abstractsemanticinfobackend.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef ABSTRACTSEMANTICINFOBACKEND_H
#define ABSTRACTSEMANTICINFOBACKEND_H
#include <lib/gwenviewlib_export.h>
// Qt
#include <QObject>
#include <QSet>
// KF
// Local
class QUrl;
namespace Gwenview
{
using SemanticInfoTag = QString;
/**
* This class represents the set of tags associated to an url.
*
* It provides convenience methods to convert to and from QVariant, which are
* useful to communicate with SemanticInfoDirModel.
*/
class GWENVIEWLIB_EXPORT TagSet : public QSet<SemanticInfoTag>
{
public:
TagSet();
TagSet(const QSet<SemanticInfoTag> &);
QVariant toVariant() const;
static TagSet fromVariant(const QVariant &);
static TagSet fromList(const QList<SemanticInfoTag> &);
private:
TagSet(const QList<SemanticInfoTag> &);
};
/**
* A POD struct used by AbstractSemanticInfoBackEnd to store the metadata
* associated to an url.
*/
struct SemanticInfo {
int mRating;
QString mDescription;
TagSet mTags;
};
/**
* An abstract class, used by SemanticInfoDirModel to store and retrieve metadata.
*/
class GWENVIEWLIB_EXPORT AbstractSemanticInfoBackEnd : public QObject
{
Q_OBJECT
public:
explicit AbstractSemanticInfoBackEnd(QObject *parent);
virtual TagSet allTags() const = 0;
virtual void refreshAllTags() = 0;
virtual void storeSemanticInfo(const QUrl &, const SemanticInfo &) = 0;
virtual void retrieveSemanticInfo(const QUrl &) = 0;
virtual QString labelForTag(const SemanticInfoTag &) const = 0;
/**
* Return a tag for a label. Will emit tagAdded() if the tag had to be
* created.
*/
virtual SemanticInfoTag tagForLabel(const QString &) = 0;
Q_SIGNALS:
void semanticInfoRetrieved(const QUrl &, const SemanticInfo &);
/**
* Emitted whenever a new tag is added to allTags()
*/
void tagAdded(const SemanticInfoTag &, const QString &label);
};
} // namespace
#endif /* ABSTRACTSEMANTICINFOBACKEND_H */
| 2,764
|
C++
|
.h
| 81
| 31.320988
| 82
| 0.763931
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,058
|
tagmodel.h
|
KDE_gwenview/lib/semanticinfo/tagmodel.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef TAGMODEL_H
#define TAGMODEL_H
#include <lib/gwenviewlib_export.h>
// Qt
#include <QStandardItemModel>
// KF
// Local
namespace Gwenview
{
using SemanticInfoTag = QString;
class AbstractSemanticInfoBackEnd;
class TagSet;
struct TagModelPrivate;
class GWENVIEWLIB_EXPORT TagModel : public QStandardItemModel
{
Q_OBJECT
public:
explicit TagModel(QObject *);
~TagModel() override;
enum {
TagRole = Qt::UserRole,
SortRole,
AssignmentStatusRole,
};
enum AssignmentStatus {
PartiallyAssigned,
FullyAssigned,
};
void setSemanticInfoBackEnd(AbstractSemanticInfoBackEnd *);
void setTagSet(const TagSet &set);
/**
* Convenience method to create a TagModel showing all tags available in
* AbstractSemanticInfoBackEnd
*/
static TagModel *createAllTagsModel(QObject *parent, AbstractSemanticInfoBackEnd *);
public Q_SLOTS:
/**
* Add a new tag. If label is empty, backend will be queried for it
*/
void addTag(const SemanticInfoTag &tag, const QString &label = QString(), AssignmentStatus status = FullyAssigned);
void removeTag(const SemanticInfoTag &tag);
private:
TagModelPrivate *const d;
};
} // namespace
#endif /* TAGMODEL_H */
| 2,084
|
C++
|
.h
| 62
| 30.241935
| 119
| 0.762
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,059
|
sorteddirmodel.h
|
KDE_gwenview/lib/semanticinfo/sorteddirmodel.h
|
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef SORTEDDIRMODEL_H
#define SORTEDDIRMODEL_H
#include <config-gwenview.h>
// Qt
#include <QPointer>
// KF
#include <KDirSortFilterProxyModel>
// Local
#include <lib/gwenviewlib_export.h>
#include <lib/mimetypeutils.h>
class KDirLister;
class KFileItem;
class QUrl;
namespace Gwenview
{
class AbstractSemanticInfoBackEnd;
struct SortedDirModelPrivate;
#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
struct SemanticInfo;
#endif
class SortedDirModel;
class GWENVIEWLIB_EXPORT AbstractSortedDirModelFilter : public QObject
{
public:
AbstractSortedDirModelFilter(SortedDirModel *model);
~AbstractSortedDirModelFilter() override;
SortedDirModel *model() const
{
return mModel;
}
virtual bool needsSemanticInfo() const = 0;
/**
* Returns true if index should be accepted.
* Warning: index is a source index of SortedDirModel
*/
virtual bool acceptsIndex(const QModelIndex &index) const = 0;
private:
QPointer<SortedDirModel> mModel;
};
/**
* This model makes it possible to show all images in a folder.
* It can filter images based on name and metadata.
*/
class GWENVIEWLIB_EXPORT SortedDirModel : public KDirSortFilterProxyModel
{
Q_OBJECT
public:
explicit SortedDirModel(QObject *parent = nullptr);
~SortedDirModel() override;
KDirLister *dirLister() const;
/**
* Redefines the dir lister, useful for debugging
*/
void setDirLister(KDirLister *);
KFileItem itemForIndex(const QModelIndex &index) const;
QUrl urlForIndex(const QModelIndex &index) const;
KFileItem itemForSourceIndex(const QModelIndex &sourceIndex) const;
QModelIndex indexForItem(const KFileItem &item) const;
QModelIndex indexForUrl(const QUrl &url) const;
void setKindFilter(MimeTypeUtils::Kinds);
MimeTypeUtils::Kinds kindFilter() const;
void adjustKindFilter(MimeTypeUtils::Kinds, bool set);
/**
* A list of file extensions we should skip
*/
void setBlackListedExtensions(const QStringList &list);
void addFilter(AbstractSortedDirModelFilter *);
void removeFilter(AbstractSortedDirModelFilter *);
void reload();
AbstractSemanticInfoBackEnd *semanticInfoBackEnd() const;
#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
SemanticInfo semanticInfoForSourceIndex(const QModelIndex &sourceIndex) const;
#endif
bool hasDocuments() const;
public Q_SLOTS:
void applyFilters();
protected:
bool filterAcceptsRow(int row, const QModelIndex &parent) const override;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
private Q_SLOTS:
void doApplyFilters();
private:
friend struct SortedDirModelPrivate;
SortedDirModelPrivate *const d;
};
} // namespace
#endif /* SORTEDDIRMODEL_H */
| 3,549
|
C++
|
.h
| 102
| 31.578431
| 84
| 0.780673
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,060
|
zoomcombobox_p.h
|
KDE_gwenview/lib/zoomcombobox/zoomcombobox_p.h
|
// SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef GWENVIEW_ZOOMCOMBOBOX_P_H
#define GWENVIEW_ZOOMCOMBOBOX_P_H
#include "zoomcombobox.h"
namespace Gwenview
{
class ZoomValidator : public QValidator
{
Q_OBJECT
Q_PROPERTY(qreal minimum READ minimum WRITE setMinimum NOTIFY changed)
Q_PROPERTY(qreal maximum READ maximum WRITE setMaximum NOTIFY changed)
public:
explicit ZoomValidator(qreal minimum, qreal maximum, ZoomComboBox *q, ZoomComboBoxPrivate *d, QWidget *parent = nullptr);
~ZoomValidator() override;
qreal minimum() const;
void setMinimum(const qreal minimum);
qreal maximum() const;
void setMaximum(const qreal maximum);
QValidator::State validate(QString &input, int &pos) const override;
private:
qreal m_minimum;
qreal m_maximum;
ZoomComboBox *m_zoomComboBox;
ZoomComboBoxPrivate *m_zoomComboBoxPrivate;
Q_DISABLE_COPY(ZoomValidator)
};
class ZoomComboBoxPrivate
{
Q_DECLARE_PUBLIC(ZoomComboBox)
public:
ZoomComboBoxPrivate(ZoomComboBox *q);
void setActions(QAction *zoomToFitAction, QAction *zoomToFillAction, QAction *actualSizeAction);
public:
ZoomComboBox *const q_ptr;
QAction *mZoomToFitAction = nullptr;
QAction *mZoomToFillAction = nullptr;
QAction *mActualSizeAction = nullptr;
qreal value = 1.0;
ZoomValidator *validator = nullptr;
int lastSelectedIndex = 0;
qreal lastCustomZoomValue = 1.0;
};
}
#endif // GWENVIEW_ZOOMCOMBOBOX_P_H
| 1,541
|
C++
|
.h
| 45
| 30.6
| 125
| 0.769075
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,061
|
zoomcombobox.h
|
KDE_gwenview/lib/zoomcombobox/zoomcombobox.h
|
// SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef GWENVIEW_ZOOMCOMBOBOX_H
#define GWENVIEW_ZOOMCOMBOBOX_H
#include <QComboBox>
#include <lib/gwenviewlib_export.h>
class QWheelEvent;
namespace Gwenview
{
class ZoomComboBoxPrivate;
/**
* QComboBox subclass designed to be somewhat similar to QSpinBox.
* Allows the user to use non-integer combobox list items,
* but only accepts integers as custom input.
*
* This class is structured in a way so that changes to the zoom done through
* user interaction are signalled to the outside. On the other hand changes
* done to the visual state of this class without user interaction will not
* lead to emitted zoom changes/signals from this class.
*/
class GWENVIEWLIB_EXPORT ZoomComboBox : public QComboBox
{
Q_OBJECT
Q_PROPERTY(qreal value READ value WRITE setValue)
Q_PROPERTY(qreal minimum READ minimum WRITE setMinimum)
Q_PROPERTY(qreal maximum READ maximum WRITE setMaximum)
public:
explicit ZoomComboBox(QWidget *parent = nullptr);
~ZoomComboBox() override;
void setActions(QAction *zoomToFitAction, QAction *zoomToFillAction, QAction *actualSizeAction);
qreal value() const;
/**
* Called when the value that is being displayed should change.
* Calling this method doesn't affect the zoom of the currently viewed image.
*/
void setValue(const qreal value);
qreal minimum() const;
void setMinimum(const qreal minimum);
qreal maximum() const;
void setMaximum(const qreal maximum);
/// Gets an integer value from text.
qreal valueFromText(const QString &text, bool *ok = nullptr) const;
/// Gets appropriately decorated text from an integer value.
QString textFromValue(const qreal value) const;
void updateDisplayedText();
void showPopup() override;
Q_SIGNALS:
void zoomChanged(qreal zoom);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
/**
* Makes sure using the mouse wheel on the combobox works as
* expected even though we sometimes programmatically change
* the currentIndex() of this ComboBox.
* @see updateCurrentIndex()
*/
void wheelEvent(QWheelEvent *event) override;
private:
/**
* The current index is the row in the popup of the ComboBox that is
* highlighted.
* This method updates the current index so it matches the current zoom
* state of the application.
* If the zoom value that is currently used doesn't exist as a row in
* the ComboBox, the currentIndex is set to -1 which hides the highlight.
*/
void updateCurrentIndex();
void moveCurrentIndex(bool moveUp);
private Q_SLOTS:
/**
* This method changes the zoom mode or value of the currently displayed image in response to
* user interaction with the Combobox' dropdown menu.
* @param index of the zoom mode or value that the user interacted with.
*/
void changeZoomTo(int index);
/**
* Sets the index as the fallback when the popup menu is closed without selection in the
* future and then calls changeZoomTo().
* @see changeZoomTo()
*/
void activateAndChangeZoomTo(int index);
private:
const std::unique_ptr<ZoomComboBoxPrivate> d_ptr;
Q_DECLARE_PRIVATE(ZoomComboBox)
Q_DISABLE_COPY(ZoomComboBox)
};
}
#endif // GWENVIEW_ZOOMCOMBOBOX_H
| 3,535
|
C++
|
.h
| 90
| 35.033333
| 100
| 0.742765
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,062
|
waylandgestures.h
|
KDE_gwenview/lib/waylandgestures/waylandgestures.h
|
/*
Gwenview: an image viewer
Copyright 2019 Steffen Hartleib <steffenhartleib@t-online.de>
Copyright 2022 Carl Schwan <carlschwan@kde.org>
Copyright 2022 Bharadwaj Raju <bharadwaj.raju777@protonmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#pragma once
#include <lib/gwenviewlib_export.h>
#include <QObject>
class PointerGestures;
class PinchGesture;
namespace Gwenview
{
class GWENVIEWLIB_EXPORT WaylandGestures : public QObject
{
Q_OBJECT
public:
WaylandGestures(QObject *parent = nullptr);
~WaylandGestures();
void init();
void setStartZoom(qreal);
void setZoomModifier(qreal);
void setRotationThreshold(qreal);
Q_SIGNALS:
void pinchGestureStarted();
void pinchZoomChanged(double);
private:
PointerGestures *m_pointerGestures;
PinchGesture *m_pinchGesture;
double m_startZoom;
double m_zoomModifier;
};
} // namespace
| 1,533
|
C++
|
.h
| 44
| 32.409091
| 81
| 0.797023
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,063
|
mpris2service.h
|
KDE_gwenview/lib/mpris2/mpris2service.h
|
/*
Gwenview: an image viewer
Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef MPRIS2SERVICE_H
#define MPRIS2SERVICE_H
#include <gwenviewlib_export.h>
// Qt
#include <QAction>
#include <QObject>
#include <QString>
class QAction;
namespace Gwenview
{
class SlideShow;
class ContextManager;
class GWENVIEWLIB_EXPORT Mpris2Service : public QObject
{
Q_OBJECT
public:
Mpris2Service(SlideShow *slideShow,
ContextManager *contextManager,
QAction *toggleSlideShowAction,
QAction *fullScreenAction,
QAction *previousAction,
QAction *nextAction,
QObject *parent);
~Mpris2Service() override;
private:
void registerOnDBus();
void unregisterOnDBus();
void onLockScreenLockedChanged(bool isLocked);
private:
QString mMpris2ServiceName;
void onFullScreenActionToggled();
QAction *m_fullscreenAction;
};
}
#endif
| 1,656
|
C++
|
.h
| 50
| 28.96
| 79
| 0.753769
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,064
|
mprismediaplayer2.h
|
KDE_gwenview/lib/mpris2/mprismediaplayer2.h
|
/*
Gwenview: an image viewer
Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef MPRISMEDIAPLAYER2_H
#define MPRISMEDIAPLAYER2_H
#include "dbusabstractadaptor.h"
// Qt
#include <QStringList>
class QAction;
namespace Gwenview
{
// https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html
class MprisMediaPlayer2 : public DBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2")
Q_PROPERTY(bool CanQuit READ canQuit CONSTANT)
Q_PROPERTY(bool CanRaise READ canRaise CONSTANT)
Q_PROPERTY(bool CanSetFullscreen READ canSetFullscreen CONSTANT)
Q_PROPERTY(QString Identity READ identity CONSTANT)
Q_PROPERTY(QString DesktopEntry READ desktopEntry CONSTANT)
Q_PROPERTY(bool HasTrackList READ hasTrackList CONSTANT)
Q_PROPERTY(bool Fullscreen READ isFullscreen WRITE setFullscreen)
Q_PROPERTY(QStringList SupportedUriSchemes READ supportedUriSchemes CONSTANT)
Q_PROPERTY(QStringList SupportedMimeTypes READ supportedMimeTypes CONSTANT)
public:
MprisMediaPlayer2(const QString &objectDBusPath, QAction *fullScreenAction, QObject *parent);
~MprisMediaPlayer2() override;
public Q_SLOTS: // D-Bus API
void Quit();
void Raise();
private:
bool canQuit() const;
bool canRaise() const;
bool canSetFullscreen() const;
bool hasTrackList() const;
QString identity() const;
QString desktopEntry() const;
bool isFullscreen() const;
void setFullscreen(bool isFullscreen);
QStringList supportedUriSchemes() const;
QStringList supportedMimeTypes() const;
void onFullScreenActionToggled(bool checked);
private:
QAction *const mFullScreenAction;
};
}
#endif
| 2,407
|
C++
|
.h
| 60
| 36.983333
| 97
| 0.795445
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,065
|
lockscreenwatcher.h
|
KDE_gwenview/lib/mpris2/lockscreenwatcher.h
|
/*
Gwenview: an image viewer
Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef LOCKSCREENWATCHER_H
#define LOCKSCREENWATCHER_H
// Qt
#include <QObject>
class OrgFreedesktopScreenSaverInterface;
class QDBusPendingCallWatcher;
namespace Gwenview
{
class LockScreenWatcher : public QObject
{
Q_OBJECT
public:
explicit LockScreenWatcher(QObject *parent);
~LockScreenWatcher() override;
public:
bool isLocked() const;
Q_SIGNALS:
void isLockedChanged(bool locked);
private:
void onScreenSaverActiveChanged(bool isActive);
void onActiveQueried(QDBusPendingCallWatcher *watcher);
void onScreenSaverServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner);
void onServiceRegisteredQueried();
void onServiceOwnerQueried();
private:
OrgFreedesktopScreenSaverInterface *mScreenSaverInterface = nullptr;
bool mLocked = false;
};
}
#endif
| 1,628
|
C++
|
.h
| 45
| 33.8
| 120
| 0.81007
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,066
|
mprismediaplayer2player.h
|
KDE_gwenview/lib/mpris2/mprismediaplayer2player.h
|
/*
Gwenview: an image viewer
Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef MPRISMEDIAPLAYER2PLAYER_H
#define MPRISMEDIAPLAYER2PLAYER_H
#include "dbusabstractadaptor.h"
// lib
#include <document/document.h>
class QDBusObjectPath;
class QAction;
namespace Gwenview
{
class SlideShow;
class ContextManager;
// https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html
class MprisMediaPlayer2Player : public DBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player")
Q_PROPERTY(QString PlaybackStatus READ playbackStatus)
Q_PROPERTY(double Rate READ rate WRITE setRate)
Q_PROPERTY(QVariantMap Metadata READ metadata)
Q_PROPERTY(double Volume READ volume WRITE setVolume)
Q_PROPERTY(qlonglong Position READ position)
Q_PROPERTY(double MinimumRate READ minimumRate CONSTANT)
Q_PROPERTY(double MaximumRate READ maximumRate CONSTANT)
Q_PROPERTY(bool Shuffle READ isShuffle WRITE setShuffle)
Q_PROPERTY(bool CanControl READ canControl CONSTANT)
Q_PROPERTY(bool CanPlay READ canPlay)
Q_PROPERTY(bool CanPause READ canPause)
Q_PROPERTY(bool CanGoNext READ canGoNext)
Q_PROPERTY(bool CanGoPrevious READ canGoPrevious)
Q_PROPERTY(bool CanSeek READ canSeek CONSTANT)
public:
MprisMediaPlayer2Player(const QString &objectDBusPath,
SlideShow *slideShow,
ContextManager *contextManager,
QAction *toggleSlideShowAction,
QAction *fullScreenAction,
QAction *previousAction,
QAction *nextAction,
QObject *parent);
~MprisMediaPlayer2Player() override;
public Q_SLOTS: // D-Bus API
void Next();
void Previous();
void Pause();
void PlayPause();
void Stop();
void Play();
void Seek(qlonglong Offset);
void SetPosition(const QDBusObjectPath &trackId, qlonglong pos);
void OpenUri(const QString &uri);
Q_SIGNALS: // D-Bus API
void Seeked(qlonglong Position) const;
private:
QString playbackStatus() const;
double rate() const;
QVariantMap metadata() const;
double volume() const;
qlonglong position() const;
double minimumRate() const;
double maximumRate() const;
bool isShuffle() const;
bool canGoNext() const;
bool canGoPrevious() const;
bool canPlay() const;
bool canPause() const;
bool canSeek() const;
bool canControl() const;
void setRate(double newRate);
void setVolume(double volume);
void setShuffle(bool isShuffle);
bool updatePlaybackStatus();
void onSlideShowStateChanged();
void onCurrentUrlChanged(const QUrl &url);
void onRandomActionToggled(bool checked);
void onToggleSlideShowActionChanged();
void onPreviousActionChanged();
void onNextActionChanged();
void onMetaInfoUpdated();
private:
SlideShow *mSlideShow;
ContextManager *mContextManager;
QAction *mToggleSlideShowAction;
QAction *mFullScreenAction;
QAction *mPreviousAction;
QAction *mNextAction;
bool mSlideShowEnabled;
bool mPreviousEnabled;
bool mNextEnabled;
QString mPlaybackStatus;
QVariantMap mMetaData;
Document::Ptr mCurrentDocument;
};
}
#endif
| 4,041
|
C++
|
.h
| 109
| 31.688073
| 81
| 0.738619
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,067
|
dbusabstractadaptor.h
|
KDE_gwenview/lib/mpris2/dbusabstractadaptor.h
|
/*
Gwenview: an image viewer
Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef DBUSABSTRACTADAPTOR_H
#define DBUSABSTRACTADAPTOR_H
// Qt
#include <QDBusAbstractAdaptor>
#include <QVariantMap>
namespace Gwenview
{
/**
* Extension of QDBusAbstractAdaptor for proper signalling of D-Bus object property changes
*
* QDBusAbstractAdaptor seems to fail on mapping QObject properties
* to D-Bus object properties when it comes to signalling changes to a property.
* The NOTIFY entry of Q_PROPERTY is not turned into respective D-Bus signalling of a
* property change. So we have to do this explicitly ourselves, instead of using a normal
* QObject signal and expecting the adaptor to translate it.
*
* To reduce D-Bus traffic, all registered property changes are accumulated and squashed
* between event loops where then the D-Bus signal is emitted.
*/
class DBusAbstractAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
public:
/**
* Ideally we could query the D-Bus path of the object when used, but no idea yet how to do that.
* So one has to additionally pass here the D-Bus path at which the object is registered
* for which this interface is added.
*
* @param objectDBusPath D-Bus name of the property
* @param parent memory management parent or nullptr
*/
explicit DBusAbstractAdaptor(const QString &objectDBusPath, QObject *parent);
protected:
/**
* @param propertyName D-Bus name of the property
* @param value the new value of the property
*/
void signalPropertyChange(const QString &propertyName, const QVariant &value);
private Q_SLOTS:
void emitPropertiesChangeDBusSignal();
private:
QVariantMap mChangedProperties;
const QString mObjectPath;
};
}
#endif // DBUSABSTRACTADAPTOR_H
| 2,490
|
C++
|
.h
| 61
| 38.098361
| 101
| 0.780306
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,068
|
decoratedtag.h
|
KDE_gwenview/lib/decoratedtag/decoratedtag.h
|
// SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef GWENVIEW_DECORATEDTAG_H
#define GWENVIEW_DECORATEDTAG_H
#include <QLabel>
#include <lib/gwenviewlib_export.h>
namespace Gwenview
{
class DecoratedTagPrivate;
/**
* A label with a custom background under it.
*
* TODO: Turn this into a more interactive control and make it look like Manuel's mockup.
* Should probably be turned into a QAbstractButton subclass or something.
*/
class GWENVIEWLIB_EXPORT DecoratedTag : public QLabel
{
Q_OBJECT
public:
explicit DecoratedTag(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
explicit DecoratedTag(const QString &text, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~DecoratedTag() override;
protected:
void changeEvent(QEvent *event) override;
void paintEvent(QPaintEvent *event) override;
private:
const std::unique_ptr<DecoratedTagPrivate> d_ptr;
Q_DECLARE_PRIVATE(DecoratedTag)
};
}
#endif // GWENVIEW_DECORATEDTAG_H
| 1,065
|
C++
|
.h
| 31
| 31.903226
| 113
| 0.773879
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,069
|
thumbnailprovider.h
|
KDE_gwenview/lib/thumbnailprovider/thumbnailprovider.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab
/* Gwenview - A simple image viewer for KDE
Copyright 2000-2004 Aurélien Gâteau <agateau@kde.org>
This class is based on the ImagePreviewJob class from Konqueror.
*/
/* This file is part of the KDE project
Copyright (C) 2000 David Faure <faure@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef THUMBNAILPROVIDER_H
#define THUMBNAILPROVIDER_H
#include <lib/gwenviewlib_export.h>
// Qt
#include <QImage>
#include <QPixmap>
#include <QPointer>
// KF
#include <KFileItem>
#include <KIO/Job>
// Local
#include <lib/thumbnailgroup.h>
namespace Gwenview
{
class ThumbnailGenerator;
class ThumbnailWriter;
/**
* A job that determines the thumbnails for the images in the current directory
*/
class GWENVIEWLIB_EXPORT ThumbnailProvider : public KIO::Job
{
Q_OBJECT
public:
ThumbnailProvider();
~ThumbnailProvider() override;
void stop();
/**
* To be called whenever items are removed from the view
*/
void removeItems(const KFileItemList &itemList);
/**
* Remove all pending items
*/
void removePendingItems();
/**
* Returns the list of items waiting for a thumbnail
*/
const KFileItemList &pendingItems() const;
/**
* Add items to the job
*/
void appendItems(const KFileItemList &items);
/**
* Defines size of thumbnails to generate
*/
void setThumbnailGroup(ThumbnailGroup::Enum);
bool isRunning() const;
/**
* Returns the thumbnail base dir, independent of the thumbnail size
*/
static QString thumbnailBaseDir();
/**
* Sets the thumbnail base dir, useful for unit-testing
*/
static void setThumbnailBaseDir(const QString &);
/**
* Returns the thumbnail base dir, for the @p group
*/
static QString thumbnailBaseDir(ThumbnailGroup::Enum group);
/**
* Delete the thumbnail for the @p url
*/
static void deleteImageThumbnail(const QUrl &url);
/**
* Move a thumbnail to match a file move
*/
static void moveThumbnail(const QUrl &oldUrl, const QUrl &newUrl);
/**
* Returns true if all thumbnails have been written to disk. Useful for
* unit-testing.
*/
static bool isThumbnailWriterEmpty();
Q_SIGNALS:
/**
* Emitted when the thumbnail for the @p item has been loaded
*/
void thumbnailLoaded(const KFileItem &item, const QPixmap &, const QSize &, qulonglong);
void thumbnailLoadingFailed(const KFileItem &item);
/**
* Queue is empty
*/
void finished();
protected:
void slotResult(KJob *job) override;
private Q_SLOTS:
void determineNextIcon();
void slotGotPreview(const KFileItem &, const QPixmap &);
void checkThumbnail();
void thumbnailReady(const QImage &, const QSize &);
void emitThumbnailLoadingFailed();
private:
enum {
STATE_STATORIG,
STATE_DOWNLOADORIG,
STATE_PREVIEWJOB,
STATE_NEXTTHUMB,
} mState;
KFileItemList mItems;
KFileItem mCurrentItem;
// The Url of the current item (always equivalent to m_items.first()->item()->url())
QUrl mCurrentUrl;
// The Uri of the original image (might be different from mCurrentUrl.url())
QString mOriginalUri;
// The modification time of the original image
time_t mOriginalTime;
// The file size of the original image
KIO::filesize_t mOriginalFileSize;
// The thumbnail path
QString mThumbnailPath;
// The temporary path for remote urls
QString mTempPath;
// Thumbnail group
ThumbnailGroup::Enum mThumbnailGroup;
ThumbnailGenerator *mThumbnailGenerator;
QPointer<ThumbnailGenerator> mPreviousThumbnailGenerator;
QStringList mPreviewPlugins;
void createNewThumbnailGenerator();
void abortSubjob();
void startCreatingThumbnail(const QString &path);
void emitThumbnailLoaded(const QImage &img, const QSize &size);
QImage loadThumbnailFromCache() const;
};
} // namespace
#endif /* THUMBNAILPROVIDER_H */
| 4,758
|
C++
|
.h
| 143
| 28.594406
| 92
| 0.715755
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,070
|
thumbnailgenerator.h
|
KDE_gwenview/lib/thumbnailprovider/thumbnailgenerator.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2012 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef THUMBNAILGENERATOR_H
#define THUMBNAILGENERATOR_H
// Local
#include <lib/thumbnailgroup.h>
// KF
#include <KFileItem>
// Qt
#include <QImage>
#include <QMutex>
#include <QThread>
#include <QWaitCondition>
namespace Gwenview
{
struct ThumbnailContext {
QImage mImage;
int mOriginalWidth;
int mOriginalHeight;
bool mNeedCaching;
bool load(const QString &pixPath, int pixelSize);
};
class ThumbnailGenerator : public QThread
{
Q_OBJECT
public:
ThumbnailGenerator();
// Because we override run(), like you're not really supposed to do, we
// can't trust isRunning()
bool isStopped();
void load(const QString &originalUri,
time_t originalTime,
KIO::filesize_t originalFileSize,
const QString &originalMimeType,
const QString &pixPath,
const QString &thumbnailPath,
ThumbnailGroup::Enum group);
void cancel();
QString originalUri() const;
time_t originalTime() const;
KIO::filesize_t originalFileSize() const;
QString originalMimeType() const;
protected:
void run() override;
Q_SIGNALS:
void done(const QImage &, const QSize &);
void thumbnailReadyToBeCached(const QString &thumbnailPath, const QImage &);
private:
bool testCancel();
void cacheThumbnail();
QImage mImage;
QString mPixPath;
QString mThumbnailPath;
QString mOriginalUri;
time_t mOriginalTime;
KIO::filesize_t mOriginalFileSize;
QString mOriginalMimeType;
int mOriginalWidth;
int mOriginalHeight;
QMutex mMutex;
QWaitCondition mCond;
ThumbnailGroup::Enum mThumbnailGroup;
bool mCancel;
bool mStopped = false;
};
} // namespace
#endif /* THUMBNAILGENERATOR_H */
| 2,581
|
C++
|
.h
| 81
| 27.839506
| 81
| 0.743042
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,071
|
thumbnailwriter.h
|
KDE_gwenview/lib/thumbnailprovider/thumbnailwriter.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2012 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef THUMBNAILWRITER_H
#define THUMBNAILWRITER_H
// Local
// KF
// Qt
#include <QHash>
#include <QMutex>
#include <QThread>
class QImage;
namespace Gwenview
{
/**
* Store thumbnails to disk when done generating them
*/
class ThumbnailWriter : public QThread
{
Q_OBJECT
public:
// Return thumbnail if it has still not been stored
QImage value(const QString &) const;
bool isEmpty() const;
public Q_SLOTS:
void queueThumbnail(const QString &, const QImage &);
protected:
void run() override;
private:
using Cache = QHash<QString, QImage>;
Cache mCache;
mutable QMutex mMutex;
};
} // namespace
#endif /* THUMBNAILWRITER_H */
| 1,490
|
C++
|
.h
| 48
| 28.895833
| 81
| 0.77614
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,073
|
fitshandler.h
|
KDE_gwenview/lib/imageformats/fitshandler.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#pragma once
#include <QImageIOHandler>
namespace Gwenview
{
/**
* A FITS handler.
*/
class FitsHandler : public QImageIOHandler
{
public:
bool canRead() const override;
bool read(QImage *image) override;
bool supportsOption(ImageOption option) const override;
QVariant option(ImageOption option) const override;
};
} // namespace
| 1,169
|
C++
|
.h
| 32
| 34.625
| 81
| 0.796625
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,074
|
fitsplugin.h
|
KDE_gwenview/lib/imageformats/fitsplugin.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#pragma once
#define QT_STATICPLUGIN
#include <QByteArray>
#include <QImageIOPlugin>
class QImageIOHandler;
class QIODevice;
extern const QStaticPlugin qt_static_plugin_FitsPlugin();
class Q_CORE_EXPORT FitsPlugin : public QImageIOPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "fitsplugin.json")
public:
~FitsPlugin() override
{
}
Capabilities capabilities(QIODevice *device, const QByteArray &format) const override;
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override;
};
| 1,423
|
C++
|
.h
| 34
| 39.617647
| 103
| 0.801455
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,075
|
bayer.h
|
KDE_gwenview/lib/imageformats/fitsformat/bayer.h
|
/*
* 1394-Based Digital Camera Control Library
*
* Bayer pattern decoding functions
*
* Written by Damien Douxchamps and Frederic Devernay
* The original VNG and AHD Bayer decoding are from Dave Coffin's DCRAW.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* clang-format off */
#pragma once
#include <stdint.h>
/**
* Error codes returned by most libdc1394 functions.
*
* General rule: 0 is success, negative denotes a problem.
*/
typedef enum {
DC1394_SUCCESS = 0,
DC1394_FAILURE = -1,
DC1394_NOT_A_CAMERA = -2,
DC1394_FUNCTION_NOT_SUPPORTED = -3,
DC1394_CAMERA_NOT_INITIALIZED = -4,
DC1394_MEMORY_ALLOCATION_FAILURE = -5,
DC1394_TAGGED_REGISTER_NOT_FOUND = -6,
DC1394_NO_ISO_CHANNEL = -7,
DC1394_NO_BANDWIDTH = -8,
DC1394_IOCTL_FAILURE = -9,
DC1394_CAPTURE_IS_NOT_SET = -10,
DC1394_CAPTURE_IS_RUNNING = -11,
DC1394_RAW1394_FAILURE = -12,
DC1394_FORMAT7_ERROR_FLAG_1 = -13,
DC1394_FORMAT7_ERROR_FLAG_2 = -14,
DC1394_INVALID_ARGUMENT_VALUE = -15,
DC1394_REQ_VALUE_OUTSIDE_RANGE = -16,
DC1394_INVALID_FEATURE = -17,
DC1394_INVALID_VIDEO_FORMAT = -18,
DC1394_INVALID_VIDEO_MODE = -19,
DC1394_INVALID_FRAMERATE = -20,
DC1394_INVALID_TRIGGER_MODE = -21,
DC1394_INVALID_TRIGGER_SOURCE = -22,
DC1394_INVALID_ISO_SPEED = -23,
DC1394_INVALID_IIDC_VERSION = -24,
DC1394_INVALID_COLOR_CODING = -25,
DC1394_INVALID_COLOR_FILTER = -26,
DC1394_INVALID_CAPTURE_POLICY = -27,
DC1394_INVALID_ERROR_CODE = -28,
DC1394_INVALID_BAYER_METHOD = -29,
DC1394_INVALID_VIDEO1394_DEVICE = -30,
DC1394_INVALID_OPERATION_MODE = -31,
DC1394_INVALID_TRIGGER_POLARITY = -32,
DC1394_INVALID_FEATURE_MODE = -33,
DC1394_INVALID_LOG_TYPE = -34,
DC1394_INVALID_BYTE_ORDER = -35,
DC1394_INVALID_STEREO_METHOD = -36,
DC1394_BASLER_NO_MORE_SFF_CHUNKS = -37,
DC1394_BASLER_CORRUPTED_SFF_CHUNK = -38,
DC1394_BASLER_UNKNOWN_SFF_CHUNK = -39,
} dc1394error_t;
#define DC1394_ERROR_MIN DC1394_BASLER_UNKNOWN_SFF_CHUNK
#define DC1394_ERROR_MAX DC1394_SUCCESS
#define DC1394_ERROR_NUM (DC1394_ERROR_MAX - DC1394_ERROR_MIN + 1)
/**
* Enumeration of video modes. Note that the notion of IIDC "format" is not present here, except in the format_7 name.
*/
typedef enum {
DC1394_VIDEO_MODE_160x120_YUV444 = 64,
DC1394_VIDEO_MODE_320x240_YUV422,
DC1394_VIDEO_MODE_640x480_YUV411,
DC1394_VIDEO_MODE_640x480_YUV422,
DC1394_VIDEO_MODE_640x480_RGB8,
DC1394_VIDEO_MODE_640x480_MONO8,
DC1394_VIDEO_MODE_640x480_MONO16,
DC1394_VIDEO_MODE_800x600_YUV422,
DC1394_VIDEO_MODE_800x600_RGB8,
DC1394_VIDEO_MODE_800x600_MONO8,
DC1394_VIDEO_MODE_1024x768_YUV422,
DC1394_VIDEO_MODE_1024x768_RGB8,
DC1394_VIDEO_MODE_1024x768_MONO8,
DC1394_VIDEO_MODE_800x600_MONO16,
DC1394_VIDEO_MODE_1024x768_MONO16,
DC1394_VIDEO_MODE_1280x960_YUV422,
DC1394_VIDEO_MODE_1280x960_RGB8,
DC1394_VIDEO_MODE_1280x960_MONO8,
DC1394_VIDEO_MODE_1600x1200_YUV422,
DC1394_VIDEO_MODE_1600x1200_RGB8,
DC1394_VIDEO_MODE_1600x1200_MONO8,
DC1394_VIDEO_MODE_1280x960_MONO16,
DC1394_VIDEO_MODE_1600x1200_MONO16,
DC1394_VIDEO_MODE_EXIF,
DC1394_VIDEO_MODE_FORMAT7_0,
DC1394_VIDEO_MODE_FORMAT7_1,
DC1394_VIDEO_MODE_FORMAT7_2,
DC1394_VIDEO_MODE_FORMAT7_3,
DC1394_VIDEO_MODE_FORMAT7_4,
DC1394_VIDEO_MODE_FORMAT7_5,
DC1394_VIDEO_MODE_FORMAT7_6,
DC1394_VIDEO_MODE_FORMAT7_7,
} dc1394video_mode_t;
#define DC1394_VIDEO_MODE_MIN DC1394_VIDEO_MODE_160x120_YUV444
#define DC1394_VIDEO_MODE_MAX DC1394_VIDEO_MODE_FORMAT7_7
#define DC1394_VIDEO_MODE_NUM (DC1394_VIDEO_MODE_MAX - DC1394_VIDEO_MODE_MIN + 1)
/* Special min/max are defined for Format_7 */
#define DC1394_VIDEO_MODE_FORMAT7_MIN DC1394_VIDEO_MODE_FORMAT7_0
#define DC1394_VIDEO_MODE_FORMAT7_MAX DC1394_VIDEO_MODE_FORMAT7_7
#define DC1394_VIDEO_MODE_FORMAT7_NUM (DC1394_VIDEO_MODE_FORMAT7_MAX - DC1394_VIDEO_MODE_FORMAT7_MIN + 1)
/**
* Enumeration of colour codings. For details on the data format please read the IIDC specifications.
*/
typedef enum {
DC1394_COLOR_CODING_MONO8 = 352,
DC1394_COLOR_CODING_YUV411,
DC1394_COLOR_CODING_YUV422,
DC1394_COLOR_CODING_YUV444,
DC1394_COLOR_CODING_RGB8,
DC1394_COLOR_CODING_MONO16,
DC1394_COLOR_CODING_RGB16,
DC1394_COLOR_CODING_MONO16S,
DC1394_COLOR_CODING_RGB16S,
DC1394_COLOR_CODING_RAW8,
DC1394_COLOR_CODING_RAW16,
} dc1394color_coding_t;
#define DC1394_COLOR_CODING_MIN DC1394_COLOR_CODING_MONO8
#define DC1394_COLOR_CODING_MAX DC1394_COLOR_CODING_RAW16
#define DC1394_COLOR_CODING_NUM (DC1394_COLOR_CODING_MAX - DC1394_COLOR_CODING_MIN + 1)
/**
* RAW sensor filters. These elementary tiles tesselate the image plane in RAW modes. RGGB should be interpreted in 2D as
*
* RG
* GB
*
* and similarly for other filters.
*/
typedef enum {
DC1394_COLOR_FILTER_RGGB = 512,
DC1394_COLOR_FILTER_GBRG,
DC1394_COLOR_FILTER_GRBG,
DC1394_COLOR_FILTER_BGGR,
} dc1394color_filter_t;
#define DC1394_COLOR_FILTER_MIN DC1394_COLOR_FILTER_RGGB
#define DC1394_COLOR_FILTER_MAX DC1394_COLOR_FILTER_BGGR
#define DC1394_COLOR_FILTER_NUM (DC1394_COLOR_FILTER_MAX - DC1394_COLOR_FILTER_MIN + 1)
/**
* Byte order for YUV formats (may be expanded to RGB in the future)
*
* IIDC cameras always return data in UYVY order, but conversion functions can change this if requested.
*/
typedef enum { DC1394_BYTE_ORDER_UYVY = 800, DC1394_BYTE_ORDER_YUYV, } dc1394byte_order_t;
#define DC1394_BYTE_ORDER_MIN DC1394_BYTE_ORDER_UYVY
#define DC1394_BYTE_ORDER_MAX DC1394_BYTE_ORDER_YUYV
#define DC1394_BYTE_ORDER_NUM (DC1394_BYTE_ORDER_MAX - DC1394_BYTE_ORDER_MIN + 1)
/**
* A struct containing a list of color codings
*/
typedef struct
{
uint32_t num;
dc1394color_coding_t codings[DC1394_COLOR_CODING_NUM];
} dc1394color_codings_t;
/**
* A struct containing a list of video modes
*/
typedef struct
{
uint32_t num;
dc1394video_mode_t modes[DC1394_VIDEO_MODE_NUM];
} dc1394video_modes_t;
/**
* Yet another boolean data type
*/
typedef enum { DC1394_FALSE = 0, DC1394_TRUE, } dc1394bool_t;
/**
* Yet another boolean data type, a bit more oriented towards electrical-engineers
*/
typedef enum { DC1394_OFF = 0, DC1394_ON, } dc1394switch_t;
/**
* A list of de-mosaicing techniques for Bayer-patterns.
*
* The speed of the techniques can vary greatly, as well as their quality.
*/
typedef enum {
DC1394_BAYER_METHOD_NEAREST = 0,
DC1394_BAYER_METHOD_SIMPLE,
DC1394_BAYER_METHOD_BILINEAR,
DC1394_BAYER_METHOD_HQLINEAR,
DC1394_BAYER_METHOD_DOWNSAMPLE,
DC1394_BAYER_METHOD_EDGESENSE,
DC1394_BAYER_METHOD_VNG,
DC1394_BAYER_METHOD_AHD,
} dc1394bayer_method_t;
#define DC1394_BAYER_METHOD_MIN DC1394_BAYER_METHOD_NEAREST
#define DC1394_BAYER_METHOD_MAX DC1394_BAYER_METHOD_AHD
#define DC1394_BAYER_METHOD_NUM (DC1394_BAYER_METHOD_MAX - DC1394_BAYER_METHOD_MIN + 1)
typedef struct
{
dc1394bayer_method_t method; /* Debayer method */
dc1394color_filter_t filter; /* Debayer pattern */
int offsetX, offsetY; /* Debayer offset */
} BayerParams;
/************************************************************************************************
* *
* Color conversion functions for cameras that can output raw Bayer pattern images (color *
* codings DC1394_COLOR_CODING_RAW8 and DC1394_COLOR_CODING_RAW16). *
* *
* Credits and sources: *
* - Nearest Neighbor : OpenCV library *
* - Bilinear : OpenCV library *
* - HQLinear : High-Quality Linear Interpolation For Demosaicing Of Bayer-Patterned *
* Color Images, by Henrique S. Malvar, Li-wei He, and Ross Cutler, *
* in Proceedings of the ICASSP'04 Conference. *
* - Edge Sense II : Laroche, Claude A. "Apparatus and method for adaptively interpolating *
* a full color image utilizing chrominance gradients" *
* U.S. Patent 5,373,322. Based on the code found on the website *
* http://www-ise.stanford.edu/~tingchen/ Converted to C and adapted to *
* all four elementary patterns. *
* - Downsample : "Known to the Ancients" *
* - Simple : Implemented from the information found in the manual of Allied Vision *
* Technologies (AVT) cameras. *
* - VNG : Variable Number of Gradients, a method described in *
* http://www-ise.stanford.edu/~tingchen/algodep/vargra.html *
* Sources import from DCRAW by Frederic Devernay. DCRAW is a RAW *
* converter program by Dave Coffin. URL: *
* https://www.dechifro.org/dcraw/ *
* - AHD : Adaptive Homogeneity-Directed Demosaicing Algorithm, by K. Hirakawa *
* and T.W. Parks, IEEE Transactions on Image Processing, Vol. 14, Nr. 3, *
* March 2005, pp. 360 - 369. *
* *
************************************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/**
* Perform de-mosaicing on an 8-bit image buffer
*/
dc1394error_t dc1394_bayer_decoding_8bit(const uint8_t *bayer, uint8_t *rgb, uint32_t width, uint32_t height,
dc1394color_filter_t tile, dc1394bayer_method_t method);
/**
* Perform de-mosaicing on an 16-bit image buffer
*/
dc1394error_t dc1394_bayer_decoding_16bit(const uint16_t *bayer, uint16_t *rgb, uint32_t width, uint32_t height,
dc1394color_filter_t tile, dc1394bayer_method_t method, uint32_t bits);
#ifdef __cplusplus
}
#endif
| 11,590
|
C++
|
.h
| 257
| 41.782101
| 121
| 0.625122
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,076
|
fitsdata.h
|
KDE_gwenview/lib/imageformats/fitsformat/fitsdata.h
|
/***************************************************************************
Gwenview: an image viewer
fitsimage.cpp - FITS Image
-------------------
begin : Tue Feb 24 2004
copyright : (C) 2004 by Jasem Mutlaq
copyright : (C) 2017 by Csaba Kertesz
email : mutlaqja@ikarustech.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* Some code fragments were adapted from Peter Kirchgessner's FITS plugin*
* See http://members.aol.com/pkirchg for more details. *
***************************************************************************/
#pragma once
#include "bayer.h"
typedef enum {
FITS_NORMAL,
FITS_FOCUS,
FITS_GUIDE,
FITS_CALIBRATE,
FITS_ALIGN,
} FITSMode;
#ifdef WIN32
// This header must be included before fitsio.h to avoid compiler errors with Visual Studio
#include <windows.h>
#endif
#include <fitsio.h>
#include <QIODevice>
#include <QRect>
class FITSData
{
public:
FITSData();
~FITSData();
/* Loads FITS image, scales it, and displays it in the GUI */
bool loadFITS(QIODevice &buffer);
/* Calculate stats */
void calculateStats(bool refresh = false);
// Access functions
void clearImageBuffers();
uint8_t *getImageBuffer();
int getDataType()
{
return data_type;
}
// Stats
unsigned int getSize()
{
return stats.samples_per_channel;
}
uint16_t getWidth()
{
return stats.width;
}
uint16_t getHeight()
{
return stats.height;
}
// Statistics
int getNumOfChannels()
{
return channels;
}
void getMinMax(double *min, double *max, uint8_t channel = 0)
{
*min = stats.min[channel];
*max = stats.max[channel];
}
// Debayer
bool debayer();
bool debayer_8bit();
bool debayer_16bit();
// FITS Record
int getFITSRecord(QString &recordList, int &nkeys);
// Create autostretch image from FITS File
static QImage FITSToImage(QIODevice &buffer);
QString getLastError() const;
private:
int calculateMinMax(bool refresh = false);
bool checkDebayer();
// Templated functions
template<typename T>
bool debayer();
template<typename T>
void calculateMinMax();
/* Calculate running average & standard deviation using Welford’s method for computing variance */
template<typename T>
void runningAverageStdDev();
template<typename T>
void convertToQImage(double dataMin, double dataMax, double scale, double zero, QImage &image);
/// Pointer to CFITSIO FITS file struct
fitsfile *fptr{nullptr};
/// FITS image data type (TBYTE, TUSHORT, TINT, TFLOAT, TLONG, TDOUBLE)
int data_type{0};
/// Number of channels
int channels{1};
/// Generic data image buffer
uint8_t *imageBuffer{nullptr};
/// Our very own file name
QString filename;
/// FITS Mode (Normal, WCS, Guide, Focus..etc)
FITSMode mode;
uint8_t *bayerBuffer{nullptr};
/// Bayer parameters
BayerParams debayerParams;
/// Stats struct to hold statistical data about the FITS data
struct {
double min[3], max[3];
double mean[3];
double stddev[3];
double median[3];
double SNR{0};
int bitpix{8};
int bytesPerPixel{1};
int ndim{2};
uint32_t samples_per_channel{0};
uint16_t width{0};
uint16_t height{0};
} stats;
QString lastError;
};
| 4,158
|
C++
|
.h
| 127
| 27.417323
| 104
| 0.56058
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,077
|
urlutilstest.h
|
KDE_gwenview/tests/auto/urlutilstest.h
|
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef URLUTILSTEST_H
#define URLUTILSTEST_H
// Qt
#include <QObject>
class UrlUtilsTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testFixUserEnteredUrl();
void testFixUserEnteredUrl_data();
};
#endif /* URLUTILSTEST_H */
| 1,014
|
C++
|
.h
| 27
| 35.740741
| 79
| 0.798362
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,078
|
transformimageoperationtest.h
|
KDE_gwenview/tests/auto/transformimageoperationtest.h
|
/*
Gwenview: an image viewer
Copyright 2010 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef TRANSFORMIMAGEOPERATIONTEST_H
#define TRANSFORMIMAGEOPERATIONTEST_H
// Qt
#include <QObject>
// Local
#include "../lib/document/document.h"
class TransformImageOperationTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testRotate90();
void initTestCase();
void init();
};
#endif // TRANSFORMIMAGEOPERATIONTEST_H
| 1,113
|
C++
|
.h
| 30
| 35.2
| 79
| 0.800373
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,080
|
sorteddirmodeltest.h
|
KDE_gwenview/tests/auto/sorteddirmodeltest.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2011 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef SORTEDDIRMODELTEST_H
#define SORTEDDIRMODELTEST_H
// Local
#include <testutils.h>
// Qt
#include <QObject>
// std c++
#include <memory>
class SortedDirModelTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void testHasDocuments_data();
void testHasDocuments();
private:
TestUtils::SandBoxDir mSandBoxDir;
};
#endif /* SORTEDDIRMODELTEST_H */
| 1,210
|
C++
|
.h
| 35
| 32.657143
| 79
| 0.791058
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,081
|
imagemetainfomodeltest.h
|
KDE_gwenview/tests/auto/imagemetainfomodeltest.h
|
/*
Gwenview: an image viewer
Copyright 2012 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef IMAGEMETAINFOMODELTEST_H
#define IMAGEMETAINFOMODELTEST_H
// Qt
#include <QObject>
// KF
// Local
class ImageMetaInfoModelTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testCatchExiv2Errors();
};
#endif // IMAGEMETAINFOMODELTEST_H
| 1,028
|
C++
|
.h
| 28
| 35
| 79
| 0.80668
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,082
|
thumbnailprovidertest.h
|
KDE_gwenview/tests/auto/thumbnailprovidertest.h
|
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef THUMBNAILPROVIDERTEST_H
#define THUMBNAILPROVIDERTEST_H
// Qt
#include <QColor>
#include <QHash>
#include <QObject>
#include <QSize>
class SandBox
{
public:
SandBox();
void initDir();
void fill();
void createTestImage(const QString &name, int width, int height, const QColor &color);
void copyTestImage(const QString &name, int width, int height);
QHash<QString, QSize> mSizeHash;
QString mPath;
};
class ThumbnailProviderTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void init();
void initTestCase();
void testLoadLocal();
void testLoadRemote();
void testUseEmbeddedOrNot();
void testRemoveItemsWhileGenerating();
private:
SandBox mSandBox;
};
#endif // THUMBNAILPROVIDERTEST_H
| 1,525
|
C++
|
.h
| 47
| 29.893617
| 90
| 0.776792
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,083
|
documenttest.h
|
KDE_gwenview/tests/auto/documenttest.h
|
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef DOCUMENTTEST_H
#define DOCUMENTTEST_H
// Qt
#include <QApplication>
#include <QDebug>
#include <QObject>
// KF
#include <KJob>
// Local
#include "../lib/document/document.h"
class LoadingStateSpy : public QObject
{
Q_OBJECT
public:
LoadingStateSpy(const Gwenview::Document::Ptr &doc)
: mDocument(doc)
, mCallCount(0)
{
}
public Q_SLOTS:
void readState()
{
mCallCount++;
mState = mDocument->loadingState();
}
public:
Gwenview::Document::Ptr mDocument;
int mCallCount;
Gwenview::Document::LoadingState mState;
};
class JobWatcher : public QObject
{
Q_OBJECT
public:
JobWatcher(KJob *job)
: mDone(false)
, mError(0)
{
connect(job, &KJob::result, this, &JobWatcher::slotResult);
connect(job, &QObject::destroyed, this, &JobWatcher::slotDestroyed);
}
void wait()
{
while (!mDone) {
QApplication::processEvents();
}
}
int error() const
{
return mError;
}
private Q_SLOTS:
void slotResult(KJob *job)
{
mError = job->error();
mDone = true;
}
void slotDestroyed()
{
qWarning() << "Destroyed";
mError = -1;
mDone = true;
}
private:
bool mDone;
int mError;
};
class DocumentTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testLoad();
void testLoad_data();
void testLoadTwoPasses();
void testLoadEmpty();
void testLoadDownSampled();
void testLoadDownSampled_data();
void testLoadDownSampledPng();
void testLoadRemote();
void testLoadAnimated();
void testPrepareDownSampledAfterFailure();
void testDeleteWhileLoading();
void testLoadRotated();
void testMultipleLoads();
void testSaveAs();
void testSaveRemote();
void testLosslessSave();
void testLosslessRotate();
void testModifyAndSaveAs();
void testMetaInfoJpeg();
void testMetaInfoBmp();
void testForgetModifiedDocument();
void testModifiedAndSavedSignals();
void testJobQueue();
void testCheckDocumentEditor();
void testUndoStackPush();
void testUndoRedo();
void initTestCase();
void init();
};
#endif // DOCUMENTTEST_H
| 3,027
|
C++
|
.h
| 116
| 21.732759
| 79
| 0.697127
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,084
|
jpegcontenttest.h
|
KDE_gwenview/tests/auto/jpegcontenttest.h
|
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef JPEGCONTENTTEST_H
#define JPEGCONTENTTEST_H
// Qt
#include <QObject>
class JpegContentTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void testReadInfo();
void testThumbnail();
void testResetOrientation();
void testTransform();
void testSetComment();
void testMultipleRotations();
void testLoadTruncated();
void testRawData();
void testSetImage();
};
#endif // JPEGCONTENTTEST_H
| 1,253
|
C++
|
.h
| 36
| 32.194444
| 79
| 0.780447
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,085
|
importertest.h
|
KDE_gwenview/tests/auto/importertest.h
|
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef IMPORTERTEST_H
#define IMPORTERTEST_H
// stdc++
#include <memory>
// Qt
#include <QObject>
#include <QTemporaryDir>
#include <QUrl>
// KF
class ImporterTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void init();
void testContentsAreIdentical();
void testSuccessfulImport();
void testSuccessfulImportRemote();
void testAutoRenameFormat();
void testReadOnlyDestination();
void testFileNameFormater();
void testFileNameFormater_data();
void testSkippedUrlList();
void testRenamedCount();
private:
std::unique_ptr<QTemporaryDir> mTempDir;
QList<QUrl> mDocumentList;
};
#endif /* IMPORTERTEST_H */
| 1,430
|
C++
|
.h
| 43
| 30.744186
| 79
| 0.780932
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,086
|
recursivedirmodeltest.h
|
KDE_gwenview/tests/auto/recursivedirmodeltest.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2012 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef RECURSIVEDIRMODELTEST_H
#define RECURSIVEDIRMODELTEST_H
// Local
#include <testutils.h>
// Qt
#include <QObject>
class RecursiveDirModelTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testBasic_data();
void testBasic();
void testSetNewUrl();
};
#endif /* RECURSIVEDIRMODELTEST_H */
| 1,130
|
C++
|
.h
| 31
| 34.612903
| 79
| 0.794307
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,087
|
testutils.h
|
KDE_gwenview/tests/auto/testutils.h
|
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef TESTUTILS_H
#define TESTUTILS_H
// STL
#include <cmath>
// Qt
#include <QDir>
#include <QImage>
#include <QSignalSpy>
#include <QTemporaryDir>
#include <QTest>
#include <QUrl>
// KF
#include "config-gwenview.h"
/*
* This file contains simple helpers to access test files
*/
inline QString pathForTestFile(const QString &name)
{
return QDir::cleanPath(QStringLiteral("%1/%2").arg(GV_TEST_DATA_DIR, name));
}
inline QUrl urlForTestFile(const QString &name)
{
return QUrl::fromLocalFile(pathForTestFile(name));
}
inline QString pathForTestOutputFile(const QString &name)
{
return QStringLiteral("%1/%2").arg(QDir::currentPath(), name);
}
inline QUrl urlForTestOutputFile(const QString &name)
{
return QUrl::fromLocalFile(pathForTestOutputFile(name));
}
inline bool waitForSignal(const QSignalSpy &spy, int timeout = 5)
{
for (int x = 0; x < timeout; ++x) {
if (spy.count() > 0) {
return true;
}
QTest::qWait(1000);
}
return false;
}
void createEmptyFile(const QString &path);
/**
* Returns the url of the remote url dir if remote test dir was successfully
* set up.
* If testFile is valid, it is copied into the test dir.
*/
QUrl setUpRemoteTestDir(const QString &testFile = QString());
/**
* Make sure all objects on which deleteLater() have been called have been
* destroyed.
*/
void waitForDeferredDeletes();
// FIXME: Top-level functions should move to the TestUtils namespace
namespace TestUtils
{
bool fuzzyImageCompare(const QImage &img1, const QImage &img2, int delta = 2);
bool imageCompare(const QImage &img1, const QImage &img2);
void purgeUserConfiguration();
class SandBoxDir : public QDir
{
public:
SandBoxDir();
void fill(const QStringList &files);
private:
QTemporaryDir mTempDir;
};
/**
* An event loop which stops itself after a predefined duration
*/
class TimedEventLoop : public QEventLoop
{
Q_OBJECT
public:
TimedEventLoop(int maxDurationInSeconds = 60);
int exec(ProcessEventsFlags flags = AllEvents);
private Q_SLOTS:
void fail();
private:
QTimer *mTimer;
};
} // namespace
#endif /* TESTUTILS_H */
| 2,926
|
C++
|
.h
| 99
| 27.171717
| 80
| 0.75724
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,088
|
timeutilstest.h
|
KDE_gwenview/tests/auto/timeutilstest.h
|
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef TIMEUTILSTEST_H
#define TIMEUTILSTEST_H
// Qt
#include <QObject>
class TimeUtilsTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testBasic();
void testBasic_data();
void testCache();
};
#endif /* TIMEUTILSTEST_H */
| 1,016
|
C++
|
.h
| 28
| 34.357143
| 79
| 0.790389
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,089
|
semanticinfobackendtest.h
|
KDE_gwenview/tests/auto/semanticinfobackendtest.h
|
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef SEMANTICINFOBACKENDTEST_H
#define SEMANTICINFOBACKENDTEST_H
// Qt
#include <QHash>
#include <QObject>
#include <QUrl>
// KF
// Local
#include <lib/semanticinfo/abstractsemanticinfobackend.h>
namespace Gwenview
{
/**
* Helper class which gathers the metadata retrieved when
* AbstractSemanticInfoBackEnd::retrieveSemanticInfo() is called.
*/
class SemanticInfoBackEndClient : public QObject
{
Q_OBJECT
public:
SemanticInfoBackEndClient(AbstractSemanticInfoBackEnd *);
SemanticInfo semanticInfoForUrl(const QUrl &url) const
{
return mSemanticInfoForUrl.value(url);
}
private Q_SLOTS:
void slotSemanticInfoRetrieved(const QUrl &, const SemanticInfo &);
private:
QHash<QUrl, SemanticInfo> mSemanticInfoForUrl;
AbstractSemanticInfoBackEnd *mBackEnd;
};
class SemanticInfoBackEndTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void init();
void cleanup();
void testRating();
#if 0
void testTagForLabel();
#endif
private:
AbstractSemanticInfoBackEnd *mBackEnd;
};
} // namespace
#endif // SEMANTICINFOBACKENDTEST_H
| 1,889
|
C++
|
.h
| 61
| 28.508197
| 79
| 0.792265
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,090
|
placetreemodeltest.h
|
KDE_gwenview/tests/auto/placetreemodeltest.h
|
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLACETREEMODELTEST_H
#define PLACETREEMODELTEST_H
// Qt
#include <QObject>
#include <QStringList>
#include <QTemporaryDir>
#include <QUrl>
// KF
class PlaceTreeModelTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void init();
void initTestCase();
void testListPlaces();
void testListUrl1();
private:
QUrl mUrl1, mUrl2;
QStringList mUrl1Dirs;
QTemporaryDir mTempDir;
};
#endif /* PLACETREEMODELTEST_H */
| 1,218
|
C++
|
.h
| 37
| 30.72973
| 79
| 0.787853
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,091
|
contextmanagertest.h
|
KDE_gwenview/tests/auto/contextmanagertest.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2013 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef CONTEXTMANAGERTEST_H
#define CONTEXTMANAGERTEST_H
// Local
#include <testutils.h>
// Qt
#include <QObject>
class ContextManagerTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testRemove();
};
#endif /* CONTEXTMANAGERTEST_H */
| 1,066
|
C++
|
.h
| 29
| 35.137931
| 79
| 0.798442
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,092
|
historymodeltest.h
|
KDE_gwenview/tests/auto/historymodeltest.h
|
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef HISTORYMODELTEST_H
#define HISTORYMODELTEST_H
// Qt
#include <QObject>
class HistoryModelTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testAddUrl();
void testGarbageCollect();
void testRemoveRows();
};
#endif /* HISTORYMODELTEST_H */
| 1,038
|
C++
|
.h
| 28
| 35.142857
| 79
| 0.796
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,093
|
cmsprofiletest.h
|
KDE_gwenview/tests/auto/cmsprofiletest.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2012 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef CMSPROFILETEST_H
#define CMSPROFILETEST_H
// Local
// KF
// Qt
#include <QObject>
class CmsProfileTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testLoadFromImageData();
void testLoadFromImageData_data();
#if 0 // Need some test data
void testLoadFromExiv2Image();
void testLoadFromExiv2Image_data();
#endif
};
#endif /* CMSPROFILETEST_H */
| 1,198
|
C++
|
.h
| 34
| 33.294118
| 81
| 0.791667
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,094
|
renamedialog.h
|
KDE_gwenview/app/renamedialog.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2018 Aurélien Gâteau <agateau@kde.org>
Copyright 2018 Peter Mühlenpfordt <devel@ukn8.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef RENAMEDIALOG_H
#define RENAMEDIALOG_H
// Qt
#include <QDialog>
// KF
// Local
namespace Gwenview
{
struct RenameDialogPrivate;
class RenameDialog : public QDialog
{
Q_OBJECT
public:
explicit RenameDialog(QWidget *parent);
~RenameDialog() override;
void setFilename(const QString &filename);
QString filename() const;
private:
RenameDialogPrivate *const d;
void updateButtons();
};
} // namespace
#endif /* RENAMEDIALOG_H */
| 1,335
|
C++
|
.h
| 40
| 31.275
| 81
| 0.791243
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,095
|
fullscreencontent.h
|
KDE_gwenview/app/fullscreencontent.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef FULLSCREENCONTENT_H
#define FULLSCREENCONTENT_H
// Qt
#include <QPointer>
#include <QStringList>
#include <QWidget>
// KF
// Local
#include "imagemetainfodialog.h"
#include "ui_fullscreenconfigwidget.h"
#include <lib/document/document.h>
class KActionCollection;
class QUrl;
namespace Gwenview
{
class FullScreenBar;
class FullScreenToolBar;
class ShadowFilter;
class SlideShow;
class GvCore;
class ThumbnailBarView;
class FullScreenConfigWidget : public QWidget, public Ui_FullScreenConfigWidget
{
public:
explicit FullScreenConfigWidget(QWidget *parent = nullptr)
: QWidget(parent)
{
setupUi(this);
}
};
/**
* The content of the fullscreen bar
*/
class FullScreenContent : public QObject
{
Q_OBJECT
public:
FullScreenContent(QObject *parent, GvCore *gvCore);
void init(KActionCollection *, QWidget *autoHideParentWidget, SlideShow *);
ThumbnailBarView *thumbnailBar() const;
void setDistractionFreeMode(bool);
void setFullScreenMode(bool);
public Q_SLOTS:
void setCurrentUrl(const QUrl &);
private Q_SLOTS:
void updateCurrentUrlWidgets();
void updateInformationLabel();
void updateMetaInfoDialog();
void showImageMetaInfoDialog();
void slotImageMetaInfoDialogClosed();
void slotPreferredMetaInfoKeyListChanged(const QStringList &list);
void showOptionsMenu();
void updateSlideShowIntervalLabel();
void setFullScreenBarHeight(int value);
void slotShowThumbnailsToggled(bool value);
void slotViewModeActionToggled(bool value);
void adjustSize();
void updateDocumentCountLabel();
private:
KActionCollection *mActionCollection;
FullScreenBar *mAutoHideContainer;
SlideShow *mSlideShow;
QWidget *mContent;
FullScreenToolBar *mToolBar;
FullScreenToolBar *mRightToolBar;
ThumbnailBarView *mThumbnailBar;
QLabel *mInformationLabel;
QLabel *mDocumentCountLabel;
QWidget *mInformationContainer;
ShadowFilter *mToolBarShadow;
ShadowFilter *mRightToolBarShadow;
ShadowFilter *mInformationContainerShadow;
Document::Ptr mCurrentDocument;
QPointer<ImageMetaInfoDialog> mImageMetaInfoDialog;
QPointer<FullScreenConfigWidget> mConfigWidget;
QAction *mOptionsAction;
GvCore *mGvCore;
int mMinimumThumbnailBarHeight;
bool mViewPageVisible;
void createOptionsAction();
void updateContainerAppearance();
void updateLayout();
void setupThumbnailBarStyleSheet();
};
} // namespace
#endif /* FULLSCREENCONTENT_H */
| 3,341
|
C++
|
.h
| 102
| 29.5
| 81
| 0.790669
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,096
|
startmainpage.h
|
KDE_gwenview/app/startmainpage.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef STARTMAINPAGE_H
#define STARTMAINPAGE_H
// Qt
#include <QFrame>
// KF
// Local
class QModelIndex;
class QPalette;
class QShowEvent;
class QEvent;
class QUrl;
namespace Gwenview
{
class GvCore;
class ThumbnailView;
struct StartMainPagePrivate;
class StartMainPage : public QFrame
{
Q_OBJECT
public:
explicit StartMainPage(QWidget *parent, GvCore *);
~StartMainPage() override;
void applyPalette(const QPalette &);
ThumbnailView *recentFoldersView() const;
Q_SIGNALS:
void urlSelected(const QUrl &url);
void recentFileRemoved(const QUrl &url);
void recentFilesCleared();
public Q_SLOTS:
void loadConfig();
protected:
void showEvent(QShowEvent *) override;
bool eventFilter(QObject *, QEvent *) override;
private Q_SLOTS:
void slotListViewActivated(const QModelIndex &index);
void slotTagViewClicked(const QModelIndex &index);
private:
StartMainPagePrivate *const d;
void showContextMenu(const QPoint &pos);
};
} // namespace
#endif /* STARTMAINPAGE_H */
| 1,851
|
C++
|
.h
| 58
| 29.5
| 81
| 0.787691
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,097
|
folderviewcontextmanageritem.h
|
KDE_gwenview/app/folderviewcontextmanageritem.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef FOLDERVIEWCONTEXTMANAGERITEM_H
#define FOLDERVIEWCONTEXTMANAGERITEM_H
// Qt
#include <QUrl>
// KF
// Local
#include "abstractcontextmanageritem.h"
#define USE_PLACETREE
#ifdef USE_PLACETREE
#include <lib/placetreemodel.h>
#define MODEL_CLASS PlaceTreeModel
#else
#include <lib/semanticinfo/sorteddirmodel.h>
#define MODEL_CLASS SortedDirModel
#endif
class QModelIndex;
class QTreeView;
namespace Gwenview
{
class FolderViewContextManagerItem : public AbstractContextManagerItem
{
Q_OBJECT
public:
FolderViewContextManagerItem(ContextManager *);
Q_SIGNALS:
void urlChanged(const QUrl &);
private Q_SLOTS:
void slotCurrentDirUrlChanged(const QUrl &);
void expandToSelectedUrl();
void slotRowsInserted(const QModelIndex &, int start, int end);
void slotActivated(const QModelIndex &);
private:
MODEL_CLASS *mModel;
QTreeView *mView;
QUrl mUrlToSelect;
QPersistentModelIndex mExpandingIndex;
void setupModel();
void setupView();
QModelIndex findClosestIndex(const QModelIndex &parent, const QUrl &wantedUrl);
QModelIndex findRootIndex(const QUrl &wantedUrl);
};
} // namespace
#endif /* FOLDERVIEWCONTEXTMANAGERITEM_H */
| 2,010
|
C++
|
.h
| 59
| 31.728814
| 83
| 0.802277
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,098
|
imagemetainfodialog.h
|
KDE_gwenview/app/imagemetainfodialog.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef IMAGEMETAINFODIALOG_H
#define IMAGEMETAINFODIALOG_H
// Qt
#include <QDialog>
// KF
// Local
namespace Gwenview
{
class ImageMetaInfoModel;
struct ImageMetaInfoDialogPrivate;
class ImageMetaInfoDialog : public QDialog
{
Q_OBJECT
public:
explicit ImageMetaInfoDialog(QWidget *parent);
~ImageMetaInfoDialog() override;
/**
* Defines the image metainfo model and the preferred metainfo key list.
*/
void setMetaInfo(ImageMetaInfoModel *, const QStringList &list);
QSize sizeHint() const override;
Q_SIGNALS:
void preferredMetaInfoKeyListChanged(const QStringList &);
private:
ImageMetaInfoDialogPrivate *const d;
};
} // namespace
#endif /* IMAGEMETAINFODIALOG_H */
| 1,535
|
C++
|
.h
| 44
| 32.545455
| 78
| 0.794437
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,099
|
configdialog.h
|
KDE_gwenview/app/configdialog.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef CONFIGDIALOG_H
#define CONFIGDIALOG_H
// Qt
// KF
#include <KConfigDialog>
// Local
#include "ui_advancedconfigpage.h"
#include "ui_generalconfigpage.h"
#include "ui_imageviewconfigpage.h"
namespace Gwenview
{
class InvisibleButtonGroup;
class ConfigDialog : public KConfigDialog
{
Q_OBJECT
public:
ConfigDialog(QWidget *parent);
/**
* Changes the page being displayed.
* @param page The page to be shown counted from the top.
*/
void setCurrentPage(int page);
private:
InvisibleButtonGroup *mWrapNavigationBehaviorGroup = nullptr;
InvisibleButtonGroup *mAlphaBackgroundModeGroup = nullptr;
InvisibleButtonGroup *mWheelBehaviorGroup = nullptr;
InvisibleButtonGroup *mAnimationMethodGroup = nullptr;
InvisibleButtonGroup *mFullScreenBackgroundGroup = nullptr;
InvisibleButtonGroup *mThumbnailActionsGroup = nullptr;
InvisibleButtonGroup *mZoomModeGroup = nullptr;
InvisibleButtonGroup *mThumbnailBarOrientationGroup = nullptr;
InvisibleButtonGroup *mRenderingIntentGroup = nullptr;
Ui_GeneralConfigPage mGeneralConfigPage;
Ui_ImageViewConfigPage mImageViewConfigPage;
Ui_AdvancedConfigPage mAdvancedConfigPage;
KPageWidgetItem *mGeneralConfigPageItem;
KPageWidgetItem *mImageViewConfigPageItem;
KPageWidgetItem *mAdvancedConfigPageItem;
};
} // namespace
#endif /* CONFIGDIALOG_H */
| 2,202
|
C++
|
.h
| 57
| 35.77193
| 78
| 0.804225
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,100
|
alignwithsidebarwidgetaction.h
|
KDE_gwenview/app/alignwithsidebarwidgetaction.h
|
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2021 Felix Ernst <fe.a.ernst@gmail.com>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef ALIGNWITHSIDEBARWIDGETACTION_H
#define ALIGNWITHSIDEBARWIDGETACTION_H
#include <QPointer>
#include <QToolBar>
#include <QWidgetAction>
/**
* A spacer used to align actions in the toolbar with the sidebar.
*/
class AlignWithSideBarWidgetAction : public QWidgetAction
{
Q_OBJECT
public:
AlignWithSideBarWidgetAction(QObject *parent = nullptr);
/**
* @param sideBar the QWidget this spacer will base its width on to facilitate alignment.
* Can be nullptr.
*/
void setSideBar(QWidget *sideBar);
protected:
/** @see QWidgetAction::createWidget() */
QWidget *createWidget(QWidget *parent) override;
private:
/** The sideBar to align with. */
QPointer<QWidget> mSideBar;
};
/**
* The widget of AlignWithSideBarWidgetAction.
* This class is not meant to be used from outside AlignWithSideBarWidgetAction.
*/
class AligningSpacer : public QWidget
{
Q_OBJECT
public:
AligningSpacer(QWidget *parent);
/** @see AlignWithSideBarWidgetAction::setSideBar() */
void setSideBar(QWidget *sideBar);
/**
* Used to trigger updateWidth() whenever mSideBar's width changes.
*/
bool eventFilter(QObject * /* watched */, QEvent *event) override;
protected:
/**
* Used to trigger updateWidth() when the containing toolbar is locked/unlocked.
*/
void moveEvent(QMoveEvent * /* moved */) override;
private:
/**
* Having a separator directly after an empty space looks bad unless the separator
* is aligned with a sidebar. This method is used to remove or re-add the separator
* so everything looks nice.
* @param visible Wether a potential separator after this widget should be visible.
* This will always be changed to true if the parent toolbar is vertical.
*/
void setFollowingSeparatorVisible(bool visible);
/**
* Updates the width of the spacer depending on the sizeHint() and sets the visibility
* of a potentially following separator.
*/
void update();
/**
* Calculates the width of this spacer based on its position, the sideBar width,
* the toolbar orientation and the following action.
* @return the new width in pixels.
*/
int updateWidth();
private:
/** The SideBar to align with. */
QPointer<QWidget> mSideBar;
/** The parentWidget() of this widget or nullptr when the parent isn't a QToolBar. */
QPointer<QToolBar> mToolbar;
/** This spacer removes following separators if they would look bad/pointless. */
bool mWasSeparatorRemoved = false;
};
#endif // ALIGNWITHSIDEBARWIDGETACTION_H
| 2,807
|
C++
|
.h
| 79
| 31.405063
| 93
| 0.714391
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,101
|
browsemainpage.h
|
KDE_gwenview/app/browsemainpage.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef BROWSEMAINPAGE_H
#define BROWSEMAINPAGE_H
// Qt
#include <QUrl>
#include <QWidget>
// KF
// Local
class QDropEvent;
class QModelIndex;
class QItemSelection;
class QToolButton;
class KActionCollection;
class KUrlNavigator;
namespace Gwenview
{
class GvCore;
class ThumbnailView;
struct BrowseMainPagePrivate;
/**
* This class contains all the necessary widgets displayed in browse mode:
* the thumbnail view, the url navigator, the bottom bar.
*/
class BrowseMainPage : public QWidget
{
Q_OBJECT
public:
BrowseMainPage(QWidget *parent, KActionCollection *, GvCore *);
~BrowseMainPage() override;
void reload();
ThumbnailView *thumbnailView() const;
KUrlNavigator *urlNavigator() const;
void loadConfig();
void saveConfig() const;
void setFullScreenMode(bool);
void setStatusBarVisible(bool);
QToolButton *toggleSideBarButton() const;
private Q_SLOTS:
void editLocation();
void addFolderToPlaces();
void slotDirModelRowsInserted(const QModelIndex &parent, int start, int end);
void slotDirModelRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
void slotDirModelReset();
void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void updateSortOrder();
void updateThumbnailDetails();
void slotUrlsDropped(const QUrl &destUrl, QDropEvent *);
void showMenuForDroppedUrls(const QList<QUrl> &, const QUrl &destUrl);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
void mousePressEvent(QMouseEvent *) override;
private:
BrowseMainPagePrivate *const d;
};
} // namespace
#endif /* BROWSEMAINPAGE_H */
| 2,509
|
C++
|
.h
| 71
| 32.605634
| 96
| 0.786247
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,102
|
semanticinfocontextmanageritem.h
|
KDE_gwenview/app/semanticinfocontextmanageritem.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef SEMANTICINFOCONTEXTMANAGERITEM_H
#define SEMANTICINFOCONTEXTMANAGERITEM_H
// Qt
// KF
// Local
#include "abstractcontextmanageritem.h"
#include <lib/semanticinfo/abstractsemanticinfobackend.h>
class KActionCollection;
namespace Gwenview
{
class ViewMainPage;
struct SemanticInfoContextManagerItemPrivate;
class SemanticInfoContextManagerItem : public AbstractContextManagerItem
{
Q_OBJECT
public:
SemanticInfoContextManagerItem(ContextManager *, KActionCollection *, ViewMainPage *viewMainPage);
~SemanticInfoContextManagerItem() override;
protected:
bool eventFilter(QObject *, QEvent *) override;
private Q_SLOTS:
void slotSelectionChanged();
void update();
void slotRatingChanged(int rating);
void storeDescription();
void assignTag(const SemanticInfoTag &);
void removeTag(const SemanticInfoTag &);
void showSemanticInfoDialog();
private:
friend struct SemanticInfoContextManagerItemPrivate;
SemanticInfoContextManagerItemPrivate *const d;
};
} // namespace
#endif /* SEMANTICINFOCONTEXTMANAGERITEM_H */
| 1,894
|
C++
|
.h
| 50
| 35.5
| 102
| 0.81445
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,103
|
savebar.h
|
KDE_gwenview/app/savebar.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef SAVEBAR_H
#define SAVEBAR_H
// Qt
// KF
// Local
#include <lib/slidecontainer.h>
class KActionCollection;
class QUrl;
namespace Gwenview
{
struct SaveBarPrivate;
class SaveBar : public SlideContainer
{
Q_OBJECT
public:
SaveBar(QWidget *parent, KActionCollection *collection);
~SaveBar() override;
void setFullScreenMode(bool);
public Q_SLOTS:
void setCurrentUrl(const QUrl &);
Q_SIGNALS:
void requestSaveAll();
void goToUrl(const QUrl &);
private:
SaveBarPrivate *const d;
private Q_SLOTS:
void updateContent();
void triggerAction(const QString &action);
};
} // namespace
#endif /* SAVEBAR_H */
| 1,468
|
C++
|
.h
| 47
| 29
| 78
| 0.782609
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,104
|
thumbnailviewhelper.h
|
KDE_gwenview/app/thumbnailviewhelper.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef THUMBNAILVIEWHELPER_H
#define THUMBNAILVIEWHELPER_H
// Qt
// KF
// Local
#include <lib/thumbnailview/abstractthumbnailviewhelper.h>
class KActionCollection;
namespace Gwenview
{
struct ThumbnailViewHelperPrivate;
class ThumbnailViewHelper : public AbstractThumbnailViewHelper
{
Q_OBJECT
public:
ThumbnailViewHelper(QObject *parent, KActionCollection *);
~ThumbnailViewHelper() override;
void showContextMenu(QWidget *parent) override;
void showMenuForUrlDroppedOnViewport(QWidget *parent, const QList<QUrl> &) override;
void showMenuForUrlDroppedOnDir(QWidget *parent, const QList<QUrl> &, const QUrl &) override;
public Q_SLOTS:
void setCurrentDirUrl(const QUrl &);
private:
ThumbnailViewHelperPrivate *const d;
};
} // namespace
#endif /* THUMBNAILVIEWHELPER_H */
| 1,630
|
C++
|
.h
| 42
| 36.619048
| 97
| 0.805732
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,105
|
sidebar.h
|
KDE_gwenview/app/sidebar.h
|
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef SIDEBAR_H
#define SIDEBAR_H
// Qt
#include <QFrame>
#include <QStylePainter>
#include <QTabBar>
#include <QTabWidget>
namespace Gwenview
{
class SideBar;
struct SideBarGroupPrivate;
class SideBarGroup : public QFrame
{
Q_OBJECT
public:
SideBarGroup(const QString &title = "");
~SideBarGroup() override;
void addWidget(QWidget *);
void addAction(QAction *);
void clear();
private:
SideBarGroupPrivate *const d;
};
struct SideBarPagePrivate;
class SideBarPage : public QWidget
{
Q_OBJECT
public:
SideBarPage(const QIcon &icon, const QString &title);
~SideBarPage() override;
void addWidget(QWidget *);
void addStretch();
const QIcon &icon() const;
const QString &title() const;
private:
SideBarPagePrivate *const d;
};
struct SideBarTabBarPrivate;
class SideBarTabBar : public QTabBar
{
Q_OBJECT
public:
explicit SideBarTabBar(QWidget *parent);
~SideBarTabBar() override;
enum TabButtonStyle {
TabButtonIconOnly,
TabButtonTextOnly,
TabButtonTextBesideIcon,
};
Q_ENUM(TabButtonStyle)
TabButtonStyle tabButtonStyle() const;
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
protected:
QSize tabSizeHint(const int index) const override;
QSize minimumTabSizeHint(int index) const override;
// Switches the TabButtonStyle based on the width
void tabLayoutChange() override;
void paintEvent(QPaintEvent *event) override;
private:
// Like sizeHint, but just for content size
QSize tabContentSize(const int index, const TabButtonStyle tabButtonStyle, const QStyleOptionTab &opt) const;
// Gets the tab size hint for the given TabButtonStyle
QSize tabSizeHint(const int index, const TabButtonStyle tabButtonStyle) const;
// Gets the size hint for the given TabButtonStyle
QSize sizeHint(const TabButtonStyle tabButtonStyle) const;
void drawTab(int index, QStylePainter &painter) const;
const std::unique_ptr<SideBarTabBarPrivate> d;
};
struct SideBarPrivate;
class SideBar : public QTabWidget
{
Q_OBJECT
public:
explicit SideBar(QWidget *parent);
~SideBar() override;
void addPage(SideBarPage *);
QString currentPage() const;
void setCurrentPage(const QString &name);
void loadConfig();
QSize sizeHint() const override;
private:
SideBarPrivate *const d;
};
} // namespace
#endif /* SIDEBAR_H */
| 3,213
|
C++
|
.h
| 101
| 28.465347
| 113
| 0.764191
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,106
|
spotlightmode.h
|
KDE_gwenview/app/spotlightmode.h
|
/*
This file is part of the KDE project
SPDX-License-Identifier: GPL-2.0-or-later
Project idea and initial maintainer: Aurélien Gâteau <agateau@kde.org>
SPDX-FileCopyrightText: 2024 Ravil Saifullin <saifullin.dev@gmail.com>
*/
#ifndef SPOTLIGHTMODE_H
#define SPOTLIGHTMODE_H
// Qt
#include <QHBoxLayout>
#include <QWidget>
// KF
#include <KActionCollection>
namespace Gwenview
{
struct SpotlightModePrivate;
class SpotlightMode : public QHBoxLayout
{
Q_OBJECT
public:
SpotlightMode(QWidget *parent, KActionCollection *actionCollection);
void setVisibleSpotlightModeQuitButton(bool visibe);
~SpotlightMode() override;
private:
void emitButtonQuitClicked();
SpotlightModePrivate *const d;
};
} // namespace
#endif /* SPOTLIGHTMODE_H */
| 768
|
C++
|
.h
| 29
| 24.310345
| 72
| 0.799726
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,107
|
preloader.h
|
KDE_gwenview/app/preloader.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef PRELOADER_H
#define PRELOADER_H
// Qt
#include <QObject>
// KF
// Local
class QSize;
class QUrl;
namespace Gwenview
{
struct PreloaderPrivate;
/**
* This class preloads a document to fit a specific size.
*/
class Preloader : public QObject
{
Q_OBJECT
public:
explicit Preloader(QObject *parent);
~Preloader() override;
void preload(const QUrl &, const QSize &);
private Q_SLOTS:
void doPreload();
private:
PreloaderPrivate *const d;
};
} // namespace
#endif /* PRELOADER_H */
| 1,337
|
C++
|
.h
| 44
| 28.386364
| 81
| 0.779608
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,108
|
infocontextmanageritem.h
|
KDE_gwenview/app/infocontextmanageritem.h
|
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef INFOCONTEXTMANAGERITEM_H
#define INFOCONTEXTMANAGERITEM_H
// Qt
#include <QStringList>
// Local
#include "abstractcontextmanageritem.h"
#include <QStringList>
class KFileItem;
class KFileItemList;
namespace Gwenview
{
struct InfoContextManagerItemPrivate;
class InfoContextManagerItem : public AbstractContextManagerItem
{
Q_OBJECT
public:
InfoContextManagerItem(ContextManager *);
~InfoContextManagerItem() override;
private Q_SLOTS:
void updateSideBarContent();
void updateOneFileInfo();
void showMetaInfoDialog();
void slotPreferredMetaInfoKeyListChanged(const QStringList &);
private:
void fillOneFileGroup(const KFileItem &item);
void fillMultipleItemsGroup(const KFileItemList &itemList);
friend struct InfoContextManagerItemPrivate;
InfoContextManagerItemPrivate *const d;
};
} // namespace
#endif /* INFOCONTEXTMANAGERITEM_H */
| 1,666
|
C++
|
.h
| 46
| 33.891304
| 79
| 0.814722
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,109
|
imageopscontextmanageritem.h
|
KDE_gwenview/app/imageopscontextmanageritem.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef IMAGEOPSCONTEXTMANAGERITEM_H
#define IMAGEOPSCONTEXTMANAGERITEM_H
// Qt
// KF
// Local
#include "abstractcontextmanageritem.h"
namespace Gwenview
{
class AbstractImageOperation;
class MainWindow;
class ImageOpsContextManagerItem : public AbstractContextManagerItem
{
Q_OBJECT
public:
ImageOpsContextManagerItem(ContextManager *, MainWindow *);
~ImageOpsContextManagerItem() override;
private Q_SLOTS:
void updateActions();
void updateSideBarContent();
void rotateLeft();
void rotateRight();
void mirror();
void flip();
void resizeImage();
void crop();
void startRedEyeReduction();
void applyImageOperation(AbstractImageOperation *);
void restoreDefaultImageViewTool();
void startBCG();
private:
struct Private;
Private *const d;
void resetCropState();
};
} // namespace
#endif /* IMAGEOPSCONTEXTMANAGERITEM_H */
| 1,713
|
C++
|
.h
| 52
| 30.269231
| 78
| 0.786148
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,110
|
fileopscontextmanageritem.h
|
KDE_gwenview/app/fileopscontextmanageritem.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef FILEOPSCONTEXTMANAGERITEM_H
#define FILEOPSCONTEXTMANAGERITEM_H
// Qt
// KF
#include <KNewFileMenu>
#include <KService>
// Local
#include "abstractcontextmanageritem.h"
class QAction;
class QMimeData;
class QListView;
class KActionCollection;
class KXMLGUIClient;
namespace Gwenview
{
class SideBarGroup;
class FileOpsContextManagerItem : public AbstractContextManagerItem
{
Q_OBJECT
public:
FileOpsContextManagerItem(Gwenview::ContextManager *manager, QListView *thumbnailView, KActionCollection *actionCollection, KXMLGUIClient *client);
~FileOpsContextManagerItem() override;
private Q_SLOTS:
void updateActions();
void updatePasteAction();
void updateSideBarContent();
void cut();
void copy();
void paste();
void rename();
void copyTo();
void moveTo();
void linkTo();
void trash();
void del();
void restore();
void showProperties();
void createFolder();
void populateOpenMenu();
void openInNewWindow();
void openWith(QAction *action);
void openContainingFolder();
private:
QList<QUrl> urlList() const;
void updateServiceList();
QMimeData *selectionMimeData();
QUrl pasteTargetUrl() const;
QListView *mThumbnailView;
KXMLGUIClient *mXMLGUIClient;
SideBarGroup *mGroup;
QAction *mCutAction;
QAction *mCopyAction;
QAction *mPasteAction;
QAction *mCopyToAction;
QAction *mMoveToAction;
QAction *mLinkToAction;
QAction *mRenameAction;
QAction *mTrashAction;
QAction *mDelAction;
QAction *mRestoreAction;
QAction *mShowPropertiesAction;
QAction *mCreateFolderAction;
QAction *mOpenInNewWindowAction;
QAction *mOpenWithAction;
QAction *mOpenContainingFolderAction;
QList<QAction *> mRegularFileActionList;
QList<QAction *> mTrashFileActionList;
KService::List mServiceList;
KNewFileMenu *mNewFileMenu;
bool mInTrash;
};
} // namespace
#endif /* FILEOPSCONTEXTMANAGERITEM_H */
| 2,801
|
C++
|
.h
| 89
| 28.067416
| 151
| 0.771344
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,112
|
viewmainpage.h
|
KDE_gwenview/app/viewmainpage.h
|
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef VIEWMAINPAGE_H
#define VIEWMAINPAGE_H
// Local
#include <lib/document/document.h>
// KF
// Qt
#include <QToolButton>
#include <QUrl>
#include <QWidget>
class QGraphicsWidget;
class KActionCollection;
namespace Gwenview
{
class AbstractRasterImageViewTool;
class DocumentView;
class GvCore;
class RasterImageView;
class SlideShow;
class ThumbnailBarView;
struct ViewMainPagePrivate;
/**
* Holds the active document view and associated widgetry.
*/
class ViewMainPage : public QWidget
{
Q_OBJECT
public:
static const int MaxViewCount;
ViewMainPage(QWidget *parent, SlideShow *, KActionCollection *, GvCore *);
~ViewMainPage() override;
ThumbnailBarView *thumbnailBar() const;
void loadConfig();
void saveConfig();
/**
* Reset the view
*/
void reset();
void setFullScreenMode(bool fullScreen);
void setSpotlightMode(bool spotlight);
int statusBarHeight() const;
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
/**
* Returns the url of the current document, or an invalid url if unknown
*/
QUrl url() const;
void openUrl(const QUrl &url);
/**
* Opens up to MaxViewCount urls, and set currentUrl as the current one
*/
void openUrls(const QList<QUrl> &urls, const QUrl ¤tUrl);
void reload();
Document::Ptr currentDocument() const;
bool isEmpty() const;
/**
* Returns the image view, if the current adapter has one.
*/
RasterImageView *imageView() const;
/**
* Returns the document view
*/
DocumentView *documentView() const;
QToolButton *toggleSideBarButton() const;
void showMessageWidget(QGraphicsWidget *, Qt::Alignment align = Qt::AlignHCenter | Qt::AlignTop);
Q_SIGNALS:
/**
* Emitted when the part has finished loading
*/
void completed();
void previousImageRequested();
void nextImageRequested();
void openUrlRequested(const QUrl &);
void openDirUrlRequested(const QUrl &);
void toggleFullScreenRequested();
void goToBrowseModeRequested();
void captionUpdateRequested(const QString &);
public Q_SLOTS:
void setStatusBarVisible(bool);
private Q_SLOTS:
void setThumbnailBarVisibility(bool visible);
void showContextMenu();
void slotViewFocused(DocumentView *);
void slotEnterPressed();
void trashView(DocumentView *);
void deselectView(DocumentView *);
void slotDirModelItemsAddedOrRemoved();
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
private:
friend struct ViewMainPagePrivate;
ViewMainPagePrivate *const d;
void updateFocus(const AbstractRasterImageViewTool *tool);
};
} // namespace
#endif /* VIEWMAINPAGE_H */
| 3,554
|
C++
|
.h
| 110
| 28.472727
| 101
| 0.749558
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,113
|
filtercontroller.h
|
KDE_gwenview/app/filtercontroller.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef FILTERCONTROLLER_H
#define FILTERCONTROLLER_H
#include <config-gwenview.h>
// Qt
#include <QDate>
#include <QDir>
#include <QImageReader>
#include <QList>
#include <QMimeDatabase>
#include <QMimeType>
#include <QObject>
#include <QWidget>
// KF
#include <KDirModel>
#include <KFileItem>
// Local
#include <lib/datewidget.h>
#include <lib/mimetypeutils.h>
#include <lib/semanticinfo/sorteddirmodel.h>
#include <lib/timeutils.h>
#include <semanticinfo/semanticinfodirmodel.h>
#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
// KF
#include <KRatingWidget>
// Local
#include <lib/semanticinfo/abstractsemanticinfobackend.h>
#include <lib/semanticinfo/tagmodel.h>
#endif
class QAction;
class QFrame;
class QLineEdit;
class QLabel;
class QComboBox;
class KComboBox;
namespace Gwenview
{
class SortedDirModel;
/**
* An AbstractSortedDirModelFilter which filters on the file names
*/
class NameFilter : public AbstractSortedDirModelFilter
{
public:
enum Mode {
Contains,
DoesNotContain,
};
NameFilter(SortedDirModel *model)
: AbstractSortedDirModelFilter(model)
, mText()
, mMode(Contains)
{
}
bool needsSemanticInfo() const override
{
return false;
}
bool recursiveNameSearch(const QDir &startingDir) const
{
if (!startingDir.exists()) {
return false;
}
const QStringList children = startingDir.entryList(QDir::NoDotAndDotDot | QDir::NoSymLinks | QDir::AllEntries);
const QFileInfoList childrenData = startingDir.entryInfoList(QDir::NoDotAndDotDot | QDir::NoSymLinks | QDir::AllEntries);
const QStringList acceptedMimeTypes = MimeTypeUtils::imageMimeTypes();
// check if current directory has a match
const QMimeDatabase db;
for (int i = 0, count = childrenData.count(); i < count; ++i) {
if ((children[i].contains(mText, Qt::CaseInsensitive) == (mMode == Contains))) {
const QMimeType mime = db.mimeTypeForFile(childrenData[i]);
if (acceptedMimeTypes.contains(mime.name())) {
return true;
}
}
}
// if not check for subdirectories and search those
// call this function again if there are any directories in the children
for (int i = 0, count = childrenData.count(); i < count; ++i) {
if (childrenData[i].isDir() && recursiveNameSearch(QDir(childrenData[i].absoluteFilePath()))) {
// if we have found a match, there is no need to search adjacent folders
return true;
}
}
return false;
}
bool acceptsIndex(const QModelIndex &index) const override
{
if (mText.isEmpty()) {
return true;
}
const SemanticInfoDirModel *currentModel = static_cast<const SemanticInfoDirModel *>(index.model());
const KFileItem fileItem = currentModel->itemForIndex(index);
switch (mMode) {
case Contains:
if (currentModel->hasChildren(index)) {
const QDir currentDir = QDir(fileItem.localPath());
return recursiveNameSearch(currentDir);
}
return index.data().toString().contains(mText, Qt::CaseInsensitive);
default: /*DoesNotContain:*/
if (currentModel->hasChildren(index)) {
const QDir currentDir = QDir(fileItem.localPath());
return recursiveNameSearch(currentDir);
}
return !index.data().toString().contains(mText, Qt::CaseInsensitive);
}
}
void setText(const QString &text)
{
mText = text;
model()->applyFilters();
}
void setMode(Mode mode)
{
mMode = mode;
model()->applyFilters();
}
private:
QString mText;
Mode mMode;
};
class NameFilterWidget : public QWidget
{
Q_OBJECT
public:
NameFilterWidget(SortedDirModel *);
~NameFilterWidget() override;
private Q_SLOTS:
void applyNameFilter();
private:
QPointer<NameFilter> mFilter;
KComboBox *mModeComboBox;
QLineEdit *mLineEdit;
};
/**
* An AbstractSortedDirModelFilter which filters on the file dates
*/
class DateFilter : public AbstractSortedDirModelFilter
{
public:
enum Mode {
GreaterOrEqual,
Equal,
LessOrEqual,
};
DateFilter(SortedDirModel *model)
: AbstractSortedDirModelFilter(model)
, mMode(GreaterOrEqual)
{
}
bool needsSemanticInfo() const override
{
return false;
}
bool acceptsIndex(const QModelIndex &index) const override
{
if (!mDate.isValid()) {
return true;
}
KFileItem fileItem = model()->itemForSourceIndex(index);
QDate date = TimeUtils::dateTimeForFileItem(fileItem).date();
switch (mMode) {
case GreaterOrEqual:
return date >= mDate;
case Equal:
return date == mDate;
default: /* LessOrEqual */
return date <= mDate;
}
}
void setDate(const QDate &date)
{
mDate = date;
model()->applyFilters();
}
void setMode(Mode mode)
{
mMode = mode;
model()->applyFilters();
}
private:
QDate mDate;
Mode mMode;
};
class DateFilterWidget : public QWidget
{
Q_OBJECT
public:
DateFilterWidget(SortedDirModel *);
~DateFilterWidget() override;
private Q_SLOTS:
void applyDateFilter();
private:
QPointer<DateFilter> mFilter;
KComboBox *mModeComboBox;
DateWidget *mDateWidget;
};
#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
/**
* An AbstractSortedDirModelFilter which filters on file ratings
*/
class RatingFilter : public AbstractSortedDirModelFilter
{
public:
enum Mode {
GreaterOrEqual,
Equal,
LessOrEqual,
};
RatingFilter(SortedDirModel *model)
: AbstractSortedDirModelFilter(model)
, mRating(0)
, mMode(GreaterOrEqual)
{
}
bool needsSemanticInfo() const override
{
return true;
}
bool acceptsIndex(const QModelIndex &index) const override
{
SemanticInfo info = model()->semanticInfoForSourceIndex(index);
switch (mMode) {
case GreaterOrEqual:
return info.mRating >= mRating;
case Equal:
return info.mRating == mRating;
default: /* LessOrEqual */
return info.mRating <= mRating;
}
}
void setRating(int value)
{
mRating = value;
model()->applyFilters();
}
void setMode(Mode mode)
{
mMode = mode;
model()->applyFilters();
}
private:
int mRating;
Mode mMode;
};
class RatingFilterWidget : public QWidget
{
Q_OBJECT
public:
RatingFilterWidget(SortedDirModel *);
~RatingFilterWidget() override;
private Q_SLOTS:
void slotRatingChanged(int value);
void updateFilterMode();
private:
KComboBox *mModeComboBox;
KRatingWidget *mRatingWidget;
QPointer<RatingFilter> mFilter;
};
/**
* An AbstractSortedDirModelFilter which filters on associated tags
*/
class TagFilter : public AbstractSortedDirModelFilter
{
public:
TagFilter(SortedDirModel *model)
: AbstractSortedDirModelFilter(model)
, mWantMatchingTag(true)
{
}
bool needsSemanticInfo() const override
{
return true;
}
bool acceptsIndex(const QModelIndex &index) const override
{
if (mTag.isEmpty()) {
return true;
}
SemanticInfo info = model()->semanticInfoForSourceIndex(index);
if (mWantMatchingTag) {
return info.mTags.contains(mTag);
} else {
return !info.mTags.contains(mTag);
}
}
void setTag(const SemanticInfoTag &tag)
{
mTag = tag;
model()->applyFilters();
}
void setWantMatchingTag(bool value)
{
mWantMatchingTag = value;
model()->applyFilters();
}
private:
SemanticInfoTag mTag;
bool mWantMatchingTag;
};
class TagFilterWidget : public QWidget
{
Q_OBJECT
public:
TagFilterWidget(SortedDirModel *);
~TagFilterWidget() override;
private Q_SLOTS:
void updateTagSetFilter();
private:
KComboBox *mModeComboBox;
QComboBox *mTagComboBox;
QPointer<TagFilter> mFilter;
};
#endif
/**
* An AbstractSortedDirModelFilter which filters on the image dimensions
*/
class ImageDimensions : public AbstractSortedDirModelFilter
{
public:
static const uint32_t minImageSizePx = 0; /**< Used to constraint the QLineEdit of the UI */
static const uint32_t maxImageSizePx = 100000; /**< Used to constraint the QLineEdit of the UI */
enum Mode {
GreaterOrEqual,
Equal,
LessOrEqual,
};
ImageDimensions(SortedDirModel *model)
: AbstractSortedDirModelFilter(model)
, mMode(GreaterOrEqual)
, mHeight(0)
, mWidth(0)
{
}
bool needsSemanticInfo() const override
{
return false;
}
bool acceptsIndex(const QModelIndex &index) const override
{
KFileItem fileItem = model()->itemForSourceIndex(index);
QImageReader reader(fileItem.localPath());
const QSize sizeOfImage = reader.size();
const uint32_t height = sizeOfImage.height();
const uint32_t width = sizeOfImage.width();
switch (mMode) {
case GreaterOrEqual: {
return width >= mWidth && height >= mHeight;
}
case Equal: {
return ((mWidth == 0) || (mWidth == width)) && ((mHeight == 0) || (mHeight == height));
}
default: /* LessOrEqual */
{
return ((mWidth == 0) || (width <= mWidth)) && ((mHeight == 0) || (height <= mHeight));
}
}
return true;
}
/**
* Sets the filtering mode
*/
void setMode(Mode mode)
{
mMode = mode;
model()->applyFilters();
}
/**
* Sets the image dimesions that the filter will use
*/
void setSizes(uint32_t width, uint32_t height)
{
mWidth = width;
mHeight = height;
model()->applyFilters();
}
private:
Mode mMode; /**< Contains the filtering mode of the image dimension */
uint32_t mHeight; /**< Holds the height that the filter will check */
uint32_t mWidth; /**< Holds the width that the filter will check */
};
class ImageDimensionsWidget : public QWidget
{
Q_OBJECT
public:
ImageDimensionsWidget(SortedDirModel *);
~ImageDimensionsWidget() override;
private Q_SLOTS:
void applyImageDimensions();
private:
QPointer<ImageDimensions> mFilter;
KComboBox *mModeComboBox;
KComboBox *mDimensionComboBox;
QLineEdit *mLineEditWidth;
QLineEdit *mLineEditHeight;
QLabel *mLabelWidth;
QLabel *mLabelHeight;
};
/**
* This class manages the filter widgets in the filter frame and assign the
* corresponding filters to the SortedDirModel
*/
class FilterController : public QObject
{
Q_OBJECT
public:
FilterController(QFrame *filterFrame, SortedDirModel *model);
QList<QAction *> actionList() const;
private Q_SLOTS:
void addFilterByName();
void addFilterByDate();
#ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE
void addFilterByRating();
void addFilterByTag();
#endif
void addFilterByImageDimensions();
void slotFilterWidgetClosed();
private:
void addAction(const QString &text, const char *slot, const QKeySequence &shortcut);
void addFilter(QWidget *widget);
FilterController *q;
QFrame *mFrame;
SortedDirModel *mDirModel;
QList<QAction *> mActionList;
int mFilterWidgetCount; /**< How many filter widgets are in mFrame */
};
} // namespace
#endif /* FILTERCONTROLLER_H */
| 12,669
|
C++
|
.h
| 444
| 22.869369
| 129
| 0.66653
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,114
|
fileoperations.h
|
KDE_gwenview/app/fileoperations.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef FILEOPERATIONS_H
#define FILEOPERATIONS_H
#include <QUrl>
#include <QWidget>
class ContextManager;
namespace Gwenview
{
namespace FileOperations
{
enum Operation {
TRASH,
COPY,
MOVE,
LINK,
UNKNOWN,
PUT,
};
void copyTo(const QList<QUrl> &urlList, QWidget *parent, ContextManager *contextManager);
void moveTo(const QList<QUrl> &urlList, QWidget *parent, ContextManager *contextManager);
void linkTo(const QList<QUrl> &urlList, QWidget *parent, ContextManager *contextManager);
void trash(const QList<QUrl> &urlList, QWidget *parent);
void del(const QList<QUrl> &urlList, QWidget *parent);
void rename(const QUrl &url, QWidget *parent, ContextManager *contextManager);
void showMenuForDroppedUrls(QWidget *parent, const QList<QUrl> &urlList, const QUrl &destUrl);
} // namespace
} // namespace
#endif /* FILEOPERATIONS_H */
| 1,676
|
C++
|
.h
| 43
| 37.116279
| 94
| 0.792593
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,115
|
mainwindow.h
|
KDE_gwenview/app/mainwindow.h
|
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
// Qt
#include <QAction>
// KF
#include <KXmlGuiWindow>
class QModelIndex;
class QUrl;
class QMouseEvent;
namespace Gwenview
{
class ViewMainPage;
class ContextManager;
class MainWindow : public KXmlGuiWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow() override;
/**
* Defines the url to display when the window is shown for the first time.
*/
void setInitialUrl(const QUrl &);
void startSlideShow();
ViewMainPage *viewMainPage() const;
ContextManager *contextManager() const;
void setDistractionFreeMode(bool);
public Q_SLOTS:
void showStartMainPage();
/**
* Go to url, without changing current mode
*/
void goToUrl(const QUrl &);
Q_SIGNALS:
void viewModeChanged();
public Q_SLOTS:
void setCaption(const QString &) override;
void setCaption(const QString &, bool modified) override;
protected:
bool queryClose() override;
QSize sizeHint() const override;
void showEvent(QShowEvent *) override;
void resizeEvent(QResizeEvent *) override;
void saveProperties(KConfigGroup &) override;
void readProperties(const KConfigGroup &) override;
bool eventFilter(QObject *, QEvent *) override;
void mousePressEvent(QMouseEvent *) override;
void mouseDoubleClickEvent(QMouseEvent *) override;
private Q_SLOTS:
void setActiveViewModeAction(QAction *action);
void openDirUrl(const QUrl &);
void slotThumbnailViewIndexActivated(const QModelIndex &);
void slotStartMainPageUrlSelected(const QUrl &);
void goUp();
void toggleSideBar(bool visible);
void toggleOperationsSideBar(bool visible);
void slotModifiedDocumentListChanged();
void slotUpdateCaption(const QString &caption);
void slotPartCompleted();
void slotDirModelNewItems();
void slotDirListerCompleted();
void slotSelectionChanged();
void slotCurrentDirUrlChanged(const QUrl &url);
void goToPrevious();
void goToNext();
void goToFirst();
void goToLast();
void updatePreviousNextActions();
void leaveFullScreen();
void toggleFullScreen(bool);
void leaveSpotlightMode();
void toggleSpotlightMode(bool);
void toggleSlideShow();
void updateSlideShowAction();
void saveCurrent();
void saveCurrentAs();
void openFile();
void openUrl(const QUrl &url);
void reload();
void showDocumentInFullScreen(const QUrl &);
/**
* Shows Gwenview's settings dialog.
* @param page defines which page should be shown initially.
*/
void showConfigDialog(int page = 0);
void loadConfig();
void print();
void printPreview();
void preloadNextUrl();
void toggleMenuBar();
void toggleStatusBar(bool visible);
void showFirstDocumentReached();
void showLastDocumentReached();
void replaceLocation();
void onFocusChanged(QWidget *old, QWidget *now);
private:
struct Private;
MainWindow::Private *const d;
void openSelectedDocuments();
void saveConfig();
void configureShortcuts();
void mouseButtonNavigate(QMouseEvent *);
void folderViewUrlChanged(const QUrl &url);
void syncSortOrder(const QUrl &url);
};
} // namespace
#endif /* MAINWINDOW_H */
| 4,044
|
C++
|
.h
| 122
| 29.04918
| 79
| 0.746584
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,116
|
splitter.h
|
KDE_gwenview/app/splitter.h
|
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef SPLITTER_H
#define SPLITTER_H
// Qt
#include <QSplitter>
namespace Gwenview
{
class SplitterHandle : public QSplitterHandle
{
public:
SplitterHandle(Qt::Orientation orientation, QSplitter *parent)
: QSplitterHandle(orientation, parent)
{
}
};
/**
* Home made splitter to be able to define a custom handle which is border with
* "mid" colored lines.
*/
class Splitter : public QSplitter
{
public:
Splitter(Qt::Orientation orientation, QWidget *parent)
: QSplitter(orientation, parent)
{
}
protected:
QSplitterHandle *createHandle() override
{
return new SplitterHandle(orientation(), this);
}
};
} // namespace
#endif /* SPLITTER_H */
| 1,478
|
C++
|
.h
| 48
| 28.229167
| 79
| 0.766573
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,117
|
saveallhelper.h
|
KDE_gwenview/app/saveallhelper.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2010 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef SAVEALLHELPER_H
#define SAVEALLHELPER_H
// Qt
#include <QObject>
// KF
// Local
class KJob;
namespace Gwenview
{
struct SaveAllHelperPrivate;
class SaveAllHelper : public QObject
{
Q_OBJECT
public:
explicit SaveAllHelper(QWidget *parent);
~SaveAllHelper() override;
void save();
private Q_SLOTS:
void slotCanceled();
void slotResult(KJob *);
private:
SaveAllHelperPrivate *const d;
};
} // namespace
#endif /* SAVEALLHELPER_H */
| 1,290
|
C++
|
.h
| 41
| 29.390244
| 81
| 0.78751
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,118
|
documentinfoprovider.h
|
KDE_gwenview/app/documentinfoprovider.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2010 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef DOCUMENTINFOPROVIDER_H
#define DOCUMENTINFOPROVIDER_H
// Qt
// KF
// Local
#include <lib/thumbnailview/abstractdocumentinfoprovider.h>
namespace Gwenview
{
class SortedDirModel;
class DocumentInfoProvider : public AbstractDocumentInfoProvider
{
Q_OBJECT
public:
DocumentInfoProvider(SortedDirModel *model);
bool isBusy(const QUrl &url) override;
bool isModified(const QUrl &url) override;
void thumbnailForDocument(const QUrl &url, ThumbnailGroup::Enum group, QPixmap *outPix, QSize *outFullSize) const override;
private:
SortedDirModel *const mDirModel;
};
} // namespace
#endif /* DOCUMENTINFOPROVIDER_H */
| 1,467
|
C++
|
.h
| 38
| 36.526316
| 127
| 0.805949
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,119
|
gvcore.h
|
KDE_gwenview/app/gvcore.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef GVCORE_H
#define GVCORE_H
// Qt
#include <QObject>
// KF
// Local
class KJob;
class QUrl;
class QAbstractItemModel;
class QPalette;
class QString;
namespace Gwenview
{
class AbstractSemanticInfoBackEnd;
class MainWindow;
class SortedDirModel;
struct GvCorePrivate;
class GvCore : public QObject
{
Q_OBJECT
public:
GvCore(MainWindow *mainWindow, SortedDirModel *);
~GvCore() override;
enum PaletteType {
NormalPalette = 0,
NormalViewPalette,
FullScreenPalette,
FullScreenViewPalette,
};
QAbstractItemModel *recentFoldersModel() const;
QAbstractItemModel *recentFilesModel() const;
SortedDirModel *sortedDirModel() const;
AbstractSemanticInfoBackEnd *semanticInfoBackEnd() const;
void addUrlToRecentFolders(QUrl);
void addUrlToRecentFiles(const QUrl &);
void clearRecentFilesAndFolders();
QPalette palette(PaletteType type) const;
QString fullScreenPaletteName() const;
void setTrackFileManagerSorting(bool enable);
/// Whether the file listing should follow the filemanager (i.e dolphin) sorting for this folder, default to false
bool trackFileManagerSorting();
public Q_SLOTS:
void saveAll();
void save(const QUrl &);
void saveAs(const QUrl &);
void rotateLeft(const QUrl &);
void rotateRight(const QUrl &);
void setRating(const QUrl &, int);
private Q_SLOTS:
void slotConfigChanged();
void slotSaveResult(KJob *);
private:
GvCorePrivate *const d;
bool sortingTracksFileManager = false;
};
} // namespace
#endif /* GVCORE_H */
| 2,407
|
C++
|
.h
| 73
| 29.739726
| 118
| 0.770229
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,120
|
abstractcontextmanageritem.h
|
KDE_gwenview/app/abstractcontextmanageritem.h
|
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef ABSTRACTCONTEXTMANAGERITEM_H
#define ABSTRACTCONTEXTMANAGERITEM_H
// Qt
#include <QWidget>
namespace Gwenview
{
class ContextManager;
struct AbstractContextManagerItemPrivate;
class AbstractContextManagerItem : public QObject
{
Q_OBJECT
public:
AbstractContextManagerItem(ContextManager *);
~AbstractContextManagerItem() override;
QWidget *widget() const;
ContextManager *contextManager() const;
protected:
void setWidget(QWidget *widget);
private:
AbstractContextManagerItemPrivate *const d;
};
} // namespace
#endif /* ABSTRACTCONTEXTMANAGERITEM_H */
| 1,366
|
C++
|
.h
| 38
| 33.789474
| 79
| 0.811738
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,121
|
gvbrowserextension.h
|
KDE_gwenview/part/gvbrowserextension.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef GVBROWSEREXTENSION_H
#define GVBROWSEREXTENSION_H
// Qt
#include <QtGlobal>
// KF
#include <KParts/NavigationExtension>
// Local
namespace Gwenview
{
struct GVBrowserExtensionPrivate;
class GVBrowserExtension : public KParts::NavigationExtension
{
Q_OBJECT
public:
explicit GVBrowserExtension(KParts::ReadOnlyPart *);
~GVBrowserExtension() override;
private Q_SLOTS:
void print();
private:
GVBrowserExtensionPrivate *const d;
};
} // namespace
#endif /* GVBROWSEREXTENSION_H */
| 1,329
|
C++
|
.h
| 39
| 32.205128
| 81
| 0.803292
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,122
|
gvpart.h
|
KDE_gwenview/part/gvpart.h
|
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef GVPART_H
#define GVPART_H
// Qt
// KF
#include <KParts/ReadOnlyPart>
// Local
#include <lib/document/document.h>
class KPluginMetaData;
namespace Gwenview
{
class DocumentView;
class GVPart : public KParts::ReadOnlyPart
{
Q_OBJECT
public:
GVPart(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &);
protected:
bool openUrl(const QUrl &url) override;
private Q_SLOTS:
void showContextMenu();
void showProperties();
void saveAs();
void showJobError(KJob *);
private:
DocumentView *mDocumentView = nullptr;
};
} // namespace
#endif /* GVPART_H */
| 1,405
|
C++
|
.h
| 43
| 30.534884
| 106
| 0.78513
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,123
|
importerconfigdialog.h
|
KDE_gwenview/importer/importerconfigdialog.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef IMPORTERCONFIGDIALOG_H
#define IMPORTERCONFIGDIALOG_H
// Qt
// KF
#include <KConfigDialog>
// Local
namespace Gwenview
{
struct ImporterConfigDialogPrivate;
class ImporterConfigDialog : public KConfigDialog
{
Q_OBJECT
public:
explicit ImporterConfigDialog(QWidget *);
~ImporterConfigDialog() override;
private Q_SLOTS:
void slotHelpLinkActivated(const QString &keyword);
void updatePreview();
private:
ImporterConfigDialogPrivate *const d;
};
} // namespace
#endif /* IMPORTERCONFIGDIALOG_H */
| 1,349
|
C++
|
.h
| 39
| 32.615385
| 81
| 0.804784
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,124
|
fileutils.h
|
KDE_gwenview/importer/fileutils.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef FILEUTILS_H
#define FILEUTILS_H
class QWidget;
class QUrl;
namespace Gwenview
{
namespace FileUtils
{
enum RenameResult {
RenamedOK, /** Renamed without problem */
RenamedUnderNewName, /** Destination already existed, so rename() added a suffix to make the name unique */
Skipped, /** Destination already existed and contained the same data as source, so rename() just removed the source */
RenameFailed, /** Rename failed */
};
/**
* Compare content of two urls, returns whether they are the same
*/
bool contentsAreIdentical(const QUrl &url1, const QUrl &url2, QWidget *authWindow = nullptr);
/**
* Rename src to dst, returns RenameResult
*/
RenameResult rename(const QUrl &src, const QUrl &dst, QWidget *authWindow = nullptr);
} // namespace
} // namespace
#endif /* FILEUTILS_H */
| 1,634
|
C++
|
.h
| 41
| 38.073171
| 122
| 0.777989
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,125
|
dialogpage.h
|
KDE_gwenview/importer/dialogpage.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef DIALOGPAGE_H
#define DIALOGPAGE_H
// Qt
#include <QWidget>
// KF
// Local
class KGuiItem;
namespace Gwenview
{
struct DialogPagePrivate;
class DialogPage : public QWidget
{
Q_OBJECT
public:
explicit DialogPage(QWidget *parent = nullptr);
~DialogPage() override;
void removeButtons();
void setText(const QString &);
int addButton(const KGuiItem &);
int exec();
public Q_SLOTS:
void slotShowErrors(const QStringList &, const QStringList &);
void slotShowFailedFileDetails();
void slotShowFailedDirDetails();
private:
DialogPagePrivate *const d;
};
} // namespace
#endif /* DIALOGPAGE_H */
| 1,464
|
C++
|
.h
| 45
| 30.2
| 81
| 0.779758
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,126
|
serializedurlmap.h
|
KDE_gwenview/importer/serializedurlmap.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2012 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef SERIALIZEDURLMAP_H
#define SERIALIZEDURLMAP_H
// Local
// KF
// Qt
class KConfigGroup;
class QUrl;
namespace Gwenview
{
struct SerializedUrlMapPrivate;
/**
* A map-like QUrl=>QUrl object, serialized in a KConfigGroup
*/
class SerializedUrlMap
{
public:
SerializedUrlMap();
~SerializedUrlMap();
void setConfigGroup(const KConfigGroup &);
QUrl value(const QUrl &) const;
void insert(const QUrl &key, const QUrl &value);
private:
SerializedUrlMapPrivate *const d;
};
} // namespace
#endif /* SERIALIZEDURLMAP_H */
| 1,371
|
C++
|
.h
| 42
| 30.619048
| 81
| 0.788872
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,127
|
thumbnailpage.h
|
KDE_gwenview/importer/thumbnailpage.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef THUMBNAILPAGE_H
#define THUMBNAILPAGE_H
// Qt
#include <QModelIndex>
#include <QUrl>
#include <QWidget>
// KF
// Local
#include "documentdirfinder.h"
namespace Gwenview
{
struct ThumbnailPagePrivate;
class ThumbnailPage : public QWidget
{
Q_OBJECT
public:
ThumbnailPage();
~ThumbnailPage() override;
/**
* Returns the list of urls to import
* Only valid after importRequested() has been emitted
*/
QList<QUrl> urlList() const;
QUrl destinationUrl() const;
void setDestinationUrl(const QUrl &);
void setSourceUrl(const QUrl &, const QString &icon, const QString &label);
Q_SIGNALS:
void importRequested();
void rejected();
private Q_SLOTS:
void slotImportSelected();
void slotImportAll();
void updateImportButtons();
void openUrl(const QUrl &);
void slotDocumentDirFinderDone(const QUrl &url, DocumentDirFinder::Status status);
void showConfigDialog();
void openUrlFromIndex(const QModelIndex &index);
void setupSrcUrlTreeView();
void toggleSrcUrlTreeView();
void slotSrcUrlModelExpand(const QModelIndex &index);
private:
bool mDiscoverAvailable = false;
friend struct ThumbnailPagePrivate;
ThumbnailPagePrivate *const d;
void importList(const QModelIndexList &);
void installProtocolSupport() const;
};
} // namespace
#endif /* THUMBNAILPAGE_H */
| 2,197
|
C++
|
.h
| 65
| 30.753846
| 86
| 0.768685
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,128
|
filenameformater.h
|
KDE_gwenview/importer/filenameformater.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef FILENAMEFORMATER_H
#define FILENAMEFORMATER_H
// Qt
#include <QMap>
// KF
// Local
class QDateTime;
class QString;
class QUrl;
namespace Gwenview
{
struct FileNameFormaterPrivate;
class FileNameFormater
{
public:
using HelpMap = QMap<QString, QString>;
explicit FileNameFormater(const QString &format);
~FileNameFormater();
/**
* Given an url and its dateTime, returns a filename according to the
* format passed to the constructor
*/
QString format(const QUrl &url, const QDateTime &dateTime);
/**
* Returns a map whose keys are the available keywords and values are the
* keyword help
*/
static HelpMap helpMap();
private:
FileNameFormaterPrivate *const d;
};
} // namespace
#endif /* FILENAMEFORMATER_H */
| 1,605
|
C++
|
.h
| 49
| 30.142857
| 81
| 0.77193
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,129
|
importer.h
|
KDE_gwenview/importer/importer.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef IMPORTER_H
#define IMPORTER_H
// Qt
#include <QObject>
#include <QUrl>
// KF
// Local
class KJob;
namespace Gwenview
{
struct ImporterPrivate;
class Importer : public QObject
{
Q_OBJECT
public:
explicit Importer(QWidget *authWindow);
~Importer() override;
/**
* Defines the auto-rename format applied to imported documents
* Set to QString() to reset
*/
void setAutoRenameFormat(const QString &);
void start(const QList<QUrl> &list, const QUrl &destUrl);
QList<QUrl> importedUrlList() const;
/**
* Documents which have been skipped during import
*/
QList<QUrl> skippedUrlList() const;
/**
* Documents which have failed during import
*/
QList<QUrl> failedUrlList() const;
/**
* Subfolders which failed to create during import
*/
QList<QUrl> failedSubFolderList() const;
/**
* How many documents have been renamed during import
*/
int renamedCount() const;
Q_SIGNALS:
void importFinished();
void progressChanged(int);
void maximumChanged(int);
/**
* An error has occurred and caused the whole process to stop without
* importing anything
*/
void error(const QString &message);
private Q_SLOTS:
void slotCopyDone(KJob *);
void slotPercent(KJob *, unsigned long);
void emitProgressChanged();
private:
friend struct ImporterPrivate;
ImporterPrivate *const d;
void advance();
void finalizeImport();
};
} // namespace
#endif /* IMPORTER_H */
| 2,356
|
C++
|
.h
| 77
| 26.948052
| 81
| 0.732357
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,130
|
progresspage.h
|
KDE_gwenview/importer/progresspage.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef PROGRESSPAGE_H
#define PROGRESSPAGE_H
// Qt
#include <QWidget>
// KF
// Local
namespace Gwenview
{
class Importer;
struct ProgressPagePrivate;
class ProgressPage : public QWidget
{
Q_OBJECT
public:
explicit ProgressPage(Importer *);
~ProgressPage() override;
private:
ProgressPagePrivate *const d;
};
} // namespace
#endif /* PROGRESSPAGE_H */
| 1,191
|
C++
|
.h
| 37
| 30.378378
| 81
| 0.795614
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,131
|
importdialog.h
|
KDE_gwenview/importer/importdialog.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef IMPORTDIALOG_H
#define IMPORTDIALOG_H
// Qt
#include <QUrl>
// KF
#include <KMainWindow>
// Local
namespace Gwenview
{
class ImportDialogPrivate;
class ImportDialog : public KMainWindow
{
Q_OBJECT
public:
ImportDialog();
~ImportDialog() override;
QSize sizeHint() const override;
public Q_SLOTS:
void setSourceUrl(const QUrl &, const QString &deviceUdi);
private Q_SLOTS:
void startImport();
void slotImportFinished();
void showImportError(const QString &);
Q_SIGNALS:
void showErrors(const QStringList &, const QStringList &);
private:
ImportDialogPrivate *const d;
};
} // namespace
#endif /* IMPORTDIALOG_H */
| 1,487
|
C++
|
.h
| 46
| 30.086957
| 81
| 0.783006
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,132
|
documentdirfinder.h
|
KDE_gwenview/importer/documentdirfinder.h
|
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef DOCUMENTDIRFINDER_H
#define DOCUMENTDIRFINDER_H
// Qt
#include <QObject>
// KF
#include <KFileItem>
// Local
namespace Gwenview
{
struct DocumentDirFinderPrivate;
/**
* This class is a worker which tries to find the document dir given a root
* url. This is useful for digital camera cards, which often have a dir
* hierarchy like this:
* /DCIM
* /FOOBAR
* /PICT0001.JPG
* /PICT0002.JPG
* ...
* /PICTnnnn.JPG
*/
class DocumentDirFinder : public QObject
{
Q_OBJECT
public:
enum Status {
NoDocumentFound,
DocumentDirFound,
MultipleDirsFound,
};
explicit DocumentDirFinder(const QUrl &rootUrl);
~DocumentDirFinder() override;
void start();
Q_SIGNALS:
void done(const QUrl &, DocumentDirFinder::Status);
void protocollNotSupportedError(const QString &errorText);
private Q_SLOTS:
void slotItemsAdded(const QUrl &, const KFileItemList &);
void slotCompleted();
private:
DocumentDirFinderPrivate *const d;
void finish(const QUrl &, Status);
};
} // namespace
#endif /* DOCUMENTDIRFINDER_H */
| 1,920
|
C++
|
.h
| 61
| 28.836066
| 81
| 0.758284
|
KDE/gwenview
| 117
| 25
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,133
|
phpdebug.cpp
|
KDE_umbrello/lib/kdev5-php/phpdebug.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2014 Milian Wolff <mail@milianw.de>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include "phpdebug.h"
Q_LOGGING_CATEGORY(PHP, "kdevelop.languages.php")
| 219
|
C++
|
.cpp
| 6
| 33.5
| 63
| 0.760766
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,138
|
testproviderdebug.cpp
|
KDE_umbrello/lib/kdev5-php/testprovider/testproviderdebug.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2014 Milian Wolff <mail@milianw.de>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include "testproviderdebug.h"
Q_LOGGING_CATEGORY(TESTPROVIDER, "kdevelop.languages.php.testprovider")
| 250
|
C++
|
.cpp
| 6
| 38.666667
| 71
| 0.7875
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,145
|
parserdebug.cpp
|
KDE_umbrello/lib/kdev5-php/parser/parserdebug.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2014 Milian Wolff <mail@milianw.de>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include "parserdebug.h"
Q_LOGGING_CATEGORY(PARSER, "kdevelop.languages.php.parser")
| 232
|
C++
|
.cpp
| 6
| 35.666667
| 63
| 0.77027
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,147
|
refactoring.cpp
|
KDE_umbrello/lib/kdev5-php/codegen/refactoring.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2014 Miquel Sabaté <mikisabate@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <QObject>
#include <codegen/refactoring.h>
namespace Php
{
Refactoring::Refactoring(QObject *parent)
: BasicRefactoring(parent)
{
/* There's nothing to do here. */
}
} // End of namespace Php
| 371
|
C++
|
.cpp
| 14
| 23.785714
| 70
| 0.74212
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
749,149
|
completiondebug.cpp
|
KDE_umbrello/lib/kdev5-php/completion/completiondebug.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2014 Milian Wolff <mail@milianw.de>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include "completiondebug.h"
Q_LOGGING_CATEGORY(COMPLETION, "kdevelop.languages.php.completion")
| 244
|
C++
|
.cpp
| 6
| 37.666667
| 67
| 0.782051
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,162
|
phpdocsdebug.cpp
|
KDE_umbrello/lib/kdev5-php/docs/phpdocsdebug.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2015 Kevin Funk <kfunk@kde.org>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include "phpdocsdebug.h"
Q_LOGGING_CATEGORY(DOCS, "kdevelop.languages.php.docs")
| 225
|
C++
|
.cpp
| 6
| 34.5
| 59
| 0.762791
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,163
|
phpdocumentationwidget.cpp
|
KDE_umbrello/lib/kdev5-php/docs/phpdocumentationwidget.cpp
|
/* This file is part of the KDevelop PHP Documentation Plugin
SPDX-FileCopyrightText: 2012 Milian Wolff <mail@milianw.de>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "phpdocumentationwidget.h"
#include <QProgressBar>
#include <QLabel>
#include <QVBoxLayout>
#include <QTemporaryFile>
#include <QTextStream>
#include <KLocalizedString>
#include "phpdocsplugin.h"
#include <documentation/standarddocumentationview.h>
QTemporaryFile* createStyleSheet(QObject* parent)
{
QTemporaryFile* file = new QTemporaryFile(parent);
bool ret = file->open();
Q_ASSERT(ret);
Q_UNUSED(ret);
QTextStream ts(file);
ts << ".page-tools { float: none !important; } body { background: white !important; };";
return file;
}
PhpDocumentationWidget::PhpDocumentationWidget(KDevelop::DocumentationFindWidget* find, const QUrl &url,
PhpDocsPlugin* provider, QWidget* parent)
: QStackedWidget(parent)
, m_loading(new QWidget(this))
, m_styleSheet(createStyleSheet(this))
, m_provider(provider)
{
m_part = new KDevelop::StandardDocumentationView(find, this);
m_part->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
addWidget(m_part);
addWidget(m_loading);
QProgressBar* progressbar = new QProgressBar;
progressbar->setValue(0);
progressbar->setMinimum(0);
progressbar->setMaximum(100);
progressbar->setAlignment(Qt::AlignCenter);
connect( m_part, &KDevelop::StandardDocumentationView::loadProgress,
progressbar, &QProgressBar::setValue );
QVBoxLayout* layout = new QVBoxLayout;
layout->addStretch();
QLabel* label = new QLabel(i18n("...loading documentation..."));
label->setAlignment(Qt::AlignCenter);
layout->addWidget(label);
layout->addWidget(progressbar);
layout->addStretch();
m_loading->setLayout(layout);
setCurrentWidget(m_loading);
connect(m_part, &KDevelop::StandardDocumentationView::linkClicked, this, &PhpDocumentationWidget::linkClicked);
connect(m_part, &KDevelop::StandardDocumentationView::loadFinished, this, &PhpDocumentationWidget::documentLoaded);
m_part->load( url );
}
PhpDocumentationWidget::~PhpDocumentationWidget()
{
// make sure we don't get called by any of the m_part signals on shutdown, see also:
// https://codereview.qt-project.org/#/c/83800/
disconnect(m_part, 0, this, 0);
}
void PhpDocumentationWidget::linkClicked(const QUrl& url)
{
m_part->load(url);
m_provider->addToHistory(url);
}
void PhpDocumentationWidget::documentLoaded()
{
m_part->settings()->setUserStyleSheetUrl(QUrl::fromLocalFile(m_styleSheet->fileName()));
setCurrentWidget(m_part);
removeWidget(m_loading);
delete m_loading;
m_loading = 0;
}
| 2,826
|
C++
|
.cpp
| 73
| 34.383562
| 119
| 0.733723
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
749,166
|
helper.cpp
|
KDE_umbrello/lib/kdev5-php/duchain/helper.cpp
|
/*
This file is part of KDevelop
SPDX-FileCopyrightText: 2008 Niko Sams <niko.sams@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "helper.h"
#include <KParts/MainWindow>
#include <KLocalizedString>
#include <language/duchain/ducontext.h>
#include <language/duchain/duchainlock.h>
#include <language/duchain/persistentsymboltable.h>
#include <language/duchain/duchain.h>
#include <language/duchain/stringhelpers.h>
#include <language/duchain/parsingenvironment.h>
#include <interfaces/icore.h>
#include <interfaces/iprojectcontroller.h>
#include <interfaces/iuicontroller.h>
#include <interfaces/iproject.h>
#include <project/projectmodel.h>
#include <util/path.h>
#include "editorintegrator.h"
#include "../parser/parsesession.h"
#include "phpast.h"
#include "phpdefaultvisitor.h"
#include "declarations/classdeclaration.h"
#include "declarations/classmethoddeclaration.h"
#include "declarations/functiondeclaration.h"
#include "duchaindebug.h"
#define ifDebug(x)
using namespace KDevelop;
namespace Php
{
bool isMatch(Declaration* declaration, DeclarationType declarationType)
{
if (declarationType == ClassDeclarationType
&& dynamic_cast<ClassDeclaration*>(declaration)
) {
return true;
} else if (declarationType == FunctionDeclarationType
&& dynamic_cast<FunctionDeclaration*>(declaration)
) {
return true;
} else if (declarationType == ConstantDeclarationType
&& declaration->abstractType() && declaration->abstractType()->modifiers() & AbstractType::ConstModifier
&& (!declaration->context() || declaration->context()->type() != DUContext::Class)
) {
return true;
} else if (declarationType == GlobalVariableDeclarationType
&& declaration->kind() == Declaration::Instance
&& !(declaration->abstractType() && declaration->abstractType()->modifiers() & AbstractType::ConstModifier)
) {
return true;
} else if (declarationType == NamespaceDeclarationType
&& (declaration->kind() == Declaration::Namespace || declaration->kind() == Declaration::NamespaceAlias || dynamic_cast<ClassDeclaration*>(declaration)) )
{
return true;
}
return false;
}
DeclarationPointer findDeclarationImportHelper(DUContext* currentContext, const QualifiedIdentifier& id,
DeclarationType declarationType)
{
/// Qualified identifier for 'self'
static const QualifiedIdentifier selfQId(QStringLiteral("self"));
/// Qualified identifier for 'parent'
static const QualifiedIdentifier parentQId(QStringLiteral("parent"));
/// Qualified identifier for 'static'
static const QualifiedIdentifier staticQId(QStringLiteral("static"));
ifDebug(qCDebug(DUCHAIN) << id.toString() << declarationType;)
if (declarationType == ClassDeclarationType && id == selfQId) {
DUChainReadLocker lock(DUChain::lock());
if (currentContext->type() == DUContext::Class) {
return DeclarationPointer(currentContext->owner());
} else if (currentContext->parentContext() && currentContext->parentContext()->type() == DUContext::Class) {
return DeclarationPointer(currentContext->parentContext()->owner());
} else {
return DeclarationPointer();
}
} else if (declarationType == ClassDeclarationType && id == staticQId) {
DUChainReadLocker lock;
if (currentContext->type() == DUContext::Class) {
return DeclarationPointer(currentContext->owner());
} else if (currentContext->parentContext() && currentContext->parentContext()->type() == DUContext::Class) {
return DeclarationPointer(currentContext->parentContext()->owner());
} else {
return DeclarationPointer();
}
} else if (declarationType == ClassDeclarationType && id == parentQId) {
//there can be just one Class-Context imported
DUChainReadLocker lock;
DUContext* classCtx = nullptr;
if (currentContext->type() == DUContext::Class) {
classCtx = currentContext;
} else if (currentContext->parentContext() && currentContext->parentContext()->type() == DUContext::Class) {
classCtx = currentContext->parentContext();
}
if (classCtx) {
for(const DUContext::Import &i : classCtx->importedParentContexts()) {
DUContext* ctx = i.context(classCtx->topContext());
if (ctx && ctx->type() == DUContext::Class) {
return DeclarationPointer(ctx->owner());
}
}
}
return DeclarationPointer();
} else {
DUChainReadLocker lock;
QList<Declaration*> foundDeclarations = currentContext->topContext()->findDeclarations(id);
if (foundDeclarations.isEmpty()) {
// If it's not in the top context, try the current context (namespaces...)
// this fixes the bug: https://bugs.kde.org/show_bug.cgi?id=322274
foundDeclarations = currentContext->findDeclarations(id);
}
if (foundDeclarations.isEmpty()) {
// If it is neither in the top not the current context it might be defined in a different context
// Look up with fully qualified identifier
foundDeclarations = currentContext->topContext()->findDeclarations(identifierWithNamespace(id, currentContext));
}
for(Declaration *declaration : foundDeclarations) {
if (isMatch(declaration, declarationType)) {
return DeclarationPointer(declaration);
}
}
if ( currentContext->url() == internalFunctionFile() ) {
// when compiling php internal functions, we don't need to ask the persistent symbol table for anything
return DeclarationPointer();
}
lock.unlock();
if (declarationType != GlobalVariableDeclarationType) {
ifDebug(qCDebug(DUCHAIN) << "No declarations found with findDeclarations, trying through PersistentSymbolTable";)
DeclarationPointer decl;
decl = findDeclarationInPST(currentContext, id, declarationType);
if (!decl)
{
decl = findDeclarationInPST(currentContext, identifierWithNamespace(id, currentContext), declarationType);
}
if (decl) {
ifDebug(qCDebug(DUCHAIN) << "PST declaration exists";)
} else {
ifDebug(qCDebug(DUCHAIN) << "PST declaration does not exist";)
}
return decl;
}
}
ifDebug(qCDebug(DUCHAIN) << "returning 0";)
return DeclarationPointer();
}
DeclarationPointer findDeclarationInPST(DUContext* currentContext, QualifiedIdentifier id, DeclarationType declarationType)
{
ifDebug(qCDebug(DUCHAIN) << "PST: " << id.toString() << declarationType;)
uint nr;
const IndexedDeclaration *declarations = nullptr;
DUChainWriteLocker wlock;
PersistentSymbolTable::self().declarations(id, nr, declarations);
ifDebug(qCDebug(DUCHAIN) << "found declarations:" << nr;)
/// Indexed string for 'Php', identifies environment files from this language plugin
static const IndexedString phpLangString("Php");
for (uint i = 0; i < nr; ++i) {
ParsingEnvironmentFilePointer env = DUChain::self()->environmentFileForDocument(declarations[i].indexedTopContext());
if(!env) {
ifDebug(qCDebug(DUCHAIN) << "skipping declaration, missing meta-data";)
continue;
}
if(env->language() != phpLangString) {
ifDebug(qCDebug(DUCHAIN) << "skipping declaration, invalid language" << env->language().str();)
continue;
}
if (!declarations[i].declaration()) {
ifDebug(qCDebug(DUCHAIN) << "skipping declaration, doesn't have declaration";)
continue;
} else if (!isMatch(declarations[i].declaration(), declarationType)) {
ifDebug(qCDebug(DUCHAIN) << "skipping declaration, doesn't match with declarationType";)
continue;
}
TopDUContext* top = declarations[i].declaration()->context()->topContext();
/*
* NOTE:
* To enable PHPUnit test classes, this check has been disabled.
* Formerly it only loaded declarations from open projects, but PHPUnit declarations
* belong to no project.
*
* If this behavior is unwanted, reinstate the check.
* Miha Cancula <miha@noughmad.eu>
*/
/*
if (ICore::self() && !ICore::self()->projectController()->projects().isEmpty()) {
bool loadedProjectContainsUrl = false;
for(IProject *project : ICore::self()->projectController()->projects()) {
if (project->fileSet().contains(top->url())) {
loadedProjectContainsUrl = true;
break;
}
}
if (!loadedProjectContainsUrl) {
ifDebug(qCDebug(DUCHAIN) << "skipping declaration, not in loaded project";)
continue;
}
}
*/
currentContext->topContext()->addImportedParentContext(top);
currentContext->topContext()->parsingEnvironmentFile()
->addModificationRevisions(top->parsingEnvironmentFile()->allModificationRevisions());
currentContext->topContext()->updateImportsCache();
ifDebug(qCDebug(DUCHAIN) << "using" << declarations[i].declaration()->toString() << top->url();)
wlock.unlock();
return DeclarationPointer(declarations[i].declaration());
}
wlock.unlock();
ifDebug(qCDebug(DUCHAIN) << "returning 0";)
return DeclarationPointer();
}
QByteArray formatComment(AstNode* node, EditorIntegrator* editor)
{
return KDevelop::formatComment(editor->parseSession()->docComment(node->startToken).toUtf8());
}
//Helper visitor to extract a commonScalar node
//used to get the value of an function call argument
class ScalarExpressionVisitor : public DefaultVisitor
{
public:
ScalarExpressionVisitor() : m_node(0) {}
CommonScalarAst* node() const {
return m_node;
}
private:
virtual void visitCommonScalar(CommonScalarAst* node) {
m_node = node;
}
CommonScalarAst* m_node;
};
CommonScalarAst* findCommonScalar(AstNode* node)
{
ScalarExpressionVisitor visitor;
visitor.visitNode(node);
return visitor.node();
}
static bool includeExists(const Path &include)
{
const QString path = include.pathOrUrl();
{
DUChainReadLocker lock;
if (DUChain::self()->chainForDocument(IndexedString(path))) {
return true;
}
}
if ( include.isLocalFile() ) {
return QFile::exists(path);
} else {
return false;
}
}
static IndexedString findIncludeFile(const QString &includePath, const IndexedString ¤tDocument)
{
if ( includePath.isEmpty() ) {
return IndexedString();
}
// check remote files
if ( includePath.startsWith(QLatin1String("http://"), Qt::CaseInsensitive)
|| includePath.startsWith(QLatin1String("ftp://"), Qt::CaseInsensitive) ) {
// always expect remote includes to exist
return IndexedString(includePath);
}
const Path currentPath(currentDocument.str());
// look for file relative to current url
Path include = Path(currentPath.parent(), includePath);
if ( includeExists(include) ) {
return IndexedString(include.pathOrUrl());
}
// in the first round look for a project that is a parent of the current document
// in the next round look for any project
for (int i = 0; i < 2; ++i) {
for(IProject* project : ICore::self()->projectController()->projects()) {
if ( !i && !project->path().isParentOf(currentPath)) {
continue;
}
include = Path(project->path(), includePath);
if ( includeExists(include) ) {
return IndexedString(include.pathOrUrl());
}
}
}
//TODO configurable include paths
return IndexedString();
}
IndexedString getIncludeFileForNode(UnaryExpressionAst* node, EditorIntegrator* editor) {
if ( node->includeExpression ) {
//find name of the constant (first argument of the function call)
CommonScalarAst* scalar = findCommonScalar(node->includeExpression);
if (scalar && scalar->string != -1) {
QString str = editor->parseSession()->symbol(scalar->string);
str = str.mid(1, str.length() - 2);
if ( str == QLatin1String(".") || str == QLatin1String("..") || str.endsWith('/') ) {
return IndexedString();
}
return findIncludeFile(str, editor->parseSession()->currentDocument());
}
}
return IndexedString();
}
QString prettyName(Declaration* dec) {
if (!dec) {
return {};
} else if ( dec->context() && dec->context()->type() == DUContext::Class && dec->isFunctionDeclaration() ) {
ClassMethodDeclaration* classMember = dynamic_cast<ClassMethodDeclaration*>(dec);
Q_ASSERT(classMember);
return classMember->prettyName().str();
} else if ( dec->isFunctionDeclaration() ) {
FunctionDeclaration* func = dynamic_cast<FunctionDeclaration*>(dec);
Q_ASSERT(func);
return func->prettyName().str();
} else if ( dec->internalContext() && dec->internalContext()->type() == DUContext::Class ) {
ClassDeclaration* classDec = dynamic_cast<ClassDeclaration*>(dec);
Q_ASSERT(classDec);
return classDec->prettyName().str();
} else {
return dec->identifier().toString();
}
}
const KDevelop::IndexedString& internalFunctionFile()
{
static const KDevelop::IndexedString internalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kdevphpsupport/phpfunctions.php")));
return internalFile;
}
const KDevelop::IndexedString& phpLanguageString()
{
static const KDevelop::IndexedString phpLangString("Php");
return phpLangString;
}
const IndexedString& internalTestFile()
{
static const KDevelop::IndexedString phpUnitFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kdevphpsupport/phpunitdeclarations.php")));
return phpUnitFile;
}
QualifiedIdentifier identifierForNamespace(NamespacedIdentifierAst* node, EditorIntegrator* editor, bool lastIsConstIdentifier)
{
QualifiedIdentifier id;
if (node->isGlobal != -1) {
id.setExplicitlyGlobal(true);
}
const KDevPG::ListNode< IdentifierAst* >* it = node->namespaceNameSequence->front();
do {
if (lastIsConstIdentifier && !it->hasNext()) {
id.push(Identifier(editor->parseSession()->symbol(it->element)));
} else {
id.push(Identifier(editor->parseSession()->symbol(it->element).toLower()));
}
} while (it->hasNext() && (it = it->next));
return id;
}
QualifiedIdentifier identifierWithNamespace(const QualifiedIdentifier& base, DUContext* context)
{
DUChainReadLocker lock;
auto scope = context;
while (scope && scope->type() != DUContext::Namespace) {
scope = scope->parentContext();
}
if (scope) {
return scope->scopeIdentifier() + base;
} else {
return base;
}
}
}
| 15,546
|
C++
|
.cpp
| 363
| 35.192837
| 172
| 0.658674
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
749,174
|
duchaindebug.cpp
|
KDE_umbrello/lib/kdev5-php/duchain/duchaindebug.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2014 Milian Wolff <mail@milianw.de>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include "duchaindebug.h"
Q_LOGGING_CATEGORY(DUCHAIN, "kdevelop.languages.php.duchain")
| 235
|
C++
|
.cpp
| 6
| 36.166667
| 63
| 0.773333
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
749,191
|
declarationnavigationcontext.cpp
|
KDE_umbrello/lib/kdev5-php/duchain/navigation/declarationnavigationcontext.cpp
|
/*
SPDX-FileCopyrightText: 2007 David Nolden <david.nolden.kdevelop@art-master.de>
SPDX-FileCopyrightText: 2008 Niko Sams <niko.sams@gmail.com>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include "declarationnavigationcontext.h"
#include <QTextDocument>
#include <klocalizedstring.h>
#include <language/duchain/functiondefinition.h>
#include <language/duchain/namespacealiasdeclaration.h>
#include <language/duchain/forwarddeclaration.h>
#include <language/duchain/duchainutils.h>
#include <language/duchain/types/structuretype.h>
#include "../declarations/classdeclaration.h"
#include <declarations/classmethoddeclaration.h>
#include <declarations/traitmethodaliasdeclaration.h>
#include <declarations/traitmemberaliasdeclaration.h>
#include "helper.h"
namespace Php
{
using namespace KDevelop;
DeclarationNavigationContext::DeclarationNavigationContext(DeclarationPointer decl, KDevelop::TopDUContextPointer topContext, AbstractNavigationContext* previousContext)
: AbstractDeclarationNavigationContext(decl, topContext, previousContext)
{
}
NavigationContextPointer DeclarationNavigationContext::registerChild(DeclarationPointer declaration)
{
return AbstractDeclarationNavigationContext::registerChild(new DeclarationNavigationContext(declaration, m_topContext, this));
}
void DeclarationNavigationContext::htmlClass()
{
StructureType::Ptr klass = m_declaration->abstractType().cast<StructureType>();
Q_ASSERT(klass);
ClassDeclaration* classDecl = dynamic_cast<ClassDeclaration*>(klass->declaration(m_topContext.data()));
if (classDecl) {
// write class modifier
switch (classDecl->classModifier()) {
case ClassDeclarationData::Abstract:
modifyHtml() += QStringLiteral("abstract ");
break;
case ClassDeclarationData::Final:
modifyHtml() += QStringLiteral("final ");
break;
default:
//nothing
break;
}
// write class type
if (classDecl->classType() == ClassDeclarationData::Interface) {
modifyHtml() += QStringLiteral("interface ");
} else if (classDecl->classType() == ClassDeclarationData::Trait) {
modifyHtml() += QStringLiteral("trait ");
} else {
modifyHtml() += QStringLiteral("class ");
}
// write class identifier
eventuallyMakeTypeLinks(m_declaration->abstractType());
// write inheritance
if (classDecl->baseClassesSize() > 0) {
AbstractType::Ptr extends;
QList<AbstractType::Ptr> implements;
FOREACH_FUNCTION(const BaseClassInstance& base, classDecl->baseClasses) {
StructureType::Ptr stype = base.baseClass.type<StructureType>();
if (stype) {
ClassDeclaration *classDecl = dynamic_cast<ClassDeclaration*>(stype->declaration(m_topContext.data()));
if (classDecl) {
if (classDecl->classType() == ClassDeclarationData::Interface) {
implements.append(base.baseClass.abstractType());
} else {
extends = base.baseClass.abstractType();
}
}
}
}
// write parent class
if (extends) {
modifyHtml() += QStringLiteral(" extends ");
eventuallyMakeTypeLinks(extends);
}
// write implemented interfaces
if (!implements.isEmpty()) {
modifyHtml() += QStringLiteral(" implements ");
for (QList<AbstractType::Ptr>::iterator i = implements.begin(); ;) {
eventuallyMakeTypeLinks(*i);
++i;
if (i != implements.end()) {
modifyHtml() += QStringLiteral(", ");
} else {
break;
}
}
}
}
modifyHtml() += QStringLiteral(" ");
}
}
void DeclarationNavigationContext::htmlAdditionalNavigation()
{
if (auto member = dynamic_cast<TraitMethodAliasDeclaration*>(m_declaration.data())) {
Declaration *dec = member->aliasedDeclaration().data();
if (dec && dec->context() && dec->context()->owner()) {
modifyHtml() += i18n("Use of %1 from %2<br />")
.arg(createLink(prettyQualifiedIdentifier(DeclarationPointer(dec)).toString(),
QStringLiteral("jump_to_used"),
NavigationAction(DeclarationPointer(dec),
KDevelop::NavigationAction::NavigateDeclaration)))
.arg(createLink(prettyQualifiedIdentifier(DeclarationPointer(dec->context()->owner())).toString(),
QStringLiteral("jump_to_used_container"),
NavigationAction(DeclarationPointer(dec->context()->owner()),
KDevelop::NavigationAction::NavigateDeclaration)));
}
} else if (auto member = dynamic_cast<TraitMemberAliasDeclaration*>(m_declaration.data())) {
Declaration *dec = member->aliasedDeclaration().data();
if (dec && dec->context() && dec->context()->owner()) {
modifyHtml() += i18n("Use of %1 from %2<br />")
.arg(createLink(prettyQualifiedIdentifier(DeclarationPointer(dec)).toString(),
QStringLiteral("jump_to_used"),
NavigationAction(DeclarationPointer(dec),
KDevelop::NavigationAction::NavigateDeclaration)))
.arg(createLink(prettyQualifiedIdentifier(DeclarationPointer(dec->context()->owner())).toString(),
QStringLiteral("jump_to_used_container"),
NavigationAction(DeclarationPointer(dec->context()->owner()),
KDevelop::NavigationAction::NavigateDeclaration)));
} else {
modifyHtml() += i18n("Broken member alias trait.");
}
}
KDevelop::AbstractDeclarationNavigationContext::htmlAdditionalNavigation();
}
QualifiedIdentifier DeclarationNavigationContext::prettyQualifiedIdentifier( DeclarationPointer decl ) const
{
return QualifiedIdentifier(prettyName(decl.data()));
}
void DeclarationNavigationContext::makeLink(const QString& name, DeclarationPointer declaration, NavigationAction::Type actionType)
{
if ( actionType == NavigationAction::JumpToSource && declaration->url() == internalFunctionFile() ) {
modifyHtml() += i18n("PHP internal");
return;
}
AbstractDeclarationNavigationContext::makeLink(name, declaration, actionType);
}
QString DeclarationNavigationContext::declarationKind(DeclarationPointer decl)
{
if ( decl->kind() == Declaration::Instance && decl->abstractType()
&& decl->abstractType()->modifiers() & AbstractType::ConstModifier ) {
return i18nc("kind of a php-constant, as shown in the declaration tooltip", "Constant");
}
return AbstractDeclarationNavigationContext::declarationKind(decl);
}
}
| 7,517
|
C++
|
.cpp
| 150
| 37.346667
| 169
| 0.608897
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,192
|
includenavigationcontext.cpp
|
KDE_umbrello/lib/kdev5-php/duchain/navigation/includenavigationcontext.cpp
|
/*
SPDX-FileCopyrightText: 2009 Milian Wolff <mail@milianw.de>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include "includenavigationcontext.h"
#include <language/duchain/parsingenvironment.h>
namespace Php {
IncludeNavigationContext::IncludeNavigationContext(const KDevelop::IncludeItem& item, KDevelop::TopDUContextPointer topContext)
: AbstractIncludeNavigationContext(item, topContext, KDevelop::PhpParsingEnvironment)
{
}
}
| 446
|
C++
|
.cpp
| 12
| 34.666667
| 127
| 0.824766
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
749,201
|
testcore.cpp
|
KDE_umbrello/lib/kdevplatform/tests/testcore.cpp
|
/*
SPDX-FileCopyrightText: 2008 Andreas Pakulat <apaku@gmx.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "testcore.h"
#include <shell/uicontroller.h>
#include <shell/sessioncontroller.h>
#include <shell/languagecontroller.h>
#include <shell/runcontroller.h>
#include <shell/documentcontroller.h>
#include <shell/plugincontroller.h>
#include <shell/partcontroller.h>
#include <shell/projectcontroller.h>
#include <language/backgroundparser/backgroundparser.h>
#include <interfaces/isession.h>
#include "../shell/core_p.h"
#include <QCoreApplication>
#include <QThread>
namespace QTest {
void qWait(int i) { QThread::msleep(i); }
}
#include <KParts/MainWindow>
namespace KDevelop {
TestCore::TestCore()
: Core(new CorePrivate(this))
{
Core::m_self = this;
}
TestCore* TestCore::initialize(Core::Setup mode, const QString& session)
{
qRegisterMetaType<QList<QUrl>>("QList<QUrl>");
if (!Core::m_self) {
new TestCore;
}
auto* core = qobject_cast<TestCore*>(Core::m_self);
Q_ASSERT(core);
core->initializeNonStatic(mode, session);
if (mode == Default) {
// we don't want the window to be visible, hide it
// the unit tests should work anyways
core->uiController()->activeMainWindow()->hide();
}
// resume the background parser when a unit test replaces the project controller
QObject::connect(core->d->projectController.data(), &ProjectController::destroyed,
core, [core]() {
core->d->languageController->backgroundParser()->resume();
});
return core;
}
void TestCore::initializeNonStatic(Core::Setup mode, const QString& _session)
{
QString session = _session;
if (_session.isEmpty()) {
// use a distinct session name for unit test sessions
// they are temporary (see below) but still - we want to make sure
session = QLatin1String("test-") + qApp->applicationName();
}
d->initialize(mode, session);
if (_session.isEmpty()) {
activeSession()->setTemporary(true);
}
}
void TestCore::shutdown()
{
if (self()) {
// trigger eventloop to handle Queued connections
// before entering cleanup
// this can fix random crashes under certain conditions
QTest::qWait(1);
self()->shutdown();
// wait until Core is deleted via event loop
QTest::qWait(1);
}
}
void TestCore::setShuttingDown(bool shuttingDown)
{
d->m_shuttingDown = shuttingDown;
}
void TestCore::setSessionController(SessionController* ctrl)
{
d->sessionController = ctrl;
}
void TestCore::setPluginController(PluginController* ctrl)
{
d->pluginController = ctrl;
}
void TestCore::setRunController(RunController* ctrl)
{
d->runController = ctrl;
}
void TestCore::setDocumentController(DocumentController* ctrl)
{
d->documentController = ctrl;
}
void TestCore::setPartController(PartController* ctrl)
{
d->partController = ctrl;
}
void TestCore::setProjectController(ProjectController* ctrl)
{
d->projectController = ctrl;
}
void TestCore::setLanguageController(LanguageController* ctrl)
{
d->languageController = ctrl;
}
void TestCore::setUiController(UiController* ctrl)
{
d->uiController = ctrl;
}
}
| 3,282
|
C++
|
.cpp
| 111
| 25.684685
| 86
| 0.709606
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
749,202
|
autotestshell.cpp
|
KDE_umbrello/lib/kdevplatform/tests/autotestshell.cpp
|
/*
SPDX-FileCopyrightText: 2013 Kevin Funk <kfunk@kde.org
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "autotestshell.h"
KDevelop::AutoTestShell::AutoTestShell(const QStringList& plugins)
: m_plugins(plugins)
{
}
void KDevelop::AutoTestShell::init(const QStringList& plugins)
{
// TODO: Maybe generalize, add KDEVELOP_STANDALONE build option
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
qputenv("KDE_FORK_SLAVES", "1"); // KIO slaves will be forked off instead of being started via DBus
#endif
qputenv("CLEAR_DUCHAIN_DIR", "1"); // Always clear duchain dir (also to avoid popups asking the user to clear it)
s_instance = new AutoTestShell(plugins);
}
| 692
|
C++
|
.cpp
| 18
| 35.611111
| 117
| 0.741405
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
749,203
|
ast.cpp
|
KDE_umbrello/lib/cppparser/ast.cpp
|
/*
This file is part of KDevelop
SPDX-FileCopyrightText: 2002, 2003 Roberto Raggi <roberto@kdevelop.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "ast.h"
#include <QStringList>
QString nodeTypeToString(int type)
{
switch (type) {
case NodeType_Generic:
return QLatin1String("Generic");
case NodeType_TemplateArgumentList:
return QLatin1String("TemplateArgumentList");
case NodeType_ClassOrNamespaceName:
return QLatin1String("ClassOrNamespaceName");
case NodeType_Name:
return QLatin1String("Name");
case NodeType_Declaration:
return QLatin1String("Declaration");
case NodeType_TypeSpecifier:
return QLatin1String("TypeSpecifier");
case NodeType_BaseSpecifier:
return QLatin1String("BaseSpecifier");
case NodeType_BaseClause:
return QLatin1String("BaseClause");
case NodeType_ClassSpecifier:
return QLatin1String("ClassSpecifier");
case NodeType_Enumerator:
return QLatin1String("Enumerator");
case NodeType_EnumSpecifier:
return QLatin1String("EnumSpecifier");
case NodeType_ElaboratedTypeSpecifier:
return QLatin1String("ElaboratedTypeSpecifier");
case NodeType_LinkageBody:
return QLatin1String("LinkageBody");
case NodeType_LinkageSpecification:
return QLatin1String("LinkageSpecification");
case NodeType_Namespace:
return QLatin1String("Namespace");
case NodeType_NamespaceAlias:
return QLatin1String("NamespaceAlias");
case NodeType_Using:
return QLatin1String("Using");
case NodeType_UsingDirective:
return QLatin1String("UsingDirective");
case NodeType_InitDeclaratorList:
return QLatin1String("InitDeclaratorList");
case NodeType_Typedef:
return QLatin1String("Typedef");
case NodeType_Declarator:
return QLatin1String("Declarator");
case NodeType_InitDeclarator:
return QLatin1String("InitDeclarator");
case NodeType_TemplateDeclaration:
return QLatin1String("TemplateDeclaration");
case NodeType_SimpleDeclaration:
return QLatin1String("SimpleDeclaration");
case NodeType_Statement:
return QLatin1String("Statement");
case NodeType_IfStatement:
return QLatin1String("IfStatement");
case NodeType_WhileStatement:
return QLatin1String("WhileStatement");
case NodeType_DoStatement:
return QLatin1String("DoStatement");
case NodeType_ForStatement:
return QLatin1String("ForStatement");
case NodeType_ForEachStatement: // qt4 [erbsland]
return QLatin1String("ForEachStatement");
case NodeType_SwitchStatement:
return QLatin1String("SwitchStatement");
case NodeType_CatchStatement:
return QLatin1String("CatchStatement");
case NodeType_CatchStatementList:
return QLatin1String("CatchStatementList");
case NodeType_TryBlockStatement:
return QLatin1String("TryBlockStatement");
case NodeType_DeclarationStatement:
return QLatin1String("DeclarationStatement");
case NodeType_StatementList:
return QLatin1String("StatementList");
case NodeType_TranslationUnit:
return QLatin1String("TranslationUnit");
case NodeType_FunctionDefinition:
return QLatin1String("FunctionDefinition");
case NodeType_ExpressionStatement:
return QLatin1String("ExpressionStatement");
case NodeType_ParameterDeclaration:
return QLatin1String("ParameterDeclaration");
case NodeType_ParameterDeclarationList:
return QLatin1String("ParameterDeclarationList");
case NodeType_ParameterDeclarationClause:
return QLatin1String("ParameterDeclarationClause");
case NodeType_Group:
return QLatin1String("Group");
case NodeType_AccessDeclaration:
return QLatin1String("AccessDeclaration");
case NodeType_TypeParameter:
return QLatin1String("TypeParameter");
case NodeType_TemplateParameter:
return QLatin1String("TemplateParameter");
case NodeType_TemplateParameterList:
return QLatin1String("TemplateParameterList");
case NodeType_Condition:
return QLatin1String("Condition");
case NodeType_Custom:
return QLatin1String("Custom");
}
return QString();
}
// ------------------------------------------------------------------------
AST::AST()
: m_nodeType(NodeType_Generic), m_parent(nullptr),
m_startLine(0), m_startColumn(0),
m_endLine(0), m_endColumn(0)
{
}
AST::~AST()
{
#ifndef CPPPARSER_NO_CHILDREN
if (m_parent)
m_parent->removeChild(this);
#endif
}
void AST::setStartPosition(int line, int col)
{
m_startLine = line;
m_startColumn = col;
}
void AST::getStartPosition(int* line, int* col) const
{
if (line)
*line = m_startLine;
if (col)
* col = m_startColumn;
}
void AST::setEndPosition(int line, int col)
{
m_endLine = line;
m_endColumn = col;
}
void AST::getEndPosition(int* line, int* col) const
{
if (line)
*line = m_endLine;
if (col)
* col = m_endColumn;
}
void AST::setParent(AST* parent)
{
#ifndef CPPPARSER_NO_CHILDREN
if (m_parent)
m_parent->removeChild(this);
#endif
m_parent = parent;
#ifndef CPPPARSER_NO_CHILDREN
if (m_parent)
m_parent->appendChild(this);
#endif
}
#ifndef CPPPARSER_NO_CHILDREN
void AST::appendChild(AST* child)
{
m_children.append(child);
}
void AST::removeChild(AST* child)
{
m_children.removeOne(child);
}
#endif
// ------------------------------------------------------------------------
NameAST::NameAST()
: m_global(false)
{
}
void NameAST::setGlobal(bool b)
{
m_global = b;
}
void NameAST::setUnqualifiedName(ClassOrNamespaceNameAST::Node& unqualifiedName)
{
m_unqualifiedName = std::move(unqualifiedName);
if (m_unqualifiedName.get()) m_unqualifiedName->setParent(this);
}
void NameAST::addClassOrNamespaceName(ClassOrNamespaceNameAST::Node& classOrNamespaceName)
{
if (!classOrNamespaceName.get())
return;
classOrNamespaceName->setParent(this);
m_classOrNamespaceNameList.append(classOrNamespaceName.release());
}
QString NameAST::text() const
{
if (!m_unqualifiedName.get())
return QString();
QString str;
if (m_global)
str += QLatin1String("::");
for (int i = 0; i < m_classOrNamespaceNameList.size(); ++i) {
str += m_classOrNamespaceNameList.at(i)->text() + QLatin1String("::");
}
if (m_unqualifiedName.get())
str += m_unqualifiedName->text();
return str;
}
// ------------------------------------------------------------------------
DeclarationAST::DeclarationAST()
{
}
// ------------------------------------------------------------------------
LinkageBodyAST::LinkageBodyAST()
{
}
void LinkageBodyAST::addDeclaration(DeclarationAST::Node& ast)
{
if (!ast.get())
return;
ast->setParent(this);
m_declarationList.append(ast.release());
}
// ------------------------------------------------------------------------
LinkageSpecificationAST::LinkageSpecificationAST()
{
}
void LinkageSpecificationAST::setExternType(AST::Node& externType)
{
m_externType = std::move(externType);
if (m_externType.get()) m_externType->setParent(this);
}
void LinkageSpecificationAST::setLinkageBody(LinkageBodyAST::Node& linkageBody)
{
m_linkageBody = std::move(linkageBody);
if (m_linkageBody.get()) m_linkageBody->setParent(this);
}
void LinkageSpecificationAST::setDeclaration(DeclarationAST::Node& decl)
{
m_declaration = std::move(decl);
if (m_declaration.get()) m_declaration->setParent(this);
}
// ------------------------------------------------------------------------
TranslationUnitAST::TranslationUnitAST()
{
}
void TranslationUnitAST::addDeclaration(DeclarationAST::Node& ast)
{
if (!ast.get())
return;
ast->setParent(this);
m_declarationList.append(ast.release());
}
// ------------------------------------------------------------------------
NamespaceAST::NamespaceAST()
{
}
void NamespaceAST::setNamespaceName(AST::Node& namespaceName)
{
m_namespaceName = std::move(namespaceName);
if (m_namespaceName.get()) m_namespaceName->setParent(this);
}
void NamespaceAST::setLinkageBody(LinkageBodyAST::Node& linkageBody)
{
m_linkageBody = std::move(linkageBody);
if (m_linkageBody.get()) m_linkageBody->setParent(this);
}
// ------------------------------------------------------------------------
NamespaceAliasAST::NamespaceAliasAST()
{
}
void NamespaceAliasAST::setNamespaceName(AST::Node& namespaceName)
{
m_namespaceName = std::move(namespaceName);
if (m_namespaceName.get()) m_namespaceName->setParent(this);
}
void NamespaceAliasAST::setAliasName(NameAST::Node& name)
{
m_aliasName = std::move(name);
if (m_aliasName.get()) m_aliasName->setParent(this);
}
// ------------------------------------------------------------------------
UsingAST::UsingAST()
{
}
void UsingAST::setTypeName(AST::Node& typeName)
{
m_typeName = std::move(typeName);
if (m_typeName.get()) m_typeName->setParent(this);
}
void UsingAST::setName(NameAST::Node& name)
{
m_name = std::move(name);
if (m_name.get()) m_name->setParent(this);
}
// ------------------------------------------------------------------------
UsingDirectiveAST::UsingDirectiveAST()
{
}
void UsingDirectiveAST::setName(NameAST::Node& name)
{
m_name = std::move(name);
if (m_name.get()) m_name->setParent(this);
}
TypedefAST::TypedefAST()
{
}
void TypeSpecifierAST::setName(NameAST::Node& name)
{
m_name = std::move(name);
if (m_name.get()) m_name->setParent(this);
}
void TypedefAST::setTypeSpec(TypeSpecifierAST::Node& typeSpec)
{
m_typeSpec = std::move(typeSpec);
if (m_typeSpec.get()) m_typeSpec->setParent(this);
}
void TypedefAST::setInitDeclaratorList(InitDeclaratorListAST::Node& initDeclaratorList)
{
m_initDeclaratorList = std::move(initDeclaratorList);
if (m_initDeclaratorList.get()) m_initDeclaratorList->setParent(this);
}
// ------------------------------------------------------------------------
TemplateArgumentListAST::TemplateArgumentListAST()
{
}
void TemplateArgumentListAST::addArgument(AST::Node& arg)
{
if (!arg.get())
return;
arg->setParent(this);
m_argumentList.append(arg.release());
}
QString TemplateArgumentListAST::text() const
{
QStringList l;
for (int i = 0; i < m_argumentList.size(); ++i) {
l.append(m_argumentList.at(i)->text());
}
return l.join(QLatin1String(", "));
}
// ------------------------------------------------------------------------
TemplateDeclarationAST::TemplateDeclarationAST()
{
}
void TemplateDeclarationAST::setExported(AST::Node& exported)
{
m_exported = std::move(exported);
if (m_exported.get()) m_exported->setParent(this);
}
void TemplateDeclarationAST::setTemplateParameterList(TemplateParameterListAST::Node& templateParameterList)
{
m_templateParameterList = std::move(templateParameterList);
if (m_templateParameterList.get()) m_templateParameterList->setParent(this);
}
void TemplateDeclarationAST::setDeclaration(DeclarationAST::Node& declaration)
{
m_declaration = std::move(declaration);
if (m_declaration.get()) m_declaration->setParent(this);
}
// ------------------------------------------------------------------------
ClassOrNamespaceNameAST::ClassOrNamespaceNameAST()
{
}
void ClassOrNamespaceNameAST::setName(AST::Node& name)
{
m_name = std::move(name);
if (m_name.get()) m_name->setParent(this);
}
void ClassOrNamespaceNameAST::setTemplateArgumentList(TemplateArgumentListAST::Node& templateArgumentList)
{
m_templateArgumentList = std::move(templateArgumentList);
if (m_templateArgumentList.get()) m_templateArgumentList->setParent(this);
}
QString ClassOrNamespaceNameAST::text() const
{
if (!m_name.get())
return QString();
QString str = m_name->text();
if (m_templateArgumentList.get())
str += QString::fromLatin1("< ") + m_templateArgumentList->text() + QString::fromLatin1(" >");
return str;
}
// ------------------------------------------------------------------------
TypeSpecifierAST::TypeSpecifierAST()
{
}
void TypeSpecifierAST::setCvQualify(GroupAST::Node& cvQualify)
{
m_cvQualify = std::move(cvQualify);
if (m_cvQualify.get()) m_cvQualify->setParent(this);
}
void TypeSpecifierAST::setCv2Qualify(GroupAST::Node& cv2Qualify)
{
m_cv2Qualify = std::move(cv2Qualify);
if (m_cv2Qualify.get()) m_cv2Qualify->setParent(this);
}
QString TypeSpecifierAST::text() const
{
QString str;
if (m_cvQualify.get())
str += m_cvQualify->text() + QLatin1Char(' ');
if (m_name.get())
str += m_name->text();
if (m_cv2Qualify.get())
str += QString::fromLatin1(" ") + m_cv2Qualify->text();
return str;
}
// ------------------------------------------------------------------------
ClassSpecifierAST::ClassSpecifierAST()
{
}
void ClassSpecifierAST::setClassKey(AST::Node& classKey)
{
m_classKey = std::move(classKey);
if (m_classKey.get()) m_classKey->setParent(this);
}
void ClassSpecifierAST::addDeclaration(DeclarationAST::Node& declaration)
{
if (!declaration.get())
return;
declaration->setParent(this);
m_declarationList.append(declaration.release());
}
void ClassSpecifierAST::setBaseClause(BaseClauseAST::Node& baseClause)
{
m_baseClause = std::move(baseClause);
if (m_baseClause.get()) m_baseClause->setParent(this);
}
// ------------------------------------------------------------------------
EnumSpecifierAST::EnumSpecifierAST()
{
m_isClass = false;
}
void EnumSpecifierAST::setClass(bool b)
{
m_isClass = b;
}
void EnumSpecifierAST::setEnumBase(TypeSpecifierAST::Node& enumBase)
{
m_enumBase = std::move(enumBase);
if (m_enumBase.get()) m_enumBase->setParent(this);
}
void EnumSpecifierAST::addEnumerator(EnumeratorAST::Node& enumerator)
{
if (!enumerator.get())
return;
enumerator->setParent(this);
m_enumeratorList.append(enumerator.release());
}
// ------------------------------------------------------------------------
ElaboratedTypeSpecifierAST::ElaboratedTypeSpecifierAST()
{
}
void ElaboratedTypeSpecifierAST::setKind(AST::Node& kind)
{
m_kind = std::move(kind);
if (m_kind.get()) m_kind->setParent(this);
}
QString ElaboratedTypeSpecifierAST::text() const
{
if (m_kind.get())
return m_kind->text() + QLatin1Char(' ') + TypeSpecifierAST::text();
return TypeSpecifierAST::text();
}
// ------------------------------------------------------------------------
StatementAST::StatementAST()
{
}
// ------------------------------------------------------------------------
EnumeratorAST::EnumeratorAST()
{
}
void EnumeratorAST::setId(AST::Node& id)
{
m_id = std::move(id);
if (m_id.get()) m_id->setParent(this);
}
void EnumeratorAST::setExpr(AST::Node& expr)
{
m_expr = std::move(expr);
if (m_expr.get()) m_expr->setParent(this);
}
// ------------------------------------------------------------------------
BaseClauseAST::BaseClauseAST()
{
}
void BaseClauseAST::addBaseSpecifier(BaseSpecifierAST::Node& baseSpecifier)
{
if (!baseSpecifier.get())
return;
baseSpecifier->setParent(this);
m_baseSpecifierList.append(baseSpecifier.release());
}
// ------------------------------------------------------------------------
BaseSpecifierAST::BaseSpecifierAST()
{
}
void BaseSpecifierAST::setIsVirtual(AST::Node& isVirtual)
{
m_isVirtual = std::move(isVirtual);
if (m_isVirtual.get()) m_isVirtual->setParent(this);
}
void BaseSpecifierAST::setAccess(AST::Node& access)
{
m_access = std::move(access);
if (m_access.get()) m_access->setParent(this);
}
void BaseSpecifierAST::setName(NameAST::Node& name)
{
m_name = std::move(name);
if (m_name.get()) m_name->setParent(this);
}
// ------------------------------------------------------------------------
SimpleDeclarationAST::SimpleDeclarationAST()
{
}
void SimpleDeclarationAST::setFunctionSpecifier(GroupAST::Node& functionSpecifier)
{
m_functionSpecifier = std::move(functionSpecifier);
if (m_functionSpecifier.get()) m_functionSpecifier->setParent(this);
}
void SimpleDeclarationAST::setStorageSpecifier(GroupAST::Node& storageSpecifier)
{
m_storageSpecifier = std::move(storageSpecifier);
if (m_storageSpecifier.get()) m_storageSpecifier->setParent(this);
}
void SimpleDeclarationAST::setTypeSpec(TypeSpecifierAST::Node& typeSpec)
{
m_typeSpec = std::move(typeSpec);
if (m_typeSpec.get()) m_typeSpec->setParent(this);
}
void SimpleDeclarationAST::setInitDeclaratorList(InitDeclaratorListAST::Node& initDeclaratorList)
{
m_initDeclaratorList = std::move(initDeclaratorList);
if (m_initDeclaratorList.get()) m_initDeclaratorList->setParent(this);
}
void SimpleDeclarationAST::setWinDeclSpec(GroupAST::Node& winDeclSpec)
{
m_winDeclSpec = std::move(winDeclSpec);
if (m_winDeclSpec.get()) m_winDeclSpec->setParent(this);
}
// ------------------------------------------------------------------------
InitDeclaratorListAST::InitDeclaratorListAST()
{
}
void InitDeclaratorListAST::addInitDeclarator(InitDeclaratorAST::Node& decl)
{
if (!decl.get())
return;
decl->setParent(this);
m_initDeclaratorList.append(decl.release());
}
// ------------------------------------------------------------------------
DeclaratorAST::DeclaratorAST()
{
}
void DeclaratorAST::setSubDeclarator(DeclaratorAST::Node& subDeclarator)
{
m_subDeclarator = std::move(subDeclarator);
if (m_subDeclarator.get()) m_subDeclarator->setParent(this);
}
void DeclaratorAST::setDeclaratorId(NameAST::Node& declaratorId)
{
m_declaratorId = std::move(declaratorId);
if (m_declaratorId.get()) m_declaratorId->setParent(this);
}
void DeclaratorAST::setBitfieldInitialization(AST::Node& bitfieldInitialization)
{
m_bitfieldInitialization = std::move(bitfieldInitialization);
if (m_bitfieldInitialization.get()) m_bitfieldInitialization->setParent(this);
}
void DeclaratorAST::addArrayDimension(AST::Node& arrayDimension)
{
if (!arrayDimension.get())
return;
arrayDimension->setParent(this);
m_arrayDimensionList.append(arrayDimension.release());
}
void DeclaratorAST::setParameterDeclarationClause(AUTO_PTR<class ParameterDeclarationClauseAST>& parameterDeclarationClause)
{
m_parameterDeclarationClause = std::move(parameterDeclarationClause);
if (m_parameterDeclarationClause.get()) m_parameterDeclarationClause->setParent(this);
}
void DeclaratorAST::setConstant(AST::Node& constant)
{
m_constant = std::move(constant);
if (m_constant.get()) m_constant->setParent(this);
}
void DeclaratorAST::setOverride(AST::Node& override_)
{
m_override = std::move(override_);
if (m_override.get()) m_override->setParent(this);
}
void DeclaratorAST::setFinal(AST::Node& final_)
{
m_final = std::move(final_);
if (m_final.get()) m_final->setParent(this);
}
void DeclaratorAST::setExceptionSpecification(GroupAST::Node& exceptionSpecification)
{
m_exceptionSpecification = std::move(exceptionSpecification);
if (m_exceptionSpecification.get()) m_exceptionSpecification->setParent(this);
}
void DeclaratorAST::addPtrOp(AST::Node& ptrOp)
{
if (!ptrOp.get())
return;
ptrOp->setParent(this);
m_ptrOpList.append(ptrOp.release());
}
// --------------------------------------------------------------------------
InitDeclaratorAST::InitDeclaratorAST()
{
}
void InitDeclaratorAST::setDeclarator(DeclaratorAST::Node& declarator)
{
m_declarator = std::move(declarator);
if (m_declarator.get()) m_declarator->setParent(this);
}
void InitDeclaratorAST::setInitializer(AST::Node& initializer)
{
m_initializer = std::move(initializer);
if (m_initializer.get()) m_initializer->setParent(this);
}
// --------------------------------------------------------------------------
FunctionDefinitionAST::FunctionDefinitionAST()
{
}
void FunctionDefinitionAST::setFunctionSpecifier(GroupAST::Node& functionSpecifier)
{
m_functionSpecifier = std::move(functionSpecifier);
if (m_functionSpecifier.get()) m_functionSpecifier->setParent(this);
}
void FunctionDefinitionAST::setStorageSpecifier(GroupAST::Node& storageSpecifier)
{
m_storageSpecifier = std::move(storageSpecifier);
if (m_storageSpecifier.get()) m_storageSpecifier->setParent(this);
}
void FunctionDefinitionAST::setTypeSpec(TypeSpecifierAST::Node& typeSpec)
{
m_typeSpec = std::move(typeSpec);
if (m_typeSpec.get()) m_typeSpec->setParent(this);
}
void FunctionDefinitionAST::setInitDeclarator(InitDeclaratorAST::Node& initDeclarator)
{
m_initDeclarator = std::move(initDeclarator);
if (m_initDeclarator.get()) m_initDeclarator->setParent(this);
}
void FunctionDefinitionAST::setFunctionBody(StatementListAST::Node& functionBody)
{
m_functionBody = std::move(functionBody);
if (m_functionBody.get()) m_functionBody->setParent(this);
}
void FunctionDefinitionAST::setWinDeclSpec(GroupAST::Node& winDeclSpec)
{
m_winDeclSpec = std::move(winDeclSpec);
if (m_winDeclSpec.get()) m_winDeclSpec->setParent(this);
}
// --------------------------------------------------------------------------
StatementListAST::StatementListAST()
{
}
void StatementListAST::addStatement(StatementAST::Node& statement)
{
if (!statement.get())
return;
statement->setParent(this);
m_statementList.append(statement.release());
}
// --------------------------------------------------------------------------
IfStatementAST::IfStatementAST()
{
}
void IfStatementAST::setCondition(ConditionAST::Node& condition)
{
m_condition = std::move(condition);
if (m_condition.get()) m_condition->setParent(this);
}
void IfStatementAST::setStatement(StatementAST::Node& statement)
{
m_statement = std::move(statement);
if (m_statement.get()) m_statement->setParent(this);
}
void IfStatementAST::setElseStatement(StatementAST::Node& elseStatement)
{
m_elseStatement = std::move(elseStatement);
if (m_elseStatement.get()) m_elseStatement->setParent(this);
}
// --------------------------------------------------------------------------
WhileStatementAST::WhileStatementAST()
{
}
void WhileStatementAST::setCondition(ConditionAST::Node& condition)
{
m_condition = std::move(condition);
if (m_condition.get()) m_condition->setParent(this);
}
void WhileStatementAST::setStatement(StatementAST::Node& statement)
{
m_statement = std::move(statement);
if (m_statement.get()) m_statement->setParent(this);
}
// --------------------------------------------------------------------------
DoStatementAST::DoStatementAST()
{
}
void DoStatementAST::setCondition(ConditionAST::Node& condition)
{
m_condition = std::move(condition);
if (m_condition.get()) m_condition->setParent(this);
}
void DoStatementAST::setStatement(StatementAST::Node& statement)
{
m_statement = std::move(statement);
if (m_statement.get()) m_statement->setParent(this);
}
// --------------------------------------------------------------------------
ForStatementAST::ForStatementAST()
{
}
void ForStatementAST::setCondition(ConditionAST::Node& condition)
{
m_condition = std::move(condition);
if (m_condition.get()) m_condition->setParent(this);
}
void ForStatementAST::setExpression(AST::Node& expression)
{
m_expression = std::move(expression);
if (m_expression.get()) m_expression->setParent(this);
}
void ForStatementAST::setStatement(StatementAST::Node& statement)
{
m_statement = std::move(statement);
if (m_statement.get()) m_statement->setParent(this);
}
void ForStatementAST::setInitStatement(StatementAST::Node& initStatement)
{
m_initStatement = std::move(initStatement);
if (m_initStatement.get()) m_initStatement->setParent(this);
}
// --------------------------------------------------------------------------
ForEachStatementAST::ForEachStatementAST()
{
}
void ForEachStatementAST::setExpression(AST::Node& expression)
{
m_expression = std::move(expression);
if (m_expression.get()) m_expression->setParent(this);
}
void ForEachStatementAST::setStatement(StatementAST::Node& statement)
{
m_statement = std::move(statement);
if (m_statement.get()) m_statement->setParent(this);
}
void ForEachStatementAST::setInitStatement(StatementAST::Node& initStatement)
{
m_initStatement = std::move(initStatement);
if (m_initStatement.get()) m_initStatement->setParent(this);
}
// --------------------------------------------------------------------------
SwitchStatementAST::SwitchStatementAST()
{
}
void SwitchStatementAST::setCondition(ConditionAST::Node& condition)
{
m_condition = std::move(condition);
if (m_condition.get()) m_condition->setParent(this);
}
void SwitchStatementAST::setStatement(StatementAST::Node& statement)
{
m_statement = std::move(statement);
if (m_statement.get()) m_statement->setParent(this);
}
// --------------------------------------------------------------------------
CatchStatementListAST::CatchStatementListAST()
{
}
void CatchStatementListAST::addStatement(CatchStatementAST::Node& statement)
{
if (!statement.get())
return;
statement->setParent(this);
m_statementList.append(statement.release());
}
// --------------------------------------------------------------------------
CatchStatementAST::CatchStatementAST()
{
}
void CatchStatementAST::setCondition(ConditionAST::Node& condition)
{
m_condition = std::move(condition);
if (m_condition.get()) m_condition->setParent(this);
}
void CatchStatementAST::setStatement(StatementAST::Node& statement)
{
m_statement = std::move(statement);
if (m_statement.get()) m_statement->setParent(this);
}
// --------------------------------------------------------------------------
TryBlockStatementAST::TryBlockStatementAST()
{
}
void TryBlockStatementAST::setStatement(StatementAST::Node& statement)
{
m_statement = std::move(statement);
if (m_statement.get()) m_statement->setParent(this);
}
void TryBlockStatementAST::setCatchStatementList(CatchStatementListAST::Node& statementList)
{
m_catchStatementList = std::move(statementList);
if (m_catchStatementList.get()) m_catchStatementList->setParent(this);
}
// --------------------------------------------------------------------------
DeclarationStatementAST::DeclarationStatementAST()
{
}
void DeclarationStatementAST::setDeclaration(DeclarationAST::Node& declaration)
{
m_declaration = std::move(declaration);
if (m_declaration.get()) m_declaration->setParent(this);
}
// --------------------------------------------------------------------------
ExpressionStatementAST::ExpressionStatementAST()
{
}
void ExpressionStatementAST::setExpression(AST::Node& expression)
{
m_expression = std::move(expression);
if (m_expression.get()) m_expression->setParent(this);
}
// --------------------------------------------------------------------------
ParameterDeclarationAST::ParameterDeclarationAST()
{
}
void ParameterDeclarationAST::setTypeSpec(TypeSpecifierAST::Node& typeSpec)
{
m_typeSpec = std::move(typeSpec);
if (m_typeSpec.get()) m_typeSpec->setParent(this);
}
void ParameterDeclarationAST::setDeclarator(DeclaratorAST::Node& declarator)
{
m_declarator = std::move(declarator);
if (m_declarator.get()) m_declarator->setParent(this);
}
void ParameterDeclarationAST::setExpression(AST::Node& expression)
{
m_expression = std::move(expression);
if (m_expression.get()) m_expression->setParent(this);
}
QString ParameterDeclarationAST::text() const
{
QString str;
if (m_typeSpec.get())
str += m_typeSpec->text() + QLatin1Char(' ');
if (m_declarator.get())
str += m_declarator->text();
if (m_expression.get())
str += QString::fromLatin1(" = ") + m_expression->text();
return str;
}
// --------------------------------------------------------------------------
ParameterDeclarationListAST::ParameterDeclarationListAST()
{
}
void ParameterDeclarationListAST::addParameter(ParameterDeclarationAST::Node& parameter)
{
if (!parameter.get())
return;
parameter->setParent(this);
m_parameterList.append(parameter.release());
}
QString ParameterDeclarationListAST::text() const
{
QStringList l;
for (int i = 0; i < m_parameterList.size(); ++i) {
l.append(m_parameterList.at(i)->text());
}
return l.join(QLatin1String(", "));
}
// --------------------------------------------------------------------------
ParameterDeclarationClauseAST::ParameterDeclarationClauseAST()
{
}
void ParameterDeclarationClauseAST::setParameterDeclarationList(ParameterDeclarationListAST::Node& parameterDeclarationList)
{
m_parameterDeclarationList = std::move(parameterDeclarationList);
if (m_parameterDeclarationList.get()) m_parameterDeclarationList->setParent(this);
}
void ParameterDeclarationClauseAST::setEllipsis(AST::Node& ellipsis)
{
m_ellipsis = std::move(ellipsis);
if (m_ellipsis.get()) m_ellipsis->setParent(this);
}
QString ParameterDeclarationClauseAST::text() const
{
QString str;
if (m_parameterDeclarationList.get())
str += m_parameterDeclarationList->text();
if (m_ellipsis.get())
str += QLatin1String(" ...");
return str;
}
// --------------------------------------------------------------------------
GroupAST::GroupAST()
{
}
void GroupAST::addNode(AST::Node& node)
{
if (!node.get())
return;
node->setParent(this);
m_nodeList.append(node.release());
}
QString GroupAST::text() const
{
QStringList l;
for (int i = 0; i < m_nodeList.size(); ++i) {
l.append(m_nodeList.at(i)->text());
}
return l.join(QLatin1String(" "));
}
// --------------------------------------------------------------------------
AccessDeclarationAST::AccessDeclarationAST()
{
}
void AccessDeclarationAST::addAccess(AST::Node& access)
{
if (!access.get())
return;
access->setParent(this);
m_accessList.append(access.release());
}
QString AccessDeclarationAST::text() const
{
QStringList l;
for (int i = 0; i < m_accessList.size(); ++i) {
l.append(m_accessList.at(i)->text());
}
return l.join(QLatin1String(" "));
}
// --------------------------------------------------------------------------
TypeParameterAST::TypeParameterAST()
{
}
void TypeParameterAST::setKind(AST::Node& kind)
{
m_kind = std::move(kind);
if (m_kind.get()) m_kind->setParent(this);
}
void TypeParameterAST::setTemplateParameterList(AUTO_PTR<class TemplateParameterListAST>& templateParameterList)
{
m_templateParameterList = std::move(templateParameterList);
if (m_templateParameterList.get()) m_templateParameterList->setParent(this);
}
void TypeParameterAST::setName(NameAST::Node& name)
{
m_name = std::move(name);
if (m_name.get()) m_name->setParent(this);
}
void TypeParameterAST::setTypeId(AST::Node& typeId)
{
m_typeId = std::move(typeId);
if (m_typeId.get()) m_typeId->setParent(this);
}
// --------------------------------------------------------------------------
TemplateParameterAST::TemplateParameterAST()
{
}
void TemplateParameterAST::setTypeParameter(TypeParameterAST::Node& typeParameter)
{
m_typeParameter = std::move(typeParameter);
if (m_typeParameter.get()) m_typeParameter->setParent(this);
}
void TemplateParameterAST::setTypeValueParameter(ParameterDeclarationAST::Node& typeValueParameter)
{
m_typeValueParameter = std::move(typeValueParameter);
if (m_typeValueParameter.get()) m_typeValueParameter->setParent(this);
}
// --------------------------------------------------------------------------
TemplateParameterListAST::TemplateParameterListAST()
{
}
void TemplateParameterListAST::addTemplateParameter(TemplateParameterAST::Node& templateParameter)
{
if (!templateParameter.get())
return;
templateParameter->setParent(this);
m_templateParameterList.append(templateParameter.release());
}
// --------------------------------------------------------------------------
ConditionAST::ConditionAST()
{
}
void ConditionAST::setTypeSpec(TypeSpecifierAST::Node& typeSpec)
{
m_typeSpec = std::move(typeSpec);
if (m_typeSpec.get()) m_typeSpec->setParent(this);
}
void ConditionAST::setDeclarator(DeclaratorAST::Node& declarator)
{
m_declarator = std::move(declarator);
if (m_declarator.get()) m_declarator->setParent(this);
}
void ConditionAST::setExpression(AST::Node& expression)
{
m_expression = std::move(expression);
if (m_expression.get()) m_expression->setParent(this);
}
void ClassSpecifierAST::setWinDeclSpec(GroupAST::Node & winDeclSpec)
{
m_winDeclSpec = std::move(winDeclSpec);
if (m_winDeclSpec.get()) m_winDeclSpec->setParent(this);
}
void ClassSpecifierAST::setFinal(AST::Node& final_)
{
m_final = std::move(final_);
if (m_final.get()) m_final->setParent(this);
}
| 33,182
|
C++
|
.cpp
| 1,017
| 29.330383
| 124
| 0.657306
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
749,204
|
lookup.cpp
|
KDE_umbrello/lib/cppparser/lookup.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2005 Tobias Erbsland <te@profzone.ch>
SPDX-FileCopyrightText: 2002, 2003 Roberto Raggi <roberto@kdevelop.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "lookup.h"
int Lookup::find(const HashedString& s)
{
KeywordMap::const_iterator it = keywords().find(s);
if (it == keywords().end())
return -1;
return static_cast<int>((*it));
}
const Lookup::KeywordMap& Lookup::keywords()
{
static KeywordMap keywords;
if (keywords.empty()) {
#include "keywords.h"
}
return keywords;
}
| 597
|
C++
|
.cpp
| 21
| 24.809524
| 75
| 0.699473
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
749,205
|
driver.cpp
|
KDE_umbrello/lib/cppparser/driver.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2002, 2003 Roberto Raggi <roberto@kdevelop.org>
SPDX-FileCopyrightText: 2006 David Nolden <david.nolden.kdevelop@art-master.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#define CACHELEXER
#define DBG_SRC QLatin1String("Driver")
#include "driver.h"
#include "lexer.h"
#include "parser.h"
#include "debug_utils.h"
#include <KLocalizedString>
#include <stdlib.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qdir.h>
#include <qdatastream.h>
#include <qbuffer.h>
#include <assert.h>
#include <iostream>
DEBUG_REGISTER_DISABLED(Driver)
// void Macro::read(QDataStream& stream) {
// stream >> m_idHashValid;
// stream >> m_valueHashValid;
// stream >> m_idHash;
// stream >> m_valueHash;
// stream >> m_name;
// stream >> m_body;
// stream >> m_fileName;
// stream >> m_hasArguments;
// stream >> m_argumentList;
// }
//
// void Macro::write(QDataStream& stream) const {
// stream << m_idHashValid;
// stream << m_valueHashValid;
// stream << m_idHash;
// stream << m_valueHash;
// stream << m_name;
// stream << m_body;
// stream << m_fileName;
// stream << m_hasArguments;
// stream << m_argumentList;
// }
class IntIncreaser
{
public:
IntIncreaser(int& i) : m_i(i)
{
++m_i;
}
~IntIncreaser()
{
--m_i;
}
private:
int& m_i;
};
class DefaultSourceProvider: public SourceProvider
{
public:
DefaultSourceProvider() {}
virtual QString contents(const QString& fileName)
{
QString source;
QFile f(fileName);
if (f.open(QIODevice::ReadOnly)) {
QTextStream s(&f);
source = s.readAll();
f.close();
}
return source;
}
virtual bool isModified(const QString& fileName)
{
Q_UNUSED(fileName);
return true;
}
private:
DefaultSourceProvider(const DefaultSourceProvider& source);
void operator = (const DefaultSourceProvider& source);
};
Driver::Driver()
: depresolv(0), lexer(nullptr), m_lexerCache(this), m_dependenceDepth(0), m_maxDependenceDepth(20)
{
m_sourceProvider = new DefaultSourceProvider();
}
Driver::~Driver()
{
reset();
delete m_sourceProvider;
}
void Driver::setMaxDependenceDepth(int depth)
{
m_maxDependenceDepth = depth;
}
SourceProvider* Driver::sourceProvider()
{
return m_sourceProvider;
}
void Driver::setSourceProvider(SourceProvider* sourceProvider)
{
delete m_sourceProvider;
m_sourceProvider = sourceProvider;
}
void Driver::reset()
{
m_lexerCache.clear();
m_dependences.clear();
m_macros.clear();
m_problems.clear();
m_includePaths.clear();
while (m_parsedUnits.size()) {
//TranslationUnitAST* unit = **m_parsedUnits.begin();
m_parsedUnits.erase(m_parsedUnits.begin());
//delete(unit);
}
}
QStringList Driver::getCustomIncludePath(const QString&)
{
return includePaths();
}
void Driver::remove
(const QString & fileName)
{
m_dependences.remove(fileName);
m_problems.remove(fileName);
if (!isResolveDependencesEnabled())
removeAllMacrosInFile(fileName);
QMap<QString, ParsedFilePointer>::Iterator it = m_parsedUnits.find(fileName);
if (it != m_parsedUnits.end()) {
//TranslationUnitAST * unit = **it;
m_parsedUnits.erase(it);
//delete(unit);
}
}
void Driver::removeAllMacrosInFile(const QString& fileName)
{
MacroMap::iterator it = m_macros.begin();
while (it != m_macros.end()) {
Macro m = (*it).second;
if (m.fileName() == fileName) {
m_macros.erase(it++);
} else {
++it;
}
}
}
void Driver::usingString(const HashedString& str)
{
#ifdef CACHELEXER
if (m_currentLexerCache) {
m_currentLexerCache->addString(m_lexerCache.unifyString(str));
}
#endif
}
bool Driver::hasMacro(const HashedString& name)
{
std::pair< MacroMap::const_iterator, MacroMap::const_iterator > range = m_macros.equal_range(name);
if (range.first == range.second) {
return false;
} else {
const Macro& m((*(--range.second)).second);
if (m.isUndef())
return false;
else
return true;
}
return false;
}
QString deepCopy(const QString& str)
{
return str;
//return str.ascii();
}
const Macro& Driver::macro(const HashedString& name) const
{
std::pair< MacroMap::const_iterator, MacroMap::const_iterator > range = m_macros.equal_range(name);
if (range.first == range.second) {
return (*const_cast<MacroMap&>(m_macros).insert(std::make_pair(deepCopy(name.str()), Macro()))).second; ///Since we need to return a reference, there's no other way.
} else {
return (*(--range.second)).second;
}
}
Macro& Driver::macro(const HashedString& name)
{
std::pair< MacroMap::iterator, MacroMap::iterator > range = m_macros.equal_range(name);
if (range.first == range.second) {
return (*m_macros.insert(std::make_pair(deepCopy(name.str()), Macro()))).second;
} else {
return (*(--range.second)).second;
}
}
void Driver::addMacro(const Macro & macro)
{
std::pair< MacroMap::iterator, MacroMap::iterator > range = m_macros.equal_range(macro.name());
if (range.first == range.second) {
m_macros.insert(std::make_pair(deepCopy(macro.name()), macro));
} else {
///Insert behind the other macros
m_macros.insert(range.second, std::make_pair(deepCopy(macro.name()), macro));
Macro cp = this->macro(macro.name());
assert(macro == cp);
}
#ifdef CACHELEXER
if (m_currentLexerCache)
m_currentLexerCache->addDefinedMacro(macro);
#endif
}
void Driver::removeMacro(const HashedString& macroName)
{
std::pair< MacroMap::iterator, MacroMap::iterator > range = m_macros.equal_range(macroName);
if (range.first != range.second) {
m_macros.erase(--range.second);
}
}
ParsedFilePointer Driver::takeTranslationUnit(const QString& fileName)
{
QMap<QString, ParsedFilePointer>::const_iterator it = m_parsedUnits.constFind(fileName);
ParsedFilePointer unit(*it);
m_parsedUnits[ fileName ] = nullptr;
return unit;
}
void Driver::takeTranslationUnit(const ParsedFile& file)
{
m_parsedUnits[ file.fileName() ] = nullptr;
}
ParsedFilePointer Driver::translationUnit(const QString& fileName) const
{
QMap<QString, ParsedFilePointer>::const_iterator it = m_parsedUnits.constFind(fileName);
if (it != m_parsedUnits.constEnd())
return it.value();
else
return ParsedFilePointer();
}
class Driver::ParseHelper
{
public:
ParseHelper(const QString& fileName, bool force, Driver* driver, bool reportMessages = true, QString includedFrom = QString())
: m_wasReset(false), m_fileName(fileName), m_previousFileName(driver->m_currentFileName), m_previousLexer(driver->lexer),
m_previousParsedFile(driver->m_currentParsedFile), m_previousCachedLexedFile(driver->m_currentLexerCache), m_force(force),
m_reportMessages(reportMessages), m_includedFrom(includedFrom), m_driver(driver), m_lex(m_driver) {}
/**
* This function must be called after constructing the ParseHelper.
*/
void init()
{
QFileInfo fileInfo(m_fileName);
m_driver->m_currentParsedFile = new ParsedFile(m_fileName, fileInfo.lastModified());
if (!m_includedFrom.isEmpty())
m_driver->m_currentParsedFile->setIncludedFrom(m_includedFrom);
#ifdef CACHELEXER
m_driver->m_currentLexerCache = new CachedLexedFile(m_fileName, &m_driver->m_lexerCache);
#endif
m_absoluteFilePath = fileInfo.absoluteFilePath();
QMap<QString, ParsedFilePointer>::Iterator it = m_driver->m_parsedUnits.find(m_absoluteFilePath);
if (m_force && it != m_driver->m_parsedUnits.end()) {
m_driver->takeTranslationUnit(m_absoluteFilePath);
} else if (it != m_driver->m_parsedUnits.end() && *it != (ParsedFilePointer)nullptr) {
// file already processed
return ;
}
CachedLexedFilePointer lexedFileP = m_driver->m_lexerCache.lexedFile(HashedString(m_fileName));
m_driver->m_dependences.remove(m_fileName);
m_driver->m_problems.remove(m_fileName);
m_driver->m_currentFileName = m_fileName;
m_driver->lexer = &m_lex;
m_driver->setupLexer(&m_lex);
m_lex.setReportMessages(m_reportMessages);
DEBUG() << "lexing file " << m_fileName ;
m_fileContent = m_driver->sourceProvider()->contents(m_fileName);
m_lex.setSource(m_fileContent);
if (m_previousCachedLexedFile)
m_previousCachedLexedFile->merge(*m_driver->m_currentLexerCache);
else
m_driver->findOrInsertProblemList(m_driver->m_currentMasterFileName) += m_driver->m_currentLexerCache->problems();
if (!lexedFileP && m_previousParsedFile) //only add the new cache-instance if a fitting isn't already stored, and if this file was included by another one.
m_driver->m_lexerCache.addLexedFile(m_driver->m_currentLexerCache);
//Copy the recursive include-files into the ParsedFile
m_driver->m_currentParsedFile->addIncludeFiles(m_driver->m_currentLexerCache->includeFiles());
m_driver->m_currentParsedFile->setSkippedLines(m_lex.skippedLines());
}
void parse()
{
QString oldMasterFileName = m_driver->m_currentMasterFileName; //Change the master-file so problems will be reported correctly
m_driver->m_currentMasterFileName = m_absoluteFilePath;
CachedLexedFilePointer lf = m_driver->m_currentLexerCache; //Set the lexer-cache to zero, so the problems registered through addProblem go directly into the file
m_driver->m_currentLexerCache = nullptr;
Parser parser(m_driver, m_driver->lexer);
m_driver->setupParser(&parser);
TranslationUnitAST::Node unit;
parser.parseTranslationUnit(unit);
m_driver->m_currentParsedFile->setTranslationUnit(unit);
m_driver->m_parsedUnits.insert(m_fileName, m_driver->m_currentParsedFile);
m_driver->fileParsed(*m_driver->m_currentParsedFile);
m_driver->m_currentLexerCache = lf;
m_driver->m_currentMasterFileName = oldMasterFileName;
}
ParsedFilePointer parsedFile() const
{
return m_driver->m_currentParsedFile;
}
void reset()
{
if (!m_wasReset) {
m_driver->m_currentFileName = m_previousFileName;
m_driver->lexer = m_previousLexer;
m_driver->m_currentParsedFile = m_previousParsedFile;
m_driver->m_currentLexerCache = m_previousCachedLexedFile;
m_wasReset = true;
}
}
~ParseHelper()
{
reset();
}
private:
bool m_wasReset;
QString m_fileName;
QString m_absoluteFilePath;
QString m_previousFileName;
Lexer* m_previousLexer;
ParsedFilePointer m_previousParsedFile;
CachedLexedFilePointer m_previousCachedLexedFile;
bool m_force;
bool m_reportMessages;
QString m_includedFrom;
Driver* m_driver;
Lexer m_lex;
QString m_fileContent;
};
void Driver::addDependence(const QString & fileName, const Dependence & dep)
{
// this can happen if the parser was invoked on a snippet of text and not a file
if (fileName.isEmpty() || !m_currentParsedFile)
return;
//@todo prevent cyclic dependency-loops
QFileInfo fileInfo(dep.first);
QString fn = fileInfo.absoluteFilePath();
if (!depresolv) {
findOrInsertDependenceList(fileName).insert(fn, dep);
m_currentParsedFile->addIncludeFile(dep.first, ParsedFilePointer(), dep.second == Dep_Local);
return ;
}
QString file = findIncludeFile(dep);
findOrInsertDependenceList(fileName).insert(file, dep);
m_currentParsedFile->addIncludeFile(file, ParsedFilePointer(), dep.second == Dep_Local);
if (!QFile::exists(file)) {
Problem p(i18n("Could not find include file %1").arg(dep.first),
lexer ? lexer->currentLine() : -1,
lexer ? lexer->currentColumn() : -1, Problem::Level_Warning);
addProblem(fileName, p);
return ;
}
if (m_currentLexerCache)
m_currentLexerCache->addIncludeFile(file, QDateTime()); ///The time will be overwritten in CachedLexedFile::merge(...)
/**What should be done:
* 1. Lex the file to get all the macros etc.
* 2. TODO: Check what previously set macros the file was affected by, and compare those macros to any previously parsed instances of this file.
* 2.1 If there is a parse-instance of the file where all macros that played a role had the same values, we do not need to reparse this file.
* 2.2 If there is no such fitting instance, the file needs to be parsed and put to the code-model.
*
* It'll be necessary to have multiple versions of one file in the code-model.
*/
IntIncreaser i(m_dependenceDepth);
if (m_dependenceDepth > m_maxDependenceDepth) {
DEBUG() << "maximum dependence-depth of " << m_maxDependenceDepth << " was reached, " << fileName << " will not be processed" ;
return;
}
CachedLexedFilePointer lexedFileP = m_lexerCache.lexedFile(HashedString(file));
if (lexedFileP) {
CachedLexedFile& lexedFile(*lexedFileP);
m_currentLexerCache->merge(lexedFile); //The ParseHelper will copy the include-files into the result later
for (MacroSet::Macros::const_iterator it = lexedFile.definedMacros().macros().begin(); it != lexedFile.definedMacros().macros().end(); ++it) {
addMacro((*it));
}
///@todo fill usingMacro(...)
return;
}
ParseHelper h(file, true, this, false, m_currentMasterFileName);
h.init();
/*if (m_parsedUnits.find(file) != m_parsedUnits.end())
return;*/
if (shouldParseIncludedFile(m_currentParsedFile)) ///Until the ParseHelper is destroyed, m_currentParsedFile will stay the included file
h.parse();
}
void Driver::addProblem(const QString & fileName, const Problem & problem)
{
Problem p(problem);
p.setFileName(fileName);
if (m_currentLexerCache)
m_currentLexerCache->addProblem(p);
else
findOrInsertProblemList(m_currentMasterFileName).append(p);
}
QMap< QString, Dependence >& Driver::findOrInsertDependenceList(const QString & fileName)
{
QMap<QString, QMap<QString, Dependence> >::Iterator it = m_dependences.find(fileName);
if (it != m_dependences.end())
return *it;
QMap<QString, Dependence> l;
m_dependences.insert(deepCopy(fileName), l);
return m_dependences[ fileName ];
}
QList < Problem >& Driver::findOrInsertProblemList(const QString & fileName)
{
QMap<QString, QList<Problem> >::Iterator it = m_problems.find(fileName);
if (it != m_problems.end())
return *it;
QList<Problem> l;
m_problems.insert(fileName, l);
return m_problems[ fileName ];
}
QMap< QString, Dependence > Driver::dependences(const QString & fileName) const
{
QMap<QString, QMap<QString, Dependence> >::ConstIterator it = m_dependences.find(fileName);
if (it != m_dependences.end())
return *it;
return QMap<QString, Dependence>();
}
const Driver::MacroMap& Driver::macros() const
{
return m_macros;
}
void Driver::insertMacros(const MacroSet& macros)
{
for (MacroSet::Macros::const_iterator it = macros.m_usedMacros.begin(); it != macros.m_usedMacros.end(); ++it) {
addMacro(*it);
}
}
QList < Problem > Driver::problems(const QString & fileName) const
{
QMap<QString, QList<Problem> >::ConstIterator it = m_problems.find(fileName);
if (it != m_problems.end())
return *it;
return QList<Problem>();
}
void Driver::clearMacros()
{
m_macros.clear();
}
void Driver::clearParsedMacros()
{
//Keep global macros
for (MacroMap::iterator it = m_macros.begin(); it != m_macros.end();) {
if (!(*it).second.fileName().isEmpty()) {
m_macros.erase(it++);
} else {
++it;
}
}
}
bool Driver::parseFile(const QString& fileName, bool onlyPreProcess, bool force , bool macrosGlobal)
{
QString oldMasterFileName = m_currentMasterFileName;
m_currentMasterFileName = fileName;
//if(isResolveDependencesEnabled())
clearParsedMacros(); ///Since everything will be re-lexed, we do not need any old macros
m_lexerCache.increaseFrame();
//Remove the problems now instead of in ParseHelper, because this way the problems reported by getCustomIncludePath(...) will not be discarded
m_problems.remove(fileName);
QStringList oldIncludePaths = m_includePaths;
m_includePaths = getCustomIncludePath(fileName);
ParseHelper p(fileName, force, this);
p.init();
if (!onlyPreProcess) {
p.parse();
}
if (macrosGlobal) {
for (MacroMap::iterator it = m_macros.begin(); it != m_macros.end(); ++it) {
if ((*it).second.fileName() == fileName) {
(*it).second.setFileName(QString());
}
}
}
m_includePaths = oldIncludePaths;
m_currentMasterFileName = oldMasterFileName;
return true;
}
void Driver::setupLexer(Lexer * lexer)
{
// stl
lexer->addSkipWord(QLatin1String("__STL_BEGIN_NAMESPACE"));
lexer->addSkipWord(QLatin1String("__STL_END_NAMESPACE"));
lexer->addSkipWord(QLatin1String("__STL_BEGIN_RELOPS_NAMESPACE"));
lexer->addSkipWord(QLatin1String("__STL_END_RELOPS_NAMESPACE"));
lexer->addSkipWord(QLatin1String("__STL_TEMPLATE_NULL"));
lexer->addSkipWord(QLatin1String("__STL_TRY"));
lexer->addSkipWord(QLatin1String("__STL_UNWIND"));
lexer->addSkipWord(QLatin1String("__STL_NOTHROW"));
lexer->addSkipWord(QLatin1String("__STL_NULL_TMPL_ARGS"));
lexer->addSkipWord(QLatin1String("__STL_UNWIND"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("__GC_CONST"));
lexer->addSkipWord(QLatin1String("__HASH_ALLOC_INIT"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("__STL_DEFAULT_ALLOCATOR"), SkipWordAndArguments, QLatin1String("T"));
lexer->addSkipWord(QLatin1String("__STL_MUTEX_INITIALIZER"));
lexer->addSkipWord(QLatin1String("__STL_NULL_TMPL_ARGS"));
// antlr
lexer->addSkipWord(QLatin1String("ANTLR_BEGIN_NAMESPACE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("ANTLR_USE_NAMESPACE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("ANTLR_USING_NAMESPACE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("ANTLR_END_NAMESPACE"));
lexer->addSkipWord(QLatin1String("ANTLR_C_USING"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("ANTLR_API"));
// gnu
lexer->addSkipWord(QLatin1String("__extension__"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("__attribute__"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("__BEGIN_DECLS"));
lexer->addSkipWord(QLatin1String("__END_DECLS"));
lexer->addSkipWord(QLatin1String("__THROW"));
lexer->addSkipWord(QLatin1String("__restrict"));
lexer->addSkipWord(QLatin1String("__restrict__"));
lexer->addSkipWord(QLatin1String("__attribute_pure__"));
lexer->addSkipWord(QLatin1String("__attribute_malloc__"));
lexer->addSkipWord(QLatin1String("__attribute_format_strfmon__"));
lexer->addSkipWord(QLatin1String("__asm__"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("__devinit"));
lexer->addSkipWord(QLatin1String("__devinit__"));
lexer->addSkipWord(QLatin1String("__init"));
lexer->addSkipWord(QLatin1String("__init__"));
lexer->addSkipWord(QLatin1String("__signed"));
lexer->addSkipWord(QLatin1String("__signed__"));
lexer->addSkipWord(QLatin1String("__unsigned"));
lexer->addSkipWord(QLatin1String("__unsigned__"));
lexer->addSkipWord(QLatin1String("asmlinkage"));
lexer->addSkipWord(QLatin1String("____cacheline_aligned"));
lexer->addSkipWord(QLatin1String("__glibcpp_class_requires"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("__glibcpp_class2_requires"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("__glibcpp_class4_requires"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("__glibcpp_function_requires"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("restrict"));
lexer->addSkipWord(QLatin1String("__BEGIN_NAMESPACE_STD"));
lexer->addSkipWord(QLatin1String("__END_NAMESPACE_STD"));
lexer->addSkipWord(QLatin1String("__BEGIN_NAMESPACE_C99"));
lexer->addSkipWord(QLatin1String("__END_NAMESPACE_C99"));
lexer->addSkipWord(QLatin1String("__USING_NAMESPACE_STD"), SkipWordAndArguments);
// kde
lexer->addSkipWord(QLatin1String("K_SYCOCATYPE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("EXPORT_DOCKCLASS"));
lexer->addSkipWord(QLatin1String("K_EXPORT_COMPONENT_FACTORY"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("K_SYCOCAFACTORY"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("KDE_DEPRECATED"));
// qt
lexer->addSkipWord(QLatin1String("Q_OBJECT"));
lexer->addSkipWord(QLatin1String("Q_INLINE_TEMPLATES"));
lexer->addSkipWord(QLatin1String("Q_TEMPLATE_EXTERN"));
lexer->addSkipWord(QLatin1String("Q_TYPENAME"));
lexer->addSkipWord(QLatin1String("Q_REFCOUNT"));
lexer->addSkipWord(QLatin1String("Q_EXPLICIT"));
lexer->addSkipWord(QLatin1String("QMAC_PASCAL"));
lexer->addSkipWord(QLatin1String("QT_STATIC_CONST"));
lexer->addSkipWord(QLatin1String("QT_STATIC_CONST_IMPL"));
lexer->addSkipWord(QLatin1String("QT_WIN_PAINTER_MEMBERS"));
lexer->addSkipWord(QLatin1String("QT_NC_MSGBOX"));
lexer->addSkipWord(QLatin1String("CALLBACK_CALL_TYPE"));
lexer->addSkipWord(QLatin1String("ACTIVATE_SIGNAL_WITH_PARAM"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_ALIGNOF"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_ARG"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_ASSERT"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_ASSERT_X"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_BASIC_ATOMIC_INITIALIZER"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CHECK_INVALID_SOCKETLAYER"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CHECK_NOT_STATE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CHECK_PTR"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CHECK_SOCKETENGINE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CHECK_STATE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CHECK_STATES"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CHECK_TYPE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CHECK_VALID_SOCKETLAYER"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CLASSINFO"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CLEANUP_RESOURCE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_COMPLEX_TYPE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CONSTRUCTOR_FUNCTION"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_CONSTRUCTOR_FUNCTION0"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_D"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECL_ALIGN"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_ASSOCIATIVE_ITERATOR"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_BUILTIN_METATYPE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_EXTENSION_INTERFACE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_FLAGS"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_INCOMPATIBLE_FLAGS"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_INTERFACE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_METATYPE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_MUTABLE_ASSOCIATIVE_ITERATOR"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_OPERATORS_FOR_FLAGS"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_PRIVATE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_PRIVATE_D"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_PUBLIC"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_SEQUENTIAL_ITERATOR"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_SHARED"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_SHARED_STL"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_TR_FUNCTIONS"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_TYPEINFO"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECLARE_TYPEINFO_BODY"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DECL_METATYPE_HELPER"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DESTRUCTOR_FUNCTION"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DESTRUCTOR_FUNCTION0"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DF"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DISABLE_COPY"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_DUMMY_COMPARISON_OPERATOR"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_ENUMS"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_EXPORT_PLUGIN"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_EXPORT_PLUGIN2"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_EXPORT_STATIC_PLUGIN"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_EXPORT_STATIC_PLUGIN2"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_FLAGS"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_FOREACH"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_FT_GLYPHSLOT_EMBOLDEN"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_FUNC_INFO"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_GLOBAL_STATIC"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_GLOBAL_STATIC_INIT"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_GLOBAL_STATIC_WITH_ARGS"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_GLOBAL_STATIC_WITH_INITIALIZER"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_GTK_IS_WIDGET"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_HASH_DECLARE_INT_NODES"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_IMPL_METATYPE_HELPER"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_IMPORT_PLUGIN"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_IN"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_INFINITY"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_INIT_CHECK"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_INIT_RESOURCE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_INIT_RESOURCE_EXTERN"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_INT64_C"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_INTERFACES"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_LIKELY"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_MAX_3"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_MAXINT"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_MIN_3"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_MM"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_NEAR_CLIP"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_NONE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_OVERRIDE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_PID"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_PLUGIN_INSTANCE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_PRIVATE_PROPERTY"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_PRIVATE_SLOT"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_PROPERTY"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_Q"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_QNAN"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_REGISTER_METATYPE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_RETURN_ARG"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_REVISION"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_SCRIPT_DECLARE_QMETAOBJECT"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_SETS"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_SNAN"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_TOOL_BASE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_TR"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_TYPEID"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_TYPEOF"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_UINT64_C"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_UNLIKELY"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_UNREACHABLE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_UNSET"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_UNUSED"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("Q_VARIANT_AS"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("QT_MODULE"), SkipWordAndArguments);
lexer->addSkipWord(QLatin1String("QT_BEGIN_HEADER"));
lexer->addSkipWord(QLatin1String("QT_BEGIN_NAMESPACE"));
lexer->addSkipWord(QLatin1String("QT_END_HEADER"));
lexer->addSkipWord(QLatin1String("QT_END_NAMESPACE"));
// flex
lexer->addSkipWord(QLatin1String("yyconst"));
lexer->addSkipWord(QLatin1String("YY_RULE_SETUP"));
lexer->addSkipWord(QLatin1String("YY_BREAK"));
lexer->addSkipWord(QLatin1String("YY_RESTORE_YY_MORE_OFFSET"));
// gtk
lexer->addSkipWord(QLatin1String("G_BEGIN_DECLS"));
lexer->addSkipWord(QLatin1String("G_END_DECLS"));
lexer->addSkipWord(QLatin1String("G_GNUC_CONST"));
lexer->addSkipWord(QLatin1String("G_CONST_RETURN"));
lexer->addSkipWord(QLatin1String("GTKMAIN_C_VAR"));
lexer->addSkipWord(QLatin1String("GTKVAR"));
lexer->addSkipWord(QLatin1String("GDKVAR"));
lexer->addSkipWord(QLatin1String("G_GNUC_PRINTF"), SkipWordAndArguments);
// windows
lexer->addSkipWord(QLatin1String("WINAPI"));
lexer->addSkipWord(QLatin1String("__stdcall"));
lexer->addSkipWord(QLatin1String("__cdecl"));
lexer->addSkipWord(QLatin1String("_cdecl"));
lexer->addSkipWord(QLatin1String("CALLBACK"));
// gcc extensions
if (!hasMacro("__asm__")) addMacro(Macro(QLatin1String("__asm__"), QLatin1String("asm")));
if (!hasMacro("__inline")) addMacro(Macro(QLatin1String("__inline"), QLatin1String("inline")));
if (!hasMacro("__inline__")) addMacro(Macro(QLatin1String("__inline__"), QLatin1String("inline")));
if (!hasMacro("__const")) addMacro(Macro(QLatin1String("__const"), QLatin1String("const")));
if (!hasMacro("__const__")) addMacro(Macro(QLatin1String("__const__"), QLatin1String("const")));
if (!hasMacro("__volatile__")) addMacro(Macro(QLatin1String("__volatile__"), QLatin1String("volatile")));
if (!hasMacro("__complex__")) addMacro(Macro(QLatin1String("__complex__"), QString()));
// c++ macros
if (!hasMacro("__cplusplus")) addMacro(Macro(QLatin1String("__cplusplus"), QString()));
}
void Driver::setupParser(Parser * parser)
{
Q_UNUSED(parser);
}
void Driver::clearIncludePaths()
{
m_includePaths.clear();
}
void Driver::addIncludePath(const QString &path)
{
if (!path.trimmed().isEmpty())
m_includePaths << path;
}
QString Driver::findIncludeFile(const Dependence& dep, const QString& fromFile)
{
QString fileName = dep.first;
if (dep.second == Dep_Local) {
QString path = QFileInfo(fromFile).absolutePath();
QFileInfo fileInfo(QFileInfo(path, fileName));
if (fileInfo.exists() && fileInfo.isFile())
return fileInfo.absoluteFilePath();
}
QStringList includePaths = getCustomIncludePath(fromFile);
for (QStringList::ConstIterator it = includePaths.constBegin(); it != includePaths.constEnd(); ++it) {
QFileInfo fileInfo(*it, fileName);
if (fileInfo.exists() && fileInfo.isFile())
return fileInfo.absoluteFilePath();
}
return QString();
}
QString Driver::findIncludeFile(const Dependence& dep) const
{
QString fileName = dep.first;
if (dep.second == Dep_Local) {
QString path = QFileInfo(currentFileName()).absolutePath();
QFileInfo fileInfo(QFileInfo(path, fileName));
if (fileInfo.exists() && fileInfo.isFile())
return fileInfo.absoluteFilePath();
}
for (QStringList::ConstIterator it = m_includePaths.begin(); it != m_includePaths.end(); ++it) {
QFileInfo fileInfo(*it, fileName);
if (fileInfo.exists() && fileInfo.isFile())
return fileInfo.absoluteFilePath();
}
return QString();
}
void Driver::setResolveDependencesEnabled(bool enabled)
{
depresolv = enabled;
if (depresolv)
setupPreProcessor();
}
bool Driver::shouldParseIncludedFile(const ParsedFilePointer& /*file*/)
{
return false;
}
void Driver::setupPreProcessor() {}
void Driver::fileParsed(ParsedFile & fileName)
{
Q_UNUSED(fileName);
}
void Driver::usingMacro(const Macro& macro)
{
if (m_currentParsedFile)
m_currentParsedFile->usedMacros().addMacro(macro);
#ifdef CACHELEXER
if (m_currentLexerCache)
m_currentLexerCache->addUsedMacro(macro);
#endif
}
// void Macro::computeHash() const {
// m_idHash = 7 * (HashedString::hashString(m_name) + m_argumentList.count() * 13);
// int a = 1;
// m_idHash += 31 * m_argumentList.count();
//
// m_valueHash = 27 * (HashedString::hashString(m_body) + (m_isUndefMacro ? 1 : 0));
//
// for(QList<Argument>::const_iterator it = m_argumentList.begin(); it != m_argumentList.end(); ++it) {
// a *= 19;
// m_valueHash += a * HashedString::hashString(*it);
// }
// m_valueHashValid = true;
// m_idHashValid = true;
// }
// MacroSet::MacroSet() : m_idHashValid(false), m_valueHashValid(false) {
// }
void MacroSet::addMacro(const Macro& macro)
{
std::pair<Macros::const_iterator, bool> r = m_usedMacros.insert(macro);
if (!r.second) {
//Make sure the macro added later will be used
m_usedMacros.erase(r.first);
m_usedMacros.insert(macro);
}
m_idHashValid = m_valueHashValid = false;
}
void MacroSet::merge(const MacroSet& macros)
{
Macros m = macros.m_usedMacros; //Swap is needed so the merged macros take precedence
m.insert(m_usedMacros.begin(), m_usedMacros.end());
m_usedMacros = m;
m_idHashValid = m_valueHashValid = false;
}
size_t MacroSet::idHash() const
{
if (!m_idHashValid) computeHash();
return m_idHash;
}
size_t MacroSet::valueHash() const
{
if (!m_valueHashValid) computeHash();
return m_valueHash;
}
void MacroSet::computeHash() const
{
m_idHash = 0;
m_valueHash = 0;
int mult = 1;
for (Macros::const_iterator it = m_usedMacros.begin(); it != m_usedMacros.end(); ++it) {
mult *= 31;
m_idHash += (*it).idHash();
m_valueHash += (*it).valueHash();
}
}
// void MacroSet::read(QDataStream& stream) {
// stream >> m_idHashValid >> m_idHash >> m_valueHashValid >> m_valueHash;
// int cnt;
// stream >> cnt;
// m_usedMacros.clear();
// Macro m;
// for(int a = 0; a < cnt; a++) {
// m.read(stream);
// m_usedMacros.insert(m);
// }
// }
//
// void MacroSet::write(QDataStream& stream) const {
// stream << m_idHashValid << m_idHash << m_valueHashValid << m_valueHash;
// stream << m_usedMacros.size();
// for(Macros::const_iterator it = m_usedMacros.begin(); it != m_usedMacros.end(); ++it) {
// (*it).write(stream);
// }
// }
/**
* @return All Macros that were used while processing this translation-unit
* */
MacroSet& ParsedFile::usedMacros()
{
return m_usedMacros;
}
const MacroSet& ParsedFile::usedMacros() const
{
return m_usedMacros;
}
ParsedFile::ParsedFile(const QString& fileName, const QDateTime& timeStamp)
: m_translationUnit(nullptr),
m_skippedLines(0),
m_fileName(fileName),
m_timeStamp(timeStamp)
{
m_includeFiles.insert(fileName);
}
ParsedFile::ParsedFile(const QByteArray& array)
: m_translationUnit(nullptr),
m_skippedLines(0)
{
QByteArray a(array);
QBuffer b(&a);
QDataStream d(&b);
read(d);
}
QString ParsedFile::includedFrom() const
{
return m_includedFrom;
}
void ParsedFile::setIncludedFrom(const QString& str)
{
m_includedFrom = str;
}
QByteArray ParsedFile::serialize() const
{
QByteArray array;
QBuffer b(&array);
QDataStream d(&b);
write(d);
return array;
}
// void ParsedFile::read(QDataStream& stream) {
// int directIncludeFilesCount;
// stream >> directIncludeFilesCount;
// m_directIncludeFiles.clear();
// for(int a = 0; a < directIncludeFilesCount; a++) {
// IncludeDesc i;
// stream >> i.local;
// stream >> i.includePath;
// //"parsed" will not be reconstructed
// m_directIncludeFiles.push_back(i);
// }
// stream >> m_fileName;
// stream >> m_timeStamp;
// m_usedMacros.read(stream);
// m_translationUnit = 0;
// m_includeFiles.read(stream);
// }
//
// void ParsedFile::write(QDataStream& stream) const {
// for(QList<IncludeDesc>::const_iterator it = m_directIncludeFiles.begin(); it != m_directIncludeFiles.end(); ++it) {
// stream << (*it).local;
// stream << (*it).includePath;
// }
// stream << m_fileName;
// stream << m_timeStamp;
// m_usedMacros.write(stream);
// m_includeFiles.write(stream);
// }
void ParsedFile::setTranslationUnit(const TranslationUnitAST::Node& trans)
{
m_translationUnit = trans;
}
// HashedStringSet& ParsedFile::includeFiles() {
// return m_includeFiles;
// }
int ParsedFile::skippedLines() const
{
return m_skippedLines;
}
void ParsedFile::setSkippedLines(int lines)
{
m_skippedLines = lines;
}
const HashedStringSet& ParsedFile::includeFiles() const
{
return m_includeFiles;
}
QString ParsedFile::fileName() const
{
return m_fileName;
}
QDateTime ParsedFile::timeStamp() const
{
return m_timeStamp;
}
void ParsedFile::addIncludeFiles(const HashedStringSet& includeFiles)
{
m_includeFiles += includeFiles;
}
void ParsedFile::addIncludeFile(const QString& includePath, const ParsedFilePointer& parsed, bool localInclude)
{
m_includeFiles.insert(includePath);
if (parsed)
m_includeFiles += parsed->includeFiles();
IncludeDesc d;
d.local = localInclude;
d.includePath = includePath;
d.parsed = parsed;
m_directIncludeFiles << d;
}
const QList<ParsedFile::IncludeDesc>& ParsedFile::directIncludeFiles() const
{
return m_directIncludeFiles;
}
bool MacroSet::hasMacro(const QString& name) const
{
Macros::const_iterator it = m_usedMacros.find(Macro(name, QString()));
if (it != m_usedMacros.end()) {
return true;
} else {
return false;
}
}
bool MacroSet::hasMacro(const HashedString& name) const
{
Macros::const_iterator it = m_usedMacros.find(Macro(name.str(), QString()));
if (it != m_usedMacros.end()) {
return true;
} else {
return false;
}
}
Macro MacroSet::macro(const QString& name) const
{
Macros::const_iterator it = m_usedMacros.find(Macro(name, QString()));
if (it != m_usedMacros.end()) {
return *it;
} else {
return Macro();
}
}
LexerCache* Driver::lexerCache()
{
return &m_lexerCache;
}
| 40,659
|
C++
|
.cpp
| 984
| 36.66565
| 174
| 0.701984
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
749,206
|
tree_parser.cpp
|
KDE_umbrello/lib/cppparser/tree_parser.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2002, 2003 Roberto Raggi <roberto@kdevelop.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "tree_parser.h"
#define DBG_SRC QLatin1String("TreeParser")
#include "debug_utils.h"
#include "driver.h"
DEBUG_REGISTER_DISABLED(TreeParser)
TreeParser::TreeParser()
{
}
TreeParser::~TreeParser()
{
}
void TreeParser::parseTranslationUnit(const ParsedFile& translationUnit)
{
DEBUG() << "TreeParser::parseTranslationUnit()" ;
QList<DeclarationAST*> declarations = translationUnit->declarationList();
QList<DeclarationAST*>::const_iterator it = declarations.constBegin();
for (; it != declarations.constEnd(); it++) {
if ((*it) == nullptr) {
DEBUG() << "declaration is zero" ;
continue;
}
parseDeclaration(*it);
}
}
void TreeParser::parseDeclaration(DeclarationAST* declaration)
{
DEBUG() << "TreeParser::parseDeclaration()" ;
if (!declaration)
return;
switch (declaration->nodeType()) {
case NodeType_LinkageSpecification:
parseLinkageSpecification(static_cast<LinkageSpecificationAST*>(declaration));
break;
case NodeType_Namespace:
parseNamespace(static_cast<NamespaceAST*>(declaration));
break;
case NodeType_NamespaceAlias:
parseNamespaceAlias(static_cast<NamespaceAliasAST*>(declaration));
break;
case NodeType_Using:
parseUsing(static_cast<UsingAST*>(declaration));
break;
case NodeType_UsingDirective:
parseUsingDirective(static_cast<UsingDirectiveAST*>(declaration));
break;
case NodeType_Typedef:
parseTypedef(static_cast<TypedefAST*>(declaration));
break;
case NodeType_TemplateDeclaration:
parseTemplateDeclaration(static_cast<TemplateDeclarationAST*>(declaration));
break;
case NodeType_SimpleDeclaration:
parseSimpleDeclaration(static_cast<SimpleDeclarationAST*>(declaration));
break;
case NodeType_FunctionDefinition:
parseFunctionDefinition(static_cast<FunctionDefinitionAST*>(declaration));
break;
case NodeType_AccessDeclaration:
parseAccessDeclaration(static_cast<AccessDeclarationAST*>(declaration));
break;
}
}
void TreeParser::parseLinkageSpecification(LinkageSpecificationAST* ast)
{
DEBUG() << "TreeParser::parseLinkageSpecification()" ;
if (ast->linkageBody())
parseLinkageBody(ast->linkageBody());
else if (ast->declaration())
parseDeclaration(ast->declaration());
}
void TreeParser::parseNamespace(NamespaceAST* decl)
{
DEBUG() << "TreeParser::parseNamespace()" ;
if (decl->linkageBody())
parseLinkageBody(decl->linkageBody());
}
void TreeParser::parseNamespaceAlias(NamespaceAliasAST* decl)
{
DEBUG() << "TreeParser::parseNamespaceAlias()" ;
Q_UNUSED(decl);
}
void TreeParser::parseUsing(UsingAST* decl)
{
DEBUG() << "TreeParser::parseUsing()" ;
Q_UNUSED(decl);
}
void TreeParser::parseUsingDirective(UsingDirectiveAST* decl)
{
DEBUG() << "TreeParser::parseUsingDirective()" ;
Q_UNUSED(decl);
}
void TreeParser::parseTypedef(TypedefAST* decl)
{
DEBUG() << "TreeParser::parseTypedef()" ;
if (decl->typeSpec())
parseTypeSpecifier(decl->typeSpec());
}
void TreeParser::parseTemplateDeclaration(TemplateDeclarationAST* decl)
{
DEBUG() << "TreeParser::parseTemplateDeclaration()" ;
Q_UNUSED(decl);
}
void TreeParser::parseSimpleDeclaration(SimpleDeclarationAST* decl)
{
DEBUG() << "TreeParser::parseSimpleDeclaration()" ;
Q_UNUSED(decl);
}
void TreeParser::parseFunctionDefinition(FunctionDefinitionAST* def)
{
DEBUG() << "TreeParser::parseFunctionDefinition()" ;
Q_UNUSED(def);
}
void TreeParser::parseLinkageBody(LinkageBodyAST* linkageBody)
{
DEBUG() << "TreeParser::parseLinkageBody()" ;
QList<DeclarationAST*> declarations = linkageBody->declarationList();
QList<DeclarationAST*>::const_iterator it = declarations.constBegin();
for (; it != declarations.constEnd(); ++it) {
parseDeclaration(*it);
}
}
void TreeParser::parseTypeSpecifier(TypeSpecifierAST* typeSpec)
{
DEBUG() << "TreeParser::parseTypeSpecifier()" ;
switch (typeSpec->nodeType()) {
case NodeType_ClassSpecifier:
parseClassSpecifier(static_cast<ClassSpecifierAST*>(typeSpec));
break;
case NodeType_EnumSpecifier:
parseEnumSpecifier(static_cast<EnumSpecifierAST*>(typeSpec));
break;
case NodeType_ElaboratedTypeSpecifier:
parseElaboratedTypeSpecifier(static_cast<ElaboratedTypeSpecifierAST*>(typeSpec));
break;
}
}
void TreeParser::parseClassSpecifier(ClassSpecifierAST* classSpec)
{
DEBUG() << "TreeParser::parseClassSpecifier()" ;
QList<DeclarationAST*> declarations = classSpec->declarationList();
QList<DeclarationAST*>::const_iterator it = declarations.constBegin();
for (; it != declarations.constEnd(); ++it) {
parseDeclaration(*it);
}
}
void TreeParser::parseEnumSpecifier(EnumSpecifierAST* enumSpec)
{
DEBUG() << "TreeParser::parseEnumSpecifier()" ;
Q_UNUSED(enumSpec);
}
void TreeParser::parseElaboratedTypeSpecifier(ElaboratedTypeSpecifierAST* typeSpec)
{
DEBUG() << "TreeParser::parseElaboratedTypeSpecifier()" ;
Q_UNUSED(typeSpec);
}
void TreeParser::parseAccessDeclaration (AccessDeclarationAST * access)
{
DEBUG() << "TreeParser::parseAccessDeclaration()" ;
Q_UNUSED(access);
}
| 5,540
|
C++
|
.cpp
| 164
| 29.140244
| 89
| 0.721483
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
749,207
|
lexercache.cpp
|
KDE_umbrello/lib/cppparser/lexercache.cpp
|
/*
SPDX-FileCopyrightText: 2006 David Nolden <david.nolden.kdevelop@art-master.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "lexercache.h"
#define DBG_SRC QLatin1String("LexerCache")
#include "debug_utils.h"
#include "driver.h"
DEBUG_REGISTER_DISABLED(LexerCache)
LexerCache::LexerCache(Driver* d) : m_driver(d) {}
void LexerCache::addLexedFile(const CachedLexedFilePointer& file)
{
DEBUG() << "adding an instance of " << file->fileName().str() ;
std::pair< CachedLexedFileMap::iterator, CachedLexedFileMap::iterator> files = m_files.equal_range(file->fileName());
if (files.first == files.second) {
m_files.insert(std::make_pair(file->fileName(), file));
} else {
//Make sure newer files appear first
m_files.insert(files.first, std::make_pair(file->fileName(), file));
}
int cnt = 0;
while (files.first != files.second) {
if (sourceChanged(*(*(files.first)).second)) {
m_files.erase(files.first++);
} else {
cnt++;
files.first++;
}
}
DEBUG() << "new count of cached instances for the file: " << cnt ;
}
CachedLexedFilePointer LexerCache::lexedFile(const HashedString& fileName)
{
initFileModificationCache();
std::pair< CachedLexedFileMap::iterator, CachedLexedFileMap::iterator> files = m_files.equal_range(fileName);
///@todo optimize with standard-algorithms(by first computing the intersection)
/* if(files.first != files.second)
DEBUG() << "LexerCache: cache for file " << fileName.str() << " is not empty" ;
else
DEBUG() << "LexerCache: cache for file " << fileName.str() << " is empty" ;*/
while (files.first != files.second) {
const CachedLexedFile& file(*(*(files.first)).second);
if (sourceChanged(file)) {
DEBUG() << "cache for file " << fileName.str() << " is being discarded because the file was modified" ;
m_files.erase(files.first++);
continue;
}
bool success = true;
//Make sure that none of the macros stored in the driver affect the file in a different way than the one before
Driver::MacroMap::const_iterator end = m_driver->macros().end();
for (Driver::MacroMap::const_iterator rit = m_driver->macros().begin(); rit != end;) {
Driver::MacroMap::const_iterator it = rit;
++rit;
if (rit != end && (*it).first == (*rit).first) continue; //Always only use the last macro of the same name for comparison, it is on top of the macro-stack
if ((*it).second.isUndef()) continue; //Undef-macros theoretically don't exist
if (file.hasString((*it).first)) {
if (file.m_usedMacros.hasMacro((*it).first)) {
Macro m(file.m_usedMacros.macro((*it).first.str()));
if (!(m == (*it).second)) {
DEBUG() << "The cached file " << fileName.str() << " depends on the string \"" << (*it).first.str() << "\" and used a macro for it with the body \"" << m.body() << "\"(from " << m.fileName() << "), but the driver contains the same macro with body \"" << (*it).second.body() << "\"(from " << (*it).second.fileName() << "), cache is not used" ;
//Macro with the same name was used, but it is different
success = false;
break;
}
} else {
//There is a macro that affects the file, but was not used while the previous parse
DEBUG() << "The cached file " << fileName.str() << " depends on the string \"" << (*it).first.str() << "\" and the driver contains a macro of that name with body \"" << (*it).second.body() << "\"(from " << (*it).second.fileName() << "), the cached file is not used" ;
success = false;
break;
}
}
}
//Make sure that all external macros used by the file now exist too
MacroSet::Macros::const_iterator end2 = file.usedMacros().macros().end();
for (MacroSet::Macros::const_iterator it = file.usedMacros().macros().begin(); it != end2; ++it) {
if (!m_driver->hasMacro(HashedString((*it).name()))) {
DEBUG() << "The cached file " << fileName.str() << " used a macro called \"" << it->name() << "\"(from " << it->fileName() << "), but the driver does not contain that macro, the cached file is not used" ;
success = false;
break;
}
}
if (success) {
DEBUG() << "Using cached file " << fileName.str() ;
(*files.first).second->access();
return (*files.first).second;
}
++files.first;
}
return CachedLexedFilePointer();
}
QDateTime LexerCache::fileModificationTimeCached(const HashedString& fileName)
{
FileModificationMap::const_iterator it = m_fileModificationCache.constFind(fileName);
if (it != m_fileModificationCache.constEnd()) {
///Use the cache for 10 seconds
if ((*it).m_readTime.secsTo(m_currentDateTime) < 10) {
return (*it).m_modificationTime;
}
}
QFileInfo fileInfo(fileName.str());
m_fileModificationCache[fileName].m_readTime = QDateTime::currentDateTime();
m_fileModificationCache[fileName].m_modificationTime = fileInfo.lastModified();
return fileInfo.lastModified();
}
//Should be cached too!
bool LexerCache::sourceChanged(const CachedLexedFile& file)
{
//@todo Check if any of the dependencies changed
QDateTime modTime = fileModificationTimeCached(file.fileName());
if (modTime != file.modificationTime())
return true;
for (QMap<HashedString, QDateTime>::const_iterator it = file.allModificationTimes().begin(); it != file.allModificationTimes().end(); ++it) {
QDateTime modTime = fileModificationTimeCached(it.key());
if (modTime != *it)
return true;
}
return false;
}
void LexerCache::clear()
{
m_files.clear();
m_totalStringSet.clear();
m_fileModificationCache.clear();
}
void LexerCache::erase(const CacheNode* node)
{
std::pair< CachedLexedFileMap::iterator, CachedLexedFileMap::iterator> files = m_files.equal_range(((const CachedLexedFile*)(node))->fileName());
while (files.first != files.second) {
if ((*files.first).second == ((const CachedLexedFile*)(node))) {
m_files.erase(files.first);
return;
}
files.first++;
}
DEBUG() << "Error: could not find a node in the list for file " << ((const CachedLexedFile*)(node))->fileName().str() ;
}
CachedLexedFile::CachedLexedFile(const HashedString& fileName, LexerCache* manager) : CacheNode(manager), m_fileName(fileName)
{
QFileInfo fileInfo(fileName.str());
m_modificationTime = fileInfo.lastModified();
m_allModificationTimes[ fileName ] = m_modificationTime;
}
void CachedLexedFile::addDefinedMacro(const Macro& macro)
{
DEBUG() << "defined macro " << macro.name() ;
m_definedMacros.addMacro(macro);
m_definedMacroNames.insert(HashedString(macro.name()));
}
void CachedLexedFile::addUsedMacro(const Macro& macro)
{
if (!m_definedMacros.hasMacro(macro.name())) {
DEBUG() << "used macro " << macro.name() ;
m_usedMacros.addMacro(macro);
}
}
void CachedLexedFile::addIncludeFile(const HashedString& file, const QDateTime& modificationTime)
{
m_includeFiles.insert(file);
m_allModificationTimes[file] = modificationTime;
}
QDateTime CachedLexedFile::modificationTime() const
{
return m_modificationTime;
}
void CachedLexedFile::addProblem(const Problem& p)
{
m_problems << p;
}
QList<Problem> CachedLexedFile::problems() const
{
return m_problems;
}
//The parameter should be a CachedLexedFile that was lexed AFTER the content of this file
void CachedLexedFile::merge(const CachedLexedFile& file)
{
DEBUG() << fileName().str() << ": merging " << file.fileName().str() << QLatin1Char('\n') << "defined in this: " << m_definedMacroNames.print().c_str() << QLatin1Char('\n')<< "defined macros in other: " << file.m_definedMacroNames.print().c_str() ;;
HashedStringSet tempStrings = file.m_strings;
tempStrings -= m_definedMacroNames;
m_strings += tempStrings;
m_includeFiles += file.m_includeFiles;
//Only add macros to the usedMacros-list that were not defined locally
for (MacroSet::Macros::const_iterator it = file.m_usedMacros.macros().begin(); it != file.m_usedMacros.macros().end(); ++it) {
if (!m_definedMacros.hasMacro((*it).name())) { ///If the macro was not defined locally, add it to the macros-list.
DEBUG() << "inserting used macro " << (*it).name() ;
m_usedMacros.addMacro(*it);
}
}
m_definedMacros.merge(file.m_definedMacros);
m_definedMacroNames += file.m_definedMacroNames;
for (QMap<HashedString, QDateTime>::const_iterator it = file.m_allModificationTimes.begin(); it != file.m_allModificationTimes.end(); ++it)
m_allModificationTimes[it.key()] = *it;
DEBUG() << fileName().str() << ": defined in this after merge: " << m_definedMacroNames.print().c_str() ;
m_problems += file.m_problems;
}
size_t CachedLexedFile::hash() const
{
return m_usedMacros.valueHash() + m_usedMacros.idHash() + m_definedMacros.idHash() + m_definedMacros.valueHash() + m_strings.hash();
}
void LexerCache::initFileModificationCache()
{
m_currentDateTime = QDateTime::currentDateTime();
}
void LexerCache::saveMemory()
{
m_fileModificationCache.clear();
m_totalStringSet.clear(); ///it's unclear how often this should be emptied. It may happen that completely unused strings end up in this set, then deleting it will save us memory.
}
| 9,855
|
C++
|
.cpp
| 207
| 40.657005
| 366
| 0.639763
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
749,208
|
parser.cpp
|
KDE_umbrello/lib/cppparser/parser.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2002, 2003 Roberto Raggi <roberto@kdevelop.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
// c++ support
#include "parser.h"
#include "driver.h"
#include "lexer.h"
#include "errors.h"
#define DBG_SRC QLatin1String("Parser")
#include "debug_utils.h"
#include "uml.h"
// qt
#include <QString>
#include <QStringList>
#include <KLocalizedString>
using namespace std;
DEBUG_REGISTER_DISABLED(Parser)
#define ADVANCE(tk, descr) \
{ \
const Token& token = m_lexer->lookAhead(0); \
if(token != tk){ \
reportError(i18n("'%1' expected found '%2'").arg(QLatin1String(descr)).arg(token.text())); \
return false; \
} \
nextToken(); \
}
#define ADVANCE_NR(tk, descr) \
{ \
const Token& token = m_lexer->lookAhead(0); \
if(token != tk){ \
reportError(i18n("'%1' expected found '%2'").arg(QLatin1String(descr)).arg(token.text())); \
} \
else \
nextToken(); \
}
#define CHECK(tk, descr) \
{ \
const Token& token = m_lexer->lookAhead(0); \
if(token != tk){ \
return false; \
} \
nextToken(); \
}
#define MATCH(tk, descr) \
{ \
const Token& token = m_lexer->lookAhead(0); \
if(token != tk){ \
reportError(Errors::SyntaxError); \
return false; \
} \
}
#define UPDATE_POS(node, start, end) \
{ \
int line, col; \
const Token &a = m_lexer->tokenAt(start); \
const Token &b = m_lexer->tokenAt(end!=start ? end-1 : end); \
a.getStartPosition(&line, &col); \
(node)->setStartPosition(line, col); \
b.getEndPosition(&line, &col); \
(node)->setEndPosition(line, col); \
if((node)->nodeType() == NodeType_Generic) { \
if ((start) == (end) || (end) == (start)+1) \
(node)->setSlice(m_lexer->source(), a.position(), a.length()); \
else \
(node)->setText(toString((start),(end))); \
} \
}
#define AST_FROM_TOKEN(node, tk) \
AST::Node node = CreateNode<AST>(); \
UPDATE_POS(node, (tk), (tk)+1);
//@todo remove me
enum {
OBJC_CLASS,
OBJC_PROTOCOL,
OBJC_ALIAS
};
struct ParserPrivateData {
ParserPrivateData()
{}
};
Parser::Parser(Driver* driver, Lexer* lexer)
: m_driver(driver),
m_lexer(lexer),
m_problems(0)
{
d = new ParserPrivateData();
m_maxProblems = 5;
objcp = false;
}
Parser::~Parser()
{
delete d;
d = nullptr;
}
bool Parser::reportError(const Error& err)
{
PARSER_DEBUG_METHOD;
if (m_problems < m_maxProblems) {
++m_problems;
int line=0, col=0;
const Token& token = m_lexer->lookAhead(0);
m_lexer->getTokenPosition(token, &line, &col);
QString s = m_lexer->lookAhead(0).text();
s = s.left(30).trimmed();
if (s.isEmpty())
s = i18n("<eof>");
m_driver->addProblem(m_driver->currentFileName(), Problem(err.text.arg(s), line, col));
}
return true;
}
bool Parser::reportError(const QString& msg)
{
PARSER_DEBUG_METHOD;
if (m_problems < m_maxProblems) {
++m_problems;
int line=0, col=0;
const Token& token = m_lexer->lookAhead(0);
m_lexer->getTokenPosition(token, &line, &col);
m_driver->addProblem(m_driver->currentFileName(), Problem(msg, line, col));
}
return true;
}
void Parser::syntaxError()
{
(void) reportError(Errors::SyntaxError);
}
bool Parser::skipUntil(int token)
{
PARSER_DEBUG_METHOD;
while (!m_lexer->lookAhead(0).isNull()) {
if (m_lexer->lookAhead(0) == token)
return true;
nextToken();
}
return false;
}
bool Parser::skipUntilDeclaration()
{
PARSER_DEBUG_METHOD;
clearComment();
while (!m_lexer->lookAhead(0).isNull()) {
switch (m_lexer->lookAhead(0)) {
case ';':
case '~':
case Token_scope:
case Token_identifier:
case Token_operator:
case Token_char:
case Token_wchar_t:
case Token_bool:
case Token_short:
case Token_int:
case Token_long:
case Token_signed:
case Token_unsigned:
case Token_float:
case Token_double:
case Token_void:
case Token_extern:
case Token_namespace:
case Token_using:
case Token_typedef:
case Token_asm:
case Token_template:
case Token_export:
case Token_const: // cv
case Token_noexcept:
case Token_const_expr: // cv
case Token_volatile: // cv
case Token_mutable: // cv
case Token_public:
case Token_protected:
case Token_private:
case Token_signals: // Qt
case Token_slots: // Qt
return true;
default:
nextToken();
}
}
return false;
}
bool Parser::skipUntilStatement()
{
PARSER_DEBUG_METHOD;
while (!m_lexer->lookAhead(0).isNull()) {
switch (m_lexer->lookAhead(0)) {
case ';':
case '{':
case '}':
case Token_const:
case Token_const_expr:
case Token_volatile:
case Token_mutable:
case Token_noexcept:
case Token_identifier:
case Token_case:
case Token_default:
case Token_if:
case Token_switch:
case Token_while:
case Token_do:
case Token_for:
case Token_break:
case Token_continue:
case Token_return:
case Token_goto:
case Token_try:
case Token_catch:
case Token_throw:
case Token_char:
case Token_wchar_t:
case Token_bool:
case Token_short:
case Token_int:
case Token_long:
case Token_signed:
case Token_unsigned:
case Token_float:
case Token_double:
case Token_void:
case Token_class:
case Token_struct:
case Token_union:
case Token_enum:
case Token_scope:
case Token_template:
case Token_using:
return true;
default:
nextToken();
}
}
return false;
}
bool Parser::skip(int l, int r)
{
int count = 0;
while (!m_lexer->lookAhead(0).isNull()) {
int tk = m_lexer->lookAhead(0);
if (tk == l)
++count;
else if (tk == r)
--count;
if (count == 0)
return true;
nextToken();
}
return false;
}
bool Parser::skipCommaExpression(AST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
AST::Node expr;
if (!skipExpression(expr))
return false;
while (m_lexer->lookAhead(0) == ',') {
nextToken();
if (!skipExpression(expr)) {
reportError(i18n("expression expected"));
return false;
}
}
AST::Node ast = CreateNode<AST>();
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::skipExpression(AST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
while (!m_lexer->lookAhead(0).isNull()) {
int tk = m_lexer->lookAhead(0);
switch (tk) {
case '(':
skip('(', ')');
nextToken();
break;
case '[':
skip('[', ']');
nextToken();
break;
case '{':
skip('{', '}');
nextToken();
break;
#if 0
case Token_identifier:
nextToken();
if (m_lexer->lookAhead(0) == Token_identifier)
return true;
break;
#endif
case ';':
case ',':
case ']':
case ')':
case '}':
case Token_case:
case Token_default:
case Token_if:
case Token_while:
case Token_do:
case Token_for:
case Token_break:
case Token_continue:
case Token_return:
case Token_goto: {
AST::Node ast = CreateNode<AST>();
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
}
return true;
default:
nextToken();
}
}
return false;
}
bool Parser::parseName(NameAST::Node& node)
{
PARSER_DEBUG_METHOD;
GroupAST::Node winDeclSpec;
parseWinDeclSpec(winDeclSpec);
int start = m_lexer->index();
NameAST::Node ast = CreateNode<NameAST>();
if (m_lexer->lookAhead(0) == Token_scope) {
ast->setGlobal(true);
nextToken();
}
int idx = m_lexer->index();
while (true) {
ClassOrNamespaceNameAST::Node n;
if (!parseUnqualifiedName(n)) {
return false;
}
if (m_lexer->lookAhead(0) == Token_scope) {
nextToken();
ast->addClassOrNamespaceName(n);
if (m_lexer->lookAhead(0) == Token_template)
nextToken(); /// skip optional template #### @todo CHECK
} else {
ast->setUnqualifiedName(n);
break;
}
}
if (idx == m_lexer->index())
return false;
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseTranslationUnit(TranslationUnitAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
m_problems = 0;
TranslationUnitAST::Node tun = CreateNode<TranslationUnitAST>();
node = tun;
// only setup file comment if present at first line, and first column
if (m_lexer->lookAhead(0) == Token_comment) {
processComment();
if (m_lexer->lookAhead(0).position() == 0) {
if (comment()) {
tun->setComment(comment());
clearComment();
}
}
nextToken();
}
else if (m_lexer->lookAhead(0) == '<' &&
m_lexer->lookAhead(1) == '?' &&
m_lexer->lookAhead(2) == Token_identifier &&
m_lexer->lookAhead(2).text() == QLatin1String("php") ) {
uDebug() << "found php tag";
nextToken();
nextToken();
nextToken();
}
while (!m_lexer->lookAhead(0).isNull()) {
DeclarationAST::Node def;
int startDecl = m_lexer->index();
if (!parseDeclaration(def)) {
// error recovery
if (startDecl == m_lexer->index())
nextToken(); // skip at least one token
skipUntilDeclaration();
}
node->addDeclaration(def);
}
UPDATE_POS(node, start, m_lexer->index());
// force (0,0) as start position
node->setStartPosition(0, 0);
return m_problems == 0;
}
bool Parser::parseDeclaration(DeclarationAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
switch (m_lexer->lookAhead(0)) {
case ';':
nextToken();
return true;
case Token_extern:
return parseLinkageSpecification(node);
case Token_namespace:
return parseNamespace(node);
case Token_using:
return parseUsing(node);
case Token_typedef:
return parseTypedef(node);
case Token_asm:
return parseAsmDefinition(node);
case Token_template:
case Token_export:
return parseTemplateDeclaration(node);
default: {
// m_lexer->setIndex(start);
if (objcp && parseObjcDef(node))
return true;
m_lexer->setIndex(start);
GroupAST::Node storageSpec;
parseStorageClassSpecifier(storageSpec);
GroupAST::Node cv;
parseCvQualify(cv);
TypeSpecifierAST::Node spec;
AST::Node declarator;
if (parseEnumSpecifier(spec) || parseClassSpecifier(spec)) {
int line, c;
spec->getEndPosition(&line, &c);
spec->setCvQualify(cv);
GroupAST::Node cv2;
parseCvQualify(cv2);
spec->setCv2Qualify(cv2);
InitDeclaratorListAST::Node declarators;
parseInitDeclaratorList(declarators);
SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
ADVANCE(';', ";");
preparseLineComments(line);
ast->setComment(m_commentStore.getCommentInRange(line));
ast->setStorageSpecifier(storageSpec);
ast->setTypeSpec(spec);
ast->setInitDeclaratorList(declarators);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
m_lexer->setIndex(start);
return parseDeclarationInternal(node);
}
} // end switch
}
bool Parser::parseLinkageSpecification(DeclarationAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != Token_extern) {
return false;
}
nextToken();
LinkageSpecificationAST::Node ast = CreateNode<LinkageSpecificationAST>();
int startExternType = m_lexer->index();
if (m_lexer->lookAhead(0) == Token_string_literal) {
nextToken();
AST::Node externType = CreateNode<AST>();
UPDATE_POS(externType, startExternType, m_lexer->index());
ast->setExternType(externType);
}
if (m_lexer->lookAhead(0) == '{') {
LinkageBodyAST::Node linkageBody;
parseLinkageBody(linkageBody);
ast->setLinkageBody(linkageBody);
} else {
DeclarationAST::Node decl;
if (!parseDeclaration(decl)) {
reportError(i18n("Declaration syntax error"));
}
ast->setDeclaration(decl);
}
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseLinkageBody(LinkageBodyAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != '{') {
return false;
}
nextToken();
LinkageBodyAST::Node lba = CreateNode<LinkageBodyAST>();
node = std::move(lba);
while (!m_lexer->lookAhead(0).isNull()) {
int tk = m_lexer->lookAhead(0);
if (tk == '}')
break;
DeclarationAST::Node def;
int startDecl = m_lexer->index();
if (parseDeclaration(def)) {
node->addDeclaration(def);
} else {
// error recovery
if (startDecl == m_lexer->index())
nextToken(); // skip at least one token
skipUntilDeclaration();
}
}
clearComment();
if (m_lexer->lookAhead(0) != '}') {
reportError(i18n("} expected"));
} else
nextToken();
UPDATE_POS(node, start, m_lexer->index());
return true;
}
bool Parser::parseNamespace(DeclarationAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != Token_namespace) {
return false;
}
nextToken();
int startNamespaceName = m_lexer->index();
if (m_lexer->lookAhead(0) == Token_identifier) {
nextToken();
}
AST::Node namespaceName = CreateNode<AST>();
UPDATE_POS(namespaceName, startNamespaceName, m_lexer->index());
if (m_lexer->lookAhead(0) == '=') {
// namespace alias
nextToken();
NameAST::Node name;
if (parseName(name)) {
ADVANCE(';', ";");
NamespaceAliasAST::Node ast = CreateNode<NamespaceAliasAST>();
ast->setNamespaceName(namespaceName);
ast->setAliasName(name);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
} else {
reportError(i18n("namespace expected"));
return false;
}
} else if (m_lexer->lookAhead(0) == '\\') {
// php namespace
while (m_lexer->lookAhead(0) == '\\' || m_lexer->lookAhead(0) == Token_identifier)
// namespace alias
nextToken();
} else if (m_lexer->lookAhead(0) != '{') {
reportError(i18n("{ expected"));
return false;
}
NamespaceAST::Node ast = CreateNode<NamespaceAST>();
ast->setNamespaceName(namespaceName);
LinkageBodyAST::Node linkageBody;
parseLinkageBody(linkageBody);
ast->setLinkageBody(linkageBody);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseUsing(DeclarationAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != Token_using) {
return false;
}
nextToken();
if (m_lexer->lookAhead(0) == Token_namespace) {
if (!parseUsingDirective(node)) {
return false;
}
UPDATE_POS(node, start, m_lexer->index());
return true;
}
UsingAST::Node ast = CreateNode<UsingAST>();
int startTypeName = m_lexer->index();
if (m_lexer->lookAhead(0) == Token_typename) {
nextToken();
AST::Node tn = CreateNode<AST>();
UPDATE_POS(tn, startTypeName, m_lexer->index());
ast->setTypeName(tn);
}
NameAST::Node name;
if (!parseName(name))
return false;
ast->setName(name);
ADVANCE(';', ";");
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseUsingDirective(DeclarationAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != Token_namespace) {
return false;
}
nextToken();
NameAST::Node name;
if (!parseName(name)) {
reportError(i18n("Namespace name expected"));
return false;
}
ADVANCE(';', ";");
UsingDirectiveAST::Node ast = CreateNode<UsingDirectiveAST>();
ast->setName(name);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseOperatorFunctionId(AST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != Token_operator) {
return false;
}
nextToken();
AST::Node op;
if(parseOperator(op)){
AST::Node asn = CreateNode<AST>();
node = std::move(asn);
UPDATE_POS(node, start, m_lexer->index());
if (node->text() == QLatin1String("operator > >"))
node->setText(QLatin1String("operator >>"));
return true;
} else {
// parse cast operator
GroupAST::Node cv;
parseCvQualify(cv);
TypeSpecifierAST::Node spec;
if (!parseSimpleTypeSpecifier(spec)) {
syntaxError();
return false;
}
spec->setCvQualify(cv);
GroupAST::Node cv2;
parseCvQualify(cv2);
spec->setCv2Qualify(cv2);
AST::Node ptrOp;
while (parsePtrOperator(ptrOp))
;
AST::Node asn = CreateNode<AST>();
node = std::move(asn);
UPDATE_POS(node, start, m_lexer->index());
return true;
}
}
bool Parser::parseTemplateArgumentList(TemplateArgumentListAST::Node& node, bool reportError)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
TemplateArgumentListAST::Node ast = CreateNode<TemplateArgumentListAST>();
AST::Node templArg;
if (!parseTemplateArgument(templArg))
return false;
ast->addArgument(templArg);
while (m_lexer->lookAhead(0) == ',') {
nextToken();
if (!parseTemplateArgument(templArg)) {
if (reportError) {
syntaxError();
break;
} else
return false;
}
ast->addArgument(templArg);
}
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseTypedef(DeclarationAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != Token_typedef) {
return false;
}
nextToken();
TypeSpecifierAST::Node spec;
if (!parseTypeSpecifierOrClassSpec(spec)) {
reportError(i18n("Need a type specifier to declare"));
return false;
}
InitDeclaratorListAST::Node declarators;
if (!parseInitDeclaratorList(declarators)) {
//reportError(i18n("Need an identifier to declare"));
//return false;
}
TypedefAST::Node ast = CreateNode<TypedefAST>();
if (comment()) {
ast->setComment(comment());
clearComment();
preparseLineComments(currentLine());
if (comment()) {
ast->addComment(comment());
clearComment();
}
}
ADVANCE(';', ";");
ast->setTypeSpec(spec);
ast->setInitDeclaratorList(declarators);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseAsmDefinition(DeclarationAST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
ADVANCE(Token_asm, "asm");
GroupAST::Node cv;
parseCvQualify(cv);
skip('(', ')');
ADVANCE(')', ")");
ADVANCE(';', ";");
return true;
}
bool Parser::parseTemplateDeclaration(DeclarationAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
AST::Node exp;
int startExport = m_lexer->index();
if (m_lexer->lookAhead(0) == Token_export) {
nextToken();
AST::Node n = CreateNode<AST>();
UPDATE_POS(n, startExport, m_lexer->index());
exp = std::move(n);
}
if (m_lexer->lookAhead(0) != Token_template) {
return false;
}
nextToken();
TemplateParameterListAST::Node params;
if (m_lexer->lookAhead(0) == '<') {
nextToken();
parseTemplateParameterList(params);
ADVANCE('>', ">");
}
DeclarationAST::Node def;
if (!parseDeclaration(def)) {
reportError(i18n("expected a declaration"));
}
TemplateDeclarationAST::Node ast = CreateNode<TemplateDeclarationAST>();
ast->setExported(exp);
ast->setTemplateParameterList(params);
ast->setDeclaration(def);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseOperator(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
QString text = m_lexer->lookAhead(0).text();
switch (m_lexer->lookAhead(0)) {
case Token_new:
case Token_delete:
nextToken();
if (m_lexer->lookAhead(0) == '[' && m_lexer->lookAhead(1) == ']') {
nextToken();
nextToken();
text += QLatin1String("[]");
}
return true;
case '+':
case '-':
case '*':
case '/':
case '%':
case '^':
case '&':
case '|':
case '~':
case '!':
case '=':
case '<':
case '>':
case ',':
case Token_assign:
case Token_shift:
case Token_eq:
case Token_not_eq:
case Token_leq:
case Token_geq:
case Token_and:
case Token_or:
case Token_incr:
case Token_decr:
case Token_ptrmem:
case Token_arrow:
nextToken();
if (m_lexer->lookAhead(0) == '>')
nextToken();
return true;
default:
if (m_lexer->lookAhead(0) == '(' && m_lexer->lookAhead(1) == ')') {
nextToken();
nextToken();
return true;
} else if (m_lexer->lookAhead(0) == '[' && m_lexer->lookAhead(1) == ']') {
nextToken();
nextToken();
return true;
}
}
return false;
}
bool Parser::parseCvQualify(GroupAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
GroupAST::Node ast = CreateNode<GroupAST>();
int n = 0;
while (!m_lexer->lookAhead(0).isNull()) {
int tk = m_lexer->lookAhead(0);
if (tk == Token_const || tk == Token_volatile || tk == Token_mutable) {
++n;
int startWord = m_lexer->index();
nextToken();
AST::Node word = CreateNode<AST>();
UPDATE_POS(word, startWord, m_lexer->index());
ast->addNode(word);
} else
break;
}
if (n == 0)
return false;
PARSER_DEBUG_METHOD;
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseSimpleTypeSpecifier(TypeSpecifierAST::Node& node)
{
int start = m_lexer->index();
bool isIntegral = false;
bool done = false;
while (!done) {
switch (m_lexer->lookAhead(0)) {
case Token_char:
case Token_wchar_t:
case Token_bool:
case Token_short:
case Token_int:
case Token_long:
case Token_signed:
case Token_unsigned:
case Token_float:
case Token_double:
case Token_void:
isIntegral = true;
nextToken();
break;
default:
done = true;
}
}
TypeSpecifierAST::Node ast = CreateNode<TypeSpecifierAST>();
if (isIntegral) {
ClassOrNamespaceNameAST::Node cl = CreateNode<ClassOrNamespaceNameAST>();
AST::Node n = CreateNode<AST>();
UPDATE_POS(n, start, m_lexer->index());
cl->setName(n);
UPDATE_POS(cl, start, m_lexer->index());
NameAST::Node name = CreateNode<NameAST>();
name->setUnqualifiedName(cl);
UPDATE_POS(name, start, m_lexer->index());
ast->setName(name);
} else {
NameAST::Node name;
if (!parseName(name)) {
m_lexer->setIndex(start);
return false;
}
ast->setName(name);
}
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parsePtrOperator(AST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
switch (m_lexer->lookAhead(0)) {
case '&':
case Token_and:
case '*':
nextToken();
break;
default:
{
int index = m_lexer->index();
AST::Node memPtr;
if (!parsePtrToMember(memPtr)) {
m_lexer->setIndex(index);
return false;
}
}
}
GroupAST::Node cv;
parseCvQualify(cv);
AST::Node ast = CreateNode<AST>();
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseTemplateArgument(AST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (parseTypeId(node)) {
if (m_lexer->lookAhead(0) == ',' || m_lexer->lookAhead(0) == '>')
return true;
}
m_lexer->setIndex(start);
if (!parseLogicalOrExpression(node, true)) {
return false;
}
return true;
}
bool Parser::parseTypeSpecifier(TypeSpecifierAST::Node& spec)
{
PARSER_DEBUG_METHOD;
GroupAST::Node cv;
parseCvQualify(cv);
if (parseElaboratedTypeSpecifier(spec) || parseSimpleTypeSpecifier(spec)) {
spec->setCvQualify(cv);
GroupAST::Node cv2;
parseCvQualify(cv2);
spec->setCv2Qualify(cv2);
return true;
}
return false;
}
bool Parser::parseDeclarator(DeclaratorAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
DeclaratorAST::Node ast = CreateNode<DeclaratorAST>();
DeclaratorAST::Node decl;
NameAST::Node declId;
AST::Node ptrOp;
while (parsePtrOperator(ptrOp)) {
ast->addPtrOp(ptrOp);
}
if (m_lexer->lookAhead(0) == '(') {
nextToken();
if (!parseDeclarator(decl)) {
return false;
}
ast->setSubDeclarator(decl);
if (m_lexer->lookAhead(0) != ')') {
return false;
}
nextToken();
} else {
if (m_lexer->lookAhead(0) == ':') {
// unnamed bitfield
} else if (parseDeclaratorId(declId)) {
ast->setDeclaratorId(declId);
} else {
m_lexer->setIndex(start);
return false;
}
if (m_lexer->lookAhead(0) == ':') {
nextToken();
AST::Node expr;
if (!parseConstantExpression(expr)) {
reportError(i18n("Constant expression expected"));
}
goto update_pos;
}
}
{
bool isVector = true;
while (m_lexer->lookAhead(0) == '[') {
int startArray = m_lexer->index();
nextToken();
AST::Node expr;
parseCommaExpression(expr);
ADVANCE(']', "]");
AST::Node array = CreateNode<AST>();
UPDATE_POS(array, startArray, m_lexer->index());
ast->addArrayDimension(array);
isVector = true;
}
bool skipParen = false;
if (m_lexer->lookAhead(0) == Token_identifier && m_lexer->lookAhead(1) == '(' && m_lexer->lookAhead(2) == '(') {
nextToken();
nextToken();
skipParen = true;
}
if (ast->subDeclarator() && (!isVector || m_lexer->lookAhead(0) != '(')) {
m_lexer->setIndex(start);
return false;
}
int index = m_lexer->index();
if (m_lexer->lookAhead(0) == '(') {
nextToken();
ParameterDeclarationClauseAST::Node params;
if (!parseParameterDeclarationClause(params)) {
PARSER_DEBUG_METHOD;
m_lexer->setIndex(index);
goto update_pos;
}
ast->setParameterDeclarationClause(params);
if (m_lexer->lookAhead(0) != ')') {
m_lexer->setIndex(index);
goto update_pos;
}
nextToken(); // skip ')'
int tk;
while ((tk = m_lexer->lookAhead(0)) == Token_const
|| tk == Token_override || tk == Token_final) {
int start = m_lexer->index();
nextToken();
AST::Node n = CreateNode<AST>();
UPDATE_POS(n, start, m_lexer->index());
if (tk == Token_const)
ast->setConstant(n);
else if (tk == Token_override)
ast->setOverride(n);
else
ast->setFinal(n);
}
GroupAST::Node except;
if (parseExceptionSpecification(except)) {
ast->setExceptionSpecification(except);
}
}
if (skipParen) {
if (m_lexer->lookAhead(0) != ')') {
reportError(i18n("')' expected"));
} else
nextToken();
}
}
update_pos:
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseAbstractDeclarator(DeclaratorAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
DeclaratorAST::Node ast = CreateNode<DeclaratorAST>();
DeclaratorAST::Node decl;
NameAST::Node declId;
AST::Node ptrOp;
while (parsePtrOperator(ptrOp)) {
ast->addPtrOp(ptrOp);
}
if (m_lexer->lookAhead(0) == '(') {
nextToken();
if (!parseAbstractDeclarator(decl)) {
return false;
}
ast->setSubDeclarator(decl);
if (m_lexer->lookAhead(0) != ')') {
return false;
}
nextToken();
}
{
while (m_lexer->lookAhead(0) == '[') {
int startArray = m_lexer->index();
nextToken();
AST::Node expr;
skipCommaExpression(expr);
ADVANCE(']', "]");
AST::Node array = CreateNode<AST>();
UPDATE_POS(array, startArray, m_lexer->index());
ast->addArrayDimension(array);
}
bool skipParen = false;
if (m_lexer->lookAhead(0) == Token_identifier && m_lexer->lookAhead(1) == '(' && m_lexer->lookAhead(2) == '(') {
nextToken();
nextToken();
skipParen = true;
}
int index = m_lexer->index();
if (m_lexer->lookAhead(0) == '(') {
nextToken();
ParameterDeclarationClauseAST::Node params;
if (!parseParameterDeclarationClause(params)) {
m_lexer->setIndex(index);
goto UPDATE_POS;
}
ast->setParameterDeclarationClause(params);
if (m_lexer->lookAhead(0) != ')') {
m_lexer->setIndex(index);
goto UPDATE_POS;
} else
nextToken();
int tk;
while ((tk = m_lexer->lookAhead(0)) == Token_const
|| tk == Token_override || tk == Token_final) {
int start = m_lexer->index();
nextToken();
AST::Node n = CreateNode<AST>();
UPDATE_POS(n, start, m_lexer->index());
if (tk == Token_const)
ast->setConstant(n);
else if (tk == Token_override)
ast->setOverride(n);
else
ast->setFinal(n);
}
GroupAST::Node except;
if (parseExceptionSpecification(except)) {
ast->setExceptionSpecification(except);
}
}
if (skipParen) {
if (m_lexer->lookAhead(0) != ')') {
reportError(i18n("')' expected"));
} else
nextToken();
}
}
UPDATE_POS:
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseEnumSpecifier(TypeSpecifierAST::Node& node)
{
PARSER_DEBUG_METHOD;
bool isClass = false;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != Token_enum) {
return false;
}
nextToken();
int tk = m_lexer->lookAhead(0);
if (tk == Token_class || tk == Token_struct) {
isClass = true;
nextToken();
}
Comment c = comment();
clearComment();
NameAST::Node name;
parseName(name);
TypeSpecifierAST::Node enumBase;
if (m_lexer->lookAhead(0) == ':') {
nextToken();
if (!parseSimpleTypeSpecifier(enumBase)) {
syntaxError();
return false;
}
}
tk = m_lexer->lookAhead(0);
if (tk != ';' && tk != '{') {
m_lexer->setIndex(start);
return false;
}
EnumSpecifierAST::Node ast = CreateNode<EnumSpecifierAST>();
ast->setClass(isClass);
ast->setName(name);
ast->setComment(c);
ast->setEnumBase(enumBase);
if (tk == '{') {
nextToken();
EnumeratorAST::Node enumerator;
if (parseEnumerator(enumerator)) {
ast->addEnumerator(enumerator);
while (m_lexer->lookAhead(0) == ',') {
nextToken();
if (!parseEnumerator(enumerator)) {
//reportError(i18n("Enumerator expected"));
break;
}
ast->addEnumerator(enumerator);
}
}
clearComment();
if (m_lexer->lookAhead(0) != '}')
reportError(i18n("} missing"));
else
nextToken();
}
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseTemplateParameterList(TemplateParameterListAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
TemplateParameterListAST::Node ast = CreateNode<TemplateParameterListAST>();
TemplateParameterAST::Node param;
if (!parseTemplateParameter(param)) {
return false;
}
ast->addTemplateParameter(param);
while (m_lexer->lookAhead(0) == ',') {
nextToken();
if (!parseTemplateParameter(param)) {
syntaxError();
break;
} else {
ast->addTemplateParameter(param);
}
}
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseTemplateParameter(TemplateParameterAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
TemplateParameterAST::Node ast = CreateNode<TemplateParameterAST>();
TypeParameterAST::Node typeParameter;
ParameterDeclarationAST::Node param;
int tk = m_lexer->lookAhead(0);
if ((tk == Token_class || tk == Token_typename || tk == Token_template) && parseTypeParameter(typeParameter)) {
ast->setTypeParameter(typeParameter);
goto ok;
}
if (!parseParameterDeclaration(param))
return false;
ast->setTypeValueParameter(param);
ok:
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseTypeParameter(TypeParameterAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
TypeParameterAST::Node ast = CreateNode<TypeParameterAST>();
AST_FROM_TOKEN(kind, m_lexer->index());
ast->setKind(kind);
switch (m_lexer->lookAhead(0)) {
case Token_class:
case Token_typename: {
nextToken(); // skip class
// parse optional name
NameAST::Node name;
if (parseName(name)) {
ast->setName(name);
if (m_lexer->lookAhead(0) == '=') {
nextToken();
AST::Node typeId;
if (!parseTypeId(typeId)) {
syntaxError();
return false;
}
ast->setTypeId(typeId);
}
}
}
break;
case Token_template: {
nextToken(); // skip template
ADVANCE('<', "<");
TemplateParameterListAST::Node params;
if (!parseTemplateParameterList(params)) {
return false;
}
ast->setTemplateParameterList(params);
ADVANCE('>', ">");
if (m_lexer->lookAhead(0) == Token_class)
nextToken();
// parse optional name
NameAST::Node name;
if (parseName(name)) {
ast->setName(name);
if (m_lexer->lookAhead(0) == '=') {
nextToken();
AST::Node typeId;
if (!parseTypeId(typeId)) {
syntaxError();
return false;
}
ast->setTypeId(typeId);
}
}
if (m_lexer->lookAhead(0) == '=') {
nextToken();
NameAST::Node templ_name;
parseName(templ_name);
}
}
break;
default:
return false;
} // end switch
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseStorageClassSpecifier(GroupAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
GroupAST::Node ast = CreateNode<GroupAST>();
while (!m_lexer->lookAhead(0).isNull()) {
int tk = m_lexer->lookAhead(0);
if (tk == Token_friend || tk == Token_auto || tk == Token_register || tk == Token_static ||
tk == Token_extern || tk == Token_mutable || tk == Token_const_expr ) {
int startNode = m_lexer->index();
nextToken();
AST::Node n = CreateNode<AST>();
UPDATE_POS(n, startNode, m_lexer->index());
ast->addNode(n);
} else
break;
}
if (ast->nodeList().count() == 0)
return false;
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseFunctionSpecifier(GroupAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
GroupAST::Node ast = CreateNode<GroupAST>();
while (!m_lexer->lookAhead(0).isNull()) {
int tk = m_lexer->lookAhead(0);
if (tk == Token_inline || tk == Token_virtual || tk == Token_explicit) {
int startNode = m_lexer->index();
nextToken();
AST::Node n = CreateNode<AST>();
UPDATE_POS(n, startNode, m_lexer->index());
ast->addNode(n);
} else {
break;
}
}
if (ast->nodeList().count() == 0)
return false;
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseTypeId(AST::Node& node)
{
PARSER_DEBUG_METHOD;
/// @todo implement the AST for typeId
int start = m_lexer->index();
AST::Node ast = CreateNode<AST>();
TypeSpecifierAST::Node spec;
if (!parseTypeSpecifier(spec)) {
return false;
}
DeclaratorAST::Node decl;
parseAbstractDeclarator(decl);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseInitDeclaratorList(InitDeclaratorListAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
InitDeclaratorListAST::Node ast = CreateNode<InitDeclaratorListAST>();
InitDeclaratorAST::Node decl;
if (!parseInitDeclarator(decl)) {
return false;
}
ast->addInitDeclarator(decl);
while (m_lexer->lookAhead(0) == ',') {
nextToken();
if (!parseInitDeclarator(decl)) {
syntaxError();
break;
}
ast->addInitDeclarator(decl);
}
PARSER_DEBUG_METHOD;
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseParameterDeclarationClause(ParameterDeclarationClauseAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
ParameterDeclarationClauseAST::Node ast = CreateNode<ParameterDeclarationClauseAST>();
ParameterDeclarationListAST::Node params;
if (!parseParameterDeclarationList(params)) {
if (m_lexer->lookAhead(0) == ')')
goto good;
if (m_lexer->lookAhead(0) == Token_ellipsis && m_lexer->lookAhead(1) == ')') {
AST_FROM_TOKEN(ellipsis, m_lexer->index());
ast->setEllipsis(ellipsis);
nextToken();
goto good;
}
return false;
}
if (m_lexer->lookAhead(0) == Token_ellipsis) {
AST_FROM_TOKEN(ellipsis, m_lexer->index());
ast->setEllipsis(ellipsis);
nextToken();
}
good:
ast->setParameterDeclarationList(params);
/// @todo add ellipsis
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
void Parser::nextToken(bool skipComm)
{
m_lexer->nextToken();
if (skipComm) {
if (m_lexer->lookAhead(0) == Token_comment) {
processComment();
nextToken();
}
}
}
Comment Parser::comment()
{
return m_commentStore.latestComment();
}
void Parser::preparseLineComments(int l)
{
for (int a = 0; a < 40; a++) {
if (m_lexer->lookAhead(a).isNull()) break;
int line, col;
m_lexer->lookAhead(a).getStartPosition(&line, &col);
if (line < l) {
continue;
} else if (line == l) {
if (m_lexer->lookAhead(a) == Token_comment) {
processComment(a);
}
} else {
break;
}
}
}
void Parser::processComment(int offset)
{
int line, col;
m_lexer->lookAhead(offset).getStartPosition(&line, &col);
m_commentStore.addComment(Comment(m_lexer->lookAhead(offset).text(), line));
}
template<class Type>
void Parser::eventuallyTakeComment(int startLn, int endLn, Type& ast)
{
if (comment().line() >= startLn && comment().line() <= endLn) {
if (ast.get()) {
if (comment()) {
ast->setComment(comment());
}
}
clearComment();
}
}
template<class Type>
void Parser::eventuallyTakeComment(Type& ast)
{
int line = currentLine();
Comment c = m_commentStore.getCommentsInRange(line, true);
if (ast.get() && c) {
ast->setComment(c);
}
}
void Parser::clearComment()
{
m_commentStore.clear();
}
int Parser::currentLine()
{
int ln, col;
m_lexer->lookAhead(0).getStartPosition(&ln, &col);
return ln;
}
bool Parser::parseParameterDeclarationList(ParameterDeclarationListAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
ParameterDeclarationListAST::Node ast = CreateNode<ParameterDeclarationListAST>();
ParameterDeclarationAST::Node param;
if (!parseParameterDeclaration(param)) {
m_lexer->setIndex(start);
return false;
}
ast->addParameter(param);
while (m_lexer->lookAhead(0) == ',') {
nextToken();
if (m_lexer->lookAhead(0) == Token_ellipsis)
break;
if (!parseParameterDeclaration(param)) {
m_lexer->setIndex(start);
return false;
}
ast->addParameter(param);
}
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseParameterDeclaration(ParameterDeclarationAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
// parse decl spec
TypeSpecifierAST::Node spec;
if (!parseTypeSpecifier(spec)) {
m_lexer->setIndex(start);
return false;
}
int index = m_lexer->index();
DeclaratorAST::Node decl;
if (!parseDeclarator(decl)) {
m_lexer->setIndex(index);
// try with abstract declarator
if (!parseAbstractDeclarator(decl))
return false;
}
AST::Node expr;
if (m_lexer->lookAhead(0) == '=') {
nextToken();
if (!parseLogicalOrExpression(expr,true)) {
//reportError(i18n("Expression expected"));
}
}
ParameterDeclarationAST::Node ast = CreateNode<ParameterDeclarationAST>();
ast->setTypeSpec(spec);
ast->setDeclarator(decl);
ast->setExpression(expr);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseClassSpecifier(TypeSpecifierAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
AST::Node classKey;
int classKeyStart = m_lexer->index();
int kind = m_lexer->lookAhead(0);
if (kind == Token_class || kind == Token_struct || kind == Token_union) {
AST::Node asn = CreateNode<AST>();
classKey = std::move(asn);
nextToken();
UPDATE_POS(classKey, classKeyStart, m_lexer->index());
} else {
return false;
}
GroupAST::Node winDeclSpec;
parseWinDeclSpec(winDeclSpec);
while (m_lexer->lookAhead(0) == Token_identifier && m_lexer->lookAhead(1) == Token_identifier)
nextToken();
NameAST::Node name;
parseName(name);
AST::Node final_;
int finalStart = m_lexer->index();
if (m_lexer->lookAhead(0) == Token_final) {
final_ = std::move(CreateNode<AST>());
nextToken();
UPDATE_POS(final_, finalStart, m_lexer->index());
}
BaseClauseAST::Node bases;
if (m_lexer->lookAhead(0) == ':') {
if (!parseBaseClause(bases)) {
skipUntil('{');
}
}
if (m_lexer->lookAhead(0) != '{') {
m_lexer->setIndex(start);
return false;
}
ClassSpecifierAST::Node ast = CreateNode<ClassSpecifierAST>();
eventuallyTakeComment(ast);
ADVANCE('{', "{");
ast->setWinDeclSpec(winDeclSpec);
ast->setClassKey(classKey);
ast->setName(name);
ast->setBaseClause(bases);
ast->setFinal(final_);
while (!m_lexer->lookAhead(0).isNull()) {
if (m_lexer->lookAhead(0) == '}')
break;
DeclarationAST::Node memSpec;
int startDecl = m_lexer->index();
if (!parseMemberSpecification(memSpec)) {
if (startDecl == m_lexer->index())
nextToken(); // skip at least one token
skipUntilDeclaration();
} else
ast->addDeclaration(memSpec);
}
clearComment();
if (m_lexer->lookAhead(0) != '}') {
reportError(i18n("} missing"));
} else
nextToken();
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseAccessSpecifier(AST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
switch (m_lexer->lookAhead(0)) {
case Token_public:
case Token_protected:
case Token_private: {
AST::Node asn = CreateNode<AST>();
node = std::move(asn);
nextToken();
UPDATE_POS(node, start, m_lexer->index());
return true;
}
}
return false;
}
bool Parser::parseMemberSpecification(DeclarationAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
AST::Node access;
if (m_lexer->lookAhead(0) == ';') {
nextToken();
return true;
} else if (m_lexer->lookAhead(0) == Token_Q_OBJECT || m_lexer->lookAhead(0) == Token_K_DCOP) {
nextToken();
return true;
} else if (m_lexer->lookAhead(0) == Token_signals || m_lexer->lookAhead(0) == Token_k_dcop || m_lexer->lookAhead(0) == Token_k_dcop_signals) {
AccessDeclarationAST::Node ast = CreateNode<AccessDeclarationAST>();
nextToken();
AST::Node n = CreateNode<AST>();
UPDATE_POS(n, start, m_lexer->index());
ast->addAccess(n);
ADVANCE(':', ":");
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
} else if (parseTypedef(node)) {
return true;
} else if (parseUsing(node)) {
return true;
} else if (parseTemplateDeclaration(node)) {
return true;
} else if (parseAccessSpecifier(access)) {
AccessDeclarationAST::Node ast = CreateNode<AccessDeclarationAST>();
ast->addAccess(access);
int startSlot = m_lexer->index();
if (m_lexer->lookAhead(0) == Token_slots) {
nextToken();
AST::Node sl = CreateNode<AST>();
UPDATE_POS(sl, startSlot, m_lexer->index());
ast->addAccess(sl);
}
ADVANCE(':', ":");
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
m_lexer->setIndex(start);
GroupAST::Node storageSpec;
parseStorageClassSpecifier(storageSpec);
GroupAST::Node cv;
parseCvQualify(cv);
TypeSpecifierAST::Node spec;
if (parseEnumSpecifier(spec) || parseClassSpecifier(spec)) {
spec->setCvQualify(cv);
GroupAST::Node cv2;
parseCvQualify(cv2);
spec->setCv2Qualify(cv2);
InitDeclaratorListAST::Node declarators;
parseInitDeclaratorList(declarators);
ADVANCE(';', ";");
SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
ast->setTypeSpec(spec);
ast->setInitDeclaratorList(declarators);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
m_lexer->setIndex(start);
return parseDeclarationInternal(node);
}
bool Parser::parseCtorInitializer(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
if (m_lexer->lookAhead(0) != ':') {
return false;
}
nextToken();
AST::Node inits;
if (!parseMemInitializerList(inits)) {
reportError(i18n("Member initializers expected"));
}
return true;
}
bool Parser::parseElaboratedTypeSpecifier(TypeSpecifierAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
int tk = m_lexer->lookAhead(0);
if (tk == Token_class ||
tk == Token_struct ||
tk == Token_union ||
tk == Token_enum ||
tk == Token_typename) {
AST::Node kind = CreateNode<AST>();
nextToken();
UPDATE_POS(kind, start, m_lexer->index());
NameAST::Node name;
if (parseName(name)) {
ElaboratedTypeSpecifierAST::Node ast = CreateNode<ElaboratedTypeSpecifierAST>();
ast->setKind(kind);
ast->setName(name);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
}
m_lexer->setIndex(start);
return false;
}
bool Parser::parseDeclaratorId(NameAST::Node& node)
{
PARSER_DEBUG_METHOD;
return parseName(node);
}
bool Parser::parseExceptionSpecification(GroupAST::Node& node)
{
PARSER_DEBUG_METHOD;
if (m_lexer->lookAhead(0) == Token_noexcept) {
GroupAST::Node ast = CreateNode<GroupAST>();
int start = m_lexer->index();
nextToken();
AST::Node word = CreateNode<AST>();
UPDATE_POS(word, start, m_lexer->index());
ast->addNode(word);
node = std::move(ast);
return true;
}
if (m_lexer->lookAhead(0) != Token_throw) {
return false;
}
nextToken();
ADVANCE('(', "(");
if (m_lexer->lookAhead(0) == Token_ellipsis) {
// extension found in MSVC++ 7.x headers
int start = m_lexer->index();
GroupAST::Node ast = CreateNode<GroupAST>();
AST_FROM_TOKEN(ellipsis, m_lexer->index());
ast->addNode(ellipsis);
nextToken();
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
} else if (m_lexer->lookAhead(0) == ')') {
node = CreateNode<GroupAST>();
} else {
parseTypeIdList(node);
}
ADVANCE(')', ")");
return true;
}
bool Parser::parseEnumerator(EnumeratorAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != Token_identifier) {
return false;
}
nextToken();
EnumeratorAST::Node ena = CreateNode<EnumeratorAST>();
node = std::move(ena);
AST::Node id = CreateNode<AST>();
UPDATE_POS(id, start, m_lexer->index());
node->setId(id);
int line = currentLine();
if (m_lexer->lookAhead(0) == '=') {
nextToken();
AST::Node expr;
line = currentLine();
if (!parseConstantExpression(expr)) {
reportError(i18n("Constant expression expected"));
}
node->setExpr(expr);
}
UPDATE_POS(node, start, m_lexer->index());
preparseLineComments(line);
node->setComment(m_commentStore.getCommentInRange(line));
return true;
}
bool Parser::parseInitDeclarator(InitDeclaratorAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
DeclaratorAST::Node decl;
AST::Node init;
if (!parseDeclarator(decl)) {
return false;
}
parseInitializer(init);
InitDeclaratorAST::Node ast = CreateNode<InitDeclaratorAST>();
ast->setDeclarator(decl);
ast->setInitializer(init);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseBaseClause(BaseClauseAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != ':') {
return false;
}
nextToken();
BaseClauseAST::Node bca = CreateNode<BaseClauseAST>();
BaseSpecifierAST::Node baseSpec;
if (parseBaseSpecifier(baseSpec)) {
bca->addBaseSpecifier(baseSpec);
while (m_lexer->lookAhead(0) == ',') {
nextToken();
if (!parseBaseSpecifier(baseSpec)) {
reportError(i18n("Base class specifier expected"));
return false;
}
bca->addBaseSpecifier(baseSpec);
}
} else
return false;
UPDATE_POS(bca, start, m_lexer->index());
node = std::move(bca);
return true;
}
bool Parser::parseInitializer(AST::Node& node)
{
PARSER_DEBUG_METHOD;
if (m_lexer->lookAhead(0) == '=') {
nextToken();
AST::Node init;
if (!parseInitializerClause(node)) {
reportError(i18n("Initializer clause expected"));
return false;
}
} else if (m_lexer->lookAhead(0) == '(') {
nextToken();
AST::Node expr;
skipCommaExpression(expr);
ADVANCE(')', ")");
}
return false;
}
bool Parser::parseMemInitializerList(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
AST::Node init;
if (!parseMemInitializer(init)) {
return false;
}
while (m_lexer->lookAhead(0) == ',') {
nextToken();
if (parseMemInitializer(init)) {
} else {
break;
}
}
return true;
}
bool Parser::parseMemInitializer(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
NameAST::Node initId;
if (!parseMemInitializerId(initId)) {
reportError(i18n("Identifier expected"));
return false;
}
Token token = m_lexer->lookAhead(0);
if (token != '(' && token != '{') {
reportError(i18n("'(' or '{' expected, found '%1'").arg(token.text()));
return false;
}
nextToken();
AST::Node expr;
skipCommaExpression(expr);
token = m_lexer->lookAhead(0);
if (token != ')' && token != '}') {
reportError(i18n("')' or '}' expected, found '%1'").arg(token.text()));
return false;
}
nextToken();
return true;
}
bool Parser::parseTypeIdList(GroupAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
AST::Node typeId;
if (!parseTypeId(typeId)) {
return false;
}
GroupAST::Node ast = CreateNode<GroupAST>();
ast->addNode(typeId);
while (m_lexer->lookAhead(0) == ',') {
nextToken();
if (parseTypeId(typeId)) {
ast->addNode(typeId);
} else {
reportError(i18n("Type id expected"));
break;
}
}
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseBaseSpecifier(BaseSpecifierAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
BaseSpecifierAST::Node ast = CreateNode<BaseSpecifierAST>();
AST::Node access;
if (m_lexer->lookAhead(0) == Token_virtual) {
AST_FROM_TOKEN(virt, m_lexer->index());
ast->setIsVirtual(virt);
nextToken();
parseAccessSpecifier(access);
} else {
parseAccessSpecifier(access);
if (m_lexer->lookAhead(0) == Token_virtual) {
AST_FROM_TOKEN(virt, m_lexer->index());
ast->setIsVirtual(virt);
nextToken();
}
}
NameAST::Node name;
if (!parseName(name)) {
reportError(i18n("Class name expected"));
}
ast->setAccess(access);
ast->setName(name);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseInitializerClause(AST::Node& node)
{
PARSER_DEBUG_METHOD;
if (m_lexer->lookAhead(0) == '{') {
if (!skip('{','}')) {
reportError(i18n("} missing"));
} else {
clearComment();
nextToken();
}
} else {
if (!parseAssignmentExpression(node)) {
//reportError(i18n("Expression expected"));
}
}
return true;
}
bool Parser::parseMemInitializerId(NameAST::Node& node)
{
PARSER_DEBUG_METHOD;
return parseName(node);
}
bool Parser::parsePtrToMember(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
if (m_lexer->lookAhead(0) == Token_scope) {
nextToken();
}
while (m_lexer->lookAhead(0) == Token_identifier) {
nextToken();
if (m_lexer->lookAhead(0) == Token_scope && m_lexer->lookAhead(1) == '*') {
nextToken(); // skip ::
nextToken(); // skip *
return true;
} else
break;
}
return false;
}
bool Parser::parseUnqualifiedName(ClassOrNamespaceNameAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
bool isDestructor = false;
ClassOrNamespaceNameAST::Node ast = CreateNode<ClassOrNamespaceNameAST>();
if (m_lexer->lookAhead(0) == Token_identifier) {
int startName = m_lexer->index();
AST::Node n = CreateNode<AST>();
nextToken();
UPDATE_POS(n, startName, m_lexer->index());
ast->setName(n);
} else if (m_lexer->lookAhead(0) == '~' && m_lexer->lookAhead(1) == Token_identifier) {
int startName = m_lexer->index();
AST::Node n = CreateNode<AST>();
nextToken(); // skip ~
nextToken(); // skip classname
UPDATE_POS(n, startName, m_lexer->index());
ast->setName(n);
isDestructor = true;
} else if (m_lexer->lookAhead(0) == Token_operator) {
AST::Node n;
if (!parseOperatorFunctionId(n))
return false;
ast->setName(n);
} else {
return false;
}
if (!isDestructor) {
int index = m_lexer->index();
if (m_lexer->lookAhead(0) == '<') {
nextToken();
// optional template arguments
TemplateArgumentListAST::Node args;
parseTemplateArgumentList(args);
if (m_lexer->lookAhead(0) != '>') {
m_lexer->setIndex(index);
} else {
nextToken();
ast->setTemplateArgumentList(args);
}
}
}
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseStringLiteral(AST::Node& /*node*/)
{
while (!m_lexer->lookAhead(0).isNull()) {
if (m_lexer->lookAhead(0) == Token_identifier &&
m_lexer->lookAhead(0).text() == QLatin1String("L") &&
m_lexer->lookAhead(1) == Token_string_literal) {
nextToken();
nextToken();
} else if (m_lexer->lookAhead(0) == Token_string_literal) {
nextToken();
} else
return false;
}
return true;
}
bool Parser::skipExpressionStatement(StatementAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
AST::Node expr;
skipCommaExpression(expr);
ADVANCE(';', ";");
ExpressionStatementAST::Node ast = CreateNode<ExpressionStatementAST>();
ast->setExpression(expr);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseStatement(StatementAST::Node& node) // thanks to fiore@8080.it ;)
{
PARSER_DEBUG_METHOD;
switch (m_lexer->lookAhead(0)) {
case Token_while:
return parseWhileStatement(node);
case Token_do:
return parseDoStatement(node);
case Token_for:
return parseForStatement(node);
case Token_foreach:
return parseForEachStatement(node);
case Token_if:
return parseIfStatement(node);
case Token_switch:
return parseSwitchStatement(node);
case Token_try:
return parseTryBlockStatement(node);
case Token_case:
case Token_default:
return parseLabeledStatement(node);
case Token_break:
case Token_continue:
nextToken();
ADVANCE(';', ";");
return true;
case Token_goto:
nextToken();
ADVANCE(Token_identifier, "identifier");
ADVANCE(';', ";");
return true;
case Token_return: {
nextToken();
AST::Node expr;
skipCommaExpression(expr);
ADVANCE(';', ";");
}
return true;
case '{':
return parseCompoundStatement(node);
case Token_identifier:
if (parseLabeledStatement(node))
return true;
break;
}
PARSER_DEBUG_METHOD;
if (parseDeclarationStatement(node))
return true;
return skipExpressionStatement(node);
}
bool Parser::parseCondition(ConditionAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
ConditionAST::Node ast = CreateNode<ConditionAST>();
TypeSpecifierAST::Node spec;
if (parseTypeSpecifier(spec)) {
DeclaratorAST::Node decl;
if (parseDeclarator(decl)) {
if (m_lexer->lookAhead(0) == '=') {
nextToken();
AST::Node expr;
if (skipExpression(expr)) {
ast->setTypeSpec(spec);
ast->setDeclarator(decl);
ast->setExpression(expr);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
} else {
ast->setTypeSpec(spec);
ast->setDeclarator(decl);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
}
}
m_lexer->setIndex(start);
AST::Node expr;
if (!skipCommaExpression(expr))
return false;
ast->setExpression(expr);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseWhileStatement(StatementAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
ADVANCE(Token_while, "while");
ADVANCE('(' , "(");
ConditionAST::Node cond;
if (!parseCondition(cond)) {
reportError(i18n("condition expected"));
return false;
}
ADVANCE(')', ")");
StatementAST::Node body;
if (!parseStatement(body)) {
reportError(i18n("statement expected"));
}
WhileStatementAST::Node ast = CreateNode<WhileStatementAST>();
ast->setCondition(cond);
ast->setStatement(body);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseDoStatement(StatementAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
ADVANCE(Token_do, "do");
StatementAST::Node body;
if (!parseStatement(body)) {
reportError(i18n("statement expected"));
//return false;
}
ADVANCE_NR(Token_while, "while");
ADVANCE_NR('(' , "(");
AST::Node expr;
if (!skipCommaExpression(expr)) {
reportError(i18n("expression expected"));
//return false;
}
ADVANCE_NR(')', ")");
ADVANCE_NR(';', ";");
DoStatementAST::Node ast = CreateNode<DoStatementAST>();
ast->setStatement(body);
//ast->setCondition(condition);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseForStatement(StatementAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
ADVANCE(Token_for, "for");
ADVANCE('(', "(");
StatementAST::Node init;
if (!parseForInitStatement(init)) {
reportError(i18n("for initialization expected"));
return false;
}
ConditionAST::Node cond;
parseCondition(cond);
ADVANCE(';', ";");
AST::Node expr;
skipCommaExpression(expr);
ADVANCE(')', ")");
StatementAST::Node body;
if (!parseStatement(body)) {
reportError(i18n("statement expected"));
}
ForStatementAST::Node ast = CreateNode<ForStatementAST>();
ast->setInitStatement(init);
ast->setCondition(cond);
// ast->setExpression(expression);
ast->setStatement(body);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
// qt4 [erbsland]
///@todo add the right parsing for the foreach statement
bool Parser::parseForEachStatement(StatementAST::Node& node)
{
int start = m_lexer->index();
ADVANCE(Token_foreach, "foreach");
ADVANCE('(', "(");
AST::Node expr;
// replace with the right parsing
skipCommaExpression(expr);
ADVANCE(')', ")");
StatementAST::Node body;
if (!parseStatement(body)) {
reportError(i18n("statement expected"));
}
ForEachStatementAST::Node ast = CreateNode<ForEachStatementAST>();
// add here the parser results
ast->setStatement(body);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseForInitStatement(StatementAST::Node& node)
{
PARSER_DEBUG_METHOD;
if (parseDeclarationStatement(node))
return true;
return skipExpressionStatement(node);
}
bool Parser::parseCompoundStatement(StatementAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != '{') {
return false;
}
nextToken();
StatementListAST::Node ast = CreateNode<StatementListAST>();
while (!m_lexer->lookAhead(0).isNull()) {
if (m_lexer->lookAhead(0) == '}')
break;
StatementAST::Node stmt;
int startStmt = m_lexer->index();
if (!parseStatement(stmt)) {
if (startStmt == m_lexer->index())
nextToken();
skipUntilStatement();
} else {
ast->addStatement(stmt);
}
}
clearComment();
if (m_lexer->lookAhead(0) != '}') {
reportError(i18n("} expected"));
} else {
nextToken();
}
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseIfStatement(StatementAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
ADVANCE(Token_if, "if");
ADVANCE('(' , "(");
IfStatementAST::Node ast = CreateNode<IfStatementAST>();
ConditionAST::Node cond;
if (!parseCondition(cond)) {
reportError(i18n("condition expected"));
return false;
}
ADVANCE(')', ")");
StatementAST::Node stmt;
if (!parseStatement(stmt)) {
reportError(i18n("statement expected"));
}
ast->setCondition(cond);
ast->setStatement(stmt);
if (m_lexer->lookAhead(0) == Token_else) {
nextToken();
StatementAST::Node elseStmt;
if (!parseStatement(elseStmt)) {
reportError(i18n("statement expected"));
}
ast->setElseStatement(elseStmt);
}
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseSwitchStatement(StatementAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
ADVANCE(Token_switch, "switch");
ADVANCE('(' , "(");
ConditionAST::Node cond;
if (!parseCondition(cond)) {
reportError(i18n("condition expected"));
return false;
}
ADVANCE(')', ")");
StatementAST::Node stmt;
if (!parseCompoundStatement(stmt)) {
syntaxError();
return false;
}
SwitchStatementAST::Node ast = CreateNode<SwitchStatementAST>();
ast->setCondition(cond);
ast->setStatement(stmt);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseLabeledStatement(StatementAST::Node& node)
{
PARSER_DEBUG_METHOD;
switch (m_lexer->lookAhead(0)) {
case Token_identifier:
case Token_default:
if (m_lexer->lookAhead(1) == ':') {
nextToken();
nextToken();
StatementAST::Node stmt;
if (parseStatement(stmt)) {
node = std::move(stmt);
return true;
}
}
break;
case Token_case: {
nextToken();
AST::Node expr;
if (!parseConstantExpression(expr)) {
reportError(i18n("expression expected"));
} else if (m_lexer->lookAhead(0) == Token_ellipsis) {
nextToken();
AST::Node expr2;
if (!parseConstantExpression(expr2)) {
reportError(i18n("expression expected"));
}
}
ADVANCE(':', ":");
StatementAST::Node stmt;
if (parseStatement(stmt)) {
node = std::move(stmt);
return true;
}
}
break;
}
return false;
}
bool Parser::parseBlockDeclaration(DeclarationAST::Node& node)
{
PARSER_DEBUG_METHOD;
switch (m_lexer->lookAhead(0)) {
case Token_typedef:
return parseTypedef(node);
case Token_using:
return parseUsing(node);
case Token_asm:
return parseAsmDefinition(node);
case Token_namespace:
return parseNamespaceAliasDefinition(node);
}
int start = m_lexer->index();
GroupAST::Node storageSpec;
parseStorageClassSpecifier(storageSpec);
GroupAST::Node cv;
parseCvQualify(cv);
TypeSpecifierAST::Node spec;
if (!parseTypeSpecifierOrClassSpec(spec)) { // replace with simpleTypeSpecifier?!?!
m_lexer->setIndex(start);
return false;
}
spec->setCvQualify(cv);
GroupAST::Node cv2;
parseCvQualify(cv2);
spec->setCv2Qualify(cv2);
InitDeclaratorListAST::Node declarators;
parseInitDeclaratorList(declarators);
if (m_lexer->lookAhead(0) != ';') {
m_lexer->setIndex(start);
return false;
}
nextToken();
SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
ast->setTypeSpec(spec);
ast->setInitDeclaratorList(declarators);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseNamespaceAliasDefinition(DeclarationAST::Node& /*node*/)
{
if (m_lexer->lookAhead(0) != Token_namespace) {
return false;
}
nextToken();
ADVANCE(Token_identifier, "identifier");
ADVANCE('=', "=");
NameAST::Node name;
if (!parseName(name)) {
reportError(i18n("Namespace name expected"));
}
ADVANCE(';', ";");
return true;
}
bool Parser::parseDeclarationStatement(StatementAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
DeclarationAST::Node decl;
if (!parseBlockDeclaration(decl)) {
return false;
}
DeclarationStatementAST::Node ast = CreateNode<DeclarationStatementAST>();
ast->setDeclaration(decl);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
PARSER_DEBUG_METHOD;
return true;
}
bool Parser::parseDeclarationInternal(DeclarationAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
// that is for the case '__declspec(dllexport) int ...' or
// '__declspec(dllexport) inline int ...', etc.
GroupAST::Node winDeclSpec;
parseWinDeclSpec(winDeclSpec);
GroupAST::Node funSpec;
bool hasFunSpec = parseFunctionSpecifier(funSpec);
GroupAST::Node storageSpec;
bool hasStorageSpec = parseStorageClassSpecifier(storageSpec);
if (hasStorageSpec && !hasFunSpec)
hasFunSpec = parseFunctionSpecifier(funSpec);
// that is for the case 'friend __declspec(dllexport) ....'
GroupAST::Node winDeclSpec2;
parseWinDeclSpec(winDeclSpec2);
GroupAST::Node cv;
parseCvQualify(cv);
int index = m_lexer->index();
NameAST::Node name;
if (parseName(name) && m_lexer->lookAhead(0) == '(') {
// no type specifier, maybe a constructor or a cast operator??
m_lexer->setIndex(index);
InitDeclaratorAST::Node declarator;
if (parseInitDeclarator(declarator)) {
int endSignature = m_lexer->index();
Comment mcomment;
if (declarator.get()) {
int endLine, endColumn;
declarator->getEndPosition(&endLine, &endColumn);
mcomment = m_commentStore.getCommentsInRange(endLine);
}
else {
mcomment = comment();
}
clearComment();
switch (m_lexer->lookAhead(0)) {
case ';': {
nextToken();
InitDeclaratorListAST::Node declarators = CreateNode<InitDeclaratorListAST>();
SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
// update declarators position
int startLine, startColumn, endLine, endColumn;
if (declarator.get()) {
declarator->getStartPosition(&startLine, &startColumn);
declarator->getEndPosition(&endLine, &endColumn);
declarators->setStartPosition(startLine, startColumn);
declarators->setEndPosition(endLine, endColumn);
ast->setComment(mcomment);
preparseLineComments(endLine);
Comment c = m_commentStore.getCommentInRange(endLine);
if (c) {
ast->addComment(c);
}
}
declarators->addInitDeclarator(declarator);
ast->setInitDeclaratorList(declarators);
if (hasFunSpec)
ast->setFunctionSpecifier(funSpec);
ast->setText(toString(start, endSignature));
node = std::move(ast);
UPDATE_POS(node, start, m_lexer->index());
return true;
}
break;
case ':': {
AST::Node ctorInit;
StatementListAST::Node funBody;
if (parseCtorInitializer(ctorInit) && parseFunctionBody(funBody)) {
FunctionDefinitionAST::Node ast = CreateNode<FunctionDefinitionAST>();
ast->setStorageSpecifier(storageSpec);
ast->setFunctionSpecifier(funSpec);
ast->setInitDeclarator(declarator);
ast->setFunctionBody(funBody);
ast->setText(toString(start, endSignature));
node = std::move(ast);
UPDATE_POS(node, start, m_lexer->index());
return true;
}
}
break;
case '{': {
StatementListAST::Node funBody;
if (parseFunctionBody(funBody)) {
FunctionDefinitionAST::Node ast = CreateNode<FunctionDefinitionAST>();
ast->setStorageSpecifier(storageSpec);
ast->setFunctionSpecifier(funSpec);
ast->setInitDeclarator(declarator);
ast->setText(toString(start, endSignature));
ast->setFunctionBody(funBody);
node = std::move(ast);
UPDATE_POS(node, start, m_lexer->index());
return true;
}
}
break;
case '(':
case '[':
// ops!! it seems a declarator
goto start_decl;
break;
}
}
syntaxError();
return false;
}
start_decl:
m_lexer->setIndex(index);
if (m_lexer->lookAhead(0) == Token_const && m_lexer->lookAhead(1) == Token_identifier && m_lexer->lookAhead(2) == '=') {
// constant definition
nextToken();
InitDeclaratorListAST::Node declarators;
if (parseInitDeclaratorList(declarators)) {
ADVANCE(';', ";");
DeclarationAST::Node ast = CreateNode<DeclarationAST>();
node = std::move(ast);
UPDATE_POS(node, start, m_lexer->index());
return true;
}
syntaxError();
return false;
}
TypeSpecifierAST::Node spec;
if (parseTypeSpecifier(spec)) {
if (!hasFunSpec)
parseFunctionSpecifier(funSpec); // e.g. "void inline"
spec->setCvQualify(cv);
InitDeclaratorListAST::Node declarators;
InitDeclaratorAST::Node decl;
int startDeclarator = m_lexer->index();
bool maybeFunctionDefinition = false;
if (m_lexer->lookAhead(0) != ';') {
if (parseInitDeclarator(decl) && m_lexer->lookAhead(0) == '{') {
// function definition
maybeFunctionDefinition = true;
} else {
m_lexer->setIndex(startDeclarator);
if (!parseInitDeclaratorList(declarators)) {
syntaxError();
return false;
}
}
}
Comment mcomment;
if (decl.get()) {
int line, col;
decl->getEndPosition(&line, &col);
mcomment = m_commentStore.getCommentsInRange(line);
}
else {
mcomment = comment();
}
clearComment();
int endSignature = m_lexer->index();
switch (m_lexer->lookAhead(0)) {
case ';': {
nextToken();
SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
int line, col;
ast->setComment(mcomment);
if (decl.get()) {
decl->getEndPosition(&line, &col);
preparseLineComments(line);
Comment c = m_commentStore.getCommentInRange(line);
if (c) {
ast->addComment(c);
}
}
ast->setStorageSpecifier(storageSpec);
ast->setFunctionSpecifier(funSpec);
ast->setText(toString(start, endSignature));
ast->setTypeSpec(spec);
ast->setWinDeclSpec(winDeclSpec);
ast->setInitDeclaratorList(declarators);
node = std::move(ast);
UPDATE_POS(node, start, m_lexer->index());
}
return true;
case '{': {
if (!maybeFunctionDefinition) {
syntaxError();
return false;
}
StatementListAST::Node funBody;
if (parseFunctionBody(funBody)) {
FunctionDefinitionAST::Node ast = CreateNode<FunctionDefinitionAST>();
ast->setComment(mcomment);
if (decl.get()) {
int line, col;
decl->getEndPosition(&line, &col);
preparseLineComments(line);
Comment c = m_commentStore.getCommentInRange(line);
if (c) {
ast->addComment(c);
}
}
ast->setWinDeclSpec(winDeclSpec);
ast->setStorageSpecifier(storageSpec);
ast->setFunctionSpecifier(funSpec);
ast->setText(toString(start, endSignature));
ast->setTypeSpec(spec);
ast->setFunctionBody(funBody);
ast->setInitDeclarator(decl);
node = std::move(ast);
UPDATE_POS(node, start, m_lexer->index());
return true;
}
}
break;
}
}
syntaxError();
return false;
}
bool Parser::parseFunctionBody(StatementListAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != '{') {
return false;
}
skip('{', '}'); // Using this instead of the #if 0 block below.
nextToken();
StatementListAST::Node ast = CreateNode<StatementListAST>();
#if 0
/* For Umbrello we do not require function body statement representations */
while (!m_lexer->lookAhead(0).isNull()) {
if (m_lexer->lookAhead(0) == '}')
break;
StatementAST::Node stmt;
int startStmt = m_lexer->index();
if (!parseStatement(stmt)) {
if (startStmt == m_lexer->index())
nextToken();
skipUntilStatement();
} else
ast->addStatement(stmt);
}
clearComment();
if (m_lexer->lookAhead(0) != '}') {
reportError(i18n("} expected"));
} else
nextToken();
#endif
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
QString Parser::toString(int start, int end, const QString& sep) const
{
QStringList l;
for (int i=start; i<end; ++i) {
const Token& t = m_lexer->tokenAt(i);
if (t != Token_comment)
l << t.text();
}
return l.join(sep).trimmed();
}
bool Parser::parseTypeSpecifierOrClassSpec(TypeSpecifierAST::Node& node)
{
if (parseClassSpecifier(node))
return true;
else if (parseEnumSpecifier(node))
return true;
else if (parseTypeSpecifier(node))
return true;
return false;
}
bool Parser::parseTryBlockStatement(StatementAST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != Token_try) {
return false;
}
nextToken();
StatementAST::Node stmt;
if (!parseCompoundStatement(stmt)) {
syntaxError();
}
if (m_lexer->lookAhead(0) != Token_catch) {
reportError(i18n("catch expected"));
}
CatchStatementListAST::Node list = CreateNode<CatchStatementListAST>();
while (m_lexer->lookAhead(0) == Token_catch) {
nextToken();
ADVANCE('(', "(");
ConditionAST::Node cond;
if (!parseCondition(cond)) {
reportError(i18n("condition expected"));
return false;
}
ADVANCE(')', ")");
StatementAST::Node body;
if (!parseCompoundStatement(body)) {
syntaxError();
}
CatchStatementAST::Node cstmt = CreateNode<CatchStatementAST>();
cstmt->setCondition(cond);
cstmt->setStatement(body);
int l=0, c=0;
if (cond.get())
cond->getStartPosition(&l, &c);
else if (body.get())
body->getStartPosition(&l, &c);
cstmt->setStartPosition(l, c);
if (body.get())
body->getEndPosition(&l, &c);
cstmt->setEndPosition(l, c);
list->addStatement(cstmt);
}
TryBlockStatementAST::Node ast = CreateNode<TryBlockStatementAST>();
ast->setStatement(stmt);
ast->setCatchStatementList(list);
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parsePrimaryExpression(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
switch (m_lexer->lookAhead(0)) {
case Token_string_literal: {
AST::Node lit;
parseStringLiteral(lit);
}
return true;
case Token_number_literal:
case Token_char_literal:
case Token_true:
case Token_false:
case Token_default:
nextToken();
return true;
case Token_this:
nextToken();
return true;
case Token_dynamic_cast:
case Token_static_cast:
case Token_reinterpret_cast:
case Token_const_cast: {
nextToken();
CHECK('<', "<");
AST::Node typeId;
parseTypeId(typeId);
CHECK('>', ">");
CHECK('(', "(");
AST::Node expr;
parseCommaExpression(expr);
CHECK(')', ")");
}
return true;
case Token_typeid: {
nextToken();
CHECK('(', "(");
AST::Node expr;
parseCommaExpression(expr);
CHECK(')', ")");
}
return true;
case '(': {
nextToken();
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parseExpression(expr)) {
return false;
}
CHECK(')', ")");
}
return true;
default: {
int start = m_lexer->index();
TypeSpecifierAST::Node typeSpec;
if (parseSimpleTypeSpecifier(typeSpec) && m_lexer->lookAhead(0) == '(') {
nextToken();
AST::Node expr;
parseCommaExpression(expr);
CHECK(')', ")");
return true;
}
m_lexer->setIndex(start);
NameAST::Node name;
if (parseName(name))
return true;
}
}
return false;
}
bool Parser::parsePostfixExpression(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parsePrimaryExpression(expr))
return false;
while (true) {
switch (m_lexer->lookAhead(0)) {
case '[': {
nextToken();
AST::Node e;
parseCommaExpression(e);
CHECK(']', "]");
}
break;
case '(': {
nextToken();
AST::Node funArgs;
parseCommaExpression(funArgs);
CHECK(')', ")");
}
break;
case Token_incr:
case Token_decr:
nextToken();
break;
case '.':
case Token_arrow: {
nextToken();
if (m_lexer->lookAhead(0) == Token_template)
nextToken();
NameAST::Node name;
if (!parseName(name)) {
return false;
}
}
break;
case Token_typename: {
nextToken();
NameAST::Node name;
if (!parseName(name)) {
return false;
}
CHECK('(', "(");
AST::Node expr;
parseCommaExpression(expr);
CHECK(')', ")");
}
return true;
default:
return true;
} // end switch
} // end while
return true;
}
bool Parser::parseUnaryExpression(AST::Node& node)
{
PARSER_DEBUG_METHOD;
switch (m_lexer->lookAhead(0)) {
case Token_incr:
case Token_decr:
case '*':
case '&':
case '+':
case '-':
case '!':
case '~': {
nextToken();
AST::Node expr;
return parseCastExpression(expr);
}
case Token_sizeof: {
nextToken();
int index = m_lexer->index();
if (m_lexer->lookAhead(0) == '(') {
nextToken();
AST::Node typeId;
if (parseTypeId(typeId) && m_lexer->lookAhead(0) == ')') {
nextToken();
return true;
}
m_lexer->setIndex(index);
}
AST::Node expr;
return parseUnaryExpression(expr);
}
case Token_new:
return parseNewExpression(node);
case Token_delete:
return parseDeleteExpression(node);
}
return parsePostfixExpression(node);
}
bool Parser::parseNewExpression(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
if (m_lexer->lookAhead(0) == Token_scope && m_lexer->lookAhead(1) == Token_new)
nextToken();
CHECK(Token_new, "new");
if (m_lexer->lookAhead(0) == '(') {
nextToken();
AST::Node expr;
parseCommaExpression(expr);
CHECK(')', ")");
}
if (m_lexer->lookAhead(0) == '(') {
nextToken();
AST::Node typeId;
parseTypeId(typeId);
CHECK(')', ")");
} else {
AST::Node typeId;
parseNewTypeId(typeId);
}
AST::Node init;
parseNewInitializer(init);
return true;
}
bool Parser::parseNewTypeId(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
TypeSpecifierAST::Node typeSpec;
if (parseTypeSpecifier(typeSpec)) {
AST::Node declarator;
parseNewDeclarator(declarator);
return true;
}
return false;
}
bool Parser::parseNewDeclarator(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
AST::Node ptrOp;
if (parsePtrOperator(ptrOp)) {
AST::Node declarator;
parseNewDeclarator(declarator);
return true;
}
if (m_lexer->lookAhead(0) == '[') {
while (m_lexer->lookAhead(0) == '[') {
nextToken();
AST::Node expr;
parseExpression(expr);
ADVANCE(']', "]");
}
return true;
}
return false;
}
bool Parser::parseNewInitializer(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
if (m_lexer->lookAhead(0) != '(')
return false;
nextToken();
AST::Node expr;
parseCommaExpression(expr);
CHECK(')', ")");
return true;
}
bool Parser::parseDeleteExpression(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
if (m_lexer->lookAhead(0) == Token_scope && m_lexer->lookAhead(1) == Token_delete)
nextToken();
CHECK(Token_delete, "delete");
if (m_lexer->lookAhead(0) == '[') {
nextToken();
CHECK(']', "]");
}
AST::Node expr;
return parseCastExpression(expr);
}
bool Parser::parseCastExpression(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
int index = m_lexer->index();
if (m_lexer->lookAhead(0) == '(') {
nextToken();
AST::Node typeId;
if (parseTypeId(typeId)) {
if (m_lexer->lookAhead(0) == ')') {
nextToken();
AST::Node expr;
if (parseCastExpression(expr))
return true;
}
}
}
m_lexer->setIndex(index);
AST::Node expr;
return parseUnaryExpression(expr);
}
bool Parser::parsePmExpression(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parseCastExpression(expr))
return false;
while (m_lexer->lookAhead(0) == Token_ptrmem) {
nextToken();
if (!parseCastExpression(expr))
return false;
}
return true;
}
bool Parser::parseMultiplicativeExpression(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parsePmExpression(expr))
return false;
while (m_lexer->lookAhead(0) == '*' || m_lexer->lookAhead(0) == '/' || m_lexer->lookAhead(0) == '%') {
nextToken();
if (!parsePmExpression(expr))
return false;
}
return true;
}
bool Parser::parseAdditiveExpression(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parseMultiplicativeExpression(expr))
return false;
while (m_lexer->lookAhead(0) == '+' || m_lexer->lookAhead(0) == '-') {
nextToken();
if (!parseMultiplicativeExpression(expr))
return false;
}
return true;
}
bool Parser::parseShiftExpression(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parseAdditiveExpression(expr))
return false;
while (m_lexer->lookAhead(0) == Token_shift || (m_lexer->lookAhead(0) == '>' && m_lexer->lookAhead(1) == '>')) {
nextToken();
if (!parseAdditiveExpression(expr))
return false;
}
return true;
}
bool Parser::parseRelationalExpression(AST::Node& /*node*/, bool templArgs)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parseShiftExpression(expr))
return false;
while (m_lexer->lookAhead(0) == '<' || (m_lexer->lookAhead(0) == '>' && !templArgs) ||
m_lexer->lookAhead(0) == Token_leq || m_lexer->lookAhead(0) == Token_geq) {
nextToken();
if (!parseShiftExpression(expr))
return false;
}
return true;
}
bool Parser::parseEqualityExpression(AST::Node& /*node*/, bool templArgs)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parseRelationalExpression(expr, templArgs))
return false;
while (m_lexer->lookAhead(0) == Token_eq || m_lexer->lookAhead(0) == Token_not_eq) {
nextToken();
if (!parseRelationalExpression(expr, templArgs))
return false;
}
return true;
}
bool Parser::parseAndExpression(AST::Node& /*node*/, bool templArgs)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parseEqualityExpression(expr, templArgs))
return false;
while (m_lexer->lookAhead(0) == '&') {
nextToken();
if (!parseEqualityExpression(expr, templArgs))
return false;
}
return true;
}
bool Parser::parseExclusiveOrExpression(AST::Node& /*node*/, bool templArgs)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parseAndExpression(expr, templArgs))
return false;
while (m_lexer->lookAhead(0) == '^') {
nextToken();
if (!parseAndExpression(expr, templArgs))
return false;
}
return true;
}
bool Parser::parseInclusiveOrExpression(AST::Node& /*node*/, bool templArgs)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parseExclusiveOrExpression(expr, templArgs))
return false;
while (m_lexer->lookAhead(0) == '|') {
nextToken();
if (!parseExclusiveOrExpression(expr, templArgs))
return false;
}
return true;
}
bool Parser::parseLogicalAndExpression(AST::Node& /*node*/, bool templArgs)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parseInclusiveOrExpression(expr, templArgs))
return false;
while (m_lexer->lookAhead(0) == Token_and) {
nextToken();
if (!parseInclusiveOrExpression(expr, templArgs))
return false;
}
return true;
}
bool Parser::parseLogicalOrExpression(AST::Node& node, bool templArgs)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
AST::Node expr;
if (!parseLogicalAndExpression(expr, templArgs))
return false;
while (m_lexer->lookAhead(0) == Token_or) {
nextToken();
if (!parseLogicalAndExpression(expr, templArgs))
return false;
}
AST::Node ast = CreateNode<AST>();
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseConditionalExpression(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
AST::Node expr;
if (!parseLogicalOrExpression(expr))
return false;
if (m_lexer->lookAhead(0) == '?') {
nextToken();
if (!parseExpression(expr))
return false;
CHECK(':', ":");
if (!parseAssignmentExpression(expr))
return false;
}
return true;
}
bool Parser::parseAssignmentExpression(AST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
AST::Node expr;
if (m_lexer->lookAhead(0) == Token_throw && !parseThrowExpression(expr))
return false;
else if (!parseConditionalExpression(expr))
return false;
while (m_lexer->lookAhead(0) == Token_assign || m_lexer->lookAhead(0) == '=') {
nextToken();
if (!parseConditionalExpression(expr))
return false;
}
AST::Node ast = CreateNode<AST>();
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseConstantExpression(AST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (parseConditionalExpression(node)) {
AST::Node ast = CreateNode<AST>();
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
return false;
}
bool Parser::parseExpression(AST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
if (!parseCommaExpression(node))
return false;
AST::Node ast = CreateNode<AST>();
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseCommaExpression(AST::Node& node)
{
PARSER_DEBUG_METHOD;
int start = m_lexer->index();
AST::Node expr;
if (!parseAssignmentExpression(expr))
return false;
while (m_lexer->lookAhead(0) == ',') {
nextToken();
if (!parseAssignmentExpression(expr))
return false;
}
AST::Node ast = CreateNode<AST>();
UPDATE_POS(ast, start, m_lexer->index());
node = std::move(ast);
return true;
}
bool Parser::parseThrowExpression(AST::Node& /*node*/)
{
PARSER_DEBUG_METHOD;
if (m_lexer->lookAhead(0) != Token_throw)
return false;
CHECK(Token_throw, "throw");
AST::Node expr;
if (!parseAssignmentExpression(expr))
return false;
return true;
}
bool Parser::parseIvarDeclList(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseIvarDecls(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseIvarDecl(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseIvars(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseIvarDeclarator(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseMethodDecl(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseUnarySelector(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseKeywordSelector(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseSelector(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseKeywordDecl(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseReceiver(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseObjcMessageExpr(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseMessageArgs(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseKeywordExpr(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseKeywordArgList(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseKeywordArg(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseReservedWord(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseMyParms(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseMyParm(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseOptParmList(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseObjcSelectorExpr(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseSelectorArg(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseKeywordNameList(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseKeywordName(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseObjcEncodeExpr(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseObjcString(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseProtocolRefs(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseIdentifierList(GroupAST::Node & node)
{
int start = m_lexer->index();
if (m_lexer->lookAhead(0) != Token_identifier)
return false;
GroupAST::Node ast = CreateNode<GroupAST>();
AST_FROM_TOKEN(tk, m_lexer->index());
ast->addNode(tk);
nextToken();
while (m_lexer->lookAhead(0) == ',') {
nextToken();
if (m_lexer->lookAhead(0) == Token_identifier) {
AST_FROM_TOKEN(tk, m_lexer->index());
ast->addNode(tk);
// nextToken();
}
ADVANCE(Token_identifier, "identifier");
}
node = std::move(ast);
UPDATE_POS(node, start, m_lexer->index());
return true;
}
bool Parser::parseIdentifierColon(AST::Node & node)
{
Q_UNUSED(node);
if (m_lexer->lookAhead(0) == Token_identifier && m_lexer->lookAhead(1) == ':') {
nextToken();
nextToken();
return true;
} // ### else if PTYPENAME -> return true ;
return false;
}
bool Parser::parseObjcProtocolExpr(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseObjcOpenBracketExpr(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseObjcCloseBracket(AST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseObjcDef(DeclarationAST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseObjcClassDef(DeclarationAST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseObjcClassDecl(DeclarationAST::Node & node)
{
Q_UNUSED(node);
ADVANCE(OBJC_CLASS, "@class");
GroupAST::Node idList;
if (!parseIdentifierList(idList))
return false;
ADVANCE(';', ";");
return true;
}
bool Parser::parseObjcProtocolDecl(DeclarationAST::Node & node)
{
Q_UNUSED(node);
ADVANCE(OBJC_PROTOCOL, "@protocol");
GroupAST::Node idList;
if (!parseIdentifierList(idList))
return false;
ADVANCE(';', ";");
return true;
}
bool Parser::parseObjcAliasDecl(DeclarationAST::Node & node)
{
Q_UNUSED(node);
ADVANCE(OBJC_ALIAS, "@alias");
GroupAST::Node idList;
if (!parseIdentifierList(idList))
return false;
ADVANCE(';', ";");
return true;
}
bool Parser::parseObjcProtocolDef(DeclarationAST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseObjcMethodDef(DeclarationAST::Node & node)
{
Q_UNUSED(node);
return false;
}
bool Parser::parseWinDeclSpec(GroupAST::Node & node)
{
if (m_lexer->lookAhead(0) == Token_identifier &&
m_lexer->lookAhead(0).text() == QLatin1String("__declspec") &&
m_lexer->lookAhead(1) == '(' &&
m_lexer->lookAhead(2) != ')') {
int start = m_lexer->index();
nextToken();
nextToken(); // skip '('
if (!parseIdentifierList(node))
return false;
ADVANCE(')', ")");
UPDATE_POS(node, start, m_lexer->index());
return true;
}
return false;
}
| 104,557
|
C++
|
.cpp
| 3,529
| 22.162369
| 146
| 0.577097
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
749,209
|
ast_utils.cpp
|
KDE_umbrello/lib/cppparser/ast_utils.cpp
|
/*
SPDX-FileCopyrightText: 2002 Roberto Raggi <roberto@kdevelop.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "ast_utils.h"
#include "ast.h"
#include "debug_utils.h"
#include <QRegularExpression>
#include <QStringList>
#include <KLocalizedString>
void scopeOfNode(AST* ast, QStringList& scope)
{
if (!ast)
return;
if (ast->parent())
scopeOfNode(ast->parent(), scope);
QString s;
switch (ast->nodeType()) {
case NodeType_ClassSpecifier:
if (((ClassSpecifierAST*)ast)->name()) {
s = ((ClassSpecifierAST*)ast)->name()->text();
s = s.isEmpty() ? QString::fromLatin1("<unnamed>") : s;
scope.push_back(s);
}
break;
case NodeType_Namespace: {
AST* namespaceName = ((NamespaceAST*)ast)->namespaceName();
s = namespaceName ? namespaceName->text() : QString::fromLatin1("<unnamed>");
scope.push_back(s);
}
break;
case NodeType_FunctionDefinition: {
FunctionDefinitionAST* funDef = static_cast<FunctionDefinitionAST*>(ast);
DeclaratorAST* d = funDef->initDeclarator()->declarator();
// hotfix for bug #68726
if (!d->declaratorId())
break;
QList<ClassOrNamespaceNameAST*> l = d->declaratorId()->classOrNamespaceNameList();
for (int i = 0; i < l.size(); ++i) {
AST* name = l.at(i)->name();
scope.push_back(name->text());
}
}
break;
default:
break;
}
}
QString typeSpecToString(TypeSpecifierAST* typeSpec) /// @todo remove
{
if (!typeSpec)
return QString();
return typeSpec->text().replace(QRegularExpression(QLatin1String(" :: ")), QLatin1String("::"));
}
QString declaratorToString(DeclaratorAST* declarator, const QString& scope, bool skipPtrOp)
{
if (!declarator)
return QString();
QString text;
if (!skipPtrOp) {
QList<AST*> ptrOpList = declarator->ptrOpList();
for (int i = 0; i < ptrOpList.size(); ++i) {
text += ptrOpList.at(i)->text();
}
text += QLatin1Char(' ');
}
text += scope;
if (declarator->subDeclarator())
text += QString::fromLatin1("(") + declaratorToString(declarator->subDeclarator()) + QString::fromLatin1(")");
if (declarator->declaratorId())
text += declarator->declaratorId()->text();
QList<AST*> arrays = declarator->arrayDimensionList();
for (int i = 0; i < arrays.size(); ++i) {
text += QLatin1String("[]");
}
if (declarator->parameterDeclarationClause()) {
text += QLatin1Char('(');
ParameterDeclarationListAST* l = declarator->parameterDeclarationClause()->parameterDeclarationList();
if (l != nullptr) {
QList<ParameterDeclarationAST*> params = l->parameterList();
for (int i = 0; i < params.size(); ++i) {
QString type = typeSpecToString(params.at(i)->typeSpec());
text += type;
if (!type.isEmpty())
text += QLatin1Char(' ');
text += declaratorToString(params.at(i)->declarator());
if (params.at(i))
text += QLatin1String(", ");
}
}
text += QLatin1Char(')');
if (declarator->constant() != nullptr)
text += QLatin1String(" const");
if (declarator->override_() != nullptr)
text += QLatin1String(" override");
if (declarator->final_() != nullptr)
text += QLatin1String(" final");
}
return text.replace(QRegularExpression(QLatin1String(" :: ")), QLatin1String("::")).simplified();
}
| 3,700
|
C++
|
.cpp
| 100
| 29.11
| 118
| 0.588631
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
749,210
|
lexer.cpp
|
KDE_umbrello/lib/cppparser/lexer.cpp
|
/* This file is part of KDevelop
SPDX-FileCopyrightText: 2002, 2003 Roberto Raggi <roberto@kdevelop.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "lexer.h"
#include "lookup.h"
#define DBG_SRC QLatin1String("Lexer")
#include "debug_utils.h"
#include <KLocalizedString>
#include <QMap>
#include <QList>
DEBUG_REGISTER_DISABLED(Lexer)
#if defined(KDEVELOP_BGPARSER)
#include <QThread>
class KDevTread: public QThread
{
public:
static void yield()
{
msleep(0);
}
};
inline void qthread_yield()
{
KDevTread::yield();
}
#endif
#define CREATE_TOKEN(type, start, len) Token((type), (start), (len), m_source)
#define ADD_TOKEN(tk) m_tokens.insert(m_size++, new Token(tk));
using namespace std;
Token::Token(const QString & text)
: m_type(-1),
m_position(0),
m_length(0),
m_startLine(0),
m_startColumn(0),
m_endLine(0),
m_endColumn(0),
m_text(text)
{
}
Token::Token(int type, int position, int length, const QString& text)
: m_type(type),
m_position(position),
m_length(length),
m_startLine(0),
m_startColumn(0),
m_endLine(0),
m_endColumn(0),
m_text(text)
{
DEBUG() << type << position << length << text.mid(position, length);
}
Token::Token(const Token& source)
: m_type(source.m_type),
m_position(source.m_position),
m_length(source.m_length),
m_startLine(source.m_startLine),
m_startColumn(source.m_startColumn),
m_endLine(source.m_endLine),
m_endColumn(source.m_endColumn),
m_text(source.m_text)
{
}
Token& Token::operator = (const Token& source)
{
m_type = source.m_type;
m_position = source.m_position;
m_length = source.m_length;
m_startLine = source.m_startLine;
m_startColumn = source.m_startColumn;
m_endLine = source.m_endLine;
m_endColumn = source.m_endColumn;
// m_text = source.m_text;
return (*this);
}
Token::operator int () const
{
return m_type;
}
bool Token::operator == (const Token& token) const
{
return m_type == token.m_type &&
m_position == token.m_position &&
m_length == token.m_length &&
m_startLine == token.m_startLine &&
m_startColumn == token.m_startColumn &&
m_endLine == token.m_endLine &&
m_endColumn == token.m_endColumn &&
m_text == token.m_text;
}
bool Token::isNull() const
{
return m_type == Token_eof || m_length == 0;
}
int Token::type() const
{
return m_type;
}
void Token::setType(int type)
{
m_type = type;
}
int Token::position() const
{
return m_position;
}
QString Token::text() const
{
return m_text.mid(m_position, m_length);
}
void Token::setStartPosition(int line, int column)
{
m_startLine = line;
m_startColumn = column;
}
void Token::setEndPosition(int line, int column)
{
m_endLine = line;
m_endColumn = column;
}
void Token::getStartPosition(int* line, int* column) const
{
if (line) *line = m_startLine;
if (column) *column = m_startColumn;
}
void Token::getEndPosition(int* line, int* column) const
{
if (line) *line = m_endLine;
if (column) *column = m_endColumn;
}
void Token::setPosition(int position)
{
m_position = position;
}
unsigned int Token::length() const
{
return m_length;
}
void Token::setLength(unsigned int length)
{
m_length = length;
}
struct LexerData {
typedef QMap<QString, QString> Scope;
typedef QList<Scope> StaticChain;
StaticChain staticChain;
void beginScope()
{
Scope scope;
staticChain.push_front(scope);
}
void endScope()
{
staticChain.pop_front();
}
void bind(const QString& name, const QString& value)
{
Q_ASSERT(staticChain.size() > 0);
staticChain.front().insert(name, value);
}
bool hasBind(const QString& name) const
{
StaticChain::ConstIterator it = staticChain.begin();
while (it != staticChain.end()) {
const Scope& scope = *it;
++it;
if (scope.contains(name))
return true;
}
return false;
}
QString apply(const QString& name) const
{
StaticChain::ConstIterator it = staticChain.begin();
while (it != staticChain.end()) {
const Scope& scope = *it;
++it;
if (scope.contains(name))
return scope[ name ];
}
return QString();
}
};
bool Lexer::recordComments() const
{
return m_recordComments;
}
void Lexer::setRecordComments(bool record)
{
m_recordComments = record;
}
bool Lexer::recordWhiteSpaces() const
{
return m_recordWhiteSpaces;
}
void Lexer::setRecordWhiteSpaces(bool record)
{
m_recordWhiteSpaces = record;
}
QString Lexer::source() const
{
return m_source;
}
int Lexer::index() const
{
return m_index;
}
void Lexer::setIndex(int index)
{
m_index = index;
}
const Token& Lexer::nextToken()
{
if (m_index < m_size)
return *m_tokens[ m_index++ ];
return *m_tokens[ m_index ];
}
const Token& Lexer::tokenAt(int n) const
{
return *m_tokens[ qMin(n, m_size-1) ];
}
const Token& Lexer::lookAhead(int n) const
{
Token &t = *m_tokens[ qMin(m_index + n, m_size-1) ];
DEBUG() << t;
return t;
}
int Lexer::tokenPosition(const Token& token) const
{
return token.position();
}
void Lexer::nextChar()
{
if (m_idx >= m_endIdx) {
m_currentChar = QChar();
return;
}
if (m_source[m_idx] == QLatin1Char('\n')) {
++m_currentLine;
m_currentColumn = 0;
m_startLine = true;
} else {
++m_currentColumn;
}
++m_idx;
if (m_idx < m_endIdx)
m_currentChar = m_source[m_idx];
else
m_currentChar = QChar();
}
void Lexer::nextChar(int n)
{
if (m_idx + n >= m_endIdx) {
m_idx = m_endIdx;
m_currentChar = QChar();
return;
}
m_currentColumn += n;
m_idx += n;
if (m_idx < m_endIdx)
m_currentChar = m_source[m_idx];
else
m_currentChar = QChar();
}
void Lexer::readIdentifier()
{
while (currentChar().isLetterOrNumber() || currentChar() == QLatin1Char('_'))
nextChar();
}
/**
* Return true on success, false on error (EOF encountered).
* The return value does not indicate whether spaces were skipped or not.
*/
bool Lexer::readWhiteSpaces(bool skipNewLine, bool skipOnlyOnce)
{
while (1) {
QChar ch = currentChar();
if (ch.isNull())
return false;
if (ch == QLatin1Char('\n') && !skipNewLine) {
break;
} else if (ch.isSpace()) {
nextChar();
if (currentChar().isNull())
return false;
} else if (m_inPreproc && currentChar() == QLatin1Char('\\')) {
nextChar();
if (currentChar().isNull())
return false;
if (!readWhiteSpaces(true, true))
return false;
} else {
break;
}
if (skipOnlyOnce && ch == QLatin1Char('\n')) {
skipNewLine = false;
}
}
return true;
}
//little hack for better performance
static bool isTodo(const QString& txt, int position)
{
if (txt.length() < position + 4) return false;
return (txt[ position ] == QLatin1Char('t') || txt[ position ] == QLatin1Char('T'))
&& (txt[ position+1 ] == QLatin1Char('o') || txt[ position+1 ] == QLatin1Char('O'))
&& (txt[ position+2 ] == QLatin1Char('d') || txt[ position+2 ] == QLatin1Char('D'))
&& (txt[ position+3 ] == QLatin1Char('o') || txt[ position+3 ] == QLatin1Char('O'));
}
static bool isFixme(const QString& txt, int position)
{
if (txt.length() < position + 5) return false;
return (txt[ position ] == QLatin1Char('f') || txt[ position ] == QLatin1Char('F'))
&& (txt[ position+1 ] == QLatin1Char('i') || txt[ position+1 ] == QLatin1Char('I'))
&& (txt[ position+2 ] == QLatin1Char('x') || txt[ position+2 ] == QLatin1Char('X'))
&& (txt[ position+3 ] == QLatin1Char('m') || txt[ position+3 ] == QLatin1Char('M'))
&& (txt[ position+4 ] == QLatin1Char('e') || txt[ position+4 ] == QLatin1Char('E'));
}
void Lexer::readLineComment()
{
while (!currentChar().isNull() && currentChar() != QLatin1Char('\n')) {
if (currentPosition() < 0)
break;
if (m_reportMessages && isTodo(m_source, currentPosition())) {
nextChar(4);
QString msg;
int line = m_currentLine;
int col = m_currentColumn;
while (!currentChar().isNull()) {
if (currentChar() == QLatin1Char('*') && peekChar() == QLatin1Char('/'))
break;
else if (currentChar() == QLatin1Char('\n'))
break;
msg += currentChar();
nextChar();
}
m_driver->addProblem(m_driver->currentFileName(), Problem(msg, line, col, Problem::Level_Todo));
} else if (m_reportMessages && isFixme(m_source, currentPosition())) {
nextChar(5);
QString msg;
int line = m_currentLine;
int col = m_currentColumn;
while (!currentChar().isNull()) {
if (currentChar() == QLatin1Char('*') && peekChar() == QLatin1Char('/'))
break;
else if (currentChar() == QLatin1Char('\n'))
break;
msg += currentChar();
nextChar();
}
m_driver->addProblem(m_driver->currentFileName(), Problem(msg, line, col, Problem::Level_Fixme));
} else
nextChar();
}
}
void Lexer::readMultiLineComment()
{
while (!currentChar().isNull()) {
if (currentPosition() < 0)
break;
if (currentChar() == QLatin1Char('*') && peekChar() == QLatin1Char('/')) {
nextChar(2);
return;
} else if (m_reportMessages && isTodo(m_source, currentPosition())) {
nextChar(4);
QString msg;
int line = m_currentLine;
int col = m_currentColumn;
while (!currentChar().isNull()) {
if (currentChar() == QLatin1Char('*') && peekChar() == QLatin1Char('/'))
break;
else if (currentChar() == QLatin1Char('\n'))
break;
msg += currentChar();
nextChar();
}
m_driver->addProblem(m_driver->currentFileName(), Problem(msg, line, col, Problem::Level_Todo));
} else if (m_reportMessages && isFixme(m_source, currentPosition())) {
nextChar(5);
QString msg;
int line = m_currentLine;
int col = m_currentColumn;
while (!currentChar().isNull()) {
if (currentChar() == QLatin1Char('*') && peekChar() == QLatin1Char('/'))
break;
else if (currentChar() == QLatin1Char('\n'))
break;
msg += currentChar();
nextChar();
}
m_driver->addProblem(m_driver->currentFileName(), Problem(msg, line, col, Problem::Level_Fixme));
} else
nextChar();
}
}
void Lexer::readCharLiteral()
{
if (currentChar() == QLatin1Char('\''))
nextChar(); // skip '
else if (currentChar() == QLatin1Char('L') && peekChar() == QLatin1Char('\''))
nextChar(2); // slip L'
else
return;
while (!currentChar().isNull()) {
if (currentPosition() < 0)
break;
int len = m_endIdx - m_idx;
if (len>=2 && (currentChar() == QLatin1Char('\\') && peekChar() == QLatin1Char('\''))) {
nextChar(2);
} else if (len>=2 && (currentChar() == QLatin1Char('\\') && peekChar() == QLatin1Char('\\'))) {
nextChar(2);
} else if (currentChar() == QLatin1Char('\'')) {
nextChar();
break;
} else {
nextChar();
}
}
}
void Lexer::readStringLiteral()
{
if (currentChar() != QLatin1Char('"'))
return;
nextChar(); // skip "
while (!currentChar().isNull()) {
if (currentPosition() < 0)
break;
int len = m_endIdx - m_idx;
if (len>=2 && currentChar() == QLatin1Char('\\') && peekChar() == QLatin1Char('"')) {
nextChar(2);
} else if (len>=2 && currentChar() == QLatin1Char('\\') && peekChar() == QLatin1Char('\\')) {
nextChar(2);
} else if (currentChar() == QLatin1Char('"')) {
nextChar();
break;
} else {
nextChar();
}
}
}
void Lexer::readNumberLiteral()
{
while (currentChar().isLetterOrNumber() || currentChar() == QLatin1Char('.'))
nextChar();
}
int Lexer::findOperator3() const
{
if (currentPosition() < 0)
return -1;
int n = m_endIdx - m_idx;
if (n >= 3) {
char ch = currentChar().toLatin1();
char ch1 = peekChar().toLatin1();
char ch2 = peekChar(2).toLatin1();
if (ch == '<' && ch1 == '<' && ch2 == '=') return Token_assign;
else if (ch == '>' && ch1 == '>' && ch2 == '=') return Token_assign;
else if (ch == '-' && ch1 == '>' && ch2 == '*') return Token_ptrmem;
else if (ch == '.' && ch1 == '.' && ch2 == '.') return Token_ellipsis;
}
return -1;
}
int Lexer::findOperator2() const
{
if (currentPosition() < 0)
return -1;
int n = m_endIdx - m_idx;
if (n>=2) {
char ch = currentChar().toLatin1(), ch1 = peekChar().toLatin1();
if (ch == ':' && ch1 == ':') return Token_scope;
else if (ch == '.' && ch1 == '*') return Token_ptrmem;
else if (ch == '+' && ch1 == '=') return Token_assign;
else if (ch == '-' && ch1 == '=') return Token_assign;
else if (ch == '*' && ch1 == '=') return Token_assign;
else if (ch == '/' && ch1 == '=') return Token_assign;
else if (ch == '%' && ch1 == '=') return Token_assign;
else if (ch == '^' && ch1 == '=') return Token_assign;
else if (ch == '&' && ch1 == '=') return Token_assign;
else if (ch == '|' && ch1 == '=') return Token_assign;
else if (ch == '<' && ch1 == '<') return Token_shift;
//else if(ch == '>' && ch1 == '>') return Token_shift;
else if (ch == '=' && ch1 == '=') return Token_eq;
else if (ch == '!' && ch1 == '=') return Token_eq;
else if (ch == '<' && ch1 == '=') return Token_leq;
else if (ch == '>' && ch1 == '=') return Token_geq;
else if (ch == '&' && ch1 == '&') return Token_and;
else if (ch == '|' && ch1 == '|') return Token_or;
else if (ch == '+' && ch1 == '+') return Token_incr;
else if (ch == '-' && ch1 == '-') return Token_decr;
else if (ch == '-' && ch1 == '>') return Token_arrow;
else if (ch == '#' && ch1 == '#') return Token_concat;
}
return -1;
}
bool Lexer::skipWordsEnabled() const
{
return m_skipWordsEnabled;
}
void Lexer::setSkipWordsEnabled(bool enabled)
{
m_skipWordsEnabled = enabled;
}
bool Lexer::preprocessorEnabled() const
{
return m_preprocessorEnabled;
}
void Lexer::setPreprocessorEnabled(bool enabled)
{
m_preprocessorEnabled = enabled;
}
int Lexer::currentPosition() const
{
return m_idx;
}
const QChar Lexer::currentChar() const
{
return m_currentChar;
}
QChar Lexer::peekChar(int n) const
{
if (m_idx + n >= m_endIdx)
return QChar();
return m_source[m_idx + n];
}
bool Lexer::eof() const
{
return m_idx >= m_endIdx;
}
bool Lexer::reportWarnings() const
{
return m_reportWarnings;
}
void Lexer::setReportWarnings(bool enable)
{
m_reportWarnings = enable;
}
bool Lexer::reportMessages() const
{
return m_reportMessages;
}
void Lexer::setReportMessages(bool enable)
{
m_reportMessages = enable;
}
void Lexer::insertCurrent(const QString& str)
{
if (currentPosition() < 0)
return;
m_source.insert(m_idx, str);
m_endIdx = m_source.length();
m_currentChar = m_source[m_idx];
}
Lexer::Lexer(Driver* driver)
: d(new LexerData),
m_driver(driver),
m_recordComments(true),
m_recordWhiteSpaces(false),
m_skipWordsEnabled(true),
m_preprocessorEnabled(true),
m_inPreproc(false),
m_reportWarnings(false),
m_reportMessages(false)
{
reset();
d->beginScope();
}
Lexer::~Lexer()
{
d->endScope();
delete(d);
qDeleteAll(m_tokens);
m_tokens.clear();
}
void Lexer::setSource(const QString& source)
{
reset();
m_source = source;
m_idx = 0;
m_endIdx = m_source.length();
m_inPreproc = false;
if (m_source.isEmpty()) {
m_currentChar = QChar();
return;
}
m_currentChar = m_source[0];
tokenize();
}
int Lexer::skippedLines() const
{
return m_skippedLines;
}
void Lexer::reset()
{
m_skippedLines = 0;
m_index = 0;
m_size = 0;
m_tokens.clear();
m_source = QString();
m_idx = 0;
m_endIdx = 0;
m_startLine = false;
m_ifLevel = 0;
m_skipping.resize(200);
m_skipping.fill(0);
m_trueTest.resize(200);
m_trueTest.fill(0);
m_currentLine = 0;
m_currentColumn = 0;
}
// ### should all be done with a "long" type IMO
int Lexer::toInt(const Token& token)
{
QString s = token.text();
if (token.type() == Token_number_literal) {
// hex literal ?
if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
return s.mid(2).toInt(nullptr, 16);
QString n;
int i = 0;
while (i < int(s.length()) && s[i].isDigit())
n += s[i++];
// ### respect more prefixes and suffixes ?
return n.toInt();
} else if (token.type() == Token_char_literal) {
int i = s[0] == 'L' ? 2 : 1; // wide char ?
if (s[i] == '\\') {
// escaped char
int c = s[i+1].unicode();
switch (c) {
case '0':
return 0;
case 'n':
return '\n';
// ### more
default:
return c;
}
} else {
return s[i].unicode();
}
} else {
return 0;
}
}
void Lexer::getTokenPosition(const Token& token, int* line, int* col)
{
token.getStartPosition(line, col);
}
void Lexer::nextToken(Token& tk, bool stopOnNewline)
{
int op = 0;
if (m_size == (int)m_tokens.size()) {
m_tokens.resize(m_tokens.size() + 5000 + 1);
}
if (!readWhiteSpaces(!stopOnNewline))
return;
if (currentPosition() < 0)
return;
int startLine = m_currentLine;
int startColumn = m_currentColumn;
QChar ch = currentChar();
QChar ch1 = peekChar();
if (ch.isNull() || ch.isSpace()) {
/* skip */
} else if (m_startLine && ch == '#') {
nextChar(); // skip #
if (!readWhiteSpaces(false)) // skip white spaces
return;
m_startLine = false;
int start = currentPosition();
readIdentifier(); // read the directive
QString directive = m_source.mid(start, currentPosition() - start);
handleDirective(directive);
} else if (m_startLine && m_skipping[ m_ifLevel ]) {
// skip line and continue
m_startLine = false;
int ppe = preprocessorEnabled();
setPreprocessorEnabled(false);
while (!currentChar().isNull() && currentChar() != '\n') {
Token tok(m_source);
nextToken(tok, true);
}
++m_skippedLines;
m_startLine = true;
setPreprocessorEnabled(ppe);
return;
} else if (ch == '/' && ch1 == '/') {
int start = currentPosition();
readLineComment();
if (recordComments()) {
tk = CREATE_TOKEN(Token_comment, start, currentPosition() - start);
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
}
} else if (ch == '/' && ch1 == '*') {
int start = currentPosition();
nextChar(2);
readMultiLineComment();
if (recordComments()) {
tk = CREATE_TOKEN(Token_comment, start, currentPosition() - start);
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
}
} else if (ch == '\'' || (ch == 'L' && ch1 == '\'')) {
int start = currentPosition();
readCharLiteral();
tk = CREATE_TOKEN(Token_char_literal, start, currentPosition() - start);
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
} else if (ch == '"') {
int start = currentPosition();
readStringLiteral();
tk = CREATE_TOKEN(Token_string_literal, start, currentPosition() - start);
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
} else if (ch.isLetter() || ch == '_') {
int start = currentPosition();
readIdentifier();
HashedString ide = m_source.mid(start, currentPosition() - start);
int k = Lookup::find(ide);
if (k == -1 && m_preprocessorEnabled) m_driver->usingString(ide);
if (m_preprocessorEnabled && m_driver->hasMacro(ide) &&
(k == -1 || !m_driver->macro(ide).body().isEmpty())) {
bool preproc = m_preprocessorEnabled;
m_preprocessorEnabled = false;
d->beginScope();
int svLine = currentLine();
int svColumn = currentColumn();
Macro m = m_driver->macro(ide);
m_driver->usingMacro(m);
QString ellipsisArg;
if (m.hasArguments()) {
int endIde = currentPosition();
readWhiteSpaces();
if (currentChar() == '(') {
nextChar();
int argIdx = 0;
int argCount = m.argumentList().size();
while (!currentChar().isNull() && argIdx<argCount) {
readWhiteSpaces();
QString argName = m.argumentList()[ argIdx ];
bool ellipsis = argName == "...";
QString arg = readArgument();
if (!ellipsis)
d->bind(argName, arg);
else
ellipsisArg += arg;
if (currentChar() == ',') {
nextChar();
if (!ellipsis) {
++argIdx;
} else {
ellipsisArg += ", ";
}
} else if (currentChar() == ')') {
break;
}
}
if (currentChar() == ')') {
// valid macro
nextChar();
}
} else {
tk = CREATE_TOKEN(Token_identifier, start, endIde - start);
tk.setStartPosition(svLine, svColumn);
tk.setEndPosition(svLine, svColumn + (endIde - start));
m_startLine = false;
d->endScope(); // OPS!!
m_preprocessorEnabled = preproc;
return;
}
}
int argsEndAtLine = currentLine();
int argsEndAtColumn = currentColumn();
#if defined(KDEVELOP_BGPARSER)
qthread_yield();
#endif
insertCurrent(m.body());
// tokenize the macro body
QString textToInsert;
m_endIdx = m_idx + m.body().length();
while (!currentChar().isNull()) {
readWhiteSpaces();
Token tok(m_source);
nextToken(tok);
bool stringify = !m_inPreproc && tok == '#';
bool merge = !m_inPreproc && tok == Token_concat;
if (stringify || merge)
nextToken(tok);
if (tok == Token_eof)
break;
QString tokText = tok.text();
HashedString str = (tok == Token_identifier && d->hasBind(tokText)) ? d->apply(tokText) : tokText;
if (str == ide) {
//Problem p(i18n("unsafe use of macro '%1', macro is ignored").arg(ide.str()), m_currentLine, m_currentColumn, Problem::Level_Warning);
//m_driver->addProblem(m_driver->currentFileName(), p);
m_driver->removeMacro(ide);
// str = QString::null;
}
if (stringify) {
textToInsert.append(QString::fromLatin1("\"") + str.str() + QString::fromLatin1("\" "));
} else if (merge) {
textToInsert.truncate(textToInsert.length() - 1);
textToInsert.append(str.str() + QString::fromLatin1(" "));
} else if (tok == Token_ellipsis && d->hasBind("...")) {
textToInsert.append(ellipsisArg);
} else {
textToInsert.append(str.str() + QString::fromLatin1(" "));
}
}
#if defined(KDEVELOP_BGPARSER)
qthread_yield();
#endif
insertCurrent(textToInsert); //also corrects the end-pointer
d->endScope();
m_preprocessorEnabled = preproc;
//m_driver->addMacro(m);
m_currentLine = argsEndAtLine;
m_currentColumn = argsEndAtColumn;
} else if (k != -1) {
tk = CREATE_TOKEN(k, start, currentPosition() - start);
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
} else if (m_skipWordsEnabled) {
QHash< HashedString, QPair<SkipType, QString> >::iterator pos = m_words.find(ide);
if (pos != m_words.end()) {
if ((*pos).first == SkipWordAndArguments) {
readWhiteSpaces();
if (currentChar() == '(')
skip('(', ')');
}
if (!(*pos).second.isEmpty()) {
#if defined(KDEVELOP_BGPARSER)
qthread_yield();
#endif
insertCurrent(QStringLiteral(" ") + (*pos).second + QStringLiteral(" "));
}
} else if ( /*qt_rx.exactMatch(ide) ||*/
ide.str().endsWith(QLatin1String("EXPORT")) ||
(ide.str().startsWith(QLatin1String("Q_EXPORT")) && ide.str() != QLatin1String("Q_EXPORT_INTERFACE")) ||
ide.str().startsWith(QLatin1String("QM_EXPORT")) ||
ide.str().startsWith(QLatin1String("QM_TEMPLATE"))) {
readWhiteSpaces();
if (currentChar() == '(')
skip('(', ')');
} else if (ide.str().startsWith(QLatin1String("K_TYPELIST_")) || ide.str().startsWith(QLatin1String("TYPELIST_"))) {
tk = CREATE_TOKEN(Token_identifier, start, currentPosition() - start);
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
readWhiteSpaces();
if (currentChar() == '(')
skip('(', ')');
} else {
tk = CREATE_TOKEN(Token_identifier, start, currentPosition() - start);
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
}
} else {
tk = CREATE_TOKEN(Token_identifier, start, currentPosition() - start);
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
}
} else if (ch.isNumber()) {
int start = currentPosition();
readNumberLiteral();
tk = CREATE_TOKEN(Token_number_literal, start, currentPosition() - start);
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
} else if (-1 != (op = findOperator3())) {
tk = CREATE_TOKEN(op, currentPosition(), 3);
nextChar(3);
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
} else if (-1 != (op = findOperator2())) {
tk = CREATE_TOKEN(op, currentPosition(), 2);
nextChar(2);
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
} else {
tk = CREATE_TOKEN(ch.unicode(), currentPosition(), 1);
nextChar();
tk.setStartPosition(startLine, startColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
}
m_startLine = false;
}
void Lexer::tokenize()
{
m_startLine = true;
m_size = 0;
while (currentPosition() >= 0) {
Token tk(m_source);
nextToken(tk);
if (tk.type() != -1)
ADD_TOKEN(tk);
if (currentChar().isNull())
break;
}
Token tk = CREATE_TOKEN(Token_eof, currentPosition(), 0);
tk.setStartPosition(m_currentLine, m_currentColumn);
tk.setEndPosition(m_currentLine, m_currentColumn);
ADD_TOKEN(tk);
}
void Lexer::resetSkipWords()
{
m_words.clear();
}
void Lexer::addSkipWord(const QString& word, SkipType skipType, const QString& str)
{
m_words[ word ] = qMakePair(skipType, str);
}
void Lexer::skip(int l, int r)
{
int svCurrentLine = m_currentLine;
int svCurrentColumn = m_currentColumn;
int count = 0;
while (!eof()) {
Token tk(m_source);
nextToken(tk);
if ((int)tk == l)
++count;
else if ((int)tk == r)
--count;
if (count == 0)
break;
}
m_currentLine = svCurrentLine;
m_currentColumn = svCurrentColumn;
}
QString Lexer::readArgument()
{
int count = 0;
QString arg;
if (!readWhiteSpaces())
return QString();
while (!currentChar().isNull()) {
readWhiteSpaces();
QChar ch = currentChar();
if (ch.isNull() || (!count && (ch == ',' || ch == ')')))
break;
Token tk(m_source);
nextToken(tk);
if (tk == '(') {
++count;
} else if (tk == ')') {
--count;
}
if (tk != -1)
arg += tk.text() + ' ';
}
return arg.trimmed();
}
void Lexer::handleDirective(const QString& directive)
{
m_inPreproc = true;
bool skip = skipWordsEnabled();
bool preproc = preprocessorEnabled();
setSkipWordsEnabled(false);
setPreprocessorEnabled(false);
if (directive == "define") {
if (!m_skipping[ m_ifLevel ]) {
Macro m;
processDefine(m);
}
} else if (directive == "else") {
processElse();
} else if (directive == "elif") {
processElif();
} else if (directive == "endif") {
processEndif();
} else if (directive == "if") {
processIf();
} else if (directive == "ifdef") {
processIfdef();
} else if (directive == "ifndef") {
processIfndef();
} else if (directive == "include") {
if (!m_skipping[ m_ifLevel ]) {
processInclude();
}
} else if (directive == "undef") {
if (!m_skipping[ m_ifLevel ]) {
processUndef();
}
}
// skip line
while (!currentChar().isNull() && currentChar() != '\n') {
Token tk(m_source);
nextToken(tk, true);
}
setSkipWordsEnabled(skip);
setPreprocessorEnabled(preproc);
m_inPreproc = false;
}
int Lexer::testIfLevel()
{
int rtn = !m_skipping[ m_ifLevel++ ];
m_skipping[ m_ifLevel ] = m_skipping[ m_ifLevel - 1 ];
return rtn;
}
int Lexer::macroDefined()
{
if (!readWhiteSpaces(false))
return 0;
if (currentPosition() < 0)
return 0;
int startWord = currentPosition();
readIdentifier();
HashedString word = m_source.mid(startWord, currentPosition() - startWord);
m_driver->usingString(word);
bool r = m_driver->hasMacro(word);
if (r) m_driver->usingMacro(m_driver->macro(word));
return r;
}
void Lexer::processDefine(Macro& m)
{
m.setFileName(m_driver->currentFileName());
m.setLine(m_currentLine);
m.setColumn(m_currentColumn);
if (!readWhiteSpaces(false))
return;
if (currentPosition() < 0)
return;
int startMacroName = currentPosition();
readIdentifier();
QString macroName = m_source.mid(startMacroName, int(currentPosition()-startMacroName));
m.setName(macroName);
if (currentChar() == '(') {
m.setHasArguments(true);
nextChar();
readWhiteSpaces(false);
while (!currentChar().isNull() && currentChar() != ')') {
readWhiteSpaces(false);
int startArg = currentPosition();
if (currentChar() == '.' && peekChar() == '.' && peekChar(2) == '.')
nextChar(3);
else
readIdentifier();
QString arg = m_source.mid(startArg, int(currentPosition()-startArg));
m.addArgument(Macro::Argument(arg));
readWhiteSpaces(false);
if (currentChar() != ',')
break;
nextChar(); // skip ','
}
if (currentChar() == ')')
nextChar(); // skip ')'
}
setPreprocessorEnabled(true);
QString body;
while (!currentChar().isNull() && currentChar() != '\n') {
if (currentChar().isSpace()) {
readWhiteSpaces(false);
body += ' ';
} else {
Token tk(m_source);
nextToken(tk, true);
//Do not ignore c-style comments, those may be useful in the body, and ignoring them using this check causes problems
if (tk.type() != -1 && (tk.type() != Token_comment || (tk.text().length() >= 2 && tk.text()[1] == '*'))) {
QString s = tk.text();
body += s;
}
}
}
m.setBody(body);
m_driver->addMacro(m);
}
void Lexer::processElse()
{
if (m_ifLevel == 0)
/// @todo report error
return;
if (m_ifLevel > 0 && m_skipping[m_ifLevel-1])
m_skipping[ m_ifLevel ] = m_skipping[ m_ifLevel - 1 ];
else
m_skipping[ m_ifLevel ] = m_trueTest[ m_ifLevel ];
}
void Lexer::processElif()
{
if (m_ifLevel == 0)
/// @todo report error
return;
if (!m_trueTest[m_ifLevel]) {
/// @todo implement the correct semantic for elif!!
bool inSkip = m_ifLevel > 0 && m_skipping[ m_ifLevel-1 ];
m_trueTest[ m_ifLevel ] = macroExpression() != 0;
m_skipping[ m_ifLevel ] = inSkip ? inSkip : !m_trueTest[ m_ifLevel ];
} else
m_skipping[ m_ifLevel ] = true;
}
void Lexer::processEndif()
{
if (m_ifLevel == 0)
/// @todo report error
return;
m_skipping[ m_ifLevel ] = 0;
m_trueTest[ m_ifLevel-- ] = 0;
}
void Lexer::processIf()
{
bool inSkip = m_skipping[ m_ifLevel ];
if (testIfLevel()) {
#if 0
int n;
if ((n = testDefined()) != 0) {
int isdef = macroDefined();
m_trueTest[ m_ifLevel ] = (n == 1 && isdef) || (n == -1 && !isdef);
} else
#endif
m_trueTest[ m_ifLevel ] = macroExpression() != 0;
m_skipping[ m_ifLevel ] = inSkip ? inSkip : !m_trueTest[ m_ifLevel ];
}
}
void Lexer::processIfdef()
{
bool inSkip = m_skipping[ m_ifLevel ];
if (testIfLevel()) {
m_trueTest[ m_ifLevel ] = macroDefined();
m_skipping[ m_ifLevel ] = inSkip ? inSkip : !m_trueTest[ m_ifLevel ];
}
}
void Lexer::processIfndef()
{
bool inSkip = m_skipping[ m_ifLevel ];
if (testIfLevel()) {
m_trueTest[ m_ifLevel ] = !macroDefined();
m_skipping[ m_ifLevel ] = inSkip ? inSkip : !m_trueTest[ m_ifLevel ];
}
}
void Lexer::processInclude()
{
if (m_skipping[m_ifLevel])
return;
readWhiteSpaces(false);
if (!currentChar().isNull()) {
QChar ch = currentChar();
if (ch == '"' || ch == '<') {
nextChar();
QChar ch2 = ch == QLatin1Char('"') ? QLatin1Char('"') : QLatin1Char('>');
int startWord = currentPosition();
if (startWord < 0)
return;
while (!currentChar().isNull() && currentChar() != ch2)
nextChar();
if (currentPosition() < 0)
return;
if (!currentChar().isNull()) {
QString word = m_source.mid(startWord, int(currentPosition()-startWord));
m_driver->addDependence(m_driver->currentFileName(),
Dependence(word, ch == '"' ? Dep_Local : Dep_Global));
nextChar();
}
}
}
}
void Lexer::processUndef()
{
readWhiteSpaces();
int startWord = currentPosition();
readIdentifier();
QString word = m_source.mid(startWord, currentPosition() - startWord);
Macro m(word, "");
m.setFileName(m_driver->currentFileName());
m.setUndef();
///Adds an undef-macro that shadows the previous macro
m_driver->addMacro(m);
}
int Lexer::macroPrimary()
{
if (!readWhiteSpaces(false))
return 0;
int result = 0;
switch (currentChar().toLatin1()) {
case '(':
nextChar();
result = macroExpression();
if (currentChar() != ')') {
/// @todo report error
return 0;
}
nextChar();
return result;
case '+':
case '-':
case '!':
case '~': {
QChar tk = currentChar();
nextChar();
int result = macroPrimary();
if (tk == '-') return -result;
else if (tk == '!') return !result;
else if (tk == '~') return ~result;
}
break;
default: {
Token tk(m_source);
nextToken(tk, false);
switch (tk.type()) {
case Token_identifier:
if (tk.text() == "defined") {
return macroPrimary();
}
/// @todo implement
{
HashedString h(tk.text());
m_driver->usingString(h);
if (m_driver->hasMacro(h)) {
m_driver->usingMacro(m_driver->macro(h));
Macro &m = m_driver->macro(h);
Lexer lexer(m_driver);
lexer.setSource(m.body());
int result = lexer.macroExpression();
return result;
} else {
return false;
}
}
case Token_number_literal:
case Token_char_literal:
return toInt(tk);
default:
break;
} // end switch
} // end default
} // end switch
return 0;
}
int Lexer::macroMultiplyDivide()
{
int result = macroPrimary();
int iresult, op;
while (readWhiteSpaces(false)) {
if (currentChar() == '*')
op = 0;
else if (currentChar() == '/' && !(peekChar() == '*' || peekChar() == '/'))
op = 1;
else if (currentChar() == '%')
op = 2;
else
break;
nextChar();
iresult = macroPrimary();
result = op == 0 ? (result * iresult) :
op == 1 ? (iresult == 0 ? 0 : (result / iresult)) :
(iresult == 0 ? 0 : (result % iresult)) ;
}
return result;
}
int Lexer::macroAddSubtract()
{
int result = macroMultiplyDivide();
int iresult, ad;
if (!readWhiteSpaces(false))
return result;
while (currentChar() == '+' || currentChar() == '-') {
ad = currentChar() == '+';
nextChar();
iresult = macroMultiplyDivide();
result = ad ? (result+iresult) : (result-iresult);
}
return result;
}
int Lexer::macroRelational()
{
int result = macroAddSubtract();
int iresult;
if (!readWhiteSpaces(false))
return result;
while (currentChar() == '<' || currentChar() == '>') {
int lt = currentChar() == '<';
nextChar();
if (currentChar() == '=') {
nextChar();
iresult = macroAddSubtract();
result = lt ? (result <= iresult) : (result >= iresult);
} else {
iresult = macroAddSubtract();
result = lt ? (result < iresult) : (result > iresult);
}
}
return result;
}
int Lexer::macroEquality()
{
int result = macroRelational();
int iresult, eq;
if (!readWhiteSpaces(false))
return result;
while ((currentChar() == '=' || currentChar() == '!') && peekChar() == '=') {
eq = currentChar() == '=';
nextChar(2);
iresult = macroRelational();
result = eq ? (result==iresult) : (result!=iresult);
}
return result;
}
int Lexer::macroBoolAnd()
{
int result = macroEquality();
if (!readWhiteSpaces(false))
return result;
while (currentChar() == '&' && peekChar() != '&') {
nextChar();
result &= macroEquality();
}
return result;
}
int Lexer::macroBoolXor()
{
int result = macroBoolAnd();
if (!readWhiteSpaces(false))
return result;
while (currentChar() == '^') {
nextChar();
result ^= macroBoolAnd();
}
return result;
}
int Lexer::macroBoolOr()
{
int result = macroBoolXor();
if (!readWhiteSpaces(false))
return result;
while (currentChar() == '|' && peekChar() != '|') {
nextChar();
result |= macroBoolXor();
}
return result;
}
int Lexer::macroLogicalAnd()
{
int result = macroBoolOr();
if (!readWhiteSpaces(false))
return result;
while (currentChar() == '&' && peekChar() == '&') {
nextChar(2);
int start = currentPosition();
result = macroBoolOr() && result;
QString s = m_source.mid(start, currentPosition() - start);
}
return result;
}
int Lexer::macroLogicalOr()
{
int result = macroLogicalAnd();
if (!readWhiteSpaces(false))
return result;
while (currentChar() == '|' && peekChar() == '|') {
nextChar(2);
result = macroLogicalAnd() || result;
}
return result;
}
int Lexer::macroExpression()
{
if (!readWhiteSpaces(false))
return 0;
return macroLogicalOr();
}
| 42,920
|
C++
|
.cpp
| 1,359
| 23.609272
| 155
| 0.538964
|
KDE/umbrello
| 114
| 36
| 0
|
GPL-2.0
|
9/20/2024, 9:41:49 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.