From 2a11a5f13aec18eb8c076bc2c3249afc932c921a Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 20 Dec 2007 23:24:55 +0000 Subject: [PATCH] Added initial implementation of "AnalysisVertex", a class to represent a location*state vertex in an intra-procedural, path-sensitive dataflow supergraph. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45272 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Analysis/PathSensitive/AnalysisVertex.h | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 include/clang/Analysis/PathSensitive/AnalysisVertex.h diff --git a/include/clang/Analysis/PathSensitive/AnalysisVertex.h b/include/clang/Analysis/PathSensitive/AnalysisVertex.h new file mode 100644 index 0000000000..b214dec9de --- /dev/null +++ b/include/clang/Analysis/PathSensitive/AnalysisVertex.h @@ -0,0 +1,90 @@ +//=- AnalysisVertex.h - Local, Path-Sensitive Supergraph Vertices -*- C++ -*-=// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois +// Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the template class AnalysisVertex which is used to +// represent a vertex in the location*state supergraph of an intra-procedural, +// path-sensitive dataflow analysis. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_ANALYSIS_PS_ANALYSISVERTEX +#define LLVM_CLANG_ANALYSIS_PS_ANALYSISVERTEX + +#include "llvm/ADT/SmallVector.h" +#include + +namespace clang { + +class ProgramEdge; + +template +class AnalysisVertex { + /// VertexID - A unique ID for the vertex. This number indicates the + /// creation order of vertices, with lower numbers being created first. + /// The first created vertex has VertexID == 0. + const unsigned VertexID; + + /// Location - The program edge representing the location in the function body + /// that this vertex corresponds to. + ProgramEdge Location; + + /// State - The state associated with this vertex. Normally this value + /// is immutable, but we anticipate there will be times when algorithms + /// that directly manipulate the analysis graph will need to change it. + StateTy* State; + + /// Predecessors/Successors - Keep track of the predecessor/successor + /// vertices. + typedef llvm::SmallVector<1> AdjacentVertices; + AdjacentVertices Preds; + AdjacentVertices Succs; + +public: + explicit AnalysisVertex(unsigned ID, const ProgramEdge& loc, StateTy* state) + : VertexID(ID), Location(loc), State(state) {} + + // Accessors. + State* getState() const { return State; } + const ProgramEdge& getLocation() const { return Location; } + unsigned getVertexID() const { return VertexID; } + + + // Iterators over successor and predecessor vertices. + typedef AdjacentVertices::iterator succ_iterator; + typedef AdjacentVertices::const_iterator const_succ_iterator; + + typedef AdjacentVertices::iterator pred_iterator; + typedef AdjacentVertices::const_iterator const_pred_iterator; + + pred_iterator pred_begin() { return Preds.begin(); } + pred_iterator pred_end() { return Preds.end(); } + const_pred_iterator pred_begin() const { return Preds.begin(); } + const_pred_iterator pred_end() const { return Preds.end(); } + + succ_iterator succ_begin() { return Succs.begin(); } + succ_iterator succ_end() { return Succs.end(); } + const_succ_iterator succ_begin() const { return Succs.begin(); } + const_succ_iterator succ_end() const { return Succs.end(); } + + unsigned succ_size() const { return Succs.size(); } + bool succ_empty() const { return Succs.empty(); } + + unsigned pred_size() const { return Preds.size(); } + unsigned pred_empty() const { return Preds.empty(); } + + // Manipulation of successors/predecessors. + void addPredecessor(AnalysisVertex* V) { + Preds.push_back(&V); + V.Succs.push_back(V); + } +}; + +} // end namespace clang + +#endif -- 2.50.1