Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace IVOS/Table by std::map #3083

Merged
merged 8 commits into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 71 additions & 90 deletions src/ivoc/checkpnt.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <../../nrnconf.h>
#if HAVE_IV // to end of file
#include <map>
#include <memory>

/*

Expand Down Expand Up @@ -192,20 +194,12 @@
{0, 0}};

#define VPfri void*
declareTable(InstTable, VPfri, short)
implementTable(InstTable, VPfri, short)
static InstTable* inst_table_;

declareTable(Symbols, Symbol*, int)
implementTable(Symbols, Symbol*, int)

declareTable(Objects, Object*, int)
implementTable(Objects, Object*, int)
static std::map<VPfri, short>* inst_table_;

class OcCheckpoint {
public:
OcCheckpoint();
virtual ~OcCheckpoint();
virtual ~OcCheckpoint() = default;

Check warning on line 202 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L202

Added line #L202 was not covered by tests

bool write(const char*);

Expand Down Expand Up @@ -246,9 +240,9 @@
private:
int cnt_;
int nobj_;
Objects* otable_;
bool (OcCheckpoint::*func_)(Symbol*);
Symbols* stable_;
std::unique_ptr<std::map<Object*, int>> otable_{};
bool (OcCheckpoint::*func_)(Symbol*) = nullptr;
std::unique_ptr<std::map<Symbol*, int>> stable_{};
Objectdata* objectdata_;
};

Expand Down Expand Up @@ -359,30 +353,14 @@
}

OcCheckpoint::OcCheckpoint() {
func_ = NULL;
stable_ = NULL;
otable_ = NULL;
if (!inst_table_) {
short i;
for (i = 1; hoc_inst_[i].pi; ++i) {
;
}
inst_table_ = new InstTable(2 * i);
for (i = 1; hoc_inst_[i].pi; ++i) {
inst_table_->insert((VPfri) hoc_inst_[i].pi, i);
inst_table_ = new std::map<VPfri, short>{};
for (int i = 1; hoc_inst_[i].pi; ++i) {
inst_table_->emplace((VPfri) hoc_inst_[i].pi, i);

Check warning on line 359 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L357-L359

Added lines #L357 - L359 were not covered by tests
}
}
}

OcCheckpoint::~OcCheckpoint() {
if (stable_) {
delete stable_;
}
if (otable_) {
delete otable_;
}
}

bool OcCheckpoint::write(const char* fname) {
bool b;
int i;
Expand Down Expand Up @@ -427,10 +405,7 @@
}
fprintf(f_, "#symbols=%d\n", cnt_);
b = (b && xdr(cnt_));
if (stable_) {
delete stable_;
}
stable_ = new Symbols(2 * cnt_);
stable_ = std::make_unique<std::map<Symbol*, int>>();

Check warning on line 408 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L408

Added line #L408 was not covered by tests
cnt_ = 1;
func_ = &OcCheckpoint::sym_table_install;
if (!b) {
Expand All @@ -453,13 +428,13 @@
}

bool OcCheckpoint::sym_table_install(Symbol* s) {
stable_->insert(s, cnt_);
stable_->emplace(s, cnt_);

Check warning on line 431 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L431

Added line #L431 was not covered by tests
++cnt_;
return true;
}
bool OcCheckpoint::sym_out(Symbol* s) {
int val;
stable_->find(val, s);
auto it = stable_->find(s);
int val = it != stable_->end() ? it->second : 0;

Check warning on line 437 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L436-L437

Added lines #L436 - L437 were not covered by tests
fprintf(f_, "%d %s %d %d\n", val, s->name, s->type, s->subtype);
int l1 = strlen(s->name);
bool b = xdr(val) && xdr(s->name, l1) && xdr(s->type) && xdr(s->subtype) && xdr(s->cpublic) &&
Expand Down Expand Up @@ -553,11 +528,12 @@
bool OcCheckpoint::sym_instructions(Symbol* s) {
Proc* p = s->u.u_proc;
if (s->type == FUNCTION || s->type == PROCEDURE) {
int val;
if (!stable_->find(val, s)) {
auto it = stable_->find(s);
if (it == stable_->end()) {

Check warning on line 532 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L531-L532

Added lines #L531 - L532 were not covered by tests
printf("couldn't find %s in table\n", s->name);
return false;
}
int val = it->second;

Check warning on line 536 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L536

Added line #L536 was not covered by tests
if (p->size) {
fprintf(f_, "instructions for %d |%s|\n", val, s->name);
fprintf(f_, "size %lu\n", p->size);
Expand All @@ -577,18 +553,17 @@
}
bool OcCheckpoint::instlist(unsigned long size, Inst* in) {
for (unsigned long i = 0; i < size; ++i) {
short val;
int sval;
if (in[i].in == STOP) {
fprintf(f_, " STOP\n");
val = 0;
if (!xdr(val)) {
int sval = 0;
if (!xdr(sval)) {

Check warning on line 559 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L558-L559

Added lines #L558 - L559 were not covered by tests
printf("instlist failed 1\n");
return false;
}
continue;
}
if (inst_table_->find(val, (VPfri) in[i].pf)) {
if (auto it = inst_table_->find((VPfri) in[i].pf); it != inst_table_->end()) {
auto val = it->second;

Check warning on line 566 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L565-L566

Added lines #L565 - L566 were not covered by tests
fprintf(f_, " %d\n", val);
if (!xdr(val)) {
printf("instlist failed 2\n");
Expand All @@ -600,20 +575,22 @@
switch (s[j]) {
case 's':
if (in[i].sym) {
if (!stable_->find(sval, in[i].sym)) {
auto it = stable_->find(in[i].sym);
if (it == stable_->end()) {

Check warning on line 579 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L578-L579

Added lines #L578 - L579 were not covered by tests
printf("couldn't find |%s| in table at instruction index %ld\n",
in[i].sym->name,
i);
return false;
}
auto sval = it->second;

Check warning on line 585 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L585

Added line #L585 was not covered by tests
// fprintf(f_, " %d |%s|\n", sval, in[i].sym->name);
if (!xdr(sval)) {
printf("instlist failed 3\n");
return false;
}
} else {
fprintf(f_, " 0 SYMBOL0\n");
sval = 0;
int sval = 0;

Check warning on line 593 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L593

Added line #L593 was not covered by tests
if (!xdr(sval)) {
printf("instlist failed 4\n");
return false;
Expand Down Expand Up @@ -643,17 +620,19 @@
cTemplate* t = s->u.ctemplate;
if (func_ == &OcCheckpoint::sym_values) {
Objectdata* saveod = objectdata_;
int ti;
bool b;
b = stable_->find(ti, s);
auto it = stable_->find(s);
bool b = it != stable_->end();
auto ti = b ? it->second : 0;

Check warning on line 625 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L623-L625

Added lines #L623 - L625 were not covered by tests
fprintf(f_, "%d %d %s\n", ti, t->count, s->name);
b = b && xdr(ti);
// b = b && xdr(t->count);
hoc_Item* q;
ITERATE(q, t->olist) {
Object* ob = OBJ(q);
int oid;
b = b && otable_->find(oid, ob);
auto it = otable_->find(ob);
bool found = it != otable_->end();
b = b && found;
int oid = found ? it->second : 0;

Check warning on line 635 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L632-L635

Added lines #L632 - L635 were not covered by tests
b = b && xdr(oid);
if (t->constructor) {
if (t->checkpoint) {
Expand All @@ -677,42 +656,42 @@
}
}
bool OcCheckpoint::object() {
bool b;
int i;
if (otable_) {
delete otable_;
}
b = xdr(nobj_);
otable_ = new Objects(2 * nobj_ + 1);
bool b = xdr(nobj_);
otable_ = std::make_unique<std::map<Object*, int>>();

Check warning on line 660 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L659-L660

Added lines #L659 - L660 were not covered by tests
nobj_ = 0;
func_ = &OcCheckpoint::objects;
b = pass1();
i = -1;
int i = -1;

Check warning on line 664 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L664

Added line #L664 was not covered by tests
b = b && xdr(i);
return b;
}
bool OcCheckpoint::objects(Symbol* s) {
bool b = true;
if (s->type == TEMPLATE) {
int sid;
b = b && stable_->find(sid, s);
b = b && xdr(sid);
cTemplate* t = s->u.ctemplate;
if (s->type != TEMPLATE) {
return true;

Check warning on line 670 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L669-L670

Added lines #L669 - L670 were not covered by tests
}

auto it = stable_->find(s);
bool b = it != stable_->end();
int sid = b ? it->second : 0;
b = b && xdr(sid);
cTemplate* t = s->u.ctemplate;

Check warning on line 677 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L673-L677

Added lines #L673 - L677 were not covered by tests
#undef init
if (t->init) {
b = b && stable_->find(sid, t->init);
} else {
sid = 0;
}
b = b && xdr(sid);
b = b && xdr(t->index) && xdr(t->count) && xdr(t->id);
hoc_Item* q;
ITERATE(q, t->olist) {
Object* ob = OBJ(q);
++nobj_;
otable_->insert(ob, nobj_); // 0 is null object
b = b && xdr(nobj_) && xdr(ob->refcount) && xdr(ob->index);
}
if (t->init) {
auto it2 = stable_->find(t->init);
bool b2 = it2 != stable_->end();
b = b && b2;
sid = b2 ? it2->second : sid;

Check warning on line 683 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L679-L683

Added lines #L679 - L683 were not covered by tests
} else {
sid = 0;

Check warning on line 685 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L685

Added line #L685 was not covered by tests
}
b = b && xdr(sid);
b = b && xdr(t->index) && xdr(t->count) && xdr(t->id);

Check warning on line 688 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L687-L688

Added lines #L687 - L688 were not covered by tests
hoc_Item* q;
ITERATE(q, t->olist) {
Object* ob = OBJ(q);
++nobj_;
otable_->emplace(ob, nobj_); // 0 is null object
b = b && xdr(nobj_) && xdr(ob->refcount) && xdr(ob->index);

Check warning on line 694 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L690-L694

Added lines #L690 - L694 were not covered by tests
}
return b;
}
Expand Down Expand Up @@ -764,9 +743,10 @@
}

bool OcCheckpoint::sym_values(Symbol* s) {
int sp;
bool b;
stable_->find(sp, s);
auto it = stable_->find(s);
int sp = it != stable_->end() ? it->second : 0;

Check warning on line 748 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L747-L748

Added lines #L747 - L748 were not covered by tests

if ((s->type == VAR && s->subtype == NOTUSER) || s->type == OBJECTVAR || s->type == STRING ||
s->type == SECTION) {
fprintf(f_, "%d %s\n", sp, s->name);
Expand All @@ -790,8 +770,10 @@
int i = 0;
b = b && xdr(i);
} else {
int oid;
b = b && otable_->find(oid, ob);
auto it = otable_->find(ob);
bool found = it != otable_->end();
int oid = found ? it->second : 0;
b = b && found;

Check warning on line 776 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L773-L776

Added lines #L773 - L776 were not covered by tests
b = b && xdr(oid);
}
} else if (s->type == STRING) {
Expand Down Expand Up @@ -838,11 +820,10 @@
}

bool OcCheckpoint::xdr(Object*& o) {
int i;
bool b;
b = otable_->find(i, o);
b = b && xdr(i);
return b;
auto it = otable_->find(o);
bool b = it != otable_->end();
int i = b ? it->second : 0;
return b && xdr(i);

Check warning on line 826 in src/ivoc/checkpnt.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/checkpnt.cpp#L823-L826

Added lines #L823 - L826 were not covered by tests
}

#undef Chk
Expand Down
Loading