Skip to content

Commit

Permalink
Converted all cases of "!(a is b)" to "a !is b".
Browse files Browse the repository at this point in the history
Because I finally can.
  • Loading branch information
mindhog committed Dec 4, 2019
1 parent 20d55f5 commit 6e03816
Show file tree
Hide file tree
Showing 50 changed files with 139 additions and 142 deletions.
2 changes: 1 addition & 1 deletion defs_ann.crk
Expand Up @@ -8,7 +8,7 @@ import crack.compiler CrackContext, Token, TOK_STRING;

void def_names(CrackContext ctx) {
def := ctx.getLocalDefs();
while (!(def is null)) {
while (def !is null) {
name := Token(TOK_STRING, def.getName(), ctx.getLocation());
@xmac* { $name, }.expand(ctx);
def = def.getNext();
Expand Down
4 changes: 2 additions & 2 deletions lib/crack/_poormac.crk
Expand Up @@ -50,8 +50,8 @@ void expand(CrackContext ctx) {
}

# push the tokens back into the stream with argument replacement
for (TokNode elem = m.first; !(elem is null); elem = elem.next)
if (!(elem.tok is null))
for (TokNode elem = m.first; elem !is null; elem = elem.next)
if (elem.tok !is null)
ctx.putBack(elem.tok);
else
ctx.putBack(args[elem.arg]);
Expand Down
26 changes: 13 additions & 13 deletions lib/crack/ann.crk
Expand Up @@ -243,7 +243,7 @@ class NodeListImpl : NodeList {
}

Location getLocation() {
if (!(loc is null))
if (loc !is null)
return loc;
else if (first)
return first.getLocation();
Expand Down Expand Up @@ -1048,7 +1048,7 @@ class Type {
if (!tok.isIdent())
ctx.error(tok, 'Identifier expected for type name'.buffer);
String name = {tok.getText()};
if (!(result is null))
if (result !is null)
result.pushHead(Tok(tok));

Array[Type] params;
Expand All @@ -1057,12 +1057,12 @@ class Type {

# got a left bracket, parse the type parameters
params = Array[Type]();
if (!(result is null))
if (result !is null)
result.pushHead(Tok(tok));
while (true) {
params.append(Type.parse(ctx, result));
tok = ctx.getToken();
if (!(result is null))
if (result !is null)
result.pushHead(Tok(tok));
if (tok.isRBracket()) {
break;
Expand Down Expand Up @@ -1323,7 +1323,7 @@ void property(CrackContext ctx) {
if (StaticString(tok.getText()) == "get") {
getter = readBlock(ctx);
} else if (StaticString(tok.getText()) == "set") {
if (!(readonlyAttr is null)) {
if (readonlyAttr !is null) {
ctx.error(tok, "readonly properties cannot have setters defined".buffer);
}
setter = readBlock(ctx);
Expand Down Expand Up @@ -1440,21 +1440,21 @@ void interface(CrackContext ctx) {
f `{
@abstract Object oper from $(nameTok.getText())();
@final oper bind() {
if (!(this is null))
if (this !is null)
this.oper from $(nameTok.getText())().oper bind();
}
@final oper release() {
if (!(this is null))
if (this !is null)
this.oper from $(nameTok.getText())().oper release();
}
@final oper to Object() {
if (!(this is null))
if (this !is null)
return this.oper from $(nameTok.getText())();
else
return null;
}
@final oper to bool() {
return !(this is null) &&
return this !is null &&
this.oper from $(nameTok.getText())().isTrue();
}
`;
Expand Down Expand Up @@ -1616,7 +1616,7 @@ void token_str(CrackContext ctx) {
NodeList deserializeNodeList(String tokens) {
ser := TokSerializer(tokens.buffer, tokens.size);
list := NodeListImpl(ser.getLocation());
while (!((tok := ser.getToken()) is null))
while ((tok := ser.getToken()) !is null)
list.pushHead(Tok(tok));
return list;
}
Expand Down Expand Up @@ -1732,7 +1732,7 @@ XMacro deserializeXMac(String tokens) {
TreeMap[String, _ArgDef] vars = {};
bool gotDollar;
int lastArgIndex;
while (!((tok := ser.getToken()) is null)) {
while ((tok := ser.getToken()) !is null) {
if (gotDollar) {
if (tok.isIdent()) {

Expand Down Expand Up @@ -1771,8 +1771,8 @@ TreeMap[String, uint] _getVarNames(NodeList nodes) {
Token lastTok;
for (node :in nodes) {
tok := (t := Tok.cast(node, null)) ? t.tok : null;
if (!(tok is null) && tok.isDollar()) {
if (!(lastTok is null) && lastTok.isIdent())
if (tok !is null && tok.isDollar()) {
if (lastTok !is null && lastTok.isIdent())
result[String(lastTok.getText())] = 1;
else
throw _ParseError(lastTok, "Identifier expected after '$'");
Expand Down
7 changes: 2 additions & 5 deletions lib/crack/cmdline.crk
Expand Up @@ -329,13 +329,10 @@ class CmdOptions {
result.name = arg.slice(2, eqi);
result.value = arg.slice(eqi+1);
} else {
if (!((argVal := arg.getSuffix('--enable-')) is null)) {
if ((argVal := arg.getSuffix('--enable-')) !is null) {
result.name = argVal;
result.value = "b/1";
} else if (!( (argVal := arg.getSuffix("disable-")) is
null
)
) {
} else if ((argVal := arg.getSuffix("disable-")) !is null) {
result.name = argVal;
result.value = "b/0";
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/crack/cont/array.crk
Expand Up @@ -260,7 +260,7 @@ class Array[Elem] {
}

oper del() {
if (!(__rep is null)) {
if (__rep !is null) {
if (__cap && _isObject(__rep[0])) {
for (uint i = 0; i < __size; ++i) {
_release(__rep[i]);
Expand Down
4 changes: 2 additions & 2 deletions lib/crack/cont/hashmap.crk
Expand Up @@ -841,11 +841,11 @@ $expected`);
throw AssertionError('head has a prev');
Item last;
while (cur) {
if (!(cur.prev is last))
if (cur.prev !is last)
throw AssertionError('Previous is not the last element');

index := __findSlot(cur._hash, cur.key);
if (!(_items[index] is cur))
if (_items[index] !is cur)
throw AssertionError('Item is not in its slot');

last = cur;
Expand Down
2 changes: 1 addition & 1 deletion lib/crack/cont/treemap.crk
Expand Up @@ -394,7 +394,7 @@ class TreeMap[KeyT, ValT] {
}

# move the contents of the new node to this node
if (!(node is this)) {
if (node !is this) {
key = node.key;
val = node.val;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/crack/crypt/ssl/cipher.crk
Expand Up @@ -143,7 +143,7 @@ class EncryptWriter @impl Writer {
}

void close() {
if (!(__out is null)) {
if (__out !is null) {
__ctx.encryptFinal(__buf.buffer, __size);
__buf.size = __size[0];
__out.write(__buf);
Expand Down Expand Up @@ -182,7 +182,7 @@ class DecryptWriter @impl Writer {
}

void close() {
if (!(__out is null)) {
if (__out !is null) {
__ctx.decryptFinal(__buf.buffer, __size);
__buf.size = __size[0];
__out.write(__buf);
Expand Down
8 changes: 4 additions & 4 deletions lib/crack/db/lmdb.crk
Expand Up @@ -183,11 +183,11 @@ class Iter {
bool isTrue() { return _status == MDB_SUCCESS; }

oper del() {
if (!(_cursor is null)) {
if (_cursor !is null) {
mdb_cursor_close(_cursor);
}

if (!(_txn is null)) {
if (_txn !is null) {
mdb_txn_abort(_txn);
}
free(_ival);
Expand Down Expand Up @@ -276,7 +276,7 @@ class InnerDB {
/// Commits a write transaction if one was started using startWriteTransaction
bool endWriteTransaction() {
if (writing) {
if (!(_writeTx is null)) {
if (_writeTx !is null) {
mdb_txn_commit(_writeTx);
_writeTx = null;
}
Expand Down Expand Up @@ -687,7 +687,7 @@ class Lmdb {

void close(String name) {
InnerDB idb = _dbs.get(name, null);
if (!(idb is null)) {
if (idb !is null) {
idb.close();
_dbs.delete(name);
}
Expand Down
16 changes: 8 additions & 8 deletions lib/crack/db/mongo.crk
Expand Up @@ -245,7 +245,7 @@ class BSON {

void _initType() {
c := bson_cursor_new(_b);
if (!(c is null)) {
if (c !is null) {
_type = bson_cursor_type(c);
bson_cursor_free(c);
}
Expand Down Expand Up @@ -295,7 +295,7 @@ class BSON {

// Free the memory associated with a BSON object.
oper del() {
if (!(_b is null)) bson_free(_b);
if (_b !is null) bson_free(_b);
}

// Return the size of a finished BSON object.
Expand Down Expand Up @@ -520,7 +520,7 @@ class BSON {
String getBinary() {
String crackBuf;
bufStruct b = bson_cursor_get_binary(_c);
if (!(b is null)) {
if (b !is null) {
crackBuf = String(b.data, b.size, true);
free(b); // Keep the data, not the container
}
Expand Down Expand Up @@ -631,10 +631,10 @@ class MongoSync {
}

bool connect(CString address, int port, bool slaveOK) {
if (!(_m is null))
if (_m !is null)
throw InvalidStateError("Already connected");
_m = mongo_sync_connect(address.buffer, port, slaveOK);
return !(_m is null);
return _m !is null;
}

// Add a seed to an existing MongoDB connection.
Expand All @@ -651,7 +651,7 @@ class MongoSync {

// Close and free a synchronous MongoDB connection.
void disconnect() {
if (!(_m is null)) mongo_sync_disconnect(_m);
if (_m !is null) mongo_sync_disconnect(_m);
_m = null;
}

Expand Down Expand Up @@ -893,7 +893,7 @@ class MongoSync {


oper del() {
if (!(_c is null))
if (_c !is null)
mongo_sync_cursor_free (_c);
}
}
Expand Down Expand Up @@ -932,7 +932,7 @@ class MongoSync {
BSON query, BSON sel) {
bson bquery = query is null ? bson_new() : query.get_bson();
bson bsel;
if (!(sel is null)) bsel = sel.get_bson();
if (sel !is null) bsel = sel.get_bson();

p := mongo_sync_cmd_query (_m, ns.buffer, flags, skip, ret, bquery, bsel);
if (query is null) bson_free(bquery);
Expand Down
2 changes: 1 addition & 1 deletion lib/crack/db/mongo_support.crk
Expand Up @@ -18,7 +18,7 @@ class OID : ManagedBuffer {

oper init(Buffer newdata) : ManagedBuffer(12) {
size = 12;
if (!(newdata is null)) {
if (newdata !is null) {
if (newdata.size != 12)
throw InvalidArgumentError("BSON OID objects must have size 12");
memcpy(buffer, newdata.buffer, newdata.size);
Expand Down
8 changes: 4 additions & 4 deletions lib/crack/enc/json/parser.crk
Expand Up @@ -347,14 +347,14 @@ uint JSON_value_en_main = 1;
}

res = parseFloat(p, pe);
if (!(res is null)) {
if (res !is null) {
result = res.result;
p = ( res.p) - 1; //EXEC

}

res = parseInteger(p, pe);
if (!(res is null)) {
if (res !is null) {
result = res.result;
p = ( res.p) - 1; //EXEC

Expand Down Expand Up @@ -1080,7 +1080,7 @@ uint JSON_string_en_main = 1;
# end of execute block
# line 405 "opt/json.rl"

if (cs >= JSON_string_first_final && !(result is null)) {
if (cs >= JSON_string_first_final && result !is null) {
return ParserResult(result, p + 1);
} else {
return null;
Expand Down Expand Up @@ -1551,7 +1551,7 @@ uint JSON_object_en_main = 1;


} else {
if (!(lastName is null))
if (lastName !is null)
result[lastName] = res.result;
else
throw ParseException(FStr() `No key for mapping`, line, col);
Expand Down
2 changes: 1 addition & 1 deletion lib/crack/exp/bindings.crk
Expand Up @@ -13,7 +13,7 @@ class Opaque : VTableBase {
die('attempted to construct opaque class');
}

oper to bool() { return !(this is null); }
oper to bool() { return this !is null; }
};

class Wrapper : FreeBase {
Expand Down
10 changes: 5 additions & 5 deletions lib/crack/exp/cmd/ann.crk
Expand Up @@ -75,7 +75,7 @@ class CommandArgs {
}

Token getParentName() {
return !(__parentName is null) ?
return __parentName !is null ?
__parentName :
Token(TOK_IDENT, 'parent'.buffer,
parentType.getLocation()
Expand Down Expand Up @@ -190,9 +190,9 @@ NodeList emitFieldsAsArgInfoArray(Array[Arg] args) {

name := Token(TOK_STRING, arg.name.getText(), arg.name.getLocation());
type := arg.type;
hasDefaultValue := !(arg.default is null) ? @tokens { true } :
@tokens { false };
defaultValue := !(arg.default is null) ?
hasDefaultValue := arg.default !is null ? @tokens { true } :
@tokens { false };
defaultValue := arg.default !is null ?
arg.default :
Token(TOK_NULLKW, 'null'.buffer,
arg.name.getLocation()
Expand Down Expand Up @@ -439,7 +439,7 @@ void command(CrackContext ctx) {
}

NodeList convertersBinder;
if (!(commandArgs.converters is null)) {
if (commandArgs.converters !is null) {
converters := commandArgs.converters;
convertersBinder = @xmac* { $converters }.expand();
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/crack/exp/dir.crk
Expand Up @@ -55,7 +55,7 @@ class Directory : Object, Openable {

cn := CString(name);
_dir = opendir(cn.buffer);
_isValid = !(_dir is null);
_isValid = _dir !is null;
_isOpened = true;

if (!_isValid)
Expand Down

0 comments on commit 6e03816

Please sign in to comment.