/tutorial/manifest_notation.e

http://github.com/tybor/Liberty · Specman e · 459 lines · 308 code · 66 blank · 85 comment · 3 complexity · dfcdb4db9767c4836c180b105379bc13 MD5 · raw file

  1. class MANIFEST_NOTATION
  2. --
  3. -- To know more or to discover manifest notation syntax and semantic, you
  4. -- can just read this file, or even better, run this code under our debugger:
  5. --
  6. -- se c -sedb manifest_notation -o manifest_notation
  7. -- ./manifest_notation
  8. create {ANY}
  9. make
  10. feature {}
  11. boolean_examples
  12. -- Examples of notations for the BOOLEAN type.
  13. local
  14. boolean: BOOLEAN
  15. do
  16. -- Simply True or False:
  17. boolean := True
  18. boolean := False
  19. check
  20. True -- Is always correct.
  21. end
  22. end
  23. character_examples
  24. -- Examples of notations for the CHARACTER type.
  25. local
  26. character: CHARACTER
  27. do
  28. -- The ordinary notation:
  29. character := 'a'
  30. character := 'b'
  31. character := 'c'
  32. character := 'A'
  33. character := 'B'
  34. character := 'C'
  35. character := '.'
  36. character := '+'
  37. character := '-'
  38. -- The new_line character:
  39. character := '%N'
  40. -- The tab character:
  41. character := '%T'
  42. -- The default initialization value:
  43. character := '%U'
  44. -- The percent itself:
  45. character := '%%'
  46. -- The simple quote:
  47. character := '%''
  48. -- The double quote:
  49. character := '%"'
  50. check
  51. -- The At-sign (just in case you have a strange keyboard ;-)
  52. '@' = '%A'
  53. end
  54. -- The Backspace:
  55. character := '%B'
  56. check
  57. -- Circumflex (just in case you have a strange keyboard ;-)
  58. '^' = '%C'
  59. end
  60. check
  61. -- The dollar sign (just in case you have a strange keyboard ;-)
  62. '$' = '%D'
  63. end
  64. -- The Form feed:
  65. character := '%F'
  66. check
  67. -- The backslasH (just in case you have a strange keyboard ;-)
  68. '\' = '%H'
  69. end
  70. check
  71. -- The tiLda (just in case you have a strange keyboard ;-)
  72. '~' = '%L'
  73. end
  74. check
  75. -- The back Quote
  76. '`' = '%Q'
  77. end
  78. -- The carriage Return
  79. character := '%R'
  80. check
  81. -- The Sharp (just in case you have a strange keyboard ;-)
  82. '#' = '%S'
  83. end
  84. check
  85. -- The Vertical bar (just in case you have a strange keyboard ;-)
  86. '|' = '%V'
  87. end
  88. check
  89. -- The opening bracket (just in case you have a strange keyboard ;-)
  90. '[' = '%('
  91. end
  92. check
  93. -- The closing bracket (just in case you have a strange keyboard ;-)
  94. ']' = '%)'
  95. end
  96. check
  97. -- The opening brace (just in case you have a strange keyboard ;-)
  98. '{' = '%<'
  99. end
  100. check
  101. -- The closing brace (just in case you have a strange keyboard ;-)
  102. '}' = '%>'
  103. end
  104. -- The decimal ascii notation:
  105. character := '%/97/' -- is equivalent to 'a'
  106. character := '%/32/' -- is equivalent to ' '
  107. character := '%/0/'
  108. -- is equivalent to '%U' (which is the default initialization value)
  109. -- The hexadecimal notation:
  110. character := '%/0x30/' -- is equivalent to '0'
  111. character := '%/0x31/' -- is equivalent to '1'
  112. character := '%/0x32/' -- is equivalent to '2'
  113. character := '%/0x00/' -- is equivalent to '%U'
  114. end
  115. string_examples
  116. -- Examples of notations for the STRING type.
  117. local
  118. string: STRING
  119. do
  120. string := "Hello!"
  121. string := "The escape percent for new-line %N (try to print it).%N"
  122. string := "The escape percent for tab: %T <- its a tab%N"
  123. string := "As you may guess %% <- its a percent"
  124. string := "As you may guess %" <- its a double quote !"
  125. string := "When the string is too long you%
  126. %can continue on more than one line"
  127. string := "{
  128. Look this verbatim two lines string using
  129. our debugger !
  130. }"
  131. string := "[
  132. Look left-aligned verbatim string using
  133. our debugger !
  134. ]"
  135. string := "{
  136. No escape percent in %T verbatim
  137. %N strings !
  138. ... cool.
  139. }"
  140. -- Hexadecimal notation is available too:
  141. string := "One %/0x43414645/ pl%/0x65/ase"
  142. sedb_breakpoint
  143. -- Use the -sedb option to view the string !
  144. -- Finally, keep in mind that "once" can precede the STRING
  145. -- notation to avoid multiple allocations:
  146. string := once "I am allocated once even when used inside a loop !"
  147. end
  148. unicode_string_examples
  149. -- Examples of notations for the UNICODE_STRING type.
  150. local
  151. unicode_string: UNICODE_STRING
  152. do
  153. unicode_string := U"I am not a STRING, but a UNICODE_STRING !"
  154. unicode_string := U"<- the big U indicates that."
  155. unicode_string := U"{
  156. As for STRING, you can write UNICODE_STRING on
  157. more
  158. than
  159. one
  160. line with the verbatim notation.
  161. }"
  162. -- Inside UNICODE_STRING only, you have the Ux notation to denote
  163. -- any character you want (http://www.unicode.org):
  164. unicode_string := U"The EURO sign is %/Ux20AC/!%N"
  165. end
  166. integer_examples
  167. local
  168. integer_8: INTEGER_8; integer_16: INTEGER_16; integer_32: INTEGER_32; integer_64: INTEGER_64
  169. integer: INTEGER
  170. do
  171. -- 0 is of type INTEGER_8:
  172. integer_8 := 0
  173. -- The minimum value for INTEGER_8:
  174. integer_8 := -128
  175. -- The maximum value for INTEGER_8:
  176. integer_8 := 127
  177. inspect
  178. integer_8
  179. when -128 .. 127 then
  180. -- The INTEGER_8 range
  181. -- We should always go here...
  182. else
  183. check
  184. False -- ... and never here !
  185. end
  186. end
  187. -- The INTEGER_16 range:
  188. integer_16 := -32768
  189. integer_16 := 32767
  190. -- The INTEGER_32 range:
  191. integer_32 := -2147483648
  192. integer_32 := 2147483647
  193. -- INTEGER is, at time being, equivalent to INTEGER_32:
  194. integer := integer_32
  195. integer := 0
  196. integer_32 := integer
  197. -- INTEGER_64 range:
  198. integer_64 := -9223372036854775808
  199. integer_64 := 9223372036854775807
  200. -- Now using the hexadecimal notation to denote INTEGER.
  201. -- A 2 hexadecimal digit denote an INTEGER_8.
  202. -- Setting all bits of an INTEGER_8 is achieved with:
  203. integer_8 := 0xFF
  204. check
  205. integer_8 = -1
  206. end
  207. -- A 4 hexadecimal digit denote an INTEGER_16.
  208. -- As an example, the greater positive value for an INTEGER_16 is:
  209. integer_16 := 0x7FFF
  210. check
  211. integer_16 = 32767
  212. end
  213. -- A 8 hexadecimal digit denote an INTEGER_32.
  214. -- As an example, the smallest negative value for an INTEGER_32 is:
  215. integer_32 := 0x80000000
  216. check
  217. integer_32 = -2147483648
  218. end
  219. -- A 16 hexadecimal digit denote an INTEGER_64.
  220. -- The `Maximum_integer_64':
  221. integer_64 := 0x7FFFFFFFFFFFFFFF
  222. check
  223. integer_64 = 9223372036854775807
  224. end
  225. -- The `Minimum_integer_64':
  226. integer_64 := 0x8000000000000000
  227. check
  228. integer_64 = -9223372036854775808
  229. end
  230. -- When you need to do so, the complete type notation can also be used for all kinds
  231. -- of INTEGERs:
  232. integer_32 := {INTEGER_32 1}
  233. check
  234. integer_32 = 1
  235. end
  236. integer_16 := {INTEGER_16 0xFFFF}
  237. check
  238. integer_16 = -1
  239. end
  240. end
  241. real_examples
  242. local
  243. real_32: REAL_32; real_64: REAL_64; real: REAL; real_extended: REAL_EXTENDED
  244. do
  245. -- At time being, REAL is equivalent of REAL_64. The classic notation always
  246. -- denote a REAL (i.e. a REAL_64):
  247. real := 0.0
  248. real_64 := 0.0
  249. check
  250. real = real_64
  251. end
  252. real_64 := 35.5
  253. -- The scientific notation is possible too:
  254. real_64 := 3.55e+1
  255. check
  256. real_64 = 35.5
  257. end
  258. -- You can omit the fractional part when using scientific notation:
  259. check
  260. 3E2 = 300.0
  261. end
  262. -- In order to denote a REAL_32, you must always rely on the explicit following notation:
  263. real_32 := {REAL_32 1.5}
  264. real_32 := {REAL_32 156.5E-2}
  265. -- You can as well denote REAL_80, REAL_128 or REAL_EXTENDED:
  266. real_extended := {REAL_EXTENDED 156.5E-287}
  267. end
  268. array_examples
  269. local
  270. array_of_character: ARRAY[CHARACTER]; array_of_integer: ARRAY[INTEGER]
  271. do
  272. -- A four elements ARRAY[CHARACTER] with the lower bound set to 1:
  273. array_of_character := {ARRAY[CHARACTER] 1, << 'a', 'b', 'c', 'd', 'e' >> }
  274. -- A three elements ARRAY[INTEGER] with the lower bound set to -1:
  275. array_of_integer := {ARRAY[INTEGER] -1, << 1, 2, 3 >> }
  276. end
  277. fast_array_examples
  278. local
  279. fast_array_of_character: FAST_ARRAY[CHARACTER]; fast_array_of_integer: FAST_ARRAY[INTEGER]
  280. do
  281. -- A four elements FAST_ARRAY[CHARACTER]:
  282. fast_array_of_character := {FAST_ARRAY[CHARACTER] << 'a', 'b', 'c', 'd', 'e' >> }
  283. -- A three elements FAST_ARRAY[INTEGER]:
  284. fast_array_of_integer := {FAST_ARRAY[INTEGER] << 1, 2, 3 >> }
  285. end
  286. linked_list_examples
  287. local
  288. linked_list_of_character: LINKED_LIST[CHARACTER]; linked_list_of_integer: LINKED_LIST[INTEGER]
  289. do
  290. -- A four elements LINKED_LIST[CHARACTER]:
  291. linked_list_of_character := {LINKED_LIST[CHARACTER] << 'a', 'b', 'c', 'd', 'e' >> }
  292. -- A three elements LINKED_LIST[INTEGER]:
  293. linked_list_of_integer := {LINKED_LIST[INTEGER] << 1, 2, 3 >> }
  294. end
  295. two_way_linked_list_examples
  296. local
  297. two_way_linked_list_of_character: TWO_WAY_LINKED_LIST[CHARACTER]
  298. two_way_linked_list_of_integer: TWO_WAY_LINKED_LIST[INTEGER]
  299. do
  300. -- A four elements TWO_WAY_LINKED_LIST[CHARACTER]:
  301. two_way_linked_list_of_character := {TWO_WAY_LINKED_LIST[CHARACTER] << 'a', 'b', 'c', 'd', 'e' >> }
  302. -- A three elements TWO_WAY_LINKED_LIST[INTEGER]:
  303. two_way_linked_list_of_integer := {TWO_WAY_LINKED_LIST[INTEGER] << 1, 2, 3 >> }
  304. end
  305. ring_array_examples
  306. local
  307. ring_array_of_character: RING_ARRAY[CHARACTER]; ring_array_of_integer: RING_ARRAY[INTEGER]
  308. do
  309. -- A four elements RING_ARRAY[CHARACTER]:
  310. ring_array_of_character := {RING_ARRAY[CHARACTER] 1, << 'a', 'b', 'c', 'd', 'e' >> }
  311. -- A three elements RING_ARRAY[INTEGER]:
  312. ring_array_of_integer := {RING_ARRAY[INTEGER] 1, << 1, 2, 3 >> }
  313. end
  314. set_examples
  315. local
  316. set_of_character: SET[CHARACTER]; set_of_integer: SET[INTEGER]
  317. do
  318. -- A four elements HASHED_SET[CHARACTER]:
  319. set_of_character := {HASHED_SET[CHARACTER] << 'a', 'b', 'c', 'd', 'e', 'f' >> }
  320. -- A three elements HASHED_SET[INTEGER]:
  321. set_of_integer := {AVL_SET[INTEGER] << 1, 2, 3 >> }
  322. end
  323. dictionary_examples
  324. local
  325. dictionary: DICTIONARY[CHARACTER, STRING]
  326. do
  327. -- You can as well denote a DICTIONARY creation like this:
  328. dictionary := {HASHED_DICTIONARY[CHARACTER, STRING] << 'a', "key #1";
  329. 'z', "key #2";
  330. 'z', "key #3";
  331. 'a', "key #4" >> }
  332. -- Note that the ; (semicolon) is here to separate pairs.
  333. end
  334. bijective_dictionary_examples
  335. local
  336. bijective_dictionary: BIJECTIVE_DICTIONARY[STRING, STRING]
  337. do
  338. -- You can as well denote a DICTIONARY creation like this:
  339. bijective_dictionary := {HASHED_BIJECTIVE_DICTIONARY[STRING, STRING] << "value #1", "key #1";
  340. "value #2", "key #2";
  341. "value #3", "key #3" >> }
  342. -- Note that the ; (semicolon) is here to separate pairs.
  343. end
  344. array2_examples
  345. local
  346. collection2: COLLECTION2[CHARACTER]
  347. do
  348. collection2 := {ARRAY2[CHARACTER] 1, 4, 1, 6, << 'a', 'b', 'c', 'd', 'e', 'f';
  349. 'a', 'b', 'c', 'd', 'e', 'f';
  350. 'a', 'b', 'c', 'd', 'e', 'f';
  351. 'a', 'b', 'c', 'd', 'e', 'f' >> }
  352. end
  353. fast_array2_examples
  354. local
  355. collection2: COLLECTION2[CHARACTER]
  356. do
  357. collection2 := {FAST_ARRAY2[CHARACTER] 4, 6, << 'a', 'b', 'c', 'd', 'e', 'f';
  358. 'a', 'b', 'c', 'd', 'e', 'f';
  359. 'a', 'b', 'c', 'd', 'e', 'f';
  360. 'a', 'b', 'c', 'd', 'e', 'f' >> }
  361. end
  362. native_array_examples
  363. local
  364. native_array_character: NATIVE_ARRAY[CHARACTER]; native_array_integer_8: NATIVE_ARRAY[INTEGER_8]
  365. do
  366. native_array_character := {NATIVE_ARRAY[CHARACTER] << 'a', 'b', 'c', 'd', 'e', 'f' >> }
  367. check
  368. native_array_character.item(0) = 'a'
  369. native_array_character.item(5) = 'f'
  370. end
  371. native_array_integer_8 := {NATIVE_ARRAY[INTEGER_8] << 0, 1, 2, 3, 4, 5, 6, 7, 8 >> }
  372. end
  373. make
  374. do
  375. boolean_examples
  376. character_examples
  377. string_examples
  378. unicode_string_examples
  379. integer_examples
  380. real_examples
  381. array_examples
  382. fast_array_examples
  383. linked_list_examples
  384. two_way_linked_list_examples
  385. ring_array_examples
  386. set_examples
  387. dictionary_examples
  388. bijective_dictionary_examples
  389. array2_examples
  390. fast_array2_examples
  391. native_array_examples
  392. end
  393. end -- class MANIFEST_NOTATION