diff --git a/codecompletion/items/functiondeclaration.h b/codecompletion/items/functiondeclaration.h index 2e301a57..fb0b343e 100644 --- a/codecompletion/items/functiondeclaration.h +++ b/codecompletion/items/functiondeclaration.h @@ -1,55 +1,54 @@ /***************************************************************************** * Copyright (c) 2011 Sven Brauch * * * * 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, see . * ***************************************************************************** */ #ifndef FUNCTIONDECLARATIONCOMPLETIONITEM_H #define FUNCTIONDECLARATIONCOMPLETIONITEM_H #include #include #include "declaration.h" using namespace KDevelop; namespace Python { class FunctionDeclarationCompletionItem : public Python::PythonDeclarationCompletionItem { public: FunctionDeclarationCompletionItem(DeclarationPointer decl, KDevelop::CodeCompletionContext::Ptr context); virtual ~FunctionDeclarationCompletionItem(); - virtual int argumentHintDepth() const; + int argumentHintDepth() const override; virtual int atArgument() const; void setAtArgument(int d); void setDepth(int d); void setDoNotCall(bool doNotCall); - - virtual QVariant data(const QModelIndex& index, int role, const CodeCompletionModel* model) const; - - virtual void executed(KTextEditor::View* view, const KTextEditor::Range& word) override; + + QVariant data(const QModelIndex& index, int role, const CodeCompletionModel* model) const override; + void executed(KTextEditor::View* view, const KTextEditor::Range& word) override; private: int m_atArgument; int m_depth; // indicates that no parentheses should be added when executing this item, // e.g. for import completion or inheritance bool m_doNotCall; }; } #endif // FUNCTIONDECLARATIONCOMPLETIONITEM_H diff --git a/codecompletion/items/implementfunction.h b/codecompletion/items/implementfunction.h index dfd838ef..facdf17d 100644 --- a/codecompletion/items/implementfunction.h +++ b/codecompletion/items/implementfunction.h @@ -1,43 +1,43 @@ /***************************************************************************** * Copyright (c) 2011 Sven Brauch * * * * 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, see . * ***************************************************************************** */ #ifndef IMPLEMENTFUNCTIONCOMPLETIONITEM_H #define IMPLEMENTFUNCTIONCOMPLETIONITEM_H #include #include using namespace KDevelop; namespace Python { class ImplementFunctionCompletionItem : public CompletionTreeItem { public: ImplementFunctionCompletionItem(const QString& name, const QStringList& arguments, const QString& previousIndent); - virtual void execute(KTextEditor::View* view, const KTextEditor::Range& word) override; - virtual QVariant data(const QModelIndex& index, int role, const CodeCompletionModel* model) const; + void execute(KTextEditor::View* view, const KTextEditor::Range& word) override; + QVariant data(const QModelIndex& index, int role, const CodeCompletionModel* model) const override; private: QStringList m_arguments; QString m_name; QString m_previousIndent; }; } // namespace Python #endif // IMPLEMENTFUNCTIONCOMPLETIONITEM_H diff --git a/codecompletion/items/replacementvariable.h b/codecompletion/items/replacementvariable.h index 5f22cb69..58eb4c4b 100644 --- a/codecompletion/items/replacementvariable.h +++ b/codecompletion/items/replacementvariable.h @@ -1,46 +1,46 @@ /***************************************************************************** * Copyright (c) 2013 Atanas Gospodinov * * * * 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, see . * ***************************************************************************** */ #ifndef REPLACEMENTVARIABLE_H #define REPLACEMENTVARIABLE_H #include #include "codecompletion/helpers.h" using namespace KDevelop; namespace Python { class ReplacementVariableItem : public CompletionTreeItem { public: ReplacementVariableItem(const ReplacementVariable &variable, const QString &description, bool hasEditableFields, KTextEditor::Range position = KTextEditor::Range::invalid()); - virtual void execute(KTextEditor::View* view, const KTextEditor::Range& word) override; - virtual QVariant data(const QModelIndex& index, int role, const KDevelop::CodeCompletionModel* model) const; + void execute(KTextEditor::View* view, const KTextEditor::Range& word) override; + QVariant data(const QModelIndex& index, int role, const KDevelop::CodeCompletionModel* model) const override; private: ReplacementVariable m_variable; QString m_description; bool m_hasEditableFields; KTextEditor::Range m_position; }; } #endif // REPLACEMENTVARIABLE_H diff --git a/duchain/declarationbuilder.h b/duchain/declarationbuilder.h index df714f6a..c1aba95d 100644 --- a/duchain/declarationbuilder.h +++ b/duchain/declarationbuilder.h @@ -1,314 +1,314 @@ /***************************************************************************** * Copyright (c) 2007 Piyush verma * * Copyright 2007 Andreas Pakulat * * Copyright 2011-2014 Sven Brauch * * * * 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, see . * ***************************************************************************** */ #ifndef PYTHON_DECLARATIONBUILDER_H #define PYTHON_DECLARATIONBUILDER_H #include #include #include "declarations/functiondeclaration.h" #include "typebuilder.h" #include "ast.h" namespace Python { class CorrectionHelper; typedef KDevelop::AbstractDeclarationBuilder DeclarationBuilderBase; class KDEVPYTHONDUCHAIN_EXPORT DeclarationBuilder: public DeclarationBuilderBase { public: DeclarationBuilder(PythonEditorIntegrator* editor, int ownPriority = 0); virtual ~DeclarationBuilder(); /** * @brief Entry function, called by KDevPlatform. */ - virtual ReferencedTopDUContext build(const IndexedString& url, Ast* node, - ReferencedTopDUContext updateContext = ReferencedTopDUContext()); + ReferencedTopDUContext build(const IndexedString& url, Ast* node, + ReferencedTopDUContext updateContext = ReferencedTopDUContext()) override; /** * @brief Set whether the current running pass is the first or the second one. * @param prebuilding true if first pass, false if second */ void setPrebuilding(bool prebuilding); /** * @brief Priority of this parse job. */ int jobPriority() const; /** * @brief Get the docstring which belongs to the given body * @param body Body of statements which is in the documented function or class */ QString getDocstring(QList body) const; /** * @brief Construct the dotted name of a module from an import ... from ... as statement. * * @param node the import ... from node * @param alias the ... as ... node * @param intermediate an additional string to prepend to the module name (dot is added internally) */ QString buildModuleNameFromNode(ImportFromAst* node, AliasAst* alias, const QString& intermediate) const; /** * @brief Get a list of all module names which were not found while parsing. */ QVector missingModules() const { return m_missingModules; } protected: /// AST visitor functions void visitClassDefinition(ClassDefinitionAst* node) override; void visitFunctionDefinition(FunctionDefinitionAst* node) override; void visitAssignment(AssignmentAst* node) override; void visitFor(ForAst* node) override; void visitImport(ImportAst* node) override; void visitImportFrom(ImportFromAst* node) override; void visitArguments(ArgumentsAst* node) override; void visitExceptionHandler(ExceptionHandlerAst* node) override; void visitReturn(ReturnAst* node) override; void visitCode(CodeAst* node) override; void visitCall(CallAst* node) override; void visitYield(YieldAst* node) override; void visitWithItem(WithItemAst* node) override; void visitLambda(LambdaAst* node) override; void visitComprehension(ComprehensionAst* node) override; void visitGlobal(GlobalAst* node) override; void visitAssertion(AssertionAst* node) override; void visitIf(IfAst* node) override; void visitString(StringAst* node) override; void visitNode(Ast* node) override; protected: enum VisitVariableFlags { NoVisitVariableFlags = 0x0, AbortIfReopenMismatch = 0x1 }; /// Visitor helper functions template void visitDecorators(QList decorators, T* addTo); template T* visitVariableDeclaration(Python::Ast* node, Declaration* previous=nullptr, AbstractType::Ptr type = AbstractType::Ptr(), VisitVariableFlags flags=NoVisitVariableFlags); template T* visitVariableDeclaration(Identifier* node, Ast* originalAst = 0, Declaration* previous=nullptr, AbstractType::Ptr type = AbstractType::Ptr(), VisitVariableFlags flags=NoVisitVariableFlags); template T* visitVariableDeclaration(Identifier* node, RangeInRevision range, AbstractType::Ptr type = AbstractType::Ptr(), VisitVariableFlags flags=NoVisitVariableFlags); protected: /** * @brief Applies docstring hints, such as "addsType" * @param node the called function * @param function the declaration which belongs to @p node * * Used for example in a = []; a.append(3) to set the type of a to "list of int". */ void applyDocstringHints(CallAst* node, Python::FunctionDeclaration::Ptr function); /** * @brief Try to deduce types of function arguments from a call and stores it in the duchain * @param node the called function * @param function the declaration which belongs to @p node * * Used for example in def f(x): pass; a = f(3) to set the type of x to "int" */ void addArgumentTypeHints(CallAst* node, DeclarationPointer function); /** * @brief Adjust the type of foo in an expression like assert isinstance(fooinstance, Foo) * Does nothing if the given expression isn't of any of the forms * a) isinstance(fooinstance, Foo) * b) type(fooinstance) == Foo */ void adjustForTypecheck(ExpressionAst* check, bool useUnsure); /// Helper for the above void adjustExpressionsForTypecheck(ExpressionAst* adjust, ExpressionAst* from, bool useUnsure); /** * @brief Get a list of the left-hand-side expressions of an assignment. * * @param targets the AST nodes representing the left-hand side of the assignment * * Example: a, (b, c), _ = 3, 5, 7, 9 -> this function returns a, b, c, d */ QList targetsOfAssignment(QList targets) const; /// Represents a single source type in a tuple assignment. struct SourceType { AbstractType::Ptr type; DeclarationPointer declaration; bool isAlias; }; /** * @brief Attempts to determine the unpacked type(s) of the right-hand side of an assignment. * * @param items The expression on the right-hand side of the assignment * @param fillWhenLengthMissing If non-zero and the object in @p items has an indefinite length but * a definite content type, return this many copies of that type * * Example: a, b = [1, 2, 3] and called with @p fillWhenLengthMissing = 2 -> returns int, int * a, b = "Foo", 3.5 (@p fillWhenLengthMissing ignored here because the right-hand side * has a definite amount of items) -> returns str, float */ QList sourcesOfAssignment(ExpressionAst* items, int fillWhenLengthMissing=-1) const; /** * @brief Given a list of targets (@see targetsOfAssignment) and sources (@see sourcesOfAssignment) and a * @p index, matches the sources with the targets and returns the type which belongs to @p index. * * @param targets Left-hand side of the assignment * @param sources Right-hand side of the assignment * @param index index of the item to return the type for * @param rhs Pass the right-hand side of the assignment again so that its compound type can be used in case * it consists of more than one element and unpacking is not possible; example: a = 1, 2 */ SourceType selectSource(const QList& targets, const QList& sources, int index, ExpressionAst* rhs) const; /** * @brief Handle a variable assignment to @p name and give it the type @p element. */ void assignToName(NameAst* name, const SourceType& element); /** * @brief Handle assignment to subscript @p subscript with rhs type @p element. */ void assignToSubscript(SubscriptAst* subscript, const SourceType& element); /** * @brief Handle assignment to an attribute @p attribute with rhs type @p element. */ void assignToAttribute(AttributeAst* attribute, const SourceType& element); /** * @brief Find all existing declarations for the identifier @p node */ QList existingDeclarationsForNode(Identifier* node); enum FitDeclarationType { NoTypeRequired, InstanceDeclarationType, AliasDeclarationType, FunctionDeclarationType }; FitDeclarationType kindForType(AbstractType::Ptr type, bool isAlias = false); /** * @brief schedule an object to be deleted when the declaration builder is destroyed * this is used to bypass the automated duchain cleanup for imports */ void scheduleForDeletion(DUChainBase* d, bool doschedule = true); /** * @brief python-specific version of openDeclaration which scans for existing declarations in previous versions of * this top-context in a more intelligent way. * Use this in normal declaratonbuilder code if you can't use visitVariableDeclaration. */ template T* eventuallyReopenDeclaration(Python::Identifier* name, Python::Ast* range, FitDeclarationType mustFitType); template QList reopenFittingDeclaration(QList declarations, FitDeclarationType mustFitType, RangeInRevision updateRangeTo, Declaration** ok); /** * @brief Create a declaration for an import statement. * * @param dottedName The dotted name of the module, like "random.randint". * @param declarationIdentifier provides the name and range * @param rangeNode can be used to override the declarationIdentifier's range, if required. Defaults to 0. * @param createProblem whether or not to create DUChain problems Defaults to CreateProblems. * @return :Declaration* the declaration created, or 0 if none was found. **/ Declaration* createModuleImportDeclaration(QString dottedName, QString declarationName, Python::Identifier* declarationIdentifier, ProblemPointer& problemEncountered, Python::Ast* rangeNode = 0); /** * @brief Create a tree of declarations for the specified list. * Give the list ["foo","bar","baz"], and you'll get a declaration "foo" containing "bar" in its internal context, * "bar" containing "baz" etc. * This is used in import handling. * This function automatically updates existing declaration trees to the maximum level possible! Thus, * if you call this with ["foo", "bar"], then ["foo", "baz"], "baz" will be added to "foo". * * @warning The DUChain must not be locked when this is called. * * @param nameComponents the list of names to create declarations for * @param declarationIdentifier provides the name and range * @param innerCtx the internalContext() to set on the last created declaration. Either this or aliasDeclaration must be provided! * @param aliasDeclaration the declaration to alias with the last created declaration * @param rangeNode can be used to override the declarationIdentifier's range, if required. Defaults to 0. * @return :Declaration* the top level declaration created **/ Declaration* createDeclarationTree(const QStringList& nameComponents, Identifier* declarationIdentifier, const ReferencedTopDUContext& innerCtx, Declaration* aliasDeclaration = 0, const RangeInRevision& range = RangeInRevision::invalid()); /** * @brief Find a declaration specified by "foo.bar.baz" in the given top context. * * @param dottedNameIdentifier string list of module names, starting with the most general one. * @param ctx top context to search * @return :Declaration* declaration if found, 0 otherwise. * * This will traverse nested classes and properties until the list of passed names is exhausted. * @warning The DUChain must not be locked. **/ Declaration* findDeclarationInContext(QStringList dottedNameIdentifier, TopDUContext* ctx) const; private: template T* openDeclaration(Identifier* name, Ast* range, DeclarationFlags flags = NoFlags) { T* decl = DeclarationBuilderBase::openDeclaration(name, range, flags); decl->setAlwaysForceDirect(true); return decl; }; template T* openDeclaration(const QualifiedIdentifier& id, const RangeInRevision& newRange, DeclarationFlags flags = NoFlags) { T* decl = DeclarationBuilderBase::openDeclaration(id, newRange, flags); decl->setAlwaysForceDirect(true); return decl; }; - virtual void closeDeclaration(); + void closeDeclaration() override; private: /// HACK: List of items to delete after parsing finishes, to work around the built-in cleanup logic QList m_scheduledForDeletion; QScopedPointer m_correctionHelper; int m_ownPriority = 0; StructureType::Ptr m_currentClassType; // missing modules, for not reporting them as unknown variables QVector m_missingModules; StringAst* m_lastComment = nullptr; }; } #endif // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on; auto-insert-doxygen on diff --git a/duchain/types/unsuretype.h b/duchain/types/unsuretype.h index 282ff0ba..0fb7368f 100644 --- a/duchain/types/unsuretype.h +++ b/duchain/types/unsuretype.h @@ -1,75 +1,75 @@ /** This file is part of KDevelop Copyright (C) 2011 Sven Brauch 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, see . **/ #ifndef PYTHON_UNSURETYPE_H #define PYTHON_UNSURETYPE_H #include "pythonduchainexport.h" #include "hintedtype.h" #include #include #include #include #include #include #include #include #include #include #include namespace Python { class KDEVPYTHONDUCHAIN_EXPORT UnsureType : public KDevelop::UnsureType { public: typedef KDevelop::TypePtr Ptr; UnsureType(); UnsureType(const UnsureType& rhs); UnsureType(KDevelop::UnsureTypeData& data); WhichType whichType() const override; AbstractType* clone() const override; uint hash() const override; QString toString() const override; - void addType(IndexedType type); + void addType(IndexedType type) override; const QList typesRecursive() const; bool equals(const AbstractType* rhs) const override; enum { // #warning check identity value (63) Identity = 63 }; typedef KDevelop::UnsureTypeData Data; typedef KDevelop::UnsureType BaseType; protected: TYPE_DECLARE_DATA(KDevelop::UnsureType); }; } #endif // UNSURETYPE_H