368 token = string; |
368 token = string; |
369 } |
369 } |
370 |
370 |
371 // ============================================================================ |
371 // ============================================================================ |
372 void ScriptReader::MustNumber (bool fromthis) { |
372 void ScriptReader::MustNumber (bool fromthis) { |
373 str num; |
|
374 if (!fromthis) |
373 if (!fromthis) |
375 MustNext (); |
374 MustNext (); |
376 num += token; |
|
377 |
375 |
378 // "true" and "false" are valid numbers |
376 // "true" and "false" are valid numbers |
379 if (!token.icompare ("true")) |
377 if (!token.icompare ("true")) |
380 token = "1"; |
378 token = "1"; |
381 else if (!token.icompare ("false")) |
379 else if (!token.icompare ("false")) |
382 token = "0"; |
380 token = "0"; |
383 else { |
381 else { |
384 if (!num.isnumber()) |
382 if (!token.isnumber()) |
385 ParserError ("expected a number, got `%s`", num.chars()); |
383 ParserError ("expected a number, got `%s`", token.chars()); |
386 token = num; |
384 |
387 |
|
388 // Overflow check |
|
389 str check; |
385 str check; |
390 check.appendformat ("%d", atoi (num)); |
386 check.appendformat ("%d", atoi (token)); |
391 if (token.compare (check) != 0) |
387 if (token.compare (check) != 0) |
392 ParserWarning ("integer too large: %s -> %s", token.chars(), check.chars()); |
388 ParserWarning ("integer too large: %s -> %s", token.chars(), check.chars()); |
393 } |
389 } |
394 } |
390 } |