clang API Documentation
00001 //===-- Internals.h - Implementation Details---------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H 00011 #define LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H 00012 00013 #include "clang/ARCMigrate/ARCMT.h" 00014 #include "clang/Basic/Diagnostic.h" 00015 #include "llvm/ADT/ArrayRef.h" 00016 #include "llvm/ADT/Optional.h" 00017 #include <list> 00018 00019 namespace clang { 00020 class Sema; 00021 class Stmt; 00022 00023 namespace arcmt { 00024 00025 class CapturedDiagList { 00026 typedef std::list<StoredDiagnostic> ListTy; 00027 ListTy List; 00028 00029 public: 00030 void push_back(const StoredDiagnostic &diag) { List.push_back(diag); } 00031 00032 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range); 00033 bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const; 00034 00035 void reportDiagnostics(DiagnosticsEngine &diags) const; 00036 00037 bool hasErrors() const; 00038 00039 typedef ListTy::const_iterator iterator; 00040 iterator begin() const { return List.begin(); } 00041 iterator end() const { return List.end(); } 00042 }; 00043 00044 void writeARCDiagsToPlist(const std::string &outPath, 00045 ArrayRef<StoredDiagnostic> diags, 00046 SourceManager &SM, const LangOptions &LangOpts); 00047 00048 class TransformActions { 00049 DiagnosticsEngine &Diags; 00050 CapturedDiagList &CapturedDiags; 00051 void *Impl; // TransformActionsImpl. 00052 00053 public: 00054 TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags, 00055 ASTContext &ctx, Preprocessor &PP); 00056 ~TransformActions(); 00057 00058 void startTransaction(); 00059 bool commitTransaction(); 00060 void abortTransaction(); 00061 00062 void insert(SourceLocation loc, StringRef text); 00063 void insertAfterToken(SourceLocation loc, StringRef text); 00064 void remove(SourceRange range); 00065 void removeStmt(Stmt *S); 00066 void replace(SourceRange range, StringRef text); 00067 void replace(SourceRange range, SourceRange replacementRange); 00068 void replaceStmt(Stmt *S, StringRef text); 00069 void replaceText(SourceLocation loc, StringRef text, 00070 StringRef replacementText); 00071 void increaseIndentation(SourceRange range, 00072 SourceLocation parentIndent); 00073 00074 bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range); 00075 bool clearAllDiagnostics(SourceRange range) { 00076 return clearDiagnostic(None, range); 00077 } 00078 bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) { 00079 unsigned IDs[] = { ID1, ID2 }; 00080 return clearDiagnostic(IDs, range); 00081 } 00082 bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3, 00083 SourceRange range) { 00084 unsigned IDs[] = { ID1, ID2, ID3 }; 00085 return clearDiagnostic(IDs, range); 00086 } 00087 00088 bool hasDiagnostic(unsigned ID, SourceRange range) { 00089 return CapturedDiags.hasDiagnostic(ID, range); 00090 } 00091 00092 bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) { 00093 unsigned IDs[] = { ID1, ID2 }; 00094 return CapturedDiags.hasDiagnostic(IDs, range); 00095 } 00096 00097 DiagnosticBuilder report(SourceLocation loc, unsigned diagId, 00098 SourceRange range = SourceRange()); 00099 void reportError(StringRef error, SourceLocation loc, 00100 SourceRange range = SourceRange()); 00101 void reportWarning(StringRef warning, SourceLocation loc, 00102 SourceRange range = SourceRange()); 00103 void reportNote(StringRef note, SourceLocation loc, 00104 SourceRange range = SourceRange()); 00105 00106 bool hasReportedErrors() const { 00107 return Diags.hasUnrecoverableErrorOccurred(); 00108 } 00109 00110 class RewriteReceiver { 00111 public: 00112 virtual ~RewriteReceiver(); 00113 00114 virtual void insert(SourceLocation loc, StringRef text) = 0; 00115 virtual void remove(CharSourceRange range) = 0; 00116 virtual void increaseIndentation(CharSourceRange range, 00117 SourceLocation parentIndent) = 0; 00118 }; 00119 00120 void applyRewrites(RewriteReceiver &receiver); 00121 }; 00122 00123 class Transaction { 00124 TransformActions &TA; 00125 bool Aborted; 00126 00127 public: 00128 Transaction(TransformActions &TA) : TA(TA), Aborted(false) { 00129 TA.startTransaction(); 00130 } 00131 00132 ~Transaction() { 00133 if (!isAborted()) 00134 TA.commitTransaction(); 00135 } 00136 00137 void abort() { 00138 TA.abortTransaction(); 00139 Aborted = true; 00140 } 00141 00142 bool isAborted() const { return Aborted; } 00143 }; 00144 00145 class MigrationPass { 00146 public: 00147 ASTContext &Ctx; 00148 LangOptions::GCMode OrigGCMode; 00149 MigratorOptions MigOptions; 00150 Sema &SemaRef; 00151 TransformActions &TA; 00152 const CapturedDiagList &CapturedDiags; 00153 std::vector<SourceLocation> &ARCMTMacroLocs; 00154 Optional<bool> EnableCFBridgeFns; 00155 00156 MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode, 00157 Sema &sema, TransformActions &TA, 00158 const CapturedDiagList &capturedDiags, 00159 std::vector<SourceLocation> &ARCMTMacroLocs) 00160 : Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(), 00161 SemaRef(sema), TA(TA), CapturedDiags(capturedDiags), 00162 ARCMTMacroLocs(ARCMTMacroLocs) { } 00163 00164 const CapturedDiagList &getDiags() const { return CapturedDiags; } 00165 00166 bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; } 00167 bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; } 00168 void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; } 00169 00170 bool CFBridgingFunctionsDefined(); 00171 }; 00172 00173 static inline StringRef getARCMTMacroName() { 00174 return "__IMPL_ARCMT_REMOVED_EXPR__"; 00175 } 00176 00177 } // end namespace arcmt 00178 00179 } // end namespace clang 00180 00181 #endif