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