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
Marco Bubke
flatpak-qt-creator
Commits
d8427157
Commit
d8427157
authored
Nov 27, 2009
by
Christian Kamm
Browse files
Quickfix: Disallow semantically invalid splits of if statements.
parent
dd71d9a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/plugins/cppeditor/cppquickfix.cpp
View file @
d8427157
...
...
@@ -671,6 +671,7 @@ public:
if
(
!
pattern
)
return
-
1
;
unsigned
splitKind
=
0
;
for
(
++
index
;
index
<
path
.
size
();
++
index
)
{
AST
*
node
=
path
.
at
(
index
);
condition
=
node
->
asBinaryExpression
();
...
...
@@ -678,12 +679,21 @@ public:
return
-
1
;
Token
binaryToken
=
tokenAt
(
condition
->
binary_op_token
);
if
(
binaryToken
.
is
(
T_AMPER_AMPER
)
||
binaryToken
.
is
(
T_PIPE_PIPE
))
{
if
(
isCursorOn
(
condition
->
binary_op_token
))
return
index
;
}
else
{
// only accept a chain of ||s or &&s - no mixing
if
(
!
splitKind
)
{
splitKind
=
binaryToken
.
kind
();
if
(
splitKind
!=
T_AMPER_AMPER
&&
splitKind
!=
T_PIPE_PIPE
)
return
-
1
;
// we can't reliably split &&s in ifs with an else branch
if
(
splitKind
==
T_AMPER_AMPER
&&
pattern
->
else_statement
)
return
-
1
;
}
else
if
(
splitKind
!=
binaryToken
.
kind
())
{
return
-
1
;
}
if
(
isCursorOn
(
condition
->
binary_op_token
))
return
index
;
}
return
-
1
;
...
...
@@ -719,7 +729,7 @@ public:
setTopLevelNode
(
pattern
);
int
insertPos
=
endOf
(
pattern
);
int
insertPos
=
endOf
(
ifTrueStatement
);
if
(
compoundStatement
)
insert
(
insertPos
,
QLatin1String
(
" "
));
else
...
...
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