| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef UNION_TO_STRUCT_H |
| 12 |
#define UNION_TO_STRUCT_H |
| 13 |
|
| 14 |
#include "llvm/ADT/DenseMap.h" |
| 15 |
#include "llvm/ADT/MapVector.h" |
| 16 |
#include "llvm/ADT/SmallPtrSet.h" |
| 17 |
#include "Transformation.h" |
| 18 |
|
| 19 |
namespace clang { |
| 20 |
class DeclGroupRef; |
| 21 |
class ASTContext; |
| 22 |
class DeclaratorDecl; |
| 23 |
class VarDecl; |
| 24 |
class RecordDecl; |
| 25 |
class DeclStmt; |
| 26 |
class FieldDecl; |
| 27 |
} |
| 28 |
|
| 29 |
class UnionToStructCollectionVisitor; |
| 30 |
|
| 31 |
class UnionToStruct : public Transformation { |
| 32 |
friend class UnionToStructCollectionVisitor; |
| 33 |
|
| 34 |
public: |
| 35 |
|
| 36 |
UnionToStruct(const char *TransName, const char *Desc) |
| 37 |
: Transformation(TransName, Desc), |
| 38 |
CollectionVisitor(NULL), |
| 39 |
TheRecordDecl(NULL), |
| 40 |
TheDeclaratorSet(NULL) |
| 41 |
{ } |
| 42 |
|
| 43 |
~UnionToStruct(void); |
| 44 |
|
| 45 |
private: |
| 46 |
|
| 47 |
typedef llvm::SmallPtrSet<const clang::DeclaratorDecl *, 10> |
| 48 |
DeclaratorDeclSet; |
| 49 |
|
| 50 |
typedef llvm::DenseMap<const clang::VarDecl *, const clang::DeclStmt *> |
| 51 |
VarToDeclStmtMap; |
| 52 |
|
| 53 |
typedef llvm::DenseMap<const clang::VarDecl *, clang::DeclGroupRef> |
| 54 |
VarToDeclGroupMap; |
| 55 |
|
| 56 |
typedef llvm::MapVector<const clang::RecordDecl *, DeclaratorDeclSet *> |
| 57 |
RecordDeclToDeclaratorDeclMap; |
| 58 |
|
| 59 |
virtual void Initialize(clang::ASTContext &context); |
| 60 |
|
| 61 |
virtual bool HandleTopLevelDecl(clang::DeclGroupRef D); |
| 62 |
|
| 63 |
virtual void HandleTranslationUnit(clang::ASTContext &Ctx); |
| 64 |
|
| 65 |
void addOneDeclarator(const clang::DeclaratorDecl *VD, const clang::Type *T); |
| 66 |
|
| 67 |
DeclaratorDeclSet *addOneRecord(const clang::RecordDecl *RD); |
| 68 |
|
| 69 |
void doAnalysis(void); |
| 70 |
|
| 71 |
bool isValidRecordDecl(const clang::RecordDecl *RD); |
| 72 |
|
| 73 |
void rewriteRecordDecls(void); |
| 74 |
|
| 75 |
void rewriteDeclarators(void); |
| 76 |
|
| 77 |
void rewriteOneRecordDecl(const clang::RecordDecl *RD); |
| 78 |
|
| 79 |
void rewriteOneVarDecl(const clang::VarDecl *VD); |
| 80 |
|
| 81 |
void rewriteOneFieldDecl(const clang::FieldDecl *FD); |
| 82 |
|
| 83 |
void rewriteOneFunctionDecl(const clang::FunctionDecl *FD); |
| 84 |
|
| 85 |
void getInitStrWithPointerType(const clang::Expr *E, std::string &Str); |
| 86 |
|
| 87 |
void getInitStrWithNonPointerType(const clang::Expr *E, std::string &Str); |
| 88 |
|
| 89 |
bool isTheFirstDecl(const clang::VarDecl *VD); |
| 90 |
|
| 91 |
VarToDeclStmtMap VarToDeclStmt; |
| 92 |
|
| 93 |
VarToDeclGroupMap VarToDeclGroup; |
| 94 |
|
| 95 |
RecordDeclToDeclaratorDeclMap RecordToDeclarator; |
| 96 |
|
| 97 |
UnionToStructCollectionVisitor *CollectionVisitor; |
| 98 |
|
| 99 |
const clang::RecordDecl *TheRecordDecl; |
| 100 |
|
| 101 |
DeclaratorDeclSet *TheDeclaratorSet; |
| 102 |
|
| 103 |
|
| 104 |
UnionToStruct(void); |
| 105 |
|
| 106 |
UnionToStruct(const UnionToStruct &); |
| 107 |
|
| 108 |
void operator=(const UnionToStruct &); |
| 109 |
}; |
| 110 |
#endif |