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

Ncore taclets #15

Open
wants to merge 221 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
221 commits
Select commit Hold shift + click to select a range
b1bbfdf
Add simplified Rust parser
Drodt Jun 5, 2024
b0220bd
initial commit for generalizing data structures representing calculi
unp1 Jun 12, 2024
704070f
more refactoring
unp1 Jun 12, 2024
9debf5e
polish
unp1 Jun 12, 2024
b99b975
Add AST classes
Drodt Jun 12, 2024
5c6cbac
Types, ops, and idents
Drodt Jun 14, 2024
7bc8e41
Convert to KeY AST
Drodt Jun 20, 2024
e02f171
Add ops and term
Drodt Jun 20, 2024
adde184
TermFactory
Drodt Jun 21, 2024
02bba08
Move Namespac
Drodt Jun 24, 2024
f489dea
Namespaces
Drodt Jun 25, 2024
a53a5d2
LDTs
Drodt Jun 27, 2024
76a08c4
Spotless
Drodt Jul 3, 2024
13414d8
Add taclet files
Drodt Jul 3, 2024
e61c708
Split grammars
Drodt Jul 3, 2024
33201ff
Merge branch 'main' into rusty-while
Drodt Jul 12, 2024
d791592
TermBuilder and LDTs
Drodt Jul 12, 2024
5b7df1f
Extend TermBuilder
Drodt Jul 15, 2024
0d2996a
Basic KeY-File infrastructure
Drodt Jul 16, 2024
7077abe
KeYUserProblemFile and friends
Drodt Jul 18, 2024
39b1f4b
Add SVs
Drodt Jul 19, 2024
fea930e
Spotless
Drodt Jul 19, 2024
f682fe1
Make SimpleExpressionSort proper
Drodt Jul 19, 2024
0d57115
Taclets
Drodt Jul 19, 2024
e3a4ee7
Merge branch 'main' into rusty-while
Drodt Jul 22, 2024
75b9809
Fix int literals and test
Drodt Jul 23, 2024
4f5b3f9
Add more taclets
Drodt Jul 23, 2024
bd87d2e
NoFindTaclet
Drodt Jul 23, 2024
2b05b74
TacletBuilder
Drodt Jul 23, 2024
30ef7f1
Printing + fix
Drodt Jul 25, 2024
658e810
almost working version of loading ldt.key in rusty_while
tobias-rnh Jul 24, 2024
6fbefb0
start adding copy methods for InitConfig
tobias-rnh Jul 24, 2024
b286e94
fixing parsing
tobias-rnh Jul 25, 2024
fcabfc8
spotless
tobias-rnh Jul 25, 2024
54c54c4
Start on instructions
Drodt Jul 25, 2024
479204a
start implementing TacletPBuilder
tobias-rnh Jul 25, 2024
160d0d3
copy more of TacletPBuilder
tobias-rnh Jul 25, 2024
4921e22
Matching
Drodt Jul 26, 2024
a4ec590
Improve code quality
Drodt Jul 26, 2024
22db910
Some typos
Drodt Jul 26, 2024
c36cc13
copy TacletBuilders
tobias-rnh Jul 26, 2024
091c53f
fix TacletPBuilder (WIP)
tobias-rnh Jul 26, 2024
dd8a087
start work on Semisequent
tobias-rnh Jul 26, 2024
2d5044f
Formatting
Drodt Jul 26, 2024
92b13f5
Merge pull request #10 from tobias-rnh/taclet-pbuilder
Drodt Jul 26, 2024
9af7cbf
start SemisequentChangeInfo
tobias-rnh Jul 26, 2024
b19d645
Merge branch 'rusty-while' into taclet-pbuilder
Drodt Jul 26, 2024
8ceeef7
adapt equality modulo renaming to rusty_while
tobias-rnh Jul 26, 2024
d6361f4
Merge pull request #11 from tobias-rnh/taclet-pbuilder
Drodt Jul 26, 2024
cd740e3
Read Rusty and SchemaRusty
Drodt Jul 26, 2024
601ac46
Fix ExpressionBuilder
Drodt Jul 26, 2024
4e23097
add toString() methods for simpler debugging of created taclets
tobias-rnh Jul 26, 2024
bea1bf5
add more taclets to testrules for rusty_while
tobias-rnh Jul 26, 2024
26f3394
Merge pull request #12 from tobias-rnh/taclet-pbuilder
Drodt Jul 27, 2024
a07e655
Allow application of taclets
Drodt Aug 12, 2024
ddba1ff
Spotless
Drodt Aug 12, 2024
265dbcf
Expand tests, fix quant vars, ...
Drodt Aug 13, 2024
5bfbee8
Remove references to Java in var names and comments
Drodt Aug 13, 2024
c4dcb8b
Merge branch 'main' into rusty-while
Drodt Aug 13, 2024
0cc948d
More tests & fixes
Drodt Aug 13, 2024
d83b854
More tests & fixes
Drodt Aug 13, 2024
ecf73f2
Remove some quant var checks
Drodt Aug 13, 2024
a32e029
Work on quant vars
Drodt Aug 14, 2024
ee16c3f
Merge branch 'calculus' into rusty-while
Drodt Aug 14, 2024
defb736
Use ncore.calculus; reduce passing of services
Drodt Aug 14, 2024
7fb0a59
Use calculus in rusty; formatting
Drodt Aug 14, 2024
c12e9da
Bump Java to 21
Drodt Aug 14, 2024
3f14edb
Fix tests and strats
Drodt Aug 14, 2024
ac6bdaa
Fix some constructors
Drodt Aug 14, 2024
16e27b3
Fix taclet builder; add tests
Drodt Aug 19, 2024
d601085
Add EmptyStatement, add tests, fix addRules
Drodt Aug 21, 2024
4fc34b7
Add rules; minor fix
Drodt Aug 21, 2024
08a74f1
Fix schema parsing, conversion, and matching on programs
Drodt Aug 22, 2024
cd51e34
Add varconds
Drodt Aug 22, 2024
f6459b7
First successful proof! (And fixes)
Drodt Aug 23, 2024
ed06741
Fix subst and quantifiers
Drodt Aug 26, 2024
8e45491
Spotless
Drodt Aug 26, 2024
6192b5f
Fix tests
Drodt Aug 26, 2024
0d443a2
Expand parser; rewrite converters
Drodt Aug 28, 2024
95fe495
Expand converters and AST classes
Drodt Aug 28, 2024
0705889
Add toString
Drodt Aug 28, 2024
bc33c57
Update Java & ANTLR version
Drodt Aug 29, 2024
dc42ca2
Format tests
Drodt Aug 29, 2024
fc3d61c
Merge branch 'main' into rusty-while
Drodt Aug 29, 2024
366bca0
Rename parsers
Drodt Aug 29, 2024
cbd3847
Rename module
Drodt Aug 29, 2024
8dd1d3b
More concrete type
Drodt Aug 30, 2024
34f8666
Merge branch 'main' into rusty
Drodt Aug 30, 2024
f6b5024
Add more rules; fixes
Drodt Sep 4, 2024
76e0f59
Finish IfTest
Drodt Sep 5, 2024
01433d5
Add more rules (and necessary fixes)
Drodt Sep 5, 2024
7b1d654
Add missing 'let'
Drodt Sep 6, 2024
1f093cb
Merge branch 'main' into rusty
Drodt Sep 6, 2024
75f4ca6
Add more rules
Drodt Sep 11, 2024
18285a9
Tuple rules, block assign rules
Drodt Sep 11, 2024
b841876
Compound assignment
Drodt Sep 11, 2024
17c9c31
Bool expr rules
Drodt Sep 11, 2024
02ed921
Add proof saving
Drodt Sep 14, 2024
ce56856
ProofReplayer
Drodt Sep 14, 2024
cf5dcea
RunAllProofs
Drodt Sep 17, 2024
b6bf0cc
Rework types in code
Drodt Sep 18, 2024
f9ba875
Start refactoring taclets to ncore
Drodt Sep 18, 2024
8d45819
Formatting
Drodt Sep 18, 2024
5976b4d
Fix some errors
Drodt Sep 18, 2024
889c2cc
Start using calculus in rusty
Drodt Sep 27, 2024
f5cc73a
Fix
Drodt Oct 10, 2024
20a9f4d
Remove some generics
Drodt Oct 10, 2024
21c5453
Fix generics and inheritance
Drodt Oct 16, 2024
fa7da83
Fix most errors
Drodt Oct 23, 2024
1ff2de1
fix compilation errors in TestApplyTaclet
unp1 Oct 24, 2024
1fc53f1
Spotless fixes
unp1 Oct 24, 2024
f75e8e4
Fix static initialisation errors
unp1 Oct 25, 2024
c3dc2c8
spotless fixes
unp1 Oct 25, 2024
ffd3b43
Sequents
Drodt Nov 6, 2024
0abdc55
Merge branch 'ncore-taclets' of github.com:Drodt/key into ncore-taclets
Drodt Nov 6, 2024
316232d
Fix merge error & rusty
Drodt Nov 13, 2024
97ebbe5
Fix compilation errors
Drodt Nov 13, 2024
3f27f5f
Fix Pos hash
Drodt Nov 13, 2024
fa6b7ef
Fix skolem terms
Drodt Nov 13, 2024
d6d332f
Fix goBelowUpdate and mergeRule
Drodt Nov 14, 2024
8f80ee2
Fix Empty Sequent
Drodt Nov 14, 2024
d2ab55b
Merge branch 'main' into ncore-taclets
Drodt Nov 14, 2024
18529c7
Fix rusty
Drodt Nov 14, 2024
78efa3b
Renamed package
unp1 Nov 18, 2024
4b8ab3a
Merge branch 'main' of github.com:keyproject/key into test
unp1 Nov 18, 2024
179ef65
factored out remaining equalsModProofIrrelevancy
unp1 Nov 27, 2024
a8e2b62
Fixed compilation errors and add a reflection based dynamic dispatche…
unp1 Nov 27, 2024
944ee3b
Added comments and minor code cleanup
unp1 Nov 27, 2024
3b3738d
Fix slicing
Drodt Dec 4, 2024
68b70ae
Remove EqualsModProofIrrelevancy interface
Drodt Dec 4, 2024
17d2d6b
Remove reflection
Drodt Dec 9, 2024
064570f
Replace java.SequentFormula with ncore.SequentFormula
Drodt Dec 11, 2024
ebc3268
Remove java.SequentFormula
Drodt Dec 11, 2024
499c749
Sequent refactoring
unp1 Dec 20, 2024
a3f22ca
Generalized sequents and semisequents
unp1 Dec 21, 2024
f5905b7
Fix program variable replacer
unp1 Dec 21, 2024
d25fda4
Fix compilation errors
unp1 Dec 21, 2024
5a91b58
Commit fix (unrelated) testcase
unp1 Dec 22, 2024
647d83f
Remove unused static methods from sequent kits for JavaDL and RustyDL
unp1 Dec 22, 2024
0668dd4
Spotless fixes
unp1 Dec 22, 2024
dbd7605
Generaliized and moved some rules and calculus related classes
unp1 Jan 6, 2025
8212d58
Code cleanup
unp1 Jan 6, 2025
160c069
Additional code cleanup
unp1 Jan 6, 2025
9500b05
Remove unused imports and minor cleanups
unp1 Jan 6, 2025
dde0d2f
Use ncore SchemaVariable at more places
unp1 Jan 6, 2025
568dbaf
Minor fix for SymbolcExecutionUtil
unp1 Jan 6, 2025
cc0afbc
Fixed a few tests
unp1 Jan 7, 2025
87b12e8
Fix modality caching
unp1 Jan 8, 2025
f21b9bc
Add more hashcode and equals methods to RustyAST clases
unp1 Jan 8, 2025
f919fe3
Remove JavaDL specific SchemaVariable interface
unp1 Jan 8, 2025
9280539
Added comment to Layoutable interface
unp1 Jan 8, 2025
f448b29
Remove Layoutable class
unp1 Jan 8, 2025
832d4eb
Fix compilation error (forgotten implements for no longer interface)
unp1 Jan 8, 2025
acd9e08
spotless fixes
unp1 Jan 8, 2025
dc18d6c
Replace specific Rule interface by ncore Rule interface
unp1 Jan 8, 2025
09e9772
spotless fixes
unp1 Jan 8, 2025
e99f4d6
Minor cleanup
unp1 Jan 10, 2025
0f1b567
Refactoring of InstantiationEntry classes
unp1 Jan 10, 2025
cfc0e49
Added comments to SVInstantiations interface
unp1 Jan 10, 2025
4a12eb5
Fixed bug (class cast exception) in ProgVarReplacer
unp1 Jan 10, 2025
78f8961
Fix for modality caching and sort equality
unp1 Jan 12, 2025
e96c354
Add test for WeakValue map implementation
unp1 Jan 13, 2025
8571f0b
Added comments to assumes instantiation types and minor clean up
unp1 Jan 15, 2025
e6ba6a3
Added comment for AssumesMatchResult
unp1 Jan 15, 2025
d10c2e7
Moved rule instantiation related types to corresponding package (and …
unp1 Jan 15, 2025
30b2380
Created package rules.conditions in ncore for common taclet related c…
unp1 Jan 15, 2025
ad8a543
Refactored misnamed method in RuleApp and added comments
unp1 Jan 15, 2025
280a2bf
Some taclet classes related cleanup
unp1 Jan 15, 2025
fd99b64
Removed empty class and some readability improvements to taclet classes
unp1 Jan 15, 2025
1c1ee9f
Replace usage of JFunction by Function where possible
unp1 Jan 15, 2025
51a792b
Reduced generic parameters for TacletExecutors
unp1 Jan 15, 2025
7cc5c77
Removed unnecessary RuleApp interface in Rusty
unp1 Jan 15, 2025
12c2c5e
Clean up for syntactical replace visitors
unp1 Jan 15, 2025
0ae4bdc
Clean up rusty syntactical replace visitor
unp1 Jan 15, 2025
99a3527
Fixed JavaDoc comment tags.
unp1 Jan 16, 2025
3f0bb71
Update qodana linter
unp1 Jan 16, 2025
9319356
Move exception type "IllegalInstantiationException" to ncore
unp1 Jan 16, 2025
da879c3
Fix printing of ModalOperatorSVs
unp1 Jan 17, 2025
186107d
Create textual representation of taclets in inner nodes only if these…
unp1 Jan 17, 2025
60ec89e
Fix bugs related to KeYJavaType
unp1 Jan 22, 2025
b14e154
Make EnhancedForElimination state independent
unp1 Jan 22, 2025
69f230e
Minor cleanup
unp1 Jan 22, 2025
3b2850b
Added comments and removed some unnecessary casts and qualified name …
unp1 Jan 22, 2025
a489dd9
Moved prover engine interfaces to ncore
unp1 Jan 23, 2025
454b508
Move more code for prover engine to ncore
unp1 Jan 23, 2025
d71f8de
Simplify method signatures and reduce number of generic arguments for…
unp1 Jan 23, 2025
b8ccddb
Improved naming of method in StopCondition and added comments to Appl…
unp1 Jan 24, 2025
0b96d8c
Comments for interface ProverCore
unp1 Jan 24, 2025
f885bef
Comments for TaskFinishedInfo
unp1 Jan 24, 2025
69e9ee3
More comments for generalized interfaces
unp1 Jan 24, 2025
723f19e
Comment for Taclet Triggers
unp1 Jan 24, 2025
d728a2b
Completed comment for interface ProofGoal
unp1 Jan 24, 2025
f12da11
Make proof listener list and its usage thread safe in ProofObject
unp1 Jan 24, 2025
d19468c
Minor code cleanup
unp1 Jan 24, 2025
97c768d
Consistent and improved naming of method parameters and local variables
unp1 Jan 24, 2025
bc3855a
Fix JavaDoc warning in key.core
unp1 Jan 24, 2025
19da35d
Commented FormulaChangeInfo and removed unnecessary method
unp1 Jan 24, 2025
36e2543
Improve comments in Semisequent, more consistent naming of method par…
unp1 Jan 24, 2025
9daa7bc
Improved and completed API documentation of the Sequent class
unp1 Jan 24, 2025
0affcc9
Started to move prover main loop to ncore
unp1 Jan 24, 2025
2db8253
Moved termfeatures to ncore and replaced some term feature implementa…
unp1 Jan 24, 2025
8b9b059
Moved ApplyTFFeature to ncore
unp1 Jan 24, 2025
6bd1365
Minor clean up
unp1 Jan 24, 2025
fd6cea7
Cleaned up strategy features
unp1 Jan 25, 2025
18a1890
Generalized TermLabel feature to generic TermPredicateFeature.
unp1 Jan 25, 2025
30c0b46
Minor cleanup
unp1 Jan 25, 2025
bba2f81
Moved more strategy features to ncore
unp1 Jan 25, 2025
9aeec12
Moved several termgenerators to ncore
unp1 Jan 25, 2025
8eb68ba
Slight reorganisation of the package structure concerning the default…
unp1 Jan 25, 2025
8512d58
Fix introduce bug in AutomatedRuleFeature
unp1 Jan 25, 2025
be12a5d
Moved more rule filters to ncore
unp1 Jan 25, 2025
ec648e3
Moved last remaining rule filter to ncore
unp1 Jan 26, 2025
0e74951
Progress on generalization of taclet application indices
unp1 Jan 26, 2025
add6f70
Modernized Java used in TacletIndex
unp1 Jan 26, 2025
2eabcd6
Minor clean up in AbstractProofReplayer
unp1 Jan 26, 2025
233fdb5
Fix SymbolicExecutionStrategy
unp1 Jan 26, 2025
40ff7c6
Added and improved comments
unp1 Jan 26, 2025
619275a
Remove generic from Feature class declarations
unp1 Jan 30, 2025
be361cb
Minor code cleanup
unp1 Jan 31, 2025
36b2a36
Add missing @Override annotations
unp1 Jan 31, 2025
27d43c2
Remove unnecessarily fully qualified names
unp1 Jan 31, 2025
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
Prev Previous commit
Next Next commit
Convert to KeY AST
Drodt committed Jun 20, 2024
commit 7bc8e41180f9148a3f5bdbd55c7f7ddaef8b84a5
4 changes: 4 additions & 0 deletions keyext.rusty_while/build.gradle
Original file line number Diff line number Diff line change
@@ -20,4 +20,8 @@ dependencies {

test {
useJUnitPlatform()
}

generateGrammarSource {
arguments += ["-visitor"]
}
8 changes: 4 additions & 4 deletions keyext.rusty_while/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn f(a: i32, b: i32) -> (i32, i32) {
let mut a = a + b;
let b = a - b;
fn f(a: i32, b: i32) -> i32 {
let mut a: i32 = a + b;
let b: i32 = a - b;
a = a - b;
(a, b)
a
}
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;

import org.key_project.rusty.ast.Converter;
import org.key_project.rusty.parsing.RustyWhileLexer;
import org.key_project.rusty.parsing.RustyWhileParser;

@@ -17,13 +18,16 @@
public class Test {
public static void main(String[] args) {
try {
var example = Files.readString(Paths.get("ncore.rusty_while/examples/basic.rs"),
var example = Files.readString(Paths.get("keyext.rusty_while/examples/basic.rs"),
Charset.defaultCharset());
var lexer = new RustyWhileLexer(CharStreams.fromString(example));
var ts = new CommonTokenStream(lexer);
var parser = new RustyWhileParser(ts);
var crate = parser.crate();
System.out.println(crate.item(0).function_().blockExpr().stmts().expr().getText());
System.out.println(crate.getText());
var converted = Converter.convertCrate(crate);
System.out.println(converted);
} catch (IOException e) {
throw new RuntimeException(e);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
/* This file is part of KeY - https://key-project.org
* KeY is licensed under the GNU General Public License Version 2
* SPDX-License-Identifier: GPL-2.0-only */
package org.key_project.rusty.ast;

import java.math.BigInteger;

import org.key_project.logic.Name;
import org.key_project.logic.SyntaxElement;
import org.key_project.rusty.ast.expr.*;
import org.key_project.rusty.ast.fn.Function;
import org.key_project.rusty.ast.fn.Param;
import org.key_project.rusty.ast.pat.IdentPattern;
import org.key_project.rusty.ast.pat.Pattern;
import org.key_project.rusty.ast.stmt.ExpressionStatement;
import org.key_project.rusty.ast.stmt.LetStatement;
import org.key_project.rusty.ast.stmt.Statement;
import org.key_project.rusty.ast.ty.PrimitiveType;
import org.key_project.rusty.ast.ty.Type;
import org.key_project.util.collection.ImmutableList;

public class Converter
extends org.key_project.rusty.parsing.RustyWhileParserBaseVisitor<SyntaxElement> {
private static final CrateConverter crateConverter = new CrateConverter();
private static final ItemConverter itemConverter = new ItemConverter();
private static final ExprConverter exprConverter = new ExprConverter();
private static final StmtConverter stmtConverter = new StmtConverter();
private static final IdentifierConverter identifierConverter = new IdentifierConverter();
private static final PatternConverter patternConverter = new PatternConverter();
private static final TypeConverter typeConverter = new TypeConverter();
private static final ParamConverter paramConverter = new ParamConverter();

public static Crate convertCrate(
org.key_project.rusty.parsing.RustyWhileParser.CrateContext ctx) {
return ctx.accept(crateConverter);
}

@Override
public Expr visitAssignmentExpression(
org.key_project.rusty.parsing.RustyWhileParser.AssignmentExpressionContext ctx) {
return exprConverter.visitAssignmentExpression(ctx);
}

@Override
public Expr visitBlockExpr(
org.key_project.rusty.parsing.RustyWhileParser.BlockExprContext ctx) {
return exprConverter.visitBlockExpr(ctx);
}

@Override
public Expr visitLiteralExpr(
org.key_project.rusty.parsing.RustyWhileParser.LiteralExprContext ctx) {
return exprConverter.visitLiteralExpr(ctx);
}

@Override
public Expr visitPathExpr(org.key_project.rusty.parsing.RustyWhileParser.PathExprContext ctx) {
return exprConverter.visitPathExpr(ctx);
}

@Override
public Statement visitExprStmt(
org.key_project.rusty.parsing.RustyWhileParser.ExprStmtContext ctx) {
return stmtConverter.visitExprStmt(ctx);
}

@Override
public Statement visitLetStmt(
org.key_project.rusty.parsing.RustyWhileParser.LetStmtContext ctx) {
return stmtConverter.visitLetStmt(ctx);
}

@Override
public Identifier visitIdentifier(
org.key_project.rusty.parsing.RustyWhileParser.IdentifierContext ctx) {
return identifierConverter.visitIdentifier(ctx);
}

@Override
public Pattern visitPattern(org.key_project.rusty.parsing.RustyWhileParser.PatternContext ctx) {
return patternConverter.visitPattern(ctx);
}

public Type convertParenthesizedType(
org.key_project.rusty.parsing.RustyWhileParser.ParenthesizedTypeContext ctx) {
return typeConverter.visitParenthesizedType(ctx);
}

public Type convertTypePath(
org.key_project.rusty.parsing.RustyWhileParser.TypePathContext ctx) {
return typeConverter.visitTypePath(ctx);
}

private static class CrateConverter
extends org.key_project.rusty.parsing.RustyWhileParserBaseVisitor<Crate> {
@Override
public Crate visitCrate(org.key_project.rusty.parsing.RustyWhileParser.CrateContext ctx) {
return new Crate(ctx.item().stream().map(i -> i.accept(itemConverter))
.collect(ImmutableList.collector()));
}
}

private static class ItemConverter
extends org.key_project.rusty.parsing.RustyWhileParserBaseVisitor<Item> {
@Override
public Item visitItem(org.key_project.rusty.parsing.RustyWhileParser.ItemContext ctx) {
// TODO: Rework
return ctx.function_().accept(this);
}

@Override
public Function visitFunction_(
org.key_project.rusty.parsing.RustyWhileParser.Function_Context ctx) {
return new Function(ctx.identifier().accept(identifierConverter).name(),
ctx.functionParams().functionParam().stream().map(p -> p.accept(paramConverter))
.collect(ImmutableList.collector()),
ctx.functionRetTy().type_().accept(typeConverter),
(BlockExpression) ctx.blockExpr().accept(exprConverter));
}
}

private static class ExprConverter
extends org.key_project.rusty.parsing.RustyWhileParserBaseVisitor<Expr> {
@Override
public Expr visitArithmeticOrLogicalExpression(
org.key_project.rusty.parsing.RustyWhileParser.ArithmeticOrLogicalExpressionContext ctx) {
ArithLogicalExpression.Operator op = null;
if (ctx.AND() != null)
op = ArithLogicalExpression.Operator.BitwiseAnd;
if (ctx.OR() != null)
op = ArithLogicalExpression.Operator.BitwiseOr;
if (ctx.CARET() != null)
op = ArithLogicalExpression.Operator.BitwiseXor;
if (ctx.PLUS() != null)
op = ArithLogicalExpression.Operator.Plus;
if (ctx.MINUS() != null)
op = ArithLogicalExpression.Operator.Minus;
if (ctx.PERCENT() != null)
op = ArithLogicalExpression.Operator.Modulo;
if (ctx.STAR() != null)
op = ArithLogicalExpression.Operator.Multiply;
if (ctx.SLASH() != null)
op = ArithLogicalExpression.Operator.Divide;
assert op != null;
return new ArithLogicalExpression(ctx.expr(0).accept(this), op,
ctx.expr(1).accept(this));
}

@Override
public AssignmentExpression visitAssignmentExpression(
org.key_project.rusty.parsing.RustyWhileParser.AssignmentExpressionContext ctx) {
var lhs = ctx.expr(0).accept(this);
var rhs = ctx.expr(1).accept(this);
return new AssignmentExpression(lhs, rhs);
}

@Override
public BlockExpression visitBlockExpr(
org.key_project.rusty.parsing.RustyWhileParser.BlockExprContext ctx) {
var stmtsCtx = ctx.stmts();

var stmts = stmtsCtx.stmt().stream().map(s -> s.accept(stmtConverter))
.collect(ImmutableList.collector());
var value = stmtsCtx.expr().accept(this);

return new BlockExpression(stmts, value);
}

@Override
public Expr visitLiteralExpr(
org.key_project.rusty.parsing.RustyWhileParser.LiteralExprContext ctx) {
if (ctx.KW_TRUE() != null)
return new BooleanLiteralExpression(true);
if (ctx.KW_FALSE() != null)
return new BooleanLiteralExpression(false);
var intLit = ctx.INTEGER_LITERAL();
if (intLit != null) {
var text = intLit.getText();
var split = text.split("_");
var suffix = switch (split[split.length - 1]) {
case "u8" -> IntegerLiteralExpression.IntegerSuffix.u8;
case "u16" -> IntegerLiteralExpression.IntegerSuffix.u16;
case "u32" -> IntegerLiteralExpression.IntegerSuffix.u32;
case "u64" -> IntegerLiteralExpression.IntegerSuffix.u64;
case "u128" -> IntegerLiteralExpression.IntegerSuffix.u128;
case "usize" -> IntegerLiteralExpression.IntegerSuffix.usize;
case "i8" -> IntegerLiteralExpression.IntegerSuffix.i8;
case "i16" -> IntegerLiteralExpression.IntegerSuffix.i16;
case "i32" -> IntegerLiteralExpression.IntegerSuffix.i32;
case "i64" -> IntegerLiteralExpression.IntegerSuffix.i64;
case "i128" -> IntegerLiteralExpression.IntegerSuffix.i128;
case "isize" -> IntegerLiteralExpression.IntegerSuffix.isize;
default -> throw new IllegalArgumentException(
"Right now we require a suffix on all literals");
};

var value = new BigInteger(
text.substring(0, text.length() - split[split.length - 1].length()));
return new IntegerLiteralExpression(value, suffix);
}

throw new IllegalArgumentException("Expected boolean or integer literal");
}

@Override
public PathExpression visitPathExpr(
org.key_project.rusty.parsing.RustyWhileParser.PathExprContext ctx) {
assert ctx.pathExprSegment().size() == 1;
return new PathExpression(
ctx.pathExprSegment(0).pathIdentSegment().identifier().accept(identifierConverter));
}
}

private static class StmtConverter
extends org.key_project.rusty.parsing.RustyWhileParserBaseVisitor<Statement> {
@Override
public Statement visitExprStmt(
org.key_project.rusty.parsing.RustyWhileParser.ExprStmtContext ctx) {
return new ExpressionStatement(ctx.expr().accept(exprConverter));
}

@Override
public Statement visitLetStmt(
org.key_project.rusty.parsing.RustyWhileParser.LetStmtContext ctx) {
return new LetStatement(ctx.pattern().accept(patternConverter),
ctx.type_().accept(typeConverter), ctx.expr().accept(exprConverter));
}
}

private static class IdentifierConverter
extends org.key_project.rusty.parsing.RustyWhileParserBaseVisitor<Identifier> {
@Override
public Identifier visitIdentifier(
org.key_project.rusty.parsing.RustyWhileParser.IdentifierContext ctx) {
return new Identifier(new Name(ctx.getText()));
}
}

private static class PatternConverter
extends org.key_project.rusty.parsing.RustyWhileParserBaseVisitor<Pattern> {
@Override
public Pattern visitPattern(
org.key_project.rusty.parsing.RustyWhileParser.PatternContext ctx) {
return new IdentPattern(ctx.KW_MUT() != null,
ctx.identifier().accept(identifierConverter));
}
}

private static class TypeConverter
extends org.key_project.rusty.parsing.RustyWhileParserBaseVisitor<Type> {
@Override
public Type visitParenthesizedType(
org.key_project.rusty.parsing.RustyWhileParser.ParenthesizedTypeContext ctx) {
return ctx.type_().accept(this);
}

@Override
public Type visitTypePath(
org.key_project.rusty.parsing.RustyWhileParser.TypePathContext ctx) {
assert ctx.typePathSegment().size() == 1;
var text = ctx.typePathSegment(0).pathIdentSegment().identifier().getText();
return switch (text) {
case "bool" -> PrimitiveType.BOOL;
case "u8" -> PrimitiveType.U8;
case "u16" -> PrimitiveType.U16;
case "u32" -> PrimitiveType.U32;
case "u64" -> PrimitiveType.U64;
case "u128" -> PrimitiveType.U128;
case "usize" -> PrimitiveType.USIZE;
case "i8" -> PrimitiveType.I8;
case "i16" -> PrimitiveType.I16;
case "i32" -> PrimitiveType.I32;
case "i64" -> PrimitiveType.I64;
case "i128" -> PrimitiveType.I128;
case "isize" -> PrimitiveType.ISIZE;
case "char" -> PrimitiveType.CHAR;
case "str" -> PrimitiveType.STR;
case "!" -> PrimitiveType.NEVER;
default -> throw new IllegalArgumentException("Unknown type '" + text + "'");
};
}
}

private static class ParamConverter
extends org.key_project.rusty.parsing.RustyWhileParserBaseVisitor<Param> {
@Override
public Param visitFunctionParamPattern(
org.key_project.rusty.parsing.RustyWhileParser.FunctionParamPatternContext ctx) {
return new Param(ctx.pattern().accept(patternConverter),
ctx.type_().accept(typeConverter));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* This file is part of KeY - https://key-project.org
* KeY is licensed under the GNU General Public License Version 2
* SPDX-License-Identifier: GPL-2.0-only */
package org.key_project.rusty.ast;

import java.util.stream.Collectors;

import org.key_project.logic.SyntaxElement;
import org.key_project.util.collection.ImmutableList;

public class Crate implements SyntaxElement {
private final ImmutableList<Item> items;

public Crate(ImmutableList<Item> items) {
this.items = items;
}

@Override
public int getChildCount() {
return items.size();
}

@Override
public SyntaxElement getChild(int n) {
return items.get(n);
}

@Override
public String toString() {
return items.map(Item::toString).stream().collect(Collectors.joining("\n"));
}
}
Loading