Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypedValue - Lack of information #20

Open
tfabbri opened this issue Aug 22, 2016 · 3 comments
Open

TypedValue - Lack of information #20

tfabbri opened this issue Aug 22, 2016 · 3 comments
Milestone

Comments

@tfabbri
Copy link

tfabbri commented Aug 22, 2016

The structure TypedValue presents a lack of information for Union and Record types.
Considering the following example where MyRecord1 and MyRecord2 are two records characterized by different structure:

types
    MyUnion = MyRecord1 | MyRecord2

at C code level is not possible to distinguish between the two types by checking the type field (both are characterized by type=VDM_RECORD).
Possible solution: Add a new field to TypedValue containing the name of the type (alias = 'MyRecord1' and alias='MyRecord2').

@peterwvj peterwvj modified the milestone: Version 0.0.4 Sep 20, 2016
@peterwvj peterwvj modified the milestones: v0.0.6, v0.0.8, 0.0.10 Oct 3, 2016
@peterwvj peterwvj modified the milestones: v0.0.10, v0.0.12, v0.0.14 Nov 15, 2016
@peterwvj peterwvj modified the milestones: v0.0.14, v0.0.16, v0.0.18 Nov 30, 2016
@peterwvj peterwvj removed this from the v0.1.4 milestone Mar 15, 2017
@peterwvj peterwvj modified the milestones: v0.1.6, v0.1.8 May 1, 2017
@tfabbri tfabbri mentioned this issue May 16, 2017
3 tasks
@peterwvj peterwvj modified the milestones: v0.1.8, v0.1.10 Jul 1, 2017
@peterwvj peterwvj modified the milestones: v0.1.10, v0.1.12 Aug 10, 2017
@peterwvj peterwvj modified the milestones: v0.1.12, v0.1.14 Sep 11, 2017
@peterwvj peterwvj modified the milestones: v0.1.14, v0.1.16 Sep 18, 2017
@peterwvj peterwvj modified the milestones: v0.1.16, v0.1.18 Oct 4, 2017
@bandurvp
Copy link
Contributor

The runtime library now supports full is_ type checks, so it is now possible to implement the following:

types
    MyUnion = MyRecord1 | MyRecord2
...
return is_(exp, MyRecord1);

The runtime function is(...) takes as one of its arguments a text encoding of the type being queried, in this case either MyRecord1 or MyRecord2. There is a function in the Java side of VDM2C called IsExpTypeEncoder.encodeType that will emit this encoding. For examples of how this is used, refer to IsExpTypeEncoderTest.java in the Java side of the generator. I think this will give you all the information you need to progress with this. What do you think @tfabbri ?

@tfabbri
Copy link
Author

tfabbri commented Dec 20, 2017

To be honest I do not remember well the issue. The problem was about the support for union types as in #21. Have you developed such support?

@peterwvj
Copy link
Member

peterwvj commented Dec 20, 2017

Not directly, but as Victor said above, you can now generate the char encoding for such types - see #108 (comment) for details. Based on the encoding you can use the is function in the runtime to check if a value is of a given type. IsExpEncoderTest.java contains several examples and shows you how to utilize the encoder, #108 (comment) contains another example that includes union types.

@peterwvj peterwvj modified the milestones: v0.2, v0.2.2 Feb 14, 2018
@peterwvj peterwvj modified the milestones: v0.2.2, v0.2.4 Nov 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants