Ada aspects which are private to a package -
Assume that I have the most stupid ring buffer in the world.
Size: Stable: = 16; Subtype T is integer; Package RingBuffer Push Process (value: T); Function Returns Pop; End; Package Body RingBuffer buffer: array of t (0 ... size); Readptr: Integer: = 0; Writeptr: integer: = 1; Process Push (value: T) buffer start (writeptr): = value; Writeptr: = (writeptr + 1) modern shape; End; Function Pop Returns Start T REPTR: = (PHTPTR + 1) Mod Sizes; Return buffer (PETPTR); End; End; Because my code is useless, I want to add pre-condition and postcinding so that I do not abuse it. Therefore, I change the implementation of Push as follows:
Process Push (value: T) with pre = & gt; Readptr / = writeptr is the starting buffer (writeptr): = value; Writeptr: = (writeptr + 1) modern shape; End; However, I get a compilation error because I have to introduce the introduction definitions in the process announcement, not in the implementation.
The thing is a package is that my announcement is public, the predefined values are related to the package body, which is not visible for the announcement. In order to keep the definition of aspect in the announcement, I want to refactor my code to expose the details of implementation in the public part of the package (in this case, readptr and writeptr < / code>). And I do not want to do this. I can think of some ways around it, like my push () a private PushImpl () process only in that body Is defined which is the pre-condition ... but it is terrible what is the right way to do it?
I think this will always be a problem when verification checks are private, and to check it To declare a function for:
The package RingBuffer function is Is_Full return Boolean; Process Push (value: T) with pre = & gt; Not Is_Full; Function Returns Pop; ( Is_Full is probably useful anyway; in other cases this can not happen). If you leave the implementation in the package body, youâ € ™ ll also have to enter Is_Full , but you can take them into the spec and using the expression function Can: Package RingBuffer function is_Full return boolean; Process Push (value: T) with pre = & gt; Not Is_Full; Function Returns Pop; Private buffer: array of T (0..size); Readptr: Integer: = 0; Writeptr: integer: = 1; The function is_Full return boolean (readptr = writewriter); Ending buffer;
Comments
Post a Comment