Skip to content

Commit

Permalink
Split Ast classes into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcgr committed Aug 1, 2020
1 parent 46a4d84 commit 23a4c68
Show file tree
Hide file tree
Showing 113 changed files with 2,502 additions and 1,495 deletions.
32 changes: 23 additions & 9 deletions src/AstToRamTranslator.cpp
Expand Up @@ -22,26 +22,46 @@
#include "LogStatement.h"
#include "RelationTag.h"
#include "SrcLocation.h"
#include "ast/Abstract.h"
#include "ast/Aggregator.h"
#include "ast/Argument.h"
#include "ast/Atom.h"
#include "ast/Attribute.h"
#include "ast/BinaryConstraint.h"
#include "ast/Clause.h"
#include "ast/Constant.h"
#include "ast/Constraint.h"
#include "ast/Counter.h"
#include "ast/ExecutionOrder.h"
#include "ast/ExecutionPlan.h"
#include "ast/Functor.h"
#include "ast/IO.h"
#include "ast/IntrinsicFunctor.h"
#include "ast/Literal.h"
#include "ast/Negation.h"
#include "ast/NilConstant.h"
#include "ast/Node.h"
#include "ast/NodeMapper.h"
#include "ast/NumericConstant.h"
#include "ast/Program.h"
#include "ast/ProvenanceNegation.h"
#include "ast/QualifiedName.h"
#include "ast/RecordInit.h"
#include "ast/Relation.h"
#include "ast/StringConstant.h"
#include "ast/SubroutineArgument.h"
#include "ast/TranslationUnit.h"
#include "ast/Type.h"
#include "ast/TypeSystem.h"
#include "ast/UnnamedVariable.h"
#include "ast/UserDefinedFunctor.h"
#include "ast/Utils.h"
#include "ast/Variable.h"
#include "ast/Visitor.h"
#include "ast/analysis/AuxArity.h"
#include "ast/analysis/RecursiveClauses.h"
#include "ast/analysis/RelationSchedule.h"
#include "ast/analysis/SCCGraph.h"
#include "ast/analysis/TopologicallySortedSCCGraph.h"
#include "ast/analysis/TypeEnvironment.h"
#include "json11.h"
#include "ram/Condition.h"
#include "ram/Expression.h"
#include "ram/Node.h"
Expand All @@ -53,8 +73,6 @@
#include "ram/Utils.h"
#include "utility/ContainerUtil.h"
#include "utility/FunctionalUtil.h"
#include "utility/StreamUtil.h"
#include "utility/StringUtil.h"
#include <algorithm>
#include <cassert>
#include <chrono>
Expand All @@ -64,14 +82,10 @@
#include <optional>
#include <set>
#include <sstream>
#include <type_traits>
#include <utility>
#include <vector>

namespace souffle {

using json11::Json;

class ErrorReport;

/** append statement to a list of statements */
Expand Down
16 changes: 10 additions & 6 deletions src/AstToRamTranslator.h
Expand Up @@ -18,10 +18,14 @@

#include "RamTypes.h"
#include "SymbolTable.h"
#include "ast/Abstract.h"
#include "ast/Argument.h"
#include "ast/Constant.h"
#include "ast/NilConstant.h"
#include "ast/Node.h"
#include "ast/NumericConstant.h"
#include "ast/QualifiedName.h"
#include "ast/StringConstant.h"
#include "ast/Variable.h"
#include "json11.h"
#include "ram/Relation.h"
#include "ram/Statement.h"
Expand All @@ -42,22 +46,22 @@

namespace souffle {

using json11::Json;

// forward declarations
class AstAtom;
class AstClause;
class AstLiteral;
class AstProgram;
class AstRelation;
class AstTranslationUnit;
class AuxiliaryArity;
class RamCondition;
class RamTupleElement;
class RamExpression;
class RamOperation;
class RamTranslationUnit;
class RamExpression;
class RamTupleElement;
class RecursiveClausesAnalysis;
class TypeEnvironment;
class AstRecordInit;

/**
* Main class for AST Translator
Expand Down Expand Up @@ -385,7 +389,7 @@ class AstToRamTranslator {
* Get ram records types.
* If they don't exists - create them.
*/
const Json getRecordsTypes();
const json11::Json getRecordsTypes();

/** Return a symbol table **/
SymbolTable& getSymbolTable() {
Expand Down
55 changes: 42 additions & 13 deletions src/Makefile.am
Expand Up @@ -104,46 +104,71 @@ souffle_sources = \
WriteStream.h \
WriteStreamCSV.h \
WriteStreamJSON.h \
ast/Abstract.h \
ast/Aggregator.h \
ast/Argument.h \
ast/Atom.h \
ast/Attribute.h \
ast/BinaryConstraint.h \
ast/BooleanConstraint.h \
ast/Clause.h \
ast/Component.h \
ast/ComponentInit.h \
ast/ComponentType.h \
ast/Constant.h \
ast/Constraint.h \
ast/Counter.h \
ast/ExecutionOrder.h \
ast/ExecutionPlan.h \
ast/Functor.h \
ast/FunctorDeclaration.h \
ast/IO.h \
ast/IntrinsicFunctor.h \
ast/LambdaNodeMapper.h \
ast/Literal.h \
ast/Negation.h \
ast/NilConstant.h \
ast/Node.h \
ast/NodeMapper.h \
ast/NumericConstant.h \
ast/ParserUtils.cpp \
ast/ParserUtils.h \
ast/Pragma.h \
ast/Program.h \
ast/ProvenanceNegation.h \
ast/QualifiedName.h \
ast/RecordInit.h \
ast/RecordType.h \
ast/Relation.h \
ast/StringConstant.h \
ast/SubroutineArgument.h \
ast/SubsetType.h \
ast/Term.h \
ast/TranslationUnit.h \
ast/Type.h \
ast/TypeCast.h \
ast/TypeSystem.cpp \
ast/TypeSystem.h \
ast/UnionType.h \
ast/UnnamedVariable.h \
ast/UserDefinedFunctor.h \
ast/Utils.cpp \
ast/Utils.h \
ast/Variable.h \
ast/Visitor.h \
ast/TypeSystem.cpp \
ast/TypeSystem.h \
ast/analysis/Analysis.h \
ast/analysis/AuxArity.cpp \
ast/analysis/AuxArity.h \
ast/analysis/ComponentLookup.cpp \
ast/analysis/ComponentLookup.h \
ast/analysis/Constraint.h \
ast/analysis/Ground.cpp \
ast/analysis/Ground.h \
ast/analysis/IOType.cpp \
ast/analysis/IOType.h \
ast/analysis/ProfileUse.cpp \
ast/analysis/ProfileUse.h \
ast/analysis/Type.cpp \
ast/analysis/Type.h \
ast/analysis/TypeEnvironment.cpp \
ast/analysis/TypeEnvironment.h \
ast/analysis/AuxArity.cpp \
ast/analysis/AuxArity.h \
ast/analysis/ComponentLookup.cpp \
ast/analysis/ComponentLookup.h \
ast/analysis/PrecedenceGraph.cpp \
ast/analysis/PrecedenceGraph.h \
ast/analysis/ProfileUse.cpp \
ast/analysis/ProfileUse.h \
ast/analysis/RecursiveClauses.cpp \
ast/analysis/RecursiveClauses.h \
ast/analysis/RedundantRelations.cpp \
Expand All @@ -156,6 +181,10 @@ souffle_sources = \
ast/analysis/SCCGraph.h \
ast/analysis/TopologicallySortedSCCGraph.cpp \
ast/analysis/TopologicallySortedSCCGraph.h \
ast/analysis/Type.cpp \
ast/analysis/Type.h \
ast/analysis/TypeEnvironment.cpp \
ast/analysis/TypeEnvironment.h \
ast/transform/ComponentChecker.cpp \
ast/transform/ComponentChecker.h \
ast/transform/ComponentInstantiation.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/SouffleInterface.h
Expand Up @@ -8,7 +8,7 @@

/************************************************************************
*
* @file CompiledSouffle.h
* @file SouffleInterface.h
*
* Main include file for generated C++ classes of Souffle
*
Expand Down
118 changes: 118 additions & 0 deletions src/ast/Aggregator.h
@@ -0,0 +1,118 @@
/*
* Souffle - A Datalog Compiler
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved
* Licensed under the Universal Permissive License v 1.0 as shown at:
* - https://opensource.org/licenses/UPL
* - <souffle root>/licenses/SOUFFLE-UPL.txt
*/

/************************************************************************
*
* @file Aggregator.h
*
***********************************************************************/

#pragma once

#include "AggregateOp.h"
#include "SrcLocation.h"
#include "ast/Argument.h"
#include "ast/Literal.h"
#include "ast/Node.h"
#include "ast/NodeMapper.h"
#include "utility/ContainerUtil.h"
#include "utility/MiscUtil.h"
#include "utility/StreamUtil.h"
#include <memory>
#include <ostream>
#include <string>
#include <utility>
#include <vector>

namespace souffle {

/**
* An argument aggregating a value from a sub-query.
*/
class AstAggregator : public AstArgument {
public:
AstAggregator(AggregateOp fun, Own<AstArgument> expr = nullptr, VecOwn<AstLiteral> body = {},
SrcLocation loc = {})
: AstArgument(std::move(loc)), fun(fun), targetExpression(std::move(expr)),
body(std::move(body)) {}

/** Get aggregate operator */
AggregateOp getOperator() const {
return fun;
}

/** Set aggregate operator */
void setOperator(AggregateOp op) {
fun = op;
}

/** Get target expression */
const AstArgument* getTargetExpression() const {
return targetExpression.get();
}

/** Get body literals */
std::vector<AstLiteral*> getBodyLiterals() const {
return toPtrVector(body);
}

void setBody(VecOwn<AstLiteral> bodyLiterals) {
body = std::move(bodyLiterals);
}

std::vector<const AstNode*> getChildNodes() const override {
auto res = AstArgument::getChildNodes();
if (targetExpression) {
res.push_back(targetExpression.get());
}
for (auto& cur : body) {
res.push_back(cur.get());
}
return res;
}

AstAggregator* clone() const override {
return new AstAggregator(fun, souffle::clone(targetExpression), souffle::clone(body), getSrcLoc());
}

void apply(const AstNodeMapper& map) override {
if (targetExpression) {
targetExpression = map(std::move(targetExpression));
}
for (auto& cur : body) {
cur = map(std::move(cur));
}
}

protected:
void print(std::ostream& os) const override {
os << fun;
if (targetExpression) {
os << " " << *targetExpression;
}
os << " : { " << join(body) << " }";
}

bool equal(const AstNode& node) const override {
const auto& other = static_cast<const AstAggregator&>(node);
return fun == other.fun && equal_ptr(targetExpression, other.targetExpression) &&
equal_targets(body, other.body);
}

private:
/** Aggregation operator */
AggregateOp fun;

/** Aggregation expression */
Own<AstArgument> targetExpression;

/** Body literal of sub-query */
VecOwn<AstLiteral> body;
};

} // end of namespace souffle

0 comments on commit 23a4c68

Please sign in to comment.