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

0001 /*
0002     SPDX-FileCopyrightText: 2007 Piyush verma <piyush.verma@gmail.com>
0003     SPDX-FileCopyrightText: 2010-2013 Sven Brauch <svenbrauch@googlemail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef USEBUILDER_H
0009 #define USEBUILDER_H
0010 
0011 #include "contextbuilder.h"
0012 #include "pythonduchainexport.h"
0013 #include "pythoneditorintegrator.h"
0014 #include "ast.h"
0015 
0016 #include <language/duchain/builders/abstractusebuilder.h>
0017 
0018 #include <QStack>
0019 
0020 namespace Python {
0021 
0022 class ParseSession;
0023 
0024 typedef KDevelop::AbstractUseBuilder<Ast, Identifier, ContextBuilder> UseBuilderBase;
0025 
0026 class KDEVPYTHONDUCHAIN_EXPORT UseBuilder: public UseBuilderBase
0027 {
0028 public:
0029     /// vector of names to ignore since they were unknown imports
0030     UseBuilder(PythonEditorIntegrator *editor, QVector<IndexedString> ignoreVariables);
0031     ParseSession* parseSession() const;
0032 
0033 protected:
0034     void visitName(NameAst* node) override;
0035     void visitCall(CallAst* node) override;
0036     void visitAttribute(AttributeAst* node) override;
0037     void visitSubscript(SubscriptAst* node) override;
0038     void visitMatchAs(MatchAsAst* node) override;
0039 
0040 private:
0041     ParseSession* m_session;
0042     inline int& nextUseIndex()
0043     {
0044         return m_nextUseStack.top();
0045     }
0046     QStack<int> m_nextUseStack;
0047     bool m_errorReportingEnabled;
0048     inline void disableErrorReporting() {
0049         m_errorReportingEnabled = false;
0050     };
0051     inline void enableErrorReporting() {
0052         m_errorReportingEnabled = true;
0053     };
0054     DUContext* contextAtOrCurrent(const CursorInRevision& pos);
0055     // Add a use for `method` immediately after `value`.
0056     void useHiddenMethod(ExpressionAst* value, Declaration* method);
0057 
0058     QVector<IndexedString> m_ignoreVariables;
0059 };
0060 
0061 }
0062 
0063 #endif
0064 // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on; auto-insert-doxygen on