Skip to content

Commit 62cfa5f

Browse files
committed
Use provided ostream for dag logging, allow to log dag from any CcsContext.
1 parent 3089941 commit 62cfa5f

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

api/ccs/context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CCS_CONTEXT_H_
22
#define CCS_CONTEXT_H_
33

4+
#include <iosfwd>
45
#include <memory>
56
#include <sstream>
67
#include <stdexcept>
@@ -35,6 +36,8 @@ class CcsContext {
3536

3637
class Builder;
3738

39+
void logRuleDag(std::ostream &os) const;
40+
3841
Builder builder() const;
3942

4043
CcsContext constrain(const std::string &name) const

api/ccs/domain.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define CCS_DOMAIN_H_
33

44
#include <memory>
5-
#include <istream>
5+
#include <iosfwd>
66
#include <string>
77

88
#include "ccs/context.h"
@@ -44,7 +44,8 @@ class CcsDomain {
4444
CcsDomain &loadCcsStream(std::istream &stream, const std::string &fileName,
4545
ImportResolver &importResolver);
4646
RuleBuilder ruleBuilder();
47-
void logRuleDag() const;
47+
48+
void logRuleDag(std::ostream &os) const;
4849

4950
CcsContext build();
5051
};

src/context.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ CcsContext::CcsContext(const CcsContext &parent, const std::string &name,
4040
const std::vector<std::string> &values)
4141
: searchState(SearchState::newChild(parent.searchState, Key(name, values))) {}
4242

43+
void CcsContext::logRuleDag(std::ostream &os) const {
44+
searchState->logRuleDag(os);
45+
}
46+
4347
CcsContext::Builder CcsContext::builder() const { return Builder(*this); }
4448

4549
const CcsProperty &CcsContext::getProperty(const std::string &propertyName)

src/domain.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ CcsContext CcsDomain::build() {
5959
return CcsContext(dag->root(), log, logAccesses);
6060
}
6161

62-
void CcsDomain::logRuleDag() const {
63-
std::ostringstream os;
64-
os << "CCS rule DAG: " << Dumper(*dag->root());
65-
log.info(os.str());
62+
void CcsDomain::logRuleDag(std::ostream &os) const {
63+
os << Dumper(*dag->root());
6664
}
6765

6866
}

src/graphviz.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ void visit(const Dumper &dumper, std::ostream &os,
9191
visit(dumper, os, visited, tally.node());
9292
}
9393
}
94-
9594
}
9695

9796
}

src/search_state.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "dag/key.h"
1212
#include "dag/property.h"
1313
#include "dag/specificity.h"
14+
#include "graphviz.h"
1415

1516
namespace ccs {
1617

@@ -68,6 +69,13 @@ class SearchState {
6869
static std::shared_ptr<SearchState> newChild(
6970
const std::shared_ptr<const SearchState> &parent, const Key &key);
7071

72+
void logRuleDag(std::ostream &os) const {
73+
if (parent)
74+
parent->logRuleDag(os);
75+
else
76+
os << Dumper(*root);
77+
}
78+
7179
bool extendWith(const SearchState &priorState);
7280

7381
const CcsProperty *findProperty(const std::string &propertyName) const;

test/acceptance_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ TEST_P(AcceptanceTests, Load) {
108108
ccs.loadCcsStream(input, "<literal>", ImportResolver::None);
109109
CcsContext root = ccs.build();
110110

111-
//ccs.logRuleDag();
111+
//ccs.logRuleDag(std::cout);
112+
//std::cout << std::endl;
112113

113114
for (auto it = test.assertions.cbegin(); it != test.assertions.cend(); ++it) {
114115
CcsContext ctx = root;

0 commit comments

Comments
 (0)