Skip to content

Commit f184449

Browse files
Merge pull request #333 from correctcomputation/microsoft-pr-style-1
First batch of style changes for Microsoft PR
2 parents b47c236 + b53fb9c commit f184449

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2073
-2179
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ For more information on Checked C and pointers to example code, see our
5656

5757
## 3C: Semi-automated conversion of C code to Checked C
5858

59-
This repository includes a tool called 3C that partially automates the conversion of C code to Checked C. Here is [general information about the 3C software](clang/docs/checkedc/3C/README.md), including development status and how to contribute. Here are the [usage instructions for the `3c` command-line tool](clang/tools/3c/README.md).
59+
This repository includes a tool called 3C that partially automates the
60+
conversion of C code to Checked C. Here is [general information about the 3C
61+
software](clang/docs/checkedc/3C/README.md), including development status and
62+
how to contribute. Here are the [usage instructions for the `3c` command-line
63+
tool](clang/tools/3c/README.md).
6064

6165
## More information
6266

clang-tools-extra/clangd/3CCommands.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ void As3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands) {
4848
}
4949

5050
bool Is3CCommand(const ExecuteCommandParams &Params) {
51-
return (Params.command.rfind(Command::_3C_APPLY_ONLY_FOR_THIS, 0) == 0) ||
52-
(Params.command.rfind(Command::_3C_APPLY_FOR_ALL, 0) == 0);
51+
return (Params.command.rfind(Command::_3C_APPLY_ONLY_FOR_THIS, 0) == 0) ||
52+
(Params.command.rfind(Command::_3C_APPLY_FOR_ALL, 0) == 0);
5353
}
5454

5555
bool Execute3CCommand(const ExecuteCommandParams &Params,
56-
std::string &ReplyMessage,
57-
_3CInterface &CcInterface) {
56+
std::string &ReplyMessage, _3CInterface &CcInterface) {
5857
ReplyMessage = "Checked C Pointer Modified.";
5958
if (Params.command.rfind(Command::_3C_APPLY_ONLY_FOR_THIS, 0) == 0) {
6059
int PtrId = Params._3CManualFix->ptrID;
@@ -68,6 +67,6 @@ bool Execute3CCommand(const ExecuteCommandParams &Params,
6867
}
6968
return false;
7069
}
71-
}
72-
}
70+
} // namespace clangd
71+
} // namespace clang
7372
#endif

clang-tools-extra/clangd/3CCommands.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717

1818
namespace clang {
1919
namespace clangd {
20-
// Convert the provided Diagnostic into Commands
21-
void As3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands);
22-
// Check if the execute command request from the client is a 3C command.
23-
bool Is3CCommand(const ExecuteCommandParams &Params);
20+
// Convert the provided Diagnostic into Commands.
21+
void As3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands);
22+
// Check if the execute command request from the client is a 3C command.
23+
bool Is3CCommand(const ExecuteCommandParams &Params);
2424

25-
// Interpret the provided execute command request as 3C command
26-
// and execute them.
27-
bool Execute3CCommand(const ExecuteCommandParams &Params,
28-
std::string &ReplyMessage,
29-
_3CInterface &CcInterface);
30-
}
31-
}
32-
#endif //LLVM_CLANG_TOOLS_EXTRA_CLANGD_3CCOMMANDS_H
25+
// Interpret the provided execute command request as 3C command
26+
// and execute them.
27+
bool Execute3CCommand(const ExecuteCommandParams &Params,
28+
std::string &ReplyMessage, _3CInterface &CcInterface);
29+
} // namespace clangd
30+
} // namespace clang
31+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_3CCOMMANDS_H
3332
#endif

clang-tools-extra/clangd/3CDiagnostics.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ static bool IsValidSourceFile(ConstraintsInfo &CCRes, std::string &FilePath) {
2525
return CCRes.ValidSourceFiles.find(FilePath) != CCRes.ValidSourceFiles.end();
2626
}
2727

28-
2928
bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
3029
std::lock_guard<std::mutex> Lock(DiagMutex);
3130
std::set<ConstraintKey> ProcessedCKeys;
3231
ProcessedCKeys.clear();
33-
auto GetLocRange = [](uint32_t Line, uint32_t ColNoS, uint32_t ColNoE) -> Range {
32+
auto GetLocRange = [](uint32_t Line, uint32_t ColNoS,
33+
uint32_t ColNoE) -> Range {
3434
Range nRange;
3535
Line--;
3636
nRange.start.line = Line;
@@ -60,8 +60,8 @@ bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
6060
NewDiag.Source = Diag::_3CMain;
6161
NewDiag.Severity = DiagnosticsEngine::Level::Error;
6262
NewDiag.code = std::to_string(WReason.first);
63-
NewDiag.Message = "Pointer is wild because of:" +
64-
WReason.second.getWildPtrReason();
63+
NewDiag.Message =
64+
"Pointer is wild because of:" + WReason.second.getWildPtrReason();
6565

6666
// Create notes for the information about root cause.
6767
PersistentSourceLoc SL = WReason.second.getLocation();
@@ -110,11 +110,11 @@ bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
110110
PsInfo = Line.AtomSourceMap[tC];
111111
FilePath = PsInfo->getFileName();
112112
DiagNote.AbsFile = FilePath;
113-
DiagNote.Range =
114-
GetLocRange(PsInfo->getLineNo(), PsInfo->getColSNo(),
115-
PsInfo->getColENo());
113+
DiagNote.Range = GetLocRange(
114+
PsInfo->getLineNo(), PsInfo->getColSNo(), PsInfo->getColENo());
116115
MaxPtrReasons--;
117-
DiagNote.Message = Line.RootWildAtomsWithReason[tC].getWildPtrReason();
116+
DiagNote.Message =
117+
Line.RootWildAtomsWithReason[tC].getWildPtrReason();
118118
if (MaxPtrReasons <= 1)
119119
DiagNote.Message += " (others)";
120120
NewDiag.Notes.push_back(DiagNote);
@@ -127,10 +127,9 @@ bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
127127
}
128128
}
129129

130-
131130
return true;
132131
}
133132

134-
}
135-
}
133+
} // namespace clangd
134+
} // namespace clang
136135
#endif

clang-tools-extra/clangd/3CDiagnostics.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_3CDIAGNOSTICS_H
1313
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_3CDIAGNOSTICS_H
1414

15-
#include <set>
1615
#include "Diagnostics.h"
1716
#include "clang/3C/3C.h"
17+
#include <set>
1818

1919
namespace clang {
2020
namespace clangd {
@@ -33,13 +33,12 @@ class _3CDiagnostics {
3333
std::map<std::string, std::vector<Diag>> &GetAllFilesDiagnostics() {
3434
return AllFileDiagnostics;
3535
}
36+
3637
private:
3738
// Diagnostics of all files.
3839
std::map<std::string, std::vector<Diag>> AllFileDiagnostics;
39-
40-
4140
};
42-
}
43-
}
44-
#endif //LLVM_CLANG_TOOLS_EXTRA_CLANGD_
41+
} // namespace clangd
42+
} // namespace clang
43+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_
4544
#endif

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
398398
llvm::json::Object{
399399
{"textDocumentSync", (int)TextDocumentSyncKind::Incremental},
400400
{"codeActionProvider", true},
401-
{"codeLensProvider", llvm::json::Object{
402-
{"resolveProvider", true}}},
401+
{"codeLensProvider", llvm::json::Object{{"resolveProvider", true}}},
403402
{"executeCommandProvider",
404403
llvm::json::Object{
405404
{"commands",
@@ -529,40 +528,35 @@ void ClangdLSPServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {
529528
}
530529

531530
#ifdef INTERACTIVE3C
532-
void ClangdLSPServer::_3CResultsReady(std::string FileName,
533-
bool ClearDiags) {
531+
void ClangdLSPServer::_3CResultsReady(std::string FileName, bool ClearDiags) {
534532
// Get the diagnostics and update the client.
535533
std::vector<Diag> Diagnostics;
536534
Diagnostics.clear();
537535
if (!ClearDiags) {
538536
std::lock_guard<std::mutex> lock(Server->_3CDiagInfo.DiagMutex);
539537
auto &allDiags = Server->_3CDiagInfo.GetAllFilesDiagnostics();
540-
if (allDiags.find(FileName) !=
541-
allDiags.end()) {
542-
Diagnostics.insert(
543-
Diagnostics.begin(),
544-
allDiags[FileName].begin(),
545-
allDiags[FileName].end());
538+
if (allDiags.find(FileName) != allDiags.end()) {
539+
Diagnostics.insert(Diagnostics.begin(), allDiags[FileName].begin(),
540+
allDiags[FileName].end());
546541
}
547542
}
548543
this->onDiagnosticsReady(FileName, Diagnostics);
549544
}
550545

551546
void ClangdLSPServer::send3CMessage(std::string MsgStr) {
552-
// Send message as info to the client.
553-
notify("window/showMessage",
554-
llvm::json::Object{
555-
// Info message.
556-
{"type", 3},
557-
{"message", std::move(MsgStr)},
558-
});
547+
// Send message as info to the client.
548+
notify("window/showMessage", llvm::json::Object{
549+
// Info message.
550+
{"type", 3},
551+
{"message", std::move(MsgStr)},
552+
});
559553
}
560554
#endif
561555
void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params,
562556
Callback<llvm::json::Value> Reply) {
563557
#ifdef INTERACTIVE3C
564558
// In this mode, we support only 3C commands.
565-
if(Is3CCommand(Params)) {
559+
if (Is3CCommand(Params)) {
566560
Server->execute3CCommand(Params, this);
567561
Reply("3C Background work scheduled.");
568562
} else {
@@ -1149,7 +1143,6 @@ ClangdLSPServer::ClangdLSPServer(
11491143
MsgHandler->bind("textDocument/didOpen", &ClangdLSPServer::onDocumentDidOpen);
11501144
MsgHandler->bind("textDocument/didClose", &ClangdLSPServer::onDocumentDidClose);
11511145
MsgHandler->bind("textDocument/didChange", &ClangdLSPServer::onDocumentDidChange);
1152-
// clang-format on
11531146
#else
11541147
MsgHandler->bind("initialize", &ClangdLSPServer::onInitialize);
11551148
MsgHandler->bind("shutdown", &ClangdLSPServer::onShutdown);
@@ -1179,6 +1172,7 @@ ClangdLSPServer::ClangdLSPServer(
11791172
MsgHandler->bind("textDocument/typeHierarchy", &ClangdLSPServer::onTypeHierarchy);
11801173
MsgHandler->bind("typeHierarchy/resolve", &ClangdLSPServer::onResolveTypeHierarchy);
11811174
#endif
1175+
// clang-format on
11821176
}
11831177

11841178
ClangdLSPServer::~ClangdLSPServer() = default;

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include "refactor/Rename.h"
2525
#include "refactor/Tweak.h"
2626
#ifdef INTERACTIVE3C
27-
#include "clang/3C/3C.h"
2827
#include "3CCommands.h"
28+
#include "clang/3C/3C.h"
2929
#endif
3030
#include "clang/Format/Format.h"
3131
#include "clang/Frontend/CompilerInstance.h"
@@ -122,9 +122,10 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
122122
DynamicIdx.get(), DiagConsumer, Opts.SemanticHighlighting),
123123
Opts.UpdateDebounce, Opts.RetentionPolicy)
124124
#ifdef INTERACTIVE3C
125-
, _3CInter(_3CInterface)
125+
,
126+
_3CInter(_3CInterface)
126127
#endif
127-
{
128+
{
128129
// Adds an index to the stack, at higher priority than existing indexes.
129130
auto AddIndex = [&](SymbolIndex *Idx) {
130131
if (this->Index != nullptr) {
@@ -186,8 +187,8 @@ void ClangdServer::clear3CDiagsForAllFiles(ConstraintsInfo &CcInfo,
186187
}
187188
}
188189

189-
void
190-
ClangdServer::_3CCollectAndBuildInitialConstraints(_3CLSPCallBack *ConvCB) {
190+
void ClangdServer::_3CCollectAndBuildInitialConstraints(
191+
_3CLSPCallBack *ConvCB) {
191192
auto Task = [=]() {
192193
_3CDiagInfo.ClearAllDiags();
193194
ConvCB->send3CMessage("Running 3C for first time.");
@@ -212,8 +213,7 @@ void ClangdServer::execute3CCommand(ExecuteCommandParams Params,
212213
std::string RplMsg;
213214
auto &WildPtrsInfo = _3CInter.GetWILDPtrsInfo();
214215
auto &PtrSourceMap = WildPtrsInfo.AtomSourceMap;
215-
if (PtrSourceMap.find(Params._3CManualFix->ptrID) !=
216-
PtrSourceMap.end()) {
216+
if (PtrSourceMap.find(Params._3CManualFix->ptrID) != PtrSourceMap.end()) {
217217
std::string PtrFileName =
218218
PtrSourceMap[Params._3CManualFix->ptrID]->getFileName();
219219
log("3C: File of the pointer {0}\n", PtrFileName);
@@ -242,7 +242,8 @@ void ClangdServer::_3CCloseDocument(std::string FileName) {
242242
log("3C: Finished writing back file: {0}\n", FileName);
243243
} else {
244244
log("3C: File not included during constraint solving phase. "
245-
"Rewriting failed: {0}\n", FileName);
245+
"Rewriting failed: {0}\n",
246+
FileName);
246247
}
247248
};
248249
WorkScheduler.run("3C: Writing back file.", Task);

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ class ClangdServer {
310310
// collect and build initial set of constraints on the source
311311
// files.
312312

313-
void execute3CCommand(ExecuteCommandParams Params,
314-
_3CLSPCallBack *ConvCB);
313+
void execute3CCommand(ExecuteCommandParams Params, _3CLSPCallBack *ConvCB);
315314

316315
void _3CCollectAndBuildInitialConstraints(_3CLSPCallBack *ConvCB);
317316

@@ -328,7 +327,8 @@ class ClangdServer {
328327
ArrayRef<tooling::Range> Ranges);
329328

330329
#ifdef INTERACTIVE3C
331-
void report3CDiagsForAllFiles(ConstraintsInfo &CcInfo, _3CLSPCallBack *ConvCB);
330+
void report3CDiagsForAllFiles(ConstraintsInfo &CcInfo,
331+
_3CLSPCallBack *ConvCB);
332332
void clear3CDiagsForAllFiles(ConstraintsInfo &CcInfo, _3CLSPCallBack *ConvCB);
333333
#endif
334334

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,7 @@ bool fromJSON(const llvm::json::Value &Params, ExecuteCommandParams &R) {
560560
#ifdef INTERACTIVE3C
561561
if (R.command == ExecuteCommandParams::_3C_APPLY_ONLY_FOR_THIS ||
562562
R.command == ExecuteCommandParams::_3C_APPLY_FOR_ALL) {
563-
return Args && Args->size() == 1 &&
564-
fromJSON(Args->front(), R._3CManualFix);
563+
return Args && Args->size() == 1 && fromJSON(Args->front(), R._3CManualFix);
565564
}
566565
#endif
567566
return false; // Unrecognized command.

clang-tools-extra/clangd/Protocol.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,23 +817,25 @@ llvm::json::Value toJSON(const CodeAction &);
817817
// A code lens represents a command that should be shown along with
818818
// source text, like the number of references, a way to run tests, etc.
819819
//
820-
// A code lens is _unresolved_ when no command is associated to it. For performance
821-
// reasons the creation of a code lens and resolving should be done in two stages.
820+
// A code lens is _unresolved_ when no command is associated to it. For
821+
// performance reasons the creation of a code lens and resolving should be done
822+
// in two stages.
822823
//
823824
struct CodeLens {
824-
/// The range in which this code lens is valid, should only span a single line.
825+
/// The range in which this code lens is valid, should only span a single
826+
/// line.
825827
Range range;
826828

827829
/**
828830
* The command this code lens represents.
829-
*/
831+
*/
830832
llvm::Optional<Command> command;
831833

832834
/**
833835
* A data entry field that is preserved on a code lens item between
834836
* a code lens and a code lens resolve request.
835837
*/
836-
//data?: any
838+
// data?: any
837839
};
838840

839841
llvm::json::Value toJSON(const CodeLens &);

0 commit comments

Comments
 (0)