Optimized startOfOperator a bit

This commit is contained in:
Thorbjørn Lindeijer
2009-08-28 13:43:06 +02:00
parent 9a5908bf8c
commit aba678604c

View File

@@ -549,7 +549,7 @@ void CppCodeCompletion::setPartialCompletionEnabled(bool partialCompletionEnable
} }
/* /*
Searches beckward for an access operator. Searches backwards for an access operator.
*/ */
static int startOfOperator(TextEditor::ITextEditable *editor, static int startOfOperator(TextEditor::ITextEditable *editor,
int pos, unsigned *kind, int pos, unsigned *kind,
@@ -562,39 +562,63 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
int start = pos; int start = pos;
int k = T_EOF_SYMBOL; int k = T_EOF_SYMBOL;
if (ch2 != QLatin1Char('.') && ch == QLatin1Char('.')) { switch (ch.toLatin1()) {
k = T_DOT; case '.':
--start; if (ch2 != QLatin1Char('.')) {
} else if (ch == QLatin1Char(',')) { k = T_DOT;
--start;
}
break;
case ',':
k = T_COMMA; k = T_COMMA;
--start; --start;
} else if (wantFunctionCall && ch == QLatin1Char('(')) { break;
k = T_LPAREN; case '(':
--start; if (wantFunctionCall) {
} else if (ch3 != QLatin1Char(':') && ch2 == QLatin1Char(':') && ch == QLatin1Char(':')) { k = T_LPAREN;
k = T_COLON_COLON; --start;
start -= 2; }
} else if (ch2 == QLatin1Char('-') && ch == QLatin1Char('>')) { break;
k = T_ARROW; case ':':
start -= 2; if (ch3 != QLatin1Char(':') && ch2 == QLatin1Char(':')) {
} else if (ch2 == QLatin1Char('.') && ch == QLatin1Char('*')) { k = T_COLON_COLON;
k = T_DOT_STAR; start -= 2;
start -= 2; }
} else if (ch3 == QLatin1Char('-') && ch2 == QLatin1Char('>') && ch == QLatin1Char('*')) { break;
k = T_ARROW_STAR; case '>':
start -= 3; if (ch2 == QLatin1Char('-')) {
} else if ((ch2.isNull() || ch2.isSpace()) && (ch == QLatin1Char('@') || ch == QLatin1Char('\\'))) { k = T_ARROW;
k = T_DOXY_COMMENT; start -= 2;
--start; }
} else if (ch == QLatin1Char('<')) { break;
case '*':
if (ch2 == QLatin1Char('.')) {
k = T_DOT_STAR;
start -= 2;
} else if (ch3 == QLatin1Char('-') && ch2 == QLatin1Char('>')) {
k = T_ARROW_STAR;
start -= 3;
}
break;
case '\\':
case '@':
if (ch2.isNull() || ch2.isSpace()) {
k = T_DOXY_COMMENT;
--start;
}
break;
case '<':
k = T_ANGLE_STRING_LITERAL; k = T_ANGLE_STRING_LITERAL;
--start; --start;
} else if (ch == QLatin1Char('"')) { break;
case '"':
k = T_STRING_LITERAL; k = T_STRING_LITERAL;
--start; --start;
} else if (ch == QLatin1Char('/')) { break;
case '/':
k = T_SLASH; k = T_SLASH;
--start; --start;
break;
} }
if (start == pos) if (start == pos)
@@ -635,8 +659,7 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
k = T_EOF_SYMBOL; k = T_EOF_SYMBOL;
start = pos; start = pos;
} }
else if (k == T_LPAREN) {
if (k == T_LPAREN) {
const QList<SimpleToken> &tokens = tokenUnderCursor.tokens(); const QList<SimpleToken> &tokens = tokenUnderCursor.tokens();
int i = 0; int i = 0;
for (; i < tokens.size(); ++i) { for (; i < tokens.size(); ++i) {
@@ -656,9 +679,8 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
start = pos; start = pos;
} }
} }
// Check for include preprocessor directive // Check for include preprocessor directive
if (k == T_STRING_LITERAL || k == T_ANGLE_STRING_LITERAL || k == T_SLASH) { else if (k == T_STRING_LITERAL || k == T_ANGLE_STRING_LITERAL || k == T_SLASH) {
const QList<SimpleToken> &tokens = tokenUnderCursor.tokens(); const QList<SimpleToken> &tokens = tokenUnderCursor.tokens();
int i = 0; int i = 0;
bool include = false; bool include = false;