1 / 8

ESC/JAVA2

ESC/JAVA2. 程序的规范. ESC/Java 使用 – 配置. 运行 “D:MobiusDeltaEclipseeclipse.exe” 选择 ”workspace” 的路径 配置 Java 由于 ESC/Java 仅支持 Java1.4, 所以需要配置 JDK 的版本 Window -> Preference -> Java Installed JREs Add -> “C:j2sdk1.4.2” 并勾选 Compiler Compiler Complaince Level 选择 1.4 ESC/Java2

yuma
Download Presentation

ESC/JAVA2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ESC/JAVA2 程序的规范

  2. ESC/Java使用 – 配置 • 运行 “D:\MobiusDelta\Eclipse\eclipse.exe” • 选择”workspace”的路径 • 配置Java • 由于ESC/Java仅支持Java1.4,所以需要配置JDK的版本 • Window -> Preference -> Java • Installed JREs • Add -> “C:\j2sdk1.4.2” 并勾选 • Compiler • Compiler Complaince Level 选择1.4 • ESC/Java2 • 勾选 “Use Internal Version”

  3. ESC/Java使用 – 创建工程 • File-> New -> Java Project • 注意使用Jdk 1.4.2 • JML -> Setup -> “Enable ESC/Java Nature” • 会出现一个叫”jmlspec”的新工程,这是由ESC/Java自动创建的,不要修改它 • 控制台会出现” Failed to install JML specification”,这是BUG,不影响使用 • JML -> “Enable Auto ESC/Java2 Check” • 每次保存会自动调用ESC/Java2或者 JML-> ESC/Java2 手工运行 • 解压”lab5.zip”,选择创建的工程的”src”, File -> Import -> File System -> lab5.zip 解压的路径 -> 勾选所有Java文件 -> Finish

  4. ESC/Java使用 – 界面 • ESC/Java会根据证明的结果给出提示

  5. ESC/Java的规范 • ESC/Java允许我们在Java中用特殊格式的注释引入对程序的规范 • 如 //@ requires n>1; • 注意 //和@之间不能有空格,结尾要有”;” • 规范使用Java的bool表达式 • 规范中不能带有 ++ -- += 等带副作用的运算符

  6. 规范的含义 • axiom 加入公理,证明器认为其为真 • requires 在函数入口点的约束 • ensures 在函数返回点的约束 • 不能在这里对函数的局部变量进行约束 • 返回值用特殊的关键字 \result • 可以使用如 \old(x)这样的形式表示函数入口时对应变量的状态 • assert 可以在任意语句之间加入,证明器会对其进行检查 • invariant 证明器会在所有用到和改变所涉及变量的时候检查invariant是否满足 • modifies 表示函数会修改的变量

  7. Bag0至Bag7是一个例子, 说明了一个程序在ESC/Java下如何逐步修改正确 • 观察如何写规范

  8. 实验 • 添加规范,必要时修改代码,使得Bag.java和Amount.java通过ESC/Java

More Related