File indexing completed on 2024-05-05 16:42:26

0001 /*
0002     SPDX-FileCopyrightText: 2013 Sven Brauch <svenbrauch@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #ifndef CORRECTIONHELPER_H
0008 #define CORRECTIONHELPER_H
0009 
0010 #include <language/duchain/types/abstracttype.h>
0011 #include <language/duchain/ducontext.h>
0012 #include <language/duchain/topducontext.h>
0013 
0014 #include <QStack>
0015 
0016 using namespace KDevelop;
0017 
0018 namespace Python {
0019 
0020 class DeclarationBuilder;
0021 
0022 class CorrectionHelper
0023 {
0024 public:
0025     CorrectionHelper(const IndexedString& url, DeclarationBuilder* builder);
0026     virtual ~CorrectionHelper();
0027 
0028     /// Keep this object alive as long as you are parsing a class or function.
0029     /// On destruction, it will automatically leave that class or function.
0030     struct Recursion {
0031         Recursion(CorrectionHelper* h) : m_helper(h) { };
0032         ~Recursion() {
0033             m_helper->leave();
0034         };
0035         CorrectionHelper* m_helper;
0036     };
0037 
0038     Recursion enterClass(const QString& identifier);
0039     Recursion enterFunction(const QString& identifier);
0040 
0041     AbstractType::Ptr hintForLocal(const QString& local) const;
0042     AbstractType::Ptr returnTypeHint() const;
0043 
0044 private:
0045     AbstractType::Ptr hintFor(const KDevelop::Identifier& identifier) const;
0046     void enter(const Identifier& identifier);
0047     void leave();
0048 
0049     ReferencedTopDUContext m_hintTopContext;
0050     QStack<DUContext*> m_contextStack;
0051 };
0052 
0053 } // namespace Python
0054 
0055 #endif // CORRECTIONHELPER_H