Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flatpak-qt-creator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
ae43149c
Commit
ae43149c
authored
Sep 30, 2009
by
Roberto Raggi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache the macros.
parent
06bba1dc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
46 deletions
+34
-46
src/libs/cplusplus/FastPreprocessor.cpp
src/libs/cplusplus/FastPreprocessor.cpp
+24
-33
src/libs/cplusplus/FastPreprocessor.h
src/libs/cplusplus/FastPreprocessor.h
+4
-5
src/plugins/cppeditor/cppeditor.cpp
src/plugins/cppeditor/cppeditor.cpp
+1
-1
src/plugins/cpptools/cppfindreferences.cpp
src/plugins/cpptools/cppfindreferences.cpp
+5
-7
No files found.
src/libs/cplusplus/FastPreprocessor.cpp
View file @
ae43149c
...
...
@@ -30,39 +30,40 @@
#include "FastPreprocessor.h"
#include <Literals.h>
#include <TranslationUnit.h>
#include <QtCore/QDebug>
using
namespace
CPlusPlus
;
FastMacroResolver
::
FastMacroResolver
(
const
Snapshot
&
snapshot
)
:
_snapshot
(
snapshot
)
{
}
TranslationUnit
*
_previousUnit
;
FastMacroResolver
::
FastMacroResolver
(
TranslationUnit
*
unit
,
const
Snapshot
&
snapshot
)
:
_unit
(
unit
),
_snapshot
(
snapshot
)
{
const
QString
fileName
=
QString
::
fromUtf8
(
unit
->
fileName
(),
unit
->
fileNameLength
());
QSet
<
QString
>
processed
;
updateCache
(
fileName
,
&
processed
);
}
bool
FastMacroResolver
::
isMacro
(
TranslationUnit
*
unit
,
unsigned
tokenIndex
)
const
{
if
(
unit
!=
_unit
){
qWarning
()
<<
Q_FUNC_INFO
<<
"unexpected translation unit:"
<<
unit
->
fileName
();
return
false
;
}
const
Token
&
tk
=
unit
->
tokenAt
(
tokenIndex
);
if
(
tk
.
isNot
(
T_IDENTIFIER
))
return
false
;
Identifier
*
id
=
tk
.
identifier
;
const
QByteArray
macroName
=
QByteArray
::
fromRawData
(
id
->
chars
(),
id
->
size
());
const
QString
fileName
=
QString
::
fromUtf8
(
unit
->
fileName
(),
unit
->
fileNameLength
());
bool
done
=
false
;
QSet
<
QString
>
processed
;
if
(
isMacro_helper
(
macroName
,
fileName
,
&
processed
,
&
done
))
return
true
;
return
false
;
return
_cachedMacros
.
contains
(
macroName
);
}
bool
FastMacroResolver
::
isMacro_helper
(
const
QByteArray
&
macroName
,
const
QString
&
fileName
,
QSet
<
QString
>
*
processed
,
bool
*
done
)
const
void
FastMacroResolver
::
updateCache
(
const
QString
&
fileName
,
QSet
<
QString
>
*
processed
)
{
if
(
processed
->
contains
(
fileName
))
return
false
;
return
;
processed
->
insert
(
fileName
);
...
...
@@ -72,25 +73,15 @@ bool FastMacroResolver::isMacro_helper(const QByteArray ¯oName,
for
(
int
i
=
definedMacros
.
size
()
-
1
;
i
!=
-
1
;
--
i
)
{
const
Macro
&
macro
=
definedMacros
.
at
(
i
);
if
(
macro
.
name
()
==
macroName
)
{
// ### handle line numbers.
if
(
macro
.
isHidden
())
{
*
done
=
true
;
return
false
;
}
return
true
;
}
if
(
macro
.
isHidden
())
_cachedMacros
.
remove
(
macro
.
name
());
else
_cachedMacros
.
insert
(
macro
.
name
());
}
foreach
(
const
Document
::
Include
&
incl
,
doc
->
includes
())
{
if
(
isMacro_helper
(
macroName
,
incl
.
fileName
(),
processed
,
done
))
return
true
;
else
if
(
*
done
)
return
false
;
}
foreach
(
const
Document
::
Include
&
incl
,
doc
->
includes
())
updateCache
(
incl
.
fileName
(),
processed
);
}
return
false
;
}
FastPreprocessor
::
FastPreprocessor
(
const
Snapshot
&
snapshot
)
...
...
src/libs/cplusplus/FastPreprocessor.h
View file @
ae43149c
...
...
@@ -44,18 +44,17 @@ namespace CPlusPlus {
class
CPLUSPLUS_EXPORT
FastMacroResolver
:
public
MacroResolver
{
public:
FastMacroResolver
(
const
Snapshot
&
snapshot
);
FastMacroResolver
(
TranslationUnit
*
unit
,
const
Snapshot
&
snapshot
);
virtual
bool
isMacro
(
TranslationUnit
*
unit
,
unsigned
tokenIndex
)
const
;
private:
bool
isMacro_helper
(
const
QByteArray
&
macroName
,
const
QString
&
fileName
,
QSet
<
QString
>
*
processed
,
bool
*
done
)
const
;
void
updateCache
(
const
QString
&
fileName
,
QSet
<
QString
>
*
processed
);
private:
TranslationUnit
*
_unit
;
Snapshot
_snapshot
;
QSet
<
QByteArray
>
_cachedMacros
;
};
class
CPLUSPLUS_EXPORT
FastPreprocessor
:
public
Client
...
...
src/plugins/cppeditor/cppeditor.cpp
View file @
ae43149c
...
...
@@ -2069,7 +2069,7 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
snapshot
=
source
.
snapshot
;
doc
=
source
.
snapshot
.
documentFromSource
(
preprocessedCode
,
source
.
fileName
);
FastMacroResolver
fastMacroResolver
(
snapshot
);
FastMacroResolver
fastMacroResolver
(
doc
->
translationUnit
(),
snapshot
);
doc
->
control
()
->
setMacroResolver
(
&
fastMacroResolver
);
doc
->
check
();
doc
->
control
()
->
setMacroResolver
(
0
);
...
...
src/plugins/cpptools/cppfindreferences.cpp
View file @
ae43149c
...
...
@@ -171,7 +171,8 @@ protected:
unsigned
line
,
column
;
getTokenStartPosition
(
ast
->
firstToken
(),
&
line
,
&
column
);
Symbol
*
lastVisibleSymbol
=
_doc
->
findSymbolAt
(
line
,
column
);
return
LookupContext
(
lastVisibleSymbol
,
_exprDoc
,
_doc
,
_snapshot
);
LookupContext
ctx
(
lastVisibleSymbol
,
_exprDoc
,
_doc
,
_snapshot
);
return
ctx
;
}
void
ensureNameIsValid
(
NameAST
*
ast
)
...
...
@@ -232,7 +233,7 @@ protected:
const
unsigned
end
=
tokenAt
(
endToken
).
end
();
const
QString
expression
=
_source
.
mid
(
begin
,
end
-
begin
);
// qDebug() << "*** expression:" << expression;
// qDebug() << "***
check
expression:" << expression;
TypeOfExpression
typeofExpression
;
typeofExpression
.
setSnapshot
(
_snapshot
);
...
...
@@ -426,16 +427,12 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
future
.
setProgressRange
(
0
,
files
.
size
());
FastMacroResolver
fastMacroResolver
(
snapshot
);
for
(
int
i
=
0
;
i
<
files
.
size
();
++
i
)
{
const
QString
&
fileName
=
files
.
at
(
i
);
future
.
setProgressValueAndText
(
i
,
QFileInfo
(
fileName
).
fileName
());
Document
::
Ptr
previousDoc
=
snapshot
.
value
(
fileName
);
if
(
previousDoc
)
{
if
(
Document
::
Ptr
previousDoc
=
snapshot
.
value
(
fileName
))
{
Control
*
control
=
previousDoc
->
control
();
previousDoc
->
control
();
Identifier
*
id
=
control
->
findIdentifier
(
symbolId
->
chars
(),
symbolId
->
size
());
if
(
!
id
)
continue
;
// skip this document, it's not using symbolId.
...
...
@@ -462,6 +459,7 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
TranslationUnit
*
unit
=
doc
->
translationUnit
();
Control
*
control
=
doc
->
control
();
FastMacroResolver
fastMacroResolver
(
unit
,
snapshot
);
control
->
setMacroResolver
(
&
fastMacroResolver
);
doc
->
parse
();
control
->
setMacroResolver
(
0
);
...
...
Write
Preview
Markdown
is supported
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