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
769d6282
Commit
769d6282
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Some work on rewriting conditionals.
parent
13225875
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/plugins/cpptools/cpptoolseditorsupport.cpp
+76
-10
76 additions, 10 deletions
src/plugins/cpptools/cpptoolseditorsupport.cpp
with
76 additions
and
10 deletions
src/plugins/cpptools/cpptoolseditorsupport.cpp
+
76
−
10
View file @
769d6282
...
...
@@ -111,6 +111,47 @@ public:
}
};
class
RewriteConditional
:
public
QuickFixOperation
{
QString
_source
;
BinaryExpressionAST
*
_binaryExpression
;
public:
RewriteConditional
(
const
QString
&
source
,
BinaryExpressionAST
*
node
,
Document
::
Ptr
doc
,
const
Snapshot
&
snapshot
)
:
QuickFixOperation
(
doc
,
snapshot
),
_source
(
source
),
_binaryExpression
(
node
)
{
}
virtual
QString
description
()
const
{
return
QString
::
fromUtf8
(
"Rewrite conditional (%1)"
).
arg
(
_source
.
simplified
());
}
virtual
void
apply
(
QTextCursor
tc
)
{
setTextCursor
(
tc
);
tc
.
beginEditBlock
();
UnaryExpressionAST
*
left_unary_expr
=
_binaryExpression
->
left_expression
->
asUnaryExpression
();
UnaryExpressionAST
*
right_unary_expr
=
_binaryExpression
->
right_expression
->
asUnaryExpression
();
QTextCursor
left_not_op
=
cursor
(
left_unary_expr
->
unary_op_token
);
QTextCursor
right_not_op
=
cursor
(
right_unary_expr
->
unary_op_token
);
QTextCursor
log_and_op
=
cursor
(
_binaryExpression
->
binary_op_token
);
QTextCursor
begin_of_expr
=
moveAtStartOfToken
(
_binaryExpression
->
firstToken
());
QTextCursor
end_of_expr
=
moveAtEndOfToken
(
_binaryExpression
->
lastToken
()
-
1
);
left_not_op
.
removeSelectedText
();
right_not_op
.
removeSelectedText
();
log_and_op
.
insertText
(
QLatin1String
(
"||"
));
begin_of_expr
.
insertText
(
QLatin1String
(
"!("
));
end_of_expr
.
insertText
(
QLatin1String
(
")"
));
tc
.
endEditBlock
();
}
};
class
CheckDocument
:
protected
ASTVisitor
{
QTextCursor
_textCursor
;
...
...
@@ -154,23 +195,48 @@ protected:
return
true
;
}
/*
virtual bool visit(ForStatementAST *ast)
QTextCursor
moveAtStartOfToken
(
unsigned
index
)
const
{
if (! checkPosition(ast))
return true;
unsigned
line
,
col
;
getTokenStartPosition
(
index
,
&
line
,
&
col
);
QTextCursor
tc
=
_textCursor
;
tc
.
setPosition
(
tc
.
document
()
->
findBlockByNumber
(
line
-
1
).
position
()
+
col
-
1
);
return
tc
;
}
QTextCursor
moveAtEndOfToken
(
unsigned
index
)
const
{
const
Token
&
tk
=
tokenAt
(
index
);
if (ast->initializer && ast->initializer->asDeclarationStatement() != 0) {
if (checkPosition(ast->initializer)) {
// move initializer
_nodes.append(ast);
unsigned
line
,
col
;
getTokenStartPosition
(
index
,
&
line
,
&
col
);
QTextCursor
tc
=
_textCursor
;
tc
.
setPosition
(
tc
.
document
()
->
findBlockByNumber
(
line
-
1
).
position
()
+
col
+
tk
.
length
-
1
);
return
tc
;
}
virtual
bool
visit
(
BinaryExpressionAST
*
ast
)
{
if
(
ast
->
left_expression
&&
ast
->
right_expression
&&
tokenKind
(
ast
->
binary_op_token
)
==
T_AMPER_AMPER
&&
checkPosition
(
ast
))
{
UnaryExpressionAST
*
left_unary_expr
=
ast
->
left_expression
->
asUnaryExpression
();
UnaryExpressionAST
*
right_unary_expr
=
ast
->
right_expression
->
asUnaryExpression
();
if
(
left_unary_expr
&&
left_unary_expr
->
expression
&&
tokenKind
(
left_unary_expr
->
unary_op_token
)
==
T_NOT
&&
right_unary_expr
&&
right_unary_expr
->
expression
&&
tokenKind
(
right_unary_expr
->
unary_op_token
)
==
T_NOT
)
{
// replace !a && !b with !(a || b)
QTextCursor
beg
=
moveAtStartOfToken
(
ast
->
firstToken
());
QTextCursor
end
=
moveAtEndOfToken
(
ast
->
lastToken
()
-
1
);
beg
.
setPosition
(
end
.
position
(),
QTextCursor
::
KeepAnchor
);
QString
source
=
beg
.
selectedText
();
QuickFixOperationPtr
op
(
new
RewriteConditional
(
source
,
ast
,
_doc
,
_snapshot
));
_quickFixes
.
append
(
op
);
return
true
;
}
}
return
true
;
}
*/
virtual
bool
visit
(
CastExpressionAST
*
ast
)
{
...
...
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