Skip to content

Commit

Permalink
Large integer literals (> 31 bits) are converted to Real literals.
Browse files Browse the repository at this point in the history
Added testcase for flat parsing (more needed later on).

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2581 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Oct 24, 2006
1 parent 8c092d8 commit d6fb48c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Compiler/absyn_builder/walker.g
Expand Up @@ -130,9 +130,16 @@ tokens {
return keywords;
}
int str_to_int(mstring const& str)
int str_to_int(mstring const& str, int *res)
{
return atoi(str.c_str());
unsigned long int ltmp;
char *rest;
ltmp = strtoul(str.c_str(),&rest,10);
if (ltmp > (1<<30)) { /* Rml can only handle 31 bits signed integers, i.e. 30 bits signed*/
return -1;
}
*res = (int) ltmp;
return 0;
}
double str_to_double(std::string const& str)
Expand Down Expand Up @@ -1854,7 +1861,12 @@ primary returns [void* ast]
:
( ui:UNSIGNED_INTEGER
{
ast = Absyn__INTEGER(mk_icon(str_to_int(ui->getText())));
int v;
if(str_to_int(ui->getText(),&v)== 0) {
ast = Absyn__INTEGER(mk_icon(v));
} else {
ast = Absyn__REAL(mk_rcon(str_to_double(ui->getText())));
}
}
| ur:UNSIGNED_REAL
{
Expand Down

0 comments on commit d6fb48c

Please sign in to comment.