Skip to content

Commit

Permalink
string_view
Browse files Browse the repository at this point in the history
  • Loading branch information
grencez committed Nov 20, 2023
1 parent 4ea01a5 commit 828a151
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 47 deletions.
2 changes: 2 additions & 0 deletions src/namespace.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace X {
#define PROTOCON_NAMESPACE protocon
#endif
namespace PROTOCON_NAMESPACE {
typedef unsigned Action_id;

typedef Cx::AlphaTab String;
using Cx::BitTable;
using Cx::FlatSet;
Expand Down
6 changes: 4 additions & 2 deletions src/pla.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,13 @@ oput_protocon_pc_acts_espresso_spawn(std::ostream& out, const Xn::PcSymm& pc_sym
oput_protocon_pc_acts_espresso(std::ostream& out,
const Xn::PcSymm& pc_symm,
const std::vector<Xn::ActSymm>& acts,
const std::string& espresso_name)
std::string_view espresso_name)
{
std::string exename;
exename = espresso_name;
const char* const argv[] = {
#if 1
espresso_name.c_str(),
exename.c_str(),
// Using -Dexact can take a long time.
// "-Dexact",
#else
Expand Down
2 changes: 1 addition & 1 deletion src/pla.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ oput_protocon_pc_acts_espresso(
std::ostream& out,
const Xn::PcSymm& pc_symm,
const std::vector<Xn::ActSymm>& acts,
const std::string& espresso_name);
std::string_view espresso_name);

END_NAMESPACE
#endif
Expand Down
62 changes: 33 additions & 29 deletions src/prot-ofile.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

#include "prot-ofile.hh"

#include <sstream>

#include <fildesh/ostream.hh>

#include "pla.hh"
Expand Down Expand Up @@ -69,7 +71,7 @@ string_of_access_type(Xn::VariableAccessType type)
static
void
oput_protocon_pc_vbl(std::ostream& ofile, const Xn::PcSymm& pc_symm,
unsigned vidx, const String& idxname)
unsigned vidx, std::string_view idxname)
{
const Xn::VblSymmAccessSpec& access = pc_symm.spec->access[vidx];
ofile
Expand Down Expand Up @@ -146,7 +148,7 @@ static
bool
oput_protocon_pc_acts(std::ostream& out, const Xn::PcSymm& pc_symm,
const std::vector<Xn::ActSymm>& acts,
const std::string& maybe_espresso)
std::string_view maybe_espresso)
{
const Xn::PcSymmSpec& pc_symm_spec = *pc_symm.spec;
if (pc_symm_spec.shadow_act_strings.sz() > 0) {
Expand Down Expand Up @@ -215,18 +217,18 @@ static
bool
oput_protocon_pc_assume (std::ostream& out, const Xn::PcSymm& pc_symm)
{
const String& assume_expression = pc_symm.spec->closed_assume_expression;
const auto& assume_expression = pc_symm.spec->closed_assume_expression;
if (assume_expression.empty())
return true;
out << "\n (assume & closed)\n (" << assume_expression << ");";
return true;
}

static
String
std::string
string_of_invariant_style (Xn::InvariantStyle style, Xn::InvariantScope scope)
{
String s = "";
std::ostringstream oss;
const char* pfx = "";
const char* sfx = "";

Expand All @@ -235,7 +237,7 @@ string_of_invariant_style (Xn::InvariantStyle style, Xn::InvariantScope scope)
case Xn::DirectInvariant:
break;
case Xn::ShadowInvariant:
s = "(";
oss << "(";
sfx = " % puppet)";
break;
case Xn::FutureInvariant:
Expand All @@ -245,26 +247,26 @@ string_of_invariant_style (Xn::InvariantStyle style, Xn::InvariantScope scope)
Claim( 0 );
}

s << "(future & " << pfx;
oss << "(future & " << pfx;
switch (style)
{
case Xn::FutureAndClosed:
s << "closed";
oss << "closed";
break;
case Xn::FutureAndSilent:
s << "silent";
oss << "silent";
break;
case Xn::FutureAndShadow:
s << "shadow";
oss << "shadow";
break;
case Xn::FutureAndActiveShadow:
s << "active shadow";
oss << "active shadow";
break;
case Xn::NInvariantStyles:
Claim( 0 );
}
s << ")" << sfx;
return s;
oss << ")" << sfx;
return oss.str();
}

static
Expand All @@ -287,9 +289,9 @@ string_of_invariant_behav (Xn::InvariantBehav behav)
static
bool
oput_protocon_pc_invariant(std::ostream& out, const Xn::PcSymm& pc_symm,
const String& style_str)
const std::string_view style_str)
{
const String& invariant_expression = pc_symm.spec->invariant_expression;
const auto& invariant_expression = pc_symm.spec->invariant_expression;
if (invariant_expression.empty())
return true;

Expand All @@ -301,14 +303,14 @@ oput_protocon_pc_invariant(std::ostream& out, const Xn::PcSymm& pc_symm,
bool
oput_protocon_file(std::ostream& out, const Xn::Sys& sys,
const Xn::Net& o_topology,
const vector<uint>& actions,
const std::string& maybe_espresso,
const char* comment)
const std::vector<Action_id>& actions,
std::string_view maybe_espresso,
std::string_view comment)
{
DeclLegit( good );

const Xn::Net& topo = sys.topology;
if (comment) {
if (!comment.empty()) {
out << "// " << comment;
}
oput_protocon_constants(out, *o_topology.spec);
Expand All @@ -334,11 +336,11 @@ oput_protocon_file(std::ostream& out, const Xn::Sys& sys,
out << "\n(assume & closed)\n (" << sys.spec->closed_assume_expression << ")\n ;";
}

String style_str =
std::string style_str =
string_of_invariant_style (sys.spec->invariant_style,
sys.spec->invariant_scope);
if (!sys.spec->invariant_expression.empty()) {
String legit_str = sys.spec->invariant_expression;
const auto& legit_str = sys.spec->invariant_expression;
out << "\n" << style_str << "\n (" << legit_str << ")\n ;";
}

Expand Down Expand Up @@ -388,15 +390,17 @@ oput_protocon_file(std::ostream& out, const Xn::Sys& sys,
}

bool
oput_protocon_file(std::ostream& out, const Xn::Sys& sys, const vector<uint>& actions,
const std::string& maybe_espresso, const char* comment)
oput_protocon_file(
std::ostream& out, const Xn::Sys& sys,
const std::vector<Action_id>& actions,
std::string_view maybe_espresso, std::string_view comment)
{
return oput_protocon_file(out, sys, sys.topology, actions, maybe_espresso, comment);
}

bool
oput_protocon_file(std::ostream& out, const Xn::Sys& sys,
const std::string& maybe_espresso, const char* comment)
std::string_view maybe_espresso, std::string_view comment)
{
return oput_protocon_file(out, sys, sys.actions, maybe_espresso, comment);
}
Expand All @@ -406,9 +410,9 @@ oput_protocon_file(
const std::string& ofilename,
const Xn::Sys& sys,
const Xn::Net& o_topology,
const vector<uint>& actions,
const std::string& maybe_espresso,
const char* comment)
const std::vector<Action_id>& actions,
std::string_view maybe_espresso,
std::string_view comment)
{
fildesh::ofstream out(ofilename.c_str());
if (!out.good()) {return false;}
Expand All @@ -419,8 +423,8 @@ oput_protocon_file(
oput_protocon_file(
const std::string& ofilename,
const Xn::Sys& sys,
const std::string& maybe_espresso,
const char* comment)
std::string_view maybe_espresso,
std::string_view comment)
{
return oput_protocon_file(
ofilename, sys, sys.topology, sys.actions, maybe_espresso, comment);
Expand Down
34 changes: 19 additions & 15 deletions src/prot-ofile.hh
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@

#ifndef PROT_OFILE_HH_
#define PROT_OFILE_HH_

#include "cx/synhax.hh"
#include <ostream>
#include <string>
#include <vector>

#include "namespace.hh"

bool
oput_protocon_file(
std::ostream& out,
const Xn::Sys& sys, const Xn::Net& o_topology, const vector<uint>& actions,
const std::string& maybe_espresso,
const char* comment);
const Xn::Sys& sys, const Xn::Net& o_topology,
const std::vector<Action_id>& actions,
std::string_view maybe_espresso,
std::string_view comment);
bool
oput_protocon_file(
std::ostream& out,
const Xn::Sys& sys, const vector<uint>& actions,
const std::string& maybe_espresso,
const char* comment);
const Xn::Sys& sys,
const std::vector<Action_id>& actions,
std::string_view maybe_espresso,
std::string_view comment);
bool
oput_protocon_file(
std::ostream& out,
const Xn::Sys& sys,
const std::string& maybe_espresso,
const char* comment);
std::string_view maybe_espresso,
std::string_view comment);
bool
oput_protocon_file(
const std::string& ofilename,
const Xn::Sys& sys, const Xn::Net& o_topology, const vector<uint>& actions,
const std::string& maybe_espresso,
const char* comment);
const Xn::Sys& sys, const Xn::Net& o_topology,
const std::vector<Action_id>& actions,
std::string_view maybe_espresso,
std::string_view comment);
bool
oput_protocon_file(
const std::string& ofilename,
const Xn::Sys& sys,
const std::string& maybe_espresso,
const char* comment);
std::string_view maybe_espresso,
std::string_view comment);

END_NAMESPACE
#endif
Expand Down

0 comments on commit 828a151

Please sign in to comment.