// Souffle - A Datalog Compiler
// Copyright (c) 2016, 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


.comp CallGraph {
    .decl CallGraphEdge(caller: number, callee: number)
.output CallGraphEdge()
    .decl Node(n: number)
    Node(1).
    Node(n + 1) :- Node(n), n < 10.
}

.comp CHACallGraph : CallGraph {
    CallGraphEdge(x, y + 1) :- Node(x), Node(y+1), x = y.
    CallGraphEdge(x + 1, y) :- Node(x+1), Node(y), x = y, x < 5.
}

.comp CICallGraph : CallGraph {
    CallGraphEdge(1,4).
}

.comp Main<CallGraphFlavour> {
    .init cg = CallGraphFlavour

    .decl NoWayBack(x: number, y: number)
.output NoWayBack()
    NoWayBack(x, y) :-
        cg.Node(x), cg.Node(y),
        cg.CallGraphEdge(x, y), !cg.CallGraphEdge(y, x).
}

.init cha_main = Main<CHACallGraph>
.init ci_main = Main<CICallGraph>
