2011-06-16 07:25:17 +08:00
|
|
|
//===-- Internals.h - Implementation Details---------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H
|
|
|
|
#define LLVM_CLANG_LIB_ARCMIGRATE_INTERNALS_H
|
|
|
|
|
|
|
|
#include "clang/ARCMigrate/ARCMT.h"
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2012-06-01 08:10:47 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2011-06-16 07:25:17 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class Sema;
|
|
|
|
class Stmt;
|
|
|
|
|
|
|
|
namespace arcmt {
|
|
|
|
|
|
|
|
class CapturedDiagList {
|
|
|
|
typedef std::list<StoredDiagnostic> ListTy;
|
|
|
|
ListTy List;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
|
|
|
|
|
2011-07-24 01:14:25 +08:00
|
|
|
bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
|
|
|
|
bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const;
|
2011-06-16 07:25:17 +08:00
|
|
|
|
2011-09-26 07:23:43 +08:00
|
|
|
void reportDiagnostics(DiagnosticsEngine &diags) const;
|
2011-06-18 08:53:41 +08:00
|
|
|
|
|
|
|
bool hasErrors() const;
|
2011-07-20 01:20:03 +08:00
|
|
|
|
|
|
|
typedef ListTy::const_iterator iterator;
|
|
|
|
iterator begin() const { return List.begin(); }
|
|
|
|
iterator end() const { return List.end(); }
|
2011-06-16 07:25:17 +08:00
|
|
|
};
|
|
|
|
|
2011-07-20 01:20:03 +08:00
|
|
|
void writeARCDiagsToPlist(const std::string &outPath,
|
2011-07-24 01:14:25 +08:00
|
|
|
ArrayRef<StoredDiagnostic> diags,
|
2011-07-20 01:20:03 +08:00
|
|
|
SourceManager &SM, const LangOptions &LangOpts);
|
|
|
|
|
2011-06-16 07:25:17 +08:00
|
|
|
class TransformActions {
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diags;
|
2011-06-16 07:25:17 +08:00
|
|
|
CapturedDiagList &CapturedDiags;
|
2011-07-18 15:44:45 +08:00
|
|
|
bool ReportedErrors;
|
2011-06-16 07:25:17 +08:00
|
|
|
void *Impl; // TransformActionsImpl.
|
|
|
|
|
|
|
|
public:
|
2011-09-26 07:23:43 +08:00
|
|
|
TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags,
|
2011-06-16 07:25:17 +08:00
|
|
|
ASTContext &ctx, Preprocessor &PP);
|
|
|
|
~TransformActions();
|
|
|
|
|
|
|
|
void startTransaction();
|
|
|
|
bool commitTransaction();
|
|
|
|
void abortTransaction();
|
|
|
|
|
2011-07-20 14:58:45 +08:00
|
|
|
void insert(SourceLocation loc, StringRef text);
|
|
|
|
void insertAfterToken(SourceLocation loc, StringRef text);
|
2011-06-16 07:25:17 +08:00
|
|
|
void remove(SourceRange range);
|
|
|
|
void removeStmt(Stmt *S);
|
2011-07-20 14:58:45 +08:00
|
|
|
void replace(SourceRange range, StringRef text);
|
2011-06-16 07:25:17 +08:00
|
|
|
void replace(SourceRange range, SourceRange replacementRange);
|
2011-07-20 14:58:45 +08:00
|
|
|
void replaceStmt(Stmt *S, StringRef text);
|
|
|
|
void replaceText(SourceLocation loc, StringRef text,
|
|
|
|
StringRef replacementText);
|
2011-06-16 07:25:17 +08:00
|
|
|
void increaseIndentation(SourceRange range,
|
|
|
|
SourceLocation parentIndent);
|
|
|
|
|
2011-07-24 01:14:25 +08:00
|
|
|
bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
|
2011-06-16 07:25:17 +08:00
|
|
|
bool clearAllDiagnostics(SourceRange range) {
|
2011-07-24 01:14:25 +08:00
|
|
|
return clearDiagnostic(ArrayRef<unsigned>(), range);
|
2011-06-16 07:25:17 +08:00
|
|
|
}
|
|
|
|
bool clearDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
|
|
|
|
unsigned IDs[] = { ID1, ID2 };
|
|
|
|
return clearDiagnostic(IDs, range);
|
|
|
|
}
|
|
|
|
bool clearDiagnostic(unsigned ID1, unsigned ID2, unsigned ID3,
|
|
|
|
SourceRange range) {
|
|
|
|
unsigned IDs[] = { ID1, ID2, ID3 };
|
|
|
|
return clearDiagnostic(IDs, range);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasDiagnostic(unsigned ID, SourceRange range) {
|
|
|
|
return CapturedDiags.hasDiagnostic(ID, range);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasDiagnostic(unsigned ID1, unsigned ID2, SourceRange range) {
|
|
|
|
unsigned IDs[] = { ID1, ID2 };
|
|
|
|
return CapturedDiags.hasDiagnostic(IDs, range);
|
|
|
|
}
|
|
|
|
|
2011-07-20 14:58:45 +08:00
|
|
|
void reportError(StringRef error, SourceLocation loc,
|
2011-06-16 07:25:17 +08:00
|
|
|
SourceRange range = SourceRange());
|
2012-01-25 08:20:29 +08:00
|
|
|
void reportWarning(StringRef warning, SourceLocation loc,
|
|
|
|
SourceRange range = SourceRange());
|
2011-07-20 14:58:45 +08:00
|
|
|
void reportNote(StringRef note, SourceLocation loc,
|
2011-06-16 07:25:17 +08:00
|
|
|
SourceRange range = SourceRange());
|
|
|
|
|
2011-07-18 15:44:45 +08:00
|
|
|
bool hasReportedErrors() const { return ReportedErrors; }
|
|
|
|
|
2011-06-16 07:25:17 +08:00
|
|
|
class RewriteReceiver {
|
|
|
|
public:
|
|
|
|
virtual ~RewriteReceiver();
|
|
|
|
|
2011-07-20 14:58:45 +08:00
|
|
|
virtual void insert(SourceLocation loc, StringRef text) = 0;
|
2011-06-16 07:25:17 +08:00
|
|
|
virtual void remove(CharSourceRange range) = 0;
|
|
|
|
virtual void increaseIndentation(CharSourceRange range,
|
|
|
|
SourceLocation parentIndent) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void applyRewrites(RewriteReceiver &receiver);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Transaction {
|
|
|
|
TransformActions &TA;
|
|
|
|
bool Aborted;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Transaction(TransformActions &TA) : TA(TA), Aborted(false) {
|
|
|
|
TA.startTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
~Transaction() {
|
|
|
|
if (!isAborted())
|
|
|
|
TA.commitTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void abort() {
|
|
|
|
TA.abortTransaction();
|
|
|
|
Aborted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAborted() const { return Aborted; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class MigrationPass {
|
|
|
|
public:
|
|
|
|
ASTContext &Ctx;
|
2011-11-04 23:58:08 +08:00
|
|
|
LangOptions::GCMode OrigGCMode;
|
2012-01-25 08:20:29 +08:00
|
|
|
MigratorOptions MigOptions;
|
2011-06-16 07:25:17 +08:00
|
|
|
Sema &SemaRef;
|
|
|
|
TransformActions &TA;
|
|
|
|
std::vector<SourceLocation> &ARCMTMacroLocs;
|
2012-06-01 08:10:47 +08:00
|
|
|
llvm::Optional<bool> EnableCFBridgeFns;
|
2011-06-16 07:25:17 +08:00
|
|
|
|
2011-11-04 23:58:08 +08:00
|
|
|
MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode,
|
|
|
|
Sema &sema, TransformActions &TA,
|
2011-06-16 07:25:17 +08:00
|
|
|
std::vector<SourceLocation> &ARCMTMacroLocs)
|
2012-01-25 08:20:29 +08:00
|
|
|
: Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(),
|
|
|
|
SemaRef(sema), TA(TA),
|
2011-11-04 23:58:08 +08:00
|
|
|
ARCMTMacroLocs(ARCMTMacroLocs) { }
|
|
|
|
|
|
|
|
bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
|
2012-01-25 08:20:29 +08:00
|
|
|
bool noNSAllocReallocError() const { return MigOptions.NoNSAllocReallocError; }
|
|
|
|
void setNSAllocReallocError(bool val) { MigOptions.NoNSAllocReallocError = val; }
|
2012-01-26 08:08:04 +08:00
|
|
|
bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; }
|
|
|
|
void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; }
|
2012-06-01 08:10:47 +08:00
|
|
|
|
|
|
|
bool CFBridgingFunctionsDefined();
|
2011-06-16 07:25:17 +08:00
|
|
|
};
|
|
|
|
|
2011-07-20 14:58:45 +08:00
|
|
|
static inline StringRef getARCMTMacroName() {
|
2011-06-16 07:25:17 +08:00
|
|
|
return "__IMPL_ARCMT_REMOVED_EXPR__";
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace arcmt
|
|
|
|
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|