Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Tobias Hunger
qt-creator
Commits
a49395a0
Commit
a49395a0
authored
Sep 21, 2009
by
Roberto Raggi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the indenter more Qt friendly. Added support for moc keywords.
parent
0bcbab86
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
45 deletions
+35
-45
src/libs/cplusplus/BackwardsScanner.cpp
src/libs/cplusplus/BackwardsScanner.cpp
+6
-20
src/libs/cplusplus/BackwardsScanner.h
src/libs/cplusplus/BackwardsScanner.h
+2
-2
src/libs/cplusplus/ExpressionUnderCursor.cpp
src/libs/cplusplus/ExpressionUnderCursor.cpp
+1
-1
src/libs/cplusplus/MatchingText.cpp
src/libs/cplusplus/MatchingText.cpp
+6
-6
src/libs/cplusplus/SimpleLexer.cpp
src/libs/cplusplus/SimpleLexer.cpp
+0
-13
src/plugins/cppeditor/cppeditor.cpp
src/plugins/cppeditor/cppeditor.cpp
+20
-3
No files found.
src/libs/cplusplus/BackwardsScanner.cpp
View file @
a49395a0
...
...
@@ -76,21 +76,9 @@ const SimpleToken &BackwardsScanner::fetchToken(int i)
QList
<
SimpleToken
>
adaptedTokens
;
for
(
int
i
=
0
;
i
<
_tokens
.
size
();
++
i
)
{
SimpleToken
t
=
_tokens
.
at
(
i
);
if
(
i
==
0
)
{
Q_ASSERT
(
t
.
followsNewline
());
}
t
.
setPosition
(
t
.
position
()
+
blockText
.
length
());
t
.
setText
(
_text
.
midRef
(
t
.
position
(),
t
.
length
()));
if
(
i
==
0
)
{
Q_ASSERT
(
t
.
followsNewline
());
}
adaptedTokens
.
append
(
t
);
if
(
i
==
0
)
{
Q_ASSERT
(
adaptedTokens
.
last
().
followsNewline
());
}
}
_tokens
=
_tokenize
(
blockText
,
previousBlockState
(
_block
));
...
...
@@ -111,18 +99,16 @@ int BackwardsScanner::startPosition() const
QString
BackwardsScanner
::
text
()
const
{
return
_text
;
}
QString
BackwardsScanner
::
text
(
int
begin
,
int
end
)
const
QString
BackwardsScanner
::
text
(
int
index
)
const
{
const
SimpleToken
&
firstToken
=
_tokens
.
at
(
begin
+
_offset
);
const
SimpleToken
&
lastToken
=
_tokens
.
at
(
end
+
_offset
-
1
);
return
_text
.
mid
(
firstToken
.
begin
(),
lastToken
.
end
()
-
firstToken
.
begin
());
const
SimpleToken
&
firstToken
=
_tokens
.
at
(
index
+
_offset
);
return
_text
.
mid
(
firstToken
.
begin
(),
firstToken
.
length
());
}
QStringRef
BackwardsScanner
::
textRef
(
int
begin
,
int
end
)
const
QStringRef
BackwardsScanner
::
textRef
(
int
index
)
const
{
const
SimpleToken
&
firstToken
=
_tokens
.
at
(
begin
+
_offset
);
const
SimpleToken
&
lastToken
=
_tokens
.
at
(
end
+
_offset
-
1
);
return
_text
.
midRef
(
firstToken
.
begin
(),
lastToken
.
end
()
-
firstToken
.
begin
());
const
SimpleToken
&
firstToken
=
_tokens
.
at
(
index
+
_offset
);
return
_text
.
midRef
(
firstToken
.
begin
(),
firstToken
.
length
());
}
int
BackwardsScanner
::
previousBlockState
(
const
QTextBlock
&
block
)
const
...
...
src/libs/cplusplus/BackwardsScanner.h
View file @
a49395a0
...
...
@@ -51,8 +51,8 @@ public:
int
startPosition
()
const
;
QString
text
()
const
;
QString
text
(
int
begin
,
int
end
)
const
;
QStringRef
textRef
(
int
begin
,
int
end
)
const
;
QString
text
(
int
index
)
const
;
QStringRef
textRef
(
int
index
)
const
;
// 1-based
SimpleToken
LA
(
int
index
)
const
;
...
...
src/libs/cplusplus/ExpressionUnderCursor.cpp
View file @
a49395a0
...
...
@@ -150,7 +150,7 @@ QString ExpressionUnderCursor::operator()(const QTextCursor &cursor)
if
(
i
==
initialSize
)
return
QString
();
return
scanner
.
text
(
i
,
initialSize
);
return
scanner
.
text
(
i
);
}
int
ExpressionUnderCursor
::
startOfFunctionCall
(
const
QTextCursor
&
cursor
)
const
...
...
src/libs/cplusplus/MatchingText.cpp
View file @
a49395a0
...
...
@@ -49,9 +49,9 @@ static bool shouldOverrideChar(const QChar &ch)
}
}
static
bool
isCompleteStringLiteral
(
const
BackwardsScanner
&
tk
,
int
index
,
int
startToken
)
static
bool
isCompleteStringLiteral
(
const
BackwardsScanner
&
tk
,
int
index
)
{
const
QStringRef
text
=
tk
.
textRef
(
index
,
startToken
);
const
QStringRef
text
=
tk
.
textRef
(
index
);
if
(
text
.
length
()
<
2
)
return
false
;
...
...
@@ -62,9 +62,9 @@ static bool isCompleteStringLiteral(const BackwardsScanner &tk, int index, int s
return
false
;
}
static
bool
isCompleteCharLiteral
(
const
BackwardsScanner
&
tk
,
int
index
,
int
startToken
)
static
bool
isCompleteCharLiteral
(
const
BackwardsScanner
&
tk
,
int
index
)
{
const
QStringRef
text
=
tk
.
textRef
(
index
,
startToken
);
const
QStringRef
text
=
tk
.
textRef
(
index
);
if
(
text
.
length
()
<
2
)
return
false
;
...
...
@@ -133,7 +133,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
if
(
text
.
length
()
!=
1
)
qWarning
()
<<
Q_FUNC_INFO
<<
"handle event compression"
;
if
(
isCompleteStringLiteral
(
tk
,
index
-
1
,
startToken
))
if
(
isCompleteStringLiteral
(
tk
,
index
-
1
))
return
QLatin1String
(
"
\"
"
);
return
QString
();
...
...
@@ -141,7 +141,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
if
(
text
.
length
()
!=
1
)
qWarning
()
<<
Q_FUNC_INFO
<<
"handle event compression"
;
if
(
isCompleteCharLiteral
(
tk
,
index
-
1
,
startToken
))
if
(
isCompleteCharLiteral
(
tk
,
index
-
1
))
return
QLatin1String
(
"'"
);
return
QString
();
...
...
src/libs/cplusplus/SimpleLexer.cpp
View file @
a49395a0
...
...
@@ -139,27 +139,14 @@ QList<SimpleToken> SimpleLexer::operator()(const QString &text, int state)
bool
inPreproc
=
false
;
bool
first
=
true
;
for
(;;)
{
Token
tk
;
lex
(
&
tk
);
if
(
tk
.
is
(
T_EOF_SYMBOL
))
break
;
Q_ASSERT
(
lex
.
tokenOffset
()
==
tk
.
begin
());
Q_ASSERT
(
lex
.
tokenLength
()
==
tk
.
f
.
length
);
QStringRef
spell
=
text
.
midRef
(
lex
.
tokenOffset
(),
lex
.
tokenLength
());
SimpleToken
simpleTk
(
tk
,
spell
);
if
(
first
)
{
first
=
false
;
Q_ASSERT
(
tk
.
f
.
newline
);
Q_ASSERT
(
simpleTk
.
followsNewline
());
}
lex
.
setScanAngleStringLiteralTokens
(
false
);
if
(
tk
.
f
.
newline
&&
tk
.
is
(
T_POUND
))
...
...
src/plugins/cppeditor/cppeditor.cpp
View file @
a49395a0
...
...
@@ -1472,9 +1472,6 @@ static void indentCPPBlock(const CPPEditor::TabSettings &ts,
void
CPPEditor
::
indentBlock
(
QTextDocument
*
doc
,
QTextBlock
block
,
QChar
typedChar
)
{
const
TextEditor
::
TextBlockIterator
begin
(
doc
->
begin
());
const
TextEditor
::
TextBlockIterator
end
(
block
.
next
());
QTextCursor
tc
(
block
);
tc
.
movePosition
(
QTextCursor
::
EndOfBlock
);
...
...
@@ -1509,6 +1506,26 @@ void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedCha
}
}
if
((
tokenCount
==
0
||
tk
[
0
].
isNot
(
T_POUND
))
&&
typedChar
.
isNull
()
&&
(
tk
[
-
1
].
is
(
T_IDENTIFIER
)
||
tk
[
-
1
].
is
(
T_RPAREN
)))
{
int
tokenIndex
=
-
1
;
if
(
tk
[
-
1
].
is
(
T_RPAREN
))
{
const
int
matchingBrace
=
tk
.
startOfMatchingBrace
(
0
);
if
(
matchingBrace
!=
0
&&
tk
[
matchingBrace
-
1
].
is
(
T_IDENTIFIER
))
{
tokenIndex
=
matchingBrace
-
1
;
}
}
const
QString
spell
=
tk
.
text
(
tokenIndex
);
if
(
tk
[
tokenIndex
].
followsNewline
()
&&
(
spell
.
startsWith
(
QLatin1String
(
"QT_"
))
||
spell
.
startsWith
(
QLatin1String
(
"Q_"
))))
{
const
int
indent
=
tk
.
indentation
(
tokenIndex
);
tabSettings
().
indentLine
(
block
,
indent
);
return
;
}
}
const
TextEditor
::
TextBlockIterator
begin
(
doc
->
begin
());
const
TextEditor
::
TextBlockIterator
end
(
block
.
next
());
indentCPPBlock
(
tabSettings
(),
block
,
begin
,
end
,
typedChar
);
}
...
...
Write
Preview
Markdown
is supported
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