Skip to content

Commit

Permalink
Merge pull request #4316 from guy-maurel/solutionFor3259
Browse files Browse the repository at this point in the history
take care of CT_TPARENxx
  • Loading branch information
gmaurel committed Jun 4, 2024
2 parents 24513ff + 9a802f2 commit 87bd980
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 10 deletions.
20 changes: 19 additions & 1 deletion src/align/func_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @author Ben Gardner
* @license GPL v2+
*/

#include "align/func_params.h"

#include "align/stack.h"
Expand Down Expand Up @@ -86,6 +85,25 @@ Chunk *align_func_param(Chunk *start)
pc->SetLevel(before->GetLevel());
Chunk *tmp = pc->GetPrevNc();

if (tmp->Is(CT_PTR_TYPE))
{
tmp->SetLevel(before->GetLevel());
}
}
}
else if (after->Is(CT_TPAREN_CLOSE))
{
Chunk *before = after->GetPrevType(CT_TPAREN_OPEN, after->GetLevel());

if (before->IsNotNullChunk())
{
// these are 'protect parenthesis'
// change the types and the level
before->SetType(CT_TPAREN_OPEN);
after->SetType(CT_TPAREN_CLOSE);
pc->SetLevel(before->GetLevel());
Chunk *tmp = pc->GetPrevNc();

if (tmp->Is(CT_PTR_TYPE))
{
tmp->SetLevel(before->GetLevel());
Expand Down
2 changes: 2 additions & 0 deletions src/align/stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ void AlignStack::Add(Chunk *start, size_t seqnum)
}
LOG_FMT(LAS, "AlignStack::%s(%3d): end of add\n", __func__, __LINE__);
// produces much more log output. Use it only debugging purpose
// WITH_STACKID_DEBUG;
// AlignStack::Debug();
} // AlignStack::Add


Expand Down
20 changes: 13 additions & 7 deletions src/tokenizer/combine_fix_mark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2167,7 +2167,8 @@ bool mark_function_type(Chunk *pc)
Chunk *apc;
Chunk *aft;
bool anon = false;
E_Token pt, ptp;
E_Token pt;
E_Token ptp;

// Scan backwards across the name, which can only be a word and single star
Chunk *varcnk = pc->GetPrevNcNnlNi(); // Issue #2279
Expand Down Expand Up @@ -2236,9 +2237,9 @@ bool mark_function_type(Chunk *pc)
}
else if ( aft->Is(CT_SEMICOLON)
|| aft->Is(CT_ASSIGN)
|| aft->Is(CT_COMMA) // Issue #3259
|| aft->Is(CT_FPAREN_CLOSE)) // Issue #3259
{
LOG_FMT(LFTYPE, "%s(%d):\n", __func__, __LINE__);
pt = CT_FUNC_PROTO;
}
else
Expand Down Expand Up @@ -2300,7 +2301,6 @@ bool mark_function_type(Chunk *pc)
goto nogo_exit;
}
}
LOG_FMT(LFTYPE, "%s(%d):\n", __func__, __LINE__);

// Fixes #issue 1577
// Allow word count 2 in case of function pointer declaration.
Expand Down Expand Up @@ -2362,13 +2362,19 @@ bool mark_function_type(Chunk *pc)

while ((tmp = tmp->GetPrevNcNnlNi())->IsNotNullChunk()) // Issue #2279
{
LOG_FMT(LFTYPE, " ++ type is %s, Text() '%s', on orig line %zu, orig col %zu\n",
get_token_name(tmp->GetType()), tmp->Text(),
LOG_FMT(LFTYPE, "%s(%d): ++ type is %s, Text() '%s', on orig line %zu, orig col %zu\n",
__func__, __LINE__, get_token_name(tmp->GetType()), tmp->Text(),
tmp->GetOrigLine(), tmp->GetOrigCol());

if (*tmp->GetStr().c_str() == '(')
LOG_FMT(LFTYPE, "%s(%d): ++ unbekannt: '%d'\n",
__func__, __LINE__, *tmp->GetStr().c_str());
log_pcf_flags(LFTYPE, pc->GetFlags());

if (*tmp->GetStr().c_str() == '(') // 3259 ??
{
if (!pc->TestFlags(PCF_IN_TYPEDEF))
//if (!pc->TestFlags(PCF_IN_TYPEDEF))
if ( !tmp->TestFlags(PCF_IN_TYPEDEF) // Issue #3259
&& !tmp->TestFlags(PCF_IN_FCN_DEF)) // Issue #3259
{
tmp->SetFlagBits(PCF_VAR_1ST_DEF);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/c.test
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,6 @@
10121 c/sp_after_sparen-a.cfg c/sp_after_sparen.c
10122 c/sp_after_sparen-r.cfg c/sp_after_sparen.c
10123 c/sp_after_sparen-f.cfg c/sp_after_sparen.c

10124 common/tde.cfg c/Issue_3985.c
10125 common/tde.cfg c/Issue_3992.c
10126 c/Issue_3259.cfg c/Issue_3259.h
1 change: 1 addition & 0 deletions tests/config/c/Issue_3259.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sp_after_tparen_close = add
2 changes: 1 addition & 1 deletion tests/expected/c/00420-Issue_2278.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct LIST_zNODE { int a; int b;};
struct LIST_zzzDATA { int a; int b;};

int foo1( LIST_tzHEAD *pList,
tucBOOL ( *pFn )( struct LIST_zNODE *pNode,
tucBOOL ( *pFn )( struct LIST_zNODE *pNode,
struct LIST_zzzDATA *pListData,
void *arg1 ),
void *arg2 );
5 changes: 5 additions & 0 deletions tests/expected/c/10126-Issue_3259.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int (*found_proc) (struct i2c_adapter *, int, int);

static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind,
int (*found_proc1) (struct i2c_adapter *, int, int),
int (*found_proc2) (struct i2c_adapter *, int, int));
5 changes: 5 additions & 0 deletions tests/input/c/Issue_3259.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int (*found_proc)(struct i2c_adapter *, int, int);

static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind,
int (*found_proc1)(struct i2c_adapter *, int, int),
int (*found_proc2)(struct i2c_adapter *, int, int));

0 comments on commit 87bd980

Please sign in to comment.