Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ namespace psr {

template <typename N, typename D> class DefaultSeeds {
public:
static std::map<N, std::set<D>> make(std::vector<N> node, D zeroNode) {
std::map<N, std::set<D>> res;
for (N n : node) {
res.insert(n, std::set<D>{zeroNode});
static std::map<N, std::set<D>> make(std::vector<N> Nodes, D ZeroNode) {
std::map<N, std::set<D>> Result;
for (N Node : Nodes) {
Result.insert(std::move(Node), {ZeroNode});
}
return res;
return Result;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace psr {
class EdgeFact {
public:
virtual ~EdgeFact() = default;
virtual void print(std::ostream &os) const = 0;
virtual void print(std::ostream &OS) const = 0;
};

static inline std::ostream &operator<<(std::ostream &OS, const EdgeFact &E) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class EdgeFunctionComposer

private:
// For debug purpose only
const unsigned EFComposer_Id;
static inline unsigned CurrEFComposer_Id = 0;
const unsigned EFComposerId;
static inline unsigned CurrEFComposerId = 0; // NOLINT
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the issue here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable 'CurrEfComposerId' is non-const and globally accessible, consider making it constclang-tidy(cppcoreguidelines-avoid-non-const-global-variables)


protected:
/// First edge function
Expand All @@ -49,17 +49,17 @@ class EdgeFunctionComposer
EdgeFunctionPtrType G;

public:
EdgeFunctionComposer(EdgeFunctionPtrType F, EdgeFunctionPtrType G)
: EFComposer_Id(++CurrEFComposer_Id), F(F), G(G) {}
EdgeFunctionComposer(EdgeFunctionPtrType &F, EdgeFunctionPtrType &G)
: EFComposerId(++CurrEFComposerId), F(F), G(G) {}

~EdgeFunctionComposer() override = default;

/**
* Target value computation is implemented as
* G(F(source))
*/
L computeTarget(L source) override {
return G->computeTarget(F->computeTarget(source));
L computeTarget(L Source) override {
return G->computeTarget(F->computeTarget(Source));
}

/**
Expand All @@ -69,29 +69,30 @@ class EdgeFunctionComposer
* However, it is advised to immediately reduce the resulting edge function
* by providing an own implementation of this function.
*/
EdgeFunctionPtrType composeWith(EdgeFunctionPtrType secondFunction) override {
if (auto *EI = dynamic_cast<EdgeIdentity<L> *>(secondFunction.get())) {
EdgeFunctionPtrType composeWith(EdgeFunctionPtrType SecondFunction) override {
if (auto *EI = dynamic_cast<EdgeIdentity<L> *>(SecondFunction.get())) {
return this->shared_from_this();
}
if (auto *AB = dynamic_cast<AllBottom<L> *>(secondFunction.get())) {
if (auto *AB = dynamic_cast<AllBottom<L> *>(SecondFunction.get())) {
return this->shared_from_this();
}
return F->composeWith(G->composeWith(secondFunction));
return F->composeWith(G->composeWith(SecondFunction));
}

// virtual EdgeFunctionPtrType
// joinWith(EdgeFunctionPtrType otherFunction) = 0;

bool equal_to(EdgeFunctionPtrType other) const override {
if (auto EFC = dynamic_cast<EdgeFunctionComposer<L> *>(other.get())) {
bool equal_to // NOLINT - would break too many client analyses
(EdgeFunctionPtrType Other) const override {
if (auto EFC = dynamic_cast<EdgeFunctionComposer<L> *>(Other.get())) {
return F->equal_to(EFC->F) && G->equal_to(EFC->G);
}
return false;
}

void print(std::ostream &OS, bool isForDebug = false) const override {
void print(std::ostream &OS, bool /*IsForDebug = false*/) const override {
OS << "COMP[ " << F.get()->str() << " , " << G.get()->str()
<< " ] (EF:" << EFComposer_Id << ')';
<< " ] (EF:" << EFComposerId << ')';
}
};

Expand Down
105 changes: 55 additions & 50 deletions include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ template <typename L> class EdgeFunction {
// function is used to extend an edge function in order to construct so-called
// jump functions that describe the effects of everlonger sequences of code.
//
virtual EdgeFunctionPtrType
composeWith(EdgeFunctionPtrType secondFunction) = 0;
[[nodiscard]] virtual EdgeFunctionPtrType
composeWith(EdgeFunctionPtrType SecondFunction) = 0;

//
// This function describes the join of the two edge functions this and
Expand All @@ -80,7 +80,8 @@ template <typename L> class EdgeFunction {

virtual bool equal_to(EdgeFunctionPtrType OtherFunction) const = 0;

virtual void print(std::ostream &OS, bool IsForDebug = false) const {
virtual void print(std::ostream &OS,
[[maybe_unused]] bool IsForDebug = false) const {
OS << "EdgeFunction";
}

Expand Down Expand Up @@ -111,31 +112,34 @@ class AllTop : public EdgeFunction<L>,
using typename EdgeFunction<L>::EdgeFunctionPtrType;

private:
const L topElement;
const L TopElement;

public:
AllTop(L topElement) : topElement(topElement) {}
AllTop(const L TopElement) : TopElement(std::move(TopElement)) {}

~AllTop() override = default;

L computeTarget(L source) override { return topElement; }
L computeTarget(L /*Source*/) override { return TopElement; }

EdgeFunctionPtrType composeWith(EdgeFunctionPtrType secondFunction) override {
EdgeFunctionPtrType
composeWith(EdgeFunctionPtrType /*SecondFunction*/) override {
return this->shared_from_this();
}

EdgeFunctionPtrType joinWith(EdgeFunctionPtrType otherFunction) override {
return otherFunction;
EdgeFunctionPtrType joinWith(EdgeFunctionPtrType OtherFunction) override {
return OtherFunction;
}

bool equal_to(EdgeFunctionPtrType other) const override {
if (auto *alltop = dynamic_cast<AllTop<L> *>(other.get())) {
return (alltop->topElement == topElement);
[[nodiscard]] bool equal_to // NOLINT - would break too many client analyses
(EdgeFunctionPtrType Other) const override {
if (auto *Alltop = dynamic_cast<AllTop<L> *>(Other.get())) {
return (Alltop->TopElement == TopElement);
}
return false;
}

void print(std::ostream &OS, bool isForDebug = false) const override {
void print(std::ostream &OS,
[[maybe_unused]] bool IsForDebug = false) const override {
OS << "AllTop";
}
};
Expand All @@ -149,47 +153,48 @@ class AllBottom : public EdgeFunction<L>,
using typename EdgeFunction<L>::EdgeFunctionPtrType;

private:
const L bottomElement;
const L BottomElement;

public:
AllBottom(L bottomElement) : bottomElement(bottomElement) {}
AllBottom(const L BottomElement) : BottomElement(std::move(BottomElement)) {}

~AllBottom() override = default;

L computeTarget(L source) override { return bottomElement; }
L computeTarget(L /*Source*/) override { return BottomElement; }

EdgeFunctionPtrType composeWith(EdgeFunctionPtrType secondFunction) override {
if (auto *ab = dynamic_cast<AllBottom<L> *>(secondFunction.get())) {
EdgeFunctionPtrType composeWith(EdgeFunctionPtrType SecondFunction) override {
if (auto *AB = dynamic_cast<AllBottom<L> *>(SecondFunction.get())) {
return this->shared_from_this();
}
if (auto *ei = dynamic_cast<EdgeIdentity<L> *>(secondFunction.get())) {
if (auto *EI = dynamic_cast<EdgeIdentity<L> *>(SecondFunction.get())) {
return this->shared_from_this();
}
return secondFunction->composeWith(this->shared_from_this());
return SecondFunction->composeWith(this->shared_from_this());
}

EdgeFunctionPtrType joinWith(EdgeFunctionPtrType otherFunction) override {
if (otherFunction.get() == this ||
otherFunction->equal_to(this->shared_from_this())) {
EdgeFunctionPtrType joinWith(EdgeFunctionPtrType OtherFunction) override {
if (OtherFunction.get() == this ||
OtherFunction->equal_to(this->shared_from_this())) {
return this->shared_from_this();
}
if (auto *alltop = dynamic_cast<AllTop<L> *>(otherFunction.get())) {
if (auto *Alltop = dynamic_cast<AllTop<L> *>(OtherFunction.get())) {
return this->shared_from_this();
}
if (auto *ei = dynamic_cast<EdgeIdentity<L> *>(otherFunction.get())) {
if (auto *EI = dynamic_cast<EdgeIdentity<L> *>(OtherFunction.get())) {
return this->shared_from_this();
}
return this->shared_from_this();
}

bool equal_to(EdgeFunctionPtrType other) const override {
if (auto *allbottom = dynamic_cast<AllBottom<L> *>(other.get())) {
return (allbottom->bottomElement == bottomElement);
[[nodiscard]] bool equal_to // NOLINT - would break too many client analyses
(EdgeFunctionPtrType Other) const override {
if (auto *AB = dynamic_cast<AllBottom<L> *>(Other.get())) {
return (AB->BottomElement == BottomElement);
}
return false;
}

void print(std::ostream &OS, bool isForDebug = false) const override {
void print(std::ostream &OS, bool /*IsForDebug = false*/) const override {
OS << "AllBottom";
}
};
Expand All @@ -204,44 +209,45 @@ class EdgeIdentity : public EdgeFunction<L>,
EdgeIdentity() = default;

public:
EdgeIdentity(const EdgeIdentity &ei) = delete;
EdgeIdentity(const EdgeIdentity &EI) = delete;

EdgeIdentity &operator=(const EdgeIdentity &ei) = delete;
EdgeIdentity &operator=(const EdgeIdentity &EI) = delete;

~EdgeIdentity() override = default;

L computeTarget(L source) override { return source; }
L computeTarget(L Source) override { return Source; }

EdgeFunctionPtrType composeWith(EdgeFunctionPtrType secondFunction) override {
return secondFunction;
EdgeFunctionPtrType composeWith(EdgeFunctionPtrType SecondFunction) override {
return SecondFunction;
}

EdgeFunctionPtrType joinWith(EdgeFunctionPtrType otherFunction) override {
if ((otherFunction.get() == this) ||
otherFunction->equal_to(this->shared_from_this())) {
EdgeFunctionPtrType joinWith(EdgeFunctionPtrType OtherFunction) override {
if ((OtherFunction.get() == this) ||
OtherFunction->equal_to(this->shared_from_this())) {
return this->shared_from_this();
}
if (auto *ab = dynamic_cast<AllBottom<L> *>(otherFunction.get())) {
return otherFunction;
if (auto *AB = dynamic_cast<AllBottom<L> *>(OtherFunction.get())) {
return OtherFunction;
}
if (auto *at = dynamic_cast<AllTop<L> *>(otherFunction.get())) {
if (auto *AT = dynamic_cast<AllTop<L> *>(OtherFunction.get())) {
return this->shared_from_this();
}
// do not know how to join; hence ask other function to decide on this
return otherFunction->joinWith(this->shared_from_this());
return OtherFunction->joinWith(this->shared_from_this());
}

bool equal_to(EdgeFunctionPtrType other) const override {
return this == other.get();
[[nodiscard]] bool equal_to // NOLINT - would break too many client analyses
(EdgeFunctionPtrType Other) const override {
return this == Other.get();
}

static EdgeFunctionPtrType getInstance() {
// implement singleton C++11 thread-safe (see Scott Meyers)
static EdgeFunctionPtrType instance(new EdgeIdentity<L>());
return instance;
static EdgeFunctionPtrType Instance(new EdgeIdentity<L>());
return Instance;
}

void print(std::ostream &OS, bool isForDebug = false) const override {
void print(std::ostream &OS, bool /*IsForDebug = false*/) const override {
OS << "EdgeIdentity";
}
};
Expand Down Expand Up @@ -520,11 +526,10 @@ class EdgeFunctionSingletonFactory {
auto SearchVal = Storage.find(K);
if (SearchVal != Storage.end() && !SearchVal->second.expired()) {
return SearchVal->second.lock();
} else {
auto NewEdgeFunc = std::make_shared<EdgeFunctionType>(K);
Storage[K] = NewEdgeFunc;
return NewEdgeFunc;
}
auto NewEdgeFunc = std::make_shared<EdgeFunctionType>(K);
Storage[K] = NewEdgeFunc;
return NewEdgeFunc;
}

// Initialize a cleaner thread to automatically remove unused/expired
Expand Down
Loading