| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef REDUCE_POINTER_LEVEL_H |
| 12 |
#define REDUCE_POINTER_LEVEL_H |
| 13 |
|
| 14 |
#include <string> |
| 15 |
#include "Transformation.h" |
| 16 |
#include "llvm/ADT/SmallPtrSet.h" |
| 17 |
#include "llvm/ADT/DenseMap.h" |
| 18 |
|
| 19 |
namespace clang { |
| 20 |
class DeclGroupRef; |
| 21 |
class ASTContext; |
| 22 |
class Expr; |
| 23 |
class DeclaratorDecl; |
| 24 |
class RecordDecl; |
| 25 |
class FieldDecl; |
| 26 |
class VarDecl; |
| 27 |
class Type; |
| 28 |
class ArrayType; |
| 29 |
class RecordType; |
| 30 |
class InitListExpr; |
| 31 |
class ArraySubscriptExpr; |
| 32 |
class MemberExpr; |
| 33 |
class UnaryOperator; |
| 34 |
class DeclRefExpr; |
| 35 |
} |
| 36 |
|
| 37 |
class PointerLevelCollectionVisitor; |
| 38 |
class PointerLevelRewriteVisitor; |
| 39 |
|
| 40 |
class ReducePointerLevel : public Transformation { |
| 41 |
friend class PointerLevelCollectionVisitor; |
| 42 |
friend class PointerLevelRewriteVisitor; |
| 43 |
|
| 44 |
public: |
| 45 |
|
| 46 |
ReducePointerLevel(const char *TransName, const char *Desc) |
| 47 |
: Transformation(TransName, Desc), |
| 48 |
CollectionVisitor(NULL), |
| 49 |
RewriteVisitor(NULL), |
| 50 |
MaxIndirectLevel(0), |
| 51 |
TheDecl(NULL), |
| 52 |
TheRecordDecl(NULL) |
| 53 |
{ } |
| 54 |
|
| 55 |
~ReducePointerLevel(void); |
| 56 |
|
| 57 |
private: |
| 58 |
|
| 59 |
typedef llvm::SmallPtrSet<const clang::DeclaratorDecl *, 20> DeclSet; |
| 60 |
|
| 61 |
typedef llvm::SmallPtrSet<const clang::DeclRefExpr *, 20> DeclRefExprSet; |
| 62 |
|
| 63 |
typedef llvm::SmallPtrSet<const clang::MemberExpr *, 20> MemberExprSet; |
| 64 |
|
| 65 |
typedef llvm::DenseMap<int, DeclSet *> LevelToDeclMap; |
| 66 |
|
| 67 |
typedef void (ReducePointerLevel::*InitListHandler)(const clang::Expr *Init, |
| 68 |
std::string &InitStr); |
| 69 |
|
| 70 |
typedef llvm::SmallVector<unsigned int, 10> IndexVector; |
| 71 |
|
| 72 |
virtual void Initialize(clang::ASTContext &context); |
| 73 |
|
| 74 |
virtual void HandleTranslationUnit(clang::ASTContext &Ctx); |
| 75 |
|
| 76 |
void getInitListExprString(const clang::InitListExpr *ILE, |
| 77 |
std::string &InitStr, |
| 78 |
InitListHandler Handler); |
| 79 |
|
| 80 |
const clang::DeclaratorDecl *getRefDecl(const clang::Expr *Exp); |
| 81 |
|
| 82 |
const clang::DeclRefExpr *getDeclRefExpr(const clang::Expr *Exp); |
| 83 |
|
| 84 |
const clang::DeclaratorDecl * |
| 85 |
getCanonicalDeclaratorDecl(const clang::Expr *E); |
| 86 |
|
| 87 |
void addOneDecl(const clang::DeclaratorDecl *DD, int IndirectLevel); |
| 88 |
|
| 89 |
void doAnalysis(void); |
| 90 |
|
| 91 |
void setRecordDecl(void); |
| 92 |
|
| 93 |
void copyInitStr(const clang::Expr *Exp, std::string &InitStr); |
| 94 |
|
| 95 |
void getNewLocalInitStr(const clang::Expr *Init, std::string &InitStr); |
| 96 |
|
| 97 |
void getNewGlobalInitStr(const clang::Expr *Init, |
| 98 |
std::string &InitStr); |
| 99 |
|
| 100 |
const clang::Expr *getFirstInitListElem(const clang::InitListExpr *E); |
| 101 |
|
| 102 |
void rewriteVarDecl(const clang::VarDecl *VD); |
| 103 |
|
| 104 |
void rewriteFieldDecl(const clang::FieldDecl *FD); |
| 105 |
|
| 106 |
void rewriteRecordInit(const clang::RecordDecl *RD, |
| 107 |
const clang::Expr *Init); |
| 108 |
|
| 109 |
void rewriteArrayInit(const clang::RecordDecl *RD, |
| 110 |
const clang::Expr *Init); |
| 111 |
|
| 112 |
void rewriteDerefOp(const clang::UnaryOperator *UO); |
| 113 |
|
| 114 |
void rewriteDeclRefExpr(const clang::DeclRefExpr *DRE); |
| 115 |
|
| 116 |
void replaceArrowWithDot(const clang::Expr *E); |
| 117 |
|
| 118 |
bool isPointerToSelf(const clang::Type *Ty, const clang::DeclaratorDecl *DD); |
| 119 |
|
| 120 |
void checkPrefixAndPostfix(const clang::UnaryOperator *UO); |
| 121 |
|
| 122 |
DeclSet VisitedDecls; |
| 123 |
|
| 124 |
DeclSet ValidDecls; |
| 125 |
|
| 126 |
DeclSet AddrTakenDecls; |
| 127 |
|
| 128 |
DeclRefExprSet VisitedDeclRefExprs; |
| 129 |
|
| 130 |
MemberExprSet VisitedMemberExprs; |
| 131 |
|
| 132 |
LevelToDeclMap AllPtrDecls; |
| 133 |
|
| 134 |
PointerLevelCollectionVisitor *CollectionVisitor; |
| 135 |
|
| 136 |
PointerLevelRewriteVisitor *RewriteVisitor; |
| 137 |
|
| 138 |
int MaxIndirectLevel; |
| 139 |
|
| 140 |
const clang::DeclaratorDecl *TheDecl; |
| 141 |
|
| 142 |
const clang::RecordDecl *TheRecordDecl ; |
| 143 |
|
| 144 |
|
| 145 |
ReducePointerLevel(void); |
| 146 |
|
| 147 |
ReducePointerLevel(const ReducePointerLevel &); |
| 148 |
|
| 149 |
void operator=(const ReducePointerLevel &); |
| 150 |
}; |
| 151 |
|
| 152 |
#endif |