Skip to content

Commit

Permalink
Rename context to emitter.
Browse files Browse the repository at this point in the history
  • Loading branch information
egorpugin committed Apr 10, 2019
1 parent d4c47e0 commit 61b4733
Show file tree
Hide file tree
Showing 22 changed files with 148 additions and 281 deletions.
1 change: 0 additions & 1 deletion src/builder/command.cpp
Expand Up @@ -17,7 +17,6 @@
#include <file_storage.h>
#include <hash.h>
#include <filesystem.h>
#include <primitives/context.h>
#include <primitives/debug.h>
#include <primitives/executor.h>
#include <primitives/templates.h>
Expand Down
10 changes: 5 additions & 5 deletions src/builder/db_file.cpp
Expand Up @@ -13,7 +13,7 @@

void save_from_memory_to_file(const path &fn, sqlite3 *db);

#include <primitives/context.h>
#include <primitives/emitter.h>
#include <primitives/date_time.h>
#include <primitives/debug.h>
#include <primitives/exceptions.h>
Expand Down Expand Up @@ -73,7 +73,7 @@ static void load(FileStorage &fs, const path &fn,
{
ScopedShareableFileLock lk(fn);

primitives::BinaryContext b;
primitives::BinaryStream b;
try
{
b.load(fn);
Expand Down Expand Up @@ -185,7 +185,7 @@ void FileDb::save(FileStorage &fs, ConcurrentHashMap<path, FileRecord> &files, b
}*/
}

primitives::BinaryContext b(10'000'000); // reserve amount
primitives::BinaryStream b(10'000'000); // reserve amount
std::vector<uint8_t> v;
for (auto i = files.getIterator(); i.isValid(); i.next())
{
Expand Down Expand Up @@ -254,7 +254,7 @@ void FileDb::write(std::vector<uint8_t> &v, const FileRecord &f) const

static void load(const path &fn, ConcurrentCommandStorage &commands)
{
primitives::BinaryContext b;
primitives::BinaryStream b;
try
{
b.load(fn);
Expand Down Expand Up @@ -289,7 +289,7 @@ void FileDb::load(ConcurrentCommandStorage &commands, bool local) const

void FileDb::save(ConcurrentCommandStorage &commands, bool local) const
{
primitives::BinaryContext b(10'000'000); // reserve amount
primitives::BinaryStream b(10'000'000); // reserve amount
for (auto i = commands.getIterator(); i.isValid(); i.next())
{
b.write(i.getKey());
Expand Down
6 changes: 3 additions & 3 deletions src/client/client.cpp
Expand Up @@ -29,7 +29,7 @@
#include <boost/algorithm/string_regex.hpp>
#include <boost/dll.hpp>
#include <boost/regex.hpp>
#include <primitives/context.h>
#include <primitives/emitter.h>
#include <primitives/executor.h>
#include <primitives/file_monitor.h>
#include <primitives/lock.h>
Expand Down Expand Up @@ -571,7 +571,7 @@ SUBCOMMAND_DECL(create)

// TODO: add separate extended template with configure
// common sw.cpp
primitives::CppContext ctx;
primitives::CppEmitter ctx;
ctx.beginFunction("void build(Solution &s)");
ctx.addLine("// Uncomment to make a project. Also replace s.addTarget(). with p.addTarget() below.");
ctx.addLine("// auto &p = s.addProject(\"myproject\");");
Expand Down Expand Up @@ -650,7 +650,7 @@ int main(int argc, char *argv[])
}
else if (create_type == "config")
{
primitives::CppContext ctx;
primitives::CppEmitter ctx;
ctx.beginFunction("void build(Solution &s)");
ctx.addLine("// Uncomment to make a project. Also replace s.addTarget(). with p.addTarget() below.");
ctx.addLine("// auto &p = s.addProject(\"myproject\", \"master\");");
Expand Down
1 change: 0 additions & 1 deletion src/driver/build_self.cpp
Expand Up @@ -10,7 +10,6 @@
#include <resolver.h>

#include <boost/algorithm/string.hpp>
#include <primitives/context.h>

// disable custom pragma warnings
#ifdef _MSC_VER
Expand Down
26 changes: 13 additions & 13 deletions src/driver/generator/context.h
Expand Up @@ -36,11 +36,11 @@ struct PackagePathTree
Directories getDirectories(const PackagePath &p = {});
};

struct XmlContext : primitives::Context
struct XmlEmitter : primitives::Emitter
{
std::stack<String> blocks;

XmlContext(bool print_version = true);
XmlEmitter(bool print_version = true);

void beginBlock(const String &n, const std::map<String, String> &params = {}, bool empty = false);
void beginBlockWithConfiguration(const String &n, const SolutionSettings &s, std::map<String, String> params = {}, bool empty = false);
Expand All @@ -52,17 +52,17 @@ struct XmlContext : primitives::Context
void endBlock1(bool text = false);
};

struct FiltersContext : XmlContext
struct FiltersEmitter : XmlEmitter
{
void beginProject();
void endProject();
};

struct SolutionContext;
struct SolutionEmitter;

struct ProjectContext : XmlContext
struct ProjectEmitter : XmlEmitter
{
SolutionContext *parent = nullptr;
SolutionEmitter *parent = nullptr;
std::set<String> deps;
VSProjectType ptype;

Expand All @@ -78,24 +78,24 @@ struct ProjectContext : XmlContext
void addPropertySheets(const Build &b);

void printProject(
const String &name, const PackageId &p, const Build &b, SolutionContext &ctx, Generator &g,
const String &name, const PackageId &p, const Build &b, SolutionEmitter &ctx, Generator &g,
PackagePathTree::Directories &parents, PackagePathTree::Directories &local_parents,
const path &dir, const path &projects_dir
);
};

struct SolutionContext : primitives::Context
struct SolutionEmitter : primitives::Emitter
{
struct Project
{
String name;
std::unique_ptr<SolutionContext> ctx;
ProjectContext pctx;
std::unique_ptr<SolutionEmitter> ctx;
ProjectEmitter pctx;
String solution_dir;

Project()
{
ctx = std::make_unique<SolutionContext>();
ctx = std::make_unique<SolutionEmitter>();
}
~Project()
{
Expand All @@ -104,7 +104,7 @@ struct SolutionContext : primitives::Context
}
};

using Base = primitives::Context;
using Base = primitives::Emitter;

Version version;
String all_build_name;
Expand All @@ -114,7 +114,7 @@ struct SolutionContext : primitives::Context
std::map<String, Project> projects;
const Project *first_project = nullptr;

SolutionContext();
SolutionEmitter();

void printVersion();

Expand Down
16 changes: 8 additions & 8 deletions src/driver/generator/generator.cpp
Expand Up @@ -119,7 +119,7 @@ GeneratorType fromString(const String &s)
return GeneratorType::UnspecifiedGenerator;
}

struct NinjaContext : primitives::Context
struct NinjaEmitter : primitives::Emitter
{
void addCommand(const Build &b, const path &dir, const builder::Command &c)
{
Expand Down Expand Up @@ -244,7 +244,7 @@ void NinjaGenerator::generate(const Build &b)

const auto dir = path(SW_BINARY_DIR) / toPathString(type) / b.solutions[0].getConfig();

NinjaContext ctx;
NinjaEmitter ctx;

auto ep = b.getExecutionPlan();
for (auto &c : ep.commands)
Expand All @@ -257,14 +257,14 @@ void NinjaGenerator::generate(const Build &b)
write_file(dir / "build.ninja", t);
}

struct MakeContext : primitives::Context
struct MakeEmitter : primitives::Emitter
{
bool nmake = false;
std::unordered_map<path, size_t> programs;
std::unordered_map<path, size_t> generated_programs;

MakeContext()
: Context("\t")
MakeEmitter()
: Emitter("\t")
{}

void gatherPrograms(const Solution::CommandExecutionPlan::Vec &commands)
Expand Down Expand Up @@ -497,7 +497,7 @@ void MakeGenerator::generate(const Build &b)

auto ep = b.solutions[0].getExecutionPlan();

MakeContext ctx;
MakeEmitter ctx;
ctx.nmake = type == GeneratorType::NMake;
ctx.gatherPrograms(ep.commands);

Expand Down Expand Up @@ -537,9 +537,9 @@ void MakeGenerator::generate(const Build &b)
for (auto &c : ep.commands)
outputs.insert(c->outputs.begin(), c->outputs.end());
if (ctx.nmake)
ctx.addTarget("clean", {}, { "@del " + normalize_path_windows(MakeContext::printFiles(outputs, true)) });
ctx.addTarget("clean", {}, { "@del " + normalize_path_windows(MakeEmitter::printFiles(outputs, true)) });
else
ctx.addTarget("clean", {}, { "@rm -f " + MakeContext::printFiles(outputs, true) });
ctx.addTarget("clean", {}, { "@rm -f " + MakeEmitter::printFiles(outputs, true) });

write_file(d / "Makefile", ctx.getText());
}
Expand Down
2 changes: 1 addition & 1 deletion src/driver/generator/generator.h
Expand Up @@ -9,7 +9,7 @@
#include <cppan_version.h>
#include <package_path.h>

#include <primitives/context.h>
#include <primitives/emitter.h>
#include <primitives/filesystem.h>

namespace sw
Expand Down

0 comments on commit 61b4733

Please sign in to comment.