Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
teaching
nswi098
Cecko
skeleton
Commits
5c191f9a
Commit
5c191f9a
authored
Oct 22, 2020
by
Bednárek David RNDr. Ph.D.
Browse files
-d line mode coverage
parent
e795ef75
Changes
3
Hide whitespace changes
Inline
Side-by-side
fmwk/ckcontext.hpp
View file @
5c191f9a
...
...
@@ -69,49 +69,88 @@ namespace cecko {
extern
err_def_n
INCOMPATIBLE
;
}
struct
coverage_counter
{
public:
coverage_counter
()
:
num
(
0
)
{}
void
inc
()
{
++
num
;
}
namespace
coverage
{
int
get
()
const
{
return
num
;
}
private:
int
num
;
};
struct
coverage_counter
{
public:
coverage_counter
()
:
num
(
0
)
{}
struct
coverage_data
{
public:
void
inc
(
std
::
string
n
)
{
auto
rv
=
map_
.
try_emplace
(
std
::
move
(
n
));
rv
.
first
->
second
.
inc
();
}
void
inc
()
{
++
num
;
}
template
<
typename
F
>
void
for_each
(
F
&&
f
)
const
{
for
(
auto
&&
a
:
map_
)
int
get
()
const
{
f
(
a
.
first
,
a
.
second
)
;
return
num
;
}
}
private:
private:
int
num
;
};
using
map_t
=
std
::
map
<
std
::
string
,
coverage_counter
>
;
map_t
map_
;
};
using
map_element_t
=
std
::
pair
<
const
std
::
string
,
coverage_counter
>
;
using
map_element_obs
=
const
map_element_t
*
;
struct
line_coverage_data
{
public:
void
push
(
map_element_obs
p
)
{
v_
.
push_back
(
p
);
}
template
<
typename
F
>
void
for_each
(
F
&&
f
)
const
{
for
(
auto
&&
a
:
v_
)
{
f
(
a
->
first
);
}
}
private:
std
::
vector
<
map_element_obs
>
v_
;
};
using
line_map_t
=
std
::
map
<
loc_t
,
line_coverage_data
>
;
struct
coverage_data
{
public:
void
inc
(
loc_t
line
,
std
::
string
n
)
{
auto
rv
=
map_
.
try_emplace
(
std
::
move
(
n
));
rv
.
first
->
second
.
inc
();
auto
rvl
=
line_map_
.
try_emplace
(
line
);
rvl
.
first
->
second
.
push
(
&*
rv
.
first
);
}
template
<
typename
F
>
void
for_each
(
F
&&
f
)
const
{
for
(
auto
&&
a
:
map_
)
{
f
(
a
.
first
,
a
.
second
);
}
}
template
<
typename
F
>
void
for_each_line
(
F
&&
f
)
const
{
for
(
auto
&&
a
:
line_map_
)
{
f
(
a
.
first
,
a
.
second
);
}
}
private:
map_t
map_
;
line_map_t
line_map_
;
};
}
class
context
:
public
CKContext
{
public:
context
(
CKTablesObs
tables
,
std
::
ostream
*
outp
,
coverage_data
*
cd
)
:
CKContext
(
tables
),
line_
(
1
),
outp_
(
outp
),
cd_
(
cd
)
{}
context
(
CKTablesObs
tables
,
std
::
ostream
*
outp
,
coverage
::
coverage_data
*
cd
)
:
CKContext
(
tables
),
line_
(
1
),
outp_
(
outp
),
cd_
(
cd
)
{}
std
::
ostream
&
out
()
{
return
*
outp_
;
}
...
...
@@ -125,7 +164,7 @@ namespace cecko {
void
cov
(
std
::
string
n
)
{
cd_
->
inc
(
std
::
move
(
n
));
cd_
->
inc
(
line
(),
std
::
move
(
n
));
}
private:
...
...
@@ -133,7 +172,7 @@ namespace cecko {
std
::
ostream
*
outp_
;
coverage_data
*
cd_
;
coverage
::
coverage_data
*
cd_
;
};
using
context_obs
=
context
*
;
...
...
fmwk/ckmain.cpp
View file @
5c191f9a
...
...
@@ -74,6 +74,44 @@ namespace cecko {
covf
<<
std
::
setw
(
5
)
<<
cc
.
get
()
<<
"
\t
"
<<
name
<<
std
::
endl
;
});
}
if
(
!
covlinename
.
empty
())
{
std
::
ofstream
covf
(
covlinename
);
std
::
ifstream
inf
(
input_fname
);
loc_t
infline
=
0
;
cd_
.
for_each_line
([
&
covf
,
&
inf
,
&
infline
](
auto
&&
line
,
auto
&&
lcd
)
{
for
(;;)
{
std
::
string
ins
;
std
::
getline
(
inf
,
ins
);
++
infline
;
//covf << std::setw(5) << infline << "\t";
covf
<<
ins
;
if
(
infline
>=
line
)
{
std
::
string
delim
=
"
\t
//# "
;
lcd
.
for_each
([
&
covf
,
&
delim
](
auto
&&
name
)
{
covf
<<
delim
<<
name
;
delim
=
" "
;
});
covf
<<
std
::
endl
;
break
;
}
covf
<<
std
::
endl
;
}
});
for
(;;)
{
std
::
string
ins
;
std
::
getline
(
inf
,
ins
);
if
(
inf
.
fail
())
break
;
++
infline
;
//covf << std::setw(5) << infline << "\t";
covf
<<
ins
;
covf
<<
std
::
endl
;
}
}
return
true
;
}
...
...
@@ -101,6 +139,11 @@ namespace cecko {
return
false
;
covname
=
get_val
();
return
true
;
case
'd'
:
if
(
!
covlinename
.
empty
())
return
false
;
covlinename
=
get_val
();
return
true
;
case
'z'
:
if
(
!!
outp_owner_
)
return
false
;
...
...
fmwk/ckmain.hpp
View file @
5c191f9a
...
...
@@ -26,6 +26,7 @@ namespace cecko {
public:
std
::
string
input_fname
;
std
::
string
covname
;
std
::
string
covlinename
;
main_state_parser
()
:
outp_
(
&
std
::
cout
)
{}
...
...
@@ -60,7 +61,7 @@ namespace cecko {
std
::
ostream
*
outp_
;
std
::
unique_ptr
<
std
::
ofstream
>
outp_owner_
;
coverage_data
cd_
;
coverage
::
coverage_data
cd_
;
};
class
main_state_code
:
public
main_state_parser
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment