public void addDeferredInvocation(DeferredInvocation di, DFG functionGraph, List <List <Identifier> > sources) { // create invocation node //DFGNode dfgni = new DFGNode(invc); Guid subgraphId = Guid.NewGuid(); //addNode(dfgni); // add the copied graph nodes to this graph foreach (DFGNode dfgn in functionGraph.nodes) { dfgn.subGraphId = subgraphId; addNode(dfgn); } // hook up the return node to the invocation node //functionGraph.returnNode.addEdge(dfgni); //if (functionGraph.returnNode == null) //{ // functionGraph.returnNode //} functionGraph.returnNode.addEdge(di.invocationNode); // hook up actual args to formal args for (int i = 0; i < sources.Count; i++) { List <Identifier> paramSources = sources[i]; foreach (Identifier ident in paramSources) { DFGNode source = _findNode(ident); source.addEdge(functionGraph._formalParams[i]); } } }
public DFGNode addInvocation(Invocation invc) { DFGNode dfgni = new DFGNode(invc); addNode(dfgni); return(dfgni); }
public void visitFunction(Function f) { DFGNode high; DFGNode low; high = _dfg.high; low = _dfg.low; if (_isVerification) { high = DFGNode.generateHigh(); low = DFGNode.generateLow(); } else { high = _dfg.high; low = _dfg.low; } DFGVisitor fv = new DFGVisitor(f.body, f.formalParams, high, low, _componentFunctionGraphs, _deferredInvocations, _currentComponent, _isVerification); Dictionary <Identifier, DFG> functionList = _componentFunctionGraphs[_currentComponent]; // if function has no return, add a ghost return if (fv.dfg.returnNode == null) { fv.dfg.addReturn(); } functionList.Add(f.name.identifier, fv.dfg); }
public DeferredInvocation(Invocation i, DFGNode invNode, DFGVisitor dfgv, Identifier inComp) { visitor = dfgv; invocation = i; invocationNode = invNode; inComponent = inComp; }
public DFG(DFGNode high, DFGNode low) { _initialise(); _high = high; _low = low; //addNode(high); //addNode(low); }
public void addAssign(List <Identifier> sources, Identifier sink) { DFGNode sinkNode = _findNode(sink); foreach (Identifier i in sources) { DFGNode source = _findNode(i); source.addEdge(sinkNode); } }
public DFG() { _initialise(); _high = DFGNode.generateHigh(); addNode(_high); _low = DFGNode.generateLow(); addNode(_low); }
public void visitVariable(Variable d) { DFGNode dfgn = new DFGNode(d); _dfg.addNode(dfgn); if (_capturingFormalParams) { _dfg.addFormalParam(dfgn); } }
public void addReturn(List <Identifier> sources) { _return = new DFGNode(DFGNodeType.Return, "return"); if (sources != null) { foreach (Identifier i in sources) { DFGNode source = _findNode(i); source.addEdge(_return); } } _nodes.Add(_return); }
public DFGVisitor(StatementList functionCode, VarList formalParams, DFGNode high, DFGNode low, Dictionary <Identifier, Dictionary <Identifier, DFG> > componentFunctionGraphs, List <DeferredInvocation> deferredInvocations, Identifier currentComponent, bool isVerification) { _isParent = false; _initialise(functionCode, componentFunctionGraphs, formalParams, high, low, deferredInvocations, currentComponent, isVerification); try { _code.accept(this); } catch (ParseException pe) { _errors.Add(pe); } }
public void addAddition(List <Identifier> sources, Identifier addition) { DFGNode sinkNode = _findNode(addition); if (sinkNode == null) { sinkNode = new DFGNode(DFGNodeType.Addition, addition.name); addNode(sinkNode); } foreach (Identifier i in sources) { DFGNode source = _findNode(i); source.addEdge(sinkNode); } ; }
private List <DFGNode> _bfs(DFGNode root, DFGNode dest) { Queue <DFGNode> q = new Queue <DFGNode>(); List <DFGNode> result = new List <DFGNode>(); List <DFGNode> visited = new List <DFGNode>(); q.Enqueue(root); bool found = false; while (q.Count > 0) { DFGNode current = q.Dequeue(); if (current == null) { continue; } result.Add(current); visited.Add(current); foreach (DFGNode node in current.adjacencyList) { if (!visited.Contains(node) && !q.Contains(node)) { q.Enqueue(node); } } if (dest == current) { found = true; break; } } if (found) { return(result); } else { return(null); } }
private void _replace(DFGNode newNode, DFGNode nodeToReplace) { foreach (DFGNode n in nodeToReplace.adjacencyList) { n.parents.Remove(nodeToReplace); newNode.addEdge(n); } foreach (DFGNode n in nodeToReplace.parents) { n.adjacencyList.Remove(nodeToReplace); n.addEdge(newNode); } nodeToReplace.adjacencyList.Clear(); nodeToReplace.parents.Clear(); nodeToReplace = newNode; }
private DFGNode _findNode(Identifier i) { // find non-security nodes DFGNode dfgn = _nodes.Find(n => n.subGraphId == new Guid() && ((n.variable != null && n.variable.identifier == i) || (n.invocation != null && n.invocation.identifier == i && n.invocation.invocationCount == i.invocationCount) || (n.type == DFGNodeType.Addition && n.label.Equals(i.name)))); // find if security node if (dfgn == null) { if (i.name.Equals(GingerToken.High.ToString())) { dfgn = _high; } else if (i.name.Equals(GingerToken.Low.ToString())) { dfgn = _low; } } return(dfgn); }
private void _initialise(SLNodeCollection code, Dictionary <Identifier, Dictionary <Identifier, DFG> > componentFunctionGraphs, VarList formalParams, DFGNode high, DFGNode low, List <DeferredInvocation> di, Identifier currentComponent, bool isVerification) { _errors = new List <ParseException>(); _addingSources = false; //_buildingExprList = false; _capturingFormalParams = false; _capturingComponent = false; //shouldReplaceNodes = false; //_formalParams = formalParams; _sources = new List <Identifier>(); _code = code; //_dfg = new DFG(high, low); //_dfg = new DFG(); _currentComponent = currentComponent; _isVerification = isVerification; if ((high != null && low != null)) { _dfg = new DFG(high, low); } else { _dfg = new DFG(); } if (di == null) { _deferredInvocations = new List <DeferredInvocation>(); } else { _deferredInvocations = di; } if (componentFunctionGraphs == null) { _componentFunctionGraphs = new Dictionary <Identifier, Dictionary <Identifier, DFG> >(new ImportIdentifierComparer()); } else { _componentFunctionGraphs = componentFunctionGraphs; } if (formalParams != null) { _capturingFormalParams = true; foreach (Variable v in formalParams) { visitVariable(v); } _capturingFormalParams = false; } }
public void replaceLow(DFGNode low) { _replace(low, _low); }
public void replaceHigh(DFGNode high) { _replace(high, _high); }
public void addReturn() { _return = new DFGNode(DFGNodeType.Return, "return"); _nodes.Add(_return); }
//public VerificationVisitor(StatementList functionCode, VarList formalParams, DFGNode high, DFGNode low, Dictionary<Identifier, Dictionary<Identifier, DFG>> componentFunctionGraphs, List<DeferredInvocation> deferredInvocations, Identifier currentComponent) : base(functionCode, formalParams, high, low, componentFunctionGraphs, deferredInvocations, currentComponent) //{ // //try // //{ // // _code.accept(this); // //} // //catch (ParseException pe) // //{ // // _errors.Add(pe); // //} //} public new void visitComponentList(ComponentList cl) { base.visitComponentList(cl); foreach (Component c in cl) { if (c.type == GingerToken.Implementation && c.extends != null) { Identifier implementationIdent = c.variable.identifier; foreach (Component cc in cl) { if (cc.variable.identifier == c.extends) { Identifier contractIdent = cc.variable.identifier; c.accept(this); if (!_componentFunctionGraphs.ContainsKey(contractIdent)) { cc.accept(this); } foreach (DeferredInvocation defInv in _deferredInvocations) { defInv.visitor.visitDeferredInvocation(defInv); } _deferredInvocations.Clear(); //_cleanup(); Dictionary <Identifier, DFG> implementationFunctions = _componentFunctionGraphs[implementationIdent]; Dictionary <Identifier, DFG> contractFunctions = _componentFunctionGraphs[contractIdent]; foreach (KeyValuePair <Identifier, DFG> entry in implementationFunctions) { if (contractFunctions.ContainsKey(entry.Key)) { Dictionary <DFGNode, DFGNode> inOutEdges = new Dictionary <DFGNode, DFGNode>(); DFG implementationGraph = entry.Value; DFG contractGraph = contractFunctions[entry.Key]; // perform closure on graphs implementationGraph.performClosure(); contractGraph.performClosure(); foreach (DFGNode inNode in implementationGraph.ins) { // is there an edge from an in to an out? foreach (DFGNode outNode in implementationGraph.outs) { if (inNode.adjacencyList.Contains(outNode)) { DFGNode contractInNode = null; try { contractInNode = contractGraph.ins.Single(fp => fp.label.Equals(inNode.label)); } catch (InvalidOperationException ioe) { _errors.Add(new ParseException(0, 0, $"Edge {inNode.label} to {outNode.label} in {implementationIdent.name}.{entry.Key.name} does not exist in the contract", ExceptionLevel.ERROR)); } if (contractInNode != null && !contractInNode.adjacencyList.Any(n => n.label.Equals(outNode.label) && (n.type != DFGNodeType.Return || n == contractGraph.returnNode))) { _errors.Add(new ParseException(0, 0, $"Edge {inNode.label} to {outNode.label} in {implementationIdent.name}.{entry.Key.name} does not exist in the contract", ExceptionLevel.ERROR)); } } } } } else { _errors.Add(new ParseException(0, 0, $"{implementationIdent.name}.{entry.Key.name} does not exist in {contractIdent.name}", ExceptionLevel.ERROR)); } } } } } } }
public void addNode(DFGNode n) { _nodes.Add(n); }
private void _addEdge(DFGNode source, DFGNode target) { source.addEdge(target); }
public void addFormalParam(DFGNode formalParam) { _formalParams.Add(formalParam); }