Skip to content

Commit

Permalink
Fix remaining semantic errors
Browse files Browse the repository at this point in the history
(WIP)
  • Loading branch information
dspinellis committed Jul 18, 2024
1 parent 833983c commit 6a3458e
Show file tree
Hide file tree
Showing 21 changed files with 319 additions and 190 deletions.
47 changes: 24 additions & 23 deletions src/cscout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ file_analyze(Fileid fi)
cfun->get_pre_cpp_metrics().process_char((char)val);
if (c == '\n') {
Filedetails::add_line_end(fi, ti.get_streampos());
if (!Filedetails::is_processed(fi, ++line_number))
if (!Filedetails::is_line_processed(fi, ++line_number))
Filedetails::get_pre_cpp_metrics(fi).add_unprocessed();
}
}
Expand Down Expand Up @@ -452,7 +452,7 @@ file_hypertext(FILE *of, Fileid fi, bool eval_query)
break;
if (at_bol) {
fprintf(of,"<a name=\"%d\"></a>", line_number);
if (mark_unprocessed && !Filedetails::is_processed(fi, line_number))
if (mark_unprocessed && !Filedetails::is_line_processed(fi, line_number))
fprintf(of, "<span class=\"unused\">");
if (Option::show_line_number->get()) {
char buff[50];
Expand Down Expand Up @@ -502,7 +502,7 @@ file_hypertext(FILE *of, Fileid fi, bool eval_query)
fprintf(of, "%s", html((char)val));
if ((char)val == '\n') {
at_bol = true;
if (mark_unprocessed && !Filedetails::is_processed(fi, line_number))
if (mark_unprocessed && !Filedetails::is_line_processed(fi, line_number))
fprintf(of, "</span>");
line_number++;
}
Expand Down Expand Up @@ -1621,13 +1621,13 @@ visit_functions(FILE *fo, const char *call_path, Call *f,
/*
* Visit all files associated with a includes/included relationship with f
* The method to obtain the relationship container is passed through
* the get_map method pointer.
* the get_map function pointer.
* The method to check if a file should be included in the visit is passed through the
* the is_ok method pointer.
* Set the visited flag for all nodes visited.
*/
static void
visit_include_files(Fileid f, const FileIncMap & (Fileid::*get_map)() const,
visit_include_files(Fileid f, const FileIncMap & (*get_map)(Fileid fi),
bool (IncDetails::*is_ok)() const, int level)
{
if (level == 0)
Expand All @@ -1636,7 +1636,7 @@ visit_include_files(Fileid f, const FileIncMap & (Fileid::*get_map)() const,
if (DP())
cout << "Visiting " << f.get_fname() << endl;
Filedetails::set_visited(f);
const FileIncMap &m = (f.*get_map)();
const FileIncMap &m = get_map(f);
for (FileIncMap::const_iterator i = m.begin(); i != m.end(); i++) {
if (!Filedetails::is_visited(i->first) && (i->second.*is_ok)())
visit_include_files(i->first, get_map, is_ok, level - 1);
Expand All @@ -1646,22 +1646,23 @@ visit_include_files(Fileid f, const FileIncMap & (Fileid::*get_map)() const,
/*
* Visit all files associated with a global variable def/ref relationship with f
* The method to obtain the relationship container is passed through
* the get_set method pointer.
* the get_fileid_set method pointer.
* Set the visited flag for all nodes visited.
*/
static void
visit_globobj_files(Fileid f, const Fileidset & (*get_set)() const, int level)
visit_globobj_files(Fileid f, const Fileidset & (*get_fileid_set)(Fileid fi),
int level)
{
if (level == 0)
return;

if (DP())
cout << "Visiting " << f.get_fname() << endl;
Filedetails::set_visited(f);
const Fileidset &s = get_set(f);
const Fileidset &s = get_fileid_set(f);
for (Fileidset::const_iterator i = s.begin(); i != s.end(); i++) {
if (!Filedetails::is_visited(*i))
visit_globobj_files(*i, get_set, level - 1);
visit_globobj_files(*i, get_fileid_set, level - 1);
}
}

Expand Down Expand Up @@ -2044,30 +2045,30 @@ single_file_graph(char gtype, EdgeMatrix &edges)
case 'I': // Include graph
switch (*ltype) {
case 'D':
visit_include_files(fileid, &Fileid::get_includers, &IncDetails::is_directly_included, Option::cgraph_depth->get());
visit_include_files(fileid, &Filedetails::get_includers, &IncDetails::is_directly_included, Option::cgraph_depth->get());
break;
case 'U':
visit_include_files(fileid, &Fileid::get_includes, &IncDetails::is_directly_included, Option::cgraph_depth->get());
visit_include_files(fileid, &Filedetails::get_includes, &IncDetails::is_directly_included, Option::cgraph_depth->get());
break;
}
break;
case 'C': // Compile-time dependency graph
switch (*ltype) {
case 'D':
visit_include_files(fileid, &Fileid::get_includers, &IncDetails::is_required, Option::cgraph_depth->get());
visit_include_files(fileid, &Filedetails::get_includers, &IncDetails::is_required, Option::cgraph_depth->get());
break;
case 'U':
visit_include_files(fileid, &Fileid::get_includes, &IncDetails::is_required, Option::cgraph_depth->get());
visit_include_files(fileid, &Filedetails::get_includes, &IncDetails::is_required, Option::cgraph_depth->get());
break;
}
break;
case 'G': // Global object def/ref graph (data dependency)
switch (*ltype) {
case 'D':
visit_globobj_files(fileid, &Filedetails::glob_uses, Option::cgraph_depth->get());
visit_globobj_files(fileid, &Filedetails::get_glob_uses, Option::cgraph_depth->get());
break;
case 'U':
visit_globobj_files(fileid, &Filedetails::glob_used_by, Option::cgraph_depth->get());
visit_globobj_files(fileid, &Filedetails::get_glob_used_by, Option::cgraph_depth->get());
break;
}
break;
Expand Down Expand Up @@ -2248,7 +2249,7 @@ fgraph_page(GraphDisplay *gd)
switch (*gtype) {
case 'C': // Compile-time dependency graph
case 'I': { // Include graph
const FileIncMap &m(i->get_includes());
const FileIncMap &m(Filedetails::get_includes(*i));
for (FileIncMap::const_iterator j = m.begin(); j != m.end(); j++) {
if (*gtype == 'I' && !j->second.is_directly_included())
continue;
Expand Down Expand Up @@ -2288,7 +2289,7 @@ fgraph_page(GraphDisplay *gd)
}
break;
case 'G': // Global object def/ref graph (data dependency)
for (Fileidset::const_iterator j = Filedetails::glob_uses(*i).begin(); j != Filedetails::glob_uses(*i).end(); j++) {
for (Fileidset::const_iterator j = Filedetails::get_glob_uses(*i).begin(); j != Filedetails::get_glob_uses(*i).end(); j++) {
if (!all && j->get_readonly())
continue;
if (only_visited && !Filedetails::is_visited(*j))
Expand Down Expand Up @@ -3163,10 +3164,10 @@ warning_report()
if (i->get_readonly() || // Don't report on RO files
!Filedetails::is_compilation_unit(*i) || // Algorithm only works for CUs
*i == input_file_id || // Don't report on main file
i->get_includers().size() > 1) // For files that are both CUs and included
Filedetails::get_includers(*i).size() > 1) // For files that are both CUs and included
// by others all bets are off
continue;
const FileIncMap &m = i->get_includes();
const FileIncMap &m = Filedetails::get_includes(*i);
// Find the status of our include sites
include_sites.clear();
for (FileIncMap::const_iterator j = m.begin(); j != m.end(); j++) {
Expand All @@ -3192,7 +3193,7 @@ warning_report()
for (set <Fileid>::const_iterator fi = sf.begin(); fi != sf.end(); fi++)
cerr << i->get_path() << ':' <<
line << ": " <<
"(" << Filetails::get_pre_cpp_const_metrics(*i).get_int_metric(Metrics::em_nuline) << " unprocessed lines)"
"(" << Filedetails::get_pre_cpp_const_metrics(*i).get_int_metric(Metrics::em_nuline) << " unprocessed lines)"
" unused included file " <<
fi->get_path() <<
endl;
Expand Down Expand Up @@ -3427,7 +3428,7 @@ main(int argc, char *argv[])

input_file_id = Fileid(argv[optind]);

Fileid::unify_identical_files();
Filedetails::unify_identical_files();

if (process_mode == pm_obfuscation)
return obfuscate();
Expand Down Expand Up @@ -3664,7 +3665,7 @@ garbage_collect(Fileid root)
// Store them in a set to calculate set difference
for (set <Fileid>::const_iterator i = touched_files.begin(); i != touched_files.end(); i++)
if (*i != root && *i != input_file_id)
Filedetails::set_includes(root, *i, /* directly included (conservatively) */ false, i->required());
Filedetails::set_includes(root, *i, /* directly included (conservatively) */ false, Filedetails::is_required(*i));
if (process_mode == pm_database)
Fdep::dumpSql(Sql::getInterface(), root);
Fdep::reset();
Expand Down
7 changes: 4 additions & 3 deletions src/ctag.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2011 Diomidis Spinellis
* (C) Copyright 2011-2024 Diomidis Spinellis
*
* This file is part of CScout.
*
Expand Down Expand Up @@ -41,6 +41,7 @@
#include "attr.h"
#include "metrics.h"
#include "fileid.h"
#include "filedetails.h"
#include "tokid.h"
#include "eclass.h"
#include "token.h"
Expand Down Expand Up @@ -99,7 +100,7 @@ CTag::save()
out <<
i->name << '\t' << // Identifier
i->definition.get_path() << '\t' << // File
i->definition.get_fileid().line_number(i->definition.get_streampos()) << '\t' <<// Line number
Filedetails::get_line_number(i->definition.get_fileid(), i->definition.get_streampos()) << '\t' <<// Line number
"\t;\""; // Extended information

/*
Expand Down Expand Up @@ -131,7 +132,7 @@ CTag::save()
out << "\tfile:";
break;
default:
if (i->definition.get_fileid().get_includers().size() == 0)
if (Filedetails::get_includers(i->definition.get_fileid()).size() == 0)
out << "\tfile:";
break;
}
Expand Down
7 changes: 4 additions & 3 deletions src/eclass.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2001-2015 Diomidis Spinellis
* (C) Copyright 2001-2024 Diomidis Spinellis
*
* This file is part of CScout.
*
Expand Down Expand Up @@ -47,6 +47,7 @@
#include "pltoken.h"
#include "macro.h"
#include "pdtoken.h"
#include "filedetails.h"
#include "eclass.h"

// Remove references to the equivalence class from the tokid map
Expand Down Expand Up @@ -155,7 +156,7 @@ Eclass::functions()
setTokid::const_iterator i;

for (i = members.begin(); i != members.end(); i++) {
FCallSet fc(i->get_fileid().get_functions());
FCallSet fc(Filedetails::get_functions(i->get_fileid()));
for (FCallSet::const_iterator j = fc.begin(); j != fc.end(); j++)
if ((*j)->is_span_valid() &&
*i >= (*j)->get_begin().get_tokid() &&
Expand All @@ -175,7 +176,7 @@ Eclass::is_unused()
return (true);
// More complex case: see if all the members come from unified identical files
Tokid amember(*members.begin());
if (amember.get_fileid().get_identical_files().size() == members.size())
if (Filedetails::get_identical_files(amember.get_fileid()).size() == members.size())
return (true);
return (false);
}
Expand Down
6 changes: 3 additions & 3 deletions src/eclass.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2001-2015 Diomidis Spinellis
* (C) Copyright 2001-2024 Diomidis Spinellis
*
* This file is part of CScout.
*
Expand Down Expand Up @@ -67,8 +67,8 @@ class Eclass {
// Functions where the this appears
set <Call *> functions();
// Other accessor functions
void set_attribute(int v) { Filedetails::set_attribute(attr, v); }
bool get_attribute(int v) { return Filedetails::get_attribute(attr, v); }
void set_attribute(int v) { attr.set_attribute(v); }
bool get_attribute(int v) { return attr.get_attribute(v); }
bool is_identifier() { return attr.is_identifier(); }
// Return true if this equivalence class is unintentionally unused
bool is_unused();
Expand Down
4 changes: 2 additions & 2 deletions src/fcall.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2003-2015 Diomidis Spinellis
* (C) Copyright 2003-2024 Diomidis Spinellis
*
* This file is part of CScout.
*
Expand Down Expand Up @@ -114,6 +114,6 @@ FCall::set_current_fun(const Type &t)
Pdtoken::macros_size());
nesting.push(cfun);
if (nesting.size() == 1)
Filedetails::add_function(Fchar::get_fileid().get_pre_cpp_metrics(), t.is_static());
Filedetails::get_pre_cpp_metrics(Fchar::get_fileid()).add_function(t.is_static());
}

6 changes: 3 additions & 3 deletions src/fchar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ Fchar::simple_getnext()
case '\\': // \newline splicing
c2 = in.get();
if (c2 == '\n') {
Filedetails::process_line(Fchar::get_fileid(), !Pdtoken::skipping());
Filedetails::set_line_processed(Fchar::get_fileid(), !Pdtoken::skipping());
line_number++;
goto again;
} else if (c2 == '\r') {
// DOS/WIN32 cr-lf EOL
c3 = in.get();
if (c3 == '\n') {
Filedetails::process_line(Fchar::get_fileid(), !Pdtoken::skipping());
Filedetails::set_line_processed(Fchar::get_fileid(), !Pdtoken::skipping());
line_number++;
goto again;
}
Expand Down Expand Up @@ -158,7 +158,7 @@ Fchar::simple_getnext()
default: in.putback(c3); in.putback(c2); return;
}
case '\n':
Filedetails::process_line(Fchar::get_fileid(), !Pdtoken::skipping());
Filedetails::set_line_processed(Fchar::get_fileid(), !Pdtoken::skipping());
line_number++;
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/fdep.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2003-2015 Diomidis Spinellis
* (C) Copyright 2003-2024 Diomidis Spinellis
*
* This file is part of CScout.
*
Expand Down Expand Up @@ -36,6 +36,7 @@ using namespace std;
#include "metrics.h"
#include "fileid.h"
#include "tokid.h"
#include "filedetails.h"

class Sql;

Expand Down
Loading

0 comments on commit 6a3458e

Please sign in to comment.