summaryrefslogtreecommitdiff
path: root/Test/dafny0/ExternNegative2.dfy
diff options
context:
space:
mode:
authorGravatar Richard L. Ford <richford@microsoft.com>2016-01-27 14:09:16 -0800
committerGravatar Richard L. Ford <richford@microsoft.com>2016-01-27 14:09:16 -0800
commit17405efd598d2a8a2dac304ee9a7f7d9bd30a558 (patch)
tree6e32fa175e06fd77c1c9135e99531b485a9b99b7 /Test/dafny0/ExternNegative2.dfy
parent436966ef61a3e4330bbe705d0d0319fcde5f3099 (diff)
Implement 'extern' declaration modifier.
The 'extern' declaration modifier provides a more convenient way of interfacing Dafny code with C# source files and .Net DLLs. We support an 'extern' keyword on a module, class, function method, or method (cannot extern ghost). We check the CompileNames of all modules to make sure there are no duplicate names. Every Dafny-generated C# class is marked partial, so it can potentially be extended. The extern keyword could be accompanied by an optional string naming the corresponding C# method/class to connect to. If not given the name of the method/class is used. An 'extern' keyword implies an {:axiom} attribute for functions and methods, so their ensures clauses are assumed to be true without proof. In addition to the .dfy files, the user may supply C# files (.cs) and dynamic linked libraries (.dll) on command line. These will be passed onto the C# compiler, the .cs files as sources, and the .dll files as references. As part of this change the grammar was refactored some. New productions are - TopDecls - a list of top-level declarations. - TopDecl - a single top-level declaration - DeclModifiers - a list of declaration modifiers which are either 'abstract', 'ghost', 'static', 'protected', or 'extern'. They can be in any order and we diagnose duplicates. In addition, since they are not all allowed in all contexts, we check and give diagnostics if an DeclModifier appears where it is not allowed.
Diffstat (limited to 'Test/dafny0/ExternNegative2.dfy')
-rw-r--r--Test/dafny0/ExternNegative2.dfy26
1 files changed, 26 insertions, 0 deletions
diff --git a/Test/dafny0/ExternNegative2.dfy b/Test/dafny0/ExternNegative2.dfy
new file mode 100644
index 00000000..3d09913b
--- /dev/null
+++ b/Test/dafny0/ExternNegative2.dfy
@@ -0,0 +1,26 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+extern "Modx" module Mod1
+{
+ extern "classx" class Class1
+ {
+ extern "Fun1x" static function method Fun1() : int
+ ensures Fun1() > 0
+ extern "Method1x" static method Method1() returns (x: int)
+ ensures x > 0
+ static function method Fun2() : int
+ ensures Fun2() > 0
+ {
+ Fun1()
+ }
+ static method Method2() returns (x: int)
+ ensures x > 0
+ {
+ x := Method1();
+ }
+ }
+}
+// Will give error about duplicate CompileName for module.
+extern "Modx" module Mod2
+{
+}