This machine mirrors various open-source projects.
20 Gbit/s uplink.
If there are any issues or you want another project mirrored, please contact
mirror-service -=AT=- netcologne DOT de !
00001 //===-- DeclRewriter.h ---------------------------------------- -*- C++ -*-===// 00002 // 00003 // This file is distributed under the MIT license. See LICENSE.txt for details. 00004 // 00005 // Copyright (C) 2009-2010, Stephen Wilson 00006 // 00007 //===----------------------------------------------------------------------===// 00008 00009 //===----------------------------------------------------------------------===// 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef COMMA_AST_DECLREWRITER_HDR_GUARD 00017 #define COMMA_AST_DECLREWRITER_HDR_GUARD 00018 00019 #include "comma/ast/AstRewriter.h" 00020 00021 #include "llvm/ADT/DenseMap.h" 00022 00023 namespace comma { 00024 00025 class DeclRewriter : public AstRewriter { 00026 00027 public: 00028 00034 DeclRewriter(AstResource &resource, 00035 DeclRegion *context, DeclRegion *origin) 00036 : AstRewriter(resource), context(context), origin(origin) { } 00037 00039 DeclRewriter(const AstRewriter &rewrites, 00040 DeclRegion *context, DeclRegion *origin) 00041 : AstRewriter(rewrites), context(context), origin(origin) { } 00042 00047 void setContext(DeclRegion *context) { 00048 assert(context->getParent() == this->context); 00049 this->context = context; 00050 } 00051 00056 void setOrigin(DeclRegion *origin) { 00057 assert(origin->getParent() == this->origin); 00058 this->origin = origin; 00059 } 00060 00062 00063 const DeclRegion *getContext() const { return context; } 00064 DeclRegion *getContext() { return context; } 00066 00068 00069 const DeclRegion *getOrigin() const { return origin; } 00070 DeclRegion *getOrigin() { return origin; } 00072 00079 00080 TypeDecl *rewriteTypeDecl(TypeDecl *tdecl); 00081 00082 FunctionDecl *rewriteFunctionDecl(FunctionDecl *fdecl); 00083 00084 ProcedureDecl *rewriteProcedureDecl(ProcedureDecl *pdecl); 00085 00086 EnumerationDecl *rewriteEnumerationDecl(EnumerationDecl *edecl); 00087 00088 ArrayDecl *rewriteArrayDecl(ArrayDecl *adecl); 00089 00090 IntegerDecl *rewriteIntegerDecl(IntegerDecl *idecl); 00091 00092 RecordDecl *rewriteRecordDecl(RecordDecl *rdecl); 00093 00094 IncompleteTypeDecl *rewriteIncompleteTypeDecl(IncompleteTypeDecl *ITD); 00095 00096 AccessDecl *rewriteAccessDecl(AccessDecl *access); 00097 00098 CarrierDecl *rewriteCarrierDecl(CarrierDecl *carrier); 00100 00102 Decl *rewriteDecl(Decl *decl); 00103 00104 private: 00105 DeclRegion *context; 00106 DeclRegion *origin; 00107 00110 typedef llvm::DenseMap<Decl*, Decl*> DeclMap; 00111 DeclMap declRewrites; 00112 00115 Decl *findRewrite(Decl *source) const { return declRewrites.lookup(source); } 00116 00118 bool hasRewrite(Decl *source) const { return findRewrite(source) != 0; } 00119 00122 void addDeclRewrite(Decl *source, Decl *target) { 00123 assert(!hasRewrite(source) && "Cannot override decl rewrite rules!"); 00124 declRewrites[source] = target; 00125 } 00126 00129 void mirrorRegion(DeclRegion *source, DeclRegion *target); 00130 00131 Type *rewriteType(Type *type); 00132 AccessType *rewriteAccessType(AccessType *type); 00133 RecordType *rewriteRecordType(RecordType *type); 00134 ArrayType *rewriteArrayType(ArrayType *type); 00135 IncompleteType *rewriteIncompleteType(IncompleteType *type); 00136 00137 Expr *rewriteExpr(Expr *expr); 00138 00139 IntegerLiteral *rewriteIntegerLiteral(IntegerLiteral *lit); 00140 FunctionCallExpr *rewriteFunctionCall(FunctionCallExpr *call); 00141 AttribExpr *rewriteAttrib(AttribExpr *attrib); 00142 ConversionExpr *rewriteConversion(ConversionExpr *conv); 00143 }; 00144 00145 } // end comma namespace. 00146 00147 #endif