| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef REDUCE_ARRAY_SIZE_H |
| 12 |
#define REDUCE_ARRAY_SIZE_H |
| 13 |
|
| 14 |
#include <string> |
| 15 |
#include <utility> |
| 16 |
#include "llvm/ADT/MapVector.h" |
| 17 |
#include "llvm/ADT/SmallVector.h" |
| 18 |
#include "Transformation.h" |
| 19 |
|
| 20 |
namespace clang { |
| 21 |
class DeclGroupRef; |
| 22 |
class ASTContext; |
| 23 |
class VarDecl; |
| 24 |
class ArraySubscriptExpr; |
| 25 |
class Expr; |
| 26 |
} |
| 27 |
|
| 28 |
class ReduceArraySizeCollectionVisitor; |
| 29 |
|
| 30 |
class ReduceArraySize : public Transformation { |
| 31 |
friend class ReduceArraySizeCollectionVisitor; |
| 32 |
|
| 33 |
public: |
| 34 |
|
| 35 |
ReduceArraySize(const char *TransName, const char *Desc) |
| 36 |
: Transformation(TransName, Desc), |
| 37 |
CollectionVisitor(NULL), |
| 38 |
TheVarDecl(NULL), |
| 39 |
TheDimValue(-1), |
| 40 |
TheDimIdx(0) |
| 41 |
{ } |
| 42 |
|
| 43 |
~ReduceArraySize(void); |
| 44 |
|
| 45 |
private: |
| 46 |
|
| 47 |
typedef llvm::SmallVector<int, 10> DimValueVector; |
| 48 |
|
| 49 |
typedef llvm::MapVector<const clang::VarDecl *, DimValueVector *> |
| 50 |
VarDeclToDimMap; |
| 51 |
|
| 52 |
typedef std::pair<clang::SourceLocation, clang::SourceLocation> |
| 53 |
BracketLocPair; |
| 54 |
|
| 55 |
virtual void Initialize(clang::ASTContext &context); |
| 56 |
|
| 57 |
virtual bool HandleTopLevelDecl(clang::DeclGroupRef D); |
| 58 |
|
| 59 |
virtual void HandleTranslationUnit(clang::ASTContext &Ctx); |
| 60 |
|
| 61 |
bool isIntegerExpr(const clang::Expr *Exp); |
| 62 |
|
| 63 |
void handleOneVar(const clang::VarDecl *VD); |
| 64 |
|
| 65 |
void handleOneASE(const clang::ArraySubscriptExpr *ASE); |
| 66 |
|
| 67 |
void doAnalysis(void); |
| 68 |
|
| 69 |
void rewriteArrayVarDecl(void); |
| 70 |
|
| 71 |
void getBracketLocPair(const clang::VarDecl *VD, unsigned int Dim, |
| 72 |
unsigned int DimIdx, BracketLocPair &LocPair); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
VarDeclToDimMap VarDeclToDim; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
VarDeclToDimMap OrigVarDeclToDim; |
| 82 |
|
| 83 |
ReduceArraySizeCollectionVisitor *CollectionVisitor; |
| 84 |
|
| 85 |
const clang::VarDecl *TheVarDecl; |
| 86 |
|
| 87 |
int TheDimValue; |
| 88 |
|
| 89 |
unsigned TheDimIdx; |
| 90 |
|
| 91 |
|
| 92 |
ReduceArraySize(void); |
| 93 |
|
| 94 |
ReduceArraySize(const ReduceArraySize &); |
| 95 |
|
| 96 |
void operator=(const ReduceArraySize &); |
| 97 |
}; |
| 98 |
|
| 99 |
#endif |