Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
flatpak-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
Marco Bubke
flatpak-qt-creator
Commits
6f19835f
Commit
6f19835f
authored
14 years ago
by
Christian Kamm
Browse files
Options
Downloads
Patches
Plain Diff
C++ indenter: Ensure indent and padding are non-negative.
Reviewed-by: Roberto Raggi
parent
de187cb6
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/cppcodeformatter.cpp
+20
-4
20 additions, 4 deletions
src/plugins/cpptools/cppcodeformatter.cpp
with
20 additions
and
4 deletions
src/plugins/cpptools/cppcodeformatter.cpp
+
20
−
4
View file @
6f19835f
...
@@ -1247,6 +1247,12 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
...
@@ -1247,6 +1247,12 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
*
indentDepth
=
m_indentSize
;
*
indentDepth
=
m_indentSize
;
break
;
break
;
}
}
// ensure padding and indent are >= 0
*
indentDepth
=
qMax
(
0
,
*
indentDepth
);
*
savedIndentDepth
=
qMax
(
0
,
*
savedIndentDepth
);
*
paddingDepth
=
qMax
(
0
,
*
paddingDepth
);
*
savedPaddingDepth
=
qMax
(
0
,
*
savedPaddingDepth
);
}
}
void
QtStyleCodeFormatter
::
adjustIndent
(
const
QList
<
CPlusPlus
::
Token
>
&
tokens
,
int
lexerState
,
int
*
indentDepth
,
int
*
paddingDepth
)
const
void
QtStyleCodeFormatter
::
adjustIndent
(
const
QList
<
CPlusPlus
::
Token
>
&
tokens
,
int
lexerState
,
int
*
indentDepth
,
int
*
paddingDepth
)
const
...
@@ -1287,7 +1293,10 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
...
@@ -1287,7 +1293,10 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
if
(
topState
.
type
==
expression
&&
previousState
.
type
==
declaration_start
)
{
if
(
topState
.
type
==
expression
&&
previousState
.
type
==
declaration_start
)
{
*
paddingDepth
=
m_indentSize
;
*
paddingDepth
=
m_indentSize
;
}
else
if
(
topState
.
type
==
ternary_op
)
{
}
else
if
(
topState
.
type
==
ternary_op
)
{
*
paddingDepth
-=
2
;
if
(
*
paddingDepth
>=
2
)
*
paddingDepth
-=
2
;
else
*
paddingDepth
=
0
;
}
}
break
;
break
;
case
T_LBRACE
:
{
case
T_LBRACE
:
{
...
@@ -1382,8 +1391,12 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
...
@@ -1382,8 +1391,12 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
break
;
break
;
case
T_LESS_LESS
:
case
T_LESS_LESS
:
case
T_GREATER_GREATER
:
case
T_GREATER_GREATER
:
if
(
topState
.
type
==
stream_op
||
topState
.
type
==
stream_op_cont
)
if
(
topState
.
type
==
stream_op
||
topState
.
type
==
stream_op_cont
)
{
*
paddingDepth
-=
3
;
// to align << with <<
if
(
*
paddingDepth
>=
3
)
*
paddingDepth
-=
3
;
// to align << with <<
else
*
paddingDepth
=
0
;
}
break
;
break
;
case
T_COMMENT
:
case
T_COMMENT
:
case
T_DOXY_COMMENT
:
case
T_DOXY_COMMENT
:
...
@@ -1395,7 +1408,10 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
...
@@ -1395,7 +1408,10 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
&&
(
kind
==
T_COMMENT
||
kind
==
T_DOXY_COMMENT
)
&&
(
kind
==
T_COMMENT
||
kind
==
T_DOXY_COMMENT
)
&&
(
lexerState
==
Lexer
::
State_Default
&&
(
lexerState
==
Lexer
::
State_Default
||
tokens
.
size
()
!=
1
))
{
||
tokens
.
size
()
!=
1
))
{
*
indentDepth
-=
m_indentSize
;
if
(
*
indentDepth
>=
m_indentSize
)
*
indentDepth
-=
m_indentSize
;
else
*
indentDepth
=
0
;
}
}
break
;
break
;
}
}
...
...
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