Skip to content

Commit

Permalink
Moved out appendStmt into a utils construct.
Browse files Browse the repository at this point in the history
  • Loading branch information
azreika committed Nov 16, 2020
1 parent 19471bc commit 8259a59
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
23 changes: 8 additions & 15 deletions src/ast2ram/AstToRamTranslator.cpp
Expand Up @@ -122,11 +122,14 @@ namespace souffle::ast2ram {
AstToRamTranslator::AstToRamTranslator() = default;
AstToRamTranslator::~AstToRamTranslator() = default;

/** append statement to a list of statements */
void AstToRamTranslator::appendStmt(VecOwn<ram::Statement>& stmtList, Own<ram::Statement> stmt) {
if (stmt) {
stmtList.push_back(std::move(stmt));
}
void AstToRamTranslator::addRamSubroutine(std::string subroutineID, Own<ram::Statement> subroutine) {
assert(!contains(ramSubroutines, subroutineID) && "subroutine ID should not already exist");
ramSubroutines[subroutineID] = std::move(subroutine);
}

void AstToRamTranslator::addRamRelation(std::string relationName, Own<ram::Relation> ramRelation) {
assert(!contains(ramRelations, relationName) && "ram relation should not already exist");
ramRelations[relationName] = std::move(ramRelation);
}

size_t AstToRamTranslator::getEvaluationArity(const ast::Atom* atom) const {
Expand Down Expand Up @@ -747,16 +750,6 @@ void AstToRamTranslator::finaliseAstTypes() {
});
}

void AstToRamTranslator::addRamSubroutine(std::string subroutineID, Own<ram::Statement> subroutine) {
assert(!contains(ramSubroutines, subroutineID) && "subroutine ID should not already exist");
ramSubroutines[subroutineID] = std::move(subroutine);
}

void AstToRamTranslator::addRamRelation(std::string relationName, Own<ram::Relation> ramRelation) {
assert(!contains(ramRelations, relationName) && "ram relation should not already exist");
ramRelations[relationName] = std::move(ramRelation);
}

Own<ram::Sequence> AstToRamTranslator::translateProgram(const ast::TranslationUnit& translationUnit) {
// keep track of relevant analyses
ioType = translationUnit.getAnalysis<ast::analysis::IOTypeAnalysis>();
Expand Down
1 change: 0 additions & 1 deletion src/ast2ram/AstToRamTranslator.h
Expand Up @@ -118,7 +118,6 @@ class AstToRamTranslator {
const ast::analysis::PolymorphicObjectsAnalysis* polyAnalysis = nullptr;

void nameUnnamedVariables(ast::Clause* clause);
void appendStmt(VecOwn<ram::Statement>& stmtList, Own<ram::Statement> stmt);
Own<ram::Sequence> translateSCC(size_t scc, size_t idx);
virtual void addNegation(ast::Clause& clause, const ast::Atom* atom);
virtual void clearExpiredRelations(
Expand Down
7 changes: 7 additions & 0 deletions src/ast2ram/utility/Utils.cpp
Expand Up @@ -24,6 +24,7 @@
#include "souffle/utility/ContainerUtil.h"
#include "souffle/utility/StringUtil.h"
#include <string>
#include <vector>

namespace souffle::ast2ram {

Expand All @@ -47,6 +48,12 @@ std::string getRelationName(const ast::QualifiedName& id) {
return toString(join(id.getQualifiers(), "."));
}

void appendStmt(VecOwn<ram::Statement>& stmtList, Own<ram::Statement> stmt) {
if (stmt) {
stmtList.push_back(std::move(stmt));
}
}

Own<ram::TupleElement> makeRamTupleElement(const Location& loc) {
return mk<ram::TupleElement>(loc.identifier, loc.element);
}
Expand Down
8 changes: 6 additions & 2 deletions src/ast2ram/utility/Utils.h
Expand Up @@ -27,6 +27,7 @@ class Relation;

namespace souffle::ram {
class Clear;
class Statement;
class TupleElement;
} // namespace souffle::ram

Expand All @@ -49,10 +50,13 @@ std::string getDeltaRelationName(const ast::Relation* rel);
/** Get the corresponding RAM 'new' relation name for the relation */
std::string getNewRelationName(const ast::Relation* rel);

/** create a RAM element access node */
/** Append statement to a list of statements */
void appendStmt(VecOwn<ram::Statement>& stmtList, Own<ram::Statement> stmt);

/** Create a RAM element access node */
Own<ram::TupleElement> makeRamTupleElement(const Location& loc);

/** add a statement to store a relation */
/** Add a statement to store a relation */
Own<ram::Clear> makeRamClear(const ast::Relation* relation);

} // namespace souffle::ast2ram

0 comments on commit 8259a59

Please sign in to comment.