summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/ExpressionUnderCursor.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@nokia.com>2009-11-11 09:35:42 +0100
committerErik Verbruggen <erik.verbruggen@nokia.com>2009-11-11 09:35:42 +0100
commit2d2d0b59c81628516c84f1573250c5fb79f1803c (patch)
treef8121294d6612ca1fddf27079b928e8f01947f1c /src/libs/cplusplus/ExpressionUnderCursor.cpp
parenta6bbec2b56f4a07f408bf3213b3b15fa6fc10330 (diff)
downloadqt-creator-2d2d0b59c81628516c84f1573250c5fb79f1803c.tar.gz
Changed ExpressionUnderCursor to handle Objective-C send-message operations.
Diffstat (limited to 'src/libs/cplusplus/ExpressionUnderCursor.cpp')
-rw-r--r--src/libs/cplusplus/ExpressionUnderCursor.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/libs/cplusplus/ExpressionUnderCursor.cpp b/src/libs/cplusplus/ExpressionUnderCursor.cpp
index 67980ce4e1..3bfec589c8 100644
--- a/src/libs/cplusplus/ExpressionUnderCursor.cpp
+++ b/src/libs/cplusplus/ExpressionUnderCursor.cpp
@@ -106,8 +106,45 @@ int ExpressionUnderCursor::startOfExpression_helper(BackwardsScanner &tk, int in
return startOfExpression(tk, index - 2);
} else if (tk[index - 2].is(T_DOT_STAR) || tk[index - 2].is(T_ARROW_STAR)) {
return startOfExpression(tk, index - 2);
-// } else if (tk[index - 2].is(T_IDENTIFIER) && tk[index - 3].is(T_LBRACKET)) {
-// return index - 3;
+ } else if (tk[index - 2].is(T_LBRACKET)) {
+ // array subscription:
+ // array[i
+ return index - 1;
+ } else if (tk[index - 2].is(T_COLON)) {
+ // either of:
+ // cond ? expr1 : id
+ // or:
+ // [receiver messageParam:id
+ // and in both cases, the id (and only the id) is what we want, so:
+ return index - 1;
+ } else if (tk[index - 2].is(T_IDENTIFIER) && tk[index - 3].is(T_LBRACKET)) {
+ // Very common Objective-C case:
+ // [receiver message
+ // which we handle immediately:
+ return index - 3;
+ } else {
+ // See if we are handling an Objective-C messaging expression in the form of:
+ // [receiver messageParam1:expression messageParam2
+ // or:
+ // [receiver messageParam1:expression messageParam2:expression messageParam3
+ // ... etc
+ int i = index - 1;
+ while (tk[i].isNot(T_EOF_SYMBOL)) {
+ if (tk[i].is(T_LBRACKET))
+ break;
+ if (tk[i].is(T_LBRACE) || tk[i].is(T_RBRACE))
+ break;
+ else if (tk[i].is(T_RBRACKET))
+ i = tk.startOfMatchingBrace(i + 1) - 1;
+ else
+ --i;
+ }
+
+ int j = i;
+ while (tk[j].is(T_LBRACKET))
+ ++j;
+ if (tk[j].is(T_IDENTIFIER) && tk[j + 1].is(T_IDENTIFIER))
+ return i;
}
return index - 1;
} else if (tk[index - 1].is(T_RPAREN)) {