Skip to content

Commit

Permalink
Merge pull request #4292 from guy-maurel/print_version
Browse files Browse the repository at this point in the history
Print version
  • Loading branch information
gmaurel committed May 6, 2024
2 parents feb18a4 + 71e9c30 commit 751b12c
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -4430,6 +4430,10 @@ debug_decode_the_flags;
extern Option<bool>
debug_use_the_exit_function_pop; // = true

// print (or not) the version in the file defined at the command option -o.
extern Option<bool>
debug_print_version;

// insert the number of the line at the beginning of each line
extern Option<bool>
set_numbering_for_html_output;
Expand Down
8 changes: 8 additions & 0 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "reindent_line.h"
#include "tokenizer/tokenize.h"
#include "unc_ctype.h"
#include "uncrustify_version.h"
#include "unicode.h"

#include <ctime>
Expand Down Expand Up @@ -705,6 +706,13 @@ void output_text(FILE *pfile)
pp_indent_with_tabs = options::indent_with_tabs();
}

if (options::debug_print_version())
{
add_text("// Version: ");
add_text(UNCRUSTIFY_VERSION);
add_char('\n');
}

// loop over the whole chunk list
for (pc = Chunk::GetHead(); pc->IsNotNullChunk(); pc = pc->GetNext())
{
Expand Down
32 changes: 29 additions & 3 deletions src/tokenizer/combine_fix_mark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2171,8 +2171,14 @@ bool mark_function_type(Chunk *pc)

// Scan backwards across the name, which can only be a word and single star
Chunk *varcnk = pc->GetPrevNcNnlNi(); // Issue #2279
LOG_FMT(LFTYPE, "%s(%d): varcnk: text '%s', type %s, @ orig line %zu:, orig col %zu\n",
__func__, __LINE__, varcnk->Text(), get_token_name(varcnk->GetType()),
varcnk->GetOrigLine(), varcnk->GetOrigCol());

varcnk = varcnk->GetPrevNbsb();
LOG_FMT(LFTYPE, "%s(%d): varcnk: text '%s', type %s, @ orig line %zu:, orig col %zu\n",
__func__, __LINE__, varcnk->Text(), get_token_name(varcnk->GetType()),
varcnk->GetOrigLine(), varcnk->GetOrigCol());

if ( varcnk->IsNotNullChunk()
&& !varcnk->IsWord())
Expand All @@ -2192,13 +2198,22 @@ bool mark_function_type(Chunk *pc)
goto nogo_exit;
}
}
LOG_FMT(LFTYPE, "%s(%d): pc: text is '%s', type is %s, @ orig line is %zu:, orig col is %zu\n",
__func__, __LINE__, pc->Text(), get_token_name(pc->GetType()),
pc->GetOrigLine(), pc->GetOrigCol());
apo = pc->GetNextNcNnl();
LOG_FMT(LFTYPE, "%s(%d): apo: text is '%s', type is %s, @ orig line is %zu:, orig col is %zu\n",
__func__, __LINE__, apo->Text(), get_token_name(apo->GetType()),
apo->GetOrigLine(), apo->GetOrigCol());

if (apo->IsNullChunk())
{
return(false);
}
apc = apo->GetClosingParen();
LOG_FMT(LFTYPE, "%s(%d): apc: text is '%s', type is %s, @ orig line is %zu:, orig col is %zu\n",
__func__, __LINE__, apc->Text(), get_token_name(apc->GetType()),
apc->GetOrigLine(), apc->GetOrigCol());

if ( apc->IsNotNullChunk()
&& ( !apo->IsParenOpen()
Expand All @@ -2207,15 +2222,23 @@ bool mark_function_type(Chunk *pc)
LOG_FMT(LFTYPE, "%s(%d): not followed by parens\n", __func__, __LINE__);
goto nogo_exit;
}
LOG_FMT(LFTYPE, "%s(%d): apc: text is '%s', type is %s, @ orig line is %zu:, orig col is %zu\n",
__func__, __LINE__, apc->Text(), get_token_name(apc->GetType()),
apc->GetOrigLine(), apc->GetOrigCol());
aft = apc->GetNextNcNnl();
LOG_FMT(LFTYPE, "%s(%d): aft: text is '%s', type is %s, @ orig line is %zu:, orig col is %zu\n",
__func__, __LINE__, aft->Text(), get_token_name(aft->GetType()),
aft->GetOrigLine(), aft->GetOrigCol());

if (aft->Is(CT_BRACE_OPEN))
{
pt = CT_FUNC_DEF;
}
else if ( aft->Is(CT_SEMICOLON)
|| aft->Is(CT_ASSIGN))
|| aft->Is(CT_ASSIGN)
|| aft->Is(CT_FPAREN_CLOSE)) // Issue #3259
{
LOG_FMT(LFTYPE, "%s(%d):\n", __func__, __LINE__);
pt = CT_FUNC_PROTO;
}
else
Expand All @@ -2230,7 +2253,8 @@ bool mark_function_type(Chunk *pc)
while ((tmp = tmp->GetPrevNcNnlNi())->IsNotNullChunk()) // Issue #2279
{
tmp = tmp->GetPrevNbsb();
LOG_FMT(LFTYPE, " -- type is %s, %s on orig line %zu, orig col is %zu",
LOG_FMT(LFTYPE, "%s(%d): -- type is %s, %s on orig line %zu, orig col is %zu", // Issue #3259
__func__, __LINE__,
get_token_name(tmp->GetType()), tmp->Text(),
tmp->GetOrigLine(), tmp->GetOrigCol());

Expand Down Expand Up @@ -2269,12 +2293,14 @@ bool mark_function_type(Chunk *pc)
}
else
{
LOG_FMT(LFTYPE, " -- unexpected token: type is %s, Text() '%s', on orig line %zu, orig col %zu\n",
LOG_FMT(LFTYPE, "%s(%d): -- unexpected token: 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());
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
9 changes: 9 additions & 0 deletions tests/cli/output/universalindent.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8437,6 +8437,15 @@ TrueFalse=debug_use_the_exit_function_pop=true|debug_use_the_exit_function_pop=f
TrueFalseRegex=debug_use_the_exit_function_pop\s*=\s*true|debug_use_the_exit_function_pop\s*=\s*false
ValueDefault=true

[Debug Print Version]
Category=13
Description="<html>print (or not) the version in the file defined at the command option -o.</html>"
Enabled=false
EditorType=boolean
TrueFalse=debug_print_version=true|debug_print_version=false
TrueFalseRegex=debug_print_version\s*=\s*true|debug_print_version\s*=\s*false
ValueDefault=false

[Set Numbering For Html Output]
Category=13
Description="<html>insert the number of the line at the beginning of each line</html>"
Expand Down
1 change: 1 addition & 0 deletions tests/config/cpp/Issue_3259.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sp_after_tparen_close = add
1 change: 1 addition & 0 deletions tests/cpp.test
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
30162 cpp/Issue_4239.cfg cpp/Issue_4239.cpp
30163 cpp/Issue_4220.cfg cpp/Issue_4220.cpp
30164 cpp/Issue_3120.cfg cpp/Issue_3120.cpp
30165 cpp/Issue_3259.cfg cpp/Issue_3259.h

30200 cpp/bug_1862.cfg cpp/bug_1862.cpp
30201 cpp/cmt_indent-1.cfg cpp/cmt_indent.cpp
Expand Down
4 changes: 4 additions & 0 deletions tests/expected/cpp/30165-Issue_3259.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int (*found_proc) (struct i2c_adapter *, int, int);

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

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

0 comments on commit 751b12c

Please sign in to comment.