clang API Documentation

ReachableCode.h
Go to the documentation of this file.
00001 //===- ReachableCode.h -----------------------------------------*- C++ --*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // A flow-sensitive, path-insensitive analysis of unreachable code.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_REACHABLECODE_H
00015 #define LLVM_CLANG_ANALYSIS_ANALYSES_REACHABLECODE_H
00016 
00017 #include "clang/Basic/SourceLocation.h"
00018 
00019 //===----------------------------------------------------------------------===//
00020 // Forward declarations.
00021 //===----------------------------------------------------------------------===//
00022 
00023 namespace llvm {
00024   class BitVector;
00025 }
00026 
00027 namespace clang {
00028   class AnalysisDeclContext;
00029   class CFGBlock;
00030   class Preprocessor;
00031 }
00032 
00033 //===----------------------------------------------------------------------===//
00034 // API.
00035 //===----------------------------------------------------------------------===//
00036 
00037 namespace clang {
00038 namespace reachable_code {
00039 
00040 /// Classifications of unreachable code.
00041 enum UnreachableKind {
00042   UK_Return,
00043   UK_Break,
00044   UK_Loop_Increment,
00045   UK_Other
00046 };
00047 
00048 class Callback {
00049   virtual void anchor();
00050 public:
00051   virtual ~Callback() {}
00052   virtual void HandleUnreachable(UnreachableKind UK,
00053                                  SourceLocation L,
00054                                  SourceRange ConditionVal,
00055                                  SourceRange R1,
00056                                  SourceRange R2) = 0;
00057 };
00058 
00059 /// ScanReachableFromBlock - Mark all blocks reachable from Start.
00060 /// Returns the total number of blocks that were marked reachable.  
00061 unsigned ScanReachableFromBlock(const CFGBlock *Start,
00062                                 llvm::BitVector &Reachable);
00063 
00064 void FindUnreachableCode(AnalysisDeclContext &AC, Preprocessor &PP,
00065                          Callback &CB);
00066 
00067 }} // end namespace clang::reachable_code
00068 
00069 #endif