Skip to content

Commit

Permalink
Support handling certain casts in expressions
Browse files Browse the repository at this point in the history
This fixes evaluating the DBL_MAX constant in certain glibc versions.
  • Loading branch information
mstorsjo committed Aug 22, 2013
1 parent afbdb1e commit 8c5b06d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,27 @@ static double eval_prim(CXToken *tokens, unsigned *n, unsigned last)
double d;
(*n)++;
clang_disposeString(s);
if (*n + 1 <= last) {
CXString s2;
const char *str2;
s = clang_getTokenSpelling(TU, tokens[*n]);
str = clang_getCString(s);
s2 = clang_getTokenSpelling(TU, tokens[*n + 1]);
str2 = clang_getCString(s2);
// This should ideally recognize all built-in types
// and also check the type name against all typedefs
// (it also doesn't support two word typnames such as structs.
// This is enough for handling double casts in DBL_MAX in
// certain glibc versions though.
if (!strcmp(str2, ")") && !strcmp(str, "double")) {
clang_disposeString(s);
clang_disposeString(s2);
(*n) += 2;
return eval_prim(tokens, n, last);
}
clang_disposeString(s);
clang_disposeString(s2);
}
d = eval_expr(tokens, n, last);
if (*n > last) {
fprintf(stderr, "No right parenthesis found\n");
Expand Down

0 comments on commit 8c5b06d

Please sign in to comment.