Skip to content

Commit

Permalink
clang-tidy: Add readability-else-after-return
Browse files Browse the repository at this point in the history
  • Loading branch information
dnadlinger committed Nov 2, 2015
1 parent 9df487e commit 05d4535
Show file tree
Hide file tree
Showing 22 changed files with 484 additions and 463 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Checks: -*,modernize-*,-modernize-redundant-void-arg,google-readability-braces-around-statements,google-explicit-constructor,google-readability-casting,misc-assert-side-effect,misc-assign-operator-signature,misc-inefficient-algorithm,misc-move-constructor-init,misc-non-copyable-objects,misc-sizeof-container,misc-undelegated-constructor,misc-unused-alias-decls,readability-container-size-empty,readability-redundant-string-cstr
Checks: -*,modernize-*,-modernize-redundant-void-arg,google-readability-braces-around-statements,google-explicit-constructor,google-readability-casting,misc-assert-side-effect,misc-assign-operator-signature,misc-inefficient-algorithm,misc-move-constructor-init,misc-non-copyable-objects,misc-sizeof-container,misc-undelegated-constructor,misc-unused-alias-decls,readability-container-size-empty,readability-else-after-return,readability-redundant-string-cstr
3 changes: 2 additions & 1 deletion gen/abi-win64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ bool Win64TargetABI::returnInArg(TypeFunction *tf) {
// (incl. 2x32-bit cfloat) are returned in a register (RAX, or
// XMM0 for single float/ifloat/double/idouble)
// * all other types are returned via struct-return (sret)
return (rt->ty == Tstruct && !((TypeStruct *)rt)->sym->isPOD()) ||
return (rt->ty == Tstruct &&
!(static_cast<TypeStruct *>(rt))->sym->isPOD()) ||
isPassedWithByvalSemantics(rt);
}

Expand Down
16 changes: 7 additions & 9 deletions gen/abi-x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,15 @@ struct X86TargetABI : TargetABI {
}
// other ABI's follow C, which is cdouble and creal returned on the stack
// as well as structs (except for some OSX cases).
else {
if (isMagicCLong(rt)) {
return false;
}

if (rt->ty == Tstruct) {
return !isOSX || returnOSXStructInArg((TypeStruct *)rt);
}
return (rt->ty == Tsarray || rt->ty == Tcomplex64 ||
rt->ty == Tcomplex80);
if (isMagicCLong(rt)) {
return false;
}

if (rt->ty == Tstruct) {
return !isOSX || returnOSXStructInArg((TypeStruct *)rt);
}
return (rt->ty == Tsarray || rt->ty == Tcomplex64 || rt->ty == Tcomplex80);
}

bool passByVal(Type *t) override {
Expand Down
9 changes: 6 additions & 3 deletions gen/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,13 +1021,16 @@ LLValue *DtoArrayLen(DValue *v) {
if (t->ty == Tarray) {
if (DSliceValue *s = v->isSlice()) {
return s->len;
} else if (v->isNull()) {
}
if (v->isNull()) {
return DtoConstSize_t(0);
} else if (v->isLVal()) {
}
if (v->isLVal()) {
return DtoLoad(DtoGEPi(v->getLVal(), 0, 0), ".len");
}
return gIR->ir->CreateExtractValue(v->getRVal(), 0, ".len");
} else if (t->ty == Tsarray) {
}
if (t->ty == Tsarray) {
assert(!v->isSlice());
assert(!v->isNull());
assert(v->type->toBasetype()->ty == Tsarray);
Expand Down
29 changes: 15 additions & 14 deletions gen/asm-x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,14 @@ typedef struct {
unsigned nOperands() {
if (!operands[0]) {
return 0;
} else if (!operands[1]) {
}
if (!operands[1]) {
return 1;
} else if (!operands[2]) {
}
if (!operands[2]) {
return 2;
} else {
return 3;
}
return 3;
}
} AsmOpInfo;

Expand Down Expand Up @@ -2085,9 +2086,8 @@ struct AsmProcessor {
Token *peekToken() {
if (token->next) {
return token->next;
} else {
return &eof_tok;
}
return &eof_tok;
}

void expectEnd() {
Expand Down Expand Up @@ -2162,7 +2162,8 @@ struct AsmProcessor {
l = strcmp(opcode, opData[k].inMnemonic);
if (!l) {
return opData[k].asmOp;
} else if (l < 0) {
}
if (l < 0) {
j = k;
} else {
i = k + 1;
Expand Down Expand Up @@ -3282,10 +3283,9 @@ struct AsmProcessor {
}
e = e->semantic(sc);
return e->ctfeInterpret();
} else {
stmt->error("expected integer operand(s) for '%s'", Token::tochars[op]);
return newIntExp(0);
}
stmt->error("expected integer operand(s) for '%s'", Token::tochars[op]);
return newIntExp(0);
}

void parseOperand() {
Expand Down Expand Up @@ -3717,7 +3717,8 @@ struct AsmProcessor {

if (ident == Id::__LOCAL_SIZE) {
return new IdentifierExp(stmt->loc, ident);
} else if (ident == Id::dollar) {
}
if (ident == Id::dollar) {
do_dollar:
return new IdentifierExp(stmt->loc, ident);
} else {
Expand Down Expand Up @@ -3772,7 +3773,8 @@ struct AsmProcessor {
}
invalidExpression();
return Handled;
} else if (token->value == TOKcolon) {
}
if (token->value == TOKcolon) {
nextToken();
if (operand->segmentPrefix != Reg_Invalid) {
stmt->error("too many segment prefixes");
Expand All @@ -3782,9 +3784,8 @@ struct AsmProcessor {
stmt->error("'%s' is not a segment register", ident->string);
}
return parseAsmExp();
} else {
return newRegExp(static_cast<Reg>(i));
}
return newRegExp(static_cast<Reg>(i));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gen/cl_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ template <class DataType> class FlagParser : public cl::generic_parser_base {

private:
struct OptionValue : cl::OptionValueBase<DataType, false> {
OptionValue() {}
OptionValue(){};
};
const OptionValue EmptyOptionValue;

Expand Down
51 changes: 24 additions & 27 deletions gen/classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ DValue *DtoCastClass(Loc &loc, DValue *val, Type *_to) {
return new DImValue(_to, rval);
}
// class -> bool
else if (to->ty == Tbool) {
if (to->ty == Tbool) {
IF_LOG Logger::println("to bool");
LLValue *llval = val->getRVal();
LLValue *zero = LLConstant::getNullValue(llval->getType());
return new DImValue(_to, gIR->ir->CreateICmpNE(llval, zero));
}
// class -> integer
else if (to->isintegral()) {
if (to->isintegral()) {
IF_LOG Logger::println("to %s", to->toChars());

// get class ptr
Expand All @@ -228,7 +228,7 @@ DValue *DtoCastClass(Loc &loc, DValue *val, Type *_to) {
return DtoCastInt(loc, &im, _to);
}
// class -> typeof(null)
else if (to->ty == Tnull) {
if (to->ty == Tnull) {
IF_LOG Logger::println("to %s", to->toChars());
return new DImValue(_to, LLConstant::getNullValue(DtoType(_to)));
}
Expand Down Expand Up @@ -256,7 +256,7 @@ DValue *DtoCastClass(Loc &loc, DValue *val, Type *_to) {
return DtoDynamicCastInterface(loc, val, _to);
}
// class -> interface - static cast
else if (it->isBaseOf(fc->sym, nullptr)) {
if (it->isBaseOf(fc->sym, nullptr)) {
Logger::println("static down cast");

// get the from class
Expand Down Expand Up @@ -295,32 +295,29 @@ DValue *DtoCastClass(Loc &loc, DValue *val, Type *_to) {
return new DImValue(_to, v);
}
// class -> interface
else {
Logger::println("from object");
return DtoDynamicCastObject(loc, val, _to);
}

Logger::println("from object");
return DtoDynamicCastObject(loc, val, _to);
}
// x -> class
else {
Logger::println("to class");
// interface -> class
if (fc->sym->isInterfaceDeclaration()) {
Logger::println("interface cast");
return DtoDynamicCastInterface(loc, val, _to);
}
// class -> class - static down cast
else if (tc->sym->isBaseOf(fc->sym, nullptr)) {
Logger::println("static down cast");
LLType *tolltype = DtoType(_to);
LLValue *rval = DtoBitCast(val->getRVal(), tolltype);
return new DImValue(_to, rval);
}
// class -> class - dynamic up cast
else {
Logger::println("dynamic up cast");
return DtoDynamicCastObject(loc, val, _to);
}

Logger::println("to class");
// interface -> class
if (fc->sym->isInterfaceDeclaration()) {
Logger::println("interface cast");
return DtoDynamicCastInterface(loc, val, _to);
}
// class -> class - static down cast
if (tc->sym->isBaseOf(fc->sym, nullptr)) {
Logger::println("static down cast");
LLType *tolltype = DtoType(_to);
LLValue *rval = DtoBitCast(val->getRVal(), tolltype);
return new DImValue(_to, rval);
}
// class -> class - dynamic up cast

Logger::println("dynamic up cast");
return DtoDynamicCastObject(loc, val, _to);
}

//////////////////////////////////////////////////////////////////////////////////////////
Expand Down
18 changes: 9 additions & 9 deletions gen/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,8 @@ LLValue *DtoComplexEquals(Loc &loc, TOK op, DValue *lhs, DValue *rhs) {

if (op == TOKequal) {
return gIR->ir->CreateAnd(b1, b2);
} else {
return gIR->ir->CreateOr(b1, b2);
}
return gIR->ir->CreateOr(b1, b2);
}

//////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -452,7 +451,8 @@ DValue *DtoCastComplex(Loc &loc, DValue *val, Type *_to) {

LLValue *pair = DtoAggrPair(DtoType(_to), re, im);
return new DImValue(_to, pair);
} else if (to->isimaginary()) {
}
if (to->isimaginary()) {
// FIXME: this loads both values, even when we only need one
LLValue *v = val->getRVal();
LLValue *impart = gIR->ir->CreateExtractValue(v, 1, ".im_part");
Expand All @@ -472,10 +472,12 @@ DValue *DtoCastComplex(Loc &loc, DValue *val, Type *_to) {
}
auto im = new DImValue(extractty, impart);
return DtoCastFloat(loc, im, to);
} else if (to->ty == Tbool) {
}
if (to->ty == Tbool) {
return new DImValue(
_to, DtoComplexEquals(loc, TOKnotequal, val, DtoNullValue(vty)));
} else if (to->isfloating() || to->isintegral()) {
}
if (to->isfloating() || to->isintegral()) {
// FIXME: this loads both values, even when we only need one
LLValue *v = val->getRVal();
LLValue *repart = gIR->ir->CreateExtractValue(v, 0, ".re_part");
Expand All @@ -495,9 +497,7 @@ DValue *DtoCastComplex(Loc &loc, DValue *val, Type *_to) {
}
auto re = new DImValue(extractty, repart);
return DtoCastFloat(loc, re, to);
} else {
error(loc, "Don't know how to cast %s to %s", vty->toChars(),
to->toChars());
fatal();
}
error(loc, "Don't know how to cast %s to %s", vty->toChars(), to->toChars());
fatal();
}
Loading

0 comments on commit 05d4535

Please sign in to comment.