2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2010-05-28 15:25:24 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2010-05-28 15:25:24 +02:00
|
|
|
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <cplusplus/ASTfwd.h>
|
|
|
|
|
#include <cplusplus/ASTVisitor.h>
|
2010-05-28 15:25:24 +02:00
|
|
|
|
2010-05-28 17:17:11 +02:00
|
|
|
#include "CppDocument.h"
|
2010-05-28 15:25:24 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QList>
|
|
|
|
|
#include <QTextCursor>
|
2010-05-28 15:25:24 +02:00
|
|
|
|
2013-04-23 15:04:36 +02:00
|
|
|
#undef WITH_AST_PATH_DUMP
|
2010-05-28 15:25:24 +02:00
|
|
|
|
|
|
|
|
namespace CPlusPlus {
|
|
|
|
|
|
|
|
|
|
class CPLUSPLUS_EXPORT ASTPath: public ASTVisitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ASTPath(Document::Ptr doc)
|
|
|
|
|
: ASTVisitor(doc->translationUnit()),
|
|
|
|
|
_doc(doc), _line(0), _column(0)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
QList<AST *> operator()(const QTextCursor &cursor)
|
2011-08-17 11:35:57 +02:00
|
|
|
{ return this->operator()(cursor.blockNumber() + 1, cursor.positionInBlock() + 1); }
|
2010-05-28 15:25:24 +02:00
|
|
|
|
2011-08-17 11:35:57 +02:00
|
|
|
/// line and column are 1-based!
|
2010-05-28 15:25:24 +02:00
|
|
|
QList<AST *> operator()(int line, int column);
|
|
|
|
|
|
2013-04-23 15:04:36 +02:00
|
|
|
#ifdef WITH_AST_PATH_DUMP
|
2010-05-28 15:25:24 +02:00
|
|
|
static void dump(const QList<AST *> nodes);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
protected:
|
2015-07-30 18:15:07 +02:00
|
|
|
bool preVisit(AST *ast) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
unsigned firstNonGeneratedToken(AST *ast) const;
|
|
|
|
|
unsigned lastNonGeneratedToken(AST *ast) const;
|
2010-05-28 15:25:24 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Document::Ptr _doc;
|
2019-07-24 18:40:10 +02:00
|
|
|
int _line;
|
|
|
|
|
int _column;
|
2010-05-28 15:25:24 +02:00
|
|
|
QList<AST *> _nodes;
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
} // namespace CPlusPlus
|