Skip to content

Commit

Permalink
Merge pull request #4305 from PoeticPete/fix-objc-colon
Browse files Browse the repository at this point in the history
Fix objc msg colon mislabeled as conditional colon
  • Loading branch information
gmaurel committed Jun 4, 2024
2 parents 47fea59 + ce9c0de commit a40c530
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/tokenizer/mark_question_colon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* return the chunk colon if found or Chunk::NullChunkPtr
* if a ; (CT_SEMI_COLON) chunk is found
*/
Chunk *search_for_colon(Chunk *pc_question)
Chunk *search_for_colon(Chunk *pc_question, int depth)
{
Chunk *pc2 = pc_question->GetNextNcNnl();
bool colon_found = false;
Expand Down Expand Up @@ -67,7 +67,7 @@ Chunk *search_for_colon(Chunk *pc_question)
{
LOG_FMT(LCOMBINE, "%s(%d): orig line is %zu, orig col is %zu, level is %zu, Text() is '%s'\n",
__func__, __LINE__, pc2->GetOrigLine(), pc2->GetOrigCol(), pc2->GetLevel(), pc2->Text());
pc2 = search_for_colon(pc2);
pc2 = search_for_colon(pc2, depth + 1);
LOG_FMT(LCOMBINE, "%s(%d): orig line is %zu, orig col is %zu, level is %zu, Text() is '%s'\n",
__func__, __LINE__, pc2->GetOrigLine(), pc2->GetOrigCol(), pc2->GetLevel(), pc2->Text());
continue;
Expand Down Expand Up @@ -107,12 +107,13 @@ Chunk *search_for_colon(Chunk *pc_question)
LOG_FMT(LCOMBINE, "%s(%d): orig line is %zu, orig col is %zu, level is %zu, Text() is '%s'\n",
__func__, __LINE__, pc2->GetOrigLine(), pc2->GetOrigCol(), pc2->GetLevel(), pc2->Text());

if (colon_found)
if (colon_found && depth > 0)
{
// There can only be another CT_COND_COLON if there is more than 1 CT_QUESTION (ie. depth > 0)
pc2->SetType(CT_COND_COLON);
return(pc2);
}
else
else if (!colon_found)
{
// E2 found orig line is 23, orig col is 3
pc2->SetType(CT_COND_COLON);
Expand Down Expand Up @@ -157,7 +158,7 @@ void mark_question_colon()
{
pc_question = pc;
// look for E2, COLON, E3...
pc = search_for_colon(pc);
pc = search_for_colon(pc, 0);

LOG_FMT(LCOMBINE, "%s(%d): orig line is %zu, orig col is %zu, level is %zu, Text() is '%s'\n",
__func__, __LINE__, pc->GetOrigLine(), pc->GetOrigCol(), pc->GetLevel(), pc->Text());
Expand Down
5 changes: 5 additions & 0 deletions tests/config/oc/60012.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sp_cond_colon = force
align_oc_msg_colon_span = 1
indent_columns = 4
indent_with_tabs = 0
indent_ternary_operator = 2
5 changes: 5 additions & 0 deletions tests/expected/oc/60012-Issue_4304.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
static void func() {
[NSObject doStuff:true ? 1 : 0
param2:@"test"
param3:@"test2"];
}
5 changes: 5 additions & 0 deletions tests/input/oc/Issue_4304.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
static void func() {
[NSObject doStuff:true ? 1 : 0
param2:@"test"
param3:@"test2"];
}
1 change: 1 addition & 0 deletions tests/objective-c.test
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,4 @@
# we need any expert to solve
#11032 oc/U10-Cpp.cfg oc/newlines.mm
60011 oc/UNI-11095.cfg oc/UNI-11095.mm
60012 oc/60012.cfg oc/Issue_4304.mm

0 comments on commit a40c530

Please sign in to comment.