1//== PseudoConstantAnalysis.h - Find Pseudo-constants in the AST -*- C++ -*-==// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file tracks the usage of variables in a Decl body to see if they are 11// never written to, implying that they constant. This is useful in static 12// analysis to see if a developer might have intended a variable to be const. 13// 14//===----------------------------------------------------------------------===// 15 16#ifndef LLVM_CLANG_ANALYSIS_PSEUDOCONSTANTANALYSIS 17#define LLVM_CLANG_ANALYSIS_PSEUDOCONSTANTANALYSIS 18 19#include "clang/AST/Stmt.h" 20 21namespace clang { 22 23class PseudoConstantAnalysis { 24public: 25 PseudoConstantAnalysis(const Stmt *DeclBody); 26 ~PseudoConstantAnalysis(); 27 28 bool isPseudoConstant(const VarDecl *VD); 29 bool wasReferenced(const VarDecl *VD); 30 31private: 32 void RunAnalysis(); 33 inline static const Decl *getDecl(const Expr *E); 34 35 // for storing the result of analyzed ValueDecls 36 void *NonConstantsImpl; 37 void *UsedVarsImpl; 38 39 const Stmt *DeclBody; 40 bool Analyzed; 41}; 42 43} 44 45#endif 46