Skip to content

Commit

Permalink
Fix several function metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinellis committed Jul 22, 2024
1 parent 8f1e7b2 commit 248f2b6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ class Call {
}

// Set number of arguments
static inline void set_num_args(int n) {
static inline void set_pre_cpp_num_args(int n) {
if (current_fun && !current_fun->pre_cpp_metrics.is_processed())
current_fun->pre_cpp_metrics.set_metric(FunMetrics::em_nparam, n);
current_fun->pre_cpp_metrics.set_metric(FunMetrics::em_nmparam, n);
}

// Process a token destined for preprocessing
Expand Down Expand Up @@ -250,14 +250,14 @@ class Call {

// Increase the current function's level of nesting
static inline void increase_nesting() {
if (current_fun && !current_fun->pre_cpp_metrics.is_processed() &&
if (current_fun && !current_fun->post_cpp_metrics.is_processed() &&
!macro_nesting)
current_fun->pre_cpp_metrics.update_nesting(++(current_fun->curr_stmt_nesting));
current_fun->post_cpp_metrics.update_nesting(++(current_fun->curr_stmt_nesting));
}

// Decrease the current function's level of nesting
static inline void decrease_nesting() {
if (!current_fun || current_fun->pre_cpp_metrics.is_processed())
if (!current_fun || current_fun->post_cpp_metrics.is_processed())
return;
if (macro_nesting)
macro_nesting--;
Expand Down
10 changes: 7 additions & 3 deletions src/cscout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,12 +1554,16 @@ function_page(FILE *fo, void *p)
RefFunCall::store_type::const_iterator rfc;
if ((rfc = RefFunCall::store.find(ec)) != RefFunCall::store.end())
repl_temp << html(rfc->second.get_replacement());
else if (f->is_defined())
for (int i = 0; i < f->get_pre_cpp_metrics().get_metric(FunMetrics::em_nparam); i++) {
else if (f->is_defined()) {
int nparam = f->is_cfun()
? f->get_post_cpp_metrics().get_metric(FunMetrics::em_nfparam)
: f->get_pre_cpp_metrics().get_metric(FunMetrics::em_nmparam);
for (int i = 0; i < nparam; i++) {
repl_temp << '@' << i + 1;
if (i + 1 < f->get_pre_cpp_metrics().get_metric(FunMetrics::em_nparam))
if (i + 1 < nparam)
repl_temp << ", ";
}
}
fprintf(fo, "<li> Refactor arguments into: \n"
"<INPUT TYPE=\"text\" NAME=\"ncall\" VALUE=\"%s\" SIZE=40 MAXLENGTH=256> "
"<INPUT TYPE=\"submit\" NAME=\"repl\" VALUE=\"Save\">\n",
Expand Down
2 changes: 1 addition & 1 deletion src/fcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ FCall::set_current_fun(const Type &t)
cout << "Current function " << id->get_name() << "\n";
cout << "Type: " << t << "\n";
}
cfun->get_pre_cpp_metrics().set_metric(FunMetrics::em_ngnsoc,
cfun->get_post_cpp_metrics().set_metric(FunMetrics::em_ngnsoc,
Block::global_namespace_occupants_size() +
Pdtoken::macros_size());
nesting.push(cfun);
Expand Down
7 changes: 4 additions & 3 deletions src/funmetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ MetricDetails FunMetrics::metric_details[] = {
// BEGIN AUTOSCHEMA FunMetrics
// During processing (once based on processed)
// pre-cpp, post-cpp, file
{ em_ngnsoc, 1, 1, 0, "NGNSOC", "Number of global namespace occupants at function's top"},
{ em_nparam, 1, 1, 0, "NPARAM", "Number of parameters"},
{ em_maxnest, 1, 1, 0, "MAXNEST", "Maximum level of statement nesting"},
{ em_ngnsoc, 0, 1, 0, "NGNSOC", "Number of global namespace occupants at function's top"},
{ em_nmparam, 1, 0, 0, "NMPARAM", "Number of parameters (for macros)"},
{ em_nfparam, 0, 1, 0, "NFPARAM", "Number of parameters (for functions)"},
{ em_maxnest, 0, 1, 0, "MAXNEST", "Maximum level of statement nesting"},
// Metrics dynamically derived
{ em_nlabel, 1, 1, 0, "NLABEL", "Number of goto labels"},
{ em_fanin, 1, 1, 0, "FANIN", "Fan-in (number of calling functions)"},
Expand Down
3 changes: 2 additions & 1 deletion src/funmetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class FunMetrics : public Metrics {
// During processing (once based on processed)
em_ngnsoc = // Number of global namespace occupants at function's top
Metrics::metric_max,
em_nparam, // Number of parameters
em_nmparam, // Number of macro parameters
em_nfparam, // Number of function parameters
em_maxnest, // Maximum level of statement nesting
// Stored metrics stop here
stored_metric_max,
Expand Down
2 changes: 1 addition & 1 deletion src/pdtoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ Pdtoken::process_define(bool is_immutable)
MCall::set_current_fun(m);
t.getnext<Fchar>();
}
MCall::set_num_args(m.get_num_args());
MCall::set_pre_cpp_num_args(m.get_num_args());
} else
Metrics::call_pre_cpp_metrics(&Metrics::add_ppomacro);
if (DP()) cout << "Body starts with " << t;
Expand Down
2 changes: 1 addition & 1 deletion src/stab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ obj_define(const Token& tok, Type typ)
fc = new FCall(utok, typ, tok.get_name());
}
}
fc->get_pre_cpp_metrics().set_metric(FunMetrics::em_nparam, typ.get_nparam());
fc->get_post_cpp_metrics().set_metric(FunMetrics::em_nfparam, typ.get_nparam());
}

static Stab Block::*objptr = &Block::obj;
Expand Down

0 comments on commit 248f2b6

Please sign in to comment.