Skip to content

Commit

Permalink
Fix warnings in generated code (#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
scallyw4g committed Jun 26, 2022
1 parent 90d8565 commit 6ef4a41
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cpp/frontend_flag_spec.cc
Expand Up @@ -50,7 +50,7 @@ void _CreateDefaults(DefaultPair_c* in,
val = new value__Float(pair->val.f);
break;
case flag_type_e::Str: {
char* s = pair->val.s;
const char* s = pair->val.s;
if (s == nullptr) {
val = new value__Undef();
} else {
Expand Down
2 changes: 1 addition & 1 deletion cpp/frontend_flag_spec.h
Expand Up @@ -22,7 +22,7 @@ union Val_c {
bool b;
int i;
float f;
char* s;
const char* s;
};

struct DefaultPair_c {
Expand Down
4 changes: 2 additions & 2 deletions cpp/libc.cc
Expand Up @@ -79,10 +79,10 @@ List<Str*>* regex_match(Str* pattern, Str* str) {

int outlen = pat.re_nsub + 1; // number of captures

int match;
const char* s0 = str0.Get();
regmatch_t* pmatch = (regmatch_t*)malloc(sizeof(regmatch_t) * outlen);
if (match = (regexec(&pat, s0, outlen, pmatch, 0) == 0)) {
int match = regexec(&pat, s0, outlen, pmatch, 0) == 0;
if (match) {
int i;
for (i = 0; i < outlen; i++) {
int len = pmatch[i].rm_eo - pmatch[i].rm_so;
Expand Down
4 changes: 4 additions & 0 deletions frontend/consts_gen.py
Expand Up @@ -360,6 +360,7 @@ def out(fmt, *args):
out(' case %s: return %s;' % (a, b))
out("""\
}
InvalidCodePath();
}
""")

Expand All @@ -375,6 +376,7 @@ def out(fmt, *args):
out(' case %s: return %s;' % (a, b))
out("""\
}
InvalidCodePath();
}
""")

Expand All @@ -390,6 +392,7 @@ def out(fmt, *args):
out(' case %s: return %s;' % (a, b))
out("""\
}
InvalidCodePath();
}
""")

Expand All @@ -404,6 +407,7 @@ def out(fmt, *args):
out(' case %s: return %s;' % (a, b))
out("""\
}
InvalidCodePath();
}
""")

Expand Down
10 changes: 4 additions & 6 deletions frontend/lexer_gen.py
Expand Up @@ -209,7 +209,7 @@ def TranslateSimpleLexer(func_name, lexer_def):
const unsigned char* p = line + start_pos; /* modified by re2c */
/* Echo and History lexer apparently need this, but others don't */
const unsigned char* YYMARKER;
__attribute__((unused)) const unsigned char* YYMARKER;
for (;;) {
/*!re2c
Expand Down Expand Up @@ -241,7 +241,7 @@ def TranslateBracket(func_name, token_dict):
const unsigned char* p = s; /* modified by re2c */
const unsigned char* end = s + len;
const unsigned char* YYMARKER;
__attribute__((unused)) const unsigned char* YYMARKER;
int id;
for (;;) {
Expand Down Expand Up @@ -273,8 +273,6 @@ def StringToInt(func_name, name_def):
const unsigned char* p = s; /* modified by re2c */
const unsigned char* end = s + len;
const unsigned char* YYMARKER;
//fprintf(stderr, "*** s = %%s\n", s);
for (;;) {
Expand Down Expand Up @@ -325,7 +323,7 @@ def TranslateOshLexer(lexer_def):
const unsigned char* p = line + start_pos; /* modified by re2c */
//printf("p: %p q: %p\n", p, q);
const unsigned char* YYMARKER; /* why do we need this? */
__attribute__((unused)) const unsigned char* YYMARKER; /* why do we need this? */
switch (lex_mode) {
""")

Expand Down Expand Up @@ -405,7 +403,7 @@ def TranslateRegexToPredicate(py_regex, func_name):
const unsigned char* end = s + len;
/* MatchBraceRangeToken needs this, but others don't */
const unsigned char* YYMARKER;
__attribute__((unused)) const unsigned char* YYMARKER;
/*!re2c
re2c:define:YYCTYPE = "unsigned char";
Expand Down
15 changes: 15 additions & 0 deletions mycpp/mylib.h
Expand Up @@ -29,6 +29,21 @@
#define free dumb_free
#endif

// TODO(Jesse): Put NotImplemented on a compile-time switch such that we cannot
// make a release build if we're not finished implementing the interpreter.
// ie.
//
// #if OIL_INTERNAL
// #define NotImplemented() assert(!"Not Implemented")
// #else
// #define NotImplemented() NOT IMPLENTED !!! // Intentionally a compile error
// #endif
//
//
#define NotImplemented() assert(!"Not Implemented")

#define InvalidCodePath() assert(!"Invalid Code Path")

class Str;

template <class T>
Expand Down

0 comments on commit 6ef4a41

Please sign in to comment.