Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
e2a0a4d7
Commit
e2a0a4d7
authored
Jun 15, 2009
by
Roberto Raggi
Browse files
Keep the original encoded text around while preprocessing.
parent
dbba0ff8
Changes
12
Hide whitespace changes
Inline
Side-by-side
src/libs/cplusplus/CppDocument.cpp
View file @
e2a0a4d7
...
...
@@ -356,7 +356,7 @@ void Snapshot::insert(Document::Ptr doc)
insert
(
doc
->
fileName
(),
doc
);
}
QByteArray
Snapshot
::
preprocessedCode
(
const
Q
ByteArray
&
source
,
const
QString
&
fileName
)
const
QByteArray
Snapshot
::
preprocessedCode
(
const
Q
String
&
source
,
const
QString
&
fileName
)
const
{
FastPreprocessor
pp
(
*
this
);
return
pp
.
run
(
fileName
,
source
);
...
...
src/libs/cplusplus/CppDocument.h
View file @
e2a0a4d7
...
...
@@ -272,7 +272,7 @@ public:
Snapshot
();
~
Snapshot
();
QByteArray
preprocessedCode
(
const
Q
ByteArray
&
source
,
QByteArray
preprocessedCode
(
const
Q
String
&
source
,
const
QString
&
fileName
)
const
;
Document
::
Ptr
documentFromSource
(
const
QByteArray
&
preprocessedCode
,
...
...
src/libs/cplusplus/FastPreprocessor.cpp
View file @
e2a0a4d7
...
...
@@ -36,7 +36,7 @@ FastPreprocessor::FastPreprocessor(const Snapshot &snapshot)
_preproc
(
this
,
&
_env
)
{
}
QByteArray
FastPreprocessor
::
run
(
QString
fileName
,
const
Q
ByteArray
&
source
)
QByteArray
FastPreprocessor
::
run
(
QString
fileName
,
const
Q
String
&
source
)
{
const
QByteArray
preprocessed
=
_preproc
(
fileName
,
source
);
return
preprocessed
;
...
...
src/libs/cplusplus/FastPreprocessor.h
View file @
e2a0a4d7
...
...
@@ -51,7 +51,7 @@ class CPLUSPLUS_EXPORT FastPreprocessor: public Client
public:
FastPreprocessor
(
const
Snapshot
&
snapshot
);
QByteArray
run
(
QString
fileName
,
const
Q
ByteArray
&
source
);
QByteArray
run
(
QString
fileName
,
const
Q
String
&
source
);
// CPlusPlus::Client
virtual
void
sourceNeeded
(
QString
&
fileName
,
IncludeType
,
unsigned
)
...
...
src/libs/cplusplus/pp-engine.cpp
View file @
e2a0a4d7
...
...
@@ -564,11 +564,21 @@ void Preprocessor::popState()
_savedStates
.
removeLast
();
}
QByteArray
Preprocessor
::
operator
()(
const
QString
&
filename
,
QByteArray
Preprocessor
::
operator
()(
const
QString
&
fileName
,
const
QString
&
source
)
{
const
QString
previousOriginalSource
=
_originalSource
;
_originalSource
=
source
;
const
QByteArray
bytes
=
source
.
toLatin1
();
const
QByteArray
preprocessedCode
=
operator
()(
fileName
,
bytes
);
_originalSource
=
previousOriginalSource
;
return
preprocessedCode
;
}
QByteArray
Preprocessor
::
operator
()(
const
QString
&
fileName
,
const
QByteArray
&
source
)
{
QByteArray
preprocessed
;
preprocess
(
file
n
ame
,
source
,
&
preprocessed
);
preprocess
(
file
N
ame
,
source
,
&
preprocessed
);
return
preprocessed
;
}
...
...
@@ -1098,7 +1108,7 @@ void Preprocessor::processInclude(bool, TokenIterator firstToken,
const
char
*
beginOfPath
=
endOfToken
(
*
start
);
const
char
*
endOfPath
=
startOfToken
(
*
tk
);
QString
fn
=
QS
tring
::
fromUtf8
(
beginOfPath
,
endOfPath
-
beginOfPath
);
QString
fn
=
s
tring
(
beginOfPath
,
endOfPath
-
beginOfPath
);
client
->
sourceNeeded
(
fn
,
Client
::
IncludeGlobal
,
firstToken
->
lineno
);
}
else
if
(
tk
->
is
(
T_ANGLE_STRING_LITERAL
)
||
tk
->
is
(
T_STRING_LITERAL
))
{
...
...
@@ -1111,7 +1121,7 @@ void Preprocessor::processInclude(bool, TokenIterator firstToken,
if
(
beginOfPath
+
1
!=
endOfPath
&&
((
quote
==
'"'
&&
endOfPath
[
-
1
]
==
'"'
)
||
(
quote
==
'<'
&&
endOfPath
[
-
1
]
==
'>'
)))
{
QString
fn
=
QS
tring
::
fromUtf8
(
beginOfPath
+
1
,
spell
.
length
()
-
2
);
QString
fn
=
s
tring
(
beginOfPath
+
1
,
spell
.
length
()
-
2
);
client
->
sourceNeeded
(
fn
,
Client
::
IncludeLocal
,
firstToken
->
lineno
);
}
}
...
...
@@ -1422,3 +1432,12 @@ bool Preprocessor::isQtReservedWord(const QByteArray ¯oId) const
return
true
;
return
false
;
}
QString
Preprocessor
::
string
(
const
char
*
first
,
int
length
)
const
{
if
(
_originalSource
.
isEmpty
())
return
QString
::
fromUtf8
(
first
,
length
);
const
int
position
=
first
-
_source
.
constData
();
return
_originalSource
.
mid
(
position
,
length
);
}
src/libs/cplusplus/pp-engine.h
View file @
e2a0a4d7
...
...
@@ -50,25 +50,23 @@
#define CPLUSPLUS_PP_ENGINE_H
#include
"PreprocessorClient.h"
#include
"pp-macro-expander.h"
#include
<Token.h>
#include
<QVector>
namespace
CPlusPlus
{
class
Token
;
}
namespace
CPlusPlus
{
struct
Value
;
class
Environment
;
class
CPLUSPLUS_EXPORT
Preprocessor
{
public:
Preprocessor
(
Client
*
client
,
Environment
*
env
);
QByteArray
operator
()(
const
QString
&
filename
,
const
QByteArray
&
source
);
QByteArray
operator
()(
const
QString
&
filename
,
const
QString
&
source
);
QByteArray
operator
()(
const
QString
&
filename
,
const
QByteArray
&
source
);
void
preprocess
(
const
QString
&
filename
,
const
QByteArray
&
source
,
...
...
@@ -169,6 +167,8 @@ private:
void
out
(
char
ch
);
void
out
(
const
char
*
s
);
QString
string
(
const
char
*
first
,
int
len
)
const
;
private:
Client
*
client
;
Environment
*
env
;
...
...
@@ -186,6 +186,8 @@ private:
QByteArray
*
_result
;
bool
_markGeneratedTokens
;
QString
_originalSource
;
};
}
// namespace CPlusPlus
...
...
src/plugins/cppeditor/cppeditor.cpp
View file @
e2a0a4d7
...
...
@@ -495,7 +495,7 @@ void CPPEditor::reformatDocument()
QByteArray
source
=
toPlainText
().
toUtf8
();
Control
control
;
StringLiteral
*
fileId
=
control
.
findOrInsert
FileName
(
"<file>"
);
StringLiteral
*
fileId
=
control
.
findOrInsert
StringLiteral
(
"<file>"
);
TranslationUnit
unit
(
&
control
,
fileId
);
unit
.
setQtMocRunEnabled
(
true
);
unit
.
setSource
(
source
.
constData
(),
source
.
length
());
...
...
src/plugins/cpptools/cppmodelmanager.cpp
View file @
e2a0a4d7
...
...
@@ -171,7 +171,7 @@ public:
CppPreprocessor
(
QPointer
<
CppModelManager
>
modelManager
);
virtual
~
CppPreprocessor
();
void
setWorkingCopy
(
const
QMap
<
QString
,
Q
ByteArray
>
&
workingCopy
);
void
setWorkingCopy
(
const
QMap
<
QString
,
Q
String
>
&
workingCopy
);
void
setIncludePaths
(
const
QStringList
&
includePaths
);
void
setFrameworkPaths
(
const
QStringList
&
frameworkPaths
);
void
setProjectFiles
(
const
QStringList
&
files
);
...
...
@@ -190,8 +190,8 @@ public: // attributes
protected:
CPlusPlus
::
Document
::
Ptr
switchDocument
(
CPlusPlus
::
Document
::
Ptr
doc
);
bool
includeFile
(
const
QString
&
absoluteFilePath
,
Q
ByteArray
*
result
);
Q
ByteArray
tryIncludeFile
(
QString
&
fileName
,
IncludeType
type
);
bool
includeFile
(
const
QString
&
absoluteFilePath
,
Q
String
*
result
);
Q
String
tryIncludeFile
(
QString
&
fileName
,
IncludeType
type
);
void
mergeEnvironment
(
CPlusPlus
::
Document
::
Ptr
doc
);
...
...
@@ -212,7 +212,7 @@ private:
Preprocessor
preprocess
;
QStringList
m_includePaths
;
QStringList
m_systemIncludePaths
;
QMap
<
QString
,
Q
ByteArray
>
m_workingCopy
;
QMap
<
QString
,
Q
String
>
m_workingCopy
;
QStringList
m_projectFiles
;
QStringList
m_frameworkPaths
;
QSet
<
QString
>
m_included
;
...
...
@@ -233,7 +233,7 @@ CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager)
CppPreprocessor
::~
CppPreprocessor
()
{
}
void
CppPreprocessor
::
setWorkingCopy
(
const
QMap
<
QString
,
Q
ByteArray
>
&
workingCopy
)
void
CppPreprocessor
::
setWorkingCopy
(
const
QMap
<
QString
,
Q
String
>
&
workingCopy
)
{
m_workingCopy
=
workingCopy
;
}
void
CppPreprocessor
::
setIncludePaths
(
const
QStringList
&
includePaths
)
...
...
@@ -543,13 +543,13 @@ class Process: public std::unary_function<Document::Ptr, void>
{
QPointer
<
CppModelManager
>
_modelManager
;
Snapshot
_snapshot
;
QMap
<
QString
,
Q
ByteArray
>
_workingCopy
;
QMap
<
QString
,
Q
String
>
_workingCopy
;
Document
::
Ptr
_doc
;
public:
Process
(
QPointer
<
CppModelManager
>
modelManager
,
Snapshot
snapshot
,
const
QMap
<
QString
,
Q
ByteArray
>
&
workingCopy
)
const
QMap
<
QString
,
Q
String
>
&
workingCopy
)
:
_modelManager
(
modelManager
),
_snapshot
(
snapshot
),
_workingCopy
(
workingCopy
)
...
...
@@ -605,7 +605,7 @@ void CppPreprocessor::resetEnvironment()
m_processed
.
clear
();
}
bool
CppPreprocessor
::
includeFile
(
const
QString
&
absoluteFilePath
,
Q
ByteArray
*
result
)
bool
CppPreprocessor
::
includeFile
(
const
QString
&
absoluteFilePath
,
Q
String
*
result
)
{
if
(
absoluteFilePath
.
isEmpty
()
||
m_included
.
contains
(
absoluteFilePath
))
{
return
true
;
...
...
@@ -634,11 +634,11 @@ bool CppPreprocessor::includeFile(const QString &absoluteFilePath, QByteArray *r
return
false
;
}
Q
ByteArray
CppPreprocessor
::
tryIncludeFile
(
QString
&
fileName
,
IncludeType
type
)
Q
String
CppPreprocessor
::
tryIncludeFile
(
QString
&
fileName
,
IncludeType
type
)
{
QFileInfo
fileInfo
(
fileName
);
if
(
fileName
==
QLatin1String
(
pp_configuration_file
)
||
fileInfo
.
isAbsolute
())
{
Q
ByteArray
contents
;
Q
String
contents
;
includeFile
(
fileName
,
&
contents
);
return
contents
;
}
...
...
@@ -649,7 +649,7 @@ QByteArray CppPreprocessor::tryIncludeFile(QString &fileName, IncludeType type)
path
+=
QLatin1Char
(
'/'
);
path
+=
fileName
;
path
=
QDir
::
cleanPath
(
path
);
Q
ByteArray
contents
;
Q
String
contents
;
if
(
includeFile
(
path
,
&
contents
))
{
fileName
=
path
;
return
contents
;
...
...
@@ -661,7 +661,7 @@ QByteArray CppPreprocessor::tryIncludeFile(QString &fileName, IncludeType type)
path
+=
QLatin1Char
(
'/'
);
path
+=
fileName
;
path
=
QDir
::
cleanPath
(
path
);
Q
ByteArray
contents
;
Q
String
contents
;
if
(
includeFile
(
path
,
&
contents
))
{
fileName
=
path
;
return
contents
;
...
...
@@ -674,7 +674,7 @@ QByteArray CppPreprocessor::tryIncludeFile(QString &fileName, IncludeType type)
path
+=
QLatin1Char
(
'/'
);
path
+=
fileName
;
path
=
QDir
::
cleanPath
(
path
);
Q
ByteArray
contents
;
Q
String
contents
;
if
(
includeFile
(
path
,
&
contents
))
{
fileName
=
path
;
return
contents
;
...
...
@@ -693,7 +693,7 @@ QByteArray CppPreprocessor::tryIncludeFile(QString &fileName, IncludeType type)
path
+=
QLatin1String
(
".framework/Headers/"
);
path
+=
name
;
path
=
QDir
::
cleanPath
(
path
);
Q
ByteArray
contents
;
Q
String
contents
;
if
(
includeFile
(
path
,
&
contents
))
{
fileName
=
path
;
return
contents
;
...
...
@@ -708,14 +708,14 @@ QByteArray CppPreprocessor::tryIncludeFile(QString &fileName, IncludeType type)
foreach
(
const
QString
&
projectFile
,
m_projectFiles
)
{
if
(
projectFile
.
endsWith
(
path
))
{
fileName
=
projectFile
;
Q
ByteArray
contents
;
Q
String
contents
;
includeFile
(
fileName
,
&
contents
);
return
contents
;
}
}
//qDebug() << "**** file" << fileName << "not found!";
return
Q
ByteArray
();
return
Q
String
();
}
void
CppPreprocessor
::
macroAdded
(
const
Macro
&
macro
)
...
...
@@ -790,7 +790,7 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type,
if
(
fileName
.
isEmpty
())
return
;
Q
ByteArray
contents
=
tryIncludeFile
(
fileName
,
type
);
Q
String
contents
=
tryIncludeFile
(
fileName
,
type
);
if
(
m_currentDoc
)
{
m_currentDoc
->
addIncludeFile
(
fileName
,
line
);
...
...
@@ -822,7 +822,7 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type,
Document
::
Ptr
previousDoc
=
switchDocument
(
doc
);
const
QByteArray
preprocessedCode
=
preprocess
(
fileName
.
toUtf8
()
,
contents
);
const
QByteArray
preprocessedCode
=
preprocess
(
fileName
,
contents
);
doc
->
setSource
(
preprocessedCode
);
doc
->
tokenize
();
...
...
@@ -984,9 +984,9 @@ void CppModelManager::removeEditorSupport(AbstractEditorSupport *editorSupport)
m_addtionalEditorSupport
.
remove
(
editorSupport
);
}
QMap
<
QString
,
Q
ByteArray
>
CppModelManager
::
buildWorkingCopyList
()
QMap
<
QString
,
Q
String
>
CppModelManager
::
buildWorkingCopyList
()
{
QMap
<
QString
,
Q
ByteArray
>
workingCopy
;
QMap
<
QString
,
Q
String
>
workingCopy
;
QMapIterator
<
TextEditor
::
ITextEditor
*
,
CppEditorSupport
*>
it
(
m_editorSupport
);
while
(
it
.
hasNext
())
{
it
.
next
();
...
...
@@ -1041,7 +1041,7 @@ void CppModelManager::updateProjectInfo(const ProjectInfo &pinfo)
QFuture
<
void
>
CppModelManager
::
refreshSourceFiles
(
const
QStringList
&
sourceFiles
)
{
if
(
!
sourceFiles
.
isEmpty
()
&&
qgetenv
(
"QTCREATOR_NO_CODE_INDEXER"
).
isNull
())
{
const
QMap
<
QString
,
Q
ByteArray
>
workingCopy
=
buildWorkingCopyList
();
const
QMap
<
QString
,
Q
String
>
workingCopy
=
buildWorkingCopyList
();
CppPreprocessor
*
preproc
=
new
CppPreprocessor
(
this
);
preproc
->
setProjectFiles
(
projectFiles
());
...
...
src/plugins/cpptools/cppmodelmanager.h
View file @
e2a0a4d7
...
...
@@ -89,7 +89,7 @@ public:
CppEditorSupport
*
editorSupport
(
TextEditor
::
ITextEditor
*
editor
)
const
{
return
m_editorSupport
.
value
(
editor
);
}
QMap
<
QString
,
Q
ByteArray
>
buildWorkingCopyList
();
QMap
<
QString
,
Q
String
>
buildWorkingCopyList
();
void
emitDocumentUpdated
(
CPlusPlus
::
Document
::
Ptr
doc
);
...
...
src/plugins/cpptools/cppsemanticsearch.cpp
View file @
e2a0a4d7
...
...
@@ -262,7 +262,7 @@ SemanticSearch *SearchFunctionCallFactory::create(QFutureInterface<Core::Utils::
static
void
semanticSearch_helper
(
QFutureInterface
<
Core
::
Utils
::
FileSearchResult
>
&
future
,
QPointer
<
CppModelManager
>
modelManager
,
QMap
<
QString
,
Q
ByteArray
>
wl
,
QMap
<
QString
,
Q
String
>
wl
,
SemanticSearchFactory
::
Ptr
factory
)
{
const
Snapshot
snapshot
=
modelManager
->
snapshot
();
...
...
@@ -277,14 +277,14 @@ static void semanticSearch_helper(QFutureInterface<Core::Utils::FileSearchResult
QByteArray
source
;
if
(
wl
.
contains
(
fileName
))
source
=
wl
.
value
(
fileName
);
source
=
snapshot
.
preprocessedCode
(
wl
.
value
(
fileName
),
fileName
);
else
{
QFile
file
(
fileName
);
if
(
!
file
.
open
(
QFile
::
ReadOnly
))
continue
;
const
QString
contents
=
QTextStream
(
&
file
).
readAll
();
// ### FIXME
source
=
snapshot
.
preprocessedCode
(
contents
.
toUtf8
()
,
fileName
);
source
=
snapshot
.
preprocessedCode
(
contents
,
fileName
);
}
Document
::
Ptr
newDoc
=
snapshot
.
documentFromSource
(
source
,
fileName
);
...
...
src/plugins/cpptools/cpptoolseditorsupport.cpp
View file @
e2a0a4d7
...
...
@@ -348,12 +348,12 @@ void CppEditorSupport::setTextEditor(TextEditor::ITextEditor *textEditor)
updateDocument
();
}
Q
ByteArray
CppEditorSupport
::
contents
()
Q
String
CppEditorSupport
::
contents
()
{
if
(
!
_textEditor
)
return
Q
ByteArray
();
return
Q
String
();
else
if
(
!
_cachedContents
.
isEmpty
())
_cachedContents
=
_textEditor
->
contents
()
.
toUtf8
()
;
_cachedContents
=
_textEditor
->
contents
();
return
_cachedContents
;
}
...
...
@@ -403,7 +403,7 @@ void CppEditorSupport::checkDocumentNow()
qobject_cast
<
TextEditor
::
BaseTextEditor
*>
(
_textEditor
->
widget
());
Snapshot
snapshot
=
_modelManager
->
snapshot
();
const
Q
ByteArray
plainText
=
contents
();
const
Q
String
plainText
=
contents
();
const
QString
fileName
=
_textEditor
->
file
()
->
fileName
();
const
QByteArray
preprocessedCode
=
snapshot
.
preprocessedCode
(
plainText
,
fileName
);
...
...
src/plugins/cpptools/cpptoolseditorsupport.h
View file @
e2a0a4d7
...
...
@@ -112,7 +112,7 @@ public:
int
updateDocumentInterval
()
const
;
void
setUpdateDocumentInterval
(
int
updateDocumentInterval
);
Q
ByteArray
contents
();
// UTF-8 encoded
Q
String
contents
();
Q_SIGNALS:
void
contentsChanged
();
...
...
@@ -132,7 +132,7 @@ private:
QTimer
*
_updateDocumentTimer
;
int
_updateDocumentInterval
;
QFuture
<
void
>
_documentParser
;
Q
ByteArray
_cachedContents
;
Q
String
_cachedContents
;
QTimer
*
_quickFixTimer
;
TextEditor
::
ITextMark
*
_quickFixMark
;
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment