diff options
author | Nikolai Kosjar <[email protected]> | 2014-08-19 15:59:29 +0200 |
---|---|---|
committer | Nikolai Kosjar <[email protected]> | 2014-08-25 13:06:01 +0200 |
commit | 89bd4ee3c4e4be4b39dee9ef12e798d21be3d2cb (patch) | |
tree | 520ad32c8ff76c22e3ea41006c07012c3053d1d9 /src/plugins/cpptools/cppchecksymbols.cpp | |
parent | 2fa15f221fc2ff2c36995fe904cc3a4837d62760 (diff) |
C++: Base parsing on editor document instead of widget
This mainly takes CppEditorSupport apart.
* Parsing is now invoked by CPPEditorDocument itself by listening to
QTextDocument::contentsChanged().
* Upon construction and destruction CPPEditorDocument creates and
deletes an EditorDocumentHandle for (un)registration in the model
manager. This handle provides everything to generate the working copy
and to access the editor document processor.
* A CPPEditorDocument owns a BaseEditorDocumentProcessor instance that
controls parsing, semantic info recalculation and the semantic
highlighting for the document. This is more or less what is left from
CppEditorSupport and can be considered as the backend of a
CPPEditorDocument. CPPEditorDocument itself is quite small.
* BuiltinEditorDocumentProcessor and ClangEditorDocumentProcessor
derive from BaseEditorDocumentProcessor and implement the gaps.
* Since the semantic info calculation was bound to the widget, it
also calculated the local uses, which depend on the cursor
position. This calculation got moved into the extracted class
UseSeletionsUpdater in the cppeditor plugin, which is run once the
cursor position changes or the semantic info document is updated.
* Some more logic got extracted:
- SemanticInfoUpdater (logic was in CppEditorSupport)
- SemanticHighlighter (logic was in CppEditorSupport)
* The *Parser and *Processor classes can be easily accessed by the
static function get().
* CppHighlightingSupport is gone since it turned out to be useless.
* The editor dependency in CompletionAssistProviders is gone since we
actually only need the file path now.
Change-Id: I49d3a7bd138c5ed9620123e34480772535156508
Reviewed-by: Orgad Shaneh <[email protected]>
Reviewed-by: Erik Verbruggen <[email protected]>
Diffstat (limited to 'src/plugins/cpptools/cppchecksymbols.cpp')
-rw-r--r-- | src/plugins/cpptools/cppchecksymbols.cpp | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/src/plugins/cpptools/cppchecksymbols.cpp b/src/plugins/cpptools/cppchecksymbols.cpp index 4f528d47d6f..eb6974c470b 100644 --- a/src/plugins/cpptools/cppchecksymbols.cpp +++ b/src/plugins/cpptools/cppchecksymbols.cpp @@ -298,6 +298,8 @@ static bool acceptName(NameAST *ast, unsigned *referenceToken) CheckSymbols::Future CheckSymbols::go(Document::Ptr doc, const LookupContext &context, const QList<CheckSymbols::Result> ¯oUses) { QTC_ASSERT(doc, return Future()); + QTC_ASSERT(doc->translationUnit(), return Future()); + QTC_ASSERT(doc->translationUnit()->ast(), return Future()); return (new CheckSymbols(doc, context, macroUses))->start(); } @@ -477,7 +479,7 @@ bool CheckSymbols::visit(NamespaceAST *ast) if (!tok.generated()) { unsigned line, column; getTokenStartPosition(ast->identifier_token, &line, &column); - Result use(line, column, tok.utf16chars(), CppHighlightingSupport::TypeUse); + Result use(line, column, tok.utf16chars(), SemanticHighlighter::TypeUse); addUse(use); } } @@ -492,13 +494,13 @@ bool CheckSymbols::visit(UsingDirectiveAST *) bool CheckSymbols::visit(EnumeratorAST *ast) { - addUse(ast->identifier_token, CppHighlightingSupport::EnumerationUse); + addUse(ast->identifier_token, SemanticHighlighter::EnumerationUse); return true; } bool CheckSymbols::visit(DotDesignatorAST *ast) { - addUse(ast->identifier_token, CppHighlightingSupport::FieldUse); + addUse(ast->identifier_token, SemanticHighlighter::FieldUse); return true; } @@ -513,7 +515,7 @@ bool CheckSymbols::visit(SimpleDeclarationAST *ast) if (funTy->isVirtual() || (nameAST->asDestructorName() && hasVirtualDestructor(_context.lookupType(funTy->enclosingScope())))) { - addUse(nameAST, CppHighlightingSupport::VirtualMethodUse); + addUse(nameAST, SemanticHighlighter::VirtualMethodUse); declrIdNameAST = nameAST; } else if (maybeAddFunction(_context.lookup(decl->name(), decl->enclosingScope()), @@ -521,7 +523,7 @@ bool CheckSymbols::visit(SimpleDeclarationAST *ast) declrIdNameAST = nameAST; // Add a diagnostic message if non-virtual function has override/final marker - if ((_usages.back().kind != CppHighlightingSupport::VirtualMethodUse)) { + if ((_usages.back().kind != SemanticHighlighter::VirtualMethodUse)) { if (funTy->isOverride()) warning(declrIdNameAST, QCoreApplication::translate( "CPlusplus::CheckSymbols", "Only virtual functions can be marked 'override'")); @@ -559,7 +561,7 @@ bool CheckSymbols::visit(ElaboratedTypeSpecifierAST *ast) { accept(ast->attribute_list); accept(ast->name); - addUse(ast->name, CppHighlightingSupport::TypeUse); + addUse(ast->name, SemanticHighlighter::TypeUse); return false; } @@ -796,14 +798,14 @@ void CheckSymbols::checkName(NameAST *ast, Scope *scope) if (klass) { if (hasVirtualDestructor(_context.lookupType(klass))) { - addUse(ast, CppHighlightingSupport::VirtualMethodUse); + addUse(ast, SemanticHighlighter::VirtualMethodUse); } else { bool added = false; if (highlightCtorDtorAsType && maybeType(ast->name)) added = maybeAddTypeOrStatic(_context.lookup(ast->name, klass), ast); if (!added) - addUse(ast, CppHighlightingSupport::FunctionUse); + addUse(ast, SemanticHighlighter::FunctionUse); } } } else if (maybeType(ast->name) || maybeStatic(ast->name)) { @@ -853,14 +855,14 @@ bool CheckSymbols::visit(QualifiedNameAST *ast) if (binding && ast->unqualified_name) { if (ast->unqualified_name->asDestructorName() != 0) { if (hasVirtualDestructor(binding)) { - addUse(ast->unqualified_name, CppHighlightingSupport::VirtualMethodUse); + addUse(ast->unqualified_name, SemanticHighlighter::VirtualMethodUse); } else { bool added = false; if (highlightCtorDtorAsType && maybeType(ast->name)) added = maybeAddTypeOrStatic(binding->find(ast->unqualified_name->name), ast->unqualified_name); if (!added) - addUse(ast->unqualified_name, CppHighlightingSupport::FunctionUse); + addUse(ast->unqualified_name, SemanticHighlighter::FunctionUse); } } else { QList<LookupItem> items = binding->find(ast->unqualified_name->name); @@ -904,7 +906,7 @@ ClassOrNamespace *CheckSymbols::checkNestedName(QualifiedNameAST *ast) if (NameAST *class_or_namespace_name = nested_name_specifier->class_or_namespace_name) { if (TemplateIdAST *template_id = class_or_namespace_name->asTemplateId()) { if (template_id->template_token) { - addUse(template_id, CppHighlightingSupport::TypeUse); + addUse(template_id, SemanticHighlighter::TypeUse); binding = 0; // there's no way we can find a binding. } @@ -928,7 +930,7 @@ ClassOrNamespace *CheckSymbols::checkNestedName(QualifiedNameAST *ast) bool CheckSymbols::visit(TypenameTypeParameterAST *ast) { - addUse(ast->name, CppHighlightingSupport::TypeUse); + addUse(ast->name, SemanticHighlighter::TypeUse); accept(ast->type_id); return false; } @@ -936,7 +938,7 @@ bool CheckSymbols::visit(TypenameTypeParameterAST *ast) bool CheckSymbols::visit(TemplateTypeParameterAST *ast) { accept(ast->template_parameter_list); - addUse(ast->name, CppHighlightingSupport::TypeUse); + addUse(ast->name, SemanticHighlighter::TypeUse); accept(ast->type_id); return false; } @@ -988,7 +990,7 @@ bool CheckSymbols::visit(MemInitializerAST *ast) bool CheckSymbols::visit(GotoStatementAST *ast) { if (ast->identifier_token) - addUse(ast->identifier_token, CppHighlightingSupport::LabelUse); + addUse(ast->identifier_token, SemanticHighlighter::LabelUse); return false; } @@ -996,7 +998,7 @@ bool CheckSymbols::visit(GotoStatementAST *ast) bool CheckSymbols::visit(LabeledStatementAST *ast) { if (ast->label_token && !tokenAt(ast->label_token).isKeyword()) - addUse(ast->label_token, CppHighlightingSupport::LabelUse); + addUse(ast->label_token, SemanticHighlighter::LabelUse); accept(ast->statement); return false; @@ -1017,7 +1019,7 @@ bool CheckSymbols::visit(SimpleSpecifierAST *ast) if (id.equalTo(_doc->control()->cpp11Override()) || id.equalTo(_doc->control()->cpp11Final())) { - addUse(ast->specifier_token, CppHighlightingSupport::PseudoKeywordUse); + addUse(ast->specifier_token, SemanticHighlighter::PseudoKeywordUse); } } } @@ -1028,7 +1030,7 @@ bool CheckSymbols::visit(SimpleSpecifierAST *ast) bool CheckSymbols::visit(ClassSpecifierAST *ast) { if (ast->final_token) - addUse(ast->final_token, CppHighlightingSupport::PseudoKeywordUse); + addUse(ast->final_token, SemanticHighlighter::PseudoKeywordUse); return true; } @@ -1053,7 +1055,7 @@ bool CheckSymbols::visit(FunctionDefinitionAST *ast) if (fun->isVirtual() || (declId->asDestructorName() && hasVirtualDestructor(_context.lookupType(fun->enclosingScope())))) { - addUse(declId, CppHighlightingSupport::VirtualMethodUse); + addUse(declId, SemanticHighlighter::VirtualMethodUse); } else if (!maybeAddFunction(_context.lookup(fun->name(), fun->enclosingScope()), declId, fun->argumentCount())) { @@ -1161,7 +1163,7 @@ void CheckSymbols::addType(ClassOrNamespace *b, NameAST *ast) unsigned line, column; getTokenStartPosition(startToken, &line, &column); const unsigned length = tok.utf16chars(); - const Result use(line, column, length, CppHighlightingSupport::TypeUse); + const Result use(line, column, length, SemanticHighlighter::TypeUse); addUse(use); } @@ -1203,12 +1205,12 @@ bool CheckSymbols::maybeAddTypeOrStatic(const QList<LookupItem> &candidates, Nam getTokenStartPosition(startToken, &line, &column); const unsigned length = tok.utf16chars(); - Kind kind = CppHighlightingSupport::TypeUse; + Kind kind = SemanticHighlighter::TypeUse; if (c->enclosingEnum() != 0) - kind = CppHighlightingSupport::EnumerationUse; + kind = SemanticHighlighter::EnumerationUse; else if (c->isStatic()) // treat static variable as a field(highlighting) - kind = CppHighlightingSupport::FieldUse; + kind = SemanticHighlighter::FieldUse; const Result use(line, column, length, kind); addUse(use); @@ -1245,7 +1247,7 @@ bool CheckSymbols::maybeAddField(const QList<LookupItem> &candidates, NameAST *a getTokenStartPosition(startToken, &line, &column); const unsigned length = tok.utf16chars(); - const Result use(line, column, length, CppHighlightingSupport::FieldUse); + const Result use(line, column, length, SemanticHighlighter::FieldUse); addUse(use); return true; @@ -1270,7 +1272,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST return false; enum { Match_None, Match_TooManyArgs, Match_TooFewArgs, Match_Ok } matchType = Match_None; - Kind kind = CppHighlightingSupport::FunctionUse; + Kind kind = SemanticHighlighter::FunctionUse; foreach (const LookupItem &r, candidates) { Symbol *c = r.declaration(); @@ -1297,21 +1299,21 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST if (argumentCount < funTy->minimumArgumentCount()) { if (matchType != Match_Ok) { - kind = funTy->isVirtual() ? CppHighlightingSupport::VirtualMethodUse : CppHighlightingSupport::FunctionUse; + kind = funTy->isVirtual() ? SemanticHighlighter::VirtualMethodUse : SemanticHighlighter::FunctionUse; matchType = Match_TooFewArgs; } } else if (argumentCount > funTy->argumentCount() && !funTy->isVariadic()) { if (matchType != Match_Ok) { matchType = Match_TooManyArgs; - kind = funTy->isVirtual() ? CppHighlightingSupport::VirtualMethodUse : CppHighlightingSupport::FunctionUse; + kind = funTy->isVirtual() ? SemanticHighlighter::VirtualMethodUse : SemanticHighlighter::FunctionUse; } } else if (!funTy->isVirtual()) { matchType = Match_Ok; - kind = CppHighlightingSupport::FunctionUse; + kind = SemanticHighlighter::FunctionUse; //continue, to check if there is a matching candidate which is virtual } else { matchType = Match_Ok; - kind = CppHighlightingSupport::VirtualMethodUse; + kind = SemanticHighlighter::VirtualMethodUse; break; } } @@ -1321,7 +1323,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST if (highlightCtorDtorAsType && (isConstructor || isDestructor) && maybeType(ast->name) - && kind == CppHighlightingSupport::FunctionUse) { + && kind == SemanticHighlighter::FunctionUse) { return false; } |