| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef EMPTY_STRUCT_TO_INT_H |
| 12 |
#define EMPTY_STRUCT_TO_INT_H |
| 13 |
|
| 14 |
#include "llvm/ADT/SetVector.h" |
| 15 |
#include "llvm/ADT/SmallPtrSet.h" |
| 16 |
#include "Transformation.h" |
| 17 |
|
| 18 |
namespace clang { |
| 19 |
class DeclGroupRef; |
| 20 |
class ASTContext; |
| 21 |
class RecordDecl; |
| 22 |
class FieldDecl; |
| 23 |
} |
| 24 |
|
| 25 |
class EmptyStructToIntASTVisitor; |
| 26 |
class EmptyStructToIntRewriteVisitor; |
| 27 |
|
| 28 |
class EmptyStructToInt : public Transformation { |
| 29 |
friend class EmptyStructToIntASTVisitor; |
| 30 |
friend class EmptyStructToIntRewriteVisitor; |
| 31 |
|
| 32 |
public: |
| 33 |
|
| 34 |
EmptyStructToInt(const char *TransName, const char *Desc) |
| 35 |
: Transformation(TransName, Desc), |
| 36 |
CollectionVisitor(NULL), |
| 37 |
RewriteVisitor(NULL), |
| 38 |
TheRecordDecl(NULL) |
| 39 |
{ } |
| 40 |
|
| 41 |
~EmptyStructToInt(void); |
| 42 |
|
| 43 |
private: |
| 44 |
|
| 45 |
typedef llvm::DenseMap<const clang::RecordDecl *, IndexVector *> |
| 46 |
RecordDeclToFieldIdxVectorMap; |
| 47 |
|
| 48 |
typedef llvm::SetVector<const clang::RecordDecl *> RecordDeclSet; |
| 49 |
|
| 50 |
typedef llvm::SmallPtrSet<const clang::CXXRecordDecl *, 20> CXXRecordDeclSet; |
| 51 |
|
| 52 |
typedef llvm::SmallPtrSet<void *, 20> LocPtrSet; |
| 53 |
|
| 54 |
virtual void Initialize(clang::ASTContext &context); |
| 55 |
|
| 56 |
virtual void HandleTranslationUnit(clang::ASTContext &Ctx); |
| 57 |
|
| 58 |
void handleOneRecordDecl(const clang::RecordDecl *RD, |
| 59 |
const clang::RecordDecl *BaseRD, |
| 60 |
const clang::FieldDecl *FD, |
| 61 |
unsigned int Idx); |
| 62 |
|
| 63 |
void handleOneVarDecl(const clang::VarDecl *VD); |
| 64 |
|
| 65 |
bool isValidRecordDecl(const clang::RecordDecl *RD); |
| 66 |
|
| 67 |
bool pointToSelf(const clang::FieldDecl *FD); |
| 68 |
|
| 69 |
void removeRecordDecls(void); |
| 70 |
|
| 71 |
void doAnalysis(void); |
| 72 |
|
| 73 |
const clang::RecordDecl *getBaseRecordDef(const clang::Type *Ty); |
| 74 |
|
| 75 |
void getInitExprs(const clang::Type *Ty, |
| 76 |
const clang::Expr *E, |
| 77 |
const IndexVector *IdxVec, |
| 78 |
ExprVector &InitExprs); |
| 79 |
|
| 80 |
const clang::FieldDecl *getFieldDeclByIdx(const clang::RecordDecl *RD, |
| 81 |
unsigned int Idx); |
| 82 |
|
| 83 |
bool isSourceRangeWithinRecordDecl(clang::SourceRange Range, |
| 84 |
const clang::RecordDecl *RD); |
| 85 |
RecordDeclToFieldIdxVectorMap RecordDeclToField; |
| 86 |
|
| 87 |
RecordDeclSet VisitedRecordDecls; |
| 88 |
|
| 89 |
CXXRecordDeclSet BaseClassDecls; |
| 90 |
|
| 91 |
LocPtrSet VisitedLocs; |
| 92 |
|
| 93 |
EmptyStructToIntASTVisitor *CollectionVisitor; |
| 94 |
|
| 95 |
EmptyStructToIntRewriteVisitor *RewriteVisitor; |
| 96 |
|
| 97 |
const clang::RecordDecl *TheRecordDecl; |
| 98 |
|
| 99 |
|
| 100 |
EmptyStructToInt(void); |
| 101 |
|
| 102 |
EmptyStructToInt(const EmptyStructToInt &); |
| 103 |
|
| 104 |
void operator=(const EmptyStructToInt &); |
| 105 |
}; |
| 106 |
|
| 107 |
#endif |
| 108 |
|