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
c6968d95
Commit
c6968d95
authored
Jun 25, 2009
by
Roberto Raggi
Browse files
Mark the externals
parent
9ac5ab04
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/plugins/cppeditor/cppeditor.cpp
View file @
c6968d95
...
...
@@ -110,7 +110,7 @@ public:
}
};
class
Find
Local
s
:
protected
ASTVisitor
class
Find
Use
s
:
protected
ASTVisitor
{
Scope
*
_functionScope
;
...
...
@@ -177,7 +177,7 @@ class FindLocals: protected ASTVisitor
};
public:
Find
Local
s
(
Control
*
control
)
Find
Use
s
(
Control
*
control
)
:
ASTVisitor
(
control
)
{
}
...
...
@@ -193,19 +193,25 @@ public:
:
name
(
name
),
line
(
line
),
column
(
column
),
length
(
length
)
{}
};
typedef
QHash
<
Symbol
*
,
QList
<
Use
>
>
UseMap
;
typedef
QHashIterator
<
Symbol
*
,
QList
<
Use
>
>
UseIterator
;
typedef
QHash
<
Symbol
*
,
QList
<
Use
>
>
Local
UseMap
;
typedef
QHashIterator
<
Symbol
*
,
QList
<
Use
>
>
Local
UseIterator
;
UseMap
uses
;
// ### private
typedef
QHash
<
Identifier
*
,
QList
<
Use
>
>
ExternalUseMap
;
typedef
QHashIterator
<
Identifier
*
,
QList
<
Use
>
>
ExternalUseIterator
;
UseMap
operator
()(
FunctionDefinitionAST
*
ast
)
// local and external uses.
LocalUseMap
localUses
;
ExternalUseMap
externalUses
;
void
operator
()(
FunctionDefinitionAST
*
ast
)
{
uses
.
clear
();
localUses
.
clear
();
externalUses
.
clear
();
if
(
ast
&&
ast
->
symbol
)
{
_functionScope
=
ast
->
symbol
->
members
();
accept
(
ast
);
}
return
uses
;
}
protected:
...
...
@@ -221,7 +227,7 @@ protected:
continue
;
else
if
(
member
->
line
()
<
line
||
(
member
->
line
()
==
line
&&
member
->
column
()
<=
column
))
{
//qDebug() << "*** found member:" << member->line() << member->column() << member->name()->identifier()->chars();
u
ses
[
member
].
append
(
Use
(
ast
,
line
,
column
,
id
->
size
()));
localU
ses
[
member
].
append
(
Use
(
ast
,
line
,
column
,
id
->
size
()));
return
true
;
}
}
...
...
@@ -258,10 +264,8 @@ protected:
scope
=
scope
->
enclosingScope
();
}
#if 0
qDebug() << "symbol:" << id->chars() << "at pos:" << line << column
<< "is not defined";
#endif
Identifier
*
id
=
identifier
(
ast
->
identifier_token
);
externalUses
[
id
].
append
(
Use
(
ast
,
line
,
column
,
id
->
size
()));
return
false
;
}
...
...
@@ -875,6 +879,41 @@ void CPPEditor::updateMethodBoxIndex()
m_updateMethodBoxTimer
->
start
(
UPDATE_METHOD_BOX_INTERVAL
);
}
static
void
highlightUses
(
QTextDocument
*
doc
,
const
QTextCharFormat
&
format
,
TranslationUnit
*
translationUnit
,
const
QList
<
FindUses
::
Use
>
&
uses
,
QList
<
QTextEdit
::
ExtraSelection
>
*
selections
)
{
foreach
(
const
FindUses
::
Use
&
use
,
uses
)
{
SimpleNameAST
*
name
=
use
.
name
;
bool
generated
=
false
;
for
(
unsigned
tk
=
name
->
firstToken
(),
end
=
name
->
lastToken
();
tk
!=
end
;
++
tk
)
{
if
(
translationUnit
->
tokenAt
(
tk
).
generated
)
{
generated
=
true
;
break
;
}
}
if
(
!
generated
)
{
unsigned
startLine
,
startColumn
;
unsigned
endLine
,
endColumn
;
translationUnit
->
getTokenStartPosition
(
name
->
firstToken
(),
&
startLine
,
&
startColumn
);
translationUnit
->
getTokenEndPosition
(
name
->
lastToken
()
-
1
,
&
endLine
,
&
endColumn
);
QTextEdit
::
ExtraSelection
sel
;
sel
.
cursor
=
QTextCursor
(
doc
);
sel
.
cursor
.
setPosition
(
doc
->
findBlockByNumber
(
startLine
-
1
).
position
()
+
startColumn
-
1
);
sel
.
cursor
.
setPosition
(
doc
->
findBlockByLineNumber
(
endLine
-
1
).
position
()
+
endColumn
-
1
,
QTextCursor
::
KeepAnchor
);
sel
.
format
=
format
;
selections
->
append
(
sel
);
}
}
}
void
CPPEditor
::
updateMethodBoxIndexNow
()
{
m_updateMethodBoxTimer
->
stop
();
...
...
@@ -913,18 +952,19 @@ void CPPEditor::updateMethodBoxIndexNow()
FunctionDefinitionUnderCursor
functionDefinitionUnderCursor
(
control
);
FunctionDefinitionAST
*
currentFunctionDefinition
=
functionDefinitionUnderCursor
(
ast
,
textCursor
());
QTextCharFormat
format
;
format
.
setBackground
(
Qt
::
lightGray
);
FindLocals
findLocals
(
control
);
const
FindLocals
::
UseMap
useMap
=
findLocals
(
currentFunctionDefinition
);
FindLocals
::
UseIterator
it
(
useMap
);
FindUses
useTable
(
control
);
useTable
(
currentFunctionDefinition
);
FindUses
::
LocalUseIterator
it
(
useTable
.
localUses
);
while
(
it
.
hasNext
())
{
it
.
next
();
const
QList
<
Find
Local
s
::
Use
>
&
uses
=
it
.
value
();
const
QList
<
Find
Use
s
::
Use
>
&
uses
=
it
.
value
();
bool
good
=
false
;
foreach
(
const
Find
Local
s
::
Use
&
use
,
uses
)
{
foreach
(
const
Find
Use
s
::
Use
&
use
,
uses
)
{
unsigned
l
=
line
;
unsigned
c
=
column
+
1
;
// convertCursorPosition() returns a 0-based column number.
if
(
l
==
use
.
line
&&
c
>=
use
.
column
&&
c
<=
(
use
.
column
+
use
.
length
))
{
...
...
@@ -936,111 +976,33 @@ void CPPEditor::updateMethodBoxIndexNow()
if
(
!
good
)
continue
;
foreach
(
const
FindLocals
::
Use
&
use
,
uses
)
{
SimpleNameAST
*
name
=
use
.
name
;
bool
generated
=
false
;
for
(
unsigned
tk
=
name
->
firstToken
(),
end
=
name
->
lastToken
();
tk
!=
end
;
++
tk
)
{
if
(
translationUnit
->
tokenAt
(
tk
).
generated
)
{
generated
=
true
;
break
;
}
}
if
(
generated
)
continue
;
unsigned
startLine
,
startColumn
;
unsigned
endLine
,
endColumn
;
translationUnit
->
getTokenStartPosition
(
name
->
firstToken
(),
&
startLine
,
&
startColumn
);
translationUnit
->
getTokenEndPosition
(
name
->
lastToken
()
-
1
,
&
endLine
,
&
endColumn
);
QTextEdit
::
ExtraSelection
sel
;
sel
.
cursor
=
textCursor
();
sel
.
cursor
.
setPosition
(
document
()
->
findBlockByNumber
(
startLine
-
1
).
position
()
+
startColumn
-
1
);
sel
.
cursor
.
setPosition
(
document
()
->
findBlockByLineNumber
(
endLine
-
1
).
position
()
+
endColumn
-
1
,
QTextCursor
::
KeepAnchor
);
sel
.
format
=
format
;
selections
.
append
(
sel
);
}
break
;
// done.
highlightUses
(
document
(),
format
,
translationUnit
,
uses
,
&
selections
);
break
;
// done
}
setExtraSelections
(
CodeSemanticsSelection
,
selections
);
#ifdef QTCREATOR_WITH_ADVANCED_HIGHLIGHTER
Snapshot
snapshot
=
m_modelManager
->
snapshot
();
Document
::
Ptr
thisDocument
=
snapshot
.
value
(
file
()
->
fileName
());
if
(
!
thisDocument
)
return
;
if
(
Symbol
*
symbol
=
thisDocument
->
findSymbolAt
(
line
,
column
))
{
QTextCursor
tc
=
textCursor
();
tc
.
movePosition
(
QTextCursor
::
EndOfWord
);
ExpressionUnderCursor
expressionUnderCursor
;
const
QString
expression
=
expressionUnderCursor
(
tc
);
//qDebug() << "expression:" << expression;
Snapshot
snapshot
;
snapshot
.
insert
(
thisDocument
->
fileName
(),
thisDocument
);
TypeOfExpression
typeOfExpression
;
typeOfExpression
.
setSnapshot
(
snapshot
);
const
QList
<
TypeOfExpression
::
Result
>
results
=
typeOfExpression
(
expression
,
thisDocument
,
symbol
,
TypeOfExpression
::
Preprocess
);
LookupContext
context
=
typeOfExpression
.
lookupContext
();
foreach
(
const
TypeOfExpression
::
Result
&
result
,
results
)
{
FullySpecifiedType
ty
=
result
.
first
;
Symbol
*
symbol
=
result
.
second
;
if
(
file
()
->
fileName
()
!=
symbol
->
fileName
())
continue
;
else
if
(
symbol
->
isGenerated
())
continue
;
else
if
(
symbol
->
isBlock
())
continue
;
if
(
symbol
)
{
int
column
=
symbol
->
column
();
if
(
column
!=
0
)
--
column
;
FindUses
::
ExternalUseIterator
it2
(
useTable
.
externalUses
);
while
(
it2
.
hasNext
())
{
it2
.
next
();
const
QList
<
FindUses
::
Use
>
&
uses
=
it2
.
value
();
if
(
symbol
->
isGenerated
())
column
=
0
;
QTextCursor
c
(
document
()
->
findBlockByNumber
(
symbol
->
line
()
-
1
));
c
.
setPosition
(
c
.
position
()
+
column
);
const
QString
text
=
c
.
block
().
text
();
int
i
=
column
;
for
(;
i
<
text
.
length
();
++
i
)
{
const
QChar
&
ch
=
text
.
at
(
i
);
if
(
ch
==
QLatin1Char
(
'*'
)
||
ch
==
QLatin1Char
(
'&'
))
c
.
movePosition
(
QTextCursor
::
NextCharacter
);
else
break
;
}
c
.
movePosition
(
QTextCursor
::
EndOfWord
,
QTextCursor
::
KeepAnchor
);
QTextEdit
::
ExtraSelection
sel
;
sel
.
cursor
=
c
;
sel
.
format
.
setBackground
(
Qt
::
darkYellow
);
selections
.
append
(
sel
);
//break;
bool
good
=
false
;
foreach
(
const
FindUses
::
Use
&
use
,
uses
)
{
unsigned
l
=
line
;
unsigned
c
=
column
+
1
;
// convertCursorPosition() returns a 0-based column number.
if
(
l
==
use
.
line
&&
c
>=
use
.
column
&&
c
<=
(
use
.
column
+
use
.
length
))
{
good
=
true
;
break
;
}
}
if
(
!
good
)
continue
;
highlightUses
(
document
(),
format
,
translationUnit
,
uses
,
&
selections
);
break
;
// done
}
setExtraSelections
(
CodeSemanticsSelection
,
selections
);
#endif // QTCREATOR_WITH_ADVANCED_HIGHLIGHTER
}
void
CPPEditor
::
updateMethodBoxToolTip
()
...
...
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