-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
79 changed files
with
2,171 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Souffle - A Datalog Compiler | ||
* Copyright (c) 2023, The Souffle Developers. 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 | ||
*/ | ||
|
||
#include "ast/Lattice.h" | ||
#include "souffle/utility/MiscUtil.h" | ||
#include "souffle/utility/StreamUtil.h" | ||
|
||
#include <utility> | ||
|
||
namespace souffle::ast { | ||
|
||
std::optional<LatticeOperator> latticeOperatorFromString(const std::string& str) { | ||
if (str == "Bottom") return Bottom; | ||
if (str == "Top") return Top; | ||
if (str == "Lub") return Lub; | ||
if (str == "Glb") return Glb; | ||
if (str == "Leq") return Leq; | ||
return std::nullopt; | ||
} | ||
|
||
std::string latticeOperatorToString(const LatticeOperator op) { | ||
switch (op) { | ||
case Bottom: return "Bottom"; | ||
case Top: return "Top"; | ||
case Lub: return "Lub"; | ||
case Glb: return "Glb"; | ||
case Leq: return "Leq"; | ||
default: assert(false && "unknown lattice operator"); | ||
} | ||
return ""; | ||
} | ||
|
||
Lattice::Lattice(QualifiedName name, std::map<LatticeOperator, Own<ast::Argument>> ops, SrcLocation loc) | ||
: Node(std::move(loc)), name(std::move(name)), operators(std::move(ops)) {} | ||
|
||
void Lattice::setQualifiedName(QualifiedName name) { | ||
this->name = std::move(name); | ||
} | ||
|
||
const std::map<LatticeOperator, const ast::Argument*> Lattice::getOperators() const { | ||
std::map<LatticeOperator, const ast::Argument*> ops; | ||
for (const auto& [op, arg] : operators) { | ||
ops.emplace(std::make_pair(op, arg.get())); | ||
} | ||
return ops; | ||
} | ||
|
||
bool Lattice::hasGlb() const { | ||
return operators.count(Glb) > 0; | ||
} | ||
|
||
bool Lattice::hasLub() const { | ||
return operators.count(Lub) > 0; | ||
} | ||
|
||
bool Lattice::hasBottom() const { | ||
return operators.count(Bottom) > 0; | ||
} | ||
|
||
bool Lattice::hasTop() const { | ||
return operators.count(Top) > 0; | ||
} | ||
|
||
const ast::Argument* Lattice::getLub() const { | ||
return operators.at(Lub).get(); | ||
} | ||
|
||
const ast::Argument* Lattice::getGlb() const { | ||
return operators.at(Glb).get(); | ||
} | ||
|
||
const ast::Argument* Lattice::getBottom() const { | ||
return operators.at(Bottom).get(); | ||
} | ||
|
||
const ast::Argument* Lattice::getTop() const { | ||
return operators.at(Top).get(); | ||
} | ||
|
||
void Lattice::print(std::ostream& os) const { | ||
os << ".lattice " << getQualifiedName() << " {\n "; | ||
bool first = true; | ||
for (const auto& [op, arg] : operators) { | ||
if (!first) { | ||
os << ",\n "; | ||
} | ||
os << latticeOperatorToString(op) << " -> " << *arg; | ||
first = false; | ||
} | ||
os << "\n}"; | ||
} | ||
|
||
bool Lattice::equal(const Node& node) const { | ||
const auto& other = asAssert<Lattice>(node); | ||
return getQualifiedName() == other.getQualifiedName() && equal_targets(operators, other.operators); | ||
} | ||
|
||
Lattice* Lattice::cloning() const { | ||
return new Lattice(getQualifiedName(), clone(operators), getSrcLoc()); | ||
} | ||
|
||
} // namespace souffle::ast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Souffle - A Datalog Compiler | ||
* Copyright (c) 2023, The Souffle Developers. 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 Lattice.h | ||
* | ||
* Defines the Lattice class | ||
* | ||
***********************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include "ast/Argument.h" | ||
#include "ast/Node.h" | ||
#include "ast/QualifiedName.h" | ||
#include "parser/SrcLocation.h" | ||
|
||
#include <map> | ||
#include <optional> | ||
|
||
namespace souffle::ast { | ||
|
||
enum LatticeOperator { Bottom = 0, Top, Lub, Glb, Leq }; | ||
|
||
std::optional<LatticeOperator> latticeOperatorFromString(const std::string& str); | ||
|
||
/** | ||
* @class Lattice | ||
* @brief An class to define Lattice attributes for a type | ||
*/ | ||
class Lattice : public Node { | ||
public: | ||
Lattice(QualifiedName name, std::map<LatticeOperator, Own<ast::Argument>> operators, | ||
SrcLocation loc = {}); | ||
|
||
/** Return type name */ | ||
const QualifiedName& getQualifiedName() const { | ||
return name; | ||
} | ||
|
||
/** Set type name */ | ||
void setQualifiedName(QualifiedName name); | ||
|
||
const std::map<LatticeOperator, const ast::Argument*> getOperators() const; | ||
|
||
bool hasGlb() const; | ||
bool hasLub() const; | ||
bool hasBottom() const; | ||
bool hasTop() const; | ||
|
||
const ast::Argument* getLub() const; | ||
const ast::Argument* getGlb() const; | ||
const ast::Argument* getBottom() const; | ||
const ast::Argument* getTop() const; | ||
|
||
protected: | ||
void print(std::ostream& os) const override; | ||
|
||
private: | ||
bool equal(const Node& node) const override; | ||
|
||
Lattice* cloning() const override; | ||
|
||
private: | ||
/** type name */ | ||
QualifiedName name; | ||
|
||
const std::map<LatticeOperator, Own<ast::Argument>> operators; | ||
}; | ||
|
||
} // namespace souffle::ast |
Oops, something went wrong.