Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
31522c55
Commit
31522c55
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Improved the semantic search for class declarations.
parent
769d6282
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/plugins/cpptools/cppsemanticsearch.cpp
+41
-16
41 additions, 16 deletions
src/plugins/cpptools/cppsemanticsearch.cpp
src/plugins/cpptools/cppsemanticsearch.h
+1
-1
1 addition, 1 deletion
src/plugins/cpptools/cppsemanticsearch.h
with
42 additions
and
17 deletions
src/plugins/cpptools/cppsemanticsearch.cpp
+
41
−
16
View file @
31522c55
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include
"cppmodelmanager.h"
#include
"cppmodelmanager.h"
#include
<AST.h>
#include
<AST.h>
#include
<Literals.h>
#include
<TranslationUnit.h>
#include
<TranslationUnit.h>
#include
<QtCore/QDir>
#include
<QtCore/QDir>
...
@@ -44,13 +45,14 @@ using namespace CPlusPlus;
...
@@ -44,13 +45,14 @@ using namespace CPlusPlus;
namespace
{
namespace
{
class
Find
Class
:
public
SemanticSearch
class
Search
Class
:
public
SemanticSearch
{
{
QString
_text
;
QString
_text
;
QTextDocument
::
FindFlags
_findFlags
;
QTextDocument
::
FindFlags
_findFlags
;
public:
public:
FindClass
(
QFutureInterface
<
Core
::
Utils
::
FileSearchResult
>
&
future
,
Document
::
Ptr
doc
,
Snapshot
snapshot
)
SearchClass
(
QFutureInterface
<
Core
::
Utils
::
FileSearchResult
>
&
future
,
Document
::
Ptr
doc
,
Snapshot
snapshot
)
:
SemanticSearch
(
future
,
doc
,
snapshot
)
:
SemanticSearch
(
future
,
doc
,
snapshot
)
{
}
{
}
...
@@ -66,25 +68,48 @@ public:
...
@@ -66,25 +68,48 @@ public:
protected
:
protected
:
using
ASTVisitor
::
visit
;
using
ASTVisitor
::
visit
;
virtual
bool
visit
(
ClassSpecifier
AST
*
ast
)
bool
match
(
Name
AST
*
name
)
{
{
if
(
ast
->
name
)
{
if
(
!
name
)
Qt
::
CaseSensitivity
cs
=
Qt
::
CaseInsensitive
;
return
false
;
else
if
(
SimpleNameAST
*
simpleName
=
name
->
asSimpleName
())
{
if
(
Identifier
*
id
=
identifier
(
simpleName
->
identifier_token
))
{
Qt
::
CaseSensitivity
cs
=
Qt
::
CaseInsensitive
;
if
(
_findFlags
&
QTextDocument
::
FindCaseSensitively
)
cs
=
Qt
::
CaseSensitive
;
QString
s
=
QString
::
fromUtf8
(
id
->
chars
(),
id
->
size
());
int
index
=
s
.
indexOf
(
_text
,
0
,
cs
);
if
(
index
!=
-
1
)
{
reportResult
(
simpleName
->
identifier_token
,
index
,
_text
.
length
());
return
true
;
}
}
}
if
(
_findFlags
&
QTextDocument
::
FindCaseSensitively
)
else
if
(
QualifiedNameAST
*
q
=
name
->
asQualifiedName
())
{
cs
=
Qt
::
CaseSensitive
;
return
match
(
q
->
unqualified_name
);
}
Token
start
=
tokenAt
(
ast
->
name
->
firstToken
());
return
false
;
Token
end
=
tokenAt
(
ast
->
name
->
lastToken
()
-
1
);
}
const
QString
className
=
QString
::
fromUtf8
(
source
().
constData
()
+
start
.
begin
(),
end
.
end
()
-
start
.
begin
());
if
(
className
.
contains
(
_text
,
cs
))
virtual
bool
visit
(
ElaboratedTypeSpecifierAST
*
ast
)
reportResult
(
ast
->
name
->
firstToken
());
{
if
(
tokenKind
(
ast
->
classkey_token
)
!=
T_ENUM
)
{
match
(
ast
->
name
);
}
}
return
true
;
return
true
;
}
}
virtual
bool
visit
(
ClassSpecifierAST
*
ast
)
{
match
(
ast
->
name
);
return
true
;
}
};
};
}
// end of anonymous namespace
}
// end of anonymous namespace
...
@@ -130,7 +155,7 @@ QString SemanticSearch::matchingLine(const Token &tk) const
...
@@ -130,7 +155,7 @@ QString SemanticSearch::matchingLine(const Token &tk) const
return
matchingLine
;
return
matchingLine
;
}
}
void
SemanticSearch
::
reportResult
(
unsigned
tokenIndex
)
void
SemanticSearch
::
reportResult
(
unsigned
tokenIndex
,
int
offset
,
int
len
)
{
{
const
Token
&
tk
=
tokenAt
(
tokenIndex
);
const
Token
&
tk
=
tokenAt
(
tokenIndex
);
const
QString
lineText
=
matchingLine
(
tk
);
const
QString
lineText
=
matchingLine
(
tk
);
...
@@ -142,14 +167,14 @@ void SemanticSearch::reportResult(unsigned tokenIndex)
...
@@ -142,14 +167,14 @@ void SemanticSearch::reportResult(unsigned tokenIndex)
--
col
;
// adjust the column position.
--
col
;
// adjust the column position.
_future
.
reportResult
(
Core
::
Utils
::
FileSearchResult
(
QDir
::
toNativeSeparators
(
_doc
->
fileName
()),
_future
.
reportResult
(
Core
::
Utils
::
FileSearchResult
(
QDir
::
toNativeSeparators
(
_doc
->
fileName
()),
line
,
lineText
,
col
,
tk
.
length
));
line
,
lineText
,
col
+
offset
,
len
));
}
}
SemanticSearch
*
SearchClassDeclarationsFactory
::
create
(
QFutureInterface
<
Core
::
Utils
::
FileSearchResult
>
&
future
,
SemanticSearch
*
SearchClassDeclarationsFactory
::
create
(
QFutureInterface
<
Core
::
Utils
::
FileSearchResult
>
&
future
,
Document
::
Ptr
doc
,
Document
::
Ptr
doc
,
Snapshot
snapshot
)
Snapshot
snapshot
)
{
{
Find
Class
*
findClass
=
new
Find
Class
(
future
,
doc
,
snapshot
);
Search
Class
*
findClass
=
new
Search
Class
(
future
,
doc
,
snapshot
);
findClass
->
setText
(
_text
);
findClass
->
setText
(
_text
);
findClass
->
setFindFlags
(
_findFlags
);
findClass
->
setFindFlags
(
_findFlags
);
return
findClass
;
return
findClass
;
...
...
This diff is collapsed.
Click to expand it.
src/plugins/cpptools/cppsemanticsearch.h
+
1
−
1
View file @
31522c55
...
@@ -68,7 +68,7 @@ public:
...
@@ -68,7 +68,7 @@ public:
protected:
protected:
QString
matchingLine
(
const
CPlusPlus
::
Token
&
tk
)
const
;
QString
matchingLine
(
const
CPlusPlus
::
Token
&
tk
)
const
;
void
reportResult
(
unsigned
tokenIndex
);
void
reportResult
(
unsigned
tokenIndex
,
int
offset
,
int
len
);
};
};
class
SemanticSearchFactory
class
SemanticSearchFactory
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment