diff --git a/src/Makefile.am b/src/Makefile.am index 32afbe3c382..fb29476a30c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -201,6 +201,7 @@ souffle_sources = \ ast2ram/ProvenanceClauseTranslator.h \ ast2ram/ValueIndex.cpp \ ast2ram/ValueIndex.h \ + ast2ram/ValueTranslator.cpp \ ast2ram/ValueTranslator.h \ interpreter/Context.h \ interpreter/Engine.cpp \ diff --git a/src/ast2ram/ValueTranslator.cpp b/src/ast2ram/ValueTranslator.cpp new file mode 100644 index 00000000000..a31a99d14d9 --- /dev/null +++ b/src/ast2ram/ValueTranslator.cpp @@ -0,0 +1,49 @@ +/* + * Souffle - A Datalog Compiler + * Copyright (c) 2020 The Souffle Developers. All rights reserved + * Licensed under the Universal Permissive License v 1.0 as shown at: + * - https://opensource.org/licenses/UPL + * - /licenses/SOUFFLE-UPL.txt + */ + +/************************************************************************ + * + * @file ValueTranslator.cpp + * + ***********************************************************************/ + +#include "ast2ram/ValueTranslator.h" +#include "ast/NumericConstant.h" +#include "ast2ram/AstToRamTranslator.h" +#include "ast2ram/ValueIndex.h" +#include "ram/FloatConstant.h" +#include "ram/SignedConstant.h" +#include "ram/UndefValue.h" +#include "ram/UnsignedConstant.h" + +namespace souffle::ast2ram { + +Own ValueTranslator::visitVariable(const ast::Variable& var) { + assert(index.isDefined(var) && "variable not grounded"); + return translator.makeRamTupleElement(index.getDefinitionPoint(var)); +} + +Own ValueTranslator::visitUnnamedVariable(const ast::UnnamedVariable&) { + return mk(); +} +Own ValueTranslator::visitNumericConstant(const ast::NumericConstant& c) { + assert(c.getType().has_value() && "At this points all constants should have type."); + + switch (*c.getType()) { + case ast::NumericConstant::Type::Int: + return mk(RamSignedFromString(c.getConstant(), nullptr, 0)); + case ast::NumericConstant::Type::Uint: + return mk(RamUnsignedFromString(c.getConstant(), nullptr, 0)); + case ast::NumericConstant::Type::Float: + return mk(RamFloatFromString(c.getConstant())); + } + + fatal("unexpected numeric constant type"); +} + +} // namespace souffle::ast2ram diff --git a/src/ast2ram/ValueTranslator.h b/src/ast2ram/ValueTranslator.h index c7a03bea916..9e9e2b628a4 100644 --- a/src/ast2ram/ValueTranslator.h +++ b/src/ast2ram/ValueTranslator.h @@ -10,13 +10,10 @@ * * @file ValueTranslator.h * - * Value translator. - * ***********************************************************************/ #pragma once -#include "ast/NumericConstant.h" #include "ast/UnnamedVariable.h" #include "ast/Variable.h" #include "ast/analysis/Functor.h" @@ -36,7 +33,6 @@ #include "ram/Expression.h" #include "ram/Extend.h" #include "ram/Filter.h" -#include "ram/FloatConstant.h" #include "ram/IO.h" #include "ram/IntrinsicOperator.h" #include "ram/LogRelationTimer.h" @@ -61,11 +57,15 @@ #include "ram/Swap.h" #include "ram/TranslationUnit.h" #include "ram/TupleElement.h" -#include "ram/UndefValue.h" -#include "ram/UnsignedConstant.h" #include "ram/UserDefinedOperator.h" #include "ram/utility/Utils.h" +namespace souffle::ast { +class Variable; +class UnnamedVariable; +class NumericConstant; +} // namespace souffle::ast + namespace souffle::ast2ram { class ValueTranslator : public ast::Visitor> { @@ -73,30 +73,11 @@ class ValueTranslator : public ast::Visitor> { ValueTranslator(AstToRamTranslator& translator, const ValueIndex& index, SymbolTable& symTab) : translator(translator), index(index), symTab(symTab) {} - Own visitVariable(const ast::Variable& var) override { - assert(index.isDefined(var) && "variable not grounded"); - return translator.makeRamTupleElement(index.getDefinitionPoint(var)); - } - - Own visitUnnamedVariable(const ast::UnnamedVariable&) override { - return mk(); - } + Own visitVariable(const ast::Variable& var) override; - Own visitNumericConstant(const ast::NumericConstant& c) override { - assert(c.getType().has_value() && "At this points all constants should have type."); - - switch (*c.getType()) { - case ast::NumericConstant::Type::Int: - return mk(RamSignedFromString(c.getConstant(), nullptr, 0)); - case ast::NumericConstant::Type::Uint: - return mk(RamUnsignedFromString(c.getConstant(), nullptr, 0)); - case ast::NumericConstant::Type::Float: - return mk(RamFloatFromString(c.getConstant())); - } - - fatal("unexpected numeric constant type"); - } + Own visitUnnamedVariable(const ast::UnnamedVariable&) override; + Own visitNumericConstant(const ast::NumericConstant& c); Own visitStringConstant(const ast::StringConstant& c) override { return mk(symTab.lookup(c.getConstant())); }