Skip to content

Commit 18c56a0

Browse files
committed
[WebAssembly] clang-tidy (NFC)
Summary: This patch fixes clang-tidy warnings on wasm-only files. The list of checks used is: `-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*` (LLVM's default .clang-tidy list is the same except it does not have `modernize-*`. But I've seen in multiple CLs in LLVM the modernize style was recommended and code was fixed based on the style, so I added it as well.) The common fixes are: - Variable names start with an uppercase letter - Function names start with a lowercase letter - Use `auto` when you use casts so the type is evident - Use inline initialization for class member variables - Use `= default` for empty constructors / destructors - Use `using` in place of `typedef` Reviewers: sbc100, tlively, aardappel Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits Differential Revision: https://reviews.llvm.org/D57500 llvm-svn: 353075
1 parent 2e862c7 commit 18c56a0

Some content is hidden

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

46 files changed

+526
-543
lines changed

llvm/include/llvm/MC/MCSectionWasm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class MCSectionWasm final : public MCSection {
5555

5656
/// Decides whether a '.section' directive should be printed before the
5757
/// section name
58-
bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
58+
bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
5959

6060
StringRef getSectionName() const { return SectionName; }
6161
const MCSymbolWasm *getGroup() const { return Group; }

llvm/lib/BinaryFormat/Wasm.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "llvm/BinaryFormat/Wasm.h"
1010

11-
std::string llvm::wasm::toString(wasm::WasmSymbolType type) {
12-
switch (type) {
11+
std::string llvm::wasm::toString(wasm::WasmSymbolType Type) {
12+
switch (Type) {
1313
case wasm::WASM_SYMBOL_TYPE_FUNCTION:
1414
return "WASM_SYMBOL_TYPE_FUNCTION";
1515
case wasm::WASM_SYMBOL_TYPE_GLOBAL:
@@ -24,8 +24,8 @@ std::string llvm::wasm::toString(wasm::WasmSymbolType type) {
2424
llvm_unreachable("unknown symbol type");
2525
}
2626

27-
std::string llvm::wasm::relocTypetoString(uint32_t type) {
28-
switch (type) {
27+
std::string llvm::wasm::relocTypetoString(uint32_t Type) {
28+
switch (Type) {
2929
#define WASM_RELOC(NAME, VALUE) \
3030
case VALUE: \
3131
return #NAME;

llvm/lib/MC/MCParser/WasmAsmParser.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ using namespace llvm;
3232
namespace {
3333

3434
class WasmAsmParser : public MCAsmParserExtension {
35-
MCAsmParser *Parser;
36-
MCAsmLexer *Lexer;
35+
MCAsmParser *Parser = nullptr;
36+
MCAsmLexer *Lexer = nullptr;
3737

3838
template<bool (WasmAsmParser::*HandlerMethod)(StringRef, SMLoc)>
3939
void addDirectiveHandler(StringRef Directive) {
@@ -44,9 +44,7 @@ class WasmAsmParser : public MCAsmParserExtension {
4444
}
4545

4646
public:
47-
WasmAsmParser() : Parser(nullptr), Lexer(nullptr) {
48-
BracketExpressionsSupported = true;
49-
}
47+
WasmAsmParser() { BracketExpressionsSupported = true; }
5048

5149
void Initialize(MCAsmParser &P) override {
5250
Parser = &P;
@@ -60,19 +58,20 @@ class WasmAsmParser : public MCAsmParserExtension {
6058
addDirectiveHandler<&WasmAsmParser::parseDirectiveType>(".type");
6159
}
6260

63-
bool Error(const StringRef &msg, const AsmToken &tok) {
64-
return Parser->Error(tok.getLoc(), msg + tok.getString());
61+
bool error(const StringRef &Msg, const AsmToken &Tok) {
62+
return Parser->Error(Tok.getLoc(), Msg + Tok.getString());
6563
}
6664

67-
bool IsNext(AsmToken::TokenKind Kind) {
68-
auto ok = Lexer->is(Kind);
69-
if (ok) Lex();
70-
return ok;
65+
bool isNext(AsmToken::TokenKind Kind) {
66+
auto Ok = Lexer->is(Kind);
67+
if (Ok)
68+
Lex();
69+
return Ok;
7170
}
7271

73-
bool Expect(AsmToken::TokenKind Kind, const char *KindName) {
74-
if (!IsNext(Kind))
75-
return Error(std::string("Expected ") + KindName + ", instead got: ",
72+
bool expect(AsmToken::TokenKind Kind, const char *KindName) {
73+
if (!isNext(Kind))
74+
return error(std::string("Expected ") + KindName + ", instead got: ",
7675
Lexer->getTok());
7776
return false;
7877
}
@@ -87,9 +86,9 @@ class WasmAsmParser : public MCAsmParserExtension {
8786
if (Parser->parseIdentifier(Name))
8887
return TokError("expected identifier in directive");
8988
// FIXME: currently requiring this very fixed format.
90-
if (Expect(AsmToken::Comma, ",") || Expect(AsmToken::String, "string") ||
91-
Expect(AsmToken::Comma, ",") || Expect(AsmToken::At, "@") ||
92-
Expect(AsmToken::EndOfStatement, "eol"))
89+
if (expect(AsmToken::Comma, ",") || expect(AsmToken::String, "string") ||
90+
expect(AsmToken::Comma, ",") || expect(AsmToken::At, "@") ||
91+
expect(AsmToken::EndOfStatement, "eol"))
9392
return true;
9493
// This is done automatically by the assembler for text sections currently,
9594
// so we don't need to emit that here. This is what it would do (and may
@@ -106,12 +105,12 @@ class WasmAsmParser : public MCAsmParserExtension {
106105
if (Parser->parseIdentifier(Name))
107106
return TokError("expected identifier in directive");
108107
auto Sym = getContext().getOrCreateSymbol(Name);
109-
if (Expect(AsmToken::Comma, ","))
108+
if (expect(AsmToken::Comma, ","))
110109
return true;
111110
const MCExpr *Expr;
112111
if (Parser->parseExpression(Expr))
113112
return true;
114-
if (Expect(AsmToken::EndOfStatement, "eol"))
113+
if (expect(AsmToken::EndOfStatement, "eol"))
115114
return true;
116115
// This is done automatically by the assembler for functions currently,
117116
// so we don't need to emit that here. This is what it would do:
@@ -124,24 +123,24 @@ class WasmAsmParser : public MCAsmParserExtension {
124123
// This could be the start of a function, check if followed by
125124
// "label,@function"
126125
if (!Lexer->is(AsmToken::Identifier))
127-
return Error("Expected label after .type directive, got: ",
126+
return error("Expected label after .type directive, got: ",
128127
Lexer->getTok());
129128
auto WasmSym = cast<MCSymbolWasm>(
130129
getStreamer().getContext().getOrCreateSymbol(
131130
Lexer->getTok().getString()));
132131
Lex();
133-
if (!(IsNext(AsmToken::Comma) && IsNext(AsmToken::At) &&
132+
if (!(isNext(AsmToken::Comma) && isNext(AsmToken::At) &&
134133
Lexer->is(AsmToken::Identifier)))
135-
return Error("Expected label,@type declaration, got: ", Lexer->getTok());
134+
return error("Expected label,@type declaration, got: ", Lexer->getTok());
136135
auto TypeName = Lexer->getTok().getString();
137136
if (TypeName == "function")
138137
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
139138
else if (TypeName == "global")
140139
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
141140
else
142-
return Error("Unknown WASM symbol type: ", Lexer->getTok());
141+
return error("Unknown WASM symbol type: ", Lexer->getTok());
143142
Lex();
144-
return Expect(AsmToken::EndOfStatement, "EOL");
143+
return expect(AsmToken::EndOfStatement, "EOL");
145144
}
146145
};
147146

llvm/lib/MC/MCSectionWasm.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
using namespace llvm;
1616

17-
MCSectionWasm::~MCSectionWasm() {} // anchor.
17+
MCSectionWasm::~MCSectionWasm() = default; // anchor.
1818

1919
// Decides whether a '.section' directive
2020
// should be printed before the section name.
21-
bool MCSectionWasm::ShouldOmitSectionDirective(StringRef Name,
21+
bool MCSectionWasm::shouldOmitSectionDirective(StringRef Name,
2222
const MCAsmInfo &MAI) const {
2323
return MAI.shouldOmitSectionDirective(Name);
2424
}
@@ -50,7 +50,7 @@ void MCSectionWasm::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
5050
raw_ostream &OS,
5151
const MCExpr *Subsection) const {
5252

53-
if (ShouldOmitSectionDirective(SectionName, MAI)) {
53+
if (shouldOmitSectionDirective(SectionName, MAI)) {
5454
OS << '\t' << getSectionName();
5555
if (Subsection) {
5656
OS << '\t';

llvm/lib/MC/MCWasmObjectTargetWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
using namespace llvm;
1212

13-
MCWasmObjectTargetWriter::MCWasmObjectTargetWriter(bool Is64Bit_)
14-
: Is64Bit(Is64Bit_) {}
13+
MCWasmObjectTargetWriter::MCWasmObjectTargetWriter(bool Is64Bit)
14+
: Is64Bit(Is64Bit) {}
1515

1616
// Pin the vtable to this object file
1717
MCWasmObjectTargetWriter::~MCWasmObjectTargetWriter() = default;

llvm/lib/MC/MCWasmStreamer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434

3535
using namespace llvm;
3636

37-
MCWasmStreamer::~MCWasmStreamer() {}
37+
MCWasmStreamer::~MCWasmStreamer() = default; // anchor.
3838

3939
void MCWasmStreamer::mergeFragment(MCDataFragment *DF, MCDataFragment *EF) {
4040
flushPendingLabels(DF, DF->getContents().size());
4141

42-
for (unsigned i = 0, e = EF->getFixups().size(); i != e; ++i) {
43-
EF->getFixups()[i].setOffset(EF->getFixups()[i].getOffset() +
42+
for (unsigned I = 0, E = EF->getFixups().size(); I != E; ++I) {
43+
EF->getFixups()[I].setOffset(EF->getFixups()[I].getOffset() +
4444
DF->getContents().size());
45-
DF->getFixups().push_back(EF->getFixups()[i]);
45+
DF->getFixups().push_back(EF->getFixups()[I]);
4646
}
4747
if (DF->getSubtargetInfo() == nullptr && EF->getSubtargetInfo())
4848
DF->setHasInstructions(*EF->getSubtargetInfo());
@@ -179,9 +179,9 @@ void MCWasmStreamer::EmitInstToData(const MCInst &Inst,
179179
MCDataFragment *DF = getOrCreateDataFragment();
180180

181181
// Add the fixups and data.
182-
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
183-
Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
184-
DF->getFixups().push_back(Fixups[i]);
182+
for (unsigned I = 0, E = Fixups.size(); I != E; ++I) {
183+
Fixups[I].setOffset(Fixups[I].getOffset() + DF->getContents().size());
184+
DF->getFixups().push_back(Fixups[I]);
185185
}
186186
DF->setHasInstructions(STI);
187187
DF->getContents().append(Code.begin(), Code.end());

0 commit comments

Comments
 (0)