summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpplocalsymbols.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2021-08-30 10:58:08 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2021-09-01 14:53:58 +0000
commit284817fae6514701902ccdb834c2faa46462f2e8 (patch)
tree44a8c7d9813dc110b61c4639036366c7696bd7e9 /src/plugins/cpptools/cpplocalsymbols.cpp
parent3e1fa0f170d523971d2c3c12da15a6e291f56511 (diff)
downloadqt-creator-284817fae6514701902ccdb834c2faa46462f2e8.tar.gz
Merge CppTools into CppEditor
There was no proper separation of responsibilities between these plugins. In particular, CppTools had lots of editor-related functionality, so it's not clear why it was separated out in the first place. In fact, for a lot of code, it seemed quite arbitrary where it was put (just one example: switchHeaderSource() was in CppTools, wheras switchDeclarationDefinition() was in CppEditor). Merging the plugins will enable us to get rid of various convoluted pseudo-abstractions that were only introduced to keep up the artificial separation. Change-Id: Iafc3bce625b4794f6d4aa03df6cddc7f2d26716a Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/cpptools/cpplocalsymbols.cpp')
-rw-r--r--src/plugins/cpptools/cpplocalsymbols.cpp309
1 files changed, 0 insertions, 309 deletions
diff --git a/src/plugins/cpptools/cpplocalsymbols.cpp b/src/plugins/cpptools/cpplocalsymbols.cpp
deleted file mode 100644
index 36ce87ce49..0000000000
--- a/src/plugins/cpptools/cpplocalsymbols.cpp
+++ /dev/null
@@ -1,309 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-****************************************************************************/
-
-#include "cpplocalsymbols.h"
-#include "semantichighlighter.h"
-
-#include "cppsemanticinfo.h"
-
-using namespace CPlusPlus;
-using namespace CppTools;
-
-namespace {
-
-class FindLocalSymbols: protected ASTVisitor
-{
-public:
- explicit FindLocalSymbols(Document::Ptr doc)
- : ASTVisitor(doc->translationUnit())
- { }
-
- // local and external uses.
- SemanticInfo::LocalUseMap localUses;
-
- void operator()(DeclarationAST *ast)
- {
- localUses.clear();
-
- if (!ast)
- return;
-
- if (FunctionDefinitionAST *def = ast->asFunctionDefinition()) {
- if (def->symbol) {
- accept(ast);
- }
- } else if (ObjCMethodDeclarationAST *decl = ast->asObjCMethodDeclaration()) {
- if (decl->method_prototype->symbol) {
- accept(ast);
- }
- }
- }
-
-protected:
- using ASTVisitor::visit;
- using ASTVisitor::endVisit;
-
- using HighlightingResult = TextEditor::HighlightingResult;
-
- void enterScope(Scope *scope)
- {
- _scopeStack.append(scope);
-
- for (int i = 0; i < scope->memberCount(); ++i) {
- if (Symbol *member = scope->memberAt(i)) {
- if (member->isTypedef())
- continue;
- if (!member->isGenerated() && (member->isDeclaration() || member->isArgument())) {
- if (member->name() && member->name()->isNameId()) {
- const Token token = tokenAt(member->sourceLocation());
- int line, column;
- getPosition(token.utf16charsBegin(), &line, &column);
- localUses[member].append(
- HighlightingResult(line, column, token.utf16chars(),
- SemanticHighlighter::LocalUse));
- }
- }
- }
- }
- }
-
- bool checkLocalUse(NameAST *nameAst, int firstToken)
- {
- if (SimpleNameAST *simpleName = nameAst->asSimpleName()) {
- const Token token = tokenAt(simpleName->identifier_token);
- if (token.generated())
- return false;
- const Identifier *id = identifier(simpleName->identifier_token);
- for (int i = _scopeStack.size() - 1; i != -1; --i) {
- if (Symbol *member = _scopeStack.at(i)->find(id)) {
- if (member->isTypedef() || !(member->isDeclaration() || member->isArgument()))
- continue;
- if (!member->isGenerated() && (member->sourceLocation() < firstToken
- || member->enclosingScope()->isFunction())) {
- int line, column;
- getTokenStartPosition(simpleName->identifier_token, &line, &column);
- localUses[member].append(
- HighlightingResult(line, column, token.utf16chars(),
- SemanticHighlighter::LocalUse));
- return false;
- }
- }
- }
- }
-
- return true;
- }
-
- bool visit(CaptureAST *ast) override
- {
- return checkLocalUse(ast->identifier, ast->firstToken());
- }
-
- bool visit(IdExpressionAST *ast) override
- {
- return checkLocalUse(ast->name, ast->firstToken());
- }
-
- bool visit(SizeofExpressionAST *ast) override
- {
- if (ast->expression && ast->expression->asTypeId()) {
- TypeIdAST *typeId = ast->expression->asTypeId();
- if (!typeId->declarator && typeId->type_specifier_list && !typeId->type_specifier_list->next) {
- if (NamedTypeSpecifierAST *namedTypeSpec = typeId->type_specifier_list->value->asNamedTypeSpecifier()) {
- if (checkLocalUse(namedTypeSpec->name, namedTypeSpec->firstToken()))
- return false;
- }
- }
- }
-
- return true;
- }
-
- bool visit(CastExpressionAST *ast) override
- {
- if (ast->expression && ast->expression->asUnaryExpression()) {
- TypeIdAST *typeId = ast->type_id->asTypeId();
- if (typeId && !typeId->declarator && typeId->type_specifier_list && !typeId->type_specifier_list->next) {
- if (NamedTypeSpecifierAST *namedTypeSpec = typeId->type_specifier_list->value->asNamedTypeSpecifier()) {
- if (checkLocalUse(namedTypeSpec->name, namedTypeSpec->firstToken())) {
- accept(ast->expression);
- return false;
- }
- }
- }
- }
-
- return true;
- }
-
- bool visit(FunctionDefinitionAST *ast) override
- {
- if (ast->symbol)
- enterScope(ast->symbol);
- return true;
- }
-
- void endVisit(FunctionDefinitionAST *ast) override
- {
- if (ast->symbol)
- _scopeStack.removeLast();
- }
-
- bool visit(LambdaExpressionAST *ast) override
- {
- if (ast->lambda_declarator && ast->lambda_declarator->symbol)
- enterScope(ast->lambda_declarator->symbol);
- return true;
- }
-
- void endVisit(LambdaExpressionAST *ast) override
- {
- if (ast->lambda_declarator && ast->lambda_declarator->symbol)
- _scopeStack.removeLast();
- }
-
- bool visit(CompoundStatementAST *ast) override
- {
- if (ast->symbol)
- enterScope(ast->symbol);
- return true;
- }
-
- void endVisit(CompoundStatementAST *ast) override
- {
- if (ast->symbol)
- _scopeStack.removeLast();
- }
-
- bool visit(IfStatementAST *ast) override
- {
- if (ast->symbol)
- enterScope(ast->symbol);
- return true;
- }
-
- void endVisit(IfStatementAST *ast) override
- {
- if (ast->symbol)
- _scopeStack.removeLast();
- }
-
- bool visit(WhileStatementAST *ast) override
- {
- if (ast->symbol)
- enterScope(ast->symbol);
- return true;
- }
-
- void endVisit(WhileStatementAST *ast) override
- {
- if (ast->symbol)
- _scopeStack.removeLast();
- }
-
- bool visit(ForStatementAST *ast) override
- {
- if (ast->symbol)
- enterScope(ast->symbol);
- return true;
- }
-
- void endVisit(ForStatementAST *ast) override
- {
- if (ast->symbol)
- _scopeStack.removeLast();
- }
-
- bool visit(ForeachStatementAST *ast) override
- {
- if (ast->symbol)
- enterScope(ast->symbol);
- return true;
- }
-
- void endVisit(ForeachStatementAST *ast) override
- {
- if (ast->symbol)
- _scopeStack.removeLast();
- }
-
- bool visit(RangeBasedForStatementAST *ast) override
- {
- if (ast->symbol)
- enterScope(ast->symbol);
- return true;
- }
-
- void endVisit(RangeBasedForStatementAST *ast) override
- {
- if (ast->symbol)
- _scopeStack.removeLast();
- }
-
- bool visit(SwitchStatementAST *ast) override
- {
- if (ast->symbol)
- enterScope(ast->symbol);
- return true;
- }
-
- void endVisit(SwitchStatementAST *ast) override
- {
- if (ast->symbol)
- _scopeStack.removeLast();
- }
-
- bool visit(CatchClauseAST *ast) override
- {
- if (ast->symbol)
- enterScope(ast->symbol);
- return true;
- }
-
- void endVisit(CatchClauseAST *ast) override
- {
- if (ast->symbol)
- _scopeStack.removeLast();
- }
-
- bool visit(ExpressionOrDeclarationStatementAST *ast) override
- {
- accept(ast->declaration);
- return false;
- }
-
-private:
- QList<Scope *> _scopeStack;
-};
-
-} // end of anonymous namespace
-
-
-LocalSymbols::LocalSymbols(Document::Ptr doc, DeclarationAST *ast)
-{
- FindLocalSymbols findLocalSymbols(doc);
- findLocalSymbols(ast);
- uses = findLocalSymbols.localUses;
-}