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

Verified java #5748

Draft
wants to merge 86 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
1a31018
Great stuff
keyboardDrummer Aug 2, 2024
434875a
Improvement
keyboardDrummer Aug 2, 2024
dd35b37
Remove the printing foresight for now
keyboardDrummer Aug 2, 2024
6e8b8a2
Added printer and grammar APIs
keyboardDrummer Aug 2, 2024
f34cafa
Cleanup
keyboardDrummer Aug 2, 2024
da31097
Little bit more progress
keyboardDrummer Aug 2, 2024
fd39930
Introduce orientation
keyboardDrummer Aug 2, 2024
e9b6a0a
Add division
keyboardDrummer Aug 3, 2024
e873de8
Add parameterless constructors
keyboardDrummer Aug 3, 2024
7846eef
Fix reference related errors
keyboardDrummer Aug 3, 2024
609e92a
Fixed all the reference errors. Only one remaining error
keyboardDrummer Aug 3, 2024
3e89cab
Trying to add actual parser
keyboardDrummer Aug 3, 2024
e7e0a1a
Good progress
keyboardDrummer Aug 3, 2024
994bd85
Some tests
keyboardDrummer Aug 3, 2024
09d4453
Small refactoring
keyboardDrummer Aug 3, 2024
536a67a
Bunch of parse tests pass
keyboardDrummer Aug 3, 2024
84f8edf
Added test
keyboardDrummer Aug 3, 2024
da3e68c
Manual trivia test passes
keyboardDrummer Aug 3, 2024
11c6929
Save before sequence refactoring
keyboardDrummer Aug 3, 2024
93ec82a
Did most of sequence refactoring
keyboardDrummer Aug 3, 2024
62d496a
Use IEnumerable instead of List, for Many
keyboardDrummer Aug 3, 2024
c7fe48c
Basic implementation of AddTrivia
keyboardDrummer Aug 4, 2024
32f95c0
Fix issue with incorrect recursives parameter
keyboardDrummer Aug 4, 2024
523cd0e
TestMany succeeds for Grammar
keyboardDrummer Aug 4, 2024
ecc4206
TestGrammar tests pass now
keyboardDrummer Aug 4, 2024
1d39e2e
Fixed readonly issues of Dafny AST
keyboardDrummer Aug 4, 2024
f67a50f
More work towards AddComments working
keyboardDrummer Aug 4, 2024
6a37f7f
Improved error handling
keyboardDrummer Aug 4, 2024
74a747d
Fix error message issue
keyboardDrummer Aug 4, 2024
6a2913a
Changes so the comment addition might work
keyboardDrummer Aug 4, 2024
f175e8d
Progress
keyboardDrummer Aug 4, 2024
7ad2d01
Do not use fail
keyboardDrummer Aug 4, 2024
2f04d5b
Tiny Java program parses
keyboardDrummer Aug 4, 2024
5bf2545
IDE test shows diagnostics error for vjava
keyboardDrummer Aug 5, 2024
8ae0505
Added SafeDivision test
keyboardDrummer Aug 5, 2024
84201ca
Go to definition works
keyboardDrummer Aug 5, 2024
7943207
Navigation tests pass
keyboardDrummer Aug 5, 2024
79625e0
Support requires clause and add draft of run test
keyboardDrummer Aug 5, 2024
97785eb
Run improvements
keyboardDrummer Aug 5, 2024
823ede9
Run works, except that we need to refer to in32
keyboardDrummer Aug 5, 2024
3ac3b1b
Add comments to run file
keyboardDrummer Aug 5, 2024
b60bf10
Update language server document selector
keyboardDrummer Aug 5, 2024
07fe19c
Improve parser error reporting using fail grammars
keyboardDrummer Aug 6, 2024
c85eb4b
Implemented Print features
keyboardDrummer Aug 6, 2024
4f9b287
First results from printer test
keyboardDrummer Aug 6, 2024
dbff27a
Printer almost works as desired
keyboardDrummer Aug 6, 2024
9d8d329
Printed java is equal to the input
keyboardDrummer Aug 6, 2024
b6fdbeb
Draft for vjava backend
keyboardDrummer Aug 6, 2024
07ed2a7
Work on the vjava backend
keyboardDrummer Aug 6, 2024
ab055c7
Descent demo state
keyboardDrummer Aug 6, 2024
5fa6795
Improve function definition
keyboardDrummer Aug 6, 2024
6fc26fc
Cleanup
keyboardDrummer Aug 6, 2024
d12c462
Test second example parses
keyboardDrummer Aug 6, 2024
d66bc86
Small tweaks
keyboardDrummer Aug 14, 2024
6fc340b
Various fixes
keyboardDrummer Aug 15, 2024
cf2ead9
Extend Java grammar
keyboardDrummer Aug 15, 2024
1c954c8
Add char grammar
keyboardDrummer Aug 19, 2024
c0c9c79
Progress
keyboardDrummer Aug 19, 2024
056b04d
Parsing succeeds
keyboardDrummer Aug 19, 2024
cd3748f
Type resolution error
keyboardDrummer Aug 19, 2024
7c14dad
Save before dealing with <==>
keyboardDrummer Aug 19, 2024
e9bb86f
Add operator precedence
keyboardDrummer Aug 19, 2024
0b2cf27
Fewer errors
keyboardDrummer Aug 20, 2024
989c704
Fix tokens
keyboardDrummer Aug 20, 2024
8415712
Parsing seems good
keyboardDrummer Aug 20, 2024
ba077f3
Passed resolver, but getting verification errors
keyboardDrummer Aug 20, 2024
ed95abf
Verification passes
keyboardDrummer Aug 20, 2024
72ad849
Experiments with caching
keyboardDrummer Aug 20, 2024
4fa6670
Some caching improvements
keyboardDrummer Aug 20, 2024
850c904
Attempt at optimization that introduces a bug
keyboardDrummer Aug 20, 2024
6f7d68f
Add debugName to recursive
keyboardDrummer Aug 20, 2024
616b068
TestComplicated
keyboardDrummer Aug 20, 2024
90777bc
Turn on cache
keyboardDrummer Aug 20, 2024
b4cf6fb
Further simplifications
keyboardDrummer Aug 20, 2024
9840d9a
Fixes and comment
keyboardDrummer Aug 21, 2024
dc5a1fa
Add more comments
keyboardDrummer Aug 21, 2024
9d124a8
Tests pass again
keyboardDrummer Aug 21, 2024
dabf18a
Fixes
keyboardDrummer Aug 23, 2024
56705c1
Add reason and remove some unused caching
keyboardDrummer Aug 23, 2024
e37fca6
Fix printing
keyboardDrummer Aug 23, 2024
9a952ef
Some printing fixes
keyboardDrummer Aug 21, 2024
eab38f5
Some printing error reporting
keyboardDrummer Aug 23, 2024
290d379
Slightly better printing error reporting
keyboardDrummer Aug 21, 2024
dd90aaf
Small printing progress
keyboardDrummer Aug 21, 2024
06063e6
Better printing error messaging
keyboardDrummer Aug 21, 2024
2318238
Some more fixes
keyboardDrummer Aug 22, 2024
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
1 change: 0 additions & 1 deletion Binaries/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion Scripts/dafny
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if [ "${MY_OS:0:5}" == "MINGW" ] || [ "${MY_OS:0:6}" == "CYGWIN" ]; then
else
DAFNY_EXE_NAME="Dafny.dll"
fi
DAFNY="$DAFNY_ROOT/Binaries/$DAFNY_EXE_NAME"
DAFNY="$DAFNY_ROOT/Binaries/net8.0/$DAFNY_EXE_NAME"
if [[ ! -e "$DAFNY" ]]; then
echo "Error: $DAFNY_EXE_NAME not found at $DAFNY."
exit 1
Expand Down
2 changes: 1 addition & 1 deletion Source/AutoExtern.Test/AutoExtern.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion Source/AutoExtern.Test/Minimal/Library.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Source/AutoExtern.Test/Tutorial/ClientApp/ClientApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<NoWarn>CS3021; CS0162</NoWarn>
<!-- <Nullable>enable</Nullable> -->
Expand Down
2 changes: 1 addition & 1 deletion Source/AutoExtern.Test/Tutorial/Library/Library.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Source/AutoExtern/AutoExtern.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Expand Down
27 changes: 27 additions & 0 deletions Source/CompilerBuilder.Test/CompilerBuilder.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CompilerBuilder\CompilerBuilder.csproj" />
</ItemGroup>

</Project>
117 changes: 117 additions & 0 deletions Source/CompilerBuilder.Test/TestGrammars.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using CompilerBuilder.Grammars;

namespace CompilerBuilder.Test;

using static GrammarBuilder;

public class TestGrammars {

[Fact]
public void TestNumber() {
var number = Number;
var parsed = number.ToParser().Parse("123124").Success!.Value;
Assert.Equal(123124, parsed);
}

[Fact]
public void TestIdentifier() {
var number = Identifier;
var parsed = number.ToParser().Parse("abcdefg").Success!.Value;
Assert.Equal("abcdefg", parsed);
}

[Fact]
public void TestKeyword() {
var parser = Keyword("hello").Then(Constant(true));
var parsed = parser.ToParser().Parse("hello").Success!.Value;
Assert.True(parsed);

var byeResult = parser.ToParser().Parse("bye");
Assert.Contains("Expected", byeResult.Failure!.Message);
}

[Fact]
public void TestChoice() {
var numberOrIdentifier = Number.UpCast<int, object>().Or(Identifier.UpCast<string, object>());
Assert.Equal(123124, numberOrIdentifier.ToParser().Parse("123124").Success!.Value);
Assert.Equal("abcefg", numberOrIdentifier.ToParser().Parse("abcefg").Success!.Value);
Assert.Null(numberOrIdentifier.ToParser().Parse("!@!@$#").Success);
}

record Person {
public int Age;
public string Name;
}

[Fact]
public void TestSequence() {
var person =
Constructor<Person>().
Then(Number, (p) => p.Age).
Then(Identifier, (p) => p.Name);
var result = person.ToParser().Parse("123124Jan");
Assert.Equal(123124, result.Success!.Value.Age);
Assert.Equal("Jan", result.Success!.Value.Name);
Assert.Null(person.ToParser().Parse("1231").Success);
}

[Fact]
public void TestMany() {
var person =
Constructor<Person>().
Then(Number, (p) => p.Age).
Then(Identifier, (p) => p.Name);
var persons = person.Many();
var parser = persons.ToParser();
var goodResult = parser.Parse("123124Jan12313Henk12Remy");
Assert.Equal(3, goodResult.Success!.Value.Count());
Assert.Equal("Remy", goodResult.Success!.Value.ElementAt(2).Name);
var badResult = parser.Parse("123124Jan12313Henk12");
Assert.Null(badResult.Success);
}

[Fact]
public void LeftRecursive() {
var parser = Recursive<int>(self => Number.Or(self.Then("^")), "LeftRecursiveTest");
var result = parser.ToParser().Parse("13^^^");
Assert.Equal(13, result.Success!.Value);
}

record PersonWithTrivia {
public int Age;
public string Name;
public List<string> Trivia = new();

public PersonWithTrivia() {
Age = 0;
Name = null;
}
}

[Fact]
public void ManualTrivia() {
var trivia = Comments.SlashSlashLineComment().Or(Whitespace).Or(Comments.BlockComment()).Many();
var person =
Constructor<PersonWithTrivia>().
Then(Number, (p) => p.Age).
Then(trivia, (p) => p.Trivia).
Then(Identifier, (p) => p.Name);
var input = "123 Remy";
var result = person.ToParser().Parse(input);
Assert.NotNull(result.Success);
Assert.Equal(" ", result.Success?.Value.Trivia[0]);

var input2 = @"123// line comment

// another linecomment
/** block

comment
*/
Remy";
var result2 = person.ToParser().Parse(input2);
Assert.NotNull(result2.Success);
Assert.Equal("// another linecomment\n", result2.Success?.Value.Trivia[2]);
}

}
133 changes: 133 additions & 0 deletions Source/CompilerBuilder.Test/TestParsing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
namespace CompilerBuilder.Test;

using static ParserBuilder;

public class TestParsing {

[Fact]
public void TestNumber() {
var number = Number;
var parsed = number.Parse("123124").ForceSuccess.Value;
Assert.Equal(123124, parsed);
}

[Fact]
public void TestChar() {
var parsed = CharInSingleQuotes.Parse("'d'").ForceSuccess.Value;
Assert.Equal("d", parsed);
}

[Fact]
public void TestIdentifier() {
var number = Identifier;
var result = number.Parse("abcdefg");
var parsed = result.ForceSuccess.Value;
Assert.Equal("abcdefg", parsed);
}

[Fact]
public void TestKeyword() {
var parser = Keyword("hello").Then(Constant(true));
var parsed = parser.Parse("hello").Success!.Value;
Assert.True(parsed);

var byeResult = parser.Parse("bye");
Assert.Contains("Expected", byeResult.Failure!.Message);
}

[Fact]
public void TestChoice() {
var numberOrIdentifier = Fail<object>("a number or identifier").
Or(Number.Map(i => (object)i).Or(Identifier.Map(s => (object)s)));
Assert.Equal(123124, numberOrIdentifier.Parse("123124").Success!.Value);
Assert.Equal("abcefg", numberOrIdentifier.Parse("abcefg").Success!.Value);
Assert.Null(numberOrIdentifier.Parse("!@!@$#").Success);

Assert.Equal("'!@#!@' is not the end of the text", numberOrIdentifier.Parse("123124!@#!@#").Failure!.Message);
Assert.Equal("'!@#!@' is not a number or identifier", numberOrIdentifier.Parse("!@#!@#").Failure!.Message);
}

record Person {
public int Age;
public string Name;
}

[Fact]
public void TestSequence() {
var person =
Value(() => new Person()).
Then(Number, (p, v) => p.Age = v).
Then(Identifier, (p, v) => p.Name = v);
var result = person.Parse("123124Jan");
Assert.Equal(123124, result.Success!.Value.Age);
Assert.Equal("Jan", result.Success!.Value.Name);
Assert.Null(person.Parse("1231").Success);

Assert.Equal("'!@#!@' is not an identifier", person.Parse("123124!@#!@#").Failure!.Message);
}

[Fact]
public void TestMany() {
var person =
Value(() => new Person()).
Then("^").
Then(Number, (p, v) => p.Age = v).
Then(Identifier, (p, v) => p.Name = v);
var persons = person.Many();
var goodResult = persons.Parse("^123124Jan^12313Henk^12Remy");
Assert.Equal(3, goodResult.ForceSuccess.Value.Count);
Assert.Equal("Remy", goodResult.ForceSuccess.Value[2].Name);
var badResult = persons.Parse("^123124Jan^12313Henk^12");
Assert.Null(badResult.Success);
}

[Fact]
public void LeftRecursive() {
var parser = Recursive<int>(self => Number.Or(self.Then("^")), "LeftRecursiveTest");
var result = parser.Parse("13^^^");
Assert.Equal(13, result.ForceSuccess.Value);
}

class PersonWithTrivia {
public int Age;
public string Name;
public List<string> Trivia = new();

public PersonWithTrivia() {
Age = 0;
Name = null;
}
}

[Fact]
public void ManualTrivia() {
var trivia = SlashSlashLineComment.Or(Whitespace).Many();
var person =
Value(() => new PersonWithTrivia()).
Then(Number, (p, v) => p.Age = v).
Then(trivia, (p, newTrivia) => p.Trivia.AddRange(newTrivia)).
Then(Identifier, (p, v) => p.Name = v);
var input = "123 Remy";
var result = person.Parse(input);
Assert.NotNull(result.Success);
Assert.Equal(123, result.Success?.Value.Age);
Assert.Equal(" ", result.Success?.Value.Trivia[0]);

var input2 = @"123// line comment

// another linecomment
Remy";
var result2 = person.Parse(input2);
Assert.NotNull(result2.Success);
Assert.Equal("// another linecomment\n", result2.Success?.Value.Trivia[2]);
}

// There were a lot of issues in the following that this file should test, but did not.
// Things like nested recursive things
// And not dropping intermediate results when growing a seed.
// class Div {
// int Foo(int x) {
// return 3 / x;
// }
// }
}
6 changes: 6 additions & 0 deletions Source/CompilerBuilder.Test/TestPrinting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CompilerBuilder.Test;


public class TestPrinting {

}
15 changes: 15 additions & 0 deletions Source/CompilerBuilder/CompilerBuilder.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Boogie.ExecutionEngine" Version="3.2.2" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="5.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public static bool Is(IToken tok) {
return false;
}

public static Expression WrapExpression(Expression expr) {
return Expression.CreateParensExpression(new AutoGeneratedToken(expr.tok), expr);
}

public override IToken WithVal(string newVal) {
return new AutoGeneratedToken(WrappedToken.WithVal(newVal));
}
Expand Down
Loading