Skip to content

Commit

Permalink
Fixed various Xcode+Clang warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aardappel committed Dec 10, 2022
1 parent 755494e commit bcea80e
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 67 deletions.
2 changes: 1 addition & 1 deletion lobster/src/lobster/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ struct CodeGen {
Emit((int)ownedvars.size());
for (auto si : ownedvars) Emit(si);
auto profile = sf.attributes.find("profile");
if (LOBSTER_FRAME_PROFILER && profile != sf.attributes.end()) {
if (profile != sf.attributes.end() && LOBSTER_FRAME_PROFILER) {
EmitOp(IL_PROFILE);
auto str = string(profile->second);
if (str.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion lobster/src/lobster/slaballoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class SlabAlloc {
loopdllist(usedpages, h) {
h->isfree = (char *)calloc((size_t)numobjs(h->size), 1);
}
for (iint i = 0; i < MAXBUCKETS; i++) {
for (iint i = 1; i < MAXBUCKETS; i++) {
loopdllist(reuse[i], n) {
PageHeader *page = ppage(n);
page->isfree[(((char *)n) - ((char *)(page + 1))) / (i * ALIGN)] = 1;
Expand Down
4 changes: 4 additions & 0 deletions lobster/src/lobster/typecheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,8 @@ struct TypeChecker {
if (errn) Error(*errn, "could not resolve type variable ", Q(type->tv->name));
break;
}
default:
break;
}
return type;
}
Expand Down Expand Up @@ -3133,6 +3135,8 @@ Node *NativeCall::TypeCheck(TypeChecker &tc, size_t /*reqret*/) {
: tc.NewTypeVar();
assert(rlt == LT_KEEP);
break;
default:
break;
}
// This allows the 0th retval to inherit the type of the 0th arg, and is
// a bit special purpose..
Expand Down
1 change: 1 addition & 0 deletions lobster/src/lobster/wfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ template<typename T> bool WaveFunctionCollapse(const int2 &insize, const char **
for (size_t i = 0; i < tiles.size(); i++)
if (cell.wf & to_bitmask(i))
total_freq += tiles[i].freq;
assert(total_freq);
auto freqpick = rnd.rnd_int(total_freq);
// Now pick.
size_t picked = 0;
Expand Down
8 changes: 4 additions & 4 deletions lobster/src/tocpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ string ToCPP(NativeRegistry &natreg, string &sd, string_view bytecode_buffer, bo
ip = code + 3; // Past first IL_JUMP.
const int *funstart = nullptr;
int nkeepvars = 0;
int ndefsave = 0;
string sdt, sp;
int opc = -1;
const int *args = nullptr;
Expand All @@ -180,7 +179,6 @@ string ToCPP(NativeRegistry &natreg, string &sd, string_view bytecode_buffer, bo
if (opc == IL_FUNSTART || is_start) {
funstart = args;
nkeepvars = 0;
ndefsave = 0;
sdt.clear();
has_profile = false;
auto it = function_lookup.find(id);
Expand All @@ -197,7 +195,7 @@ string ToCPP(NativeRegistry &natreg, string &sd, string_view bytecode_buffer, bo
auto nargs_fun = *fip++;
auto nargs = fip;
fip += nargs_fun;
ndefsave = *fip++;
int ndefsave = *fip++;
auto defs = fip;
fip += ndefsave;
nkeepvars = *fip++;
Expand Down Expand Up @@ -240,7 +238,7 @@ string ToCPP(NativeRegistry &natreg, string &sd, string_view bytecode_buffer, bo
}
}
fip += nargs_fun;
ndefsave = *fip++;
int ndefsave = *fip++;
for (int i = 0; i < ndefsave; i++) {
// for most locals, this just saves an nil, only in recursive cases it has an actual
// value.
Expand Down Expand Up @@ -362,6 +360,7 @@ string ToCPP(NativeRegistry &natreg, string &sd, string_view bytecode_buffer, bo
case IL_RETURNNONLOCAL:
case IL_RETURNANY: {
// FIXME: emit epilogue stuff only once at end of function.
assert(funstart);
auto fip = funstart;
fip++; // function id.
fip++; // regs_max.
Expand Down Expand Up @@ -499,6 +498,7 @@ string ToCPP(NativeRegistry &natreg, string &sd, string_view bytecode_buffer, bo
for (int i = 0; i < nkeepvars; i++) {
append(sd, " DecVal(vm, keepvar[", i, "]);\n");
}
assert(funstart);
if (*(funstart - 2) == IL_FUNSTART && runtime_checks >= RUNTIME_ASSERT_PLUS) {
append(sd, " PopFunId(vm);\n");
}
Expand Down
1 change: 1 addition & 0 deletions lobster/src/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ string VM::MemoryUsage(size_t show_max) {
totalgpu += p.second.gpu;
}
sort(sorted.begin(), sorted.end(), _UsageSorter);
if (!total) return sd;
append(sd, "TOTAL: ", total / 1024, " K (", totalgpu * 100 / total, "% on GPU)\n");
for (auto [i, p] : enumerate(sorted)) {
if (i >= show_max || p.second.bytes < 1024) break;
Expand Down
4 changes: 4 additions & 0 deletions lobster/src/vmdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ void Value::ToFlexBuffer(VM &vm, flexbuffers::Builder &builder, ValueType t) con
case V_FLOAT:
builder.Double(fval());
return;
default:
break;
}
if (IsRefNil(t)) {
if (!ref_) {
Expand All @@ -304,6 +306,8 @@ void Value::ToFlexBuffer(VM &vm, flexbuffers::Builder &builder, ValueType t) con
case V_CLASS:
oval()->ToFlexBuffer(vm, builder);
return;
default:
break;
}
}
string sd;
Expand Down
14 changes: 11 additions & 3 deletions osx/TreeSheets/TreeSheets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
33306EF017695EE900AF5315 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33306EEB17695EE900AF5315 /* AudioToolbox.framework */; };
33306EF117695EE900AF5315 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33306EEC17695EE900AF5315 /* Carbon.framework */; };
33306EF217695EE900AF5315 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33306EED17695EE900AF5315 /* IOKit.framework */; };
33306EF317695EE900AF5315 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33306EEE17695EE900AF5315 /* OpenGL.framework */; };
33306EF91769625C00AF5315 /* images in Resources */ = {isa = PBXBuildFile; fileRef = 33306EF51769625C00AF5315 /* images */; };
33306EFA1769625C00AF5315 /* docs in Resources */ = {isa = PBXBuildFile; fileRef = 33306EF61769625C00AF5315 /* docs */; };
33306EFB1769625C00AF5315 /* examples in Resources */ = {isa = PBXBuildFile; fileRef = 33306EF71769625C00AF5315 /* examples */; };
Expand All @@ -37,7 +36,7 @@
3387FFDF204C5FBF00612ED7 /* lobster_impl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3387FFDC204C5FBE00612ED7 /* lobster_impl.cpp */; };
33B01131286CCC0100974382 /* tocpp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33B0112F286CCC0100974382 /* tocpp.cpp */; };
33B01132286CCC0100974382 /* tccbind.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33B01130286CCC0100974382 /* tccbind.cpp */; };
33B01134286CD56800974382 /* libtcc.c in Sources */ = {isa = PBXBuildFile; fileRef = 33B01133286CD56800974382 /* libtcc.c */; };
33B01134286CD56800974382 /* libtcc.c in Sources */ = {isa = PBXBuildFile; fileRef = 33B01133286CD56800974382 /* libtcc.c */; settings = {COMPILER_FLAGS = "-w -Xanalyzer -analyzer-disable-all-checks"; }; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -117,6 +116,7 @@
33B0112F286CCC0100974382 /* tocpp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tocpp.cpp; path = ../../lobster/src/tocpp.cpp; sourceTree = "<group>"; };
33B01130286CCC0100974382 /* tccbind.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tccbind.cpp; path = ../../lobster/src/tccbind.cpp; sourceTree = "<group>"; };
33B01133286CD56800974382 /* libtcc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = libtcc.c; path = ../../lobster/external/libtcc/libtcc.c; sourceTree = "<group>"; };
33B2E7A12944FBB300C1167A /* wfc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wfc.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -128,7 +128,6 @@
33306EF117695EE900AF5315 /* Carbon.framework in Frameworks */,
330D5CE12641E0420010ADFE /* QuartzCore.framework in Frameworks */,
33306EF217695EE900AF5315 /* IOKit.framework in Frameworks */,
33306EF317695EE900AF5315 /* OpenGL.framework in Frameworks */,
33306EBF17695BE000AF5315 /* Cocoa.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -271,6 +270,7 @@
3387FFF7204C5FE600612ED7 /* lobster */ = {
isa = PBXGroup;
children = (
33B2E7A12944FBB300C1167A /* wfc.h */,
3387FFF8204C5FE600612ED7 /* slaballoc.h */,
3387FFF9204C5FE600612ED7 /* typecheck.h */,
3387FFFA204C5FE600612ED7 /* tocpp.h */,
Expand Down Expand Up @@ -513,12 +513,14 @@
33306ED917695BE000AF5315 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD)";
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
GCC_INLINES_ARE_PRIVATE_EXTERN = NO;
GCC_PRECOMPILE_PREFIX_HEADER = NO;
GCC_PREFIX_HEADER = "";
GCC_PREPROCESSOR_DEFINITIONS = (
Expand All @@ -530,6 +532,7 @@
__WXOSX__,
__WXOSX_COCOA__,
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
GCC_WARN_PEDANTIC = NO;
HEADER_SEARCH_PATHS = (
Expand All @@ -539,6 +542,7 @@
INFOPLIST_FILE = "TreeSheets/TreeSheets-Info.plist";
MACOSX_DEPLOYMENT_TARGET = 10.15;
ONLY_ACTIVE_ARCH = NO;
OTHER_CFLAGS = "";
OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)";
OTHER_LDFLAGS = (
"-L/usr/local/lib",
Expand Down Expand Up @@ -573,12 +577,14 @@
33306EDA17695BE000AF5315 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD)";
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
GCC_INLINES_ARE_PRIVATE_EXTERN = NO;
GCC_PRECOMPILE_PREFIX_HEADER = NO;
GCC_PREFIX_HEADER = "";
GCC_PREPROCESSOR_DEFINITIONS = (
Expand All @@ -587,6 +593,7 @@
__WXOSX__,
__WXOSX_COCOA__,
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
GCC_WARN_PEDANTIC = NO;
HEADER_SEARCH_PATHS = (
Expand All @@ -595,6 +602,7 @@
);
INFOPLIST_FILE = "TreeSheets/TreeSheets-Info.plist";
MACOSX_DEPLOYMENT_TARGET = 10.15;
OTHER_CFLAGS = "";
OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)";
OTHER_LDFLAGS = (
"-L/usr/local/lib",
Expand Down
8 changes: 4 additions & 4 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,6 @@ struct Document {

const wxChar *Key(wxDC &dc, wxChar uk, int k, bool alt, bool ctrl, bool shift,
bool &unprocessed) {
Cell *c = selected.GetCell();
if (uk == WXK_NONE || (k < ' ' && k)) {
switch (k) {
case WXK_BACK: // no menu shortcut available in wxwidgets
Expand Down Expand Up @@ -818,7 +817,8 @@ struct Document {
}
} else if (uk >= ' ') {
if (!selected.g) return NoSel();
if (!(c = selected.ThinExpand(this))) return OneCell();
Cell *c = selected.ThinExpand(this);
if (!c) return OneCell();
ShiftToCenter(dc);
c->AddUndo(this); // FIXME: not needed for all keystrokes, or at least, merge all
// keystroke undos within same cell
Expand Down Expand Up @@ -1731,8 +1731,8 @@ struct Document {
void PasteSingleText(Cell *c, const wxString &t) { c->text.Insert(this, t, selected); }

void PasteOrDrop() {
Cell *c = selected.GetCell();
if (!(c = selected.ThinExpand(this))) return;
Cell *c = selected.ThinExpand(this);
if (!c) return;
wxBusyCursor wait;
switch (dataobjc->GetReceivedFormat().GetType()) {
case wxDF_FILENAME: {
Expand Down
54 changes: 0 additions & 54 deletions src/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,60 +226,6 @@ class Vector : public NonCopyable {
void append(Vector<T> &o) { loopv(i, o) push() = o[i]; }
};

class MTRnd {
const static uint N = 624;
const static uint M = 397;
const static uint K = 0x9908B0DFU;

uint hiBit(uint u) { return u & 0x80000000U; }
uint loBit(uint u) { return u & 0x00000001U; }
uint loBits(uint u) { return u & 0x7FFFFFFFU; }

uint mixBits(uint u, uint v) { return hiBit(u) | loBits(v); }

uint state[N + 1];
uint *next;
int left;

public:
MTRnd() : left(-1) {}

void SeedMT(uint seed) {
uint x = (seed | 1U) & 0xFFFFFFFFU, *s = state;
int j;
for (left = 0, *s++ = x, j = N; --j; *s++ = (x *= 69069U) & 0xFFFFFFFFU)
;
}

uint ReloadMT() {
uint *p0 = state, *p2 = state + 2, *pM = state + M, s0, s1;
int j;
if (left < -1) SeedMT(4357U);
left = N - 1, next = state + 1;
for (s0 = state[0], s1 = state[1], j = N - M + 1; --j; s0 = s1, s1 = *p2++)
*p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
for (pM = state, j = M; --j; s0 = s1, s1 = *p2++)
*p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
s1 = state[0], *p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
s1 ^= (s1 >> 11);
s1 ^= (s1 << 7) & 0x9D2C5680U;
s1 ^= (s1 << 15) & 0xEFC60000U;
return (s1 ^ (s1 >> 18));
}

uint RandomMT() {
uint y;
if (--left < 0) return (ReloadMT());
y = *next++;
y ^= (y >> 11);
y ^= (y << 7) & 0x9D2C5680U;
y ^= (y << 15) & 0xEFC60000U;
return (y ^ (y >> 18));
}

int operator()(int max) { return RandomMT() % max; }
};

// for use with vc++ crtdbg

#if defined(_DEBUG) && defined(_WIN32)
Expand Down

0 comments on commit bcea80e

Please sign in to comment.