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

[do not merge] WIP Exceptions #348

Closed
wants to merge 299 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
299 commits
Select commit Hold shift + click to select a range
ee09caf
Allows for hello.dfy to fully compile into Java code
Jun 14, 2019
57b1e1c
fix resolved comments
Jun 14, 2019
4572251
Testing tuple implementation for Java
Jun 7, 2019
7471f69
Add support for unsigned numerics
Jun 12, 2019
e725973
Change DafnyString implmentation to use String internally
Jun 12, 2019
de0c0ab
Allows for Hello.dfy to work completely
Jun 17, 2019
23ba5a0
Recursively compiles Java files in the relevant directory
Jun 18, 2019
41d9713
Add functionality for program to run if it has a main method and flag…
Jun 18, 2019
b10dff5
Merge branch 'java-compiler' of ssh://git.amazon.com:2222/pkg/Dafny i…
Jun 20, 2019
d06d346
Successfully compile Calls.dfy to Java
Jun 21, 2019
6e6b1ba
Successfully compile and run Class.dfy into Java
Jun 25, 2019
90a0cc3
Address comments in CR-10022662 Revision 1
Jun 26, 2019
55e70f3
Add support for dynamically adding tuple sizes
Jun 20, 2019
f5111b3
Add support for dynamically adding tuple sizes
Jun 20, 2019
8280897
Add EmitDatatypeValue"
Jun 21, 2019
7362e4b
Restructure compilation list so __default is added to _System
Jun 21, 2019
6ed3950
Add dynamic compilation of Tuple0
Jun 21, 2019
8ee55fd
Add compilation for abstract class for algebraic datatypes
Jun 24, 2019
54adbfc
Add object methods to algebraic types without type parameters
Jun 24, 2019
72d10e4
Add datatype support with fields
Jun 25, 2019
096e064
Auto-format code after pushing tuples
Jun 27, 2019
c402020
No logical changes, moved relevant unimplemented functions up in file
Jun 26, 2019
72f96c2
Implement lambda functions, IIFE0, tail-recursion, and for-each loops
Jun 27, 2019
0befbc1
Allows Dt.dfy to successfully compile and run in Java
Jun 29, 2019
860f115
pb/compiler-java-cs in one commit
Jun 6, 2019
f643912
forreal please work
Jun 6, 2019
e404277
addressed CR-9317576 comments
Jun 6, 2019
0528dad
Added Java Classes For Dafny Types
Jun 6, 2019
a6a113b
removed uneccessary functionality from DafnySet
Jun 6, 2019
dae0fc7
finished implementing ClassWriter.CreateMethod
Jun 6, 2019
501b07d
addressed comments in CR-9354201
Jun 6, 2019
36e5c81
few TODO comments removed
Jun 6, 2019
2b49911
module headers printed out properly, example:
Jun 7, 2019
7756330
Improve Java implementation of Dafny datatypes.
Jun 7, 2019
622ac47
Edited csharp Multiset to use BigInteger for multiplicity
Jun 11, 2019
934163c
Add BigOrdinal Support
Jun 12, 2019
b94b349
add set to mset conversion
Jun 13, 2019
fd0e96d
finished most of ClassWriter class functions
Jun 10, 2019
1836397
Add functions to emit literal expressions
Jun 11, 2019
4dd4400
implements few more functions called from TrExpr in Compiler.cs
Jun 12, 2019
72066dd
Adds more functions that retrieve data from Collection types
Jun 13, 2019
1897cfc
Adjusts indents to have 2 spaces instead of 4
Jun 13, 2019
1970e6f
Adds Java functionality for bitwise Rotate operation
Jun 13, 2019
022d7a6
Allows for hello.dfy to fully compile into Java code
Jun 14, 2019
f13aba2
fix resolved comments
Jun 14, 2019
56531d5
Testing tuple implementation for Java
Jun 7, 2019
894b5d7
Add support for unsigned numerics
Jun 12, 2019
9635764
Change DafnyString implmentation to use String internally
Jun 12, 2019
994a1a3
Allows for Hello.dfy to work completely
Jun 17, 2019
eac8cd1
Recursively compiles Java files in the relevant directory
Jun 18, 2019
02362fa
Add functionality for program to run if it has a main method and flag…
Jun 18, 2019
8e533c7
pb/compiler-java-cs in one commit
Jun 6, 2019
f31bb87
forreal please work
Jun 6, 2019
c6c9975
Successfully compile Calls.dfy to Java
Jun 21, 2019
4e821ea
Successfully compile and run Class.dfy into Java
Jun 25, 2019
44cd381
Address comments in CR-10022662 Revision 1
Jun 26, 2019
4dd96e5
Add support for dynamically adding tuple sizes
Jun 20, 2019
88481f7
Add support for dynamically adding tuple sizes
Jun 20, 2019
0310a79
Add EmitDatatypeValue"
Jun 21, 2019
4515b90
Restructure compilation list so __default is added to _System
Jun 21, 2019
09ee768
Add dynamic compilation of Tuple0
Jun 21, 2019
607e856
Add compilation for abstract class for algebraic datatypes
Jun 24, 2019
c434e5c
Add object methods to algebraic types without type parameters
Jun 24, 2019
ee22a10
Add datatype support with fields
Jun 25, 2019
185e594
No logical changes, moved relevant unimplemented functions up in file
Jun 26, 2019
d1c74cc
Implement lambda functions, IIFE0, tail-recursion, and for-each loops
Jun 27, 2019
ca49433
Allows Dt.dfy to successfully compile and run in Java
Jun 29, 2019
e9072dc
Fix merge conflicts
Jul 2, 2019
4f08547
Tracks DafnyClasses folder in Binaries
Jul 3, 2019
0ef0884
Add functionality for externs, but no partial externs yet, and Java n…
Jul 2, 2019
10a7af9
No logical changes, removed extraneous code
Jul 2, 2019
4d6cbd4
Allows Ghosts.dfy to compile successfully, plus retroactive fixes
Jul 2, 2019
1052373
Allow for Java compilation on non-Unix machines, and error code checking
Jul 3, 2019
412a952
Add euclidean division support
Jun 19, 2019
158c719
Add euclidean modulus
Jun 19, 2019
5b429e2
chnage method names to support overloading
Jun 20, 2019
1bef382
Defined specifications for Euclidean Divisions
Jun 26, 2019
38ccc73
Change tests to run in JDK 8
Jun 26, 2019
461be55
Copy c# code into java compiler to be refactored for java
Jun 25, 2019
acd5644
Allow set method to compile
Jun 25, 2019
50a63fd
Allow multisets method to compile
Jun 26, 2019
88e84d3
Allow sequence method to compile completely
Jun 26, 2019
1bc007b
Allow strings method to compile
Jun 26, 2019
7f3e43f
Allow Map method to compile
Jun 27, 2019
e8d77c5
Add Dafnymap class
Jun 27, 2019
9248844
Resolve merge conflicts from rebasing
Jun 27, 2019
b8d5651
Allow InterplayBetweenSeqCharAndString to compile
Jun 27, 2019
8ca3f2d
Allow Collections to compile completely
Jun 28, 2019
e4a3949
Allows collections to run without errors
Jun 29, 2019
bf810d7
Allow compiled class to run with correct output
Jul 1, 2019
a01df92
Revisions to make program compile with better type checking
Jul 8, 2019
526d569
Change size casting to use valueOf instead
Jul 8, 2019
77fad89
Fix a few lines for more optimal design
Jul 8, 2019
6af26df
Fix mistakes when solving merge conflicts in rebase
Jul 8, 2019
3e738ee
Copied DafnyClasses files from Test to Binaries
Jul 9, 2019
d376535
Modify wrapper classes to match functionality
Jul 9, 2019
0c9728c
Fix java casting in operators
Jul 9, 2019
f02507c
Further edits to java classes to match functionality
Jul 10, 2019
baab596
Allow Numbers.dfy to compile completely
Jul 10, 2019
c0b28af
Allows Arrays.dfy to compile and javac can now run on Windows
Jul 9, 2019
ab9d87c
Address comments on CR-10533809 R1
Jul 10, 2019
da5600d
Resolve merge conflicts from java-compiler, add Helpers.java from Jac…
Jul 10, 2019
04bcbf9
Allows Forall.dfy to compile
Jul 12, 2019
6780e2b
Remove comment that throws exception when compile fails
Jul 12, 2019
9a8a632
create skeleton for methods needed in let.dfy
Jul 8, 2019
fdc62b7
Allo Let.dfy to compile completely and run correctly
Jul 9, 2019
5703e3d
Fix mistakes when selecting wrong version from merge conflict
Jul 10, 2019
3dc3710
Merge branch 'java-compiler-needs-master' into java-compiler
Jul 12, 2019
46087ab
Merge branch 'java-compiler' of ssh://git.amazon.com:2222/pkg/Dafny i…
Jul 12, 2019
16b4241
Fixes #315
mschlaipfer Jul 12, 2019
284a801
Add bigrational class
Jul 1, 2019
45d36ab
Allow Numbers.dfy to compile with correct math
Jul 10, 2019
a8f0489
Improve code abstraction
Jul 11, 2019
99f34e9
Add revised versions of classes to binaries;
Jul 16, 2019
6696727
Merge branch 'js/numbers_fix' into java-compiler
Jul 16, 2019
89cb689
Merge branch 'js/numbers_fix' into java-compiler
Jul 16, 2019
592ed43
Merge branch 'java-compiler' of ssh://git.amazon.com:2222/pkg/Dafny i…
Jul 23, 2019
d955fe9
Allow TypeParams to fully compile
Jul 15, 2019
0ff3d2e
Allow getDefault to work with non-generic types
Jul 17, 2019
41e57db
Allow typeparams to compile with default values
Jul 18, 2019
d6b198b
Allow type params to compile and run with correct output
Jul 18, 2019
2add0b1
Improve code abstraction and file structure
Jul 22, 2019
3c48222
Eliminate all uses of SupportsAmb...
Jul 23, 2019
aa1605d
Address comments from previous CRs
Jul 12, 2019
7b79487
Allows Comprehensions.dfy to compile fully
Jul 15, 2019
f14f8e4
Allows S3EncryptionClient compile to Java code, unknown if correct, S…
Jul 16, 2019
92a918d
Fix issue with calling static generic methods
Jul 17, 2019
12b146f
Fix string interpolation code style
Jul 17, 2019
f2801e4
Fixes type errors from S3EncryptionClient, change in directory struct…
Jul 19, 2019
f07cf11
Fix bug regarding tuple type declarations
Jul 19, 2019
e067933
Does not create empty package files anymore, and empty packages are n…
Jul 19, 2019
6085b10
Fix issue of datatypes with single constructors, prevent repeating im…
Jul 22, 2019
214b3d6
Avoids creating empty Java file if there is no main method
Jul 22, 2019
0619387
Allows Comprehensions.dfy to compile fully
Jul 15, 2019
e466b97
Do not create/import empty package files
Jul 19, 2019
ee1e61f
Fix type errors from S3EncryptionClient, change in directory structur…
Jul 19, 2019
9e45e6d
Fix typenames and dynamically created DafnyClasses when compiling S3E…
Jul 23, 2019
d7f9504
Add method in DafnyByte to return signed byte value
Jul 23, 2019
4c4a6ba
Merge Jack's changes and ensure all dfy files in Test/comp compile
Jul 24, 2019
ab13196
Delete old Java-compile output folder before writing new files
Jul 24, 2019
084ea8b
Allows Vihang's Base64.dfy to compile successfully
Jul 24, 2019
735bebf
Fix TypeName_Companion method in Compiler-java.cs
Jul 25, 2019
5391f39
Compile S3EncryptionClient without compile-time errors
Jul 25, 2019
7829ca8
Allows Vihang's Base64.dfy to compile successfully
Jul 24, 2019
d1c080c
Compile Yucca successfully
Jul 25, 2019
925ad44
Run S3EncryptionClient successfully
Jul 26, 2019
7e4e99e
Run full S3EncryptionClient successfully
Jul 29, 2019
b6ab8c1
Run full S3EncryptionClient successfully
Jul 29, 2019
b28c0ef
NO LOGICAL CHANGES: Add comment
Jul 30, 2019
7aba53b
Add java testing to lit testing suite
Jul 25, 2019
11de646
Allow java files to compile without warnings
Jul 25, 2019
0e69ab1
Allow Arrays.dfy to compile withour warnings
Jul 25, 2019
0014aea
Fix explosive union expect
Jul 25, 2019
e4fc786
Allow ghosts.dfy to compile without warnings
Jul 26, 2019
517168f
Allow test suite to run java files with correct output
Jul 26, 2019
5500f19
Fix final touchups for test suite
Jul 29, 2019
11f2bb3
Update Java classes tester to match live
Jul 30, 2019
9c515f7
Fix multiset update to avoid duplicate work
Jul 30, 2019
4933a60
Run formatter
Jul 30, 2019
388dbc2
Add byteValue to Ubyte
Jul 30, 2019
70ae188
Add type parameter to sequence
Jul 30, 2019
04b5049
Fix bug in SequenceTest
Jul 31, 2019
4c3aa17
Add string interpolation, remove excess whitespace
Jul 31, 2019
0ccad91
Add more Byte/UByte tests
Aug 1, 2019
85657ac
Correct wrong binary ops
Aug 2, 2019
1d168bc
Move DafnyClasses from Binaries to DafnyRuntime
Aug 2, 2019
0b50af2
Use JAR file for DafnyClasses
Aug 2, 2019
a3aaf80
Fix Ghosts.dfy NullPointerException
Aug 5, 2019
029f6cf
Remove formatting changes
Aug 5, 2019
56ff578
Factor out classpath setting code
Aug 5, 2019
36d7ba6
Fix Ghosts.dfy NullPointerException
Aug 5, 2019
3f05a40
NO LOGICAL CHANGES: Revert DafnyRuntime.cs copy to master
Aug 6, 2019
76a2427
Merge branch 'java-compiler-to-master' into java-compiler
Aug 6, 2019
098a56a
Do not wrap `const`s in `Lit`s
amaurremi Jul 31, 2019
c46cc3d
Motivating examples for functional extensionality
amaurremi Aug 1, 2019
dc49ab2
Add unsigned conversions
Aug 7, 2019
a9485a3
Added test to clarify expressivity of no `Lit` around `const`s. Minor…
amaurremi Aug 7, 2019
77ce20d
use platform.system() instead of os.name to detect whether to use mono
samuelgruetter Aug 8, 2019
e78e60e
Merge branch 'java-compiler-to-master' into java-compiler
Aug 8, 2019
62d6f35
Merge branch 'java-compiler' of ssh://git.amazon.com:2222/pkg/Dafny i…
Aug 8, 2019
43187f2
Fix character compare binary operations
Aug 7, 2019
b2a1d04
Fix UByte addition/subtraction
Aug 7, 2019
92a163b
Delete explosiveunion, get DafnyRuntime.cs from master
Aug 9, 2019
3ae95ac
exceptions syntactic sugar first step: `:-` in var update as an alias…
samuelgruetter Aug 9, 2019
6b01ee7
rerun Coco
samuelgruetter Aug 9, 2019
021e34f
enable `:-` in var decls too
samuelgruetter Aug 9, 2019
722b4c2
rerun Coco
samuelgruetter Aug 9, 2019
6b67561
Pass all tests in comp
Aug 10, 2019
f06e6d3
Move Java unit tests to DafnyRuntimeJava
Aug 10, 2019
9d6aaca
desugaring of `:-` statements
samuelgruetter Aug 10, 2019
0153015
Fix null-dereference crash
RustanLeino Aug 10, 2019
05bd4e4
Reformatting test files
amaurremi Aug 8, 2019
716faee
Modify .travis.yml to run jdk8, TEST
Aug 12, 2019
6b0c0d6
Suppress deprecation warning, revert .travis.yml
Aug 12, 2019
da277a2
Fix suppresswarning bug
Aug 12, 2019
78d166a
Merge pull request #345 from samuelgruetter/lit_cygwin
RustanLeino Aug 12, 2019
88a0e18
test interaction of desugaring with parser, typechecker and verifyer
samuelgruetter Aug 12, 2019
e240864
implement EnsureSupportsNonVoidErrorHandling and use it to improve er…
samuelgruetter Aug 13, 2019
8149af8
Merge pull request #349 from RustanLeino/fix-null-crash
RustanLeino Aug 13, 2019
4d685bd
Use WriteLine instead of newline
Aug 13, 2019
5fbca18
fix whitespace and remove naming of `:-` in grammar
samuelgruetter Aug 13, 2019
4ae3882
rerun coco
samuelgruetter Aug 13, 2019
297e38f
Fix Bitvectors.dfy
Aug 9, 2019
9e4080d
Fix dafny0/ArrayElementInitCompile.dfy
Aug 10, 2019
c0997fe
address comments by @RustanLeino
samuelgruetter Aug 13, 2019
c938c6d
Merge pull request #344 from amaurremi/lit-and-funext
RustanLeino Aug 14, 2019
227bbd1
Merge branch 'master' into fix-315
RustanLeino Aug 14, 2019
be0a7f1
Fix Bitvectors.dfy
Aug 9, 2019
7e0f2e3
Merge pull request #317 from mschlaipfer/fix-315
RustanLeino Aug 14, 2019
051e810
Typecheck variables in the Requires clause of lambda functions (handles)
amaurremi Aug 14, 2019
eda3580
Fix misc. bugs
Aug 14, 2019
f7d1d0a
Fix dafny0/NonZeroInitializationCompile.dfy
Aug 14, 2019
4d3c1c8
implement `:-` without LHS, and
samuelgruetter Aug 14, 2019
2b7a25d
rerun coco
samuelgruetter Aug 14, 2019
f172fc4
also commit VoidOutcome
samuelgruetter Aug 15, 2019
c6fda17
update .gitignore
samuelgruetter Aug 15, 2019
26895c6
Merge pull request #355 from amaurremi/typecheck-in-requires-clause
RustanLeino Aug 15, 2019
aed7e14
Remove tab character from main
Aug 15, 2019
92a32cf
Fix Array functions
Aug 9, 2019
e30ef12
Add missing multset functionality
Aug 9, 2019
210f683
Add more specifics for + and - ops
Aug 13, 2019
d7dd5e6
Order varaibles to allow java compilation
Aug 14, 2019
08b135a
Fix add/subtract bug
Aug 15, 2019
c9b7f23
Address PR comments
Aug 15, 2019
f63ffdb
enable test for statement-level where RHS of `:-` is an expression
samuelgruetter Aug 15, 2019
c88079e
Remove global variable MemberSelectObjIsTrait
Aug 16, 2019
f41387d
Remove unecessary methods from numerics
Aug 16, 2019
fc796bc
Update test cases
Aug 16, 2019
db753f4
Add safet checks to tuples
Aug 16, 2019
f9dea17
Merge branch 'java-compiler' of ssh://git.amazon.com:2222/pkg/Dafny i…
Aug 16, 2019
b643abf
Merge pull request #347 from psbang/java-compiler
RustanLeino Aug 16, 2019
923f812
Add syntax for type members of (co)datatypes and newtypes.
RustanLeino Aug 10, 2019
711fa94
Resolve members of (co)datatypes and newtypes
RustanLeino Aug 10, 2019
5becaed
Verify members of (co)datatypes and newtypes
RustanLeino Aug 10, 2019
023df3b
time lit tests
samuelgruetter Aug 16, 2019
7774dfb
Compile type members for (co)datatypes and newtypes
RustanLeino Aug 10, 2019
3f5237f
Fix C# compile name-clashes
RustanLeino Aug 11, 2019
fa2e37a
Refactor NeedsCustomReceiver expression in compiler
RustanLeino Aug 15, 2019
2b8d0f7
first try at parsing `:-` on expression level,
samuelgruetter Aug 17, 2019
b6f9aa1
Failed attempt at fixing the "LL1 warning in UnaryExpression: lbrace
samuelgruetter Aug 17, 2019
40c7bd2
Revert failed attempt
samuelgruetter Aug 17, 2019
b3fb175
remove unused IToken Colon field from UserSuppliedAttributes
samuelgruetter Aug 17, 2019
ec15c40
New approach to disambiguate between attribute and set display:
samuelgruetter Aug 17, 2019
cb744f8
rerun coco
samuelgruetter Aug 17, 2019
735827e
Merge pull request #350 from RustanLeino/type-members
RustanLeino Aug 17, 2019
d3ee64e
Merge pull request #357 from samuelgruetter/time-lit
RustanLeino Aug 17, 2019
d294979
replace tabs by spaces in Dafny.atg
samuelgruetter Aug 17, 2019
6158d4a
Finally, a parser for `:-` on expression level without Coco warnings
samuelgruetter Aug 17, 2019
eb631f1
rerun coco
samuelgruetter Aug 17, 2019
2bc839b
Merge old exceptions branch in new exceptions branch forked from master
samuelgruetter Aug 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ Source/DafnyExtension/z3.exe
Test/**/*.exe
Test/**/*.dll
Test/**/*.mdb
Test/**/*.pdb
Test/**/Output/
Test/server/model.bvd
Test/dafny0/Extern.cs
Test/dafny0/ExternCopyFromTrait.cs
Test/git-issues/github-issue-305-*.cs
Test/desktop/*
Test/node_modules/
Test/package-lock.json

Docs/OnlineTutorial/DocumentationTransducer.exe
Docs/OnlineTutorial/DocumentationTransducer.pdb
Expand All @@ -50,6 +55,10 @@ Test/comp/*.cs
Test/comp/*.js
Test/comp/*-go

# Ignore files generated by Rider IDE
# Generated by Rider IDE
*.sln.DotSettings.user
*.sln.DotSettings

# Generated by Visual Studio 2019
*.csproj.user
Source/.vs
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ script:
- cd dafny/Test
# The /optimize flag does not work on mono
- find . -name "*.dfy" -exec sed -i 's!/optimize !!g' {} +
- lit -v .
- lit --time-tests -v .
Binary file added Binaries/DafnyRuntime-1.jar
Binary file not shown.
14 changes: 9 additions & 5 deletions Source/Dafny/Cloner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public virtual TopLevelDecl CloneDeclaration(TopLevelDecl d, ModuleDefinition m)
} else if (d is NewtypeDecl) {
var dd = (NewtypeDecl)d;
if (dd.Var == null) {
return new NewtypeDecl(Tok(dd.tok), dd.Name, m, CloneType(dd.BaseType), CloneAttributes(dd.Attributes));
return new NewtypeDecl(Tok(dd.tok), dd.Name, m, CloneType(dd.BaseType), dd.Members.ConvertAll(CloneMember), CloneAttributes(dd.Attributes));
} else {
return new NewtypeDecl(Tok(dd.tok), dd.Name, m, CloneBoundVar(dd.Var), CloneExpr(dd.Constraint), dd.WitnessKind, CloneExpr(dd.Witness), CloneAttributes(dd.Attributes));
return new NewtypeDecl(Tok(dd.tok), dd.Name, m, CloneBoundVar(dd.Var), CloneExpr(dd.Constraint), dd.WitnessKind, CloneExpr(dd.Witness), dd.Members.ConvertAll(CloneMember), CloneAttributes(dd.Attributes));
}
} else if (d is TupleTypeDecl) {
var dd = (TupleTypeDecl)d;
Expand All @@ -67,13 +67,13 @@ public virtual TopLevelDecl CloneDeclaration(TopLevelDecl d, ModuleDefinition m)
var dd = (IndDatatypeDecl)d;
var tps = dd.TypeArgs.ConvertAll(CloneTypeParam);
var ctors = dd.Ctors.ConvertAll(CloneCtor);
var dt = new IndDatatypeDecl(Tok(dd.tok), dd.Name, m, tps, ctors, CloneAttributes(dd.Attributes));
var dt = new IndDatatypeDecl(Tok(dd.tok), dd.Name, m, tps, ctors, dd.Members.ConvertAll(CloneMember), CloneAttributes(dd.Attributes));
return dt;
} else if (d is CoDatatypeDecl) {
var dd = (CoDatatypeDecl)d;
var tps = dd.TypeArgs.ConvertAll(CloneTypeParam);
var ctors = dd.Ctors.ConvertAll(CloneCtor);
var dt = new CoDatatypeDecl(Tok(dd.tok), dd.Name, m, tps, ctors, CloneAttributes(dd.Attributes));
var dt = new CoDatatypeDecl(Tok(dd.tok), dd.Name, m, tps, ctors, dd.Members.ConvertAll(CloneMember), CloneAttributes(dd.Attributes));
return dt;
} else if (d is IteratorDecl) {
var dd = (IteratorDecl)d;
Expand Down Expand Up @@ -249,7 +249,7 @@ public Attributes CloneAttributes(Attributes attrs) {
return CloneAttributes(attrs.Prev);
} else if (attrs is UserSuppliedAttributes) {
var usa = (UserSuppliedAttributes)attrs;
return new UserSuppliedAttributes(Tok(usa.tok), Tok(usa.OpenBrace), Tok(usa.Colon), Tok(usa.CloseBrace), attrs.Args.ConvertAll(CloneExpr), CloneAttributes(attrs.Prev));
return new UserSuppliedAttributes(Tok(usa.tok), Tok(usa.OpenBrace), Tok(usa.CloseBrace), attrs.Args.ConvertAll(CloneExpr), CloneAttributes(attrs.Prev));
} else {
return new Attributes(attrs.Name, attrs.Args.ConvertAll(CloneExpr), CloneAttributes(attrs.Prev));
}
Expand Down Expand Up @@ -629,6 +629,10 @@ public virtual Statement CloneStmt(Statement stmt) {
var s = (UpdateStmt)stmt;
r = new UpdateStmt(Tok(s.Tok), Tok(s.EndTok), s.Lhss.ConvertAll(CloneExpr), s.Rhss.ConvertAll(CloneRHS), s.CanMutateKnownState);

} else if (stmt is AssignOrReturnStmt) {
var s = (AssignOrReturnStmt)stmt;
r = new AssignOrReturnStmt(Tok(s.Tok), Tok(s.EndTok), s.Lhss.ConvertAll(CloneExpr), CloneExpr(s.Rhs));

} else if (stmt is VarDeclStmt) {
var s = (VarDeclStmt)stmt;
var lhss = s.Locals.ConvertAll(c => new LocalVariable(Tok(c.Tok), Tok(c.EndTok), c.Name, CloneType(c.OptionalType), c.IsGhost));
Expand Down
96 changes: 68 additions & 28 deletions Source/Dafny/Compiler-Csharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ protected override BlockTargetWriter CreateIterator(IteratorDecl iter, TargetWri
return wIter;
}

protected override void DeclareDatatype(DatatypeDecl dt, TargetWriter wr) {
CompileDatatypeBase(dt, wr);
protected override IClassWriter/*?*/ DeclareDatatype(DatatypeDecl dt, TargetWriter wr) {
var w = CompileDatatypeBase(dt, wr);
CompileDatatypeConstructors(dt, wr);
return w;
}

void CompileDatatypeBase(DatatypeDecl dt, TargetWriter wr) {
IClassWriter CompileDatatypeBase(DatatypeDecl dt, TargetWriter wr) {
Contract.Requires(dt != null);
Contract.Requires(wr != null);

Expand All @@ -236,7 +237,7 @@ void CompileDatatypeBase(DatatypeDecl dt, TargetWriter wr) {
// }
// }
// public static Dt<T> _DafnyDefaultValue() { return Default; }
// public abstract Dt<T> Get(); // for co-datatypes
// public abstract Dt<T> _Get(); // for co-datatypes
//
// public static create_Ctor0(field0, field1, ...) { // for record types: create
// return new Dt_Ctor0(field0, field1, ...); // for record types: new Dt
Expand All @@ -248,7 +249,7 @@ void CompileDatatypeBase(DatatypeDecl dt, TargetWriter wr) {
//
// public T0 dtor_Dtor0 { get {
// var d = this; // for inductive datatypes
// var d = this.Get(); // for co-inductive datatypes
// var d = this._Get(); // for co-inductive datatypes
// if (d is DT_Ctor0) { return ((DT_Ctor0)d).Dtor0; }
// if (d is DT_Ctor1) { return ((DT_Ctor1)d).Dtor0; }
// ...
Expand All @@ -267,7 +268,8 @@ void CompileDatatypeBase(DatatypeDecl dt, TargetWriter wr) {
}

// from here on, write everything into the new block created here:
wr = wr.NewNamedBlock("public{0} class {1}", dt.IsRecordType ? "" : " abstract", DtT_protected);
var btw = wr.NewNamedBlock("public{0} class {1}", dt.IsRecordType ? "" : " abstract", DtT_protected);
wr = btw;

// constructor
if (dt.IsRecordType) {
Expand Down Expand Up @@ -313,7 +315,7 @@ void CompileDatatypeBase(DatatypeDecl dt, TargetWriter wr) {
wr.WriteLine("public static {0} _DafnyDefaultValue() {{ return Default; }}", DtT_protected);

if (dt is CoDatatypeDecl) {
wr.WriteLine("public abstract {0} Get();", DtT_protected);
wr.WriteLine("public abstract {0} _Get();", DtT_protected);
}

// create methods
Expand Down Expand Up @@ -361,7 +363,7 @@ void CompileDatatypeBase(DatatypeDecl dt, TargetWriter wr) {
if (!arg.IsGhost && arg.HasName) {
// public T0 dtor_Dtor0 { get {
// var d = this; // for inductive datatypes
// var d = this.Get(); // for co-inductive datatypes
// var d = this._Get(); // for co-inductive datatypes
// if (d is DT_Ctor0) { return ((DT_Ctor0)d).Dtor0; }
// if (d is DT_Ctor1) { return ((DT_Ctor1)d).Dtor0; }
// ...
Expand All @@ -372,13 +374,13 @@ void CompileDatatypeBase(DatatypeDecl dt, TargetWriter wr) {
var wGet = wDtor.NewBlock("get");
if (dt.IsRecordType) {
if (dt is CoDatatypeDecl) {
wGet.WriteLine("return this.Get().{0};", IdName(arg));
wGet.WriteLine("return this._Get().{0};", IdName(arg));
} else {
wGet.WriteLine("return this.{0};", IdName(arg));
}
} else {
if (dt is CoDatatypeDecl) {
wGet.WriteLine("var d = this.Get();");
wGet.WriteLine("var d = this._Get();");
} else {
wGet.WriteLine("var d = this;");
}
Expand All @@ -396,6 +398,18 @@ void CompileDatatypeBase(DatatypeDecl dt, TargetWriter wr) {
}
}
}

return new ClassWriter(this, btw);
}

string NeedsNew(TopLevelDeclWithMembers ty, string memberName) {
Contract.Requires(ty != null);
Contract.Requires(memberName != null);
if (ty.Members.Exists(member => member.Name == memberName)) {
return "new ";
} else {
return "";
}
}

void CompileDatatypeConstructors(DatatypeDecl dt, TargetWriter wrx) {
Expand All @@ -407,16 +421,16 @@ void CompileDatatypeConstructors(DatatypeDecl dt, TargetWriter wrx) {
// Computer c;
// Dt<T> d;
// public Dt__Lazy(Computer c) { this.c = c; }
// public override Dt<T> Get() { if (c != null) { d = c(); c = null; } return d; }
// public override string ToString() { return Get().ToString(); }
// public override Dt<T> _Get() { if (c != null) { d = c(); c = null; } return d; }
// public override string ToString() { return _Get().ToString(); }
// }
var w = wrx.NewNamedBlock("public class {0}__Lazy{2} : {1}{2}", dt.CompileName, IdName(dt), typeParams);
w.WriteLine("public delegate {0}{1} Computer();", dt.CompileName, typeParams);
w.WriteLine("Computer c;");
w.WriteLine("{0}{1} d;", dt.CompileName, typeParams);
w.WriteLine("public {2}delegate {0}{1} Computer();", dt.CompileName, typeParams, NeedsNew(dt, "Computer"));
w.WriteLine("{0}Computer c;", NeedsNew(dt, "c"));
w.WriteLine("{2}{0}{1} d;", dt.CompileName, typeParams, NeedsNew(dt, "d"));
w.WriteLine("public {0}__Lazy(Computer c) {{ this.c = c; }}", dt.CompileName);
w.WriteLine("public override {0}{1} Get() {{ if (c != null) {{ d = c(); c = null; }} return d; }}", dt.CompileName, typeParams);
w.WriteLine("public override string ToString() { return Get().ToString(); }");
w.WriteLine("public override {0}{1} _Get() {{ if (c != null) {{ d = c(); c = null; }} return d; }}", dt.CompileName, typeParams);
w.WriteLine("public override string ToString() { return _Get().ToString(); }");
}

if (dt.IsRecordType) {
Expand All @@ -442,7 +456,7 @@ void DatatypeFieldsAndConstructor(DatatypeCtor ctor, int constructorIndex, Targe
// public Dt_Ctor(arguments) { // for record types: Dt
// Fields = arguments;
// }
// public override Dt<T> Get() { return this; } // for co-datatypes only
// public override Dt<T> _Get() { return this; } // for co-datatypes only
// public override bool Equals(object other) {
// var oth = other as Dt_Ctor; // for record types: Dt
// return oth != null && equals(_field0, oth._field0) && ... ;
Expand Down Expand Up @@ -477,7 +491,7 @@ void DatatypeFieldsAndConstructor(DatatypeCtor ctor, int constructorIndex, Targe

if (dt is CoDatatypeDecl) {
string typeParams = dt.TypeArgs.Count == 0 ? "" : string.Format("<{0}>", TypeParameters(dt.TypeArgs));
wr.WriteLine("public override {0}{1} Get() {{ return this; }}", dt.CompileName, typeParams);
wr.WriteLine("public override {0}{1} _Get() {{ return this; }}", dt.CompileName, typeParams);
}

// Equals method
Expand Down Expand Up @@ -617,7 +631,7 @@ string DtCreateName(DatatypeCtor ctor) {
}
}

protected override void DeclareNewtype(NewtypeDecl nt, TargetWriter wr) {
protected override IClassWriter DeclareNewtype(NewtypeDecl nt, TargetWriter wr) {
var cw = CreateClass(IdName(nt), null, wr) as CsharpCompiler.ClassWriter;
var w = cw.StaticMemberWriter;
if (nt.NativeType != null) {
Expand All @@ -635,6 +649,7 @@ protected override void DeclareNewtype(NewtypeDecl nt, TargetWriter wr) {
w.WriteLine(");");
}
}
return cw;
}

protected override void DeclareSubsetType(SubsetTypeDecl sst, TargetWriter wr) {
Expand Down Expand Up @@ -705,17 +720,28 @@ public void Finish() { }
}
}

var customReceiver = NeedsCustomReceiver(m);

wr.Write("{0}{1}{2}{3} {4}",
createBody ? "public " : "",
m.IsStatic ? "static " : "",
m.IsStatic || customReceiver ? "static " : "",
hasDllImportAttribute ? "extern " : "",
targetReturnTypeReplacement ?? "void",
IdName(m));
if (m.TypeArgs.Count != 0) {
wr.Write("<{0}>", TypeParameters(m.TypeArgs));
}
wr.Write("(");
int nIns = WriteFormals("", m.Ins, wr);
int nIns;
if (customReceiver) {
var nt = m.EnclosingClass;
var receiverType = UserDefinedType.FromTopLevelDecl(m.tok, nt);
DeclareFormal("", "_this", receiverType, m.tok, true, wr);
nIns = 1;
} else {
nIns = 0;
}
nIns += WriteFormals(nIns == 0 ? "" : ", ", m.Ins, wr);
if (targetReturnTypeReplacement == null) {
WriteFormals(nIns == 0 ? "" : ", ", m.Outs, wr);
}
Expand All @@ -726,7 +752,7 @@ public void Finish() { }
} else {
var w = wr.NewBlock(")", null, BlockTargetWriter.BraceStyle.Newline, BlockTargetWriter.BraceStyle.Newline);
if (m.IsTailRecursive) {
if (!m.IsStatic) {
if (!m.IsStatic && !customReceiver) {
w.WriteLine("var _this = this;");
}
w.IndentLess(); w.WriteLine("TAIL_CALL_START: ;");
Expand All @@ -744,12 +770,19 @@ public void Finish() { }
protected BlockTargetWriter/*?*/ CreateFunction(string name, List<TypeParameter>/*?*/ typeArgs, List<Formal> formals, Type resultType, Bpl.IToken tok, bool isStatic, bool createBody, MemberDecl member, TargetWriter wr) {
var hasDllImportAttribute = ProcessDllImport(member, wr);

wr.Write("{0}{1}{2}{3} {4}", createBody ? "public " : "", isStatic ? "static " : "", hasDllImportAttribute ? "extern " : "", TypeName(resultType, wr, tok), name);
var customReceiver = NeedsCustomReceiver(member);

wr.Write("{0}{1}{2}{3} {4}", createBody ? "public " : "", isStatic || customReceiver ? "static " : "", hasDllImportAttribute ? "extern " : "", TypeName(resultType, wr, tok), name);
if (typeArgs != null && typeArgs.Count != 0) {
wr.Write("<{0}>", TypeParameters(typeArgs));
}
wr.Write("(");
WriteFormals("", formals, wr);
if (customReceiver) {
var nt = member.EnclosingClass;
var receiverType = UserDefinedType.FromTopLevelDecl(tok, nt);
DeclareFormal("", "_this", receiverType, tok, true, wr);
}
WriteFormals(customReceiver ? ", " : "", formals, wr);
if (!createBody || hasDllImportAttribute) {
wr.WriteLine(");");
return null;
Expand Down Expand Up @@ -853,7 +886,7 @@ protected override string TypeName(Type type, TextWriter wr, Bpl.IToken tok, Mem
} else if (xType is BitvectorType) {
var t = (BitvectorType)xType;
return t.NativeType != null ? GetNativeTypeName(t.NativeType) : "BigInteger";
} else if (xType.AsNewtype != null) {
} else if (xType.AsNewtype != null && member == null) { // when member is given, use UserDefinedType case below
var nativeType = xType.AsNewtype.NativeType;
if (nativeType != null) {
return GetNativeTypeName(nativeType);
Expand Down Expand Up @@ -1467,6 +1500,10 @@ public static string PublicIdProtect(string name) {
case "when":
case "where":
return "@" + name;
// methods with expected names
case "ToString":
case "GetHashCode":
return "_" + name;
default:
return name;
}
Expand All @@ -1488,7 +1525,10 @@ protected override string FullTypeName(UserDefinedType udt, MemberDecl/*?*/ memb
}

protected override void EmitThis(TargetWriter wr) {
wr.Write(enclosingMethod != null && enclosingMethod.IsTailRecursive ? "_this" : "this");
var custom =
(enclosingMethod != null && enclosingMethod.IsTailRecursive) ||
thisContext is NewtypeDecl;
wr.Write(custom ? "_this" : "this");
}

protected override void EmitDatatypeValue(DatatypeValue dtv, string arguments, TargetWriter wr) {
Expand Down Expand Up @@ -1690,7 +1730,7 @@ protected override TargetWriter EmitBetaRedex(List<string> boundVars, List<Expre

protected override void EmitDestructor(string source, Formal dtor, int formalNonGhostIndex, DatatypeCtor ctor, List<Type> typeArgs, Type bvType, TargetWriter wr) {
var dtorName = FormalName(dtor, formalNonGhostIndex);
wr.Write("(({0}){1}{2}).{3}", DtCtorName(ctor, typeArgs, wr), source, ctor.EnclosingDatatype is CoDatatypeDecl ? ".Get()" : "", dtorName);
wr.Write("(({0}){1}{2}).{3}", DtCtorName(ctor, typeArgs, wr), source, ctor.EnclosingDatatype is CoDatatypeDecl ? "._Get()" : "", dtorName);
}

protected override BlockTargetWriter CreateLambda(List<Type> inTypes, Bpl.IToken tok, List<string> inNames, Type resultType, TargetWriter wr, bool untyped = false) {
Expand Down
Loading