|
@@ -13,6 +13,7 @@
|
|
#include "clang/Sema/Sema.h"
|
|
#include "clang/Sema/Sema.h"
|
|
#include "clang/Sema/SemaDiagnostic.h"
|
|
#include "clang/Sema/SemaDiagnostic.h"
|
|
#include "clang/Tooling/Tooling.h"
|
|
#include "clang/Tooling/Tooling.h"
|
|
|
|
+#include "llvm/Testing/Support/Annotations.h"
|
|
#include "gmock/gmock.h"
|
|
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
#include "gtest/gtest.h"
|
|
#include <cstddef>
|
|
#include <cstddef>
|
|
@@ -107,41 +108,18 @@ CompletionContext runCompletion(StringRef Code, size_t Offset) {
|
|
return ResultCtx;
|
|
return ResultCtx;
|
|
}
|
|
}
|
|
|
|
|
|
-struct ParsedAnnotations {
|
|
|
|
- std::vector<size_t> Points;
|
|
|
|
- std::string Code;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-ParsedAnnotations parseAnnotations(StringRef AnnotatedCode) {
|
|
|
|
- ParsedAnnotations R;
|
|
|
|
- while (!AnnotatedCode.empty()) {
|
|
|
|
- size_t NextPoint = AnnotatedCode.find('^');
|
|
|
|
- if (NextPoint == StringRef::npos) {
|
|
|
|
- R.Code += AnnotatedCode;
|
|
|
|
- AnnotatedCode = "";
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- R.Code += AnnotatedCode.substr(0, NextPoint);
|
|
|
|
- R.Points.push_back(R.Code.size());
|
|
|
|
-
|
|
|
|
- AnnotatedCode = AnnotatedCode.substr(NextPoint + 1);
|
|
|
|
- }
|
|
|
|
- return R;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
CompletionContext runCodeCompleteOnCode(StringRef AnnotatedCode) {
|
|
CompletionContext runCodeCompleteOnCode(StringRef AnnotatedCode) {
|
|
- ParsedAnnotations P = parseAnnotations(AnnotatedCode);
|
|
|
|
- assert(P.Points.size() == 1 && "expected exactly one annotation point");
|
|
|
|
- return runCompletion(P.Code, P.Points.front());
|
|
|
|
|
|
+ llvm::Annotations A(AnnotatedCode);
|
|
|
|
+ return runCompletion(A.code(), A.point());
|
|
}
|
|
}
|
|
|
|
|
|
std::vector<std::string>
|
|
std::vector<std::string>
|
|
collectPreferredTypes(StringRef AnnotatedCode,
|
|
collectPreferredTypes(StringRef AnnotatedCode,
|
|
std::string *PtrDiffType = nullptr) {
|
|
std::string *PtrDiffType = nullptr) {
|
|
- ParsedAnnotations P = parseAnnotations(AnnotatedCode);
|
|
|
|
|
|
+ llvm::Annotations A(AnnotatedCode);
|
|
std::vector<std::string> Types;
|
|
std::vector<std::string> Types;
|
|
- for (size_t Point : P.Points) {
|
|
|
|
- auto Results = runCompletion(P.Code, Point);
|
|
|
|
|
|
+ for (size_t Point : A.points()) {
|
|
|
|
+ auto Results = runCompletion(A.code(), Point);
|
|
if (PtrDiffType) {
|
|
if (PtrDiffType) {
|
|
assert(PtrDiffType->empty() || *PtrDiffType == Results.PtrDiffType);
|
|
assert(PtrDiffType->empty() || *PtrDiffType == Results.PtrDiffType);
|
|
*PtrDiffType = Results.PtrDiffType;
|
|
*PtrDiffType = Results.PtrDiffType;
|