Skip to content

Making checked-c-convert into a library #837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/CConvertCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CLANGD_CCONVERTCOMMANDS_H

#include "Protocol.h"
#include "cconvert/CConvInteractive.h"
#include "clang/CConv/CConv.h"

namespace clang {
namespace clangd {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/CConvertDiagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <set>
#include "Diagnostics.h"
#include "cconvert/CConvInteractive.h"
#include "clang/CConv/CConv.h"

namespace clang {
namespace clangd {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ add_clang_library(cconvClangDaemon
refactor/Tweak.cpp

LINK_LIBS
CConv
clangAST
clangASTMatchers
clangBasic
Expand Down Expand Up @@ -254,7 +255,6 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
# FIXME: Make fuzzer not use linux-specific APIs, build it everywhere.
add_subdirectory(fuzzer)
endif()
add_subdirectory(cconvert)
add_subdirectory(tool)
add_subdirectory(indexer)
add_subdirectory(index/dex/dexp)
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/ClangdLSPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,13 @@ void ClangdLSPServer::ccConvResultsReady(std::string FileName,
this->onDiagnosticsReady(FileName, Diagnostics);
}

void ClangdLSPServer::sendCConvMessage(std::string msg) {\
void ClangdLSPServer::sendCConvMessage(std::string MsgStr) {
// Send message as info to the client.
notify("window/showMessage",
llvm::json::Object{
// Info message.
{"type", 3},
{"message", std::move(msg)},
{"message", std::move(MsgStr)},
});
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/ClangdLSPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "Protocol.h"
#include "Transport.h"
#ifdef INTERACTIVECCCONV
#include "cconvert/CConvInteractive.h"
#include "clang/CConv/CConv.h"
#endif
#include "clang/Tooling/Core/Replacement.h"
#include "llvm/ADT/Optional.h"
Expand Down Expand Up @@ -64,7 +64,7 @@ class ClangdLSPServer : private DiagnosticsConsumer {

#ifdef INTERACTIVECCCONV
void ccConvResultsReady(std::string FileName, bool ClearDiags = false) override;
void sendCConvMessage(std::string msg) override;
void sendCConvMessage(std::string MsgStr) override;
#endif

private:
Expand Down
61 changes: 33 additions & 28 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "refactor/Rename.h"
#include "refactor/Tweak.h"
#ifdef INTERACTIVECCCONV
#include "cconvert/CConvInteractive.h"
#include "clang/CConv/CConv.h"
#include "CConvertCommands.h"
#endif
#include "clang/Format/Format.h"
Expand Down Expand Up @@ -170,34 +170,36 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
}

#ifdef INTERACTIVECCCONV
void ClangdServer::reportCConvDiagsForAllFiles(DisjointSet &ccInfo,
void ClangdServer::reportCConvDiagsForAllFiles(DisjointSet &CcInfo,
CConvLSPCallBack *ConvCB) {
// Update the diag information for all the valid files.
for (auto &srcFileDiags : CConvDiagInfo.GetAllFilesDiagnostics()) {
ConvCB->ccConvResultsReady(srcFileDiags.first);
for (auto &SrcFileDiags : CConvDiagInfo.GetAllFilesDiagnostics()) {
ConvCB->ccConvResultsReady(SrcFileDiags.first);
}
}

void ClangdServer::clearCConvDiagsForAllFiles(DisjointSet &ccInfo,
void ClangdServer::clearCConvDiagsForAllFiles(DisjointSet &CcInfo,
CConvLSPCallBack *ConvCB) {
for (auto &srcFileDiags : CConvDiagInfo.GetAllFilesDiagnostics()) {
for (auto &SrcFileDiags : CConvDiagInfo.GetAllFilesDiagnostics()) {
// Clear diags for all files.
ConvCB->ccConvResultsReady(srcFileDiags.first, true);
ConvCB->ccConvResultsReady(SrcFileDiags.first, true);
}
}

void ClangdServer::cconvCollectAndBuildInitialConstraints(CConvLSPCallBack *ConvCB) {
void
ClangdServer::cconvCollectAndBuildInitialConstraints(CConvLSPCallBack *ConvCB) {
auto Task = [=]() {
CConvDiagInfo.ClearAllDiags();
ConvCB->sendCConvMessage("Running CConv for first time.");
CConvInter.BuildInitialConstraints();
CConvInter.SolveConstraints();
ConvCB->sendCConvMessage("Finished running CConv.");
log("CConv: Built initial constraints successfully.\n");
auto &ccInterfaceInfo = CConvInter.GetWILDPtrsInfo();
auto &WildPtrsInfo = CConvInter.GetWILDPtrsInfo();
log("CConv: Got WILD Ptrs Info.\n");
CConvDiagInfo.PopulateDiagsFromDisjointSet(ccInterfaceInfo);
CConvDiagInfo.PopulateDiagsFromDisjointSet(WildPtrsInfo);
log("CConv: Populated Diags from Disjoint Sets.\n");
reportCConvDiagsForAllFiles(ccInterfaceInfo, ConvCB);
reportCConvDiagsForAllFiles(WildPtrsInfo, ConvCB);
ConvCB->sendCConvMessage("CConv: Finished updating problems.");
log("CConv: Updated the diag information.\n");
};
Expand All @@ -207,37 +209,40 @@ void ClangdServer::cconvCollectAndBuildInitialConstraints(CConvLSPCallBack *Conv
void ClangdServer::executeCConvCommand(ExecuteCommandParams Params,
CConvLSPCallBack *ConvCB) {
auto Task = [this, Params, ConvCB]() {
std::string replyMessage;
auto &wildPtrInfo = CConvInter.GetWILDPtrsInfo();
auto &ptrSourceMap = wildPtrInfo.PtrSourceMap;
if (ptrSourceMap.find(Params.ccConvertManualFix->ptrID) != ptrSourceMap.end()) {
std::string ptrFileName = ptrSourceMap[Params.ccConvertManualFix->ptrID]->getFileName();
log("CConv: File of the pointer {0}\n", ptrFileName);
clearCConvDiagsForAllFiles(wildPtrInfo, ConvCB);
std::string RplMsg;
auto &WildPtrsInfo = CConvInter.GetWILDPtrsInfo();
auto &PtrSourceMap = WildPtrsInfo.PtrSourceMap;
if (PtrSourceMap.find(Params.ccConvertManualFix->ptrID) !=
PtrSourceMap.end()) {
std::string PtrFileName =
PtrSourceMap[Params.ccConvertManualFix->ptrID]->getFileName();
log("CConv: File of the pointer {0}\n", PtrFileName);
clearCConvDiagsForAllFiles(WildPtrsInfo, ConvCB);
ConvCB->sendCConvMessage("CConv modifying constraints.");
ExecuteCCCommand(Params, replyMessage, CConvInter);
ExecuteCCCommand(Params, RplMsg, CConvInter);
this->CConvDiagInfo.ClearAllDiags();
auto &ccInterfaceInfo = wildPtrInfo;
ConvCB->sendCConvMessage("CConv Updating new issues after editing constraints.");
this->CConvDiagInfo.PopulateDiagsFromDisjointSet(ccInterfaceInfo);
ConvCB->sendCConvMessage("CConv Updating new issues "
"after editing constraints.");
this->CConvDiagInfo.PopulateDiagsFromDisjointSet(WildPtrsInfo);
log("CConv calling call-back\n");
// ConvCB->ccConvResultsReady(ptrFileName);
ConvCB->sendCConvMessage("CConv Updated new issues.");
reportCConvDiagsForAllFiles(ccInterfaceInfo, ConvCB);
reportCConvDiagsForAllFiles(WildPtrsInfo, ConvCB);
} else {
ConvCB->sendCConvMessage("CConv contraint key already removed.");
}
};
WorkScheduler.run("Applying on demand ptr modifications", Task);
}

void ClangdServer::cconvCloseDocument(std::string file) {
void ClangdServer::cconvCloseDocument(std::string FileName) {
auto Task = [=]() {
log("CConv: Trying to write back file: {0}\n", file);
if (CConvInter.WriteConvertedFileToDisk(file)) {
log("CConv: Finished writing back file: {0}\n", file);
log("CConv: Trying to write back file: {0}\n", FileName);
if (CConvInter.WriteConvertedFileToDisk(FileName)) {
log("CConv: Finished writing back file: {0}\n", FileName);
} else {
log("CConv: File not included during constraint solving phase. Rewriting failed: {0}\n", file);
log("CConv: File not included during constraint solving phase. "
"Rewriting failed: {0}\n", FileName);
}
};
WorkScheduler.run("CConv: Writing back file.", Task);
Expand Down
11 changes: 6 additions & 5 deletions clang-tools-extra/clangd/ClangdServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ class DiagnosticsConsumer {
#ifdef INTERACTIVECCCONV
class CConvLSPCallBack {
public:
virtual void ccConvResultsReady(std::string targetFileName, bool clearDiags = false) = 0;
virtual void sendCConvMessage(std::string msg) = 0;
virtual void ccConvResultsReady(std::string FileName,
bool ClearDiags = false) = 0;
virtual void sendCConvMessage(std::string MsgStr) = 0;
};
#endif

Expand Down Expand Up @@ -316,7 +317,7 @@ class ClangdServer {

CConvertDiagnostics CConvDiagInfo;

void cconvCloseDocument(std::string file);
void cconvCloseDocument(std::string FileName);
#endif

private:
Expand All @@ -327,8 +328,8 @@ class ClangdServer {
ArrayRef<tooling::Range> Ranges);

#ifdef INTERACTIVECCCONV
void reportCConvDiagsForAllFiles(DisjointSet &ccInfo, CConvLSPCallBack *ConvCB);
void clearCConvDiagsForAllFiles(DisjointSet &ccInfo, CConvLSPCallBack *ConvCB);
void reportCConvDiagsForAllFiles(DisjointSet &CcInfo, CConvLSPCallBack *ConvCB);
void clearCConvDiagsForAllFiles(DisjointSet &CcInfo, CConvLSPCallBack *ConvCB);
#endif

const FileSystemProvider &FSProvider;
Expand Down
Loading