In Zorba, there is some chaos with the types of length variables. They have the type xqp_long, xqp_ulong, long, ulong, etc.. Therefore, the following warnings are shown if I compile zorba on windows:
src\runtime\sequences\sequences_impl.cpp(477) : warning C4244: '=' : conversion from 'double' to 'zorba::xqp_long', possible loss of data
src\runtime\sequences\sequences_impl.cpp(482) : warning C4244: '=' : conversion from 'double' to 'zorba::xqp_long', possible loss of data
src\runtime\collections\collections_impl.cpp(1165) : warning C4244: 'argument' : conversion from 'zorba::xqp_ulong' to 'ulong', possible loss of data
src\runtime\core\var_iterators.cpp(341) : warning C4244: 'argument' : conversion from 'zorba::xqp_long' to 'ulong', possible loss of data
src\runtime\core\var_iterators.cpp(378) : warning C4244: '=' : conversion from 'zorba::xqp_long' to 'ulong', possible loss of data
src\runtime\core\var_iterators.cpp(379) : warning C4244: '=' : conversion from 'zorba::xqp_long' to 'ulong', possible loss of data
src\runtime\core\var_iterators.cpp(630) : warning C4244: 'argument' : conversion from 'zorba::xqp_long' to 'ulong', possible loss of data
src\runtime\core\var_iterators.cpp(656) : warning C4244: 'argument' : conversion from 'zorba::xqp_long' to 'ulong', possible loss of data
src\runtime\core\var_iterators.cpp(735) : warning C4244: 'argument' : conversion from 'zorba::xqp_long' to 'ulong', possible loss of data
src\runtime\core\var_iterators.cpp(755) : warning C4244: '=' : conversion from 'zorba::xqp_long' to 'ulong', possible loss of data
src\runtime\core\var_iterators.cpp(756) : warning C4244: '=' : conversion from 'zorba::xqp_long' to 'ulong', possible loss of data
src\store\naive\loader_fast.cpp(218) : warning C4244: 'return' : conversion from 'std::streamsize' to 'long', possible loss of data
src\store\naive\loader_dtd.cpp(221) : warning C4244: 'return' : conversion from 'std::streamsize' to 'long', possible loss of data
src\store\naive\loader_dtd.cpp(273) : warning C4244: 'initializing' : conversion from 'std::streamoff' to 'size_t', possible loss of data
Quoting David's email on this:
Unfortunately, this is not a straight forward task because we have a little type mess. For example in src/runtime/ collections/ collections_ impl.cpp: 1164, a xs_ulong is subtracted from a ulong and the result passed to a function that accepts ulong. Therefore, a warning is shown on Windows.
We have several situations like this in runtime code. I think, we should forbid to cast away XQuery types in the runtime. Especially if they are passed via XQuery function parameters to the runtime. I think, the only reason why these castings are done is because of the implementation of the store (e.g. the nodes of a collection are saved in a vector ...). Therefore, the castings should be done inside the store and not outside. They are store implementation dependent. Thus, store functions like Collection: :nodeAt( ...) should expect XQuery types. xs_integer or xs_unsignedLong. And in the long run, the store should throw an error if it detects an overflow. Or maybe, it is able to handle XQuery types some day and does not have to cast them at all. But the decision what to do with the XQuery types should be taken by the store only!
This change would also have consequences to the Zorba API. E.g. Collection::size() returns an unsigned long currently. But the fn:count function of XQuery returns xs:integer. I think, Collection::size() should return xs:integer too. I am not sure if the value should be returned wrapped in an Item or as a value of the type xs_integer. But it should definitely be returned without being casted to different type.