Skip to content

Commit

Permalink
Added test coverage, and refactored decompile.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Carter committed May 4, 2018
1 parent 15de609 commit 936cb25
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 28 deletions.
9 changes: 7 additions & 2 deletions TR/CONTENTS
@@ -1,6 +1,11 @@
TR01: Formatting of cell values.
TR02: command creation.
TR03: Tcl/swig - OBSOLETE
TR04: atlast Forth subsystem - OBSOLETE

TR05: Legacy Oleo
TR06: Magic numbers
TR07: coverage testing


OBSOLETE:
TR03: Tcl/swig - OBSOLETE
TR04: atlast Forth subsystem - OBSOLETE
23 changes: 23 additions & 0 deletions TR/TR07
@@ -0,0 +1,23 @@
TR07: coverage testing
===========================================================================
2018-05-05


Compile and link using the flag `--coverage'

Run the program as usual. This will create a bunch of files of files in
the `src' directory.

`cd src' directory

To obtain coverage info on a particular file, e.g. `decompile.cc', run:
gcov decompile.cc
This creates the file decompile.cc.gcov

Inspect coverage using `less decompile.cc.gcov'. Interpreting it:
https://gcc.gnu.org/onlinedocs/gcc/Invoking-Gcov.html
Simply, the columns are:
1. Number of executions. `-:' means unexcutable code, `#####' means
unexecuted code
2. line number
3. Code
1 change: 1 addition & 0 deletions conf
Expand Up @@ -7,6 +7,7 @@ if [ ! -f configure ]; then
autoreconf -iv
fi

#COV="--coverage"
DBG=--with-debug
#GPROF=--with-gprof

Expand Down
4 changes: 4 additions & 0 deletions src/.gitignore
Expand Up @@ -5,3 +5,7 @@ parse.cc
parse.hh
posixtm.cc
posixtm.hh

*.gcda
*.gcno
*.gcov
3 changes: 3 additions & 0 deletions src/Makefile.am
@@ -1,11 +1,13 @@
# permissive flag is set due to pesky obstack
COV = --coverage
AM_CXXFLAGS = @ASAN_CXXFLAGS@
AM_CXXFLAGS += -std=c++17
#AM_CXXFLAGS += -fpermissive
#AM_CXXFLAGS += -Wno-write-strings
#AM_CXXFLAGS += -Wformat -Wformat-security
AM_CXXFLAGS += -DDATADIR="\"$(datadir)\""
AM_CXXFLAGS += -Wfatal-errors
AM_CXXFLAGS += $(COV)

YFLAGS = -d
#EXTRA_DIST = $(srcdir)/neoleo.i
Expand All @@ -18,6 +20,7 @@ CLEANFILES = $(BUILT_SOURCES)

#neoleo_LDADD = -lm @CURSES_LIBS@ -lpanel $(ASAN_FLAGSL)
neoleo_LDADD = @ASAN_LIBS@ -lm @CURSES_LIBS@ -lpanel
neoleo_LDFLAGS = $(COV)

# Optional component: neobasic:
#if 0
Expand Down
33 changes: 7 additions & 26 deletions src/decompile.cc
Expand Up @@ -581,50 +581,31 @@ decomp_str(const CELLREF r, const CELLREF c)
const char *
decomp(const CELLREF r, const CELLREF c, CELL *cell)
{
const char *tmp = decomp_formula (r, c, cell, 0);
return tmp;
return decomp_formula (r, c, cell, 0);
}


const std::string
decomp_formula_1(const CELLREF r, const CELLREF c, CELL *cell, int tog)
{
std::string str;

extern char *bname[];
switch (GET_TYP (cell)) {
case 0:
return "";
break;
case TYP_FLT:
if (tog)
str = flt_to_str_fmt(cell);
else
str = flt_to_str (cell->gFlt());
log_debug_1("decomp_formula_1:TYP_FLT:"s + str);
break;
if (tog) return flt_to_str_fmt(cell);
return flt_to_str (cell->gFlt());
case TYP_INT:
{
static char buf[20];
sprintf(buf, "%ld", (long int) cell->gInt());
str = buf;
}
break;
return std::to_string(cell->gInt());
case TYP_STR:
str = backslash_a_string (cell->gString(), 1);
log_debug_1("decomp_formula_1:TYP_STR:"s + str);
break;
return backslash_a_string (cell->gString(), 1);
case TYP_BOL:
str = bname[cell->gBol()];
break;
return bname[cell->gBol()];
case TYP_ERR:
str = ename[cell->gBol()];
break;
return ename[cell->gBol()];
default:
panic ("Unknown type %d in decomp", GET_TYP (cell));

}
return str;
}

const char *
Expand Down

0 comments on commit 936cb25

Please sign in to comment.