Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
12ecb527
Commit
12ecb527
authored
Aug 05, 2010
by
Roberto Raggi
Browse files
Simplified FindUsages.
parent
928c6874
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/libs/cplusplus/FindUsages.cpp
View file @
12ecb527
...
...
@@ -78,21 +78,25 @@ QList<int> FindUsages::references() const
void
FindUsages
::
operator
()(
Symbol
*
symbol
)
{
if
(
!
symbol
)
return
;
_id
=
symbol
->
identifier
();
if
(
!
_id
)
return
;
_processed
.
clear
();
_references
.
clear
();
_usages
.
clear
();
_declSymbol
=
symbol
;
_declSymbol
FullyQualifiedName
=
LookupContext
::
fullyQualifiedName
(
symbol
)
;
_inSimpleDeclaration
=
0
;
_inQProperty
=
false
;
_id
=
0
;
if
(
_declSymbol
&&
0
!=
(
_id
=
_declSymbol
->
identifier
()))
_id
=
_doc
->
control
()
->
findOrInsertIdentifier
(
_id
->
chars
(),
_id
->
size
());
// get the canonical id
_id
=
_doc
->
control
()
->
findOrInsertIdentifier
(
_id
->
chars
(),
_id
->
size
());
if
(
_id
)
{
_exprDoc
=
Document
::
create
(
"<references>"
);
accept
(
_doc
->
translationUnit
()
->
ast
());
}
accept
(
_doc
->
translationUnit
()
->
ast
());
}
QString
FindUsages
::
matchingLine
(
const
Token
&
tk
)
const
...
...
@@ -160,13 +164,26 @@ void FindUsages::reportResult(unsigned tokenIndex)
_references
.
append
(
tokenIndex
);
}
bool
FindUsages
::
compareFullyQualifiedName
(
const
QList
<
const
Name
*>
&
path
,
const
QList
<
const
Name
*>
&
other
)
{
if
(
path
.
length
()
!=
other
.
length
())
return
false
;
for
(
int
i
=
0
;
i
<
path
.
length
();
++
i
)
{
if
(
!
path
.
at
(
i
)
->
isEqualTo
(
other
.
at
(
i
)))
return
false
;
}
return
true
;
}
bool
FindUsages
::
checkCandidates
(
const
QList
<
LookupItem
>
&
candidates
)
const
{
if
(
ClassOrNamespace
*
c
=
_context
.
lookupType
(
_declSymbol
)
)
{
for
(
int
i
=
candidates
.
size
()
-
1
;
i
!=
-
1
;
--
i
)
{
const
LookupItem
&
r
=
candidates
.
at
(
i
);
Symbol
*
s
=
r
.
declaration
()
;
if
(
_
co
ntext
.
lookupType
(
s
)
==
c
)
for
(
int
i
=
candidates
.
size
()
-
1
;
i
!=
-
1
;
--
i
)
{
const
LookupItem
&
r
=
candidates
.
at
(
i
);
if
(
Symbol
*
s
=
r
.
declaration
()
)
{
if
(
co
mpareFullyQualifiedName
(
LookupContext
::
fullyQualifiedName
(
s
),
_declSymbolFullyQualifiedName
)
)
return
true
;
}
}
...
...
@@ -180,6 +197,16 @@ void FindUsages::ensureNameIsValid(NameAST *ast)
ast
->
name
=
_sem
.
check
(
ast
,
/*scope = */
0
);
}
bool
FindUsages
::
visit
(
NamespaceAST
*
ast
)
{
const
Identifier
*
id
=
identifier
(
ast
->
identifier_token
);
if
(
id
==
_id
&&
ast
->
symbol
)
{
const
QList
<
LookupItem
>
candidates
=
_context
.
lookup
(
ast
->
symbol
->
name
(),
scopeAt
(
ast
->
identifier_token
));
reportResult
(
ast
->
identifier_token
,
candidates
);
}
return
true
;
}
bool
FindUsages
::
visit
(
MemInitializerAST
*
ast
)
{
if
(
ast
->
name
&&
ast
->
name
->
asSimpleName
()
!=
0
)
{
...
...
src/libs/cplusplus/FindUsages.h
View file @
12ecb527
...
...
@@ -82,6 +82,7 @@ protected:
void
ensureNameIsValid
(
NameAST
*
ast
);
virtual
bool
visit
(
NamespaceAST
*
ast
);
virtual
bool
visit
(
MemInitializerAST
*
ast
);
virtual
bool
visit
(
MemberAccessAST
*
ast
);
virtual
bool
visit
(
QualifiedNameAST
*
ast
);
...
...
@@ -104,15 +105,15 @@ protected:
virtual
bool
visit
(
TemplateTypeParameterAST
*
ast
);
unsigned
startOfTemplateDeclaration
(
TemplateDeclarationAST
*
ast
)
const
;
static
bool
compareFullyQualifiedName
(
const
QList
<
const
Name
*>
&
path
,
const
QList
<
const
Name
*>
&
other
);
private:
const
Identifier
*
_id
;
Symbol
*
_declSymbol
;
QList
<
const
Name
*>
_declSymbolFullyQualifiedName
;
Document
::
Ptr
_doc
;
Snapshot
_snapshot
;
LookupContext
_context
;
QByteArray
_source
;
Document
::
Ptr
_exprDoc
;
Semantic
_sem
;
QList
<
QualifiedNameAST
*>
_qualifiedNameStack
;
QList
<
TemplateDeclarationAST
*>
_templateDeclarationStack
;
...
...
src/plugins/cpptools/cppfindreferences.cpp
View file @
12ecb527
...
...
@@ -185,7 +185,7 @@ static void find_helper(QFutureInterface<Usage> &future,
const
QString
sourceFile
=
QString
::
fromUtf8
(
symbol
->
fileName
(),
symbol
->
fileNameLength
());
QStringList
files
(
sourceFile
);
if
(
symbol
->
isClass
()
||
symbol
->
isForwardClassDeclaration
())
{
if
(
symbol
->
isClass
()
||
symbol
->
isForwardClassDeclaration
()
||
(
symbol
->
scope
()
&&
symbol
->
scope
()
->
isNamespaceScope
())
)
{
foreach
(
const
Document
::
Ptr
&
doc
,
context
.
snapshot
())
{
if
(
doc
->
fileName
()
==
sourceFile
)
continue
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment