2011-07-17 15:40:56 +00: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"
|
2012-12-02 13:20:44 +00:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2011-07-17 15:40:56 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2012-08-15 20:02:54 +00:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2012-12-02 13:20:44 +00:00
|
|
|
#include <list>
|
2011-07-17 15:40:56 +00:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class Sema;
|
|
|
|
class Stmt;
|
|
|
|
|
|
|
|
namespace arcmt {
|
|
|
|
|
|
|
|
class CapturedDiagList {
|
|
|
|
typedef std::list<StoredDiagnostic> ListTy;
|
|
|
|
ListTy List;
|
2018-08-02 17:33:11 +00:00
|
|
|
|
2011-07-17 15:40:56 +00:00
|
|
|
public:
|
|
|
|
void push_back(const StoredDiagnostic &diag) { List.push_back(diag); }
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
|
|
|
|
bool hasDiagnostic(ArrayRef<unsigned> IDs, SourceRange range) const;
|
2011-07-17 15:40:56 +00:00
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
void reportDiagnostics(DiagnosticsEngine &diags) const;
|
2011-07-17 15:40:56 +00:00
|
|
|
|
|
|
|
bool hasErrors() const;
|
2011-10-20 21:14:49 +00:00
|
|
|
|
|
|
|
typedef ListTy::const_iterator iterator;
|
|
|
|
iterator begin() const { return List.begin(); }
|
|
|
|
iterator end() const { return List.end(); }
|
2011-07-17 15:40:56 +00:00
|
|
|
};
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
void writeARCDiagsToPlist(const std::string &outPath,
|
|
|
|
ArrayRef<StoredDiagnostic> diags,
|
|
|
|
SourceManager &SM, const LangOptions &LangOpts);
|
|
|
|
|
2011-07-17 15:40:56 +00:00
|
|
|
class TransformActions {
|
2011-10-20 21:14:49 +00:00
|
|
|
DiagnosticsEngine &Diags;
|
2011-07-17 15:40:56 +00:00
|
|
|
CapturedDiagList &CapturedDiags;
|
|
|
|
void *Impl; // TransformActionsImpl.
|
|
|
|
|
|
|
|
public:
|
2011-10-20 21:14:49 +00:00
|
|
|
TransformActions(DiagnosticsEngine &diag, CapturedDiagList &capturedDiags,
|
2011-07-17 15:40:56 +00:00
|
|
|
ASTContext &ctx, Preprocessor &PP);
|
|
|
|
~TransformActions();
|
|
|
|
|
|
|
|
void startTransaction();
|
|
|
|
bool commitTransaction();
|
|
|
|
void abortTransaction();
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
void insert(SourceLocation loc, StringRef text);
|
|
|
|
void insertAfterToken(SourceLocation loc, StringRef text);
|
2011-07-17 15:40:56 +00:00
|
|
|
void remove(SourceRange range);
|
|
|
|
void removeStmt(Stmt *S);
|
2011-10-20 21:14:49 +00:00
|
|
|
void replace(SourceRange range, StringRef text);
|
2011-07-17 15:40:56 +00:00
|
|
|
void replace(SourceRange range, SourceRange replacementRange);
|
2011-10-20 21:14:49 +00:00
|
|
|
void replaceStmt(Stmt *S, StringRef text);
|
|
|
|
void replaceText(SourceLocation loc, StringRef text,
|
|
|
|
StringRef replacementText);
|
2011-07-17 15:40:56 +00:00
|
|
|
void increaseIndentation(SourceRange range,
|
|
|
|
SourceLocation parentIndent);
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
bool clearDiagnostic(ArrayRef<unsigned> IDs, SourceRange range);
|
2011-07-17 15:40:56 +00:00
|
|
|
bool clearAllDiagnostics(SourceRange range) {
|
2015-01-18 16:23:48 +00:00
|
|
|
return clearDiagnostic(None, range);
|
2011-07-17 15:40:56 +00: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);
|
|
|
|
}
|
|
|
|
|
2014-11-24 09:15:30 +00:00
|
|
|
DiagnosticBuilder report(SourceLocation loc, unsigned diagId,
|
|
|
|
SourceRange range = SourceRange());
|
2011-10-20 21:14:49 +00:00
|
|
|
void reportError(StringRef error, SourceLocation loc,
|
2011-07-17 15:40:56 +00:00
|
|
|
SourceRange range = SourceRange());
|
2012-04-14 14:01:31 +00:00
|
|
|
void reportWarning(StringRef warning, SourceLocation loc,
|
|
|
|
SourceRange range = SourceRange());
|
2011-10-20 21:14:49 +00:00
|
|
|
void reportNote(StringRef note, SourceLocation loc,
|
2011-07-17 15:40:56 +00:00
|
|
|
SourceRange range = SourceRange());
|
|
|
|
|
2014-11-24 09:15:30 +00:00
|
|
|
bool hasReportedErrors() const {
|
|
|
|
return Diags.hasUnrecoverableErrorOccurred();
|
|
|
|
}
|
2011-10-20 21:14:49 +00:00
|
|
|
|
2011-07-17 15:40:56 +00:00
|
|
|
class RewriteReceiver {
|
|
|
|
public:
|
|
|
|
virtual ~RewriteReceiver();
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
virtual void insert(SourceLocation loc, StringRef text) = 0;
|
2011-07-17 15:40:56 +00: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;
|
2012-04-14 14:01:31 +00:00
|
|
|
LangOptions::GCMode OrigGCMode;
|
|
|
|
MigratorOptions MigOptions;
|
2011-07-17 15:40:56 +00:00
|
|
|
Sema &SemaRef;
|
|
|
|
TransformActions &TA;
|
2013-04-08 18:45:10 +00:00
|
|
|
const CapturedDiagList &CapturedDiags;
|
2011-07-17 15:40:56 +00:00
|
|
|
std::vector<SourceLocation> &ARCMTMacroLocs;
|
2013-04-08 18:45:10 +00:00
|
|
|
Optional<bool> EnableCFBridgeFns;
|
2011-07-17 15:40:56 +00:00
|
|
|
|
2012-04-14 14:01:31 +00:00
|
|
|
MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode,
|
|
|
|
Sema &sema, TransformActions &TA,
|
2013-04-08 18:45:10 +00:00
|
|
|
const CapturedDiagList &capturedDiags,
|
2011-07-17 15:40:56 +00:00
|
|
|
std::vector<SourceLocation> &ARCMTMacroLocs)
|
2012-04-14 14:01:31 +00:00
|
|
|
: Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(),
|
2013-04-08 18:45:10 +00:00
|
|
|
SemaRef(sema), TA(TA), CapturedDiags(capturedDiags),
|
2012-04-14 14:01:31 +00:00
|
|
|
ARCMTMacroLocs(ARCMTMacroLocs) { }
|
|
|
|
|
2013-04-08 18:45:10 +00:00
|
|
|
const CapturedDiagList &getDiags() const { return CapturedDiags; }
|
|
|
|
|
2012-04-14 14:01:31 +00:00
|
|
|
bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; }
|
|
|
|
bool noFinalizeRemoval() const { return MigOptions.NoFinalizeRemoval; }
|
|
|
|
void setNoFinalizeRemoval(bool val) {MigOptions.NoFinalizeRemoval = val; }
|
2012-08-15 20:02:54 +00:00
|
|
|
|
|
|
|
bool CFBridgingFunctionsDefined();
|
2011-07-17 15:40:56 +00:00
|
|
|
};
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
static inline StringRef getARCMTMacroName() {
|
2011-07-17 15:40:56 +00:00
|
|
|
return "__IMPL_ARCMT_REMOVED_EXPR__";
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace arcmt
|
|
|
|
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|