Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
49c75444
Commit
49c75444
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Removed obsolete code.
parent
51fbf969
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/plugins/cppeditor/cppquickfix.cpp
+0
-186
0 additions, 186 deletions
src/plugins/cppeditor/cppquickfix.cpp
src/plugins/cppeditor/cppquickfix.h
+0
-2
0 additions, 2 deletions
src/plugins/cppeditor/cppquickfix.h
with
0 additions
and
188 deletions
src/plugins/cppeditor/cppquickfix.cpp
+
0
−
186
View file @
49c75444
...
@@ -910,165 +910,6 @@ private:
...
@@ -910,165 +910,6 @@ private:
PostfixExpressionAST
*
qlatin1Call
;
PostfixExpressionAST
*
qlatin1Call
;
};
};
/*
Replace
a + b
With
a % b
If a and b are of string type.
*/
class
UseFastStringConcatenation
:
public
QuickFixOperation
{
public:
UseFastStringConcatenation
()
{}
virtual
QString
description
()
const
{
return
QApplication
::
translate
(
"CppTools::QuickFix"
,
"Use Fast String Concatenation with %"
);
}
virtual
int
match
(
const
QList
<
AST
*>
&
path
)
{
if
(
path
.
isEmpty
())
return
-
1
;
// need to search 'up' too
int
index
=
path
.
size
()
-
1
;
if
(
BinaryExpressionAST
*
binary
=
asPlusNode
(
path
[
index
]))
{
while
(
0
!=
(
binary
=
asPlusNode
(
binary
->
left_expression
)))
_binaryExpressions
.
prepend
(
binary
);
}
// search 'down'
for
(
index
=
path
.
size
()
-
1
;
index
!=
-
1
;
--
index
)
{
AST
*
node
=
path
.
at
(
index
);
if
(
BinaryExpressionAST
*
binary
=
asPlusNode
(
node
))
{
_binaryExpressions
.
append
(
binary
);
}
else
if
(
!
_binaryExpressions
.
isEmpty
())
{
break
;
}
}
if
(
_binaryExpressions
.
isEmpty
())
return
-
1
;
// verify types of arguments
BinaryExpressionAST
*
prevBinary
=
0
;
foreach
(
BinaryExpressionAST
*
binary
,
_binaryExpressions
)
{
if
(
binary
->
left_expression
!=
prevBinary
)
{
if
(
!
hasCorrectType
(
binary
->
left_expression
))
return
-
1
;
}
if
(
binary
->
right_expression
!=
prevBinary
)
{
if
(
!
hasCorrectType
(
binary
->
right_expression
))
return
-
1
;
}
prevBinary
=
binary
;
}
return
index
+
_binaryExpressions
.
size
();
}
virtual
void
createChangeSet
()
{
// replace + -> %
foreach
(
BinaryExpressionAST
*
binary
,
_binaryExpressions
)
replace
(
binary
->
binary_op_token
,
"%"
);
// wrap literals in QLatin1Literal
foreach
(
StringLiteralAST
*
literal
,
_stringLiterals
)
{
insert
(
startOf
(
literal
),
"QLatin1Literal("
);
insert
(
endOf
(
literal
),
")"
);
}
// replace QLatin1String/QString/QByteArray(literal) -> QLatin1Literal(literal)
foreach
(
PostfixExpressionAST
*
postfix
,
_incorrectlyWrappedLiterals
)
{
replace
(
postfix
->
base_expression
,
"QLatin1Literal"
);
}
}
BinaryExpressionAST
*
asPlusNode
(
AST
*
ast
)
{
BinaryExpressionAST
*
binary
=
ast
->
asBinaryExpression
();
if
(
binary
&&
tokenAt
(
binary
->
binary_op_token
).
kind
()
==
T_PLUS
)
return
binary
;
return
0
;
}
bool
hasCorrectType
(
ExpressionAST
*
ast
)
{
if
(
StringLiteralAST
*
literal
=
ast
->
asStringLiteral
())
{
_stringLiterals
+=
literal
;
return
true
;
}
if
(
PostfixExpressionAST
*
postfix
=
ast
->
asPostfixExpression
())
{
if
(
postfix
->
base_expression
&&
postfix
->
postfix_expression_list
&&
postfix
->
postfix_expression_list
->
value
&&
!
postfix
->
postfix_expression_list
->
next
)
{
NameAST
*
name
=
postfix
->
base_expression
->
asName
();
CallAST
*
call
=
postfix
->
postfix_expression_list
->
value
->
asCall
();
if
(
name
&&
call
)
{
QByteArray
nameStr
(
name
->
name
->
identifier
()
->
chars
());
if
((
nameStr
==
"QLatin1String"
||
nameStr
==
"QString"
||
nameStr
==
"QByteArray"
)
&&
call
->
expression_list
&&
call
->
expression_list
->
value
&&
call
->
expression_list
->
value
->
asStringLiteral
()
&&
!
call
->
expression_list
->
next
)
{
_incorrectlyWrappedLiterals
+=
postfix
;
return
true
;
}
}
}
}
const
QList
<
LookupItem
>
&
lookup
=
typeOf
(
ast
);
if
(
lookup
.
isEmpty
())
return
false
;
return
isQtStringType
(
lookup
[
0
].
type
());
}
bool
isBuiltinStringType
(
FullySpecifiedType
type
)
{
// char*
if
(
PointerType
*
ptrTy
=
type
->
asPointerType
())
if
(
IntegerType
*
intTy
=
ptrTy
->
elementType
()
->
asIntegerType
())
if
(
intTy
->
kind
()
==
IntegerType
::
Char
)
return
true
;
return
false
;
}
bool
isQtStringType
(
FullySpecifiedType
type
)
{
if
(
NamedType
*
nameTy
=
type
->
asNamedType
())
{
if
(
!
nameTy
->
name
()
||
!
nameTy
->
name
()
->
identifier
())
return
false
;
QByteArray
name
(
nameTy
->
name
()
->
identifier
()
->
chars
());
if
(
name
==
"QString"
||
name
==
"QByteArray"
||
name
==
"QLatin1String"
||
name
==
"QLatin1Literal"
||
name
==
"QStringRef"
||
name
==
"QChar"
)
return
true
;
}
return
false
;
}
private
:
QList
<
BinaryExpressionAST
*>
_binaryExpressions
;
QList
<
StringLiteralAST
*>
_stringLiterals
;
QList
<
PostfixExpressionAST
*>
_incorrectlyWrappedLiterals
;
};
}
// end of anonymous namespace
}
// end of anonymous namespace
...
@@ -1318,31 +1159,6 @@ void QuickFixOperation::apply()
...
@@ -1318,31 +1159,6 @@ void QuickFixOperation::apply()
_textCursor
.
endEditBlock
();
_textCursor
.
endEditBlock
();
}
}
/**
* Returns a list of possible fully specified types associated with the
* given expression.
*
* NOTE: The fully specified types only stay valid until the next call to typeOf.
*/
const
QList
<
LookupItem
>
QuickFixOperation
::
typeOf
(
CPlusPlus
::
ExpressionAST
*
ast
)
{
#ifdef __GNUC__
# warning port me
#endif
qWarning
()
<<
Q_FUNC_INFO
<<
__LINE__
;
return
QList
<
LookupItem
>
();
#if 0
unsigned line, column;
document()->translationUnit()->getTokenStartPosition(ast->firstToken(), &line, &column);
Symbol *lastVisibleSymbol = document()->findSymbolAt(line, column);
ResolveExpression resolveExpression(lastVisibleSymbol, _lookupContext);
return resolveExpression(ast);
#endif
}
CPPQuickFixCollector
::
CPPQuickFixCollector
()
CPPQuickFixCollector
::
CPPQuickFixCollector
()
:
_modelManager
(
CppTools
::
CppModelManagerInterface
::
instance
()),
_editable
(
0
),
_editor
(
0
)
:
_modelManager
(
CppTools
::
CppModelManagerInterface
::
instance
()),
_editable
(
0
),
_editor
(
0
)
{
}
{
}
...
@@ -1395,7 +1211,6 @@ int CPPQuickFixCollector::startCompletion(TextEditor::ITextEditable *editable)
...
@@ -1395,7 +1211,6 @@ int CPPQuickFixCollector::startCompletion(TextEditor::ITextEditable *editable)
QSharedPointer
<
FlipBinaryOp
>
flipBinaryOp
(
new
FlipBinaryOp
());
QSharedPointer
<
FlipBinaryOp
>
flipBinaryOp
(
new
FlipBinaryOp
());
QSharedPointer
<
WrapStringLiteral
>
wrapStringLiteral
(
new
WrapStringLiteral
());
QSharedPointer
<
WrapStringLiteral
>
wrapStringLiteral
(
new
WrapStringLiteral
());
QSharedPointer
<
CStringToNSString
>
wrapCString
(
new
CStringToNSString
());
QSharedPointer
<
CStringToNSString
>
wrapCString
(
new
CStringToNSString
());
QSharedPointer
<
UseFastStringConcatenation
>
useFastStringConcat
(
new
UseFastStringConcatenation
());
QList
<
QuickFixOperationPtr
>
candidates
;
QList
<
QuickFixOperationPtr
>
candidates
;
candidates
.
append
(
rewriteLogicalAndOp
);
candidates
.
append
(
rewriteLogicalAndOp
);
...
@@ -1409,7 +1224,6 @@ int CPPQuickFixCollector::startCompletion(TextEditor::ITextEditable *editable)
...
@@ -1409,7 +1224,6 @@ int CPPQuickFixCollector::startCompletion(TextEditor::ITextEditable *editable)
candidates
.
append
(
wrapStringLiteral
);
candidates
.
append
(
wrapStringLiteral
);
if
(
_editor
->
mimeType
()
==
CppTools
::
Constants
::
OBJECTIVE_CPP_SOURCE_MIMETYPE
)
if
(
_editor
->
mimeType
()
==
CppTools
::
Constants
::
OBJECTIVE_CPP_SOURCE_MIMETYPE
)
candidates
.
append
(
wrapCString
);
candidates
.
append
(
wrapCString
);
candidates
.
append
(
useFastStringConcat
);
QMap
<
int
,
QList
<
QuickFixOperationPtr
>
>
matchedOps
;
QMap
<
int
,
QList
<
QuickFixOperationPtr
>
>
matchedOps
;
...
...
This diff is collapsed.
Click to expand it.
src/plugins/cppeditor/cppquickfix.h
+
0
−
2
View file @
49c75444
...
@@ -129,8 +129,6 @@ protected:
...
@@ -129,8 +129,6 @@ protected:
Range
createRange
(
CPlusPlus
::
AST
*
ast
)
const
;
// ### rename me
Range
createRange
(
CPlusPlus
::
AST
*
ast
)
const
;
// ### rename me
void
reindent
(
const
Range
&
range
);
void
reindent
(
const
Range
&
range
);
const
QList
<
CPlusPlus
::
LookupItem
>
typeOf
(
CPlusPlus
::
ExpressionAST
*
ast
);
private
:
private
:
CPlusPlus
::
Document
::
Ptr
_document
;
CPlusPlus
::
Document
::
Ptr
_document
;
CPlusPlus
::
Snapshot
_snapshot
;
CPlusPlus
::
Snapshot
_snapshot
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment