TelluIoT / ThingML

The ThingML modelling language
https://github.com/TelluIoT/ThingML
Apache License 2.0
102 stars 33 forks source link

Litteral 4294967295 is not parsed #132

Closed nharrand closed 6 years ago

nharrand commented 7 years ago

The following code isn't parsed. Meanwhile if 4294967295 is replaced by '4294967295', it works.

datatype UInt32<4>  
    @c_type "uint32_t"
    @java_type "long"
    @java_primitive "true";

thing TestUInt32 {

    property min : UInt32 = 4294967295

    statechart TestType init S0 {

        state S0 {
            transition -> S1
            guard min == 4294967295
        }
    state S1 {}
    }
}

configuration TestUInt32Cfg {
    instance tT : TestUInt32
}
brice-morin commented 7 years ago

Relates to #156

jakhog commented 6 years ago

I think this issue is to this line in the ThingML grammar (here):

terminal INT returns ecore::EInt: ('0'..'9')+;

It seems that the ecore::EInt type uses ints in Java. And while that sound fine at first, it is actually a problem - since the integer literal only represents the absolute value of the number (it doesn't include the - part).

This means that when you write -2147483648 the parser actually tries to parse 2147483648 - which is outside the range of Java ints.

So - to fix this issue - I think we have to switch to ecore::ELong, and possibly check that the literal is within range somewhere else (either in a custom TerminalConverter, or in the Checker).

jakhog commented 6 years ago

Since I'm not a certified Xtext guru yet - I'll give the responsibility back to the Franck guru