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
9a211433
Commit
9a211433
authored
Sep 30, 2009
by
Roberto Raggi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented a simple(fast?) strategy to resolve macro references.
parent
e50d60ac
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
3 deletions
+103
-3
src/libs/cplusplus/FastPreprocessor.cpp
src/libs/cplusplus/FastPreprocessor.cpp
+62
-0
src/libs/cplusplus/FastPreprocessor.h
src/libs/cplusplus/FastPreprocessor.h
+19
-0
src/plugins/cppeditor/cppeditor.cpp
src/plugins/cppeditor/cppeditor.cpp
+7
-2
src/plugins/cpptools/cppfindreferences.cpp
src/plugins/cpptools/cppfindreferences.cpp
+11
-1
src/shared/cplusplus/Parser.cpp
src/shared/cplusplus/Parser.cpp
+4
-0
No files found.
src/libs/cplusplus/FastPreprocessor.cpp
View file @
9a211433
...
...
@@ -28,9 +28,71 @@
**************************************************************************/
#include "FastPreprocessor.h"
#include <Literals.h>
#include <TranslationUnit.h>
using
namespace
CPlusPlus
;
FastMacroResolver
::
FastMacroResolver
(
const
Snapshot
&
snapshot
)
:
_snapshot
(
snapshot
)
{
}
bool
FastMacroResolver
::
isMacro
(
TranslationUnit
*
unit
,
unsigned
tokenIndex
)
const
{
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
;
}
bool
FastMacroResolver
::
isMacro_helper
(
const
QByteArray
&
macroName
,
const
QString
&
fileName
,
QSet
<
QString
>
*
processed
,
bool
*
done
)
const
{
if
(
processed
->
contains
(
fileName
))
return
false
;
processed
->
insert
(
fileName
);
if
(
Document
::
Ptr
doc
=
_snapshot
.
value
(
fileName
))
{
const
QList
<
Macro
>
definedMacros
=
doc
->
definedMacros
();
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
;
}
}
foreach
(
const
Document
::
Include
&
incl
,
doc
->
includes
())
{
if
(
isMacro_helper
(
macroName
,
incl
.
fileName
(),
processed
,
done
))
return
true
;
else
if
(
*
done
)
return
false
;
}
}
return
false
;
}
FastPreprocessor
::
FastPreprocessor
(
const
Snapshot
&
snapshot
)
:
_snapshot
(
snapshot
),
_preproc
(
this
,
&
_env
)
...
...
src/libs/cplusplus/FastPreprocessor.h
View file @
9a211433
...
...
@@ -34,11 +34,30 @@
#include "CppDocument.h"
#include "pp.h"
#include <Control.h>
#include <QtCore/QSet>
#include <QtCore/QString>
namespace
CPlusPlus
{
class
CPLUSPLUS_EXPORT
FastMacroResolver
:
public
MacroResolver
{
public:
FastMacroResolver
(
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
;
private:
Snapshot
_snapshot
;
};
class
CPLUSPLUS_EXPORT
FastPreprocessor
:
public
Client
{
Environment
_env
;
...
...
src/plugins/cppeditor/cppeditor.cpp
View file @
9a211433
...
...
@@ -57,6 +57,8 @@
#include <cplusplus/TypeOfExpression.h>
#include <cplusplus/MatchingText.h>
#include <cplusplus/BackwardsScanner.h>
#include <cplusplus/FastPreprocessor.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <coreplugin/icore.h>
...
...
@@ -2064,10 +2066,13 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
if
(
!
doc
)
{
const
QByteArray
preprocessedCode
=
source
.
snapshot
.
preprocessedCode
(
source
.
code
,
source
.
fileName
);
snapshot
=
source
.
snapshot
;
doc
=
source
.
snapshot
.
documentFromSource
(
preprocessedCode
,
source
.
fileName
);
doc
->
check
();
snapshot
=
source
.
snapshot
;
FastMacroResolver
fastMacroResolver
(
snapshot
);
doc
->
control
()
->
setMacroResolver
(
&
fastMacroResolver
);
doc
->
check
();
doc
->
control
()
->
setMacroResolver
(
0
);
}
Control
*
control
=
doc
->
control
();
...
...
src/plugins/cpptools/cppfindreferences.cpp
View file @
9a211433
...
...
@@ -52,6 +52,7 @@
#include <cplusplus/ResolveExpression.h>
#include <cplusplus/Overview.h>
#include <cplusplus/TypeOfExpression.h>
#include <cplusplus/FastPreprocessor.h>
#include <QtCore/QTime>
#include <QtCore/QtConcurrentRun>
...
...
@@ -425,6 +426,8 @@ 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
());
...
...
@@ -456,8 +459,15 @@ static void find_helper(QFutureInterface<Core::Utils::FileSearchResult> &future,
Control
*
control
=
doc
->
control
();
if
(
Identifier
*
id
=
control
->
findIdentifier
(
symbolId
->
chars
(),
symbolId
->
size
()))
{
doc
->
check
();
TranslationUnit
*
unit
=
doc
->
translationUnit
();
Control
*
control
=
doc
->
control
();
control
->
setMacroResolver
(
&
fastMacroResolver
);
doc
->
parse
();
control
->
setMacroResolver
(
0
);
doc
->
check
();
Process
process
(
doc
,
snapshot
,
&
future
);
process
(
symbol
,
id
,
unit
->
ast
());
}
...
...
src/shared/cplusplus/Parser.cpp
View file @
9a211433
...
...
@@ -2561,6 +2561,10 @@ bool Parser::parseBuiltinTypeSpecifier(SpecifierAST *&node)
bool
Parser
::
parseSimpleDeclaration
(
DeclarationAST
*&
node
,
bool
acceptStructDeclarator
)
{
if
(
LA
()
==
T_IDENTIFIER
&&
isMacro
(
cursor
()))
{
// printf("***** found macro reference `%s'\n", tok().identifier->chars());
}
unsigned
qt_invokable_token
=
0
;
if
(
acceptStructDeclarator
&&
(
LA
()
==
T_Q_SIGNAL
||
LA
()
==
T_Q_SLOT
))
qt_invokable_token
=
consumeToken
();
...
...
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