From dcb153908f86eb70750a1f5e0418f9af7b2b6ca1 Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Thu, 3 Oct 2024 11:13:44 +0200 Subject: [PATCH 01/16] smallestCommonType now supports void --- .../frontend/transformation/model/types/complex/CVoid.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/CVoid.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/CVoid.java index 4d9d121d1e..353ca2cc9a 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/CVoid.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/CVoid.java @@ -29,6 +29,11 @@ public R accept(CComplexTypeVisitor visitor, T param) { return visitor.visit(this, param); } + @Override + public CComplexType getSmallestCommonType(CComplexType type) { + return type; + } + @Override public String getTypeName() { return "void"; From 244eb924efdddb48e89d6fc197dff4057ab24663 Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Thu, 3 Oct 2024 12:01:15 +0200 Subject: [PATCH 02/16] Fixed struct and pointer dereferencing --- .../grammar/type/TypeVisitor.java | 31 ++++++------------- .../model/declaration/CDeclaration.java | 4 ++- .../model/types/simple/Struct.java | 21 ++++++++++--- .../mit/theta/c2xcfa/FrontendXcfaBuilder.kt | 4 ++- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/TypeVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/TypeVisitor.java index 83acdef4b6..5fbaf45690 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/TypeVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/TypeVisitor.java @@ -28,32 +28,15 @@ import hu.bme.mit.theta.frontend.transformation.grammar.preprocess.TypedefVisitor; import hu.bme.mit.theta.frontend.transformation.model.declaration.CDeclaration; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; -import hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleType; -import hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory; -import hu.bme.mit.theta.frontend.transformation.model.types.simple.DeclaredName; import hu.bme.mit.theta.frontend.transformation.model.types.simple.Enum; -import hu.bme.mit.theta.frontend.transformation.model.types.simple.NamedType; -import hu.bme.mit.theta.frontend.transformation.model.types.simple.Struct; +import hu.bme.mit.theta.frontend.transformation.model.types.simple.*; import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.tree.ParseTree; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; -import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.Atomic; -import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.DeclaredName; -import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.Enum; -import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.Extern; -import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.NamedType; -import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.Signed; -import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.ThreadLocal; -import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.Typedef; -import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.Unsigned; -import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.Volatile; +import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.*; public class TypeVisitor extends CBaseVisitor { private final DeclarationVisitor declarationVisitor; @@ -245,13 +228,17 @@ public CSimpleType visitCompoundDefinition(CParser.CompoundDefinitionContext ctx CParser.SpecifierQualifierListContext specifierQualifierListContext = structDeclarationContext.specifierQualifierList(); CSimpleType cSimpleType = specifierQualifierListContext.accept(this); if (structDeclarationContext.structDeclaratorList() == null) { - struct.addField(cSimpleType.getAssociatedName(), cSimpleType); + final var decl = new CDeclaration(cSimpleType); + struct.addField(decl); } else { for (CParser.StructDeclaratorContext structDeclaratorContext : structDeclarationContext.structDeclaratorList() .structDeclarator()) { CDeclaration declaration = structDeclaratorContext.accept( declarationVisitor); - struct.addField(declaration.getName(), cSimpleType); + if (declaration.getType() == null) { + declaration.setType(cSimpleType); + } + struct.addField(declaration); } } } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/declaration/CDeclaration.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/declaration/CDeclaration.java index 7c8ce9b585..7242590d40 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/declaration/CDeclaration.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/declaration/CDeclaration.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.List; +import static com.google.common.base.Preconditions.checkNotNull; + public class CDeclaration { private CSimpleType type; @@ -37,7 +39,7 @@ public class CDeclaration { private CStatement initExpr; public CDeclaration(CSimpleType cSimpleType) { - this.name = null; + this.name = checkNotNull(cSimpleType).getAssociatedName(); this.type = cSimpleType; this.derefCounter = cSimpleType.getPointerLevel(); this.varDecls = new ArrayList<>(); diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Struct.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Struct.java index eb3d8ad12f..a7b55db04d 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Struct.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Struct.java @@ -20,7 +20,9 @@ import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.common.logging.Logger.Level; import hu.bme.mit.theta.frontend.ParseContext; +import hu.bme.mit.theta.frontend.transformation.model.declaration.CDeclaration; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; +import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CPointer; import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CStruct; import java.util.ArrayList; @@ -28,9 +30,11 @@ import java.util.List; import java.util.Map; +import static com.google.common.base.Preconditions.checkNotNull; + public class Struct extends NamedType { - private final Map fields; + private final Map fields; private final String name; private final Logger uniqueWarningLogger; @@ -52,8 +56,8 @@ public static Struct getByName(String name) { currentlyBeingBuilt = false; } - public void addField(String name, CSimpleType type) { - fields.put(name, type); + public void addField(CDeclaration decl) { + fields.put(checkNotNull(decl.getName()), checkNotNull(decl)); } @Override @@ -64,9 +68,16 @@ public CComplexType getActualType() { } currentlyBeingBuilt = true; List> actualFields = new ArrayList<>(); - fields.forEach((s, cSimpleType) -> actualFields.add(Tuple2.of(s, cSimpleType.getActualType()))); + fields.forEach((s, cDeclaration) -> actualFields.add(Tuple2.of(s, cDeclaration.getActualType()))); currentlyBeingBuilt = false; - return new CStruct(this, actualFields, parseContext); + + CComplexType type = new CStruct(this, actualFields, parseContext); + + for (int i = 0; i < getPointerLevel(); i++) { + type = new CPointer(this, type, parseContext); + } + + return type; } @Override diff --git a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt index 6dccaaa36c..7bd0113897 100644 --- a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt +++ b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt @@ -94,7 +94,9 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo continue } if (type is CStruct) { - error("Not handling init expression of struct array ${globalDeclaration.get1()}") + uniqueWarningLogger.write( + Logger.Level.INFO, "Not handling init expression of struct array ${globalDeclaration.get1()}" + ) } builder.addVar(XcfaGlobalVar(globalDeclaration.get2(), type.nullValue)) if (type is CArray) { From c24de492baad29f0ad4b54fc38a2c79ccfe7e868 Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Thu, 17 Oct 2024 11:21:59 +0200 Subject: [PATCH 03/16] Instead of FrontendFailure, throw UnsupportedElement --- .../UnsupportedFrontendElementException.java | 23 +++++++++ .../grammar/expression/ExpressionVisitor.java | 48 +++++-------------- .../expression/UnsupportedInitializer.java | 3 +- .../grammar/type/DeclarationVisitor.java | 9 ++-- .../grammar/type/TypeVisitor.java | 17 +++---- .../model/statements/CAssignment.java | 3 +- .../model/statements/CInitializerList.java | 3 +- .../model/statements/CStatement.java | 7 +-- .../model/types/complex/CComplexType.java | 22 +++------ .../model/types/complex/integer/Fitsall.java | 2 +- .../visitors/bitvector/CastVisitor.java | 5 +- .../model/types/simple/NamedType.java | 3 +- .../mit/theta/xcfa/cli/params/ExitCodes.kt | 5 ++ 13 files changed, 76 insertions(+), 74 deletions(-) create mode 100644 subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/UnsupportedFrontendElementException.java diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/UnsupportedFrontendElementException.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/UnsupportedFrontendElementException.java new file mode 100644 index 0000000000..e3bef460e0 --- /dev/null +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/UnsupportedFrontendElementException.java @@ -0,0 +1,23 @@ +/* + * Copyright 2024 Budapest University of Technology and Economics + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.bme.mit.theta.frontend; + +public class UnsupportedFrontendElementException extends RuntimeException { + public UnsupportedFrontendElementException(String message) { + super(message); + } +} diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java index 60a7ff7609..d714b8693a 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java @@ -18,13 +18,7 @@ import hu.bme.mit.theta.c.frontend.dsl.gen.CBaseVisitor; import hu.bme.mit.theta.c.frontend.dsl.gen.CParser; -import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionAccessContext; -import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionBracesContext; -import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionBracketsContext; -import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionDecrementContext; -import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionIncrementContext; -import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionMemberAccessContext; -import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.PostfixExpressionPtrMemberAccessContext; +import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.*; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.common.logging.Logger.Level; @@ -35,33 +29,22 @@ import hu.bme.mit.theta.core.type.abstracttype.AbstractExprs; import hu.bme.mit.theta.core.type.abstracttype.DivExpr; import hu.bme.mit.theta.core.type.abstracttype.ModExpr; -import hu.bme.mit.theta.core.type.anytype.Dereference; -import hu.bme.mit.theta.core.type.anytype.Exprs; -import hu.bme.mit.theta.core.type.anytype.IteExpr; -import hu.bme.mit.theta.core.type.anytype.RefExpr; -import hu.bme.mit.theta.core.type.anytype.Reference; +import hu.bme.mit.theta.core.type.anytype.*; import hu.bme.mit.theta.core.type.booltype.BoolExprs; import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.bvtype.BvAndExpr; -import hu.bme.mit.theta.core.type.bvtype.BvExprs; -import hu.bme.mit.theta.core.type.bvtype.BvOrExpr; -import hu.bme.mit.theta.core.type.bvtype.BvType; -import hu.bme.mit.theta.core.type.bvtype.BvXorExpr; +import hu.bme.mit.theta.core.type.bvtype.*; import hu.bme.mit.theta.core.type.fptype.FpLitExpr; import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.utils.BvUtils; import hu.bme.mit.theta.core.utils.FpUtils; import hu.bme.mit.theta.frontend.ParseContext; +import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException; import hu.bme.mit.theta.frontend.transformation.ArchitectureConfig; import hu.bme.mit.theta.frontend.transformation.grammar.function.FunctionVisitor; import hu.bme.mit.theta.frontend.transformation.grammar.preprocess.TypedefVisitor; import hu.bme.mit.theta.frontend.transformation.grammar.type.TypeVisitor; import hu.bme.mit.theta.frontend.transformation.model.declaration.CDeclaration; -import hu.bme.mit.theta.frontend.transformation.model.statements.CAssignment; -import hu.bme.mit.theta.frontend.transformation.model.statements.CCall; -import hu.bme.mit.theta.frontend.transformation.model.statements.CCompound; -import hu.bme.mit.theta.frontend.transformation.model.statements.CExpr; -import hu.bme.mit.theta.frontend.transformation.model.statements.CStatement; +import hu.bme.mit.theta.frontend.transformation.model.statements.*; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CArray; import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CPointer; @@ -70,23 +53,14 @@ import org.kframework.mpfr.BinaryMathContext; import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Deque; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Add; import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Div; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Geq; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Ite; import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Mod; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Neq; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Sub; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.*; import static hu.bme.mit.theta.core.type.anytype.Exprs.Reference; import static hu.bme.mit.theta.core.type.fptype.FpExprs.FpType; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; @@ -310,7 +284,7 @@ public Expr visitRelationalExpression(CParser.RelationalExpressionContext ctx guard = AbstractExprs.Geq(leftExpr, rightExpr); break; default: - throw new IllegalStateException("Unexpected value: " + ctx.signs.get(i).getText()); + throw new UnsupportedFrontendElementException("Unexpected relational expression sign: " + ctx.signs.get(i).getText()); } // MaxEnumAnalyzer.instance.consume(guard); TODO: handle circular dependency CComplexType signedInt = CComplexType.getSignedInt(parseContext); @@ -415,7 +389,7 @@ public Expr visitMultiplicativeExpression(CParser.MultiplicativeExpressionCon } break; default: - throw new IllegalStateException("Unexpected value: " + ctx.signs.get(i).getText()); + throw new UnsupportedFrontendElementException("Unexpected multiplicative expression sign: " + ctx.signs.get(i).getText()); } parseContext.getMetadata().create(expr, "cType", smallestCommonType); expr = smallestCommonType.castTo(expr); @@ -665,9 +639,9 @@ public Expr visitPrimaryExpressionConstant(CParser.PrimaryExpressionConstantC BigFloat bigFloat; if (text.startsWith("0x")) { - throw new UnsupportedOperationException("Hexadecimal FP constants are not yet supported!"); + throw new UnsupportedFrontendElementException("Hexadecimal FP constants are not yet supported!"); } else if (text.startsWith("0b")) { - throw new UnsupportedOperationException("Binary FP constants are not yet supported!"); + throw new UnsupportedFrontendElementException("Binary FP constants are not yet supported!"); } else { bigFloat = new BigFloat(text, new BinaryMathContext(significand - 1, exponent)); } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/UnsupportedInitializer.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/UnsupportedInitializer.java index 121f0a9bba..b11b230c07 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/UnsupportedInitializer.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/UnsupportedInitializer.java @@ -20,6 +20,7 @@ import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.NullaryExpr; import hu.bme.mit.theta.core.type.inttype.IntType; +import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; @@ -32,7 +33,7 @@ public IntType getType() { @Override public LitExpr eval(Valuation val) { - throw new UnsupportedOperationException("UnsupportedInitializer expressions are not supported."); + throw new UnsupportedFrontendElementException("UnsupportedInitializer expressions are not supported."); } @Override diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/DeclarationVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/DeclarationVisitor.java index f752eb7ef8..84be79414d 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/DeclarationVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/DeclarationVisitor.java @@ -22,6 +22,7 @@ import hu.bme.mit.theta.common.logging.Logger.Level; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.frontend.ParseContext; +import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException; import hu.bme.mit.theta.frontend.transformation.grammar.expression.UnsupportedInitializer; import hu.bme.mit.theta.frontend.transformation.grammar.function.FunctionVisitor; import hu.bme.mit.theta.frontend.transformation.grammar.preprocess.TypedefVisitor; @@ -140,7 +141,7 @@ public CDeclaration visitStructDeclaratorSimple(CParser.StructDeclaratorSimpleCo @Override public CDeclaration visitStructDeclaratorConstant(CParser.StructDeclaratorConstantContext ctx) { - throw new UnsupportedOperationException("Not yet supported!"); + throw new UnsupportedFrontendElementException("Not yet supported!"); } @Override @@ -191,17 +192,17 @@ public CDeclaration visitDirectDeclaratorArray1(CParser.DirectDeclaratorArray1Co @Override public CDeclaration visitDirectDeclaratorArray2(CParser.DirectDeclaratorArray2Context ctx) { - throw new UnsupportedOperationException("Not yet implemented!"); + throw new UnsupportedFrontendElementException("Not yet implemented!"); } @Override public CDeclaration visitDirectDeclaratorArray3(CParser.DirectDeclaratorArray3Context ctx) { - throw new UnsupportedOperationException("Not yet implemented!"); + throw new UnsupportedFrontendElementException("Not yet implemented!"); } @Override public CDeclaration visitDirectDeclaratorArray4(CParser.DirectDeclaratorArray4Context ctx) { - throw new UnsupportedOperationException("Not yet implemented!"); + throw new UnsupportedFrontendElementException("Not yet implemented!"); } @Override diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/TypeVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/TypeVisitor.java index 5fbaf45690..8fad36f961 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/TypeVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/type/TypeVisitor.java @@ -25,6 +25,7 @@ import hu.bme.mit.theta.common.logging.Logger.Level; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.frontend.ParseContext; +import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException; import hu.bme.mit.theta.frontend.transformation.grammar.preprocess.TypedefVisitor; import hu.bme.mit.theta.frontend.transformation.model.declaration.CDeclaration; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; @@ -194,15 +195,15 @@ public CSimpleType visitStorageClassSpecifier(CParser.StorageClassSpecifierConte case "auto": case "register": case "_Thread_local": - throw new UnsupportedOperationException("Not yet implemented"); + throw new UnsupportedFrontendElementException("Not yet implemented (" + ctx.getText() + ")"); } - throw new UnsupportedOperationException( + throw new UnsupportedFrontendElementException( "Storage class specifier not expected: " + ctx.getText()); } @Override public CSimpleType visitTypeSpecifierAtomic(CParser.TypeSpecifierAtomicContext ctx) { - throw new UnsupportedOperationException("Not yet implemented"); + throw new UnsupportedFrontendElementException("Not yet implemented"); } @Override @@ -212,7 +213,7 @@ public CSimpleType visitTypeSpecifierCompound(CParser.TypeSpecifierCompoundConte @Override public CSimpleType visitTypeSpecifierFunctionPointer(CParser.TypeSpecifierFunctionPointerContext ctx) { - throw new UnsupportedOperationException("Function pointers not yet implemented"); + throw new UnsupportedFrontendElementException("Function pointers not yet implemented"); } @Override @@ -285,7 +286,7 @@ public CSimpleType visitEnumUsage(CParser.EnumUsageContext ctx) { @Override public CSimpleType visitTypeSpecifierExtension(CParser.TypeSpecifierExtensionContext ctx) { - throw new UnsupportedOperationException("Not yet implemented"); + throw new UnsupportedFrontendElementException("Not yet implemented typeSpecifierExtension"); } @Override @@ -348,7 +349,7 @@ public CSimpleType visitTypeSpecifierTypedefName(CParser.TypeSpecifierTypedefNam @Override public CSimpleType visitTypeSpecifierTypeof(CParser.TypeSpecifierTypeofContext ctx) { - throw new UnsupportedOperationException("Not yet implemented"); + throw new UnsupportedFrontendElementException("Not yet implemented typeSpecifierTypeof"); } @Override @@ -357,13 +358,13 @@ public CSimpleType visitTypeQualifier(CParser.TypeQualifierContext ctx) { case "const": return null; case "restrict": - throw new UnsupportedOperationException("Not yet implemented!"); + throw new UnsupportedFrontendElementException("Not yet implemented 'restrict'!"); case "volatile": return Volatile(); case "_Atomic": return Atomic(); } - throw new UnsupportedOperationException( + throw new UnsupportedFrontendElementException( "Type qualifier " + ctx.getText() + " not expected!"); } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CAssignment.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CAssignment.java index 748b919252..8d285f2d04 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CAssignment.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CAssignment.java @@ -21,6 +21,7 @@ import hu.bme.mit.theta.core.type.bvtype.BvExprs; import hu.bme.mit.theta.core.type.bvtype.BvType; import hu.bme.mit.theta.frontend.ParseContext; +import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; import java.util.List; @@ -99,7 +100,7 @@ public Expr getrExpression() { ret = BvExprs.Or(List.of((Expr) type.castTo(lValue), (Expr) type.castTo(rExpression))); break; default: - throw new RuntimeException("Bad operator: " + operator); + throw new UnsupportedFrontendElementException("Unsupported operator: " + operator); } parseContext.getMetadata().create(ret, "cType", CComplexType.getType(lValue, parseContext)); ret = CComplexType.getType(lValue, parseContext).castTo(ret); diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CInitializerList.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CInitializerList.java index 4d7670b096..d12151fe4b 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CInitializerList.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CInitializerList.java @@ -19,6 +19,7 @@ import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.frontend.ParseContext; +import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; import java.util.ArrayList; @@ -38,7 +39,7 @@ public CInitializerList(CComplexType type, ParseContext parseContext) { @Override public Expr getExpression() { - throw new UnsupportedOperationException("Cannot create expression of initializer list."); + throw new UnsupportedFrontendElementException("Cannot create expression of initializer list."); } @Override diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatement.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatement.java index 44f8087a79..93a2199239 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatement.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatement.java @@ -18,6 +18,7 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.frontend.ParseContext; +import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException; /** * Every Program, Function and Statement is a subclass of this base class. @@ -60,7 +61,7 @@ public void setId(String id) { * @return The expression associated with the statement. */ public Expr getExpression() { - throw new RuntimeException("Cannot get expression!"); + throw new UnsupportedFrontendElementException("Cannot get expression!"); } public CStatement getPostStatements() { @@ -68,7 +69,7 @@ public CStatement getPostStatements() { } public void setPostStatements(CStatement postStatements) { - throw new UnsupportedOperationException("Only CCompounds shall currently have pre- and post statements!"); + throw new UnsupportedFrontendElementException("Only CCompounds shall currently have pre- and post statements!"); } public CStatement getPreStatements() { @@ -76,7 +77,7 @@ public CStatement getPreStatements() { } public void setPreStatements(CStatement preStatements) { - throw new UnsupportedOperationException("Only CCompounds shall currently have pre- and post statements!"); + throw new UnsupportedFrontendElementException("Only CCompounds shall currently have pre- and post statements!"); } public abstract R accept(CStatementVisitor visitor, P param); diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/CComplexType.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/CComplexType.java index 32b8c4b0e4..1f54441d28 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/CComplexType.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/CComplexType.java @@ -26,11 +26,8 @@ import hu.bme.mit.theta.core.type.fptype.FpType; import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.frontend.ParseContext; -import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CArray; -import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CCompound; -import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CFunction; -import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CPointer; -import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CStruct; +import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException; +import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.*; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.CInteger; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.Fitsall; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.c128.C128; @@ -62,12 +59,7 @@ import java.util.Map.Entry; import java.util.Optional; -import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getCastVisitor; -import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getLimitVisitor; -import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getNullValueVisitor; -import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getTypeVisitor; -import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getUnitValueVisitor; -import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.getValueVisitor; +import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.*; public abstract class CComplexType { private final CSimpleType origin; @@ -208,7 +200,7 @@ private static CComplexType getType(Type type, ParseContext parseContext) { if (longDoubleType.equals(type)) { return new CFloat(null, parseContext); } - throw new RuntimeException("No suitable size found for type: " + type); + throw new UnsupportedFrontendElementException("No suitable size found for type: " + type); } else if (type instanceof BvType) { for (Entry entry : parseContext.getArchitecture().standardTypeSizes.entrySet()) { String s = entry.getKey(); @@ -230,9 +222,9 @@ private static CComplexType getType(Type type, ParseContext parseContext) { } } } - throw new RuntimeException("No suitable width found for type: " + type); + throw new UnsupportedFrontendElementException("No suitable width found for type: " + type); } else { - throw new RuntimeException("Not yet implemented for type: " + type); + throw new UnsupportedFrontendElementException("Not yet implemented for type: " + type); } } @@ -307,7 +299,7 @@ public R accept(CComplexTypeVisitor visitor, T param) { public static class CComplexTypeVisitor { public R visit(CComplexType type, T param) { - throw new UnsupportedOperationException("Not (yet) implemented (" + type.getClass().getSimpleName() + " in " + this.getClass().getName() + ")"); + throw new UnsupportedFrontendElementException("Not (yet) implemented (" + type.getClass().getSimpleName() + " in " + this.getClass().getName() + ")"); } public R visit(CVoid type, T param) { diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Fitsall.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Fitsall.java index 6550e48040..8cb56130a7 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Fitsall.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Fitsall.java @@ -41,7 +41,7 @@ public String getTypeName() { @Override public CInteger getSignedVersion() { - throw new RuntimeException("Bool does not have a signed version!"); + throw new RuntimeException("Fitsall does not have a signed version!"); } @Override diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/CastVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/CastVisitor.java index ab2fd3faa7..6187ff3391 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/CastVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/CastVisitor.java @@ -25,6 +25,7 @@ import hu.bme.mit.theta.core.type.fptype.FpRoundingMode; import hu.bme.mit.theta.core.type.fptype.FpType; import hu.bme.mit.theta.frontend.ParseContext; +import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CVoid; import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CPointer; @@ -89,7 +90,7 @@ private Expr handleSignedConversion(CInteger type, Expr param } } } else { - throw new IllegalStateException("Compound types are not directly supported!"); + throw new UnsupportedFrontendElementException("Compound types are not directly supported!"); } } @@ -119,7 +120,7 @@ private Expr handleUnsignedConversion(CInteger type, Expr par } } } else { - throw new IllegalStateException("Compound types are not directly supported!"); + throw new UnsupportedFrontendElementException("Compound types are not directly supported!"); } } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/NamedType.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/NamedType.java index 2cbc83220d..2ff2c5fdb0 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/NamedType.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/NamedType.java @@ -19,6 +19,7 @@ import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.common.logging.Logger.Level; import hu.bme.mit.theta.frontend.ParseContext; +import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CVoid; import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CPointer; @@ -169,7 +170,7 @@ protected void patch(CSimpleType cSimpleType) { break; default: if (!cSimpleType.isTypedef()) { - throw new RuntimeException( + throw new UnsupportedFrontendElementException( "namedType should be short or long or type specifier, instead it is " + namedType); } diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/ExitCodes.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/ExitCodes.kt index 563a7abaa3..1ecf5e665a 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/ExitCodes.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/ExitCodes.kt @@ -18,6 +18,7 @@ package hu.bme.mit.theta.xcfa.cli.params import com.microsoft.z3.Z3Exception import hu.bme.mit.theta.common.exception.NotSolvableException +import hu.bme.mit.theta.frontend.UnsupportedFrontendElementException import hu.bme.mit.theta.solver.UnknownSolverStatusException import hu.bme.mit.theta.solver.javasmt.JavaSMTSolverException import hu.bme.mit.theta.solver.smtlib.solver.SmtLibSolverException @@ -32,6 +33,7 @@ enum class ExitCodes(val code: Int) { SERVER_ERROR(202), PORTFOLIO_ERROR(203), + UNSUPPORTED_ELEMENT(209), FRONTEND_FAILED(210), INVALID_PARAM(211), @@ -59,6 +61,9 @@ fun exitOnError(stacktrace: Boolean, throwDontExit: Boolean, body: () -> T): } catch (e: ErrorCodeException) { e.printStackTrace() exitProcess(throwDontExit, e, e.code) + } catch (e: UnsupportedFrontendElementException) { + e.printCauseAndTrace(stacktrace) + exitProcess(throwDontExit, e, ExitCodes.UNSUPPORTED_ELEMENT.code) } catch (e: SmtLibSolverException) { e.printCauseAndTrace(stacktrace) exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code) From 6325e7839f5519b77787f5d0a53f978d0135e809 Mon Sep 17 00:00:00 2001 From: "ThetaBotMaintainer[bot]" <139346997+ThetaBotMaintainer[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2024 09:29:59 +0000 Subject: [PATCH 04/16] Version bump --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index e029ef4eda..20a45bf13f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -28,7 +28,7 @@ buildscript { allprojects { group = "hu.bme.mit.theta" - version = "6.5.2" + version = "6.6.0" apply(from = rootDir.resolve("gradle/shared-with-buildSrc/mirrors.gradle.kts")) } From 1efc717114a0eefd09d5f73a8488e5c942f748ae Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Thu, 17 Oct 2024 12:08:35 +0200 Subject: [PATCH 05/16] Modified set file names --- .github/actions/benchexec-test/theta.xml | 88 ++++++++++++++---------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/.github/actions/benchexec-test/theta.xml b/.github/actions/benchexec-test/theta.xml index 2ce7d4bc50..5960b731de 100644 --- a/.github/actions/benchexec-test/theta.xml +++ b/.github/actions/benchexec-test/theta.xml @@ -1,4 +1,20 @@ + + @@ -11,90 +27,90 @@ - - ../sv-benchmarks/c/ReachSafety-Arrays.set + + ../sv-benchmarks/c/Arrays.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-BitVectors.set + + ../sv-benchmarks/c/BitVectors.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-ControlFlow.set + + ../sv-benchmarks/c/ControlFlow.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-ECA.set + + ../sv-benchmarks/c/ECA.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-Floats.set + + ../sv-benchmarks/c/Floats.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-Heap.set + + ../sv-benchmarks/c/Heap.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-Loops.set + + ../sv-benchmarks/c/Loops.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-ProductLines.set + + ../sv-benchmarks/c/ProductLines.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-Recursive.set + + ../sv-benchmarks/c/Recursive.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-Sequentialized.set + + ../sv-benchmarks/c/Sequentialized.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-XCSP.set + + ../sv-benchmarks/c/XCSP.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-Combinations.set + + ../sv-benchmarks/c/Combinations.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-Hardware.set + + ../sv-benchmarks/c/Hardware.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-Hardness.set + + ../sv-benchmarks/c/Hardness.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ReachSafety-Fuzzle.set + + ../sv-benchmarks/c/Fuzzle.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/ConcurrencySafety-Main.set + + ../sv-benchmarks/c/Concurrency.set ../sv-benchmarks/c/properties/unreach-call.prp - - ../sv-benchmarks/c/NoDataRace-Main.set + + ../sv-benchmarks/c/Concurrency.set ../sv-benchmarks/c/properties/no-data-race.prp - ../sv-benchmarks/c/ConcurrencySafety-NoOverflows.set + ../sv-benchmarks/c/Concurrency.set ../sv-benchmarks/c/properties/no-overflow.prp - ../sv-benchmarks/c/ConcurrencySafety-MemSafety.set + ../sv-benchmarks/c/ConcurrencySafety.set ../sv-benchmarks/c/properties/valid-memsafety.prp From 5f150a6ed2918250c1663d1865d58422cc995bf4 Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Thu, 17 Oct 2024 14:43:49 +0200 Subject: [PATCH 06/16] Moved to timeout-based ending of bencjmarking --- .github/actions/benchexec-test/action.yml | 20 +++++++++---------- .github/workflows/linux-build-test-deploy.yml | 19 +++++++++++++++++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.github/actions/benchexec-test/action.yml b/.github/actions/benchexec-test/action.yml index d0f198ec4c..d71d1be253 100644 --- a/.github/actions/benchexec-test/action.yml +++ b/.github/actions/benchexec-test/action.yml @@ -49,20 +49,20 @@ runs: run: | unzip release/Theta.zip sed -i 's/ --input \$1/ --portfolio ${{ inputs.portfolio }} --input \$1/g' Theta/theta-start.sh - - name: Cut setfile if too long - id: setfile - shell: bash - run: | - cd sv-benchmarks/c - for i in $(sed 's/#.*$//g' ${{ inputs.task }}.set); do find . -wholename ./$i; done | while read line; do grep "${line#./}" $GITHUB_ACTION_PATH/unsupported.txt >/dev/null 2>/dev/null || test -z $(yq e '.properties.[] | select(.property_file == "../properties/unreach-call.prp")' $line) >/dev/null 2>/dev/null || echo $(echo $line | sha1sum | awk ' { print $1 } ') $line ; done | sort -k1 | awk ' { $1=""; print $0 } ' | awk '{$1=$1};1' > all-files.txt - head -n${{ inputs.test_number }} all-files.txt > ${{ inputs.task }}.set - echo "length=$(cat ${{ inputs.task }}.set | wc -l)" >> "$GITHUB_OUTPUT" - cat ${{ inputs.task }}.set +# - name: Cut setfile if too long +# id: setfile +# shell: bash +# run: | +# cd sv-benchmarks/c +# for i in $(sed 's/#.*$//g' ${{ inputs.task }}.set); do find . -wholename ./$i; done | while read line; do grep "${line#./}" $GITHUB_ACTION_PATH/unsupported.txt >/dev/null 2>/dev/null || test -z $(yq e '.properties.[] | select(.property_file == "../properties/unreach-call.prp")' $line) >/dev/null 2>/dev/null || echo $(echo $line | sha1sum | awk ' { print $1 } ') $line ; done | sort -k1 | awk ' { $1=""; print $0 } ' | awk '{$1=$1};1' > all-files.txt +# head -n${{ inputs.test_number }} all-files.txt > ${{ inputs.task }}.set +# echo "length=$(cat ${{ inputs.task }}.set | wc -l)" >> "$GITHUB_OUTPUT" +# cat ${{ inputs.task }}.set - name: Run benchexec shell: bash if: steps.setfile.outputs.length != '0' run: | - benchexec xml/theta.xml -n 2 --no-container --tool-directory Theta -t ${{ inputs.task }} + timeout 300 benchexec xml/theta.xml -n 2 --no-container --tool-directory Theta -t ${{ inputs.task }} - name: Upload results uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 if: steps.setfile.outputs.length != '0' diff --git a/.github/workflows/linux-build-test-deploy.yml b/.github/workflows/linux-build-test-deploy.yml index c670c7f497..80040fd800 100644 --- a/.github/workflows/linux-build-test-deploy.yml +++ b/.github/workflows/linux-build-test-deploy.yml @@ -49,7 +49,24 @@ jobs: test-benchexec: strategy: matrix: - task: [ReachSafety-Arrays, ReachSafety-BitVectors, ReachSafety-ControlFlow, ReachSafety-ECA, ReachSafety-Floats, ReachSafety-Heap, ReachSafety-Loops, ReachSafety-ProductLines, ReachSafety-Recursive, ReachSafety-Sequentialized, ReachSafety-XCSP, ReachSafety-Combinations, ReachSafety-Hardware, ConcurrencySafety-Main, NoDataRace-Main, ConcurrencySafety-NoOverflows, ConcurrencySafety-MemSafety] + task: + - Arrays + - BitVectors + - ControlFlow + - ECA + - Floats + - Heap + - Loops + - ProductLines + - Recursive + - Sequentialized + - XCSP + - Combinations + - Hardware + - Concurrency + - NoDataRace + - ConcurrencySafety-NoOverflows + - ConcurrencySafety-MemSafety portfolio: [CEGAR, BOUNDED, HORN] runs-on: ubuntu-latest needs: create-archives From 8b7f5d4e1a63d01f9d998da09103abbee75ac9ca Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Thu, 17 Oct 2024 15:06:15 +0200 Subject: [PATCH 07/16] Fix bug in action --- .github/actions/benchexec-test/action.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/actions/benchexec-test/action.yml b/.github/actions/benchexec-test/action.yml index d71d1be253..e56e7e8d09 100644 --- a/.github/actions/benchexec-test/action.yml +++ b/.github/actions/benchexec-test/action.yml @@ -60,12 +60,10 @@ runs: # cat ${{ inputs.task }}.set - name: Run benchexec shell: bash - if: steps.setfile.outputs.length != '0' run: | timeout 300 benchexec xml/theta.xml -n 2 --no-container --tool-directory Theta -t ${{ inputs.task }} - name: Upload results uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 - if: steps.setfile.outputs.length != '0' with: name: BenchexecResults-${{ inputs.task }}-${{ inputs.portfolio }} path: results From 295fee2fc9c58eb622ab7f53bf8b4170090f52cf Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Thu, 17 Oct 2024 18:04:57 +0200 Subject: [PATCH 08/16] Timeout produced nonzero exit code; fixed --- .github/actions/benchexec-test/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/benchexec-test/action.yml b/.github/actions/benchexec-test/action.yml index e56e7e8d09..8444c92201 100644 --- a/.github/actions/benchexec-test/action.yml +++ b/.github/actions/benchexec-test/action.yml @@ -61,7 +61,7 @@ runs: - name: Run benchexec shell: bash run: | - timeout 300 benchexec xml/theta.xml -n 2 --no-container --tool-directory Theta -t ${{ inputs.task }} + timeout 300 benchexec xml/theta.xml -n 2 --no-container --tool-directory Theta -t ${{ inputs.task }} || true - name: Upload results uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: From 7ff2cc6505060ce1643d8f4686ab04765bd71f84 Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Fri, 18 Oct 2024 11:32:04 +0200 Subject: [PATCH 09/16] removed comment from xml --- .github/actions/benchexec-test/theta.xml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.github/actions/benchexec-test/theta.xml b/.github/actions/benchexec-test/theta.xml index 5960b731de..e2a7455cee 100644 --- a/.github/actions/benchexec-test/theta.xml +++ b/.github/actions/benchexec-test/theta.xml @@ -1,20 +1,4 @@ - - From b0ca2940f46d96938fbbfc7f141f244d47969b57 Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Fri, 18 Oct 2024 15:23:24 +0200 Subject: [PATCH 10/16] Moved conditional expressions to function visitor --- .../frontends/c-frontend/src/main/antlr/C.g4 | 2 +- .../grammar/expression/ExpressionVisitor.java | 71 ++++----- .../grammar/function/FunctionVisitor.java | 136 +++++++++++++----- 3 files changed, 142 insertions(+), 67 deletions(-) diff --git a/subprojects/frontends/c-frontend/src/main/antlr/C.g4 b/subprojects/frontends/c-frontend/src/main/antlr/C.g4 index af6b7ccd1c..386d294c42 100644 --- a/subprojects/frontends/c-frontend/src/main/antlr/C.g4 +++ b/subprojects/frontends/c-frontend/src/main/antlr/C.g4 @@ -173,7 +173,7 @@ logicalOrExpression ; conditionalExpression - : logicalOrExpression ('?' expression ':' conditionalExpression)? + : logicalOrExpression ('?' ifTrue=expression ':' ifFalse=expression)? ; assignmentExpression diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java index d714b8693a..18f2ee1123 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java @@ -44,7 +44,10 @@ import hu.bme.mit.theta.frontend.transformation.grammar.preprocess.TypedefVisitor; import hu.bme.mit.theta.frontend.transformation.grammar.type.TypeVisitor; import hu.bme.mit.theta.frontend.transformation.model.declaration.CDeclaration; -import hu.bme.mit.theta.frontend.transformation.model.statements.*; +import hu.bme.mit.theta.frontend.transformation.model.statements.CAssignment; +import hu.bme.mit.theta.frontend.transformation.model.statements.CCall; +import hu.bme.mit.theta.frontend.transformation.model.statements.CExpr; +import hu.bme.mit.theta.frontend.transformation.model.statements.CStatement; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CArray; import hu.bme.mit.theta.frontend.transformation.model.types.complex.compound.CPointer; @@ -110,37 +113,41 @@ public List getPreStatements() { return preStatements; } - @Override - public Expr visitConditionalExpression(CParser.ConditionalExpressionContext ctx) { - if (ctx.expression() != null) { - CStatement ifTrue = ctx.expression().accept(functionVisitor); - addPreStatements(ifTrue); - if (ifTrue instanceof CAssignment) { - preStatements.add(ifTrue); - } - Expr expr = ctx.logicalOrExpression().accept(this); - Expr lhs = ifTrue.getExpression(); - Expr rhs = ctx.conditionalExpression().accept(this); - CComplexType smallestCommonType = CComplexType.getSmallestCommonType(List.of(CComplexType.getType(lhs, parseContext), CComplexType.getType(rhs, parseContext)), parseContext); - IteExpr ite = Ite( - AbstractExprs.Neq(CComplexType.getType(expr, parseContext).getNullValue(), expr), - smallestCommonType.castTo(lhs), - smallestCommonType.castTo(rhs) - ); - parseContext.getMetadata().create(ite, "cType", smallestCommonType); - return ite; - } else return ctx.logicalOrExpression().accept(this); - } - - private void addPreStatements(CStatement ifTrue) { - if (ifTrue instanceof CCompound) { - if (ifTrue.getPreStatements() != null) preStatements.add(ifTrue.getPreStatements()); - if (ifTrue.getPostStatements() != null) postStatements.add(ifTrue.getPostStatements()); - for (CStatement cStatement : ((CCompound) ifTrue).getcStatementList()) { - addPreStatements(cStatement); - } - } - } +// @Override +// public Expr visitConditionalExpression(CParser.ConditionalExpressionContext ctx) { +// if (ctx.expression() != null) { +// CStatement cond = ctx.logicalOrExpression().accept(functionVisitor); +// CStatement ifTrue = ctx.expression().accept(functionVisitor); +// CStatement ifFalse = ctx.conditionalExpression().accept(functionVisitor); +// +// Expr expr = ctx.logicalOrExpression().accept(this); +// Expr lhs = ifTrue.getExpression(); +// Expr rhs = ctx.conditionalExpression().accept(this); +// +// preStatements.add(new CIf(cond, ifTrue, ifFalse, parseContext)); +// +// CComplexType smallestCommonType = CComplexType.getSmallestCommonType(List.of(CComplexType.getType(lhs, parseContext), CComplexType.getType(rhs, parseContext)), parseContext); +// IteExpr ite = Ite( +// AbstractExprs.Neq(CComplexType.getType(expr, parseContext).getNullValue(), expr), +// smallestCommonType.castTo(lhs), +// smallestCommonType.castTo(rhs) +// ); +// parseContext.getMetadata().create(ite, "cType", smallestCommonType); +// return ite; +// } else return ctx.logicalOrExpression().accept(this); +// } + +// private void addPrePostStatementsForConditional(CStatement statement) { +// if (statement instanceof CCompound) { +// if (statement.getPreStatements() != null) preStatements.add(statement.getPreStatements()); +// if (statement.getPostStatements() != null) postStatements.add(statement.getPostStatements()); +// for (CStatement cStatement : ((CCompound) statement).getcStatementList()) { +// addPrePostStatementsForConditional(cStatement); +// } +// } else { +// preStatements.add(statement); +// } +// } @Override public Expr visitLogicalOrExpression(CParser.LogicalOrExpressionContext ctx) { diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java index eb98d8d707..61906b9eb2 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java @@ -26,7 +26,9 @@ import hu.bme.mit.theta.core.stmt.AssumeStmt; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; +import hu.bme.mit.theta.core.type.abstracttype.AbstractExprs; import hu.bme.mit.theta.core.type.anytype.Exprs; +import hu.bme.mit.theta.core.type.anytype.IteExpr; import hu.bme.mit.theta.core.type.arraytype.ArrayType; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.frontend.ParseContext; @@ -40,26 +42,7 @@ import hu.bme.mit.theta.frontend.transformation.grammar.type.DeclarationVisitor; import hu.bme.mit.theta.frontend.transformation.grammar.type.TypeVisitor; import hu.bme.mit.theta.frontend.transformation.model.declaration.CDeclaration; -import hu.bme.mit.theta.frontend.transformation.model.statements.CAssignment; -import hu.bme.mit.theta.frontend.transformation.model.statements.CAssume; -import hu.bme.mit.theta.frontend.transformation.model.statements.CBreak; -import hu.bme.mit.theta.frontend.transformation.model.statements.CCase; -import hu.bme.mit.theta.frontend.transformation.model.statements.CCompound; -import hu.bme.mit.theta.frontend.transformation.model.statements.CContinue; -import hu.bme.mit.theta.frontend.transformation.model.statements.CDecls; -import hu.bme.mit.theta.frontend.transformation.model.statements.CDefault; -import hu.bme.mit.theta.frontend.transformation.model.statements.CDoWhile; -import hu.bme.mit.theta.frontend.transformation.model.statements.CExpr; -import hu.bme.mit.theta.frontend.transformation.model.statements.CFor; -import hu.bme.mit.theta.frontend.transformation.model.statements.CFunction; -import hu.bme.mit.theta.frontend.transformation.model.statements.CGoto; -import hu.bme.mit.theta.frontend.transformation.model.statements.CIf; -import hu.bme.mit.theta.frontend.transformation.model.statements.CInitializerList; -import hu.bme.mit.theta.frontend.transformation.model.statements.CProgram; -import hu.bme.mit.theta.frontend.transformation.model.statements.CRet; -import hu.bme.mit.theta.frontend.transformation.model.statements.CStatement; -import hu.bme.mit.theta.frontend.transformation.model.statements.CSwitch; -import hu.bme.mit.theta.frontend.transformation.model.statements.CWhile; +import hu.bme.mit.theta.frontend.transformation.model.statements.*; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CVoid; import hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleType; @@ -67,20 +50,13 @@ import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.Token; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.StringJoiner; +import java.util.*; +import java.util.stream.Stream; import static com.google.common.base.Preconditions.checkState; import static hu.bme.mit.theta.core.decl.Decls.Var; import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Add; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Ite; import static hu.bme.mit.theta.core.utils.TypeUtils.cast; import static hu.bme.mit.theta.grammar.UtilsKt.textWithWS; @@ -541,18 +517,110 @@ public CStatement visitAssignmentExpressionAssignmentExpression(CParser.Assignme @Override public CStatement visitAssignmentExpressionConditionalExpression(CParser.AssignmentExpressionConditionalExpressionContext ctx) { - ExpressionVisitor expressionVisitor = new ExpressionVisitor(parseContext, this, variables, functions, typedefVisitor, typeVisitor, uniqueWarningLogger); + return ctx.conditionalExpression().accept(this); + } + + /* + This collects the following: + - the current compound's pre-statement + - all pre-statements of the pre-statement (before the pre-statement) + - all the pre-statement of every cStatement + */ + private List collectPreStatements(CStatement cStatement) { + if (cStatement instanceof CCompound) { + return Stream.concat( + Stream.concat( + collectPreStatements(cStatement.getPreStatements()).stream(), + Stream.of(cStatement.getPreStatements())), + ((CCompound) cStatement).getcStatementList().stream().flatMap(cStatement1 -> collectPreStatements(cStatement1).stream()) + ).toList(); + } else return List.of(); + } + + /* + This collects the following: + - all the post-statements of every cStatement + - the current compound's post-statement + - all post-statements of the post-statement (after the post-statement) + */ + private List collectPostStatements(CStatement cStatement) { + if (cStatement instanceof CCompound) { + return Stream.concat( + ((CCompound) cStatement).getcStatementList().stream().flatMap(cStatement1 -> collectPostStatements(cStatement1).stream()), + Stream.concat( + Stream.of(cStatement.getPreStatements()), + collectPostStatements(cStatement.getPreStatements()).stream()) + ).toList(); + } else return List.of(); + } + + // This is in the function visitor, not in the expression visitor, because + // cond ? f1() : f2() + // will only call either f1 or f2 (it can be used for branching) + @Override + public CStatement visitConditionalExpression(CParser.ConditionalExpressionContext ctx) { CCompound compound = new CCompound(parseContext); CCompound preStatements = new CCompound(parseContext); CCompound postStatements = new CCompound(parseContext); - Expr ret = ctx.conditionalExpression().accept(expressionVisitor); - CExpr cexpr = new CExpr(ret, parseContext); + + ExpressionVisitor expressionVisitor = new ExpressionVisitor(parseContext, this, variables, functions, typedefVisitor, typeVisitor, uniqueWarningLogger); + + Expr iteExpr; + if (!ctx.expression().isEmpty()) { + CStatement ifTrue = ctx.ifTrue.accept(this); + CStatement ifFalse = ctx.ifFalse.accept(this); + + Expr expr = ctx.logicalOrExpression().accept(expressionVisitor); + Expr lhs = ifTrue.getExpression(); + Expr rhs = ifFalse.getExpression(); + + CCompound guardCompound = new CCompound(parseContext); + guardCompound.getcStatementList().add(new CExpr(expr, parseContext)); + guardCompound.setPostStatements(new CCompound(parseContext)); + guardCompound.setPreStatements(new CCompound(parseContext)); + + + CCompound ifTruePre = new CCompound(parseContext); + ifTruePre.getcStatementList().addAll(collectPreStatements(ifTrue)); + ifTruePre.setPostStatements(new CCompound(parseContext)); + ifTruePre.setPreStatements(new CCompound(parseContext)); + CCompound ifFalsePre = new CCompound(parseContext); + ifFalsePre.getcStatementList().addAll(collectPreStatements(ifFalse)); + ifFalsePre.setPostStatements(new CCompound(parseContext)); + ifFalsePre.setPreStatements(new CCompound(parseContext)); + + CCompound ifTruePost = new CCompound(parseContext); + ifTruePost.getcStatementList().addAll(collectPostStatements(ifTrue)); + ifTruePost.setPostStatements(new CCompound(parseContext)); + ifTruePost.setPreStatements(new CCompound(parseContext)); + CCompound ifFalsePost = new CCompound(parseContext); + ifFalsePost.getcStatementList().addAll(collectPostStatements(ifFalse)); + ifFalsePost.setPostStatements(new CCompound(parseContext)); + ifFalsePost.setPreStatements(new CCompound(parseContext)); + + + preStatements.getcStatementList().add(new CIf(guardCompound, ifTruePre, ifFalsePre, parseContext)); + postStatements.getcStatementList().add(new CIf(guardCompound, ifTruePost, ifFalsePost, parseContext)); + + CComplexType smallestCommonType = CComplexType.getSmallestCommonType(List.of(CComplexType.getType(lhs, parseContext), CComplexType.getType(rhs, parseContext)), parseContext); + IteExpr ite = Ite( + AbstractExprs.Neq(CComplexType.getType(expr, parseContext).getNullValue(), expr), + smallestCommonType.castTo(lhs), + smallestCommonType.castTo(rhs) + ); + parseContext.getMetadata().create(ite, "cType", smallestCommonType); + iteExpr = ite; + } else { + iteExpr = ctx.logicalOrExpression().accept(expressionVisitor); + } + + CExpr cexpr = new CExpr(iteExpr, parseContext); compound.getcStatementList().add(cexpr); preStatements.getcStatementList().addAll(expressionVisitor.getPreStatements()); compound.setPreStatements(preStatements); recordMetadata(ctx, compound); - postStatements.getcStatementList().addAll(expressionVisitor.getPostStatements()); compound.setPostStatements(postStatements); + postStatements.getcStatementList().addAll(expressionVisitor.getPostStatements()); recordMetadata(ctx, compound); return compound; } From e3e4e16cf84c89f1f1c88fb7398f7543879b6707 Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Fri, 18 Oct 2024 16:30:03 +0200 Subject: [PATCH 11/16] Initializer lists now somewhat work --- .../grammar/function/FunctionVisitor.java | 15 ++++++++++----- .../bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java index 61906b9eb2..427034fb2c 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java @@ -432,14 +432,19 @@ public CStatement visitBodyDeclaration(CParser.BodyDeclarationContext ctx) { createVars(declaration); if (declaration.getType() instanceof Struct) { checkState(declaration.getInitExpr() instanceof CInitializerList, "Struct can only be initialized via an initializer list!"); + final var initializerList = (CInitializerList) declaration.getInitExpr(); List> varDecls = declaration.getVarDecls(); - for (int i = 0; i < varDecls.size(); i++) { - VarDecl varDecl = varDecls.get(i); - Tuple2, CStatement> initializer = ((CInitializerList) declaration.getInitExpr()).getStatements().get(i); - - CAssignment cAssignment = new CAssignment(varDecl.getRef(), initializer.get2(), "=", parseContext); + VarDecl varDecl = varDecls.get(0); + final var ptrType = CComplexType.getUnsignedLong(parseContext); + LitExpr currentValue = ptrType.getNullValue(); + LitExpr unitValue = ptrType.getUnitValue(); + for (Tuple2, CStatement> statement : initializerList.getStatements()) { + final var expr = statement.get2().getExpression(); + final var deref = Exprs.Dereference(cast(varDecl.getRef(), currentValue.getType()), cast(currentValue, currentValue.getType()), expr.getType()); + CAssignment cAssignment = new CAssignment(deref, statement.get2(), "=", parseContext); recordMetadata(ctx, cAssignment); compound.getcStatementList().add(cAssignment); + currentValue = Add(currentValue, unitValue).eval(ImmutableValuation.empty()); } } else { checkState(declaration.getVarDecls().size() == 1, "non-struct declarations shall only have one variable!"); diff --git a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt index 7bd0113897..d82a92fa4a 100644 --- a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt +++ b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt @@ -192,7 +192,7 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo for (flatVariable in flatVariables) { builder.addVar(flatVariable) val type = CComplexType.getType(flatVariable.ref, parseContext) - if (type is CArray && builder.getParams().none { it.first == flatVariable }) { + if ((type is CArray || type is CStruct) && builder.getParams().none { it.first == flatVariable }) { initStmtList.add(StmtLabel( Stmts.Assign(cast(flatVariable, flatVariable.type), cast(type.getValue("$ptrCnt"), flatVariable.type)) From 6591e8ba5d8304ce6cf13c4d4bd612023d950223 Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Fri, 18 Oct 2024 19:36:13 +0200 Subject: [PATCH 12/16] Removed commented out code --- .../grammar/expression/ExpressionVisitor.java | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java index 18f2ee1123..609518ea3e 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/expression/ExpressionVisitor.java @@ -113,42 +113,6 @@ public List getPreStatements() { return preStatements; } -// @Override -// public Expr visitConditionalExpression(CParser.ConditionalExpressionContext ctx) { -// if (ctx.expression() != null) { -// CStatement cond = ctx.logicalOrExpression().accept(functionVisitor); -// CStatement ifTrue = ctx.expression().accept(functionVisitor); -// CStatement ifFalse = ctx.conditionalExpression().accept(functionVisitor); -// -// Expr expr = ctx.logicalOrExpression().accept(this); -// Expr lhs = ifTrue.getExpression(); -// Expr rhs = ctx.conditionalExpression().accept(this); -// -// preStatements.add(new CIf(cond, ifTrue, ifFalse, parseContext)); -// -// CComplexType smallestCommonType = CComplexType.getSmallestCommonType(List.of(CComplexType.getType(lhs, parseContext), CComplexType.getType(rhs, parseContext)), parseContext); -// IteExpr ite = Ite( -// AbstractExprs.Neq(CComplexType.getType(expr, parseContext).getNullValue(), expr), -// smallestCommonType.castTo(lhs), -// smallestCommonType.castTo(rhs) -// ); -// parseContext.getMetadata().create(ite, "cType", smallestCommonType); -// return ite; -// } else return ctx.logicalOrExpression().accept(this); -// } - -// private void addPrePostStatementsForConditional(CStatement statement) { -// if (statement instanceof CCompound) { -// if (statement.getPreStatements() != null) preStatements.add(statement.getPreStatements()); -// if (statement.getPostStatements() != null) postStatements.add(statement.getPostStatements()); -// for (CStatement cStatement : ((CCompound) statement).getcStatementList()) { -// addPrePostStatementsForConditional(cStatement); -// } -// } else { -// preStatements.add(statement); -// } -// } - @Override public Expr visitLogicalOrExpression(CParser.LogicalOrExpressionContext ctx) { if (ctx.logicalAndExpression().size() > 1) { From 185dc7ad29920254fc689ac68ff01952a1c65c5a Mon Sep 17 00:00:00 2001 From: "ThetaBotMaintainer[bot]" <139346997+ThetaBotMaintainer[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:12:37 +0000 Subject: [PATCH 13/16] Reformatted code --- buildSrc/build.gradle.kts | 3 +- .../src/main/kotlin/maven-artifact.gradle.kts | 9 +- scripts/complex.kts | 324 ++++++--- scripts/simple.kts | 6 +- .../theta/cfa/analysis/CfaToMonolithicExpr.kt | 12 +- .../bounded/BoundedCheckerBuilder.kt | 12 +- .../analysis/algorithm/chc/HornChecker.kt | 3 +- .../analysis/algorithm/mcm/MemoryEvent.kt | 12 +- .../algorithm/mcm/analysis/PartialSolver.kt | 3 +- .../mit/theta/analysis/ptr/ItpRefToPtrPrec.kt | 6 +- .../bme/mit/theta/analysis/ptr/PtrAction.kt | 23 +- .../bme/mit/theta/analysis/ptr/PtrAnalysis.kt | 15 +- .../hu/bme/mit/theta/analysis/ptr/PtrUtils.kt | 37 +- .../analysis/runtimemonitor/CexMonitor.kt | 9 +- .../runtimemonitor/MonitorCheckpoint.kt | 3 +- .../mit/theta/analysis/multi/MultiInitFunc.kt | 2 +- .../theta/analysis/multi/MultiPartialOrd.kt | 2 +- .../theta/analysis/multi/MultiTransFunc.kt | 2 +- .../multi/builder/MultiBuilderResult.kt | 2 +- .../multi/builder/MultiControlInitFunc.kt | 2 +- .../theta/analysis/algorithm/BoundedTest.kt | 9 +- .../mit/theta/analysis/ptr/PtrAnalysisTest.kt | 37 +- .../java/hu/bme/mit/theta/core/ChcUtils.kt | 6 +- .../hu/bme/mit/theta/grammar/dsl/Utils.kt | 6 +- .../mit/theta/grammar/dsl/expr/ExprParser.kt | 210 ++++-- .../mit/theta/grammar/dsl/stmt/StmtParser.kt | 3 +- .../bme/mit/theta/grammar/gson/ArgAdapter.kt | 6 +- .../theta/grammar/gson/ArgAdapterHelper.kt | 9 +- .../theta/grammar/gson/SafetyResultAdapter.kt | 12 +- .../mit/theta/grammar/gson/StateAdapters.kt | 3 +- .../mit/theta/grammar/gson/TraceAdapter.kt | 18 +- .../mit/theta/grammar/gson/VarDeclAdapter.kt | 6 +- .../hu/bme/mit/theta/grammar/dsl/ExprTest.kt | 283 +++++--- .../hu/bme/mit/theta/grammar/dsl/StmtTest.kt | 18 +- .../hu/bme/mit/theta/grammar/dsl/TypeTest.kt | 6 +- .../hu/bme/mit/theta/grammar/gson/TestGson.kt | 36 +- .../MultiNondetDiningPhilosophersTest.kt | 30 +- .../hu/bme/mit/theta/frontend/CStatistics.kt | 6 +- subprojects/frontends/llvm/build.gradle.kts | 30 +- .../compilers/DefaultGraphPatternCompiler.kt | 6 +- .../compilers/GraphPatternCompiler.kt | 6 +- .../pattern2expr/Pattern2ExprCompiler.kt | 24 +- .../mit/theta/graphsolver/GraphSolverTest.kt | 162 +++-- .../smtlib/GenericSmtLibHornSolverTest.kt | 7 +- .../mit/theta/solver/z3/Z3HornSolverTest.kt | 7 +- .../mit/theta/c2xcfa/FrontendXcfaBuilder.kt | 488 +++++++++----- .../java/hu/bme/mit/theta/c2xcfa/Utils.kt | 6 +- .../hu/bme/mit/theta/cat/dsl/CatVisitor.kt | 3 +- subprojects/xcfa/llvm2xcfa/build.gradle.kts | 6 +- .../hu/bme/mit/theta/xcfa/analysis/Utils.kt | 3 +- .../mit/theta/xcfa/analysis/XcfaAbstractor.kt | 7 +- .../bme/mit/theta/xcfa/analysis/XcfaAction.kt | 12 +- .../mit/theta/xcfa/analysis/XcfaAnalysis.kt | 148 +++-- .../theta/xcfa/analysis/XcfaPrecRefiner.kt | 15 +- .../analysis/XcfaSingeExprTraceRefiner.kt | 13 +- .../bme/mit/theta/xcfa/analysis/XcfaState.kt | 125 ++-- .../theta/xcfa/analysis/XcfaStateAdapter.kt | 6 +- .../xcfa/analysis/XcfaToMonolithicExpr.kt | 36 +- .../xcfa/analysis/coi/XcfaCoiMultiThread.kt | 6 +- .../theta/xcfa/analysis/oc/XcfaOcChecker.kt | 6 +- .../xcfa/analysis/oc/XcfaOcTraceExtractor.kt | 24 +- .../theta/xcfa/analysis/por/XcfaDporLts.kt | 7 +- .../xcfa/analysis/XcfaExplAnalysisTest.kt | 97 ++- .../xcfa/analysis/XcfaPredAnalysisTest.kt | 100 ++- .../theta/xcfa/analysis/XcfaStateLtsTest.kt | 3 +- .../bme/mit/theta/xcfa/cli/ExecuteConfig.kt | 23 +- .../cli/checkers/ConfigToBoundedChecker.kt | 24 +- .../xcfa/cli/checkers/ConfigToCegarChecker.kt | 45 +- .../xcfa/cli/checkers/ConfigToChecker.kt | 6 +- .../xcfa/cli/checkers/ConfigToOcChecker.kt | 12 +- .../xcfa/cli/checkers/ConfigToPortfolio.kt | 71 +- .../xcfa/cli/checkers/InProcessChecker.kt | 31 +- .../mit/theta/xcfa/cli/params/ParamValues.kt | 45 +- .../mit/theta/xcfa/cli/params/XcfaConfig.kt | 108 ++- .../mit/theta/xcfa/cli/portfolio/bounded.kt | 98 ++- .../mit/theta/xcfa/cli/portfolio/complex23.kt | 507 +++++++++----- .../mit/theta/xcfa/cli/portfolio/complex24.kt | 616 ++++++++++++------ .../bme/mit/theta/xcfa/cli/portfolio/horn.kt | 44 +- .../bme/mit/theta/xcfa/cli/portfolio/stm.kt | 29 +- .../bme/mit/theta/xcfa/cli/utils/GsonUtils.kt | 45 +- .../mit/theta/xcfa/cli/utils/PropertyUtils.kt | 6 +- .../mit/theta/xcfa/cli/utils/XcfaParser.kt | 79 ++- .../theta/xcfa/cli/utils/XcfaWitnessWriter.kt | 93 ++- .../xcfa/cli/witnesses/TraceToWitness.kt | 39 +- .../mit/theta/xcfa/cli/witnesses/Witness.kt | 17 +- .../mit/theta/xcfa/cli/XcfaCliParseTest.kt | 136 ++-- .../theta/xcfa/cli/XcfaCliPortfolioTest.kt | 22 +- .../mit/theta/xcfa/cli/XcfaCliVerifyTest.kt | 24 +- .../mit/theta/xcfa/cli/XcfaCliWitnessTest.kt | 40 +- .../hu/bme/mit/theta/xcfa/cli/XcfaDslTest.kt | 15 +- .../hu/bme/mit/theta/xcfa/cli/XcfaToCTest.kt | 12 +- .../xcfa-cli/src/test/resources/simple.kts | 16 +- .../main/java/hu/bme/mit/theta/xcfa/Utils.kt | 36 +- .../java/hu/bme/mit/theta/xcfa/XcfaToC.kt | 6 +- .../hu/bme/mit/theta/xcfa/gson/XcfaAdapter.kt | 9 +- .../mit/theta/xcfa/gson/XcfaLabelAdapter.kt | 9 +- .../java/hu/bme/mit/theta/xcfa/model/Dsl.kt | 49 +- .../hu/bme/mit/theta/xcfa/model/Visualizer.kt | 3 +- .../hu/bme/mit/theta/xcfa/model/XcfaLabel.kt | 33 +- .../xcfa/passes/AssumeFalseRemovalPass.kt | 3 +- .../xcfa/passes/AtomicReadsOneWritePass.kt | 9 +- .../xcfa/passes/CLibraryFunctionsPass.kt | 16 +- .../theta/xcfa/passes/ErrorLocationPass.kt | 7 +- .../xcfa/passes/FetchExecuteWriteback.kt | 44 +- .../theta/xcfa/passes/FinalLocationPass.kt | 18 +- .../xcfa/passes/FpFunctionsToExprsPass.kt | 286 +++++--- .../xcfa/passes/HavocPromotionAndRange.kt | 15 +- .../theta/xcfa/passes/InlineProceduresPass.kt | 40 +- .../hu/bme/mit/theta/xcfa/passes/LbePass.kt | 18 +- .../theta/xcfa/passes/MallocFunctionPass.kt | 42 +- .../mit/theta/xcfa/passes/NoSideEffectPass.kt | 4 +- .../theta/xcfa/passes/NondetFunctionPass.kt | 16 +- .../mit/theta/xcfa/passes/NormalizePass.kt | 4 +- .../theta/xcfa/passes/ProcedurePassManager.kt | 44 +- .../theta/xcfa/passes/ReferenceElimination.kt | 104 ++- .../theta/xcfa/passes/SvCompIntrinsicsPass.kt | 19 +- .../mit/theta/xcfa/passes/UnusedVarPass.kt | 3 +- .../hu/bme/mit/theta/xcfa/passes/Utils.kt | 66 +- .../hu/bme/mit/theta/xcfa/gson/GsonTest.kt | 18 +- .../hu/bme/mit/theta/xcfa/passes/PassTests.kt | 31 +- .../hu/bme/mit/theta/xcfa/passes/UtilsTest.kt | 36 +- .../hu/bme/mit/theta/xcfa2chc/TestChcUtils.kt | 112 ++-- .../theta/xsts/analysis/XstsToRelations.kt | 3 +- .../theta/xsts/analysis/util/RandomXsts.kt | 54 +- .../xsts/analysis/util/XstsSerializer.kt | 3 +- .../mit/theta/xsts/utils/XSTSVarChanger.kt | 6 +- 126 files changed, 3926 insertions(+), 1987 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 093b423f12..5b1c79903a 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -44,7 +44,8 @@ dependencies { // https://github.com/gradle/kotlin-dsl/issues/1207 configurations.all { val isKotlinCompiler = name == "embeddedKotlin" || name.startsWith("kotlin") || name.startsWith( - "kapt") + "kapt" + ) if (!isKotlinCompiler) { resolutionStrategy.eachDependency { if (requested.group == "org.jetbrains.kotlin" && requested.module.name == "kotlin-compiler-embeddable") { diff --git a/buildSrc/src/main/kotlin/maven-artifact.gradle.kts b/buildSrc/src/main/kotlin/maven-artifact.gradle.kts index 95ddb2d588..acb489be5d 100644 --- a/buildSrc/src/main/kotlin/maven-artifact.gradle.kts +++ b/buildSrc/src/main/kotlin/maven-artifact.gradle.kts @@ -107,11 +107,14 @@ tasks { repositories { maven { val releasesRepoUrl = uri( - "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") + "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + ) val snapshotsRepoUrl = uri( - "https://s01.oss.sonatype.org/content/repositories/snapshots/") + "https://s01.oss.sonatype.org/content/repositories/snapshots/" + ) url = if (version.toString() - .endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl + .endsWith("SNAPSHOT") + ) snapshotsRepoUrl else releasesRepoUrl credentials { username = System.getenv("OSSRH_USERNAME") password = System.getenv("OSSRH_PASSWORD") diff --git a/scripts/complex.kts b/scripts/complex.kts index b90d3907cc..98e5e6d073 100644 --- a/scripts/complex.kts +++ b/scripts/complex.kts @@ -89,38 +89,60 @@ val predConfig = baseConfig.copy(domain = Domain.PRED_CART, refinement = Refinem fun integerStm(): STM { fun getStm(inProcess: Boolean): STM { - val config_1_1 = ConfigNode("QuickFullExpl_z3_4.10.1_$inProcess", - quickExplConfig.copy(abstractionSolver = "z3:4.10.1", refinementSolver = "z3:4.10.1", - refinement = Refinement.NWT_IT_WP), checker, inProcess) - val config_2_1 = ConfigNode("EmptyExpl_z3_4.10.1_$inProcess", - emptyExplConfig.copy(abstractionSolver = "z3:4.10.1", refinementSolver = "z3:4.10.1", - refinement = Refinement.NWT_IT_WP), checker, inProcess) - val config_3_1 = ConfigNode("PredCart_z3_4.10.1_$inProcess", - predConfig.copy(abstractionSolver = "z3:4.10.1", refinementSolver = "z3:4.10.1"), checker, inProcess) + val config_1_1 = ConfigNode( + "QuickFullExpl_z3_4.10.1_$inProcess", + quickExplConfig.copy( + abstractionSolver = "z3:4.10.1", refinementSolver = "z3:4.10.1", + refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) + val config_2_1 = ConfigNode( + "EmptyExpl_z3_4.10.1_$inProcess", + emptyExplConfig.copy( + abstractionSolver = "z3:4.10.1", refinementSolver = "z3:4.10.1", + refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) + val config_3_1 = ConfigNode( + "PredCart_z3_4.10.1_$inProcess", + predConfig.copy(abstractionSolver = "z3:4.10.1", refinementSolver = "z3:4.10.1"), checker, inProcess + ) val config_1_2 = ConfigNode("QuickFullExpl_Z3_$inProcess", quickExplConfig.copy(), checker, inProcess) val config_2_2 = ConfigNode("EmptyExpl_Z3_$inProcess", emptyExplConfig.copy(), checker, inProcess) val config_3_2 = ConfigNode("PredCart_Z3_$inProcess", predConfig.copy(), checker, inProcess) - val config_1_3 = ConfigNode("QuickFullExpl_princess_2022_07_01_$inProcess", + val config_1_3 = ConfigNode( + "QuickFullExpl_princess_2022_07_01_$inProcess", quickExplConfig.copy(abstractionSolver = "princess:2022-07-01", refinementSolver = "princess:2022-07-01"), - checker, inProcess) - val config_2_3 = ConfigNode("EmptyExpl_princess_2022_07_01_$inProcess", + checker, inProcess + ) + val config_2_3 = ConfigNode( + "EmptyExpl_princess_2022_07_01_$inProcess", emptyExplConfig.copy(abstractionSolver = "princess:2022-07-01", refinementSolver = "princess:2022-07-01"), - checker, inProcess) - val config_3_3 = ConfigNode("PredCart_mathsat_5.6.8_$inProcess", + checker, inProcess + ) + val config_3_3 = ConfigNode( + "PredCart_mathsat_5.6.8_$inProcess", predConfig.copy(abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8"), checker, - inProcess) + inProcess + ) - val config_1_4 = ConfigNode("QuickFullExpl_mathsat_5.6.8_$inProcess", + val config_1_4 = ConfigNode( + "QuickFullExpl_mathsat_5.6.8_$inProcess", quickExplConfig.copy(abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8"), checker, - inProcess) - val config_2_4 = ConfigNode("EmptyExpl_mathsat_5.6.8_$inProcess", + inProcess + ) + val config_2_4 = ConfigNode( + "EmptyExpl_mathsat_5.6.8_$inProcess", emptyExplConfig.copy(abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8"), checker, - inProcess) - val config_3_4 = ConfigNode("PredCart_princess_2022_07_01_$inProcess", + inProcess + ) + val config_3_4 = ConfigNode( + "PredCart_princess_2022_07_01_$inProcess", predConfig.copy(abstractionSolver = "princess:2022-07-01", refinementSolver = "princess:2022-07-01"), - checker, inProcess) + checker, inProcess + ) val timeouts = setOf( Edge(config_1_1, config_2_1, timeoutTrigger), @@ -136,9 +158,13 @@ fun integerStm(): STM { Edge(config_2_4, config_3_1, if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything")), ) - val notTimeout = if (inProcess) ExceptionTrigger(ErrorCodeException(ExitCodes.SOLVER_ERROR.code), - label = "SolverError") else ExceptionTrigger(fallthroughExceptions = timeoutTrigger.exceptions, - label = "AnythingButTimeout") + val notTimeout = if (inProcess) ExceptionTrigger( + ErrorCodeException(ExitCodes.SOLVER_ERROR.code), + label = "SolverError" + ) else ExceptionTrigger( + fallthroughExceptions = timeoutTrigger.exceptions, + label = "AnythingButTimeout" + ) val solverExceptions = setOf( Edge(config_1_1, config_1_2, notTimeout), @@ -166,32 +192,60 @@ fun integerStm(): STM { fun bitwiseStm(): STM { fun getStm(inProcess: Boolean): STM { - val config_1_1 = ConfigNode("QuickFullExpl_Z3_$inProcess", - quickExplConfig.copy(refinement = Refinement.NWT_IT_WP), checker, inProcess) - val config_2_1 = ConfigNode("EmptyExpl_Z3_$inProcess", emptyExplConfig.copy(refinement = Refinement.NWT_IT_WP), - checker, inProcess) - val config_3_1 = ConfigNode("PredCart_mathsat_5.6.8_$inProcess", + val config_1_1 = ConfigNode( + "QuickFullExpl_Z3_$inProcess", + quickExplConfig.copy(refinement = Refinement.NWT_IT_WP), checker, inProcess + ) + val config_2_1 = ConfigNode( + "EmptyExpl_Z3_$inProcess", emptyExplConfig.copy(refinement = Refinement.NWT_IT_WP), + checker, inProcess + ) + val config_3_1 = ConfigNode( + "PredCart_mathsat_5.6.8_$inProcess", predConfig.copy(abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8"), checker, - inProcess) - - val config_1_2 = ConfigNode("QuickFullExpl_cvc5_1.0.2_$inProcess", - quickExplConfig.copy(abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker, inProcess) - val config_2_2 = ConfigNode("EmptyExpl_cvc5_1.0.2_$inProcess", - emptyExplConfig.copy(abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker, inProcess) - val config_3_2 = ConfigNode("PredCart_z3_4.10.1_$inProcess", - predConfig.copy(abstractionSolver = "z3:4.10.1", refinementSolver = "z3:4.10.1"), checker, inProcess) - - val config_1_3 = ConfigNode("QuickFullExpl_mathsat_5.6.8_$inProcess", - quickExplConfig.copy(abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", - refinement = Refinement.NWT_IT_WP), checker, inProcess) - val config_2_3 = ConfigNode("EmptyExpl_mathsat_5.6.8_$inProcess", - emptyExplConfig.copy(abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", - refinement = Refinement.SEQ_ITP), checker, inProcess) - val config_3_3 = ConfigNode("PredCart_cvc5_1.0.2_$inProcess", - predConfig.copy(abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker, inProcess) + inProcess + ) + + val config_1_2 = ConfigNode( + "QuickFullExpl_cvc5_1.0.2_$inProcess", + quickExplConfig.copy( + abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", + refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) + val config_2_2 = ConfigNode( + "EmptyExpl_cvc5_1.0.2_$inProcess", + emptyExplConfig.copy( + abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", + refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) + val config_3_2 = ConfigNode( + "PredCart_z3_4.10.1_$inProcess", + predConfig.copy(abstractionSolver = "z3:4.10.1", refinementSolver = "z3:4.10.1"), checker, inProcess + ) + + val config_1_3 = ConfigNode( + "QuickFullExpl_mathsat_5.6.8_$inProcess", + quickExplConfig.copy( + abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", + refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) + val config_2_3 = ConfigNode( + "EmptyExpl_mathsat_5.6.8_$inProcess", + emptyExplConfig.copy( + abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", + refinement = Refinement.SEQ_ITP + ), checker, inProcess + ) + val config_3_3 = ConfigNode( + "PredCart_cvc5_1.0.2_$inProcess", + predConfig.copy( + abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", + refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) val timeouts = setOf( Edge(config_1_1, config_2_1, timeoutTrigger), @@ -204,9 +258,13 @@ fun bitwiseStm(): STM { Edge(config_2_3, config_3_1, if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything")), ) - val notTimeout = if (inProcess) ExceptionTrigger(ErrorCodeException(ExitCodes.SOLVER_ERROR.code), - label = "SolverError") else ExceptionTrigger(fallthroughExceptions = timeoutTrigger.exceptions, - label = "AnythingButTimeout") + val notTimeout = if (inProcess) ExceptionTrigger( + ErrorCodeException(ExitCodes.SOLVER_ERROR.code), + label = "SolverError" + ) else ExceptionTrigger( + fallthroughExceptions = timeoutTrigger.exceptions, + label = "AnythingButTimeout" + ) val solverExceptions = setOf( Edge(config_1_1, config_1_2, notTimeout), @@ -231,57 +289,113 @@ fun bitwiseStm(): STM { fun floatsStm(): STM { fun getStm(inProcess: Boolean): STM { - val config_1_1 = ConfigNode("QuickFullExpl_cvc5_1.0.2_$inProcess", - quickExplConfig.copy(abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker, inProcess) - val config_2_1 = ConfigNode("EmptyExpl_cvc5_1.0.2_$inProcess", - quickExplConfig.copy(abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker, inProcess) - val config_3_1 = ConfigNode("PredCart_mathsat_5.6.8_$inProcess", + val config_1_1 = ConfigNode( + "QuickFullExpl_cvc5_1.0.2_$inProcess", + quickExplConfig.copy( + abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", + refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) + val config_2_1 = ConfigNode( + "EmptyExpl_cvc5_1.0.2_$inProcess", + quickExplConfig.copy( + abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", + refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) + val config_3_1 = ConfigNode( + "PredCart_mathsat_5.6.8_$inProcess", predConfig.copy(abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8"), checker, - inProcess) - - val config_1_2 = ConfigNode("QuickFullExpl_cvc5_1.0.2_seq_$inProcess", - quickExplConfig.copy(abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.SEQ_ITP), checker, inProcess) - val config_2_2 = ConfigNode("EmptyExpl_cvc5_1.0.2_seq_$inProcess", - emptyExplConfig.copy(abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.SEQ_ITP), checker, inProcess) - val config_3_2 = ConfigNode("PredCart_bitwuzla_latest_$inProcess", - predConfig.copy(abstractionSolver = "bitwuzla:latest", refinementSolver = "bitwuzla:latest", - refinement = Refinement.NWT_IT_WP), checker, inProcess) - - val config_1_3 = ConfigNode("QuickFullExpl_mathsat_5.6.8_$inProcess", - quickExplConfig.copy(abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", - validateAbstractionSolver = true, validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP), - checker, inProcess) - val config_2_3 = ConfigNode("EmptyExpl_mathsat_5.6.8_$inProcess", - emptyExplConfig.copy(abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", - validateAbstractionSolver = true, validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP), - checker, inProcess) - val config_3_3 = ConfigNode("PredCart_cvc5_1.0.2_$inProcess", - predConfig.copy(abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker, inProcess) - - val config_1_4 = ConfigNode("QuickFullExpl_mathsat_fp_$inProcess", - quickExplConfig.copy(abstractionSolver = "mathsat:fp", refinementSolver = "mathsat:fp", - validateAbstractionSolver = true, validateRefinementSolver = true), checker, inProcess) - val config_2_4 = ConfigNode("EmptyExpl_mathsat_fp_$inProcess", - emptyExplConfig.copy(abstractionSolver = "mathsat:fp", refinementSolver = "mathsat:fp", - validateAbstractionSolver = true, validateRefinementSolver = true), checker, inProcess) - val config_3_4 = ConfigNode("PredCart_mathsat_fp_$inProcess", - predConfig.copy(abstractionSolver = "mathsat:fp", refinementSolver = "mathsat:fp", - validateAbstractionSolver = true, validateRefinementSolver = true), checker, inProcess) - - val config_1_5 = ConfigNode("QuickFullExpl_Z3_$inProcess", - quickExplConfig.copy(abstractionSolver = "Z3", refinementSolver = "Z3", validateAbstractionSolver = true, - validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP), checker, inProcess) - val config_2_5 = ConfigNode("EmptyExpl_Z3_$inProcess", - emptyExplConfig.copy(abstractionSolver = "Z3", refinementSolver = "Z3", validateAbstractionSolver = true, - validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP), checker, inProcess) - val config_3_5 = ConfigNode("PredCart_Z3_$inProcess", + inProcess + ) + + val config_1_2 = ConfigNode( + "QuickFullExpl_cvc5_1.0.2_seq_$inProcess", + quickExplConfig.copy( + abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", + refinement = Refinement.SEQ_ITP + ), checker, inProcess + ) + val config_2_2 = ConfigNode( + "EmptyExpl_cvc5_1.0.2_seq_$inProcess", + emptyExplConfig.copy( + abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", + refinement = Refinement.SEQ_ITP + ), checker, inProcess + ) + val config_3_2 = ConfigNode( + "PredCart_bitwuzla_latest_$inProcess", + predConfig.copy( + abstractionSolver = "bitwuzla:latest", refinementSolver = "bitwuzla:latest", + refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) + + val config_1_3 = ConfigNode( + "QuickFullExpl_mathsat_5.6.8_$inProcess", + quickExplConfig.copy( + abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", + validateAbstractionSolver = true, validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP + ), + checker, inProcess + ) + val config_2_3 = ConfigNode( + "EmptyExpl_mathsat_5.6.8_$inProcess", + emptyExplConfig.copy( + abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", + validateAbstractionSolver = true, validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP + ), + checker, inProcess + ) + val config_3_3 = ConfigNode( + "PredCart_cvc5_1.0.2_$inProcess", + predConfig.copy( + abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", + refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) + + val config_1_4 = ConfigNode( + "QuickFullExpl_mathsat_fp_$inProcess", + quickExplConfig.copy( + abstractionSolver = "mathsat:fp", refinementSolver = "mathsat:fp", + validateAbstractionSolver = true, validateRefinementSolver = true + ), checker, inProcess + ) + val config_2_4 = ConfigNode( + "EmptyExpl_mathsat_fp_$inProcess", + emptyExplConfig.copy( + abstractionSolver = "mathsat:fp", refinementSolver = "mathsat:fp", + validateAbstractionSolver = true, validateRefinementSolver = true + ), checker, inProcess + ) + val config_3_4 = ConfigNode( + "PredCart_mathsat_fp_$inProcess", + predConfig.copy( + abstractionSolver = "mathsat:fp", refinementSolver = "mathsat:fp", + validateAbstractionSolver = true, validateRefinementSolver = true + ), checker, inProcess + ) + + val config_1_5 = ConfigNode( + "QuickFullExpl_Z3_$inProcess", + quickExplConfig.copy( + abstractionSolver = "Z3", refinementSolver = "Z3", validateAbstractionSolver = true, + validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) + val config_2_5 = ConfigNode( + "EmptyExpl_Z3_$inProcess", + emptyExplConfig.copy( + abstractionSolver = "Z3", refinementSolver = "Z3", validateAbstractionSolver = true, + validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP + ), checker, inProcess + ) + val config_3_5 = ConfigNode( + "PredCart_Z3_$inProcess", predConfig.copy(abstractionSolver = "Z3", refinementSolver = "Z3", refinement = Refinement.NWT_IT_WP), - checker, inProcess) + checker, inProcess + ) val timeouts = setOf( Edge(config_1_1, config_2_1, timeoutTrigger), @@ -300,9 +414,13 @@ fun floatsStm(): STM { Edge(config_2_5, config_3_1, if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything")), ) - val notTimeout = if (inProcess) ExceptionTrigger(ErrorCodeException(ExitCodes.SOLVER_ERROR.code), - label = "SolverError") else ExceptionTrigger(fallthroughExceptions = timeoutTrigger.exceptions, - label = "AnythingButTimeout") + val notTimeout = if (inProcess) ExceptionTrigger( + ErrorCodeException(ExitCodes.SOLVER_ERROR.code), + label = "SolverError" + ) else ExceptionTrigger( + fallthroughExceptions = timeoutTrigger.exceptions, + label = "AnythingButTimeout" + ) val solverExceptions = setOf( Edge(config_1_1, config_1_2, notTimeout), diff --git a/scripts/simple.kts b/scripts/simple.kts index 78c2678a13..da95633e75 100644 --- a/scripts/simple.kts +++ b/scripts/simple.kts @@ -47,8 +47,10 @@ var baseConfig = XcfaCegarConfig( ) if (traitsTyped.multithreaded) { - baseConfig = baseConfig.copy(search = Search.BFS, porLevel = POR.AAPOR, - pruneStrategy = PruneStrategy.LAZY) + baseConfig = baseConfig.copy( + search = Search.BFS, porLevel = POR.AAPOR, + pruneStrategy = PruneStrategy.LAZY + ) if (propertyTyped == ErrorDetection.DATA_RACE) { baseConfig = baseConfig.copy(porLevel = POR.BASIC) diff --git a/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaToMonolithicExpr.kt b/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaToMonolithicExpr.kt index ca6c125314..1164bb66af 100644 --- a/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaToMonolithicExpr.kt +++ b/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaToMonolithicExpr.kt @@ -41,11 +41,13 @@ fun CFA.toMonolithicExpr(): MonolithicExpr { } val locVar = Decls.Var("__loc__", Int()) val tranList = this.edges.map { e -> - SequenceStmt.of(listOf( - AssumeStmt.of(Eq(locVar.ref, Int(map[e.source]!!))), - e.stmt, - AssignStmt.of(locVar, Int(map[e.target]!!)) - )) + SequenceStmt.of( + listOf( + AssumeStmt.of(Eq(locVar.ref, Int(map[e.source]!!))), + e.stmt, + AssignStmt.of(locVar, Int(map[e.target]!!)) + ) + ) }.toList() val trans = NonDetStmt.of(tranList); val transUnfold = StmtUtils.toExpr(trans, VarIndexingFactory.indexing(0)); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/bounded/BoundedCheckerBuilder.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/bounded/BoundedCheckerBuilder.kt index bfd1aeadf9..b54dc029aa 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/bounded/BoundedCheckerBuilder.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/bounded/BoundedCheckerBuilder.kt @@ -35,7 +35,8 @@ fun buildBMC( lfPathOnly: () -> Boolean = { true }, ): BoundedChecker { return BoundedChecker(monolithicExpr, shouldGiveUp, bmcSolver, bmcEnabled, lfPathOnly, null, { false }, null, - { false }, valToState, biValToAction, logger) + { false }, valToState, biValToAction, logger + ) } @JvmOverloads @@ -51,8 +52,10 @@ fun buildKIND( lfPathOnly: () -> Boolean = { true }, kindEnabled: (Int) -> Boolean = { true }, ): BoundedChecker { - return BoundedChecker(monolithicExpr, shouldGiveUp, bmcSolver, bmcEnabled, lfPathOnly, null, { false }, indSolver, - kindEnabled, valToState, biValToAction, logger) + return BoundedChecker( + monolithicExpr, shouldGiveUp, bmcSolver, bmcEnabled, lfPathOnly, null, { false }, indSolver, + kindEnabled, valToState, biValToAction, logger + ) } @JvmOverloads @@ -69,5 +72,6 @@ fun buildIMC( imcEnabled: (Int) -> Boolean = { true }, ): BoundedChecker { return BoundedChecker(monolithicExpr, shouldGiveUp, bmcSolver, bmcEnabled, lfPathOnly, itpSolver, imcEnabled, null, - { false }, valToState, biValToAction, logger) + { false }, valToState, biValToAction, logger + ) } \ No newline at end of file diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/chc/HornChecker.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/chc/HornChecker.kt index 0c083b7cd0..8630eed180 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/chc/HornChecker.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/chc/HornChecker.kt @@ -68,7 +68,8 @@ class HornChecker( logger.write(Logger.Level.MAINSTEP, "Proof (model) found\n") val model = solver.model.toMap() SafetyResult.safe( - Invariant(relations.associateWith { model[it.constDecl] as? Expr ?: True() })) + Invariant(relations.associateWith { model[it.constDecl] as? Expr ?: True() }) + ) } SolverStatus.UNSAT -> { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/MemoryEvent.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/MemoryEvent.kt index d10f26e4d1..eeb9b794a4 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/MemoryEvent.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/MemoryEvent.kt @@ -52,8 +52,10 @@ open class MemoryEvent(protected val type: MemoryEventType, protected val tag: S throw UnsupportedOperationException("Not memory IO!") } - abstract class MemoryIO(id: Int, private val `var`: VarDecl<*>, private val localVar: VarDecl<*>, - type: MemoryEventType, tag: String) : + abstract class MemoryIO( + id: Int, private val `var`: VarDecl<*>, private val localVar: VarDecl<*>, + type: MemoryEventType, tag: String + ) : MemoryEvent(type, tag, id) { override fun asMemoryIO(): MemoryIO { @@ -86,8 +88,10 @@ open class MemoryEvent(protected val type: MemoryEventType, protected val tag: S } } - class Write(id: Int, `var`: VarDecl<*>, localVar: VarDecl<*>, private val dependencies: Set>, - tag: String) : + class Write( + id: Int, `var`: VarDecl<*>, localVar: VarDecl<*>, private val dependencies: Set>, + tag: String + ) : MemoryIO(id, `var`, localVar, MemoryEventType.WRITE, tag) { override fun asWrite(): Write { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/analysis/PartialSolver.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/analysis/PartialSolver.kt index a0257bb216..24b877d848 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/analysis/PartialSolver.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/analysis/PartialSolver.kt @@ -54,5 +54,6 @@ class PartialSolver( data class CandidateExecutionGraph( val nodes: List, - val knownEvents: Map, ThreeVL>) { + val knownEvents: Map, ThreeVL> +) { } \ No newline at end of file diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/ItpRefToPtrPrec.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/ItpRefToPtrPrec.kt index c3ec804041..6b17827bf2 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/ItpRefToPtrPrec.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/ItpRefToPtrPrec.kt @@ -30,8 +30,10 @@ class ItpRefToPtrPrec

(private val innerRefToPrec: RefutationToPrec { val newDerefs = refutation[index].dereferences val innerPrec = innerRefToPrec.toPrec(refutation, index).repatch() - return PtrPrec(innerPrec, newDerefs.flatMap { it.ops }.toSet(), - if (newDerefs.isEmpty()) 0 else refutation.size() - index) + return PtrPrec( + innerPrec, newDerefs.flatMap { it.ops }.toSet(), + if (newDerefs.isEmpty()) 0 else refutation.size() - index + ) } override fun join(prec1: PtrPrec

, prec2: PtrPrec

): PtrPrec

{ diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrAction.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrAction.kt index 015084a889..4dee747bb0 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrAction.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrAction.kt @@ -61,19 +61,30 @@ abstract class PtrAction(writeTriples: WriteTriples = emptyMap(), val inCnt: Int val postList = ArrayList() for ((deref, type) in stmt.dereferencesWithAccessTypes) { - Preconditions.checkState(deref.uniquenessIdx.isPresent, - "Incomplete dereferences (missing uniquenessIdx) are not handled properly.") + Preconditions.checkState( + deref.uniquenessIdx.isPresent, + "Incomplete dereferences (missing uniquenessIdx) are not handled properly." + ) val expr = deref.getIte(nextWriteTriples) if (type == AccessType.WRITE) { val writeExpr = ExprUtils.simplify(IntExprs.Add(expr, IntExprs.Int(1))) nextWriteTriples.getOrPut(deref.type) { ArrayList() } .add(Triple(lookup[deref]!!.first, lookup[deref]!!.second, deref.uniquenessIdx.get())) - postList.add(Stmts.Assume(ExprUtils.simplify(BoolExprs.And(listOf( - AbstractExprs.Eq(writeExpr, deref.uniquenessIdx.get()), - ))))) + postList.add( + Stmts.Assume( + ExprUtils.simplify( + BoolExprs.And( + listOf( + AbstractExprs.Eq(writeExpr, deref.uniquenessIdx.get()), + ) + ) + ) + ) + ) } else { preList.add( - Stmts.Assume(ExprUtils.simplify(AbstractExprs.Eq(expr, deref.uniquenessIdx.get())))) + Stmts.Assume(ExprUtils.simplify(AbstractExprs.Eq(expr, deref.uniquenessIdx.get()))) + ) } // postList.add(Stmts.Assume(Eq(vargen("value", deref.type).ref, deref))) // debug mode } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrAnalysis.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrAnalysis.kt index 4eb29ec625..881fecb5bb 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrAnalysis.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrAnalysis.kt @@ -35,16 +35,20 @@ import hu.bme.mit.theta.core.stmt.Stmt * */ -class PtrAnalysis(private val innerAnalysis: Analysis, - private val isHavoc: Boolean = false) : +class PtrAnalysis( + private val innerAnalysis: Analysis, + private val isHavoc: Boolean = false +) : Analysis, PtrAction, PtrPrec

> { override fun getPartialOrd(): PartialOrd> = innerAnalysis.partialOrd.getPtrPartialOrd() override fun getInitFunc(): InitFunc, PtrPrec

> = innerAnalysis.initFunc.getPtrInitFunc() - override fun getTransFunc(): TransFunc, PtrAction, PtrPrec

> = innerAnalysis.transFunc.getPtrTransFunc( - isHavoc) + override fun getTransFunc(): TransFunc, PtrAction, PtrPrec

> = + innerAnalysis.transFunc.getPtrTransFunc( + isHavoc + ) } fun PartialOrd.getPtrPartialOrd(): PartialOrd> = PartialOrd { state1, state2 -> @@ -56,7 +60,8 @@ fun InitFunc.getPtrInitFunc(): InitFunc TransFunc.getPtrTransFunc( - isHavoc: Boolean = false): TransFunc, PtrAction, PtrPrec

> = TransFunc { state, action, prec -> + isHavoc: Boolean = false +): TransFunc, PtrAction, PtrPrec

> = TransFunc { state, action, prec -> val writeTriples = action.nextWriteTriples() val patchedPrec = prec.innerPrec.patch(writeTriples) val exprAction: ExprAction = if (isHavoc) { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrUtils.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrUtils.kt index 3cc08a0cf1..d1748f2526 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrUtils.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrUtils.kt @@ -53,7 +53,8 @@ enum class AccessType { val Stmt.dereferencesWithAccessTypes: List, AccessType>> get() = when (this) { is MemoryAssignStmt<*, *, *> -> expr.dereferences.map { Pair(it, AccessType.READ) } + listOf( - Pair(deref, AccessType.WRITE)) + deref.ops.flatMap { it.dereferences }.map { Pair(it, AccessType.READ) } + Pair(deref, AccessType.WRITE) + ) + deref.ops.flatMap { it.dereferences }.map { Pair(it, AccessType.READ) } is AssignStmt<*> -> expr.dereferences.map { Pair(it, AccessType.READ) } is AssumeStmt -> cond.dereferences.map { Pair(it, AccessType.READ) } @@ -83,19 +84,23 @@ fun SequenceStmt.collapse(): Stmt = this } -fun Stmt.uniqueDereferences(vargen: (String, Type) -> VarDecl<*>, - lookup: MutableMap, Pair, Expr<*>>>): Stmt { +fun Stmt.uniqueDereferences( + vargen: (String, Type) -> VarDecl<*>, + lookup: MutableMap, Pair, Expr<*>>> +): Stmt { val ret = ArrayList() val newStmt = when (this) { is MemoryAssignStmt<*, *, *> -> { MemoryAssignStmt.create( deref.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second as Dereference<*, *, *>, - expr.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second) + expr.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second + ) } is AssignStmt<*> -> AssignStmt.of( TypeUtils.cast(varDecl, varDecl.type), - TypeUtils.cast(expr.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second, varDecl.type)) + TypeUtils.cast(expr.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second, varDecl.type) + ) is AssumeStmt -> AssumeStmt.of(cond.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second) is SequenceStmt -> Stmts.SequenceStmt(stmts.map { it.uniqueDereferences(vargen, lookup) }) @@ -109,13 +114,16 @@ fun Stmt.uniqueDereferences(vargen: (String, Type) -> VarDecl<*>, return SequenceStmt.of(ret + newStmt).collapse() } -fun Expr.uniqueDereferences(vargen: (String, Type) -> VarDecl<*>, - lookup: MutableMap, Pair, Expr<*>>>): Pair, Expr> = +fun Expr.uniqueDereferences( + vargen: (String, Type) -> VarDecl<*>, + lookup: MutableMap, Pair, Expr<*>>> +): Pair, Expr> = if (this is Dereference<*, *, T>) { val ret = ArrayList() Preconditions.checkState(this.uniquenessIdx.isEmpty, "Only non-pretransformed dereferences should be here") val arrayExpr = ExprUtils.simplify( - array.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second) + array.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second + ) val arrayLaterRef = if (arrayExpr !is LitExpr<*>) { val arrayConst = vargen("a", array.type).ref ret.add(Assume(Eq(arrayConst, arrayExpr))) @@ -124,7 +132,8 @@ fun Expr.uniqueDereferences(vargen: (String, Type) -> VarDecl<*>, arrayExpr } val offsetExpr = ExprUtils.simplify( - offset.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second) + offset.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second + ) val offsetLaterRef = if (offsetExpr !is LitExpr<*>) { val offsetConst = vargen("o", offset.type).ref ret.add(Assume(Eq(offsetConst, offsetExpr))) @@ -141,7 +150,8 @@ fun Expr.uniqueDereferences(vargen: (String, Type) -> VarDecl<*>, } else { val ret = ArrayList() Pair(ret, - this.withOps(this.ops.map { it.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second })) + this.withOps(this.ops.map { it.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second }) + ) } object TopCollection : Set> { @@ -168,8 +178,11 @@ enum class PtrTracking { fun Dereference.getIte(writeTriples: WriteTriples): Expr { val list = writeTriples[type] ?: emptyList() return list.fold(Int(0) as Expr) { elze, (arr, off, value) -> - IteExpr.of(BoolExprs.And( - listOf(Eq(arr, array), Eq(off, offset))), value, elze) + IteExpr.of( + BoolExprs.And( + listOf(Eq(arr, array), Eq(off, offset)) + ), value, elze + ) } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/CexMonitor.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/CexMonitor.kt index 32c78c9b0e..95069ed1c1 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/CexMonitor.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/CexMonitor.kt @@ -39,8 +39,10 @@ class CexMonitor constructor( fun checkIfNewCexFound(): Boolean { return if (arg.cexs.anyMatch { cex -> !cexHashStorage.contains(cex) }) { - logger.write(Logger.Level.VERBOSE, - "Counterexample hash check: new cex found successfully\n") + logger.write( + Logger.Level.VERBOSE, + "Counterexample hash check: new cex found successfully\n" + ) true } else { logger.write(Logger.Level.INFO, "Counterexample hash check: NO new cex found\n") @@ -65,7 +67,8 @@ class CexMonitor constructor( when (checkpointName) { "CegarChecker.unsafeARG" -> if (checkIfNewCexFound()) addNewCounterexample() else throwNotSolvable() else -> throw RuntimeException( - "Unknown checkpoint name in CexMonitor execution: $checkpointName") + "Unknown checkpoint name in CexMonitor execution: $checkpointName" + ) } } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/MonitorCheckpoint.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/MonitorCheckpoint.kt index 0e1faccd73..7ddfe7adec 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/MonitorCheckpoint.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/MonitorCheckpoint.kt @@ -52,7 +52,8 @@ class MonitorCheckpoint internal constructor(private val name: String) { assert(registeredCheckpoints.contains(checkpointName)) { "Checkpoint name $checkpointName was not registered (add it in MonitorCheckpoint.kt)" } // see checkpointNames above registeredCheckpoints[checkpointName]?.registerMonitor(m) ?: error( - "Checkpoint with name $checkpointName not found.") + "Checkpoint with name $checkpointName not found." + ) } fun execute(name: String) { diff --git a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiInitFunc.kt b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiInitFunc.kt index 4d7e740082..f3c1ab15ec 100644 --- a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiInitFunc.kt +++ b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiInitFunc.kt @@ -22,7 +22,7 @@ import hu.bme.mit.theta.analysis.State class MultiInitFunc> -( + ( private val createInitialState: (LControl, RControl, DataState) -> MState, private val dataInitFunc: InitFunc, private val extractLeftControlPrec: (LPrec) -> LControlPrec, diff --git a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiPartialOrd.kt b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiPartialOrd.kt index 68b3c77b27..b48b564c28 100644 --- a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiPartialOrd.kt +++ b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiPartialOrd.kt @@ -20,7 +20,7 @@ import hu.bme.mit.theta.analysis.State class MultiPartialOrd> -( + ( private val leftPartOrd: PartialOrd, private val leftCombineStates: (LControl, DataState) -> LState, private val rightPartOrd: PartialOrd, diff --git a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiTransFunc.kt b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiTransFunc.kt index ffe72c9757..02021807d9 100644 --- a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiTransFunc.kt +++ b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiTransFunc.kt @@ -24,7 +24,7 @@ class MultiTransFunc, MAction : MultiAction> -( + ( private val defineNextSide: (MState) -> MultiSide, private val createState: (LControl, RControl, DataState, MultiSide) -> MState, private val leftTransFunc: TransFunc, diff --git a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/MultiBuilderResult.kt b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/MultiBuilderResult.kt index eea37fb1ce..d090ac8cb4 100644 --- a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/MultiBuilderResult.kt +++ b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/MultiBuilderResult.kt @@ -33,7 +33,7 @@ import hu.bme.mit.theta.analysis.unit.UnitState * the whole IDE. For this reason, a POJO has to be used instead */ private data class MultiBuilderResult, MControlState : MultiState, MAction : MultiAction, MLts : MultiLts> -( + ( val side: MultiAnalysisSide, MultiPrec>, val lts: MLts ) diff --git a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/MultiControlInitFunc.kt b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/MultiControlInitFunc.kt index d094692eac..6aa4f6614a 100644 --- a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/MultiControlInitFunc.kt +++ b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/MultiControlInitFunc.kt @@ -28,7 +28,7 @@ import hu.bme.mit.theta.analysis.unit.UnitState * Serves as a control initial function for a multi analysis if the product is nested and this analysis is going to be a part of a larger product. */ internal class MultiControlInitFunc, MPrec : MultiPrec> -( + ( private val leftControlInitFunc: InitFunc, private val rightControlInitFunc: InitFunc, private val createState: (lState: LControl, rState: RControl) -> MState diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/BoundedTest.kt b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/BoundedTest.kt index c1a49e333e..5156908c26 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/BoundedTest.kt +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/BoundedTest.kt @@ -43,7 +43,8 @@ class BoundedTest { } private val biValToAction = { valuation: Valuation?, valuation2: Valuation? -> ExprActionStub( - emptyList()) + emptyList() + ) } init { @@ -76,7 +77,8 @@ class BoundedTest { indSolver = indSolver, valToState = valToState, biValToAction = biValToAction, - logger = ConsoleLogger(Logger.Level.VERBOSE)) + logger = ConsoleLogger(Logger.Level.VERBOSE) + ) val safetyResult: SafetyResult<*, *> = checker.check() Assert.assertTrue(safetyResult.isUnsafe()) } @@ -93,7 +95,8 @@ class BoundedTest { indSolver = indSolver, valToState = valToState, biValToAction = biValToAction, - logger = ConsoleLogger(Logger.Level.VERBOSE)) + logger = ConsoleLogger(Logger.Level.VERBOSE) + ) val safetyResult: SafetyResult<*, *> = checker.check() Assert.assertTrue(safetyResult.isSafe()) } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/ptr/PtrAnalysisTest.kt b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/ptr/PtrAnalysisTest.kt index 9379846676..6c2a0a179c 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/ptr/PtrAnalysisTest.kt +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/ptr/PtrAnalysisTest.kt @@ -43,31 +43,44 @@ class PtrAnalysisTest { private val explTop1 = PtrState(ExplState.top(), nextCnt = 1) private val emptyAction = PtrActionStub(listOf(), emptyMap()) - private val readLiteralOnly = PtrActionStub(listOf(Assume(Eq(Dereference(Int(0), Int(1), Int()), Int(0)))), - emptyMap()) - private val writeLiteralOnly = PtrActionStub(listOf(MemoryAssign(Dereference(Int(0), Int(1), Int()), Int(0))), - emptyMap()) + private val readLiteralOnly = PtrActionStub( + listOf(Assume(Eq(Dereference(Int(0), Int(1), Int()), Int(0)))), + emptyMap() + ) + private val writeLiteralOnly = PtrActionStub( + listOf(MemoryAssign(Dereference(Int(0), Int(1), Int()), Int(0))), + emptyMap() + ) private val emptyPrec = PtrPrec(ExplPrec.empty(), emptySet()) @JvmStatic fun testInputs(): Collection { return listOf( - Arguments.of(explTop0, emptyAction, emptyPrec, - listOf(explTop0)), - Arguments.of(explTop0, readLiteralOnly, emptyPrec, - listOf(explTop1)), - Arguments.of(explTop0, writeLiteralOnly, emptyPrec, + Arguments.of( + explTop0, emptyAction, emptyPrec, + listOf(explTop0) + ), + Arguments.of( + explTop0, readLiteralOnly, emptyPrec, + listOf(explTop1) + ), + Arguments.of( + explTop0, writeLiteralOnly, emptyPrec, listOf( - PtrState(ExplState.top(), 1))), + PtrState(ExplState.top(), 1) + ) + ), ) } } @ParameterizedTest @MethodSource("testInputs") - fun transFuncTest(state: PtrState, action: PtrAction, prec: PtrPrec, - expectedResult: Collection>) { + fun transFuncTest( + state: PtrState, action: PtrAction, prec: PtrPrec, + expectedResult: Collection> + ) { val analysis = PtrAnalysis(ExplAnalysis.create(Z3LegacySolverFactory.getInstance().createSolver(), True())) val result = analysis.transFunc.getSuccStates(state, action, prec) diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/ChcUtils.kt b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/ChcUtils.kt index 5b7789b350..1f3d2ee7c5 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/ChcUtils.kt +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/ChcUtils.kt @@ -61,8 +61,10 @@ open class Relation(val name: String, vararg paramTypes: Type) { open operator fun invoke(vararg params: Expr<*>) = RelationApp(this, params.toList()) } -data class RelationApp(val relation: Relation, val params: List>, - val constraints: List> = emptyList()) { +data class RelationApp( + val relation: Relation, val params: List>, + val constraints: List> = emptyList() +) { init { checkArgument(params.size == relation.arity) diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/Utils.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/Utils.kt index 488fe3330b..665121a5cd 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/Utils.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/Utils.kt @@ -33,8 +33,10 @@ fun ParserRuleContext.textWithWS(): String { object ThrowingErrorListener : BaseErrorListener() { @Throws(ParseCancellationException::class) - override fun syntaxError(recognizer: Recognizer<*, *>?, offendingSymbol: Any?, line: Int, - charPositionInLine: Int, msg: String, e: RecognitionException?) { + override fun syntaxError( + recognizer: Recognizer<*, *>?, offendingSymbol: Any?, line: Int, + charPositionInLine: Int, msg: String, e: RecognitionException? + ) { throw ParseCancellationException("line $line:$charPositionInLine $msg") } } \ No newline at end of file diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/expr/ExprParser.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/expr/ExprParser.kt index f896e6265a..adfdcc3f80 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/expr/ExprParser.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/expr/ExprParser.kt @@ -118,8 +118,10 @@ class ExpressionWrapper(scope: Scope, content: String) { } private fun pop() { - Preconditions.checkState(currentScope.enclosingScope().isPresent, - "Enclosing scope is not present.") + Preconditions.checkState( + currentScope.enclosingScope().isPresent, + "Enclosing scope is not present." + ) currentScope = currentScope.enclosingScope().get() env.pop() } @@ -127,8 +129,10 @@ class ExpressionWrapper(scope: Scope, content: String) { //// override fun visitFuncLitExpr(ctx: FuncLitExprContext): Expr { return if (ctx.result != null) { - val param = Decls.Param(ctx.param.name.text, - TypeWrapper(ctx.param.type().textWithWS()).instantiate()) + val param = Decls.Param( + ctx.param.name.text, + TypeWrapper(ctx.param.type().textWithWS()).instantiate() + ) push(listOf(param)) val result = ctx.result.accept>(this) as Expr pop() @@ -144,8 +148,10 @@ class ExpressionWrapper(scope: Scope, content: String) { } else { ctx.decls.stream() .map { d: DeclContext -> - Decls.Param(d.name.getText(), - TypeWrapper(d.ttype.textWithWS()).instantiate()) + Decls.Param( + d.name.getText(), + TypeWrapper(d.ttype.textWithWS()).instantiate() + ) }.collect(Collectors.toList()) } } @@ -153,8 +159,10 @@ class ExpressionWrapper(scope: Scope, content: String) { //// override fun visitIteExpr(ctx: IteExprContext): Expr { return if (ctx.cond != null) { - val cond: Expr = TypeUtils.cast(ctx.cond.accept>(this), - BoolExprs.Bool()) + val cond: Expr = TypeUtils.cast( + ctx.cond.accept>(this), + BoolExprs.Bool() + ) val then: Expr<*> = ctx.then.accept>(this) val elze: Expr<*> = ctx.elze.accept>(this) AbstractExprs.Ite(cond, then, elze) @@ -165,10 +173,14 @@ class ExpressionWrapper(scope: Scope, content: String) { override fun visitIffExpr(ctx: IffExprContext): Expr { return if (ctx.rightOp != null) { - val leftOp: Expr = TypeUtils.cast(ctx.leftOp.accept>(this), - BoolExprs.Bool()) - val rightOp: Expr = TypeUtils.cast(ctx.rightOp.accept>(this), - BoolExprs.Bool()) + val leftOp: Expr = TypeUtils.cast( + ctx.leftOp.accept>(this), + BoolExprs.Bool() + ) + val rightOp: Expr = TypeUtils.cast( + ctx.rightOp.accept>(this), + BoolExprs.Bool() + ) BoolExprs.Iff(leftOp, rightOp) } else { visitChildren(ctx) @@ -177,10 +189,14 @@ class ExpressionWrapper(scope: Scope, content: String) { override fun visitImplyExpr(ctx: ImplyExprContext): Expr { return if (ctx.rightOp != null) { - val leftOp: Expr = TypeUtils.cast(ctx.leftOp.accept>(this), - BoolExprs.Bool()) - val rightOp: Expr = TypeUtils.cast(ctx.rightOp.accept>(this), - BoolExprs.Bool()) + val leftOp: Expr = TypeUtils.cast( + ctx.leftOp.accept>(this), + BoolExprs.Bool() + ) + val rightOp: Expr = TypeUtils.cast( + ctx.rightOp.accept>(this), + BoolExprs.Bool() + ) BoolExprs.Imply(leftOp, rightOp) } else { visitChildren(ctx) @@ -191,8 +207,10 @@ class ExpressionWrapper(scope: Scope, content: String) { return if (ctx.paramDecls != null) { val paramDecls = createParamList(ctx.paramDecls) push(paramDecls) - val op: Expr = TypeUtils.cast(ctx.op.accept>(this), - BoolExprs.Bool()) + val op: Expr = TypeUtils.cast( + ctx.op.accept>(this), + BoolExprs.Bool() + ) pop() BoolExprs.Forall(paramDecls, op) } else { @@ -204,8 +222,10 @@ class ExpressionWrapper(scope: Scope, content: String) { return if (ctx.paramDecls != null) { val paramDecls = createParamList(ctx.paramDecls) push(paramDecls) - val op: Expr = TypeUtils.cast(ctx.op.accept>(this), - BoolExprs.Bool()) + val op: Expr = TypeUtils.cast( + ctx.op.accept>(this), + BoolExprs.Bool() + ) pop() BoolExprs.Exists(paramDecls, op) } else { @@ -228,10 +248,14 @@ class ExpressionWrapper(scope: Scope, content: String) { override fun visitXorExpr(ctx: XorExprContext): Expr { return if (ctx.rightOp != null) { - val leftOp: Expr = TypeUtils.cast(ctx.leftOp.accept>(this), - BoolExprs.Bool()) - val rightOp: Expr = TypeUtils.cast(ctx.rightOp.accept>(this), - BoolExprs.Bool()) + val leftOp: Expr = TypeUtils.cast( + ctx.leftOp.accept>(this), + BoolExprs.Bool() + ) + val rightOp: Expr = TypeUtils.cast( + ctx.rightOp.accept>(this), + BoolExprs.Bool() + ) BoolExprs.Xor(leftOp, rightOp) } else { visitChildren(ctx) @@ -253,8 +277,10 @@ class ExpressionWrapper(scope: Scope, content: String) { override fun visitNotExpr(ctx: NotExprContext): Expr { return if (ctx.op != null) { - val op: Expr = TypeUtils.cast(ctx.op.accept>(this), - BoolExprs.Bool()) + val op: Expr = TypeUtils.cast( + ctx.op.accept>(this), + BoolExprs.Bool() + ) BoolExprs.Not(op) } else { visitChildren(ctx) @@ -386,8 +412,10 @@ class ExpressionWrapper(scope: Scope, content: String) { } } - private fun createAdditiveExpr(opsHead: Expr<*>, opsTail: List>, - oper: Token, ctx: AdditiveExprContext): Expr { + private fun createAdditiveExpr( + opsHead: Expr<*>, opsTail: List>, + oper: Token, ctx: AdditiveExprContext + ): Expr { return if (opsTail.isEmpty()) { opsHead } else { @@ -398,18 +426,24 @@ class ExpressionWrapper(scope: Scope, content: String) { } } - private fun createAdditiveSubExpr(leftOp: Expr<*>, rightOp: Expr<*>, oper: Token, - ctx: AdditiveExprContext): Expr { + private fun createAdditiveSubExpr( + leftOp: Expr<*>, rightOp: Expr<*>, oper: Token, + ctx: AdditiveExprContext + ): Expr { return when (oper.type) { PLUS -> createAddExpr(leftOp, rightOp) MINUS -> createSubExpr(leftOp, rightOp) BV_ADD -> createBvAddExpr(TypeUtils.castBv(leftOp), TypeUtils.castBv(rightOp)) BV_SUB -> createBvSubExpr(TypeUtils.castBv(leftOp), TypeUtils.castBv(rightOp)) - FPADD -> FpExprs.Add(getRoundingMode(ctx.oper.text), - java.util.List.of(TypeUtils.castFp(leftOp), TypeUtils.castFp(rightOp))) + FPADD -> FpExprs.Add( + getRoundingMode(ctx.oper.text), + java.util.List.of(TypeUtils.castFp(leftOp), TypeUtils.castFp(rightOp)) + ) - FPSUB -> FpExprs.Sub(getRoundingMode(ctx.oper.text), TypeUtils.castFp(leftOp), - TypeUtils.castFp(rightOp)) + FPSUB -> FpExprs.Sub( + getRoundingMode(ctx.oper.text), TypeUtils.castFp(leftOp), + TypeUtils.castFp(rightOp) + ) else -> throw ParseException(ctx, "Unknown operator '" + oper.text + "'") } @@ -459,8 +493,10 @@ class ExpressionWrapper(scope: Scope, content: String) { } } - private fun createMutliplicativeExpr(opsHead: Expr<*>, opsTail: List>, - oper: Token, ctx: MultiplicativeExprContext): Expr { + private fun createMutliplicativeExpr( + opsHead: Expr<*>, opsTail: List>, + oper: Token, ctx: MultiplicativeExprContext + ): Expr { return if (opsTail.isEmpty()) { opsHead } else { @@ -471,8 +507,10 @@ class ExpressionWrapper(scope: Scope, content: String) { } } - private fun createMultiplicativeSubExpr(leftOp: Expr<*>, rightOp: Expr<*>, oper: Token, - ctx: MultiplicativeExprContext): Expr { + private fun createMultiplicativeSubExpr( + leftOp: Expr<*>, rightOp: Expr<*>, oper: Token, + ctx: MultiplicativeExprContext + ): Expr { return when (oper.type) { MUL -> createMulExpr(leftOp, rightOp) BV_MUL -> createBvMulExpr(TypeUtils.castBv(leftOp), TypeUtils.castBv(rightOp)) @@ -485,11 +523,15 @@ class ExpressionWrapper(scope: Scope, content: String) { BV_UREM -> createBvURemExpr(TypeUtils.castBv(leftOp), TypeUtils.castBv(rightOp)) BV_SREM -> createBvSRemExpr(TypeUtils.castBv(leftOp), TypeUtils.castBv(rightOp)) FPREM -> FpExprs.Rem(leftOp as Expr, rightOp as Expr) - FPMUL -> FpExprs.Mul(getRoundingMode(ctx.oper.text), - java.util.List.of(leftOp as Expr, rightOp as Expr)) + FPMUL -> FpExprs.Mul( + getRoundingMode(ctx.oper.text), + java.util.List.of(leftOp as Expr, rightOp as Expr) + ) - FPDIV -> FpExprs.Div(getRoundingMode(ctx.oper.text), leftOp as Expr, - rightOp as Expr) + FPDIV -> FpExprs.Div( + getRoundingMode(ctx.oper.text), leftOp as Expr, + rightOp as Expr + ) else -> throw ParseException(ctx, "Unknown operator '" + oper.text + "'") } @@ -563,8 +605,10 @@ class ExpressionWrapper(scope: Scope, content: String) { } } - private fun createConcatExpr(opsHead: Expr<*>, opsTail: List>, - oper: Token): Expr { + private fun createConcatExpr( + opsHead: Expr<*>, opsTail: List>, + oper: Token + ): Expr { return if (opsTail.isEmpty()) { opsHead } else { @@ -575,8 +619,10 @@ class ExpressionWrapper(scope: Scope, content: String) { } } - private fun createConcatSubExpr(leftOp: Expr<*>, rightOp: Expr<*>, - oper: Token): Expr { + private fun createConcatSubExpr( + leftOp: Expr<*>, rightOp: Expr<*>, + oper: Token + ): Expr { return when (oper.type) { BV_CONCAT -> createBvConcatExpr(TypeUtils.castBv(leftOp), TypeUtils.castBv(rightOp)) else -> throw AssertionError() @@ -599,10 +645,12 @@ class ExpressionWrapper(scope: Scope, content: String) { val extendType = BvExprs.BvType(ctx.rightOp.size.getText().toInt()) when (ctx.oper.getType()) { BV_ZERO_EXTEND -> BvExprs.ZExt( - TypeUtils.castBv(ctx.leftOp.accept>(this)), extendType) + TypeUtils.castBv(ctx.leftOp.accept>(this)), extendType + ) BV_SIGN_EXTEND -> BvExprs.SExt( - TypeUtils.castBv(ctx.leftOp.accept>(this)), extendType) + TypeUtils.castBv(ctx.leftOp.accept>(this)), extendType + ) else -> throw AssertionError() } @@ -621,20 +669,28 @@ class ExpressionWrapper(scope: Scope, content: String) { FP_ABS -> FpExprs.Abs(op as Expr) FP_IS_INF -> FpExprs.IsInfinite(op as Expr) FP_IS_NAN -> FpExprs.IsNan(op as Expr) - FPROUNDTOINT -> FpExprs.RoundToIntegral(getRoundingMode(ctx.oper.text), - op as Expr) + FPROUNDTOINT -> FpExprs.RoundToIntegral( + getRoundingMode(ctx.oper.text), + op as Expr + ) FPSQRT -> FpExprs.Sqrt(getRoundingMode(ctx.oper.text), op as Expr) - FPTOFP -> FpExprs.ToFp(getRoundingMode(ctx.oper.text), op as Expr, - getExp(ctx.oper.getText()), getSignificand(ctx.oper.getText())) - - FPTOBV -> FpExprs.ToBv(getRoundingMode(ctx.oper.text), op as Expr, - getBvSize(ctx.oper.getText()), isSignedBv(ctx.oper.getText())) - - FP_FROM_BV -> FpExprs.FromBv(getRoundingMode(ctx.oper.text), + FPTOFP -> FpExprs.ToFp( + getRoundingMode(ctx.oper.text), op as Expr, + getExp(ctx.oper.getText()), getSignificand(ctx.oper.getText()) + ) + + FPTOBV -> FpExprs.ToBv( + getRoundingMode(ctx.oper.text), op as Expr, + getBvSize(ctx.oper.getText()), isSignedBv(ctx.oper.getText()) + ) + + FP_FROM_BV -> FpExprs.FromBv( + getRoundingMode(ctx.oper.text), op as Expr, FpType.of(getExp(ctx.oper.getText()), getSignificand(ctx.oper.getText())), - isSignedFp(ctx.oper.getText())) + isSignedFp(ctx.oper.getText()) + ) FPNEG -> FpExprs.Neg(op as Expr) FPPOS -> FpExprs.Pos(op as Expr) @@ -717,7 +773,8 @@ class ExpressionWrapper(scope: Scope, content: String) { return if (ctx.array != null) { ArrayReadExpr.create( ctx.array.accept(this), - ctx.index.accept(this)) + ctx.index.accept(this) + ) } else { visitChildren(ctx) } @@ -728,7 +785,8 @@ class ExpressionWrapper(scope: Scope, content: String) { ArrayWriteExpr.create( ctx.array.accept(this), ctx.index.accept(this), - ctx.elem.accept(this)) + ctx.elem.accept(this) + ) } else { visitChildren(ctx) } @@ -746,8 +804,10 @@ class ExpressionWrapper(scope: Scope, content: String) { return if (ctx.op != null) { val op = ctx.op.accept(this) val bitvec = TypeUtils.castBv(op) - return BvExprs.Extract(bitvec, Int(ctx.from.getText()), - IntExprs.Int(ctx.until.getText())) + return BvExprs.Extract( + bitvec, Int(ctx.from.getText()), + IntExprs.Int(ctx.until.getText()) + ) } else { visitChildren(ctx) } @@ -804,14 +864,19 @@ class ExpressionWrapper(scope: Scope, content: String) { override fun visitArrLitExpr(ctx: ArrLitExprContext): Expr { Preconditions.checkNotNull(ctx.elseExpr) val indexType = if (ctx.indexExpr.size > 0) ctx.indexExpr[0].accept( - this).type else Int() + this + ).type else Int() val elseElem = ctx.elseExpr.accept(this) val valueType = elseElem.type val elems = ctx.indexExpr.mapIndexed { idx, it -> Tuple2.of(it.accept(this), ctx.valueExpr[idx].accept(this)) } - return ExprUtils.simplify(ArrayInitExpr.create(elems, elseElem, - ArrayType.of(indexType, valueType))) + return ExprUtils.simplify( + ArrayInitExpr.create( + elems, elseElem, + ArrayType.of(indexType, valueType) + ) + ) } override fun visitBvLitExpr(ctx: BvLitExprContext): Expr { @@ -822,7 +887,8 @@ class ExpressionWrapper(scope: Scope, content: String) { decodeBinaryBvContent(content.substring(1)) } else if (content.startsWith("d")) { check( - sizeAndContent.size == 2) { "Decimal value is only parseable if size is given." } + sizeAndContent.size == 2 + ) { "Decimal value is only parseable if size is given." } decodeDecimalBvContent(content.substring(1), sizeAndContent[0].toInt()) } else if (content.startsWith("x")) { decodeHexadecimalBvContent(content.substring(1)) @@ -843,7 +909,8 @@ class ExpressionWrapper(scope: Scope, content: String) { '0' -> value[i] = false '1' -> value[i] = true else -> throw IllegalArgumentException( - "Binary literal can contain only 0 and 1") + "Binary literal can contain only 0 and 1" + ) } } return value @@ -853,7 +920,8 @@ class ExpressionWrapper(scope: Scope, content: String) { var value = BigInteger(lit) Preconditions.checkArgument( value.compareTo( - BigInteger.TWO.pow(size - 1).multiply(BigInteger.valueOf(-1))) >= 0 && + BigInteger.TWO.pow(size - 1).multiply(BigInteger.valueOf(-1)) + ) >= 0 && value.compareTo(BigInteger.TWO.pow(size)) < 0, "Decimal literal is not in range" ) @@ -892,8 +960,10 @@ class ExpressionWrapper(scope: Scope, content: String) { override fun visitIdExpr(ctx: IdExprContext): RefExpr<*> { val optSymbol = currentScope.resolve(ctx.id.getText()) if (optSymbol.isEmpty) { - throw ParseException(ctx, - "Identifier '" + ctx.id.getText() + "' cannot be resolved") + throw ParseException( + ctx, + "Identifier '" + ctx.id.getText() + "' cannot be resolved" + ) } val symbol = optSymbol.get() val decl = env.eval(symbol) as Decl<*> diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/stmt/StmtParser.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/stmt/StmtParser.kt index 09ea6e8f9d..d11ca4187c 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/stmt/StmtParser.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/stmt/StmtParser.kt @@ -108,7 +108,8 @@ class StatementWrapper(val content: String, scope: Scope) { override fun visitMemAssignStmt(ctx: MemAssignStmtContext): Stmt { val derefExpr: Dereference<*, *, *> = ExpressionWrapper(scope, ctx.derefExpr().textWithWS()).instantiate( - env) as Dereference<*, *, *> + env + ) as Dereference<*, *, *> val value = ExpressionWrapper(scope, ctx.value.textWithWS()) val valueE: Expr<*> = value.instantiate(env) return if (derefExpr.type == valueE.type) { diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/ArgAdapter.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/ArgAdapter.kt index a05598f87e..eaad49e3e0 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/ArgAdapter.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/ArgAdapter.kt @@ -26,9 +26,11 @@ import hu.bme.mit.theta.analysis.State import hu.bme.mit.theta.analysis.algorithm.arg.ARG import java.lang.reflect.Type -class ArgAdapter(val gsonSupplier: () -> Gson, +class ArgAdapter( + val gsonSupplier: () -> Gson, private val partialOrdSupplier: () -> PartialOrd, - private val argTypeSupplier: () -> Type) : TypeAdapter>() { + private val argTypeSupplier: () -> Type +) : TypeAdapter>() { private lateinit var gson: Gson private lateinit var partialOrd: PartialOrd diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/ArgAdapterHelper.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/ArgAdapterHelper.kt index f00ff2ac89..05e193a195 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/ArgAdapterHelper.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/ArgAdapterHelper.kt @@ -54,11 +54,14 @@ data class ArgAdapterHelper( while (waitSet.isNotEmpty()) { val entry = waitSet.firstOrNull { lut.keys.contains(checkNotNull(edges[it]).source) } check( - entry != null) { "Unreachable node(s) present: $waitSet\nedges: $edges\nlut: $lut" } + entry != null + ) { "Unreachable node(s) present: $waitSet\nedges: $edges\nlut: $lut" } waitSet.remove(entry) val edge = checkNotNull(edges[entry]) - lut[entry] = arg.createSuccNode(lut[edge.source], edge.action, checkNotNull(nodes[entry]).state, - checkNotNull(nodes[entry]).target) + lut[entry] = arg.createSuccNode( + lut[edge.source], edge.action, checkNotNull(nodes[entry]).state, + checkNotNull(nodes[entry]).target + ) .also { n -> if (checkNotNull(nodes[entry]).expanded) n.expanded = true } } coveringEdges.forEach { checkNotNull(lut[it.key]).cover(lut[it.value]) } diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/SafetyResultAdapter.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/SafetyResultAdapter.kt index 6829d577c0..271417ea04 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/SafetyResultAdapter.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/SafetyResultAdapter.kt @@ -40,8 +40,10 @@ class SafetyResultAdapter( private lateinit var argType: Type private lateinit var traceType: Type - override fun write(writer: JsonWriter, - value: SafetyResult, Trace>) { + override fun write( + writer: JsonWriter, + value: SafetyResult, Trace> + ) { initGson() writer.beginObject() writer.name("arg") @@ -80,8 +82,10 @@ class SafetyResultAdapter( return if (stats.isEmpty) if (safe == true) SafetyResult.safe(arg) else SafetyResult.unsafe(trace, arg) else - if (safe == false) SafetyResult.safe(arg, stats.get()) else SafetyResult.unsafe(trace, - arg, stats.get()) + if (safe == false) SafetyResult.safe(arg, stats.get()) else SafetyResult.unsafe( + trace, + arg, stats.get() + ) } private fun initGson() { diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StateAdapters.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StateAdapters.kt index a75f2133cb..1675ec639a 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StateAdapters.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StateAdapters.kt @@ -90,7 +90,8 @@ class PredStateAdapter(val gsonSupplier: () -> Gson, val scope: Scope, val env: if (reader.nextBoolean()) ret = PredState.bottom() check(reader.nextName() == "preds") val preds = gson.fromJson>>(reader, - object : TypeToken>>() {}.type) + object : TypeToken>>() {}.type + ) if (ret == null) ret = PredState.of(preds) reader.endObject() return ret!! diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/TraceAdapter.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/TraceAdapter.kt index 0571800b23..649ec9d72c 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/TraceAdapter.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/TraceAdapter.kt @@ -26,8 +26,10 @@ import hu.bme.mit.theta.analysis.State import hu.bme.mit.theta.analysis.Trace import java.lang.reflect.Type -class TraceAdapter(val gsonSupplier: () -> Gson, private val stateTypeSupplier: () -> Type, - private val actionType: Type) : TypeAdapter>() { +class TraceAdapter( + val gsonSupplier: () -> Gson, private val stateTypeSupplier: () -> Type, + private val actionType: Type +) : TypeAdapter>() { private lateinit var gson: Gson private lateinit var stateType: Type @@ -47,11 +49,15 @@ class TraceAdapter(val gsonSupplier: () -> Gson, private val stateTypeSupplier: if (!this::stateType.isInitialized) stateType = stateTypeSupplier() reader.beginObject() check(reader.nextName() == "states") - val stateList: List = gson.fromJson(reader, - TypeToken.getParameterized(TypeToken.get(List::class.java).type, stateType).type) + val stateList: List = gson.fromJson( + reader, + TypeToken.getParameterized(TypeToken.get(List::class.java).type, stateType).type + ) check(reader.nextName() == "actions") - val actionList: List = gson.fromJson(reader, - TypeToken.getParameterized(TypeToken.get(List::class.java).type, actionType).type) + val actionList: List = gson.fromJson( + reader, + TypeToken.getParameterized(TypeToken.get(List::class.java).type, actionType).type + ) reader.endObject() return Trace.of(stateList, actionList) } diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/VarDeclAdapter.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/VarDeclAdapter.kt index 8e0ea55885..2dc571788f 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/VarDeclAdapter.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/VarDeclAdapter.kt @@ -29,8 +29,10 @@ import hu.bme.mit.theta.core.decl.Decls.Var import hu.bme.mit.theta.core.decl.VarDecl import hu.bme.mit.theta.core.type.Type -class VarDeclAdapter(val gsonSupplier: () -> Gson, val scope: MutableScope, val env: Env, - val throwIfNotInScope: Boolean = false) : TypeAdapter>() { +class VarDeclAdapter( + val gsonSupplier: () -> Gson, val scope: MutableScope, val env: Env, + val throwIfNotInScope: Boolean = false +) : TypeAdapter>() { private lateinit var gson: Gson diff --git a/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/ExprTest.kt b/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/ExprTest.kt index ff72c48eb5..b647fb75c2 100644 --- a/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/ExprTest.kt +++ b/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/ExprTest.kt @@ -91,36 +91,57 @@ class ExprTest { arrayOf(fpLit1, "(#b1 #b1010 #b101010)", emptyMap>()), arrayOf(fpLit2, "(#b0 #b1010 #b101010)", emptyMap>()), - arrayOf(ArrayLitExpr.of(listOf(), Int(2), ArrayType.of(Int(), Int())), - "(array (default 2))", emptyMap>()), - arrayOf(ArrayLitExpr.of(listOf(Tuple2.of(Int(0), Int(1))), Int(2), - ArrayType.of(Int(), Int())), "(array (0 1) (default 2))", - emptyMap>()), arrayOf( - ArrayLitExpr.of(listOf(Tuple2.of(Int(0), Int(1)), Tuple2.of(Int(1), Int(2))), - Int(3), ArrayType.of(Int(), Int())), "(array (0 1) (1 2) (default 3))", - emptyMap>()), + ArrayLitExpr.of(listOf(), Int(2), ArrayType.of(Int(), Int())), + "(array (default 2))", emptyMap>() + ), + arrayOf( + ArrayLitExpr.of( + listOf(Tuple2.of(Int(0), Int(1))), Int(2), + ArrayType.of(Int(), Int()) + ), "(array (0 1) (default 2))", + emptyMap>() + ), + arrayOf( + ArrayLitExpr.of( + listOf(Tuple2.of(Int(0), Int(1)), Tuple2.of(Int(1), Int(2))), + Int(3), ArrayType.of(Int(), Int()) + ), "(array (0 1) (1 2) (default 3))", + emptyMap>() + ), arrayOf(RefExpr.of(x), "x", mapOf(Pair(NamedSymbol("x"), x))), - arrayOf(Ite(True(), Int(1), Int(2)), "(ite true 1 2)", - emptyMap>()), + arrayOf( + Ite(True(), Int(1), Int(2)), "(ite true 1 2)", + emptyMap>() + ), arrayOf(Iff(True(), False()), "(iff true false)", emptyMap>()), arrayOf(Imply(True(), False()), "(=> true false)", emptyMap>()), - arrayOf(Forall(listOf(p), True()), "(forall ((p Int)) true)", - mapOf(Pair(NamedSymbol("p"), p))), - arrayOf(Exists(listOf(p), True()), "(exists ((p Int)) true)", - mapOf(Pair(NamedSymbol("p"), p))), + arrayOf( + Forall(listOf(p), True()), "(forall ((p Int)) true)", + mapOf(Pair(NamedSymbol("p"), p)) + ), + arrayOf( + Exists(listOf(p), True()), "(exists ((p Int)) true)", + mapOf(Pair(NamedSymbol("p"), p)) + ), - arrayOf(Max(fpLit1, fpLit2), "(fpmax (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", - emptyMap>()), - arrayOf(Min(fpLit1, fpLit2), "(fpmin (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", - emptyMap>()), + arrayOf( + Max(fpLit1, fpLit2), "(fpmax (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", + emptyMap>() + ), + arrayOf( + Min(fpLit1, fpLit2), "(fpmin (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", + emptyMap>() + ), arrayOf(Or(True(), False()), "(or true false)", emptyMap>()), arrayOf(Xor(True(), False()), "(xor true false)", emptyMap>()), - arrayOf(And(True(), False(), False()), "(and true false false)", - emptyMap>()), + arrayOf( + And(True(), False(), False()), "(and true false false)", + emptyMap>() + ), arrayOf(Not(True()), "(not true)", emptyMap>()), arrayOf(Eq(Int(1), Int(2)), "(= 1 2)", emptyMap>()), @@ -129,80 +150,142 @@ class ExprTest { arrayOf(Gt(Int(1), Int(2)), "(> 1 2)", emptyMap>()), arrayOf(Geq(Int(1), Int(2)), "(>= 1 2)", emptyMap>()), - arrayOf(BvExprs.ULt(bvLit1, bvLit1), "(bvult #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.ULeq(bvLit1, bvLit1), "(bvule #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.UGt(bvLit1, bvLit1), "(bvugt #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.UGeq(bvLit1, bvLit1), "(bvuge #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.SLt(bvLit1, bvLit1), "(bvslt #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.SLeq(bvLit1, bvLit1), "(bvsle #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.SGt(bvLit1, bvLit1), "(bvsgt #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.SGeq(bvLit1, bvLit1), "(bvsge #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.Or(listOf(bvLit1, bvLit1)), "(bvor #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.Xor(listOf(bvLit1, bvLit1)), "(bvxor #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.And(listOf(bvLit1, bvLit1)), "(bvand #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.ShiftLeft(bvLit1, bvLit1), "(bvshl #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.ArithShiftRight(bvLit1, bvLit1), "(bvashr #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.LogicShiftRight(bvLit1, bvLit1), "(bvlshr #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.RotateLeft(bvLit1, bvLit1), "(bvrol #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.RotateRight(bvLit1, bvLit1), "(bvror #b1010 #b1010)", - emptyMap>()), - - arrayOf(Add(listOf(Int(1), Int(2), Int(3))), "(+ 1 2 3)", - emptyMap>()), + arrayOf( + BvExprs.ULt(bvLit1, bvLit1), "(bvult #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.ULeq(bvLit1, bvLit1), "(bvule #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.UGt(bvLit1, bvLit1), "(bvugt #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.UGeq(bvLit1, bvLit1), "(bvuge #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.SLt(bvLit1, bvLit1), "(bvslt #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.SLeq(bvLit1, bvLit1), "(bvsle #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.SGt(bvLit1, bvLit1), "(bvsgt #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.SGeq(bvLit1, bvLit1), "(bvsge #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.Or(listOf(bvLit1, bvLit1)), "(bvor #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.Xor(listOf(bvLit1, bvLit1)), "(bvxor #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.And(listOf(bvLit1, bvLit1)), "(bvand #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.ShiftLeft(bvLit1, bvLit1), "(bvshl #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.ArithShiftRight(bvLit1, bvLit1), "(bvashr #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.LogicShiftRight(bvLit1, bvLit1), "(bvlshr #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.RotateLeft(bvLit1, bvLit1), "(bvrol #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.RotateRight(bvLit1, bvLit1), "(bvror #b1010 #b1010)", + emptyMap>() + ), + + arrayOf( + Add(listOf(Int(1), Int(2), Int(3))), "(+ 1 2 3)", + emptyMap>() + ), arrayOf(Sub(Int(1), Int(2)), "(- 1 2)", emptyMap>()), arrayOf(Add(bvLit1, bvLit1), "(bvadd #b1010 #b1010)", emptyMap>()), arrayOf(Sub(bvLit1, bvLit1), "(bvsub #b1010 #b1010)", emptyMap>()), - arrayOf(Add(fpLit1, fpLit2), "(fpadd (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", - emptyMap>()), - arrayOf(Sub(fpLit1, fpLit2), "(fpsub (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", - emptyMap>()), + arrayOf( + Add(fpLit1, fpLit2), "(fpadd (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", + emptyMap>() + ), + arrayOf( + Sub(fpLit1, fpLit2), "(fpsub (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", + emptyMap>() + ), - arrayOf(Mul(listOf(Int(1), Int(2), Int(3))), "(* 1 2 3)", - emptyMap>()), + arrayOf( + Mul(listOf(Int(1), Int(2), Int(3))), "(* 1 2 3)", + emptyMap>() + ), arrayOf(Div(Int(1), Int(2)), "(div 1 2)", emptyMap>()), arrayOf(Mod(Int(1), Int(2)), "(mod 1 2)", emptyMap>()), arrayOf(Rem(Int(1), Int(2)), "(rem 1 2)", emptyMap>()), arrayOf(Mul(bvLit1, bvLit1), "(bvmul #b1010 #b1010)", emptyMap>()), - arrayOf(UDiv(bvLit1, bvLit1), "(bvudiv #b1010 #b1010)", - emptyMap>()), - arrayOf(BvExprs.SDiv(bvLit1, bvLit2), "(bvsdiv #b1010 #b0101)", - emptyMap>()), - arrayOf(BvExprs.SMod(bvLit1, bvLit2), "(bvsmod #b1010 #b0101)", - emptyMap>()), - arrayOf(BvExprs.URem(bvLit1, bvLit2), "(bvurem #b1010 #b0101)", - emptyMap>()), - arrayOf(BvExprs.SRem(bvLit1, bvLit2), "(bvsrem #b1010 #b0101)", - emptyMap>()), - arrayOf(Mul(fpLit1, fpLit2), "(fpmul (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", - emptyMap>()), - arrayOf(FpExprs.Div(FpRoundingMode.RNE, fpLit1, fpLit2), + arrayOf( + UDiv(bvLit1, bvLit1), "(bvudiv #b1010 #b1010)", + emptyMap>() + ), + arrayOf( + BvExprs.SDiv(bvLit1, bvLit2), "(bvsdiv #b1010 #b0101)", + emptyMap>() + ), + arrayOf( + BvExprs.SMod(bvLit1, bvLit2), "(bvsmod #b1010 #b0101)", + emptyMap>() + ), + arrayOf( + BvExprs.URem(bvLit1, bvLit2), "(bvurem #b1010 #b0101)", + emptyMap>() + ), + arrayOf( + BvExprs.SRem(bvLit1, bvLit2), "(bvsrem #b1010 #b0101)", + emptyMap>() + ), + arrayOf( + Mul(fpLit1, fpLit2), "(fpmul (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", + emptyMap>() + ), + arrayOf( + FpExprs.Div(FpRoundingMode.RNE, fpLit1, fpLit2), "(fpdiv[rne] (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", - emptyMap>()), - arrayOf(FpExprs.Rem(fpLit1, fpLit2), + emptyMap>() + ), + arrayOf( + FpExprs.Rem(fpLit1, fpLit2), "(fprem (#b1 #b1010 #b101010) (#b0 #b1010 #b101010))", - emptyMap>()), + emptyMap>() + ), - arrayOf(Concat(listOf(bvLit1, bvLit2)), "(++ #b1010 #b0101)", - emptyMap>()), - arrayOf(ZExt(bvLit1, BvType(5)), "(bv_zero_extend #b1010 (Bv 5))", - emptyMap>()), - arrayOf(SExt(bvLit1, BvType(5)), "(bv_sign_extend #b1010 (Bv 5))", - emptyMap>()), + arrayOf( + Concat(listOf(bvLit1, bvLit2)), "(++ #b1010 #b0101)", + emptyMap>() + ), + arrayOf( + ZExt(bvLit1, BvType(5)), "(bv_zero_extend #b1010 (Bv 5))", + emptyMap>() + ), + arrayOf( + SExt(bvLit1, BvType(5)), "(bv_sign_extend #b1010 (Bv 5))", + emptyMap>() + ), arrayOf(Pos(Int(1)), "(+ 1)", emptyMap>()), arrayOf(Neg(Int(1)), "(- 1)", emptyMap>()), @@ -210,17 +293,27 @@ class ExprTest { arrayOf(Neg(bvLit1), "(bvneg #b1010)", emptyMap>()), arrayOf(Not(bvLit1), "(bvnot #b1010)", emptyMap>()), - arrayOf(ArrayReadExpr.create( - ArrayLitExpr.of(emptyList(), Int(2), ArrayType.of(Int(), Int())), Int(5)), - "(read (array (default 2)) 5)", emptyMap>()), - arrayOf(ArrayWriteExpr.create( - ArrayLitExpr.of(emptyList(), Int(2), - ArrayType.of(Int(), Int())), Int(5), Int(6)), - "(write (array (default 2)) 5 6)", emptyMap>()), + arrayOf( + ArrayReadExpr.create( + ArrayLitExpr.of(emptyList(), Int(2), ArrayType.of(Int(), Int())), Int(5) + ), + "(read (array (default 2)) 5)", emptyMap>() + ), + arrayOf( + ArrayWriteExpr.create( + ArrayLitExpr.of( + emptyList(), Int(2), + ArrayType.of(Int(), Int()) + ), Int(5), Int(6) + ), + "(write (array (default 2)) 5 6)", emptyMap>() + ), arrayOf(Prime(Int(1)), "(prime 1)", emptyMap>()), - arrayOf(Extract(bvLit1, Int(1), Int(4)), "(extract #b1010 1 4)", - emptyMap>()), + arrayOf( + Extract(bvLit1, Int(1), Int(4)), "(extract #b1010 1 4)", + emptyMap>() + ), arrayOf(Dereference(Int(0), Int(1), Int()), "(deref 0 1 Int)", emptyMap>()), ) @@ -240,7 +333,8 @@ class ExprTest { val env = Env() decls.forEach { env.define(it.key, it.value) } val expr = simplify( - ExpressionWrapper(SimpleScope(symbolTable), serialized).instantiate(env)) + ExpressionWrapper(SimpleScope(symbolTable), serialized).instantiate(env) + ) Assert.assertEquals(simplify(memory), expr) } @@ -252,7 +346,8 @@ class ExprTest { val env = Env() decls.forEach { env.define(it.key, it.value) } val expr = simplify( - ExpressionWrapper(SimpleScope(symbolTable), memory.toString()).instantiate(env)) + ExpressionWrapper(SimpleScope(symbolTable), memory.toString()).instantiate(env) + ) Assert.assertEquals(simplify(memory), expr) } diff --git a/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/StmtTest.kt b/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/StmtTest.kt index 372e1f796e..2dc532876e 100644 --- a/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/StmtTest.kt +++ b/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/StmtTest.kt @@ -53,13 +53,19 @@ class StmtTest { val addr = x.hashCode() return listOf( - arrayOf(Assign(x, Int(1)), "(assign x 1)", - mapOf(Pair(ExprTest.NamedSymbol("x"), x))), - arrayOf(MemoryAssign(Dereference(Int(addr), Int(0), Int()), Int(1)), + arrayOf( + Assign(x, Int(1)), "(assign x 1)", + mapOf(Pair(ExprTest.NamedSymbol("x"), x)) + ), + arrayOf( + MemoryAssign(Dereference(Int(addr), Int(0), Int()), Int(1)), "(memassign (deref $addr 0 Int) 1)", - mapOf(Pair(ExprTest.NamedSymbol("x"), x))), - arrayOf(Assume(Eq(x.ref, Int(1))), "(assume (= x 1))", - mapOf(Pair(ExprTest.NamedSymbol("x"), x))), + mapOf(Pair(ExprTest.NamedSymbol("x"), x)) + ), + arrayOf( + Assume(Eq(x.ref, Int(1))), "(assume (= x 1))", + mapOf(Pair(ExprTest.NamedSymbol("x"), x)) + ), arrayOf(Havoc(x), "(havoc x)", mapOf(Pair(ExprTest.NamedSymbol("x"), x))), ) } diff --git a/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/TypeTest.kt b/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/TypeTest.kt index a94dfbf86d..8745fef7c3 100644 --- a/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/TypeTest.kt +++ b/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/dsl/TypeTest.kt @@ -52,8 +52,10 @@ class TypeTest { arrayOf(BvType(32), "(Bv 32)"), arrayOf(FpType(12, 45), "(Fp 12 45)"), - arrayOf(Func(Int(), ArrayExprs.Array(Int(), Rat())), - "(Func Int (Array ([Int] -> Rat)))"), + arrayOf( + Func(Int(), ArrayExprs.Array(Int(), Rat())), + "(Func Int (Array ([Int] -> Rat)))" + ), ) } } diff --git a/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/gson/TestGson.kt b/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/gson/TestGson.kt index cb6ca93071..026a4626ee 100644 --- a/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/gson/TestGson.kt +++ b/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/gson/TestGson.kt @@ -102,11 +102,14 @@ class TestGson { val gsonBuilder = GsonBuilder() gsonBuilder.registerTypeHierarchyAdapter(ARG::class.java, - ArgAdapter(gsonSuppl, { ExplOrd.getInstance() }, { explArgAdapterHelper() })) + ArgAdapter(gsonSuppl, { ExplOrd.getInstance() }, { explArgAdapterHelper() }) + ) gsonBuilder.registerTypeHierarchyAdapter(Trace::class.java, - TraceAdapter(gsonSuppl, { ExplState::class.java }, SimpleStmtAction::class.java)) + TraceAdapter(gsonSuppl, { ExplState::class.java }, SimpleStmtAction::class.java) + ) gsonBuilder.registerTypeHierarchyAdapter(SafetyResult::class.java, - SafetyResultAdapter(gsonSuppl, { explArgHelper() }, { explTraceHelper() })) + SafetyResultAdapter(gsonSuppl, { explArgHelper() }, { explTraceHelper() }) + ) return gsonBuilder } @@ -115,11 +118,14 @@ class TestGson { val gsonBuilder = GsonBuilder() gsonBuilder.registerTypeHierarchyAdapter(ARG::class.java, - ArgAdapter(gsonSuppl, { PartialOrd { a, b -> true } }, { predArgAdapterHelper() })) + ArgAdapter(gsonSuppl, { PartialOrd { a, b -> true } }, { predArgAdapterHelper() }) + ) gsonBuilder.registerTypeHierarchyAdapter(Trace::class.java, - TraceAdapter(gsonSuppl, { PredState::class.java }, SimpleStmtAction::class.java)) + TraceAdapter(gsonSuppl, { PredState::class.java }, SimpleStmtAction::class.java) + ) gsonBuilder.registerTypeHierarchyAdapter(SafetyResult::class.java, - SafetyResultAdapter(gsonSuppl, { predArgHelper() }, { predTraceHelper() })) + SafetyResultAdapter(gsonSuppl, { predArgHelper() }, { predTraceHelper() }) + ) return gsonBuilder } @@ -133,8 +139,10 @@ class TestGson { val env = Env() env.define(symbol, x) - gsonBuilder.registerTypeHierarchyAdapter(VarDecl::class.java, - VarDeclAdapter(gsonSuppl, scope, env, false)) + gsonBuilder.registerTypeHierarchyAdapter( + VarDecl::class.java, + VarDeclAdapter(gsonSuppl, scope, env, false) + ) gsonBuilder.registerTypeHierarchyAdapter(Stmt::class.java, StringTypeAdapter { StatementWrapper(it, scope).instantiate(env) }) gsonBuilder.registerTypeHierarchyAdapter(Expr::class.java, @@ -144,8 +152,10 @@ class TestGson { gsonBuilder.registerTypeHierarchyAdapter(VarIndexing::class.java, StringTypeAdapter { BasicVarIndexing.fromString(it, scope, env) }) gsonBuilder.registerTypeHierarchyAdapter(ExplState::class.java, ExplStateAdapter(scope, env)) - gsonBuilder.registerTypeHierarchyAdapter(PredState::class.java, - PredStateAdapter(gsonSuppl, scope, env)) + gsonBuilder.registerTypeHierarchyAdapter( + PredState::class.java, + PredStateAdapter(gsonSuppl, scope, env) + ) gsonBuilder.registerTypeHierarchyAdapter(Pair::class.java, PairAdapter(gsonSuppl)) gsonBuilder.registerTypeHierarchyAdapter(Triple::class.java, TripleAdapter(gsonSuppl)) gsonBuilder.registerTypeHierarchyAdapter(Optional::class.java, OptionalAdapter(gsonSuppl)) @@ -194,8 +204,10 @@ class TestGson { gson = getGson(getExplBuilder { gson }) { gson } val trace = Trace.of( - listOf(ExplState.of(ImmutableValuation.builder().put(x, Int(1)).build()), - ExplState.of(ImmutableValuation.builder().put(x, Int(2)).build())), + listOf( + ExplState.of(ImmutableValuation.builder().put(x, Int(1)).build()), + ExplState.of(ImmutableValuation.builder().put(x, Int(2)).build()) + ), listOf(SimpleStmtAction(SkipStmt.getInstance())) ) diff --git a/subprojects/common/multi-tests/src/test/kotlin/multi/MultiNondetDiningPhilosophersTest.kt b/subprojects/common/multi-tests/src/test/kotlin/multi/MultiNondetDiningPhilosophersTest.kt index ce30555dea..408190e912 100644 --- a/subprojects/common/multi-tests/src/test/kotlin/multi/MultiNondetDiningPhilosophersTest.kt +++ b/subprojects/common/multi-tests/src/test/kotlin/multi/MultiNondetDiningPhilosophersTest.kt @@ -73,20 +73,28 @@ class MultiNondetDiningPhilosophersTest { val phil3cfa = phil3rawCfa.copyWithReplacingVars(variables.associateBy { it.name }) val phil4cfa = phil4rawCfa.copyWithReplacingVars(variables.associateBy { it.name }) - val cfa1ConfigBuilder = CfaConfigBuilder(CfaConfigBuilder.Domain.EXPL, CfaConfigBuilder.Refinement.SEQ_ITP, - Z3LegacySolverFactory.getInstance()) + val cfa1ConfigBuilder = CfaConfigBuilder( + CfaConfigBuilder.Domain.EXPL, CfaConfigBuilder.Refinement.SEQ_ITP, + Z3LegacySolverFactory.getInstance() + ) cfa1ConfigBuilder.encoding(CfaConfigBuilder.Encoding.LBE) val cfa1ExplBuilder = cfa1ConfigBuilder.ExplStrategy(phil1cfa) - val cfa2ConfigBuilder = CfaConfigBuilder(CfaConfigBuilder.Domain.EXPL, CfaConfigBuilder.Refinement.SEQ_ITP, - Z3LegacySolverFactory.getInstance()) + val cfa2ConfigBuilder = CfaConfigBuilder( + CfaConfigBuilder.Domain.EXPL, CfaConfigBuilder.Refinement.SEQ_ITP, + Z3LegacySolverFactory.getInstance() + ) cfa2ConfigBuilder.encoding(CfaConfigBuilder.Encoding.LBE) val cfa2ExplBuilder = cfa1ConfigBuilder.ExplStrategy(phil2cfa) - val cfa3ConfigBuilder = CfaConfigBuilder(CfaConfigBuilder.Domain.EXPL, CfaConfigBuilder.Refinement.SEQ_ITP, - Z3LegacySolverFactory.getInstance()) + val cfa3ConfigBuilder = CfaConfigBuilder( + CfaConfigBuilder.Domain.EXPL, CfaConfigBuilder.Refinement.SEQ_ITP, + Z3LegacySolverFactory.getInstance() + ) cfa3ConfigBuilder.encoding(CfaConfigBuilder.Encoding.LBE) val cfa3ExplBuilder = cfa1ConfigBuilder.ExplStrategy(phil3cfa) - val cfa4ConfigBuilder = CfaConfigBuilder(CfaConfigBuilder.Domain.EXPL, CfaConfigBuilder.Refinement.SEQ_ITP, - Z3LegacySolverFactory.getInstance()) + val cfa4ConfigBuilder = CfaConfigBuilder( + CfaConfigBuilder.Domain.EXPL, CfaConfigBuilder.Refinement.SEQ_ITP, + Z3LegacySolverFactory.getInstance() + ) cfa4ConfigBuilder.encoding(CfaConfigBuilder.Encoding.LBE) val cfa4ExplBuilder = cfa1ConfigBuilder.ExplStrategy(phil4cfa) @@ -110,13 +118,15 @@ class MultiNondetDiningPhilosophersTest { var prop: Expr = True() variables.forEach { prop = And(prop, Eq(it.ref, True())) } val dataPredicate = ExplStatePredicate(prop, solver) - val multiConfigBuilder = StmtMultiConfigBuilder.ItpStmtMultiConfigBuilder(totalProduct, prop, + val multiConfigBuilder = StmtMultiConfigBuilder.ItpStmtMultiConfigBuilder( + totalProduct, prop, MultiStatePredicate(dataPredicate), RefToMultiPrec(cfaRefToPrec, cfaRefToPrec, ItpRefToExplPrec()), RefToMultiPrec(cfaRefToPrec, cfaRefToPrec, ItpRefToExplPrec()), ItpRefToExplPrec(), MultiPrec(cfaInitPrec, cfaInitPrec, dataInitPrec), MultiPrec(cfaInitPrec, cfaInitPrec, dataInitPrec), dataInitPrec, Z3LegacySolverFactory.getInstance(), - logger) + logger + ) val result = multiConfigBuilder.build().check() Assertions.assertTrue(result.isUnsafe) diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/CStatistics.kt b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/CStatistics.kt index 6be63aab98..1f8d894b79 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/CStatistics.kt +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/CStatistics.kt @@ -50,8 +50,10 @@ fun CProgram.getStatistics(): CStatistics { fun CFunction.collectStatistics(): Triple { val statisticsCollectorVisitor = StatisticsCollectorVisitor() this.compound?.accept(statisticsCollectorVisitor, Unit) - return Triple(statisticsCollectorVisitor.loopNumber, statisticsCollectorVisitor.deepestLoop, - statisticsCollectorVisitor.linear) + return Triple( + statisticsCollectorVisitor.loopNumber, statisticsCollectorVisitor.deepestLoop, + statisticsCollectorVisitor.linear + ) } fun Expr<*>.isNonLinear(): Boolean { diff --git a/subprojects/frontends/llvm/build.gradle.kts b/subprojects/frontends/llvm/build.gradle.kts index 2d93c23af0..812b35248b 100644 --- a/subprojects/frontends/llvm/build.gradle.kts +++ b/subprojects/frontends/llvm/build.gradle.kts @@ -104,8 +104,10 @@ fun llvmConfigFlags(vararg args: String): Array { fun jniConfigFlags(): Array { if (!taskEnabled) return arrayOf() - val jdkHomeArr = runCommandForOutput("bash", "-c", - "dirname \$(cd \$(dirname \$(readlink -f \$(which javac) || which javac)); pwd -P)") + val jdkHomeArr = runCommandForOutput( + "bash", "-c", + "dirname \$(cd \$(dirname \$(readlink -f \$(which javac) || which javac)); pwd -P)" + ) check(jdkHomeArr.size == 1) val jdkHome = File(jdkHomeArr[0]) check(jdkHome.exists()) @@ -120,11 +122,14 @@ fun jniConfigFlags(): Array { library { targetMachines.add(machines.linux.x86_64) tasks.withType(CppCompile::class) { - compilerArgs.addAll(listOf( - "-Wall", - "-fpic", - *jniConfigFlags(), - *llvmConfigFlags("--cxxflags"))) + compilerArgs.addAll( + listOf( + "-Wall", + "-fpic", + *jniConfigFlags(), + *llvmConfigFlags("--cxxflags") + ) + ) if (!taskEnabled) { println("CppCompile is enabled: $taskEnabled") enabled = false @@ -132,10 +137,13 @@ library { } tasks.withType(LinkSharedLibrary::class) { - linkerArgs.addAll(listOf( - "-rdynamic", - *llvmConfigFlags("--cxxflags", "--ldflags", "--libs", "core", "bitreader"), - "-ldl")) + linkerArgs.addAll( + listOf( + "-rdynamic", + *llvmConfigFlags("--cxxflags", "--ldflags", "--libs", "core", "bitreader"), + "-ldl" + ) + ) if (!taskEnabled) { println("LinkSharedLibrary is enabled: $taskEnabled") enabled = false diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/DefaultGraphPatternCompiler.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/DefaultGraphPatternCompiler.kt index facf177953..1869904e1e 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/DefaultGraphPatternCompiler.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/DefaultGraphPatternCompiler.kt @@ -110,8 +110,10 @@ abstract class DefaultGraphPatternCompiler : GraphPatternCompiler { override fun compile(pattern: BasicEventSet): T? = null override fun compile(pattern: BasicRelation): T? = null - override fun getCompleteGraph(mcm: Set, - model: Valuation): Pair, Map, ThreeVL>> { + override fun getCompleteGraph( + mcm: Set, + model: Valuation + ): Pair, Map, ThreeVL>> { error("Not implemented") } } \ No newline at end of file diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/GraphPatternCompiler.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/GraphPatternCompiler.kt index 0490c9f006..fa24ce82cc 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/GraphPatternCompiler.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/GraphPatternCompiler.kt @@ -59,6 +59,8 @@ interface GraphPatternCompiler { fun compile(pattern: UnionNode): T2 fun compile(pattern: BasicEventSet): T2 fun compile(pattern: BasicRelation): T2 - fun getCompleteGraph(namedPatterns: Set, - model: Valuation): Pair, Map, ThreeVL>> + fun getCompleteGraph( + namedPatterns: Set, + model: Valuation + ): Pair, Map, ThreeVL>> } \ No newline at end of file diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/pattern2expr/Pattern2ExprCompiler.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/pattern2expr/Pattern2ExprCompiler.kt index 4102e138ff..d6355f1d95 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/pattern2expr/Pattern2ExprCompiler.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/compilers/pattern2expr/Pattern2ExprCompiler.kt @@ -48,8 +48,10 @@ class Pattern2ExprCompiler : GraphPatternCompiler, Map, - model: Valuation): Pair, Map, ThreeVL>> { + override fun getCompleteGraph( + namedPatterns: Set, + model: Valuation + ): Pair, Map, ThreeVL>> { val ret = LinkedHashMap, ThreeVL>() ret.putAll(facts) ret.putAll(namedLookup.map { n -> @@ -200,7 +202,8 @@ class Pattern2ExprCompiler : GraphPatternCompiler, Map val const = if (pattern.patternName != null) { val const = namedLookup[Pair(pattern.patternName!!, Tuple2.of(a, b))] ?: Const( - "RTC_" + uuid + "_" + a + "_" + b, Bool()) + "RTC_" + uuid + "_" + a + "_" + b, Bool() + ) namedLookup[Pair(pattern.patternName!!, Tuple2.of(a, b))] = const const } else { @@ -263,7 +266,8 @@ class Pattern2ExprCompiler : GraphPatternCompiler, Map val const = if (pattern.patternName != null) { val const = namedLookup[Pair(pattern.patternName!!, Tuple2.of(a, b))] ?: Const( - "TC_" + uuid + "_" + a + "_" + b, Bool()) + "TC_" + uuid + "_" + a + "_" + b, Bool() + ) namedLookup[Pair(pattern.patternName!!, Tuple2.of(a, b))] = const const } else { @@ -314,7 +318,8 @@ class Pattern2ExprCompiler : GraphPatternCompiler, Map> { return events.associate { a -> - Pair(Tuple1.of(a), + Pair( + Tuple1.of(a), when (facts[Pair(pattern.name, Tuple1.of(a))]) { ThreeVL.FALSE -> False() ThreeVL.TRUE -> True() @@ -323,14 +328,16 @@ class Pattern2ExprCompiler : GraphPatternCompiler, Map> { return events.map { a -> events.map { b -> - Pair(Tuple2.of(a, b), + Pair( + Tuple2.of(a, b), when (facts[Pair(pattern.name, Tuple2.of(a, b))]) { ThreeVL.FALSE -> False() ThreeVL.TRUE -> True() @@ -339,7 +346,8 @@ class Pattern2ExprCompiler : GraphPatternCompiler, Map { companion object { - private val smallLine: Pair, Map, ThreeVL>> = Pair(listOf(1, 2, 3), mapOf( - Pair(Pair("po", Tuple2.of(1, 1)), ThreeVL.FALSE), - Pair(Pair("po", Tuple2.of(1, 2)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(1, 3)), ThreeVL.FALSE), - Pair(Pair("po", Tuple2.of(2, 1)), ThreeVL.FALSE), - Pair(Pair("po", Tuple2.of(2, 2)), ThreeVL.FALSE), - Pair(Pair("po", Tuple2.of(2, 3)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(3, 1)), ThreeVL.FALSE), - Pair(Pair("po", Tuple2.of(3, 2)), ThreeVL.FALSE), - Pair(Pair("po", Tuple2.of(3, 3)), ThreeVL.FALSE), - )) + private val smallLine: Pair, Map, ThreeVL>> = Pair( + listOf(1, 2, 3), mapOf( + Pair(Pair("po", Tuple2.of(1, 1)), ThreeVL.FALSE), + Pair(Pair("po", Tuple2.of(1, 2)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(1, 3)), ThreeVL.FALSE), + Pair(Pair("po", Tuple2.of(2, 1)), ThreeVL.FALSE), + Pair(Pair("po", Tuple2.of(2, 2)), ThreeVL.FALSE), + Pair(Pair("po", Tuple2.of(2, 3)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(3, 1)), ThreeVL.FALSE), + Pair(Pair("po", Tuple2.of(3, 2)), ThreeVL.FALSE), + Pair(Pair("po", Tuple2.of(3, 3)), ThreeVL.FALSE), + ) + ) - private val smallCycle: Pair, Map, ThreeVL>> = Pair(listOf(1, 2, 3), mapOf( - Pair(Pair("po", Tuple2.of(1, 1)), ThreeVL.FALSE), - Pair(Pair("po", Tuple2.of(1, 2)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(1, 3)), ThreeVL.FALSE), - Pair(Pair("po", Tuple2.of(2, 1)), ThreeVL.FALSE), - Pair(Pair("po", Tuple2.of(2, 2)), ThreeVL.FALSE), - Pair(Pair("po", Tuple2.of(2, 3)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(3, 1)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(3, 2)), ThreeVL.FALSE), - Pair(Pair("po", Tuple2.of(3, 3)), ThreeVL.FALSE), - )) + private val smallCycle: Pair, Map, ThreeVL>> = Pair( + listOf(1, 2, 3), mapOf( + Pair(Pair("po", Tuple2.of(1, 1)), ThreeVL.FALSE), + Pair(Pair("po", Tuple2.of(1, 2)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(1, 3)), ThreeVL.FALSE), + Pair(Pair("po", Tuple2.of(2, 1)), ThreeVL.FALSE), + Pair(Pair("po", Tuple2.of(2, 2)), ThreeVL.FALSE), + Pair(Pair("po", Tuple2.of(2, 3)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(3, 1)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(3, 2)), ThreeVL.FALSE), + Pair(Pair("po", Tuple2.of(3, 3)), ThreeVL.FALSE), + ) + ) - private val smallFull: Pair, Map, ThreeVL>> = Pair(listOf(1, 2, 3), mapOf( - Pair(Pair("po", Tuple2.of(1, 1)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(1, 2)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(1, 3)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(2, 1)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(2, 2)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(2, 3)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(3, 1)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(3, 2)), ThreeVL.TRUE), - Pair(Pair("po", Tuple2.of(3, 3)), ThreeVL.TRUE), - Pair(Pair("W", Tuple1.of(1)), ThreeVL.TRUE), - Pair(Pair("R", Tuple1.of(2)), ThreeVL.TRUE), - Pair(Pair("F", Tuple1.of(3)), ThreeVL.TRUE), - )) + private val smallFull: Pair, Map, ThreeVL>> = Pair( + listOf(1, 2, 3), mapOf( + Pair(Pair("po", Tuple2.of(1, 1)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(1, 2)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(1, 3)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(2, 1)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(2, 2)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(2, 3)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(3, 1)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(3, 2)), ThreeVL.TRUE), + Pair(Pair("po", Tuple2.of(3, 3)), ThreeVL.TRUE), + Pair(Pair("W", Tuple1.of(1)), ThreeVL.TRUE), + Pair(Pair("R", Tuple1.of(2)), ThreeVL.TRUE), + Pair(Pair("F", Tuple1.of(3)), ThreeVL.TRUE), + ) + ) @Parameterized.Parameters @JvmStatic @@ -102,7 +108,8 @@ class GraphSolverTest { smallLine.first, smallLine.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -111,7 +118,8 @@ class GraphSolverTest { smallCycle.first, smallCycle.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), false ), arrayOf( @@ -120,7 +128,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), false ), arrayOf( @@ -129,7 +138,8 @@ class GraphSolverTest { smallLine.first, smallLine.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), false ), arrayOf( @@ -138,7 +148,8 @@ class GraphSolverTest { smallCycle.first, smallCycle.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -147,7 +158,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -156,7 +168,8 @@ class GraphSolverTest { smallLine.first, smallLine.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), false ), arrayOf( @@ -165,7 +178,8 @@ class GraphSolverTest { smallCycle.first, smallCycle.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), false ), arrayOf( @@ -174,7 +188,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -183,7 +198,8 @@ class GraphSolverTest { smallLine.first, smallLine.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -192,7 +208,8 @@ class GraphSolverTest { smallCycle.first, smallCycle.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -201,7 +218,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), false ), arrayOf( @@ -210,7 +228,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -219,7 +238,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), false ), arrayOf( @@ -228,7 +248,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -237,7 +258,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -246,7 +268,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -255,7 +278,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -264,7 +288,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -273,7 +298,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -282,7 +308,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -291,7 +318,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -300,7 +328,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -309,7 +338,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -318,7 +348,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -327,7 +358,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -336,7 +368,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), true ), arrayOf( @@ -345,7 +378,8 @@ class GraphSolverTest { smallFull.first, smallFull.second, SATGraphSolver( - Z3LegacySolverFactory.getInstance().createSolver()), + Z3LegacySolverFactory.getInstance().createSolver() + ), false ), ) diff --git a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/GenericSmtLibHornSolverTest.kt b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/GenericSmtLibHornSolverTest.kt index 9383d479b8..e1c2533a6d 100644 --- a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/GenericSmtLibHornSolverTest.kt +++ b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/GenericSmtLibHornSolverTest.kt @@ -126,8 +126,11 @@ class GenericSmtLibHornSolverTest { App( App( model.get(init.constDecl) as FuncLitExpr>, - p0.ref), - p1.ref)) + p0.ref + ), + p1.ref + ) + ) checkerSolver.add(Lt(p1.ref, Int(0))) Assertions.assertTrue(checkerSolver.check().isUnsat) diff --git a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3HornSolverTest.kt b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3HornSolverTest.kt index 859165d9cf..eafd44ec12 100644 --- a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3HornSolverTest.kt +++ b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3HornSolverTest.kt @@ -85,8 +85,11 @@ class Z3HornSolverTest { App( App( model.get(init.constDecl) as FuncLitExpr>, - p0.ref), - p1.ref)) + p0.ref + ), + p1.ref + ) + ) checkerSolver.add(Lt(p1.ref, Int(0))) Assertions.assertTrue(checkerSolver.check().isUnsat) diff --git a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt index d82a92fa4a..a015c6ce1d 100644 --- a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt +++ b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/FrontendXcfaBuilder.kt @@ -54,16 +54,20 @@ import org.abego.treelayout.internal.util.Contract.checkState import java.math.BigInteger import java.util.stream.Collectors -class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boolean = false, - val uniqueWarningLogger: Logger) : +class FrontendXcfaBuilder( + val parseContext: ParseContext, val checkOverflow: Boolean = false, + val uniqueWarningLogger: Logger +) : CStatementVisitorBase() { private val locationLut: MutableMap = LinkedHashMap() private var ptrCnt = 1 // counts up, uses 3k+1 get() = field.also { field += 3 } - private fun getLoc(builder: XcfaProcedureBuilder, name: String?, - metadata: MetaData): XcfaLocation { + private fun getLoc( + builder: XcfaProcedureBuilder, name: String?, + metadata: MetaData + ): XcfaLocation { if (name == null) return getAnonymousLoc(builder, metadata = metadata) locationLut.putIfAbsent(name, XcfaLocation(name, metadata = metadata)) val location = locationLut[name] @@ -100,40 +104,64 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo } builder.addVar(XcfaGlobalVar(globalDeclaration.get2(), type.nullValue)) if (type is CArray) { - initStmtList.add(StmtLabel( - Stmts.Assign(cast(globalDeclaration.get2(), globalDeclaration.get2().type), - cast(type.getValue("$ptrCnt"), globalDeclaration.get2().type)) - )) + initStmtList.add( + StmtLabel( + Stmts.Assign( + cast(globalDeclaration.get2(), globalDeclaration.get2().type), + cast(type.getValue("$ptrCnt"), globalDeclaration.get2().type) + ) + ) + ) } else { if (globalDeclaration.get1().initExpr != null && globalDeclaration.get1().initExpr.expression !is UnsupportedInitializer) { - initStmtList.add(StmtLabel( - Stmts.Assign(cast(globalDeclaration.get2(), globalDeclaration.get2().type), - cast(type.castTo(globalDeclaration.get1().initExpr.expression), - globalDeclaration.get2().type)) - )) + initStmtList.add( + StmtLabel( + Stmts.Assign( + cast(globalDeclaration.get2(), globalDeclaration.get2().type), + cast( + type.castTo(globalDeclaration.get1().initExpr.expression), + globalDeclaration.get2().type + ) + ) + ) + ) } else { - initStmtList.add(StmtLabel( - Stmts.Assign(cast(globalDeclaration.get2(), globalDeclaration.get2().type), - cast(type.nullValue, globalDeclaration.get2().type)) - )) + initStmtList.add( + StmtLabel( + Stmts.Assign( + cast(globalDeclaration.get2(), globalDeclaration.get2().type), + cast(type.nullValue, globalDeclaration.get2().type) + ) + ) + ) } } if (globalDeclaration.get1().arrayDimensions.size == 1) { - val bounds = ExprUtils.simplify(CComplexType.getUnsignedLong(parseContext) - .castTo(globalDeclaration.get1().arrayDimensions[0].expression)) - checkState(bounds is IntLitExpr || bounds is BvLitExpr, - "Only IntLit and BvLit expression expected here.") - val literalValue = if (bounds is IntLitExpr) bounds.value.toLong() else BvUtils.neutralBvLitExprToBigInteger( - bounds as BvLitExpr).toLong() + val bounds = ExprUtils.simplify( + CComplexType.getUnsignedLong(parseContext) + .castTo(globalDeclaration.get1().arrayDimensions[0].expression) + ) + checkState( + bounds is IntLitExpr || bounds is BvLitExpr, + "Only IntLit and BvLit expression expected here." + ) + val literalValue = + if (bounds is IntLitExpr) bounds.value.toLong() else BvUtils.neutralBvLitExprToBigInteger( + bounds as BvLitExpr + ).toLong() val literalToExpr = { x: Long -> if (bounds is IntLitExpr) IntLitExpr.of( - BigInteger.valueOf(x)) else BvUtils.bigIntegerToNeutralBvLitExpr(BigInteger.valueOf(x), - (bounds as BvLitExpr).type.size) + BigInteger.valueOf(x) + ) else BvUtils.bigIntegerToNeutralBvLitExpr( + BigInteger.valueOf(x), + (bounds as BvLitExpr).type.size + ) } - val initExprs: Map> = (globalDeclaration.get1()?.initExpr as? CInitializerList)?.statements?.mapIndexed { i, it -> - Pair(i, it.get2().expression) - }?.toMap() ?: emptyMap() + val initExprs: Map> = + (globalDeclaration.get1()?.initExpr as? CInitializerList)?.statements?.mapIndexed { i, it -> + Pair(i, it.get2().expression) + }?.toMap() ?: emptyMap() for (i in 0 until literalValue) { checkState(globalDeclaration.get1().actualType is CArray, "Only arrays are expected here") val embeddedType = (globalDeclaration.get1().actualType as CArray).embeddedType @@ -155,8 +183,10 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo return builder } - private fun handleFunction(function: CFunction, param: List, - xcfaBuilder: XcfaBuilder): XcfaProcedureBuilder { + private fun handleFunction( + function: CFunction, param: List, + xcfaBuilder: XcfaBuilder + ): XcfaProcedureBuilder { locationLut.clear() val flatVariables = function.flatVariables val funcDecl = function.funcDecl @@ -183,7 +213,8 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo for (functionParam in funcDecl.functionParams) { Preconditions.checkState( functionParam.actualType is CVoid || functionParam.varDecls.size > 0, - "Function param should have an associated variable!") + "Function param should have an associated variable!" + ) for (varDecl in functionParam.varDecls) { if (varDecl != null) builder.addParam(varDecl, ParamDirection.IN) } @@ -193,10 +224,14 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo builder.addVar(flatVariable) val type = CComplexType.getType(flatVariable.ref, parseContext) if ((type is CArray || type is CStruct) && builder.getParams().none { it.first == flatVariable }) { - initStmtList.add(StmtLabel( - Stmts.Assign(cast(flatVariable, flatVariable.type), - cast(type.getValue("$ptrCnt"), flatVariable.type)) - )) + initStmtList.add( + StmtLabel( + Stmts.Assign( + cast(flatVariable, flatVariable.type), + cast(type.getValue("$ptrCnt"), flatVariable.type) + ) + ) + ) } } builder.createInitLoc(getMetadata(function)) @@ -212,8 +247,10 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo val endinit = getAnonymousLoc(builder, getMetadata(function)) builder.addLoc(endinit) - val initEdge = XcfaEdge(init, endinit, SequenceLabel(initStmtList), - metadata = getMetadata(function)) + val initEdge = XcfaEdge( + init, endinit, SequenceLabel(initStmtList), + metadata = getMetadata(function) + ) builder.addEdge(initEdge) init = endinit builder.createFinalLoc(getMetadata(function)) @@ -257,10 +294,13 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo } is RefExpr<*> -> { - StmtLabel(Stmts.Assign( - cast(lValue.decl as VarDecl<*>, (lValue.decl as VarDecl<*>).type), - cast(CComplexType.getType(lValue, parseContext).castTo(rExpression), lValue.type)), - metadata = getMetadata(statement)) + StmtLabel( + Stmts.Assign( + cast(lValue.decl as VarDecl<*>, (lValue.decl as VarDecl<*>).type), + cast(CComplexType.getType(lValue, parseContext).castTo(rExpression), lValue.type) + ), + metadata = getMetadata(statement) + ) } else -> { @@ -281,17 +321,23 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo xcfaEdge = XcfaEdge(initLoc, middleLoc1, label, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) - xcfaEdge = XcfaEdge(middleLoc1, location, + xcfaEdge = XcfaEdge( + middleLoc1, location, StmtLabel(type.limit(lhs.ref), metadata = getMetadata(statement)), - metadata = getMetadata(statement)) + metadata = getMetadata(statement) + ) builder.addEdge(xcfaEdge) - xcfaEdge = XcfaEdge(middleLoc1, middleLoc2, + xcfaEdge = XcfaEdge( + middleLoc1, middleLoc2, StmtLabel(Assume(Not(type.limit(lhs.ref).cond)), metadata = getMetadata(statement)), - metadata = getMetadata(statement)) + metadata = getMetadata(statement) + ) builder.addEdge(xcfaEdge) - xcfaEdge = XcfaEdge(middleLoc2, location, + xcfaEdge = XcfaEdge( + middleLoc2, location, InvokeLabel("overflow", listOf(), metadata = getMetadata(statement)), - metadata = getMetadata(statement)) + metadata = getMetadata(statement) + ) builder.addEdge(xcfaEdge) } return location @@ -309,11 +355,13 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo builder.addEdge(xcfaEdge) val location = getAnonymousLoc(builder, metadata = getMetadata(statement)) builder.addLoc(location) - xcfaEdge = XcfaEdge(initLoc, location, StmtLabel( - statement.assumeStmt, - choiceType = ChoiceType.MAIN_PATH, - metadata = getMetadata(statement) - ), metadata = getMetadata(statement)) + xcfaEdge = XcfaEdge( + initLoc, location, StmtLabel( + statement.assumeStmt, + choiceType = ChoiceType.MAIN_PATH, + metadata = getMetadata(statement) + ), metadata = getMetadata(statement) + ) builder.addEdge(xcfaEdge) return location } @@ -330,8 +378,10 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo builder.addEdge(edge) check(breakLoc != null) edge = XcfaEdge(initLoc, breakLoc, metadata = getMetadata(statement)) - val unreachableLoc = XcfaLocation("Unreachable" + XcfaLocation.uniqueCounter(), - metadata = getMetadata(statement)) + val unreachableLoc = XcfaLocation( + "Unreachable" + XcfaLocation.uniqueCounter(), + metadata = getMetadata(statement) + ) builder.addLoc(unreachableLoc) builder.addEdge(edge) return unreachableLoc @@ -355,8 +405,10 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo builder.addVar(ret) params.add(ret.ref) for (cStatement in myParams) { - initLoc = cStatement.accept(this, - ParamPack(builder, initLoc, breakLoc, continueLoc, returnLoc)) + initLoc = cStatement.accept( + this, + ParamPack(builder, initLoc, breakLoc, continueLoc, returnLoc) + ) } params.addAll(myParams.stream().map { obj: CStatement -> obj.expression } .collect(Collectors.toList())) @@ -388,14 +440,20 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo val edge = XcfaEdge(lastLoc, initLoc, metadata = getMetadata(statement)) builder.addEdge(edge) lastLoc = initLoc - if (preStatements != null) lastLoc = preStatements.accept(this, - ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc)) + if (preStatements != null) lastLoc = preStatements.accept( + this, + ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc) + ) for (cStatement in statement.getcStatementList()) { - if (cStatement != null) lastLoc = cStatement.accept(this, - ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc)) + if (cStatement != null) lastLoc = cStatement.accept( + this, + ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc) + ) } - if (postStatements != null) lastLoc = postStatements.accept(this, - ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc)) + if (postStatements != null) lastLoc = postStatements.accept( + this, + ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc) + ) return lastLoc } @@ -412,7 +470,8 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo check(continueLoc != null) edge = XcfaEdge(initLoc, continueLoc, metadata = getMetadata(statement)) val unreachableLoc: XcfaLocation = XcfaLocation( - "Unreachable" + XcfaLocation.uniqueCounter(), metadata = getMetadata(statement)) + "Unreachable" + XcfaLocation.uniqueCounter(), metadata = getMetadata(statement) + ) builder.addLoc(unreachableLoc) builder.addEdge(edge) return unreachableLoc @@ -447,26 +506,40 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo builder.addLoc(initLoc) var xcfaEdge: XcfaEdge = XcfaEdge(lastLoc, initLoc, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) - val lastBody = body.accept(this, - ParamPack(builder, initLoc, endLoc, innerEndLoc, returnLoc)) + val lastBody = body.accept( + this, + ParamPack(builder, initLoc, endLoc, innerEndLoc, returnLoc) + ) xcfaEdge = XcfaEdge(lastBody, innerEndLoc, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) - val lastPre = buildWithoutPostStatement(guard, - ParamPack(builder, innerEndLoc, null, null, returnLoc)) - val assume = StmtLabel(Stmts.Assume( - AbstractExprs.Neq(guard.expression, CComplexType.getType(guard.expression, parseContext).nullValue)), - choiceType = ChoiceType.MAIN_PATH, metadata = getMetadata(guard)) + val lastPre = buildWithoutPostStatement( + guard, + ParamPack(builder, innerEndLoc, null, null, returnLoc) + ) + val assume = StmtLabel( + Stmts.Assume( + AbstractExprs.Neq(guard.expression, CComplexType.getType(guard.expression, parseContext).nullValue) + ), + choiceType = ChoiceType.MAIN_PATH, metadata = getMetadata(guard) + ) xcfaEdge = XcfaEdge(lastPre, innerInnerGuard, assume, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) - val assume1 = StmtLabel(Stmts.Assume( - AbstractExprs.Eq(guard.expression, CComplexType.getType(guard.expression, parseContext).nullValue)), - choiceType = ChoiceType.ALTERNATIVE_PATH, metadata = getMetadata(guard)) + val assume1 = StmtLabel( + Stmts.Assume( + AbstractExprs.Eq(guard.expression, CComplexType.getType(guard.expression, parseContext).nullValue) + ), + choiceType = ChoiceType.ALTERNATIVE_PATH, metadata = getMetadata(guard) + ) xcfaEdge = XcfaEdge(lastPre, outerInnerGuard, assume1, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) - val outerLastGuard = buildPostStatement(guard, - ParamPack(builder, outerInnerGuard, null, null, null)) - val innerLastGuard = buildPostStatement(guard, - ParamPack(builder, innerInnerGuard, null, null, null)) + val outerLastGuard = buildPostStatement( + guard, + ParamPack(builder, outerInnerGuard, null, null, null) + ) + val innerLastGuard = buildPostStatement( + guard, + ParamPack(builder, innerInnerGuard, null, null, null) + ) xcfaEdge = XcfaEdge(outerLastGuard, endLoc, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) xcfaEdge = XcfaEdge(innerLastGuard, initLoc, metadata = getMetadata(statement)) @@ -505,13 +578,21 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo builder.addLoc(startIncrement) var xcfaEdge: XcfaEdge = XcfaEdge(lastLoc, initLoc, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) - val lastInit = if (init == null) initLoc else init.accept(this, - ParamPack(builder, initLoc, null, null, returnLoc)) - val lastTest = if (guard == null) lastInit else buildWithoutPostStatement(guard, - ParamPack(builder, lastInit!!, null, null, returnLoc)) + val lastInit = if (init == null) initLoc else init.accept( + this, + ParamPack(builder, initLoc, null, null, returnLoc) + ) + val lastTest = if (guard == null) lastInit else buildWithoutPostStatement( + guard, + ParamPack(builder, lastInit!!, null, null, returnLoc) + ) val assume = StmtLabel( - Stmts.Assume(if (guard == null) True() else AbstractExprs.Neq(guard.expression, - CComplexType.getType(guard.expression, parseContext).nullValue)), + Stmts.Assume( + if (guard == null) True() else AbstractExprs.Neq( + guard.expression, + CComplexType.getType(guard.expression, parseContext).nullValue + ) + ), choiceType = ChoiceType.MAIN_PATH, metadata = if (guard == null) getMetadata(statement) else getMetadata(guard) ) @@ -519,30 +600,42 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo xcfaEdge = XcfaEdge(lastTest, endInit, assume, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) val assume1 = StmtLabel( - Stmts.Assume(if (guard == null) False() else AbstractExprs.Eq(guard.expression, - CComplexType.getType(guard.expression, parseContext).nullValue)), + Stmts.Assume( + if (guard == null) False() else AbstractExprs.Eq( + guard.expression, + CComplexType.getType(guard.expression, parseContext).nullValue + ) + ), choiceType = ChoiceType.ALTERNATIVE_PATH, metadata = if (guard == null) getMetadata(statement) else getMetadata(guard) ) xcfaEdge = XcfaEdge(lastTest, outerLastTest, assume1, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) - val innerLastGuard = if (guard == null) endInit else buildPostStatement(guard, - ParamPack(builder, endInit, endLoc, startIncrement, returnLoc)) - val lastBody = if (body == null) innerLastGuard else body.accept(this, - ParamPack(builder, innerLastGuard, endLoc, startIncrement, returnLoc)) + val innerLastGuard = if (guard == null) endInit else buildPostStatement( + guard, + ParamPack(builder, endInit, endLoc, startIncrement, returnLoc) + ) + val lastBody = if (body == null) innerLastGuard else body.accept( + this, + ParamPack(builder, innerLastGuard, endLoc, startIncrement, returnLoc) + ) xcfaEdge = XcfaEdge(lastBody, startIncrement, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) if (increment != null) { - val lastIncrement = increment.accept(this, - ParamPack(builder, startIncrement, null, null, returnLoc)) + val lastIncrement = increment.accept( + this, + ParamPack(builder, startIncrement, null, null, returnLoc) + ) xcfaEdge = XcfaEdge(lastIncrement, lastInit, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) } else { xcfaEdge = XcfaEdge(startIncrement, lastInit, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) } - val outerLastGuard = if (guard == null) outerLastTest else buildPostStatement(guard, - ParamPack(builder, outerLastTest, endLoc, startIncrement, returnLoc)) + val outerLastGuard = if (guard == null) outerLastTest else buildPostStatement( + guard, + ParamPack(builder, outerLastTest, endLoc, startIncrement, returnLoc) + ) xcfaEdge = XcfaEdge(outerLastGuard, endLoc, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) return endLoc @@ -558,11 +651,14 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo builder.addLoc(initLoc) var edge: XcfaEdge = XcfaEdge(lastLoc, initLoc, metadata = getMetadata(statement)) builder.addEdge(edge) - edge = XcfaEdge(initLoc, - getLoc(builder, statement.label, metadata = getMetadata(statement))) + edge = XcfaEdge( + initLoc, + getLoc(builder, statement.label, metadata = getMetadata(statement)) + ) builder.addLoc(getLoc(builder, statement.label, metadata = getMetadata(statement))) val unreachableLoc: XcfaLocation = XcfaLocation( - "Unreachable" + XcfaLocation.uniqueCounter(), metadata = getMetadata(statement)) + "Unreachable" + XcfaLocation.uniqueCounter(), metadata = getMetadata(statement) + ) builder.addLoc(unreachableLoc) builder.addEdge(edge) return unreachableLoc @@ -587,33 +683,51 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo builder.addLoc(initLoc) var xcfaEdge: XcfaEdge = XcfaEdge(lastLoc, initLoc, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) - val endGuard = buildWithoutPostStatement(guard, - ParamPack(builder, initLoc, breakLoc, continueLoc, returnLoc)) + val endGuard = buildWithoutPostStatement( + guard, + ParamPack(builder, initLoc, breakLoc, continueLoc, returnLoc) + ) val assume = StmtLabel( - Stmts.Assume(AbstractExprs.Neq(guard.expression, - CComplexType.getType(guard.expression, parseContext).nullValue)), + Stmts.Assume( + AbstractExprs.Neq( + guard.expression, + CComplexType.getType(guard.expression, parseContext).nullValue + ) + ), choiceType = ChoiceType.MAIN_PATH, metadata = getMetadata(guard) ) xcfaEdge = XcfaEdge(endGuard, mainBranch, assume, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) val assume1 = StmtLabel( - Stmts.Assume(AbstractExprs.Eq(guard.expression, - CComplexType.getType(guard.expression, parseContext).nullValue)), + Stmts.Assume( + AbstractExprs.Eq( + guard.expression, + CComplexType.getType(guard.expression, parseContext).nullValue + ) + ), choiceType = ChoiceType.ALTERNATIVE_PATH, metadata = getMetadata(guard) ) xcfaEdge = XcfaEdge(endGuard, elseBranch, assume1, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) - val mainAfterGuard = buildPostStatement(guard, - ParamPack(builder, mainBranch, breakLoc, continueLoc, returnLoc)) - val mainEnd = body.accept(this, - ParamPack(builder, mainAfterGuard, breakLoc, continueLoc, returnLoc)) + val mainAfterGuard = buildPostStatement( + guard, + ParamPack(builder, mainBranch, breakLoc, continueLoc, returnLoc) + ) + val mainEnd = body.accept( + this, + ParamPack(builder, mainAfterGuard, breakLoc, continueLoc, returnLoc) + ) if (elseStatement != null) { - val elseAfterGuard = buildPostStatement(guard, - ParamPack(builder, elseBranch, breakLoc, continueLoc, returnLoc)) - val elseEnd = elseStatement.accept(this, - ParamPack(builder, elseAfterGuard, breakLoc, continueLoc, returnLoc)) + val elseAfterGuard = buildPostStatement( + guard, + ParamPack(builder, elseBranch, breakLoc, continueLoc, returnLoc) + ) + val elseEnd = elseStatement.accept( + this, + ParamPack(builder, elseAfterGuard, breakLoc, continueLoc, returnLoc) + ) xcfaEdge = XcfaEdge(elseEnd, endLoc, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) } else { @@ -649,16 +763,24 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo builder.addLoc(initLoc) val xcfaEdge: XcfaEdge = XcfaEdge(lastLoc, initLoc, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) - val endExpr = expr?.accept(this, - ParamPack(builder, initLoc, breakLoc, continueLoc, returnLoc)) ?: initLoc + val endExpr = expr?.accept( + this, + ParamPack(builder, initLoc, breakLoc, continueLoc, returnLoc) + ) ?: initLoc val endLoc = getAnonymousLoc(builder, metadata = getMetadata(statement)) builder.addLoc(endLoc) val key: VarDecl<*> = builder.getParams()[0].first check(returnLoc != null) val type = CComplexType.getType(key.ref, parseContext) - val edge = XcfaEdge(endExpr, returnLoc, StmtLabel(Stmts.Assign(cast(key, key.type), - cast(type.castTo(expr?.expression ?: type.nullValue), key.type)), - metadata = getMetadata(statement)), metadata = getMetadata(statement)) + val edge = XcfaEdge( + endExpr, returnLoc, StmtLabel( + Stmts.Assign( + cast(key, key.type), + cast(type.castTo(expr?.expression ?: type.nullValue), key.type) + ), + metadata = getMetadata(statement) + ), metadata = getMetadata(statement) + ) builder.addEdge(edge) return endLoc } @@ -677,14 +799,18 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo builder.addLoc(endLoc) val edge: XcfaEdge = XcfaEdge(lastLoc, initLoc, metadata = getMetadata(statement)) builder.addEdge(edge) - val endInit = buildWithoutPostStatement(testValue, - ParamPack(builder, initLoc, breakLoc, continueLoc, returnLoc)) + val endInit = buildWithoutPostStatement( + testValue, + ParamPack(builder, initLoc, breakLoc, continueLoc, returnLoc) + ) Preconditions.checkState(body is CCompound, "Switch body has to be a CompoundStatement!") var defaultExpr: Expr? = True() for (cStatement in (body as CCompound).getcStatementList()) { if (cStatement is CCase) { - defaultExpr = BoolExprs.And(defaultExpr, - AbstractExprs.Neq(testValue.expression, cStatement.expr.expression)) + defaultExpr = BoolExprs.And( + defaultExpr, + AbstractExprs.Neq(testValue.expression, cStatement.expr.expression) + ) } } var lastLocation: XcfaLocation? = null @@ -697,19 +823,24 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo builder.addEdge(xcfaEdge) } if (cStatement is CCase) { - val afterGuard = buildPostStatement(testValue, - ParamPack(builder, checkNotNull(endInit), breakLoc, continueLoc, returnLoc)) + val afterGuard = buildPostStatement( + testValue, + ParamPack(builder, checkNotNull(endInit), breakLoc, continueLoc, returnLoc) + ) val assume = StmtLabel( Stmts.Assume( - AbstractExprs.Eq(testValue.expression, cStatement.expr.expression)), + AbstractExprs.Eq(testValue.expression, cStatement.expr.expression) + ), choiceType = ChoiceType.MAIN_PATH, metadata = getMetadata(testValue) ) xcfaEdge = XcfaEdge(afterGuard, location, assume, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) } else if (cStatement is CDefault) { - val afterGuard = buildPostStatement(testValue, - ParamPack(builder, endInit!!, breakLoc, continueLoc, returnLoc)) + val afterGuard = buildPostStatement( + testValue, + ParamPack(builder, endInit!!, breakLoc, continueLoc, returnLoc) + ) val assume = StmtLabel( Stmts.Assume(defaultExpr), choiceType = ChoiceType.MAIN_PATH, // TODO: is this what validators expect? @@ -718,12 +849,16 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo xcfaEdge = XcfaEdge(afterGuard, location, assume, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) } - lastLocation = cStatement.accept(this, - ParamPack(builder, location, endLoc, continueLoc, returnLoc)) + lastLocation = cStatement.accept( + this, + ParamPack(builder, location, endLoc, continueLoc, returnLoc) + ) } if (lastLocation != null) { - val xcfaEdge: XcfaEdge = XcfaEdge(lastLocation, endLoc, - metadata = getMetadata(statement)) + val xcfaEdge: XcfaEdge = XcfaEdge( + lastLocation, endLoc, + metadata = getMetadata(statement) + ) builder.addEdge(xcfaEdge) } return endLoc @@ -749,46 +884,66 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo for (i in 0 until if (UNROLL_COUNT == 0) 1 else UNROLL_COUNT) { val innerLoop = getAnonymousLoc(builder, metadata = getMetadata(statement)) builder.addLoc(innerLoop) - val testEndLoc = buildWithoutPostStatement(guard, - ParamPack(builder, initLoc, null, null, returnLoc)) + val testEndLoc = buildWithoutPostStatement( + guard, + ParamPack(builder, initLoc, null, null, returnLoc) + ) if (UNROLL_COUNT > 0) { initLoc = getAnonymousLoc(builder, metadata = getMetadata(statement)) builder.addLoc(initLoc) } val assume = StmtLabel( - Stmts.Assume(AbstractExprs.Neq(guard.expression, - CComplexType.getType(guard.expression, parseContext).nullValue)), + Stmts.Assume( + AbstractExprs.Neq( + guard.expression, + CComplexType.getType(guard.expression, parseContext).nullValue + ) + ), choiceType = ChoiceType.MAIN_PATH, metadata = getMetadata(guard) ) xcfaEdge = XcfaEdge(testEndLoc, innerLoop, assume, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) val assume1 = StmtLabel( - Stmts.Assume(AbstractExprs.Eq(guard.expression, - CComplexType.getType(guard.expression, parseContext).nullValue)), + Stmts.Assume( + AbstractExprs.Eq( + guard.expression, + CComplexType.getType(guard.expression, parseContext).nullValue + ) + ), choiceType = ChoiceType.ALTERNATIVE_PATH, metadata = getMetadata(statement) ) - xcfaEdge = XcfaEdge(testEndLoc, outerBeforeGuard, assume1, - metadata = getMetadata(statement)) + xcfaEdge = XcfaEdge( + testEndLoc, outerBeforeGuard, assume1, + metadata = getMetadata(statement) + ) builder.addEdge(xcfaEdge) - val lastGuard = buildPostStatement(guard, - ParamPack(builder, innerLoop, endLoc, initLoc, returnLoc)) - val lastBody = body.accept(this, - ParamPack(builder, lastGuard, endLoc, initLoc, returnLoc)) + val lastGuard = buildPostStatement( + guard, + ParamPack(builder, innerLoop, endLoc, initLoc, returnLoc) + ) + val lastBody = body.accept( + this, + ParamPack(builder, lastGuard, endLoc, initLoc, returnLoc) + ) xcfaEdge = XcfaEdge(lastBody, initLoc, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) } - val outerLastGuard = buildPostStatement(guard, - ParamPack(builder, outerBeforeGuard, null, null, null)) + val outerLastGuard = buildPostStatement( + guard, + ParamPack(builder, outerBeforeGuard, null, null, null) + ) xcfaEdge = XcfaEdge(outerLastGuard, endLoc, metadata = getMetadata(statement)) builder.addEdge(xcfaEdge) return endLoc } private fun buildWithoutPostStatement(cStatement: CStatement, param: ParamPack): XcfaLocation { - Preconditions.checkState(cStatement is CCompound, - "Currently only CCompounds have pre- and post statements!") + Preconditions.checkState( + cStatement is CCompound, + "Currently only CCompounds have pre- and post statements!" + ) val statement = cStatement as CCompound val builder: XcfaProcedureBuilder = param.builder var lastLoc = param.lastLoc @@ -803,28 +958,38 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo val edge = XcfaEdge(lastLoc, initLoc, metadata = getMetadata(statement)) builder.addEdge(edge) lastLoc = initLoc - if (preStatements != null) lastLoc = preStatements.accept(this, - ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc)) + if (preStatements != null) lastLoc = preStatements.accept( + this, + ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc) + ) for (i in 0 until cStatementList.size - 1) { val stmt = cStatementList[i] - if (stmt != null) lastLoc = stmt.accept(this, - ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc)) + if (stmt != null) lastLoc = stmt.accept( + this, + ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc) + ) } if (cStatementList.size == 0) return lastLoc val lastStatement = cStatementList[cStatementList.size - 1] lastLoc = if (postStatements == null) { - buildWithoutPostStatement(lastStatement, - ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc)) + buildWithoutPostStatement( + lastStatement, + ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc) + ) } else { - lastStatement.accept(this, - ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc)) + lastStatement.accept( + this, + ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc) + ) } return lastLoc } private fun buildPostStatement(cStatement: CStatement, param: ParamPack): XcfaLocation { - Preconditions.checkState(cStatement is CCompound, - "Currently only CCompounds have pre- and post statements!") + Preconditions.checkState( + cStatement is CCompound, + "Currently only CCompounds have pre- and post statements!" + ) val statement = cStatement as CCompound val builder: XcfaProcedureBuilder = param.builder var lastLoc = param.lastLoc @@ -834,15 +999,20 @@ class FrontendXcfaBuilder(val parseContext: ParseContext, val checkOverflow: Boo val preStatements = statement.preStatements val postStatements = statement.postStatements val cStatementList = statement.getcStatementList() - lastLoc = if (postStatements != null) postStatements.accept(this, - ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc)) else buildPostStatement( + lastLoc = if (postStatements != null) postStatements.accept( + this, + ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc) + ) else buildPostStatement( cStatementList[cStatementList.size - 1], - ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc)) + ParamPack(builder, lastLoc, breakLoc, continueLoc, returnLoc) + ) return lastLoc } - class ParamPack(builder: XcfaProcedureBuilder, lastLoc: XcfaLocation, breakLoc: XcfaLocation?, - continueLoc: XcfaLocation?, returnLoc: XcfaLocation?) { + class ParamPack( + builder: XcfaProcedureBuilder, lastLoc: XcfaLocation, breakLoc: XcfaLocation?, + continueLoc: XcfaLocation?, returnLoc: XcfaLocation? + ) { val builder: XcfaProcedureBuilder val lastLoc: XcfaLocation diff --git a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/Utils.kt b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/Utils.kt index 40d06bd9c1..d1faac52da 100644 --- a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/Utils.kt +++ b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/Utils.kt @@ -30,8 +30,10 @@ import org.antlr.v4.runtime.CharStreams import org.antlr.v4.runtime.CommonTokenStream import java.io.InputStream -fun getXcfaFromC(stream: InputStream, parseContext: ParseContext, collectStatistics: Boolean, - checkOverflow: Boolean, warningLogger: Logger): Triple?> { +fun getXcfaFromC( + stream: InputStream, parseContext: ParseContext, collectStatistics: Boolean, + checkOverflow: Boolean, warningLogger: Logger +): Triple?> { val input = CharStreams.fromStream(stream) val lexer = CLexer(input) val tokens = CommonTokenStream(lexer) diff --git a/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/CatVisitor.kt b/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/CatVisitor.kt index 6fc85e623d..861ba376b5 100644 --- a/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/CatVisitor.kt +++ b/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/CatVisitor.kt @@ -238,7 +238,8 @@ class CatVisitor(file: File) : CatBaseVisitor() { override fun visitExprComplement(ctx: ExprComplementContext): GraphPattern { val rel = ctx.e.accept(this) return if (rel is EdgePattern) Complement(rel) else if (rel is NodePattern) ComplementNode(rel) else error( - "Mismatched types") + "Mismatched types" + ) } override fun visitExprInverse(ctx: ExprInverseContext): GraphPattern { diff --git a/subprojects/xcfa/llvm2xcfa/build.gradle.kts b/subprojects/xcfa/llvm2xcfa/build.gradle.kts index 1888b50a11..874d563124 100644 --- a/subprojects/xcfa/llvm2xcfa/build.gradle.kts +++ b/subprojects/xcfa/llvm2xcfa/build.gradle.kts @@ -36,7 +36,9 @@ tasks.test { } val linkTask = task.first() dependsOn(linkTask) - systemProperty("java.library.path", - linkTask.linkedFile.get().asFile.parent + ":/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib") + systemProperty( + "java.library.path", + linkTask.linkedFile.get().asFile.parent + ":/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib" + ) } } diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/Utils.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/Utils.kt index cf5d298dab..4f9bbd7bee 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/Utils.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/Utils.kt @@ -52,7 +52,8 @@ private fun S.getState(varLookup: Map, VarDecl<*>>): is PredState -> PredState.of(preds.map { p -> p.changeVars(varLookup) }) is PtrState<*> -> PtrState(innerState.getState(varLookup)) else -> throw NotImplementedError( - "Generalizing variable instances is not implemented for data states that are not explicit or predicate.") + "Generalizing variable instances is not implemented for data states that are not explicit or predicate." + ) } as S class LazyDelegate(val getProperty: T.() -> P) { diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAbstractor.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAbstractor.kt index d17f15fda1..0e2d35e29c 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAbstractor.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAbstractor.kt @@ -122,13 +122,14 @@ class XcfaAbstractor( companion object { fun builder( - argBuilder: ArgBuilder): BasicAbstractor.Builder { + argBuilder: ArgBuilder + ): BasicAbstractor.Builder { return Builder(argBuilder) } } - class Builder(argBuilder: ArgBuilder) - : BasicAbstractor.Builder(argBuilder) { + class Builder(argBuilder: ArgBuilder) : + BasicAbstractor.Builder(argBuilder) { override fun build(): BasicAbstractor { return XcfaAbstractor(argBuilder, projection, waitlist, stopCriterion, logger) diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAction.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAction.kt index 82a8e65178..798886422e 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAction.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAction.kt @@ -24,8 +24,10 @@ import hu.bme.mit.theta.xcfa.passes.flatten data class XcfaAction @JvmOverloads -constructor(val pid: Int, val edge: XcfaEdge, private val lastWrites: WriteTriples = emptyMap(), - private val nextCnt: Int = 0) : +constructor( + val pid: Int, val edge: XcfaEdge, private val lastWrites: WriteTriples = emptyMap(), + private val nextCnt: Int = 0 +) : PtrAction(lastWrites, nextCnt) { val source: XcfaLocation = edge.source @@ -33,12 +35,14 @@ constructor(val pid: Int, val edge: XcfaEdge, private val lastWrites: WriteTripl val label: XcfaLabel = edge.label private val stmts: List = label.toStmt().flatten() - constructor(pid: Int, + constructor( + pid: Int, source: XcfaLocation, target: XcfaLocation, label: XcfaLabel = NopLabel, lastWrites: WriteTriples = emptyMap(), - nextCnt: Int = 0) : + nextCnt: Int = 0 + ) : this(pid, XcfaEdge(source, target, label), lastWrites, nextCnt) override val stmtList: List diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAnalysis.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAnalysis.kt index 64bd2e3d62..d630b6ac06 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAnalysis.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaAnalysis.kt @@ -60,7 +60,8 @@ open class XcfaAnalysis( ) : Analysis>, XcfaAction, XcfaPrec

> { init { - ConeOfInfluence.coreTransFunc = transFunc as TransFunc>, XcfaAction, XcfaPrec> + ConeOfInfluence.coreTransFunc = + transFunc as TransFunc>, XcfaAction, XcfaPrec> coreTransFunc = ConeOfInfluence.transFunc as TransFunc>, XcfaAction, XcfaPrec

> } @@ -74,14 +75,28 @@ private var tempCnt: Int = 0 fun getCoreXcfaLts() = LTS>, XcfaAction> { s -> s.processes.map { proc -> if (proc.value.locs.peek().final) { - listOf(XcfaAction(proc.key, - XcfaEdge(proc.value.locs.peek(), proc.value.locs.peek(), SequenceLabel(listOf( - proc.value.paramStmts.peek().second, - ReturnLabel(proc.value.returnStmts.peek()), - ))), nextCnt = s.sGlobal.nextCnt)) + listOf( + XcfaAction( + proc.key, + XcfaEdge( + proc.value.locs.peek(), proc.value.locs.peek(), SequenceLabel( + listOf( + proc.value.paramStmts.peek().second, + ReturnLabel(proc.value.returnStmts.peek()), + ) + ) + ), nextCnt = s.sGlobal.nextCnt + ) + ) } else if (!proc.value.paramsInitialized) { - listOf(XcfaAction(proc.key, XcfaEdge(proc.value.locs.peek(), proc.value.locs.peek(), - proc.value.paramStmts.peek().first), nextCnt = s.sGlobal.nextCnt)) + listOf( + XcfaAction( + proc.key, XcfaEdge( + proc.value.locs.peek(), proc.value.locs.peek(), + proc.value.paramStmts.peek().first + ), nextCnt = s.sGlobal.nextCnt + ) + ) } else { proc.value.locs.peek().outgoingEdges.map { edge -> val newLabel = edge.label.changeVars(proc.value.varLookup.peek()) @@ -95,15 +110,21 @@ fun getCoreXcfaLts() = LTS>, XcfaAction> { SequenceLabel(listOf(procedure.params.withIndex() .filter { it.value.second != ParamDirection.OUT }.map { iVal -> val originalVar = iVal.value.first - val tempVar = Var("tmp${tempCnt++}_" + originalVar.name, - originalVar.type) + val tempVar = Var( + "tmp${tempCnt++}_" + originalVar.name, + originalVar.type + ) lookup[originalVar] = tempVar StmtLabel( Stmts.Assign( TypeUtils.cast(tempVar, tempVar.type), - TypeUtils.cast(label.params[iVal.index], tempVar.type)), - metadata = label.metadata) - }, listOf(label.copy(tempLookup = lookup))).flatten()) + TypeUtils.cast(label.params[iVal.index], tempVar.type) + ), + metadata = label.metadata + ) + }, listOf(label.copy(tempLookup = lookup)) + ).flatten() + ) } else if (label is StartLabel) { val procedure = s.xcfa?.procedures?.find { proc -> proc.name == label.name } ?: error("No such method ${label.name}.") @@ -111,22 +132,28 @@ fun getCoreXcfaLts() = LTS>, XcfaAction> { SequenceLabel(listOf(procedure.params.withIndex() .filter { it.value.second != ParamDirection.OUT }.mapNotNull { iVal -> val originalVar = iVal.value.first - val tempVar = Var("tmp${tempCnt++}_" + originalVar.name, - originalVar.type) + val tempVar = Var( + "tmp${tempCnt++}_" + originalVar.name, + originalVar.type + ) lookup[originalVar] = tempVar val trial = Try.attempt { StmtLabel( Stmts.Assign( TypeUtils.cast(tempVar, tempVar.type), - TypeUtils.cast(label.params[iVal.index], tempVar.type)), - metadata = label.metadata) + TypeUtils.cast(label.params[iVal.index], tempVar.type) + ), + metadata = label.metadata + ) } if (trial.isSuccess) { trial.asSuccess().value } else { null } - }, listOf(label.copy(tempLookup = lookup))).flatten()) + }, listOf(label.copy(tempLookup = lookup)) + ).flatten() + ) } else label }) XcfaAction(proc.key, edge.withLabel(newNewLabel), nextCnt = s.sGlobal.nextCnt) @@ -152,7 +179,8 @@ enum class ErrorDetection { } fun getXcfaErrorPredicate( - errorDetection: ErrorDetection): Predicate>> = when (errorDetection) { + errorDetection: ErrorDetection +): Predicate>> = when (errorDetection) { ErrorDetection.ERROR_LOCATION -> Predicate>> { s -> s.processes.any { it.value.locs.peek().error } } @@ -185,11 +213,14 @@ fun getXcfaErrorPredicate( fun getPartialOrder(partialOrd: PartialOrd>) = PartialOrd>> { s1, s2 -> s1.processes == s2.processes && s1.bottom == s2.bottom && s1.mutexes == s2.mutexes && partialOrd.isLeq( - s1.sGlobal, s2.sGlobal) + s1.sGlobal, s2.sGlobal + ) } -private fun stackIsLeq(s1: XcfaState>, - s2: XcfaState>) = s2.processes.keys.all { pid -> +private fun stackIsLeq( + s1: XcfaState>, + s2: XcfaState> +) = s2.processes.keys.all { pid -> s1.processes[pid]?.let { ps1 -> val ps2 = s2.processes.getValue(pid) ps1.locs.peek() == ps2.locs.peek() && ps1.paramsInitialized && ps2.paramsInitialized @@ -198,15 +229,18 @@ private fun stackIsLeq(s1: XcfaState>, fun getStackPartialOrder(partialOrd: PartialOrd>) = PartialOrd>> { s1, s2 -> - s1.processes.size == s2.processes.size && stackIsLeq(s1, - s2) && s1.bottom == s2.bottom && s1.mutexes == s2.mutexes + s1.processes.size == s2.processes.size && stackIsLeq( + s1, + s2 + ) && s1.bottom == s2.bottom && s1.mutexes == s2.mutexes && partialOrd.isLeq(s1.withGeneralizedVars(), s2.withGeneralizedVars()) } private fun >, P : XcfaPrec> getXcfaArgBuilder( analysis: Analysis, lts: LTS>, XcfaAction>, - errorDetection: ErrorDetection) + errorDetection: ErrorDetection +) : ArgBuilder = ArgBuilder.create( lts, @@ -233,13 +267,19 @@ fun >, P : XcfaPrec> getXcfa /// EXPL -private fun getExplXcfaInitFunc(xcfa: XCFA, - solver: Solver): (XcfaPrec>) -> List>> { +private fun getExplXcfaInitFunc( + xcfa: XCFA, + solver: Solver +): (XcfaPrec>) -> List>> { val processInitState = xcfa.initProcedures.mapIndexed { i, it -> val initLocStack: LinkedList = LinkedList() initLocStack.add(it.first.initLoc) - Pair(i, XcfaProcessState(initLocStack, prefix = "T$i", - varLookup = LinkedList(listOf(createLookup(it.first, "T$i", ""))))) + Pair( + i, XcfaProcessState( + initLocStack, prefix = "T$i", + varLookup = LinkedList(listOf(createLookup(it.first, "T$i", ""))) + ) + ) }.toMap() return { p -> ExplInitFunc.create(solver, True()).getPtrInitFunc().getInitStates(p.p) @@ -248,19 +288,28 @@ private fun getExplXcfaInitFunc(xcfa: XCFA, } private fun getExplXcfaTransFunc(solver: Solver, maxEnum: Int, isHavoc: Boolean): - (XcfaState>, XcfaAction, XcfaPrec>) -> List>> { - val explTransFunc = (ExplStmtTransFunc.create(solver, - maxEnum) as TransFunc).getPtrTransFunc(isHavoc) + (XcfaState>, XcfaAction, XcfaPrec>) -> List>> { + val explTransFunc = (ExplStmtTransFunc.create( + solver, + maxEnum + ) as TransFunc).getPtrTransFunc(isHavoc) return { s, a, p -> val (newSt, newAct) = s.apply(a) - explTransFunc.getSuccStates(newSt.sGlobal, newAct, p.p.addVars( - listOf(s.processes.map { it.value.varLookup }.flatten(), - listOf(getTempLookup(a.label))).flatten())).map { newSt.withState(it) } + explTransFunc.getSuccStates( + newSt.sGlobal, newAct, p.p.addVars( + listOf( + s.processes.map { it.value.varLookup }.flatten(), + listOf(getTempLookup(a.label)) + ).flatten() + ) + ).map { newSt.withState(it) } } } -class ExplXcfaAnalysis(xcfa: XCFA, solver: Solver, maxEnum: Int, - partialOrd: PartialOrd>>, isHavoc: Boolean) : +class ExplXcfaAnalysis( + xcfa: XCFA, solver: Solver, maxEnum: Int, + partialOrd: PartialOrd>>, isHavoc: Boolean +) : XcfaAnalysis>( corePartialOrd = partialOrd, coreInitFunc = getExplXcfaInitFunc(xcfa, solver), @@ -269,13 +318,19 @@ class ExplXcfaAnalysis(xcfa: XCFA, solver: Solver, maxEnum: Int, /// PRED -private fun getPredXcfaInitFunc(xcfa: XCFA, - predAbstractor: PredAbstractor): (XcfaPrec>) -> List>> { +private fun getPredXcfaInitFunc( + xcfa: XCFA, + predAbstractor: PredAbstractor +): (XcfaPrec>) -> List>> { val processInitState = xcfa.initProcedures.mapIndexed { i, it -> val initLocStack: LinkedList = LinkedList() initLocStack.add(it.first.initLoc) - Pair(i, XcfaProcessState(initLocStack, prefix = "T$i", - varLookup = LinkedList(listOf(createLookup(it.first, "T$i", ""))))) + Pair( + i, XcfaProcessState( + initLocStack, prefix = "T$i", + varLookup = LinkedList(listOf(createLookup(it.first, "T$i", ""))) + ) + ) }.toMap() return { p -> PredInitFunc.create(predAbstractor, True()).getPtrInitFunc().getInitStates(p.p) @@ -284,9 +339,10 @@ private fun getPredXcfaInitFunc(xcfa: XCFA, } private fun getPredXcfaTransFunc(predAbstractor: PredAbstractors.PredAbstractor, isHavoc: Boolean): - (XcfaState>, XcfaAction, XcfaPrec>) -> List>> { + (XcfaState>, XcfaAction, XcfaPrec>) -> List>> { val predTransFunc = (PredTransFunc.create( - predAbstractor) as TransFunc).getPtrTransFunc(isHavoc) + predAbstractor + ) as TransFunc).getPtrTransFunc(isHavoc) return { s, a, p -> val (newSt, newAct) = s.apply(a) predTransFunc.getSuccStates(newSt.sGlobal, newAct, p.p.addVars( @@ -295,8 +351,10 @@ private fun getPredXcfaTransFunc(predAbstractor: PredAbstractors.PredAbstractor, } } -class PredXcfaAnalysis(xcfa: XCFA, solver: Solver, predAbstractor: PredAbstractor, - partialOrd: PartialOrd>>, isHavoc: Boolean) : +class PredXcfaAnalysis( + xcfa: XCFA, solver: Solver, predAbstractor: PredAbstractor, + partialOrd: PartialOrd>>, isHavoc: Boolean +) : XcfaAnalysis>( corePartialOrd = partialOrd, coreInitFunc = getPredXcfaInitFunc(xcfa, predAbstractor), diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaPrecRefiner.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaPrecRefiner.kt index 64e8984d4d..40cea2bc74 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaPrecRefiner.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaPrecRefiner.kt @@ -37,8 +37,10 @@ class XcfaPrecRefiner(refToPrec: Refuta private val refToPrec: RefutationToPrec, R> = Preconditions.checkNotNull(refToPrec) - override fun refine(prec: XcfaPrec>, trace: Trace, XcfaAction>, - refutation: R): XcfaPrec> { + override fun refine( + prec: XcfaPrec>, trace: Trace, XcfaAction>, + refutation: R + ): XcfaPrec> { Preconditions.checkNotNull(trace) Preconditions.checkNotNull(prec) Preconditions.checkNotNull(refutation) @@ -48,7 +50,8 @@ class XcfaPrecRefiner(refToPrec: Refuta it.foldVarLookup().map { Pair(it.value, it.key) } }.flatten().toMap() val reverseTempLookup = if (i > 0) getTempLookup( - trace.actions[i - 1].edge.label).entries.associateBy( + trace.actions[i - 1].edge.label + ).entries.associateBy( { it.value }) { it.key } else emptyMap() val precFromRef = refToPrec.toPrec(refutation, i).changeVars(reverseVarLookup + reverseTempLookup) runningPrec = refToPrec.join(runningPrec, precFromRef) @@ -83,10 +86,12 @@ fun

P.addVars(lookups: Collection, VarDecl<*>>>): P = else when (this) { is ExplPrec -> ExplPrec.of( - vars.map { lookups.map { lookup -> it.changeVars(lookup) } }.flatten()) as P + vars.map { lookups.map { lookup -> it.changeVars(lookup) } }.flatten() + ) as P is PredPrec -> PredPrec.of( - preds.map { lookups.map { lookup -> it.changeVars(lookup) } }.flatten()) as P + preds.map { lookups.map { lookup -> it.changeVars(lookup) } }.flatten() + ) as P is PtrPrec<*> -> PtrPrec(innerPrec.addVars(lookups)) as P diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaSingeExprTraceRefiner.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaSingeExprTraceRefiner.kt index ad0a385e5d..878e2a3964 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaSingeExprTraceRefiner.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaSingeExprTraceRefiner.kt @@ -72,15 +72,20 @@ class XcfaSingleExprTraceRefiner, states: List, actions: List): Triple, List, List>, a: A -> + Triple( + Pair(emptyMap(), 0), listOf(rawTrace.getState(0)), + listOf() + ) + ) { i: Int, (wTripleCnt: Pair, states: List, actions: List): Triple, List, List>, a: A -> val (wTriple, cnt) = wTripleCnt val newA = (a as XcfaAction).withLastWrites(wTriple, cnt) val newState = (rawTrace.getState(i + 1) as XcfaState>).let { it.withState(PtrState(it.sGlobal.innerState.patch(newA.nextWriteTriples()))) } - Triple(Pair(newA.nextWriteTriples(), newA.cnts.values.maxOrNull() ?: newA.inCnt), states + (newState as S), - actions + (newA as A)) + Triple( + Pair(newA.nextWriteTriples(), newA.cnts.values.maxOrNull() ?: newA.inCnt), states + (newState as S), + actions + (newA as A) + ) } val traceToConcretize = Trace.of(states, actions) diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaState.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaState.kt index 0054be37f2..c75bcefd8e 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaState.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaState.kt @@ -52,8 +52,10 @@ data class XcfaState @JvmOverloads constructor( fun apply(a: XcfaAction): Pair, XcfaAction> { val changes: MutableList<(XcfaState) -> XcfaState> = ArrayList() - if (mutexes[""] != null && mutexes[""] != a.pid) return Pair(copy(bottom = true), - a.withLabel(SequenceLabel(listOf(NopLabel)))) + if (mutexes[""] != null && mutexes[""] != a.pid) return Pair( + copy(bottom = true), + a.withLabel(SequenceLabel(listOf(NopLabel))) + ) val processState = processes[a.pid] checkNotNull(processState) @@ -101,12 +103,19 @@ data class XcfaState @JvmOverloads constructor( is InvokeLabel -> { val proc = xcfa?.procedures?.find { proc -> proc.name == it.name } ?: error( - "No such method ${it.name}.") + "No such method ${it.name}." + ) val returnStmt = SequenceLabel( proc.params.withIndex().filter { it.value.second != ParamDirection.IN }.map { iVal -> - StmtLabel(Assign(cast((it.params[iVal.index] as RefExpr<*>).decl as VarDecl<*>, - iVal.value.first.type), cast(iVal.value.first.ref, iVal.value.first.type)), - metadata = it.metadata) + StmtLabel( + Assign( + cast( + (it.params[iVal.index] as RefExpr<*>).decl as VarDecl<*>, + iVal.value.first.type + ), cast(iVal.value.first.ref, iVal.value.first.type) + ), + metadata = it.metadata + ) }) changes.add { state -> state.invokeFunction(a.pid, proc, returnStmt, proc.params.toMap(), it.tempLookup) @@ -161,20 +170,34 @@ data class XcfaState @JvmOverloads constructor( val pid = pidCnt++ val lookup = XcfaProcessState.createLookup(procedure, "T$pid", "") newThreadLookup[startLabel.pidVar] = pid - newProcesses[pid] = XcfaProcessState(LinkedList(listOf(procedure.initLoc)), prefix = "T$pid", + newProcesses[pid] = XcfaProcessState( + LinkedList(listOf(procedure.initLoc)), prefix = "T$pid", varLookup = LinkedList(listOf(lookup)), returnStmts = LinkedList(listOf(returnStmt)), - paramStmts = LinkedList(listOf(Pair( - /* init */ - SequenceLabel(paramList.filter { it.value != ParamDirection.OUT }.map { - StmtLabel(Assign(cast(it.key.changeVars(lookup), it.key.type), - cast(it.key.changeVars(tempLookup).ref, it.key.type))) - }), - /* deinit */ - SequenceLabel(paramList.filter { it.value != ParamDirection.IN }.map { - StmtLabel(Assign(cast(it.key.changeVars(tempLookup), it.key.type), - cast(it.key.changeVars(lookup).ref, it.key.type))) - }), - )))) + paramStmts = LinkedList( + listOf( + Pair( + /* init */ + SequenceLabel(paramList.filter { it.value != ParamDirection.OUT }.map { + StmtLabel( + Assign( + cast(it.key.changeVars(lookup), it.key.type), + cast(it.key.changeVars(tempLookup).ref, it.key.type) + ) + ) + }), + /* deinit */ + SequenceLabel(paramList.filter { it.value != ParamDirection.IN }.map { + StmtLabel( + Assign( + cast(it.key.changeVars(tempLookup), it.key.type), + cast(it.key.changeVars(lookup).ref, it.key.type) + ) + ) + }), + ) + ) + ) + ) val newMutexes = LinkedHashMap(mutexes) newMutexes["$pid"] = pid @@ -189,8 +212,10 @@ data class XcfaState @JvmOverloads constructor( return copy(processes = newProcesses, mutexes = newMutexes) } - private fun invokeFunction(pid: Int, proc: XcfaProcedure, returnStmt: XcfaLabel, - paramList: Map, ParamDirection>, tempLookup: Map, VarDecl<*>>): XcfaState { + private fun invokeFunction( + pid: Int, proc: XcfaProcedure, returnStmt: XcfaLabel, + paramList: Map, ParamDirection>, tempLookup: Map, VarDecl<*>> + ): XcfaState { val newProcesses: MutableMap = LinkedHashMap(processes) newProcesses[pid] = checkNotNull(processes[pid]?.enterFunction(proc, returnStmt, paramList, tempLookup)) return copy(processes = newProcesses) @@ -230,10 +255,12 @@ data class XcfaState @JvmOverloads constructor( } } -data class XcfaProcessState(val locs: LinkedList, val varLookup: LinkedList, VarDecl<*>>>, +data class XcfaProcessState( + val locs: LinkedList, val varLookup: LinkedList, VarDecl<*>>>, val returnStmts: LinkedList = LinkedList(listOf(NopLabel)), val paramStmts: LinkedList> = LinkedList(listOf(Pair(NopLabel, NopLabel))), - val paramsInitialized: Boolean = false, val prefix: String = "") { + val paramsInitialized: Boolean = false, val prefix: String = "" +) { internal var popped: XcfaLocation? = null // stores if the stack was popped due to abstract stack covering @@ -250,8 +277,10 @@ data class XcfaProcessState(val locs: LinkedList, val varLookup: L else -> "${locs.peek()!!} [${locs.size}], initilized=$paramsInitialized" } - fun enterFunction(xcfaProcedure: XcfaProcedure, returnStmt: XcfaLabel, paramList: Map, ParamDirection>, - tempLookup: Map, VarDecl<*>>): XcfaProcessState { + fun enterFunction( + xcfaProcedure: XcfaProcedure, returnStmt: XcfaLabel, paramList: Map, ParamDirection>, + tempLookup: Map, VarDecl<*>> + ): XcfaProcessState { val deque: LinkedList = LinkedList(locs) val varLookup: LinkedList, VarDecl<*>>> = LinkedList(varLookup) val returnStmts: LinkedList = LinkedList(returnStmts) @@ -260,20 +289,32 @@ data class XcfaProcessState(val locs: LinkedList, val varLookup: L val lookup = createLookup(xcfaProcedure, prefix, "P${procCnt++}") varLookup.push(lookup) returnStmts.push(returnStmt) - paramStmts.push(Pair( - /* init */ - SequenceLabel(paramList.filter { it.value != ParamDirection.OUT }.map { - StmtLabel(Assign(cast(it.key.changeVars(lookup), it.key.type), - cast(it.key.changeVars(tempLookup).ref, it.key.type))) - }), - /* deinit */ - SequenceLabel(paramList.filter { it.value != ParamDirection.IN }.map { - StmtLabel(Assign(cast(it.key.changeVars(tempLookup), it.key.type), - cast(it.key.changeVars(lookup).ref, it.key.type))) - }), - )) - return copy(locs = deque, varLookup = varLookup, returnStmts = returnStmts, paramStmts = paramStmts, - paramsInitialized = false) + paramStmts.push( + Pair( + /* init */ + SequenceLabel(paramList.filter { it.value != ParamDirection.OUT }.map { + StmtLabel( + Assign( + cast(it.key.changeVars(lookup), it.key.type), + cast(it.key.changeVars(tempLookup).ref, it.key.type) + ) + ) + }), + /* deinit */ + SequenceLabel(paramList.filter { it.value != ParamDirection.IN }.map { + StmtLabel( + Assign( + cast(it.key.changeVars(tempLookup), it.key.type), + cast(it.key.changeVars(lookup).ref, it.key.type) + ) + ) + }), + ) + ) + return copy( + locs = deque, varLookup = varLookup, returnStmts = returnStmts, paramStmts = paramStmts, + paramsInitialized = false + ) } fun exitFunction(): XcfaProcessState { @@ -308,8 +349,10 @@ data class XcfaProcessState(val locs: LinkedList, val varLookup: L companion object { - fun createLookup(proc: XcfaProcedure, threadPrefix: String, - procPrefix: String): Map, VarDecl<*>> = listOf(proc.params.map { it.first }, proc.vars).flatten() + fun createLookup( + proc: XcfaProcedure, threadPrefix: String, + procPrefix: String + ): Map, VarDecl<*>> = listOf(proc.params.map { it.first }, proc.vars).flatten() .associateWith { val sj = StringJoiner("::") if (threadPrefix != "") sj.add(threadPrefix) diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaStateAdapter.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaStateAdapter.kt index 30d7147c72..7b22edcdea 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaStateAdapter.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaStateAdapter.kt @@ -61,12 +61,14 @@ class XcfaStateAdapter(val gsonSupplier: () -> Gson, val stateTypeSupplier: () - val bottom: Boolean = gson.fromJson(reader, Boolean::class.java) reader.endObject() - return XcfaState(xcfa = null, + return XcfaState( + xcfa = null, processes = processes, sGlobal = sGlobal, mutexes = mutexes, threadLookup = threadLookup, - bottom = bottom) + bottom = bottom + ) } private fun initGson() { diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaToMonolithicExpr.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaToMonolithicExpr.kt index d91174ed82..882ecae465 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaToMonolithicExpr.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaToMonolithicExpr.kt @@ -52,12 +52,16 @@ fun XCFA.toMonolithicExpr(): MonolithicExpr { } val locVar = Decls.Var("__loc_", IntExprs.Int()) val tranList = proc.edges.map { (source, target, label): XcfaEdge -> - SequenceStmt.of(listOf( - AssumeStmt.of(Eq(locVar.ref, IntExprs.Int(map[source]!!))), - label.toStmt(), - AssignStmt.of(locVar, - IntExprs.Int(map[target]!!)) - )) + SequenceStmt.of( + listOf( + AssumeStmt.of(Eq(locVar.ref, IntExprs.Int(map[source]!!))), + label.toStmt(), + AssignStmt.of( + locVar, + IntExprs.Int(map[target]!!) + ) + ) + ) }.toList() val trans = NonDetStmt.of(tranList) val transUnfold = StmtUtils.toExpr(trans, VarIndexingFactory.indexing(0)) @@ -95,16 +99,24 @@ fun XCFA.valToState(val1: Valuation): XcfaState> { } return XcfaState( xcfa = this, - processes = mapOf(Pair(0, XcfaProcessState( - locs = LinkedList( - listOf(map[(valMap[valMap.keys.first { it.name == "__loc_" }] as IntLitExpr).value.toInt()])), - varLookup = LinkedList(), - ))), + processes = mapOf( + Pair( + 0, XcfaProcessState( + locs = LinkedList( + listOf(map[(valMap[valMap.keys.first { it.name == "__loc_" }] as IntLitExpr).value.toInt()]) + ), + varLookup = LinkedList(), + ) + ) + ), PtrState(ExplState.of( ImmutableValuation.from( val1.toMap() .filter { it.key.name != "__loc_" && !it.key.name.startsWith("__temp_") } - .map { Pair(Decls.Var("_" + "_" + it.key.name, it.key.type), it.value) }.toMap()))), + .map { Pair(Decls.Var("_" + "_" + it.key.name, it.key.type), it.value) }.toMap() + ) + ) + ), mutexes = emptyMap(), threadLookup = emptyMap(), bottom = false diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoiMultiThread.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoiMultiThread.kt index 0500b5d88b..6560d5ea82 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoiMultiThread.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoiMultiThread.kt @@ -90,8 +90,10 @@ class XcfaCoiMultiThread(xcfa: XCFA) : XcfaCoi(xcfa) { } } - private fun isObserved(action: A, procedures: MutableList, - multipleProcedures: Set): Boolean { + private fun isObserved( + action: A, procedures: MutableList, + multipleProcedures: Set + ): Boolean { val toVisit = edgeToProcedure.keys.filter { it.source == action.edge.source && it.target == action.edge.target }.toMutableList() diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcChecker.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcChecker.kt index 6ffa9bc1fb..69c695ca39 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcChecker.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcChecker.kt @@ -74,14 +74,16 @@ class XcfaOcChecker(xcfa: XCFA, decisionProcedure: OcDecisionProcedureType, priv private val rfs = mutableMapOf, MutableSet>() override fun check( - prec: XcfaPrec?): SafetyResult>, XcfaAction>> = let { + prec: XcfaPrec? + ): SafetyResult>, XcfaAction>> = let { if (xcfa.initProcedures.size > 1) error("Multiple entry points are not supported by OC checker.") logger.write(Logger.Level.MAINSTEP, "Adding constraints...\n") xcfa.initProcedures.forEach { processThread(Thread(it.first)) } addCrossThreadRelations() if (!addToSolver()) return@let SafetyResult.safe>, XcfaAction>>( - EmptyWitness.getInstance()) // no violations in the model + EmptyWitness.getInstance() + ) // no violations in the model logger.write(Logger.Level.MAINSTEP, "Start checking...\n") val status = ocChecker.check(events, pos, rfs) diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcTraceExtractor.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcTraceExtractor.kt index 05ff67fc9e..ad96ab9606 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcTraceExtractor.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcTraceExtractor.kt @@ -75,8 +75,10 @@ internal class XcfaOcTraceExtractor( val nextEdge = eventTrace.getOrNull(index + 1)?.edge if (nextEdge != lastEdge) { - extend(stateList.last(), event.pid, lastEdge.source, - explState.innerState)?.let { (midActions, midStates) -> + extend( + stateList.last(), event.pid, lastEdge.source, + explState.innerState + )?.let { (midActions, midStates) -> actionList.addAll(midActions) stateList.addAll(midStates) } @@ -86,9 +88,9 @@ internal class XcfaOcTraceExtractor( stateList.add(state.copy(processes = state.processes.toMutableMap().apply { put( event.pid, XcfaProcessState( - locs = LinkedList(listOf(lastEdge.target)), - varLookup = LinkedList(emptyList()) - ) + locs = LinkedList(listOf(lastEdge.target)), + varLookup = LinkedList(emptyList()) + ) ) }, sGlobal = explState, mutexes = state.mutexes.update(lastEdge, event.pid))) lastEdge = nextEdge ?: break @@ -96,8 +98,10 @@ internal class XcfaOcTraceExtractor( } if (!stateList.last().processes[violation.pid]!!.locs.peek().error) { - extend(stateList.last(), violation.pid, violation.errorLoc, - explState.innerState)?.let { (midActions, midStates) -> + extend( + stateList.last(), violation.pid, violation.errorLoc, + explState.innerState + )?.let { (midActions, midStates) -> actionList.addAll(midActions) stateList.addAll(midStates) } @@ -163,9 +167,9 @@ internal class XcfaOcTraceExtractor( currentState = currentState.copy(processes = currentState.processes.toMutableMap().apply { put( stepPid, XcfaProcessState( - locs = LinkedList(listOf(edge.target)), - varLookup = LinkedList(emptyList()) - ) + locs = LinkedList(listOf(edge.target)), + varLookup = LinkedList(emptyList()) + ) ) }, sGlobal = PtrState(explState), mutexes = currentState.mutexes.update(edge, stepPid)) states.add(currentState) diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaDporLts.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaDporLts.kt index d036c61ecd..f454fd25e9 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaDporLts.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaDporLts.kt @@ -200,7 +200,8 @@ open class XcfaDporLts(private val xcfa: XCFA) : LTS { val lastButOne = stack[stack.size - 2] val mutexNeverReleased = last.mutexLocks.containsKey( - "") && (last.state.mutexes.keys subtract lastButOne.state.mutexes.keys).contains( + "" + ) && (last.state.mutexes.keys subtract lastButOne.state.mutexes.keys).contains( "" ) if (last.node.explored.isEmpty() || mutexNeverReleased) { @@ -260,7 +261,9 @@ open class XcfaDporLts(private val xcfa: XCFA) : LTS { val action = node.inEdge.get().action if (relevantProcesses.contains(action.pid)) { if (newLastDependents.containsKey(action.pid) && index <= checkNotNull( - newLastDependents[action.pid])) { + newLastDependents[action.pid] + ) + ) { // there is an action a' such that action -> a' -> newaction (->: happens-before) relevantProcesses.remove(action.pid) } else if (dependent(newaction, action)) { diff --git a/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaExplAnalysisTest.kt b/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaExplAnalysisTest.kt index b4aa758303..8e01612ffa 100644 --- a/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaExplAnalysisTest.kt +++ b/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaExplAnalysisTest.kt @@ -82,23 +82,30 @@ class XcfaExplAnalysisTest { val lts = getXcfaLts() - val abstractor = getXcfaAbstractor(analysis, + val abstractor = getXcfaAbstractor( + analysis, PriorityWaitlist.create( - ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs())), + ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs()) + ), StopCriterions.firstCex>, XcfaAction>(), ConsoleLogger(Logger.Level.DETAIL), lts, - ErrorDetection.ERROR_LOCATION) as Abstractor>, XcfaAction, XcfaPrec>> + ErrorDetection.ERROR_LOCATION + ) as Abstractor>, XcfaAction, XcfaPrec>> val precRefiner = XcfaPrecRefiner>, ExplPrec, ItpRefutation>( - ItpRefToPtrPrec(ItpRefToExplPrec())) + ItpRefToPtrPrec(ItpRefToExplPrec()) + ) val refiner = XcfaSingleExprTraceRefiner.create( - ExprTraceBwBinItpChecker.create(BoolExprs.True(), BoolExprs.True(), - Z3LegacySolverFactory.getInstance().createItpSolver()), + ExprTraceBwBinItpChecker.create( + BoolExprs.True(), BoolExprs.True(), + Z3LegacySolverFactory.getInstance().createItpSolver() + ), precRefiner, PruneStrategy.FULL, - NullLogger.getInstance()) as Refiner>, XcfaAction, XcfaPrec>> + NullLogger.getInstance() + ) as Refiner>, XcfaAction, XcfaPrec>> val cegarChecker = CegarChecker.create(abstractor, refiner) @@ -127,23 +134,30 @@ class XcfaExplAnalysisTest { val lts = XcfaSporLts(xcfa) - val abstractor = getXcfaAbstractor(analysis, + val abstractor = getXcfaAbstractor( + analysis, PriorityWaitlist.create( - ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs())), + ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs()) + ), StopCriterions.firstCex>, XcfaAction>(), ConsoleLogger(Logger.Level.DETAIL), lts, - ErrorDetection.ERROR_LOCATION) as Abstractor>, XcfaAction, XcfaPrec>> + ErrorDetection.ERROR_LOCATION + ) as Abstractor>, XcfaAction, XcfaPrec>> val precRefiner = XcfaPrecRefiner>, ExplPrec, ItpRefutation>( - ItpRefToPtrPrec(ItpRefToExplPrec())) + ItpRefToPtrPrec(ItpRefToExplPrec()) + ) val refiner = XcfaSingleExprTraceRefiner.create( - ExprTraceBwBinItpChecker.create(BoolExprs.True(), BoolExprs.True(), - Z3LegacySolverFactory.getInstance().createItpSolver()), + ExprTraceBwBinItpChecker.create( + BoolExprs.True(), BoolExprs.True(), + Z3LegacySolverFactory.getInstance().createItpSolver() + ), precRefiner, PruneStrategy.FULL, - NullLogger.getInstance()) as Refiner>, XcfaAction, XcfaPrec>> + NullLogger.getInstance() + ) as Refiner>, XcfaAction, XcfaPrec>> val cegarChecker = CegarChecker.create(abstractor, refiner) @@ -173,23 +187,30 @@ class XcfaExplAnalysisTest { val lts = XcfaDporLts(xcfa) - val abstractor = getXcfaAbstractor(analysis, + val abstractor = getXcfaAbstractor( + analysis, lts.waitlist, StopCriterions.firstCex>, XcfaAction>(), ConsoleLogger(Logger.Level.DETAIL), lts, - ErrorDetection.ERROR_LOCATION) as Abstractor>, XcfaAction, XcfaPrec>> + ErrorDetection.ERROR_LOCATION + ) as Abstractor>, XcfaAction, XcfaPrec>> val precRefiner = XcfaPrecRefiner>, ExplPrec, ItpRefutation>( - ItpRefToPtrPrec(ItpRefToExplPrec())) + ItpRefToPtrPrec(ItpRefToExplPrec()) + ) val refiner = XcfaSingleExprTraceRefiner.create( - ExprTraceBwBinItpChecker.create(BoolExprs.True(), BoolExprs.True(), - Z3LegacySolverFactory.getInstance().createItpSolver()), + ExprTraceBwBinItpChecker.create( + BoolExprs.True(), BoolExprs.True(), + Z3LegacySolverFactory.getInstance().createItpSolver() + ), precRefiner, PruneStrategy.FULL, ConsoleLogger( - Logger.Level.DETAIL)) as Refiner>, XcfaAction, XcfaPrec>> + Logger.Level.DETAIL + ) + ) as Refiner>, XcfaAction, XcfaPrec>> val cegarChecker = CegarChecker.create(abstractor, refiner) @@ -218,24 +239,31 @@ class XcfaExplAnalysisTest { val lts = XcfaAasporLts(xcfa, mutableMapOf()) - val abstractor = getXcfaAbstractor(analysis, + val abstractor = getXcfaAbstractor( + analysis, PriorityWaitlist.create( - ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs())), + ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs()) + ), StopCriterions.firstCex>, XcfaAction>(), ConsoleLogger(Logger.Level.DETAIL), lts, - ErrorDetection.ERROR_LOCATION) as Abstractor>, XcfaAction, XcfaPrec>> + ErrorDetection.ERROR_LOCATION + ) as Abstractor>, XcfaAction, XcfaPrec>> val precRefiner = XcfaPrecRefiner, ExplPrec, ItpRefutation>( - ItpRefToPtrPrec(ItpRefToExplPrec())) + ItpRefToPtrPrec(ItpRefToExplPrec()) + ) val atomicNodePruner = AtomicNodePruner>, XcfaAction>() val refiner = XcfaSingleExprTraceRefiner.create( - ExprTraceBwBinItpChecker.create(BoolExprs.True(), BoolExprs.True(), - Z3LegacySolverFactory.getInstance().createItpSolver()), + ExprTraceBwBinItpChecker.create( + BoolExprs.True(), BoolExprs.True(), + Z3LegacySolverFactory.getInstance().createItpSolver() + ), precRefiner, PruneStrategy.FULL, NullLogger.getInstance(), - atomicNodePruner) as Refiner>, XcfaAction, XcfaPrec>> + atomicNodePruner + ) as Refiner>, XcfaAction, XcfaPrec>> val cegarChecker = CegarChecker.create(abstractor, AasporRefiner.create(refiner, PruneStrategy.FULL, mutableMapOf())) @@ -265,21 +293,26 @@ class XcfaExplAnalysisTest { val lts = XcfaAadporLts(xcfa) - val abstractor = getXcfaAbstractor(analysis, + val abstractor = getXcfaAbstractor( + analysis, lts.waitlist, StopCriterions.firstCex>, XcfaAction>(), ConsoleLogger(Logger.Level.DETAIL), lts, - ErrorDetection.ERROR_LOCATION) as Abstractor>, XcfaAction, XcfaPrec>> + ErrorDetection.ERROR_LOCATION + ) as Abstractor>, XcfaAction, XcfaPrec>> val precRefiner = XcfaPrecRefiner(ItpRefToPtrPrec(ItpRefToExplPrec())) val refiner = XcfaSingleExprTraceRefiner.create( - ExprTraceBwBinItpChecker.create(BoolExprs.True(), BoolExprs.True(), - Z3LegacySolverFactory.getInstance().createItpSolver()), + ExprTraceBwBinItpChecker.create( + BoolExprs.True(), BoolExprs.True(), + Z3LegacySolverFactory.getInstance().createItpSolver() + ), precRefiner, PruneStrategy.FULL, - NullLogger.getInstance()) as Refiner>, XcfaAction, XcfaPrec>> + NullLogger.getInstance() + ) as Refiner>, XcfaAction, XcfaPrec>> val cegarChecker = CegarChecker.create(abstractor, refiner) diff --git a/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaPredAnalysisTest.kt b/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaPredAnalysisTest.kt index e398b5ed07..88d068adf7 100644 --- a/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaPredAnalysisTest.kt +++ b/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaPredAnalysisTest.kt @@ -84,23 +84,30 @@ class XcfaPredAnalysisTest { val lts = getXcfaLts() - val abstractor = getXcfaAbstractor(analysis, + val abstractor = getXcfaAbstractor( + analysis, PriorityWaitlist.create( - ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs())), + ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs()) + ), StopCriterions.firstCex>, XcfaAction>(), ConsoleLogger(Logger.Level.DETAIL), lts, - ErrorDetection.ERROR_LOCATION) as Abstractor>, XcfaAction, XcfaPrec>> + ErrorDetection.ERROR_LOCATION + ) as Abstractor>, XcfaAction, XcfaPrec>> val precRefiner = XcfaPrecRefiner>, PredPrec, ItpRefutation>( - ItpRefToPtrPrec(ItpRefToPredPrec(ExprSplitters.whole()))) + ItpRefToPtrPrec(ItpRefToPredPrec(ExprSplitters.whole())) + ) val refiner = XcfaSingleExprTraceRefiner.create( - ExprTraceBwBinItpChecker.create(BoolExprs.True(), BoolExprs.True(), - Z3LegacySolverFactory.getInstance().createItpSolver()), + ExprTraceBwBinItpChecker.create( + BoolExprs.True(), BoolExprs.True(), + Z3LegacySolverFactory.getInstance().createItpSolver() + ), precRefiner, PruneStrategy.FULL, - NullLogger.getInstance()) as Refiner>, XcfaAction, XcfaPrec>> + NullLogger.getInstance() + ) as Refiner>, XcfaAction, XcfaPrec>> val cegarChecker = CegarChecker.create(abstractor, refiner) @@ -130,23 +137,30 @@ class XcfaPredAnalysisTest { val lts = XcfaSporLts(xcfa) - val abstractor = getXcfaAbstractor(analysis, + val abstractor = getXcfaAbstractor( + analysis, PriorityWaitlist.create( - ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs())), + ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs()) + ), StopCriterions.firstCex>, XcfaAction>(), ConsoleLogger(Logger.Level.DETAIL), lts, - ErrorDetection.ERROR_LOCATION) as Abstractor>, XcfaAction, XcfaPrec>> + ErrorDetection.ERROR_LOCATION + ) as Abstractor>, XcfaAction, XcfaPrec>> val precRefiner = XcfaPrecRefiner>, PredPrec, ItpRefutation>( - ItpRefToPtrPrec(ItpRefToPredPrec(ExprSplitters.whole()))) + ItpRefToPtrPrec(ItpRefToPredPrec(ExprSplitters.whole())) + ) val refiner = XcfaSingleExprTraceRefiner.create( - ExprTraceBwBinItpChecker.create(BoolExprs.True(), BoolExprs.True(), - Z3LegacySolverFactory.getInstance().createItpSolver()), + ExprTraceBwBinItpChecker.create( + BoolExprs.True(), BoolExprs.True(), + Z3LegacySolverFactory.getInstance().createItpSolver() + ), precRefiner, PruneStrategy.FULL, - NullLogger.getInstance()) as Refiner>, XcfaAction, XcfaPrec>> + NullLogger.getInstance() + ) as Refiner>, XcfaAction, XcfaPrec>> val cegarChecker = CegarChecker.create(abstractor, refiner) @@ -177,23 +191,30 @@ class XcfaPredAnalysisTest { val lts = XcfaDporLts(xcfa) - val abstractor = getXcfaAbstractor(analysis, + val abstractor = getXcfaAbstractor( + analysis, lts.waitlist, StopCriterions.firstCex>, XcfaAction>(), ConsoleLogger(Logger.Level.DETAIL), lts, - ErrorDetection.ERROR_LOCATION) as Abstractor>, XcfaAction, XcfaPrec>> + ErrorDetection.ERROR_LOCATION + ) as Abstractor>, XcfaAction, XcfaPrec>> val precRefiner = XcfaPrecRefiner>, PredPrec, ItpRefutation>( - ItpRefToPtrPrec(ItpRefToPredPrec(ExprSplitters.whole()))) + ItpRefToPtrPrec(ItpRefToPredPrec(ExprSplitters.whole())) + ) val refiner = XcfaSingleExprTraceRefiner.create( - ExprTraceBwBinItpChecker.create(BoolExprs.True(), BoolExprs.True(), - Z3LegacySolverFactory.getInstance().createItpSolver()), + ExprTraceBwBinItpChecker.create( + BoolExprs.True(), BoolExprs.True(), + Z3LegacySolverFactory.getInstance().createItpSolver() + ), precRefiner, PruneStrategy.FULL, ConsoleLogger( - Logger.Level.DETAIL)) as Refiner>, XcfaAction, XcfaPrec>> + Logger.Level.DETAIL + ) + ) as Refiner>, XcfaAction, XcfaPrec>> val cegarChecker = CegarChecker.create(abstractor, refiner) @@ -223,24 +244,31 @@ class XcfaPredAnalysisTest { val lts = XcfaAasporLts(xcfa, mutableMapOf()) - val abstractor = getXcfaAbstractor(analysis, + val abstractor = getXcfaAbstractor( + analysis, PriorityWaitlist.create( - ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs())), + ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), ArgNodeComparators.bfs()) + ), StopCriterions.firstCex>, XcfaAction>(), ConsoleLogger(Logger.Level.DETAIL), lts, - ErrorDetection.ERROR_LOCATION) as Abstractor>, XcfaAction, XcfaPrec>> + ErrorDetection.ERROR_LOCATION + ) as Abstractor>, XcfaAction, XcfaPrec>> val precRefiner = XcfaPrecRefiner, PredPrec, ItpRefutation>( - ItpRefToPtrPrec(ItpRefToPredPrec(ExprSplitters.whole()))) + ItpRefToPtrPrec(ItpRefToPredPrec(ExprSplitters.whole())) + ) val atomicNodePruner = AtomicNodePruner>, XcfaAction>() val refiner = XcfaSingleExprTraceRefiner.create( - ExprTraceBwBinItpChecker.create(BoolExprs.True(), BoolExprs.True(), - Z3LegacySolverFactory.getInstance().createItpSolver()), + ExprTraceBwBinItpChecker.create( + BoolExprs.True(), BoolExprs.True(), + Z3LegacySolverFactory.getInstance().createItpSolver() + ), precRefiner, PruneStrategy.FULL, NullLogger.getInstance(), - atomicNodePruner) as Refiner>, XcfaAction, XcfaPrec>> + atomicNodePruner + ) as Refiner>, XcfaAction, XcfaPrec>> val cegarChecker = CegarChecker.create(abstractor, AasporRefiner.create(refiner, PruneStrategy.FULL, mutableMapOf())) @@ -271,22 +299,28 @@ class XcfaPredAnalysisTest { val lts = XcfaAadporLts(xcfa) - val abstractor = getXcfaAbstractor(analysis, + val abstractor = getXcfaAbstractor( + analysis, lts.waitlist, StopCriterions.firstCex>, XcfaAction>(), ConsoleLogger(Logger.Level.DETAIL), lts, - ErrorDetection.ERROR_LOCATION) as Abstractor>, XcfaAction, XcfaPrec>> + ErrorDetection.ERROR_LOCATION + ) as Abstractor>, XcfaAction, XcfaPrec>> val precRefiner = XcfaPrecRefiner( - ItpRefToPtrPrec(ItpRefToPredPrec(ExprSplitters.whole()))) + ItpRefToPtrPrec(ItpRefToPredPrec(ExprSplitters.whole())) + ) val refiner = XcfaSingleExprTraceRefiner.create( - ExprTraceBwBinItpChecker.create(BoolExprs.True(), BoolExprs.True(), - Z3LegacySolverFactory.getInstance().createItpSolver()), + ExprTraceBwBinItpChecker.create( + BoolExprs.True(), BoolExprs.True(), + Z3LegacySolverFactory.getInstance().createItpSolver() + ), precRefiner, PruneStrategy.FULL, - NullLogger.getInstance()) as Refiner>, XcfaAction, XcfaPrec>> + NullLogger.getInstance() + ) as Refiner>, XcfaAction, XcfaPrec>> val cegarChecker = CegarChecker.create(abstractor, refiner) diff --git a/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaStateLtsTest.kt b/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaStateLtsTest.kt index b1a815104b..d02b0687d3 100644 --- a/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaStateLtsTest.kt +++ b/subprojects/xcfa/xcfa-analysis/src/test/java/hu/bme/mit/theta/xcfa/analysis/XcfaStateLtsTest.kt @@ -67,7 +67,8 @@ class XcfaStateLtsTest { initState = XcfaState( xcfa, mapOf( - Pair(0, + Pair( + 0, XcfaProcessState( locs = LinkedList(listOf(edges[1].source)), varLookup = LinkedList(listOf(createLookup(xcfa.initProcedures[0].first, "T0", "P0"))) diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/ExecuteConfig.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/ExecuteConfig.kt index 9469c2eca3..afb0bb997a 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/ExecuteConfig.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/ExecuteConfig.kt @@ -176,13 +176,14 @@ fun frontend(config: XcfaConfig<*, *>, logger: Logger, uniqueLogger: Logger): Tr logger.write( Logger.Level.INFO, "Frontend finished: ${xcfa.name} (in ${ - stopwatch.elapsed(TimeUnit.MILLISECONDS) - } ms)\n" + stopwatch.elapsed(TimeUnit.MILLISECONDS) + } ms)\n" ) logger.write(RESULT, "ParsingResult Success\n") logger.write(RESULT, - "Alias graph size: ${xcfa.pointsToGraph.size} -> ${xcfa.pointsToGraph.values.map { it.size }.toList()}\n") + "Alias graph size: ${xcfa.pointsToGraph.size} -> ${xcfa.pointsToGraph.values.map { it.size }.toList()}\n" + ) return Triple(xcfa, mcm, parseContext) } @@ -226,8 +227,8 @@ private fun backend( logger.write( Logger.Level.INFO, "Backend finished (in ${ - stopwatch.elapsed(TimeUnit.MILLISECONDS) - } ms)\n" + stopwatch.elapsed(TimeUnit.MILLISECONDS) + } ms)\n" ) logger.write(RESULT, result.toString() + "\n") @@ -331,8 +332,10 @@ private fun postVerificationLogging( traceFile.writeText(GraphvizWriter.getInstance().writeString(traceG)) val sequenceFile = File(resultFolder, "trace.plantuml") - writeSequenceTrace(sequenceFile, - safetyResult.asUnsafe().cex as Trace, XcfaAction>) { (_, act) -> + writeSequenceTrace( + sequenceFile, + safetyResult.asUnsafe().cex as Trace, XcfaAction> + ) { (_, act) -> act.label.getFlatLabels().map(XcfaLabel::toString) } @@ -363,8 +366,10 @@ private fun postVerificationLogging( } } -private fun writeSequenceTrace(sequenceFile: File, trace: Trace, XcfaAction>, - printer: (Pair, XcfaAction>) -> List) { +private fun writeSequenceTrace( + sequenceFile: File, trace: Trace, XcfaAction>, + printer: (Pair, XcfaAction>) -> List +) { sequenceFile.writeText("@startuml\n") var maxWidth = 0 trace.actions.forEachIndexed { i, it -> diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToBoundedChecker.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToBoundedChecker.kt index 18e0bd82ca..7feaca22b7 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToBoundedChecker.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToBoundedChecker.kt @@ -30,23 +30,31 @@ import hu.bme.mit.theta.xcfa.cli.params.XcfaConfig import hu.bme.mit.theta.xcfa.cli.utils.getSolver import hu.bme.mit.theta.xcfa.model.XCFA -fun getBoundedChecker(xcfa: XCFA, mcm: MCM, +fun getBoundedChecker( + xcfa: XCFA, mcm: MCM, config: XcfaConfig<*, *>, - logger: Logger): SafetyChecker>, XcfaAction>, XcfaPrec<*>> { + logger: Logger +): SafetyChecker>, XcfaAction>, XcfaPrec<*>> { val boundedConfig = config.backendConfig.specConfig as BoundedConfig return BoundedChecker( monolithicExpr = xcfa.toMonolithicExpr(), - bmcSolver = tryGetSolver(boundedConfig.bmcConfig.bmcSolver, - boundedConfig.bmcConfig.validateBMCSolver)?.createSolver(), + bmcSolver = tryGetSolver( + boundedConfig.bmcConfig.bmcSolver, + boundedConfig.bmcConfig.validateBMCSolver + )?.createSolver(), bmcEnabled = { !boundedConfig.bmcConfig.disable }, lfPathOnly = { !boundedConfig.bmcConfig.nonLfPath }, - itpSolver = tryGetSolver(boundedConfig.itpConfig.itpSolver, - boundedConfig.itpConfig.validateItpSolver)?.createItpSolver(), + itpSolver = tryGetSolver( + boundedConfig.itpConfig.itpSolver, + boundedConfig.itpConfig.validateItpSolver + )?.createItpSolver(), imcEnabled = { !boundedConfig.itpConfig.disable }, - indSolver = tryGetSolver(boundedConfig.indConfig.indSolver, - boundedConfig.indConfig.validateIndSolver)?.createSolver(), + indSolver = tryGetSolver( + boundedConfig.indConfig.indSolver, + boundedConfig.indConfig.validateIndSolver + )?.createSolver(), kindEnabled = { !boundedConfig.indConfig.disable }, valToState = { xcfa.valToState(it) }, biValToAction = { val1, val2 -> xcfa.valToAction(val1, val2) }, diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToCegarChecker.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToCegarChecker.kt index 8c39486021..6417f4e57c 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToCegarChecker.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToCegarChecker.kt @@ -43,14 +43,20 @@ import hu.bme.mit.theta.xcfa.cli.params.* import hu.bme.mit.theta.xcfa.cli.utils.getSolver import hu.bme.mit.theta.xcfa.model.XCFA -fun getCegarChecker(xcfa: XCFA, mcm: MCM, +fun getCegarChecker( + xcfa: XCFA, mcm: MCM, config: XcfaConfig<*, *>, - logger: Logger): SafetyChecker, XcfaAction>, Trace>, XcfaAction>, XcfaPrec<*>> { + logger: Logger +): SafetyChecker, XcfaAction>, Trace>, XcfaAction>, XcfaPrec<*>> { val cegarConfig = config.backendConfig.specConfig as CegarConfig - val abstractionSolverFactory: SolverFactory = getSolver(cegarConfig.abstractorConfig.abstractionSolver, - cegarConfig.abstractorConfig.validateAbstractionSolver) - val refinementSolverFactory: SolverFactory = getSolver(cegarConfig.refinerConfig.refinementSolver, - cegarConfig.refinerConfig.validateRefinementSolver) + val abstractionSolverFactory: SolverFactory = getSolver( + cegarConfig.abstractorConfig.abstractionSolver, + cegarConfig.abstractorConfig.validateAbstractionSolver + ) + val refinementSolverFactory: SolverFactory = getSolver( + cegarConfig.refinerConfig.refinementSolver, + cegarConfig.refinerConfig.validateRefinementSolver + ) val ignoredVarRegistry = mutableMapOf, MutableSet>() @@ -59,12 +65,14 @@ fun getCegarChecker(xcfa: XCFA, mcm: MCM, (cegarConfig.coi.porLts as XcfaDporLts).waitlist } else { PriorityWaitlist.create>, XcfaAction>>( - cegarConfig.abstractorConfig.search.getComp(xcfa)) + cegarConfig.abstractorConfig.search.getComp(xcfa) + ) } val abstractionSolverInstance = abstractionSolverFactory.createSolver() val globalStatePartialOrd: PartialOrd> = cegarConfig.abstractorConfig.domain.partialOrd( - abstractionSolverInstance) as PartialOrd> + abstractionSolverInstance + ) as PartialOrd> val corePartialOrd: PartialOrd>> = if (xcfa.isInlined) getPartialOrder(globalStatePartialOrd) else getStackPartialOrder(globalStatePartialOrd) @@ -91,18 +99,23 @@ fun getCegarChecker(xcfa: XCFA, mcm: MCM, val precRefiner: PrecRefiner = cegarConfig.abstractorConfig.domain.itpPrecRefiner(cegarConfig.refinerConfig.exprSplitter.exprSplitter) as PrecRefiner - val atomicNodePruner: NodePruner = cegarConfig.abstractorConfig.domain.nodePruner as NodePruner + val atomicNodePruner: NodePruner = + cegarConfig.abstractorConfig.domain.nodePruner as NodePruner val refiner: Refiner = if (cegarConfig.refinerConfig.refinement == Refinement.MULTI_SEQ) if (cegarConfig.porLevel == POR.AASPOR) - MultiExprTraceRefiner.create(ref, precRefiner, cegarConfig.refinerConfig.pruneStrategy, logger, - atomicNodePruner) + MultiExprTraceRefiner.create( + ref, precRefiner, cegarConfig.refinerConfig.pruneStrategy, logger, + atomicNodePruner + ) else MultiExprTraceRefiner.create(ref, precRefiner, cegarConfig.refinerConfig.pruneStrategy, logger) else if (cegarConfig.porLevel == POR.AASPOR) - XcfaSingleExprTraceRefiner.create(ref, precRefiner, cegarConfig.refinerConfig.pruneStrategy, logger, - atomicNodePruner) + XcfaSingleExprTraceRefiner.create( + ref, precRefiner, cegarConfig.refinerConfig.pruneStrategy, logger, + atomicNodePruner + ) else XcfaSingleExprTraceRefiner.create(ref, precRefiner, cegarConfig.refinerConfig.pruneStrategy, logger) @@ -125,9 +138,11 @@ fun getCegarChecker(xcfa: XCFA, mcm: MCM, return object : SafetyChecker, XcfaAction>, Trace>, XcfaAction>, XcfaPrec<*>> { override fun check( - prec: XcfaPrec<*>?): SafetyResult, XcfaAction>, Trace>, XcfaAction>> { + prec: XcfaPrec<*>? + ): SafetyResult, XcfaAction>, Trace>, XcfaAction>> { return cegarChecker.check( - prec) as SafetyResult, XcfaAction>, Trace>, XcfaAction>> + prec + ) as SafetyResult, XcfaAction>, Trace>, XcfaAction>> } override fun check(): SafetyResult, XcfaAction>, Trace>, XcfaAction>> { diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToChecker.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToChecker.kt index 4bd2dce149..2315b6405b 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToChecker.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToChecker.kt @@ -31,9 +31,11 @@ import hu.bme.mit.theta.xcfa.cli.params.Backend import hu.bme.mit.theta.xcfa.cli.params.XcfaConfig import hu.bme.mit.theta.xcfa.model.XCFA -fun getChecker(xcfa: XCFA, mcm: MCM, config: XcfaConfig<*, *>, parseContext: ParseContext, +fun getChecker( + xcfa: XCFA, mcm: MCM, config: XcfaConfig<*, *>, parseContext: ParseContext, logger: Logger, - uniqueLogger: Logger): SafetyChecker<*, *, XcfaPrec<*>> = + uniqueLogger: Logger +): SafetyChecker<*, *, XcfaPrec<*>> = if (config.backendConfig.inProcess) { InProcessChecker(xcfa, config, parseContext, logger) } else { diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToOcChecker.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToOcChecker.kt index df14f6ee8f..80cae60477 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToOcChecker.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToOcChecker.kt @@ -31,14 +31,18 @@ import hu.bme.mit.theta.xcfa.cli.params.OcConfig import hu.bme.mit.theta.xcfa.cli.params.XcfaConfig import hu.bme.mit.theta.xcfa.model.XCFA -fun getOcChecker(xcfa: XCFA, mcm: MCM, +fun getOcChecker( + xcfa: XCFA, mcm: MCM, config: XcfaConfig<*, *>, - logger: Logger): SafetyChecker>, XcfaAction>, XcfaPrec<*>> { + logger: Logger +): SafetyChecker>, XcfaAction>, XcfaPrec<*>> { val ocChecker = XcfaOcChecker(xcfa, (config.backendConfig.specConfig as OcConfig).decisionProcedure, logger) return object : SafetyChecker>, XcfaAction>, XcfaPrec<*>> { override fun check( - prec: XcfaPrec<*>?): SafetyResult>, XcfaAction>> = check() + prec: XcfaPrec<*>? + ): SafetyResult>, XcfaAction>> = check() - override fun check(): SafetyResult>, XcfaAction>> = ocChecker.check() + override fun check(): SafetyResult>, XcfaAction>> = + ocChecker.check() } } \ No newline at end of file diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToPortfolio.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToPortfolio.kt index a105f36786..0daeedf5e8 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToPortfolio.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToPortfolio.kt @@ -40,47 +40,52 @@ import javax.script.ScriptEngine import javax.script.ScriptEngineManager import javax.script.SimpleBindings -fun getPortfolioChecker(xcfa: XCFA, mcm: MCM, config: XcfaConfig<*, *>, +fun getPortfolioChecker( + xcfa: XCFA, mcm: MCM, config: XcfaConfig<*, *>, parseContext: ParseContext, logger: Logger, - uniqueLogger: Logger): SafetyChecker>, XcfaAction>, Trace>, XcfaAction>, XcfaPrec<*>> = SafetyChecker { _ -> + uniqueLogger: Logger +): SafetyChecker>, XcfaAction>, Trace>, XcfaAction>, XcfaPrec<*>> = + SafetyChecker { _ -> - val sw = Stopwatch.createStarted() - val portfolioName = (config.backendConfig.specConfig as PortfolioConfig).portfolio + val sw = Stopwatch.createStarted() + val portfolioName = (config.backendConfig.specConfig as PortfolioConfig).portfolio - val portfolioStm = when (portfolioName) { - "STABLE", - "CEGAR", - "COMPLEX", - "COMPLEX24" -> complexPortfolio24(xcfa, mcm, parseContext, config, logger, uniqueLogger) + val portfolioStm = when (portfolioName) { + "STABLE", + "CEGAR", + "COMPLEX", + "COMPLEX24" -> complexPortfolio24(xcfa, mcm, parseContext, config, logger, uniqueLogger) - "COMPLEX23" -> complexPortfolio23(xcfa, mcm, parseContext, config, logger, uniqueLogger) + "COMPLEX23" -> complexPortfolio23(xcfa, mcm, parseContext, config, logger, uniqueLogger) - "EMERGENT", - "BOUNDED" -> boundedPortfolio(xcfa, mcm, parseContext, config, logger, uniqueLogger) + "EMERGENT", + "BOUNDED" -> boundedPortfolio(xcfa, mcm, parseContext, config, logger, uniqueLogger) - "TESTING", - "CHC", - "HORN" -> hornPortfolio(xcfa, mcm, parseContext, config, logger, uniqueLogger) + "TESTING", + "CHC", + "HORN" -> hornPortfolio(xcfa, mcm, parseContext, config, logger, uniqueLogger) - else -> { - if (File(portfolioName).exists()) { - val kotlinEngine: ScriptEngine = ScriptEngineManager().getEngineByExtension("kts") - val bindings: Bindings = SimpleBindings() - bindings["xcfa"] = xcfa - bindings["mcm"] = mcm - bindings["parseContext"] = parseContext - bindings["portfolioConfig"] = config - bindings["logger"] = logger - bindings["uniqueLogger"] = uniqueLogger - kotlinEngine.eval(FileReader(portfolioName), bindings) as STM - } else { - error("No such file or built-in config: $portfolioName") + else -> { + if (File(portfolioName).exists()) { + val kotlinEngine: ScriptEngine = ScriptEngineManager().getEngineByExtension("kts") + val bindings: Bindings = SimpleBindings() + bindings["xcfa"] = xcfa + bindings["mcm"] = mcm + bindings["parseContext"] = parseContext + bindings["portfolioConfig"] = config + bindings["logger"] = logger + bindings["uniqueLogger"] = uniqueLogger + kotlinEngine.eval(FileReader(portfolioName), bindings) as STM + } else { + error("No such file or built-in config: $portfolioName") + } } } - } - val result = portfolioStm.execute() as Pair, SafetyResult<*, *>> + val result = portfolioStm.execute() as Pair, SafetyResult<*, *>> - logger.write(Logger.Level.RESULT, "Config ${result.first} succeeded in ${sw.elapsed(TimeUnit.MILLISECONDS)} ms\n") - result.second as SafetyResult>, XcfaAction>, Trace>, XcfaAction>>? -} \ No newline at end of file + logger.write( + Logger.Level.RESULT, "Config ${result.first} succeeded in ${sw.elapsed(TimeUnit.MILLISECONDS)} ms\n" + ) + result.second as SafetyResult>, XcfaAction>, Trace>, XcfaAction>>? + } \ No newline at end of file diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/InProcessChecker.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/InProcessChecker.kt index a20d9a5aaf..276f6455d8 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/InProcessChecker.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/InProcessChecker.kt @@ -47,7 +47,8 @@ class InProcessChecker( ) : SafetyChecker> { override fun check( - prec: XcfaPrec<*>?): SafetyResult { + prec: XcfaPrec<*>? + ): SafetyResult { return check() } @@ -80,16 +81,18 @@ class InProcessChecker( getGson(xcfa).toJson(processConfig) } - val pb = NuProcessBuilder(listOf( - ProcessHandle.current().info().command().orElse("java"), - "-Xss120m", - "-Xmx14210m", - "-cp", - File(XcfaCli::class.java.protectionDomain.codeSource.location.toURI()).absolutePath, - XcfaCli::class.qualifiedName, - "-c", - configJson.absolutePath - ).filterNotNull()) + val pb = NuProcessBuilder( + listOf( + ProcessHandle.current().info().command().orElse("java"), + "-Xss120m", + "-Xmx14210m", + "-cp", + File(XcfaCli::class.java.protectionDomain.codeSource.location.toURI()).absolutePath, + XcfaCli::class.qualifiedName, + "-c", + configJson.absolutePath + ).filterNotNull() + ) val processHandler = ProcessHandler() pb.setProcessListener(processHandler) val process: NuProcess = pb.start() @@ -102,8 +105,10 @@ class InProcessChecker( process.destroy(true) throw ErrorCodeException(ExitCodes.TIMEOUT.code) } else { - logger.write(Logger.Level.RESULT, - "Config timed out but started writing result, trying to wait an additional 10%...") + logger.write( + Logger.Level.RESULT, + "Config timed out but started writing result, trying to wait an additional 10%..." + ) val retCode = process.waitFor(config.backendConfig.timeoutMs / 10, TimeUnit.MILLISECONDS) if (retCode != 0) { throw ErrorCodeException(retCode) diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/ParamValues.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/ParamValues.kt index ac5b3d3236..83dbae2747 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/ParamValues.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/ParamValues.kt @@ -116,8 +116,10 @@ enum class Domain( EXPL( abstractor = { a, b, c, d, e, f, g, h, i, j -> - getXcfaAbstractor(ExplXcfaAnalysis(a, b, c, i as PartialOrd>>, j), d, - e, f, g, h) + getXcfaAbstractor( + ExplXcfaAnalysis(a, b, c, i as PartialOrd>>, j), d, + e, f, g, h + ) }, itpPrecRefiner = { XcfaPrecRefiner, ExplPrec, ItpRefutation>(ItpRefToPtrPrec(ItpRefToExplPrec())) @@ -129,8 +131,12 @@ enum class Domain( ), PRED_BOOL( abstractor = { a, b, c, d, e, f, g, h, i, j -> - getXcfaAbstractor(PredXcfaAnalysis(a, b, PredAbstractors.booleanAbstractor(b), - i as PartialOrd>>, j), d, e, f, g, h) + getXcfaAbstractor( + PredXcfaAnalysis( + a, b, PredAbstractors.booleanAbstractor(b), + i as PartialOrd>>, j + ), d, e, f, g, h + ) }, itpPrecRefiner = { a -> XcfaPrecRefiner, PredPrec, ItpRefutation>(ItpRefToPtrPrec(ItpRefToPredPrec(a))) @@ -142,8 +148,12 @@ enum class Domain( ), PRED_CART( abstractor = { a, b, c, d, e, f, g, h, i, j -> - getXcfaAbstractor(PredXcfaAnalysis(a, b, PredAbstractors.cartesianAbstractor(b), - i as PartialOrd>>, j), d, e, f, g, h) + getXcfaAbstractor( + PredXcfaAnalysis( + a, b, PredAbstractors.cartesianAbstractor(b), + i as PartialOrd>>, j + ), d, e, f, g, h + ) }, itpPrecRefiner = { a -> XcfaPrecRefiner, PredPrec, ItpRefutation>(ItpRefToPtrPrec(ItpRefToPredPrec(a))) @@ -155,8 +165,12 @@ enum class Domain( ), PRED_SPLIT( abstractor = { a, b, c, d, e, f, g, h, i, j -> - getXcfaAbstractor(PredXcfaAnalysis(a, b, PredAbstractors.booleanSplitAbstractor(b), - i as PartialOrd>>, j), d, e, f, g, h) + getXcfaAbstractor( + PredXcfaAnalysis( + a, b, PredAbstractors.booleanSplitAbstractor(b), + i as PartialOrd>>, j + ), d, e, f, g, h + ) }, itpPrecRefiner = { a -> XcfaPrecRefiner, PredPrec, ItpRefutation>(ItpRefToPtrPrec(ItpRefToPredPrec(a))) @@ -280,15 +294,19 @@ enum class Search { BFS { override fun getComp(cfa: XCFA): ArgNodeComparator { - return ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), - ArgNodeComparators.bfs()) + return ArgNodeComparators.combine( + ArgNodeComparators.targetFirst(), + ArgNodeComparators.bfs() + ) } }, DFS { override fun getComp(cfa: XCFA): ArgNodeComparator { - return ArgNodeComparators.combine(ArgNodeComparators.targetFirst(), - ArgNodeComparators.dfs()) + return ArgNodeComparators.combine( + ArgNodeComparators.targetFirst(), + ArgNodeComparators.dfs() + ) } }, ERR { @@ -321,7 +339,8 @@ enum class InitPrec( ALLASSUMES( explPrec = { xcfa -> XcfaPrec( - PtrPrec(ExplPrec.of(xcfa.collectAssumes().flatMap(ExprUtils::getVars)), emptySet())) + PtrPrec(ExplPrec.of(xcfa.collectAssumes().flatMap(ExprUtils::getVars)), emptySet()) + ) }, predPrec = { xcfa -> XcfaPrec(PtrPrec(PredPrec.of(xcfa.collectAssumes()), emptySet())) }, ), diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/XcfaConfig.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/XcfaConfig.kt index a52a05c957..3a8e43940a 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/XcfaConfig.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/XcfaConfig.kt @@ -70,16 +70,22 @@ data class InputConfig( @Parameter(names = ["--cat"], description = "Path of the cat model") var catFile: File? = null, - @Parameter(names = ["--parse-ctx"], - description = "Path of the parse context JSON (may contain additional metadata)") + @Parameter( + names = ["--parse-ctx"], + description = "Path of the parse context JSON (may contain additional metadata)" + ) var parseCtx: File? = null, - @Parameter(names = ["--xcfa-w-ctx"], - description = "XCFA and ParseContext (will overwrite --input and --parse-ctx when given)") + @Parameter( + names = ["--xcfa-w-ctx"], + description = "XCFA and ParseContext (will overwrite --input and --parse-ctx when given)" + ) var xcfaWCtx: Triple? = null, - @Parameter(names = ["--property"], - description = "Path of the property file (will overwrite --property when given)") + @Parameter( + names = ["--property"], + description = "Path of the property file (will overwrite --property when given)" + ) var propertyFile: File? = null, @Parameter(names = ["--property-value"], description = "Property") @@ -100,16 +106,22 @@ data class FrontendConfig( @Parameter(names = ["--static-coi"], description = "Enable static cone-of-influence") var staticCoi: Boolean = false, - @Parameter(names = ["--unroll"], - description = "Max number of loop iterations to unroll (use -1 to unroll completely when possible)") + @Parameter( + names = ["--unroll"], + description = "Max number of loop iterations to unroll (use -1 to unroll completely when possible)" + ) var loopUnroll: Int = 1000, - @Parameter(names = ["--force-unroll"], - description = "Number of loop iteration to unroll even if the number of iterations is unknown; in case of such a bounded loop unrolling, the safety result cannot be safe (use -1 to disable)") + @Parameter( + names = ["--force-unroll"], + description = "Number of loop iteration to unroll even if the number of iterations is unknown; in case of such a bounded loop unrolling, the safety result cannot be safe (use -1 to disable)" + ) var forceUnroll: Int = -1, - @Parameter(names = ["--enable-few"], - description = "Enable the FetchExecuteWriteback pass, which introduces a local temp var for all memory accesses") + @Parameter( + names = ["--enable-few"], + description = "Enable the FetchExecuteWriteback pass, which introduces a local temp var for all memory accesses" + ) var enableFew: Boolean = false, @Parameter(names = ["--input-type"], description = "Format of the input") @@ -206,22 +218,28 @@ data class CegarAbstractorConfig( @Parameter(names = ["--abstraction-solver"], description = "Abstraction solver name") var abstractionSolver: String = "Z3", - @Parameter(names = ["--validate-abstraction-solver"], - description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues.") + @Parameter( + names = ["--validate-abstraction-solver"], + description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues." + ) var validateAbstractionSolver: Boolean = false, @Parameter(names = ["--domain"], description = "Abstraction domain") var domain: Domain = Domain.EXPL, - @Parameter(names = ["--maxenum"], - description = "How many successors to enumerate in a transition. Only relevant to the explicit domain. Use 0 for no limit.") + @Parameter( + names = ["--maxenum"], + description = "How many successors to enumerate in a transition. Only relevant to the explicit domain. Use 0 for no limit." + ) var maxEnum: Int = 1, @Parameter(names = ["--search"], description = "Search strategy") var search: Search = Search.ERR, - @Parameter(names = ["--havoc-memory"], - description = "HAVOC memory model (do not track pointers in transition function)") + @Parameter( + names = ["--havoc-memory"], + description = "HAVOC memory model (do not track pointers in transition function)" + ) var havocMemory: Boolean = false ) : Config @@ -229,8 +247,10 @@ data class CegarRefinerConfig( @Parameter(names = ["--refinement-solver"], description = "Refinement solver name") var refinementSolver: String = "Z3", - @Parameter(names = ["--validate-refinement-solver"], - description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues.") + @Parameter( + names = ["--validate-refinement-solver"], + description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues." + ) var validateRefinementSolver: Boolean = false, @Parameter(names = ["--refinement"], description = "Refinement strategy") @@ -281,8 +301,10 @@ data class BMCConfig( @Parameter(names = ["--bmc-solver"], description = "BMC solver name") var bmcSolver: String = "Z3", - @Parameter(names = ["--validate-bmc-solver"], - description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues.") + @Parameter( + names = ["--validate-bmc-solver"], + description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues." + ) var validateBMCSolver: Boolean = false, ) : Config @@ -293,16 +315,22 @@ data class InductionConfig( @Parameter(names = ["--induction-solver", "--ind-solver"], description = "Induction solver name") var indSolver: String = "Z3", - @Parameter(names = ["--validate-induction-solver"], - description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues.") + @Parameter( + names = ["--validate-induction-solver"], + description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues." + ) var validateIndSolver: Boolean = false, - @Parameter(names = ["--ind-min-bound"], - description = "Start induction after reaching this bound") + @Parameter( + names = ["--ind-min-bound"], + description = "Start induction after reaching this bound" + ) var indMinBound: Int = 0, - @Parameter(names = ["--ind-frequency"], - description = "Frequency of induction check") + @Parameter( + names = ["--ind-frequency"], + description = "Frequency of induction check" + ) var indFreq: Int = 1, ) : Config @@ -313,8 +341,10 @@ data class InterpolationConfig( @Parameter(names = ["--interpolation-solver", "--itp-solver"], description = "Interpolation solver name") var itpSolver: String = "Z3", - @Parameter(names = ["--validate-interpolation-solver"], - description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues.") + @Parameter( + names = ["--validate-interpolation-solver"], + description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues." + ) var validateItpSolver: Boolean = false, ) : Config @@ -389,8 +419,10 @@ data class WitnessConfig( @Parameter(names = ["--cex-solver"], description = "Concretizer solver name") var concretizerSolver: String = "Z3", - @Parameter(names = ["--validate-cex-solver"], - description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues.") + @Parameter( + names = ["--validate-cex-solver"], + description = "Activates a wrapper, which validates the assertions in the solver in each (SAT) check. Filters some solver issues." + ) var validateConcretizerSolver: Boolean = false ) : Config @@ -409,11 +441,15 @@ data class DebugConfig( @Parameter(names = ["--loglevel"], description = "Detailedness of logging") var logLevel: Logger.Level = Logger.Level.MAINSTEP, - @Parameter(names = ["--arg-debug"], - description = "ARG debug mode (use the web-based debugger for ARG visualization)") + @Parameter( + names = ["--arg-debug"], + description = "ARG debug mode (use the web-based debugger for ARG visualization)" + ) var argdebug: Boolean = false, - @Parameter(names = ["--arg-to-file"], - description = "Visualize the resulting file here: https://ftsrg-edu.github.io/student-sisak-argviz/") + @Parameter( + names = ["--arg-to-file"], + description = "Visualize the resulting file here: https://ftsrg-edu.github.io/student-sisak-argviz/" + ) var argToFile: Boolean = false ) : Config \ No newline at end of file diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded.kt index 787774d93f..2cb473abb9 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded.kt @@ -38,7 +38,8 @@ fun boundedPortfolio( parseContext: ParseContext, portfolioConfig: XcfaConfig<*, *>, logger: Logger, - uniqueLogger: Logger): STM { + uniqueLogger: Logger +): STM { val checker = { config: XcfaConfig<*, *> -> runConfig(config, logger, uniqueLogger, true) } @@ -47,12 +48,14 @@ fun boundedPortfolio( input = null, xcfaWCtx = Triple(xcfa, mcm, parseContext), propertyFile = null, - property = portfolioConfig.inputConfig.property), + property = portfolioConfig.inputConfig.property + ), frontendConfig = FrontendConfig( lbeLevel = LbePass.level, loopUnroll = LoopUnrollPass.UNROLL_LIMIT, inputType = InputType.C, - specConfig = CFrontendConfig(arithmetic = ArchitectureConfig.ArithmeticType.efficient)), + specConfig = CFrontendConfig(arithmetic = ArchitectureConfig.ArithmeticType.efficient) + ), backendConfig = BackendConfig( backend = Backend.BOUNDED, solverHome = portfolioConfig.backendConfig.solverHome, @@ -62,7 +65,8 @@ fun boundedPortfolio( maxBound = 0, indConfig = InductionConfig(true), itpConfig = InterpolationConfig(true) - )), + ) + ), outputConfig = OutputConfig( versionInfo = false, resultFolder = Paths.get("./").toFile(), // cwd @@ -114,40 +118,49 @@ fun boundedPortfolio( timeoutMs: Long = 0, inProcess: Boolean = this.backendConfig.inProcess ): XcfaConfig<*, BoundedConfig> { - return copy(backendConfig = backendConfig.copy( - timeoutMs = timeoutMs, - inProcess = inProcess, - specConfig = backendConfig.specConfig!!.copy( - bmcConfig = backendConfig.specConfig!!.bmcConfig.copy(disable = !bmcEnabled, bmcSolver = bmcSolver), - indConfig = backendConfig.specConfig!!.indConfig.copy(disable = !indEnabled, indSolver = indSolver), - itpConfig = backendConfig.specConfig!!.itpConfig.copy(disable = !itpEnabled, itpSolver = itpSolver), + return copy( + backendConfig = backendConfig.copy( + timeoutMs = timeoutMs, + inProcess = inProcess, + specConfig = backendConfig.specConfig!!.copy( + bmcConfig = backendConfig.specConfig!!.bmcConfig.copy(disable = !bmcEnabled, bmcSolver = bmcSolver), + indConfig = backendConfig.specConfig!!.indConfig.copy(disable = !indEnabled, indSolver = indSolver), + itpConfig = backendConfig.specConfig!!.itpConfig.copy(disable = !itpEnabled, itpSolver = itpSolver), + ) ) - )) + ) } fun getStm(inProcess: Boolean): STM { val edges = LinkedHashSet() - val configBmcZ3 = ConfigNode("BmcZ3-$inProcess", + val configBmcZ3 = ConfigNode( + "BmcZ3-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, bmcEnabled = true, timeoutMs = 30000 - ), checker) - val configBmcMathsat = ConfigNode("BmcMathsat-$inProcess", + ), checker + ) + val configBmcMathsat = ConfigNode( + "BmcMathsat-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, bmcSolver = "mathsat:5.6.10", bmcEnabled = true, timeoutMs = 30000 - ), checker) - val configIndZ3 = ConfigNode("IndZ3-$inProcess", + ), checker + ) + val configIndZ3 = ConfigNode( + "IndZ3-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, bmcEnabled = true, indEnabled = true, timeoutMs = 300000 - ), checker) - val configIndMathsat = ConfigNode("IndMathsat-$inProcess", + ), checker + ) + val configIndMathsat = ConfigNode( + "IndMathsat-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, bmcSolver = "mathsat:5.6.10", @@ -155,33 +168,54 @@ fun boundedPortfolio( bmcEnabled = true, indEnabled = true, timeoutMs = 300000 - ), checker) - val configItpCvc5 = ConfigNode("ItpCvc5-$inProcess", + ), checker + ) + val configItpCvc5 = ConfigNode( + "ItpCvc5-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, itpEnabled = true, itpSolver = "cvc5:1.0.8", timeoutMs = 0 - ), checker) - val configItpMathsat = ConfigNode("ItpMathsat-$inProcess", + ), checker + ) + val configItpMathsat = ConfigNode( + "ItpMathsat-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, itpSolver = "mathsat:5.6.10", itpEnabled = true, timeoutMs = 0 - ), checker) + ), checker + ) edges.add(Edge(configBmcZ3, configBmcMathsat, solverError)) - edges.add(Edge(configBmcZ3, configIndZ3, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(configBmcMathsat, configIndMathsat, - if (inProcess) timeoutOrNotSolvableError else anyError)) + edges.add( + Edge( + configBmcZ3, configIndZ3, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + configBmcMathsat, configIndMathsat, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) edges.add(Edge(configIndZ3, configIndMathsat, solverError)) - edges.add(Edge(configIndZ3, configItpCvc5, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(configIndMathsat, configItpCvc5, - if (inProcess) timeoutOrNotSolvableError else anyError)) + edges.add( + Edge( + configIndZ3, configItpCvc5, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + configIndMathsat, configItpCvc5, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) edges.add(Edge(configItpCvc5, configItpMathsat, anyError)) diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex23.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex23.kt index c6901d3838..9c62a7e047 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex23.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex23.kt @@ -29,11 +29,13 @@ import hu.bme.mit.theta.xcfa.model.XCFA import hu.bme.mit.theta.xcfa.passes.LbePass import java.nio.file.Paths -fun complexPortfolio23(xcfa: XCFA, mcm: MCM, +fun complexPortfolio23( + xcfa: XCFA, mcm: MCM, parseContext: ParseContext, portfolioConfig: XcfaConfig<*, *>, logger: Logger, - uniqueLogger: Logger): STM { + uniqueLogger: Logger +): STM { val checker = { config: XcfaConfig<*, *> -> runConfig(config, logger, uniqueLogger, true) } @@ -42,12 +44,14 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, input = null, xcfaWCtx = Triple(xcfa, mcm, parseContext), propertyFile = null, - property = portfolioConfig.inputConfig.property), + property = portfolioConfig.inputConfig.property + ), frontendConfig = FrontendConfig( lbeLevel = LbePass.LbeLevel.LBE_SEQ, loopUnroll = 50, inputType = InputType.C, - specConfig = CFrontendConfig(arithmetic = ArchitectureConfig.ArithmeticType.efficient)), + specConfig = CFrontendConfig(arithmetic = ArchitectureConfig.ArithmeticType.efficient) + ), backendConfig = BackendConfig( backend = Backend.CEGAR, solverHome = portfolioConfig.backendConfig.solverHome, @@ -72,7 +76,9 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, refinement = Refinement.SEQ_ITP, exprSplitter = ExprSplitterOptions.WHOLE, pruneStrategy = PruneStrategy.FULL - ))), + ) + ) + ), outputConfig = OutputConfig( versionInfo = false, resultFolder = Paths.get("./").toFile(), // cwd @@ -92,7 +98,8 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, refinerConfig = baseCegarConfig.refinerConfig.copy(pruneStrategy = PruneStrategy.LAZY) ) baseConfig = baseConfig.copy( - backendConfig = baseConfig.backendConfig.copy(specConfig = multiThreadedCegarConfig)) + backendConfig = baseConfig.backendConfig.copy(specConfig = multiThreadedCegarConfig) + ) } val timeoutTrigger = ExceptionTrigger( @@ -123,23 +130,25 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, validateRefinementSolver: Boolean = this.backendConfig.specConfig!!.refinerConfig.validateRefinementSolver, inProcess: Boolean = this.backendConfig.inProcess ): XcfaConfig<*, CegarConfig> { - return copy(backendConfig = backendConfig.copy( - timeoutMs = timeoutMs, - inProcess = inProcess, - specConfig = backendConfig.specConfig!!.copy( - initPrec = initPrec, - abstractorConfig = backendConfig.specConfig!!.abstractorConfig.copy( - abstractionSolver = abstractionSolver, - validateAbstractionSolver = validateAbstractionSolver, - domain = domain, - ), - refinerConfig = backendConfig.specConfig!!.refinerConfig.copy( - refinementSolver = refinementSolver, - validateRefinementSolver = validateRefinementSolver, - refinement = refinement, + return copy( + backendConfig = backendConfig.copy( + timeoutMs = timeoutMs, + inProcess = inProcess, + specConfig = backendConfig.specConfig!!.copy( + initPrec = initPrec, + abstractorConfig = backendConfig.specConfig!!.abstractorConfig.copy( + abstractionSolver = abstractionSolver, + validateAbstractionSolver = validateAbstractionSolver, + domain = domain, + ), + refinerConfig = backendConfig.specConfig!!.refinerConfig.copy( + refinementSolver = refinementSolver, + validateRefinementSolver = validateRefinementSolver, + refinement = refinement, + ) ) ) - )) + ) } val quickExplConfig = baseConfig.adaptConfig(initPrec = InitPrec.ALLVARS, timeoutMs = 90_000) @@ -148,50 +157,92 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, fun integerStm(): STM { fun getStm(inProcess: Boolean): STM { - val config_1_1 = ConfigNode("QuickFullExpl_z3_4.10.1_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "z3:4.10.1", + val config_1_1 = ConfigNode( + "QuickFullExpl_z3_4.10.1_$inProcess", + quickExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "z3:4.10.1", refinementSolver = "z3:4.10.1", - refinement = Refinement.NWT_IT_WP), checker) - val config_2_1 = ConfigNode("EmptyExpl_z3_4.10.1_$inProcess", - emptyExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "z3:4.10.1", + refinement = Refinement.NWT_IT_WP + ), checker + ) + val config_2_1 = ConfigNode( + "EmptyExpl_z3_4.10.1_$inProcess", + emptyExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "z3:4.10.1", refinementSolver = "z3:4.10.1", - refinement = Refinement.NWT_IT_WP), checker) - val config_3_1 = ConfigNode("PredCart_z3_4.10.1_$inProcess", - predConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "z3:4.10.1", - refinementSolver = "z3:4.10.1"), checker) - - val config_1_2 = ConfigNode("QuickFullExpl_Z3_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess), checker) - val config_2_2 = ConfigNode("EmptyExpl_Z3_$inProcess", emptyExplConfig.adaptConfig(inProcess = inProcess), - checker) - val config_3_2 = ConfigNode("PredCart_Z3_$inProcess", predConfig.adaptConfig(inProcess = inProcess), - checker) - - val config_1_3 = ConfigNode("QuickFullExpl_princess_2022_07_01_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "princess:2022-07-01", - refinementSolver = "princess:2022-07-01"), - checker) - val config_2_3 = ConfigNode("EmptyExpl_princess_2022_07_01_$inProcess", - emptyExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "princess:2022-07-01", - refinementSolver = "princess:2022-07-01"), - checker) - val config_3_3 = ConfigNode("PredCart_mathsat_5.6.8_$inProcess", - predConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", - refinementSolver = "mathsat:5.6.8"), - checker) - - val config_1_4 = ConfigNode("QuickFullExpl_mathsat_5.6.8_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", - refinementSolver = "mathsat:5.6.8"), - checker) - val config_2_4 = ConfigNode("EmptyExpl_mathsat_5.6.8_$inProcess", - emptyExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", - refinementSolver = "mathsat:5.6.8"), - checker) - val config_3_4 = ConfigNode("PredCart_princess_2022_07_01_$inProcess", - predConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "princess:2022-07-01", - refinementSolver = "princess:2022-07-01"), - checker) + refinement = Refinement.NWT_IT_WP + ), checker + ) + val config_3_1 = ConfigNode( + "PredCart_z3_4.10.1_$inProcess", + predConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "z3:4.10.1", + refinementSolver = "z3:4.10.1" + ), checker + ) + + val config_1_2 = ConfigNode( + "QuickFullExpl_Z3_$inProcess", + quickExplConfig.adaptConfig(inProcess = inProcess), checker + ) + val config_2_2 = ConfigNode( + "EmptyExpl_Z3_$inProcess", emptyExplConfig.adaptConfig(inProcess = inProcess), + checker + ) + val config_3_2 = ConfigNode( + "PredCart_Z3_$inProcess", predConfig.adaptConfig(inProcess = inProcess), + checker + ) + + val config_1_3 = ConfigNode( + "QuickFullExpl_princess_2022_07_01_$inProcess", + quickExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "princess:2022-07-01", + refinementSolver = "princess:2022-07-01" + ), + checker + ) + val config_2_3 = ConfigNode( + "EmptyExpl_princess_2022_07_01_$inProcess", + emptyExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "princess:2022-07-01", + refinementSolver = "princess:2022-07-01" + ), + checker + ) + val config_3_3 = ConfigNode( + "PredCart_mathsat_5.6.8_$inProcess", + predConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", + refinementSolver = "mathsat:5.6.8" + ), + checker + ) + + val config_1_4 = ConfigNode( + "QuickFullExpl_mathsat_5.6.8_$inProcess", + quickExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", + refinementSolver = "mathsat:5.6.8" + ), + checker + ) + val config_2_4 = ConfigNode( + "EmptyExpl_mathsat_5.6.8_$inProcess", + emptyExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", + refinementSolver = "mathsat:5.6.8" + ), + checker + ) + val config_3_4 = ConfigNode( + "PredCart_princess_2022_07_01_$inProcess", + predConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "princess:2022-07-01", + refinementSolver = "princess:2022-07-01" + ), + checker + ) val timeouts = setOf( Edge(config_1_1, config_2_1, timeoutTrigger), @@ -203,15 +254,23 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, Edge(config_1_3, config_2_3, timeoutTrigger), Edge(config_2_3, config_3_1, timeoutTrigger), - Edge(config_1_4, config_2_4, - if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything")), - Edge(config_2_4, config_3_1, - if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything")), + Edge( + config_1_4, config_2_4, + if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything") + ), + Edge( + config_2_4, config_3_1, + if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything") + ), ) - val notTimeout = if (inProcess) ExceptionTrigger(ErrorCodeException(ExitCodes.SOLVER_ERROR.code), - label = "SolverError") else ExceptionTrigger(fallthroughExceptions = timeoutTrigger.exceptions, - label = "AnythingButTimeout") + val notTimeout = if (inProcess) ExceptionTrigger( + ErrorCodeException(ExitCodes.SOLVER_ERROR.code), + label = "SolverError" + ) else ExceptionTrigger( + fallthroughExceptions = timeoutTrigger.exceptions, + label = "AnythingButTimeout" + ) val solverExceptions = setOf( Edge(config_1_1, config_1_2, notTimeout), @@ -229,8 +288,10 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, return STM(config_1_1, timeouts union solverExceptions) } - val inProcess = HierarchicalNode("InProcess", - getStm(!portfolioConfig.debugConfig.debug)) // if not debug, then in process, else not in process + val inProcess = HierarchicalNode( + "InProcess", + getStm(!portfolioConfig.debugConfig.debug) + ) // if not debug, then in process, else not in process val notInProcess = HierarchicalNode("NotInprocess", getStm(false)) val fallbackEdge = Edge(inProcess, notInProcess, ExceptionTrigger(label = "Anything")) @@ -240,40 +301,72 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, fun bitwiseStm(): STM { fun getStm(inProcess: Boolean): STM { - val config_1_1 = ConfigNode("QuickFullExpl_Z3_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, refinement = Refinement.NWT_IT_WP), checker) - val config_2_1 = ConfigNode("EmptyExpl_Z3_$inProcess", + val config_1_1 = ConfigNode( + "QuickFullExpl_Z3_$inProcess", + quickExplConfig.adaptConfig(inProcess = inProcess, refinement = Refinement.NWT_IT_WP), checker + ) + val config_2_1 = ConfigNode( + "EmptyExpl_Z3_$inProcess", emptyExplConfig.adaptConfig(inProcess = inProcess, refinement = Refinement.NWT_IT_WP), - checker) - val config_3_1 = ConfigNode("PredCart_mathsat_5.6.8_$inProcess", - predConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", - refinementSolver = "mathsat:5.6.8"), - checker) - - val config_1_2 = ConfigNode("QuickFullExpl_cvc5_1.0.2_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", + checker + ) + val config_3_1 = ConfigNode( + "PredCart_mathsat_5.6.8_$inProcess", + predConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", + refinementSolver = "mathsat:5.6.8" + ), + checker + ) + + val config_1_2 = ConfigNode( + "QuickFullExpl_cvc5_1.0.2_$inProcess", + quickExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker) - val config_2_2 = ConfigNode("EmptyExpl_cvc5_1.0.2_$inProcess", - emptyExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", + refinement = Refinement.NWT_IT_WP + ), checker + ) + val config_2_2 = ConfigNode( + "EmptyExpl_cvc5_1.0.2_$inProcess", + emptyExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker) - val config_3_2 = ConfigNode("PredCart_z3_4.10.1_$inProcess", - predConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "z3:4.10.1", - refinementSolver = "z3:4.10.1"), checker) + refinement = Refinement.NWT_IT_WP + ), checker + ) + val config_3_2 = ConfigNode( + "PredCart_z3_4.10.1_$inProcess", + predConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "z3:4.10.1", + refinementSolver = "z3:4.10.1" + ), checker + ) - val config_1_3 = ConfigNode("QuickFullExpl_mathsat_5.6.8_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", + val config_1_3 = ConfigNode( + "QuickFullExpl_mathsat_5.6.8_$inProcess", + quickExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", - refinement = Refinement.NWT_IT_WP), checker) - val config_2_3 = ConfigNode("EmptyExpl_mathsat_5.6.8_$inProcess", - emptyExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", + refinement = Refinement.NWT_IT_WP + ), checker + ) + val config_2_3 = ConfigNode( + "EmptyExpl_mathsat_5.6.8_$inProcess", + emptyExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", - refinement = Refinement.SEQ_ITP), checker) - val config_3_3 = ConfigNode("PredCart_cvc5_1.0.2_$inProcess", - predConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", + refinement = Refinement.SEQ_ITP + ), checker + ) + val config_3_3 = ConfigNode( + "PredCart_cvc5_1.0.2_$inProcess", + predConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker) + refinement = Refinement.NWT_IT_WP + ), checker + ) val timeouts = setOf( Edge(config_1_1, config_2_1, timeoutTrigger), @@ -282,15 +375,23 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, Edge(config_1_2, config_2_2, timeoutTrigger), Edge(config_2_2, config_3_1, timeoutTrigger), - Edge(config_1_3, config_2_3, - if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything")), - Edge(config_2_3, config_3_1, - if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything")), + Edge( + config_1_3, config_2_3, + if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything") + ), + Edge( + config_2_3, config_3_1, + if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything") + ), ) - val notTimeout = if (inProcess) ExceptionTrigger(ErrorCodeException(ExitCodes.SOLVER_ERROR.code), - label = "SolverError") else ExceptionTrigger(fallthroughExceptions = timeoutTrigger.exceptions, - label = "AnythingButTimeout") + val notTimeout = if (inProcess) ExceptionTrigger( + ErrorCodeException(ExitCodes.SOLVER_ERROR.code), + label = "SolverError" + ) else ExceptionTrigger( + fallthroughExceptions = timeoutTrigger.exceptions, + label = "AnythingButTimeout" + ) val solverExceptions = setOf( Edge(config_1_1, config_1_2, notTimeout), @@ -305,8 +406,10 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, return STM(config_1_1, timeouts union solverExceptions) } - val inProcess = HierarchicalNode("InProcess", - getStm(!portfolioConfig.debugConfig.debug)) // if not debug, then in process, else not in process + val inProcess = HierarchicalNode( + "InProcess", + getStm(!portfolioConfig.debugConfig.debug) + ) // if not debug, then in process, else not in process val notInProcess = HierarchicalNode("NotInprocess", getStm(false)) val fallbackEdge = Edge(inProcess, notInProcess, ExceptionTrigger(label = "Anything")) @@ -316,74 +419,134 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, fun floatsStm(): STM { fun getStm(inProcess: Boolean): STM { - val config_1_1 = ConfigNode("QuickFullExpl_cvc5_1.0.2_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", + val config_1_1 = ConfigNode( + "QuickFullExpl_cvc5_1.0.2_$inProcess", + quickExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker) - val config_2_1 = ConfigNode("EmptyExpl_cvc5_1.0.2_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", + refinement = Refinement.NWT_IT_WP + ), checker + ) + val config_2_1 = ConfigNode( + "EmptyExpl_cvc5_1.0.2_$inProcess", + quickExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker) - val config_3_1 = ConfigNode("PredCart_mathsat_5.6.8_$inProcess", - predConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", - refinementSolver = "mathsat:5.6.8"), - checker) - - val config_1_2 = ConfigNode("QuickFullExpl_cvc5_1.0.2_seq_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", + refinement = Refinement.NWT_IT_WP + ), checker + ) + val config_3_1 = ConfigNode( + "PredCart_mathsat_5.6.8_$inProcess", + predConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", + refinementSolver = "mathsat:5.6.8" + ), + checker + ) + + val config_1_2 = ConfigNode( + "QuickFullExpl_cvc5_1.0.2_seq_$inProcess", + quickExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.SEQ_ITP), checker) - val config_2_2 = ConfigNode("EmptyExpl_cvc5_1.0.2_seq_$inProcess", - emptyExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", + refinement = Refinement.SEQ_ITP + ), checker + ) + val config_2_2 = ConfigNode( + "EmptyExpl_cvc5_1.0.2_seq_$inProcess", + emptyExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.SEQ_ITP), checker) - val config_3_2 = ConfigNode("PredCart_bitwuzla_latest_$inProcess", - predConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "bitwuzla:latest", + refinement = Refinement.SEQ_ITP + ), checker + ) + val config_3_2 = ConfigNode( + "PredCart_bitwuzla_latest_$inProcess", + predConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "bitwuzla:latest", refinementSolver = "bitwuzla:latest", - refinement = Refinement.NWT_IT_WP), checker) + refinement = Refinement.NWT_IT_WP + ), checker + ) - val config_1_3 = ConfigNode("QuickFullExpl_mathsat_5.6.8_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", + val config_1_3 = ConfigNode( + "QuickFullExpl_mathsat_5.6.8_$inProcess", + quickExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", validateAbstractionSolver = true, validateRefinementSolver = true, - refinement = Refinement.NWT_IT_WP), - checker) - val config_2_3 = ConfigNode("EmptyExpl_mathsat_5.6.8_$inProcess", - emptyExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", + refinement = Refinement.NWT_IT_WP + ), + checker + ) + val config_2_3 = ConfigNode( + "EmptyExpl_mathsat_5.6.8_$inProcess", + emptyExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:5.6.8", refinementSolver = "mathsat:5.6.8", validateAbstractionSolver = true, validateRefinementSolver = true, - refinement = Refinement.NWT_IT_WP), - checker) - val config_3_3 = ConfigNode("PredCart_cvc5_1.0.2_$inProcess", - predConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", + refinement = Refinement.NWT_IT_WP + ), + checker + ) + val config_3_3 = ConfigNode( + "PredCart_cvc5_1.0.2_$inProcess", + predConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "cvc5:1.0.2", refinementSolver = "cvc5:1.0.2", - refinement = Refinement.NWT_IT_WP), checker) + refinement = Refinement.NWT_IT_WP + ), checker + ) - val config_1_4 = ConfigNode("QuickFullExpl_mathsat_fp_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:fp", + val config_1_4 = ConfigNode( + "QuickFullExpl_mathsat_fp_$inProcess", + quickExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:fp", refinementSolver = "mathsat:fp", - validateAbstractionSolver = true, validateRefinementSolver = true), checker) - val config_2_4 = ConfigNode("EmptyExpl_mathsat_fp_$inProcess", - emptyExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:fp", + validateAbstractionSolver = true, validateRefinementSolver = true + ), checker + ) + val config_2_4 = ConfigNode( + "EmptyExpl_mathsat_fp_$inProcess", + emptyExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:fp", refinementSolver = "mathsat:fp", - validateAbstractionSolver = true, validateRefinementSolver = true), checker) - val config_3_4 = ConfigNode("PredCart_mathsat_fp_$inProcess", - predConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "mathsat:fp", + validateAbstractionSolver = true, validateRefinementSolver = true + ), checker + ) + val config_3_4 = ConfigNode( + "PredCart_mathsat_fp_$inProcess", + predConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "mathsat:fp", refinementSolver = "mathsat:fp", - validateAbstractionSolver = true, validateRefinementSolver = true), checker) + validateAbstractionSolver = true, validateRefinementSolver = true + ), checker + ) - val config_1_5 = ConfigNode("QuickFullExpl_Z3_$inProcess", - quickExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "Z3", refinementSolver = "Z3", + val config_1_5 = ConfigNode( + "QuickFullExpl_Z3_$inProcess", + quickExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "Z3", refinementSolver = "Z3", validateAbstractionSolver = true, - validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP), checker) - val config_2_5 = ConfigNode("EmptyExpl_Z3_$inProcess", - emptyExplConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "Z3", refinementSolver = "Z3", + validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP + ), checker + ) + val config_2_5 = ConfigNode( + "EmptyExpl_Z3_$inProcess", + emptyExplConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "Z3", refinementSolver = "Z3", validateAbstractionSolver = true, - validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP), checker) - val config_3_5 = ConfigNode("PredCart_Z3_$inProcess", - predConfig.adaptConfig(inProcess = inProcess, abstractionSolver = "Z3", refinementSolver = "Z3", - refinement = Refinement.NWT_IT_WP), - checker) + validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP + ), checker + ) + val config_3_5 = ConfigNode( + "PredCart_Z3_$inProcess", + predConfig.adaptConfig( + inProcess = inProcess, abstractionSolver = "Z3", refinementSolver = "Z3", + refinement = Refinement.NWT_IT_WP + ), + checker + ) val timeouts = setOf( Edge(config_1_1, config_2_1, timeoutTrigger), @@ -398,15 +561,23 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, Edge(config_1_4, config_2_4, timeoutTrigger), Edge(config_2_4, config_3_1, timeoutTrigger), - Edge(config_1_5, config_2_5, - if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything")), - Edge(config_2_5, config_3_1, - if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything")), + Edge( + config_1_5, config_2_5, + if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything") + ), + Edge( + config_2_5, config_3_1, + if (inProcess) timeoutOrSolverError else ExceptionTrigger(label = "Anything") + ), ) - val notTimeout = if (inProcess) ExceptionTrigger(ErrorCodeException(ExitCodes.SOLVER_ERROR.code), - label = "SolverError") else ExceptionTrigger(fallthroughExceptions = timeoutTrigger.exceptions, - label = "AnythingButTimeout") + val notTimeout = if (inProcess) ExceptionTrigger( + ErrorCodeException(ExitCodes.SOLVER_ERROR.code), + label = "SolverError" + ) else ExceptionTrigger( + fallthroughExceptions = timeoutTrigger.exceptions, + label = "AnythingButTimeout" + ) val solverExceptions = setOf( Edge(config_1_1, config_1_2, notTimeout), @@ -427,8 +598,10 @@ fun complexPortfolio23(xcfa: XCFA, mcm: MCM, return STM(config_1_1, timeouts union solverExceptions) } - val inProcess = HierarchicalNode("InProcess", - getStm(!portfolioConfig.debugConfig.debug)) // if not debug, then in process, else not in process + val inProcess = HierarchicalNode( + "InProcess", + getStm(!portfolioConfig.debugConfig.debug) + ) // if not debug, then in process, else not in process val notInProcess = HierarchicalNode("NotInprocess", getStm(false)) val fallbackEdge = Edge(inProcess, notInProcess, ExceptionTrigger(label = "Anything")) diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex24.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex24.kt index ca6f147553..8a5c005c3e 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex24.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex24.kt @@ -37,7 +37,8 @@ fun complexPortfolio24( parseContext: ParseContext, portfolioConfig: XcfaConfig<*, *>, logger: Logger, - uniqueLogger: Logger): STM { + uniqueLogger: Logger +): STM { val checker = { config: XcfaConfig<*, *> -> runConfig(config, logger, uniqueLogger, true) } @@ -46,12 +47,14 @@ fun complexPortfolio24( input = null, xcfaWCtx = Triple(xcfa, mcm, parseContext), propertyFile = null, - property = portfolioConfig.inputConfig.property), + property = portfolioConfig.inputConfig.property + ), frontendConfig = FrontendConfig( lbeLevel = LbePass.level, loopUnroll = LoopUnrollPass.UNROLL_LIMIT, inputType = InputType.C, - specConfig = CFrontendConfig(arithmetic = ArchitectureConfig.ArithmeticType.efficient)), + specConfig = CFrontendConfig(arithmetic = ArchitectureConfig.ArithmeticType.efficient) + ), backendConfig = BackendConfig( backend = Backend.CEGAR, solverHome = portfolioConfig.backendConfig.solverHome, @@ -75,7 +78,9 @@ fun complexPortfolio24( refinement = Refinement.SEQ_ITP, exprSplitter = ExprSplitterOptions.WHOLE, pruneStrategy = PruneStrategy.FULL - ))), + ) + ) + ), outputConfig = OutputConfig( versionInfo = false, resultFolder = Paths.get("./").toFile(), // cwd @@ -95,7 +100,8 @@ fun complexPortfolio24( abstractorConfig = baseCegarConfig.abstractorConfig.copy(search = Search.DFS), ) baseConfig = baseConfig.copy( - backendConfig = baseConfig.backendConfig.copy(specConfig = multiThreadedCegarConfig)) + backendConfig = baseConfig.backendConfig.copy(specConfig = multiThreadedCegarConfig) + ) } if (!xcfa.isInlined) { @@ -140,28 +146,31 @@ fun complexPortfolio24( validateRefinementSolver: Boolean = this.backendConfig.specConfig!!.refinerConfig.validateRefinementSolver, inProcess: Boolean = this.backendConfig.inProcess ): XcfaConfig<*, CegarConfig> { - return copy(backendConfig = backendConfig.copy( - timeoutMs = timeoutMs, - inProcess = inProcess, - specConfig = backendConfig.specConfig!!.copy( - initPrec = initPrec, - abstractorConfig = backendConfig.specConfig!!.abstractorConfig.copy( - abstractionSolver = abstractionSolver, - validateAbstractionSolver = validateAbstractionSolver, - domain = domain, - ), - refinerConfig = backendConfig.specConfig!!.refinerConfig.copy( - refinementSolver = refinementSolver, - validateRefinementSolver = validateRefinementSolver, - refinement = refinement, + return copy( + backendConfig = backendConfig.copy( + timeoutMs = timeoutMs, + inProcess = inProcess, + specConfig = backendConfig.specConfig!!.copy( + initPrec = initPrec, + abstractorConfig = backendConfig.specConfig!!.abstractorConfig.copy( + abstractionSolver = abstractionSolver, + validateAbstractionSolver = validateAbstractionSolver, + domain = domain, + ), + refinerConfig = backendConfig.specConfig!!.refinerConfig.copy( + refinementSolver = refinementSolver, + validateRefinementSolver = validateRefinementSolver, + refinement = refinement, + ) ) ) - )) + ) } fun getStm(trait: ArithmeticTrait, inProcess: Boolean): STM { val edges = LinkedHashSet() - val config_BITWISE_EXPL_NWT_IT_WP_cvc5 = ConfigNode("BITWISE_EXPL_NWT_IT_WP_cvc5:1.0.8-$inProcess", + val config_BITWISE_EXPL_NWT_IT_WP_cvc5 = ConfigNode( + "BITWISE_EXPL_NWT_IT_WP_cvc5:1.0.8-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -169,8 +178,10 @@ fun complexPortfolio24( refinementSolver = "cvc5:1.0.8", refinement = Refinement.NWT_IT_WP, timeoutMs = 100000 - ), checker) - val config_BITWISE_EXPL_NWT_IT_WP_Z3 = ConfigNode("BITWISE_EXPL_NWT_IT_WP_Z3-$inProcess", + ), checker + ) + val config_BITWISE_EXPL_NWT_IT_WP_Z3 = ConfigNode( + "BITWISE_EXPL_NWT_IT_WP_Z3-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -178,9 +189,11 @@ fun complexPortfolio24( refinementSolver = "Z3", refinement = Refinement.NWT_IT_WP, timeoutMs = 100000 - ), checker) + ), checker + ) edges.add(Edge(config_BITWISE_EXPL_NWT_IT_WP_cvc5, config_BITWISE_EXPL_NWT_IT_WP_Z3, solverError)) - val config_BITWISE_EXPL_NWT_IT_WP_mathsat = ConfigNode("BITWISE_EXPL_NWT_IT_WP_mathsat:5.6.10-$inProcess", + val config_BITWISE_EXPL_NWT_IT_WP_mathsat = ConfigNode( + "BITWISE_EXPL_NWT_IT_WP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -188,9 +201,11 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", refinement = Refinement.NWT_IT_WP, timeoutMs = 100000 - ), checker) + ), checker + ) edges.add(Edge(config_BITWISE_EXPL_NWT_IT_WP_Z3, config_BITWISE_EXPL_NWT_IT_WP_mathsat, solverError)) - val config_BITWISE_PRED_CART_SEQ_ITP_mathsat = ConfigNode("BITWISE_PRED_CART_SEQ_ITP_mathsat:5.6.10-$inProcess", + val config_BITWISE_PRED_CART_SEQ_ITP_mathsat = ConfigNode( + "BITWISE_PRED_CART_SEQ_ITP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -198,14 +213,28 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) - edges.add(Edge(config_BITWISE_EXPL_NWT_IT_WP_cvc5, config_BITWISE_PRED_CART_SEQ_ITP_mathsat, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_BITWISE_EXPL_NWT_IT_WP_Z3, config_BITWISE_PRED_CART_SEQ_ITP_mathsat, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_BITWISE_EXPL_NWT_IT_WP_mathsat, config_BITWISE_PRED_CART_SEQ_ITP_mathsat, - if (inProcess) timeoutOrSolverError else anyError)) - val config_BITWISE_PRED_CART_SEQ_ITP_cvc5 = ConfigNode("BITWISE_PRED_CART_SEQ_ITP_cvc5:1.0.8-$inProcess", + ), checker + ) + edges.add( + Edge( + config_BITWISE_EXPL_NWT_IT_WP_cvc5, config_BITWISE_PRED_CART_SEQ_ITP_mathsat, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_BITWISE_EXPL_NWT_IT_WP_Z3, config_BITWISE_PRED_CART_SEQ_ITP_mathsat, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_BITWISE_EXPL_NWT_IT_WP_mathsat, config_BITWISE_PRED_CART_SEQ_ITP_mathsat, + if (inProcess) timeoutOrSolverError else anyError + ) + ) + val config_BITWISE_PRED_CART_SEQ_ITP_cvc5 = ConfigNode( + "BITWISE_PRED_CART_SEQ_ITP_cvc5:1.0.8-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -213,9 +242,11 @@ fun complexPortfolio24( refinementSolver = "cvc5:1.0.8", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) + ), checker + ) edges.add(Edge(config_BITWISE_PRED_CART_SEQ_ITP_mathsat, config_BITWISE_PRED_CART_SEQ_ITP_cvc5, solverError)) - val config_BITWISE_EXPL_SEQ_ITP_mathsat = ConfigNode("BITWISE_EXPL_SEQ_ITP_mathsat:5.6.10-$inProcess", + val config_BITWISE_EXPL_SEQ_ITP_mathsat = ConfigNode( + "BITWISE_EXPL_SEQ_ITP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -223,12 +254,22 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) - edges.add(Edge(config_BITWISE_PRED_CART_SEQ_ITP_mathsat, config_BITWISE_EXPL_SEQ_ITP_mathsat, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_BITWISE_PRED_CART_SEQ_ITP_cvc5, config_BITWISE_EXPL_SEQ_ITP_mathsat, - if (inProcess) timeoutOrSolverError else anyError)) - val config_BITWISE_EXPL_SEQ_ITP_cvc5 = ConfigNode("BITWISE_EXPL_SEQ_ITP_cvc5:1.0.8-$inProcess", + ), checker + ) + edges.add( + Edge( + config_BITWISE_PRED_CART_SEQ_ITP_mathsat, config_BITWISE_EXPL_SEQ_ITP_mathsat, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_BITWISE_PRED_CART_SEQ_ITP_cvc5, config_BITWISE_EXPL_SEQ_ITP_mathsat, + if (inProcess) timeoutOrSolverError else anyError + ) + ) + val config_BITWISE_EXPL_SEQ_ITP_cvc5 = ConfigNode( + "BITWISE_EXPL_SEQ_ITP_cvc5:1.0.8-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -236,9 +277,11 @@ fun complexPortfolio24( refinementSolver = "cvc5:1.0.8", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) + ), checker + ) edges.add(Edge(config_BITWISE_EXPL_SEQ_ITP_mathsat, config_BITWISE_EXPL_SEQ_ITP_cvc5, solverError)) - val config_FLOAT_EXPL_NWT_IT_WP_cvc5 = ConfigNode("FLOAT_EXPL_NWT_IT_WP_cvc5:1.0.8-$inProcess", + val config_FLOAT_EXPL_NWT_IT_WP_cvc5 = ConfigNode( + "FLOAT_EXPL_NWT_IT_WP_cvc5:1.0.8-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -246,17 +289,21 @@ fun complexPortfolio24( refinementSolver = "cvc5:1.0.8", refinement = Refinement.NWT_IT_WP, timeoutMs = 200000 - ), checker) - val config_FLOAT_EXPL_NWT_IT_WP_Z3 = ConfigNode("FLOAT_EXPL_NWT_IT_WP_Z3-$inProcess", baseConfig.adaptConfig( - inProcess = inProcess, - domain = Domain.EXPL, - abstractionSolver = "Z3", - refinementSolver = "Z3", - refinement = Refinement.NWT_IT_WP, - timeoutMs = 200000 - ), checker) + ), checker + ) + val config_FLOAT_EXPL_NWT_IT_WP_Z3 = ConfigNode( + "FLOAT_EXPL_NWT_IT_WP_Z3-$inProcess", baseConfig.adaptConfig( + inProcess = inProcess, + domain = Domain.EXPL, + abstractionSolver = "Z3", + refinementSolver = "Z3", + refinement = Refinement.NWT_IT_WP, + timeoutMs = 200000 + ), checker + ) edges.add(Edge(config_FLOAT_EXPL_NWT_IT_WP_cvc5, config_FLOAT_EXPL_NWT_IT_WP_Z3, solverError)) - val config_FLOAT_EXPL_NWT_IT_WP_mathsat = ConfigNode("FLOAT_EXPL_NWT_IT_WP_mathsat:5.6.10-$inProcess", + val config_FLOAT_EXPL_NWT_IT_WP_mathsat = ConfigNode( + "FLOAT_EXPL_NWT_IT_WP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -264,9 +311,11 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", validateRefinementSolver = true, refinement = Refinement.NWT_IT_WP, timeoutMs = 200000 - ), checker) + ), checker + ) edges.add(Edge(config_FLOAT_EXPL_NWT_IT_WP_Z3, config_FLOAT_EXPL_NWT_IT_WP_mathsat, solverError)) - val config_FLOAT_PRED_CART_SEQ_ITP_mathsat = ConfigNode("FLOAT_PRED_CART_SEQ_ITP_mathsat:5.6.10-$inProcess", + val config_FLOAT_PRED_CART_SEQ_ITP_mathsat = ConfigNode( + "FLOAT_PRED_CART_SEQ_ITP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -274,14 +323,28 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", validateRefinementSolver = true, refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) - edges.add(Edge(config_FLOAT_EXPL_NWT_IT_WP_cvc5, config_FLOAT_PRED_CART_SEQ_ITP_mathsat, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_FLOAT_EXPL_NWT_IT_WP_Z3, config_FLOAT_PRED_CART_SEQ_ITP_mathsat, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_FLOAT_EXPL_NWT_IT_WP_mathsat, config_FLOAT_PRED_CART_SEQ_ITP_mathsat, - if (inProcess) timeoutOrSolverError else anyError)) - val config_FLOAT_PRED_CART_SEQ_ITP_cvc5 = ConfigNode("FLOAT_PRED_CART_SEQ_ITP_cvc5:1.0.8-$inProcess", + ), checker + ) + edges.add( + Edge( + config_FLOAT_EXPL_NWT_IT_WP_cvc5, config_FLOAT_PRED_CART_SEQ_ITP_mathsat, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_FLOAT_EXPL_NWT_IT_WP_Z3, config_FLOAT_PRED_CART_SEQ_ITP_mathsat, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_FLOAT_EXPL_NWT_IT_WP_mathsat, config_FLOAT_PRED_CART_SEQ_ITP_mathsat, + if (inProcess) timeoutOrSolverError else anyError + ) + ) + val config_FLOAT_PRED_CART_SEQ_ITP_cvc5 = ConfigNode( + "FLOAT_PRED_CART_SEQ_ITP_cvc5:1.0.8-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -289,9 +352,11 @@ fun complexPortfolio24( refinementSolver = "cvc5:1.0.8", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) + ), checker + ) edges.add(Edge(config_FLOAT_PRED_CART_SEQ_ITP_mathsat, config_FLOAT_PRED_CART_SEQ_ITP_cvc5, solverError)) - val config_FLOAT_EXPL_SEQ_ITP_mathsat = ConfigNode("FLOAT_EXPL_SEQ_ITP_mathsat:5.6.10-$inProcess", + val config_FLOAT_EXPL_SEQ_ITP_mathsat = ConfigNode( + "FLOAT_EXPL_SEQ_ITP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -299,12 +364,22 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", validateRefinementSolver = true, refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) - edges.add(Edge(config_FLOAT_PRED_CART_SEQ_ITP_mathsat, config_FLOAT_EXPL_SEQ_ITP_mathsat, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_FLOAT_PRED_CART_SEQ_ITP_cvc5, config_FLOAT_EXPL_SEQ_ITP_mathsat, - if (inProcess) timeoutOrSolverError else anyError)) - val config_FLOAT_EXPL_SEQ_ITP_cvc5 = ConfigNode("FLOAT_EXPL_SEQ_ITP_cvc5:1.0.8-$inProcess", + ), checker + ) + edges.add( + Edge( + config_FLOAT_PRED_CART_SEQ_ITP_mathsat, config_FLOAT_EXPL_SEQ_ITP_mathsat, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_FLOAT_PRED_CART_SEQ_ITP_cvc5, config_FLOAT_EXPL_SEQ_ITP_mathsat, + if (inProcess) timeoutOrSolverError else anyError + ) + ) + val config_FLOAT_EXPL_SEQ_ITP_cvc5 = ConfigNode( + "FLOAT_EXPL_SEQ_ITP_cvc5:1.0.8-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -312,9 +387,11 @@ fun complexPortfolio24( refinementSolver = "cvc5:1.0.8", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) + ), checker + ) edges.add(Edge(config_FLOAT_EXPL_SEQ_ITP_mathsat, config_FLOAT_EXPL_SEQ_ITP_cvc5, solverError)) - val config_LIN_INT_EXPL_NWT_IT_WP_mathsat = ConfigNode("LIN_INT_EXPL_NWT_IT_WP_mathsat:5.6.10-$inProcess", + val config_LIN_INT_EXPL_NWT_IT_WP_mathsat = ConfigNode( + "LIN_INT_EXPL_NWT_IT_WP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -322,8 +399,10 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", refinement = Refinement.NWT_IT_WP, timeoutMs = 100000 - ), checker) - val config_LIN_INT_EXPL_NWT_IT_WP_Z3 = ConfigNode("LIN_INT_EXPL_NWT_IT_WP_Z3-$inProcess", + ), checker + ) + val config_LIN_INT_EXPL_NWT_IT_WP_Z3 = ConfigNode( + "LIN_INT_EXPL_NWT_IT_WP_Z3-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -331,21 +410,33 @@ fun complexPortfolio24( refinementSolver = "Z3", refinement = Refinement.NWT_IT_WP, timeoutMs = 100000 - ), checker) + ), checker + ) edges.add(Edge(config_LIN_INT_EXPL_NWT_IT_WP_mathsat, config_LIN_INT_EXPL_NWT_IT_WP_Z3, solverError)) - val config_LIN_INT_EXPL_SEQ_ITP_Z3 = ConfigNode("LIN_INT_EXPL_SEQ_ITP_Z3-$inProcess", baseConfig.adaptConfig( - inProcess = inProcess, - domain = Domain.EXPL, - abstractionSolver = "Z3", - refinementSolver = "Z3", - refinement = Refinement.SEQ_ITP, - timeoutMs = 300000 - ), checker) - edges.add(Edge(config_LIN_INT_EXPL_NWT_IT_WP_mathsat, config_LIN_INT_EXPL_SEQ_ITP_Z3, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_LIN_INT_EXPL_NWT_IT_WP_Z3, config_LIN_INT_EXPL_SEQ_ITP_Z3, - if (inProcess) timeoutOrSolverError else anyError)) - val config_LIN_INT_EXPL_SEQ_ITP_mathsat = ConfigNode("LIN_INT_EXPL_SEQ_ITP_mathsat:5.6.10-$inProcess", + val config_LIN_INT_EXPL_SEQ_ITP_Z3 = ConfigNode( + "LIN_INT_EXPL_SEQ_ITP_Z3-$inProcess", baseConfig.adaptConfig( + inProcess = inProcess, + domain = Domain.EXPL, + abstractionSolver = "Z3", + refinementSolver = "Z3", + refinement = Refinement.SEQ_ITP, + timeoutMs = 300000 + ), checker + ) + edges.add( + Edge( + config_LIN_INT_EXPL_NWT_IT_WP_mathsat, config_LIN_INT_EXPL_SEQ_ITP_Z3, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_LIN_INT_EXPL_NWT_IT_WP_Z3, config_LIN_INT_EXPL_SEQ_ITP_Z3, + if (inProcess) timeoutOrSolverError else anyError + ) + ) + val config_LIN_INT_EXPL_SEQ_ITP_mathsat = ConfigNode( + "LIN_INT_EXPL_SEQ_ITP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -353,9 +444,11 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", refinement = Refinement.SEQ_ITP, timeoutMs = 300000 - ), checker) + ), checker + ) edges.add(Edge(config_LIN_INT_EXPL_SEQ_ITP_Z3, config_LIN_INT_EXPL_SEQ_ITP_mathsat, solverError)) - val config_LIN_INT_PRED_CART_SEQ_ITP_Z3 = ConfigNode("LIN_INT_PRED_CART_SEQ_ITP_Z3-$inProcess", + val config_LIN_INT_PRED_CART_SEQ_ITP_Z3 = ConfigNode( + "LIN_INT_PRED_CART_SEQ_ITP_Z3-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -363,12 +456,22 @@ fun complexPortfolio24( refinementSolver = "Z3", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) - edges.add(Edge(config_LIN_INT_EXPL_SEQ_ITP_Z3, config_LIN_INT_PRED_CART_SEQ_ITP_Z3, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_LIN_INT_EXPL_SEQ_ITP_mathsat, config_LIN_INT_PRED_CART_SEQ_ITP_Z3, - if (inProcess) timeoutOrSolverError else anyError)) - val config_LIN_INT_PRED_CART_SEQ_ITP_mathsat = ConfigNode("LIN_INT_PRED_CART_SEQ_ITP_mathsat:5.6.10-$inProcess", + ), checker + ) + edges.add( + Edge( + config_LIN_INT_EXPL_SEQ_ITP_Z3, config_LIN_INT_PRED_CART_SEQ_ITP_Z3, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_LIN_INT_EXPL_SEQ_ITP_mathsat, config_LIN_INT_PRED_CART_SEQ_ITP_Z3, + if (inProcess) timeoutOrSolverError else anyError + ) + ) + val config_LIN_INT_PRED_CART_SEQ_ITP_mathsat = ConfigNode( + "LIN_INT_PRED_CART_SEQ_ITP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -376,9 +479,11 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) + ), checker + ) edges.add(Edge(config_LIN_INT_PRED_CART_SEQ_ITP_Z3, config_LIN_INT_PRED_CART_SEQ_ITP_mathsat, solverError)) - val config_LIN_INT_PRED_CART_SEQ_ITP_z3 = ConfigNode("LIN_INT_PRED_CART_SEQ_ITP_z3:4.12.2-$inProcess", + val config_LIN_INT_PRED_CART_SEQ_ITP_z3 = ConfigNode( + "LIN_INT_PRED_CART_SEQ_ITP_z3:4.12.2-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -386,9 +491,11 @@ fun complexPortfolio24( refinementSolver = "z3:4.12.2", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) + ), checker + ) edges.add(Edge(config_LIN_INT_PRED_CART_SEQ_ITP_mathsat, config_LIN_INT_PRED_CART_SEQ_ITP_z3, solverError)) - val config_NONLIN_INT_EXPL_NWT_IT_WP_Z3 = ConfigNode("NONLIN_INT_EXPL_NWT_IT_WP_Z3-$inProcess", + val config_NONLIN_INT_EXPL_NWT_IT_WP_Z3 = ConfigNode( + "NONLIN_INT_EXPL_NWT_IT_WP_Z3-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -396,8 +503,10 @@ fun complexPortfolio24( refinementSolver = "Z3", refinement = Refinement.NWT_IT_WP, timeoutMs = 100000 - ), checker) - val config_NONLIN_INT_EXPL_NWT_IT_WP_mathsat = ConfigNode("NONLIN_INT_EXPL_NWT_IT_WP_mathsat:5.6.10-$inProcess", + ), checker + ) + val config_NONLIN_INT_EXPL_NWT_IT_WP_mathsat = ConfigNode( + "NONLIN_INT_EXPL_NWT_IT_WP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -405,9 +514,11 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", refinement = Refinement.NWT_IT_WP, timeoutMs = 100000 - ), checker) + ), checker + ) edges.add(Edge(config_NONLIN_INT_EXPL_NWT_IT_WP_Z3, config_NONLIN_INT_EXPL_NWT_IT_WP_mathsat, solverError)) - val config_NONLIN_INT_EXPL_SEQ_ITP_Z3 = ConfigNode("NONLIN_INT_EXPL_SEQ_ITP_Z3-$inProcess", + val config_NONLIN_INT_EXPL_SEQ_ITP_Z3 = ConfigNode( + "NONLIN_INT_EXPL_SEQ_ITP_Z3-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -415,12 +526,22 @@ fun complexPortfolio24( refinementSolver = "Z3", refinement = Refinement.SEQ_ITP, timeoutMs = 100000 - ), checker) - edges.add(Edge(config_NONLIN_INT_EXPL_NWT_IT_WP_Z3, config_NONLIN_INT_EXPL_SEQ_ITP_Z3, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_NONLIN_INT_EXPL_NWT_IT_WP_mathsat, config_NONLIN_INT_EXPL_SEQ_ITP_Z3, - if (inProcess) timeoutOrSolverError else anyError)) - val config_NONLIN_INT_EXPL_SEQ_ITP_z3 = ConfigNode("NONLIN_INT_EXPL_SEQ_ITP_z3:4.12.2-$inProcess", + ), checker + ) + edges.add( + Edge( + config_NONLIN_INT_EXPL_NWT_IT_WP_Z3, config_NONLIN_INT_EXPL_SEQ_ITP_Z3, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_NONLIN_INT_EXPL_NWT_IT_WP_mathsat, config_NONLIN_INT_EXPL_SEQ_ITP_Z3, + if (inProcess) timeoutOrSolverError else anyError + ) + ) + val config_NONLIN_INT_EXPL_SEQ_ITP_z3 = ConfigNode( + "NONLIN_INT_EXPL_SEQ_ITP_z3:4.12.2-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -428,9 +549,11 @@ fun complexPortfolio24( refinementSolver = "z3:4.12.2", refinement = Refinement.SEQ_ITP, timeoutMs = 100000 - ), checker) + ), checker + ) edges.add(Edge(config_NONLIN_INT_EXPL_SEQ_ITP_Z3, config_NONLIN_INT_EXPL_SEQ_ITP_z3, solverError)) - val config_NONLIN_INT_EXPL_SEQ_ITP_mathsat = ConfigNode("NONLIN_INT_EXPL_SEQ_ITP_mathsat:5.6.10-$inProcess", + val config_NONLIN_INT_EXPL_SEQ_ITP_mathsat = ConfigNode( + "NONLIN_INT_EXPL_SEQ_ITP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -438,23 +561,38 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", refinement = Refinement.SEQ_ITP, timeoutMs = 200000 - ), checker) - edges.add(Edge(config_NONLIN_INT_EXPL_SEQ_ITP_Z3, config_NONLIN_INT_EXPL_SEQ_ITP_mathsat, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_NONLIN_INT_EXPL_SEQ_ITP_z3, config_NONLIN_INT_EXPL_SEQ_ITP_mathsat, - if (inProcess) timeoutOrSolverError else anyError)) + ), checker + ) + edges.add( + Edge( + config_NONLIN_INT_EXPL_SEQ_ITP_Z3, config_NONLIN_INT_EXPL_SEQ_ITP_mathsat, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_NONLIN_INT_EXPL_SEQ_ITP_z3, config_NONLIN_INT_EXPL_SEQ_ITP_mathsat, + if (inProcess) timeoutOrSolverError else anyError + ) + ) val config_NONLIN_INT_PRED_CART_SEQ_ITP_mathsat = ConfigNode( "NONLIN_INT_PRED_CART_SEQ_ITP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( - inProcess = inProcess, - domain = Domain.PRED_CART, - abstractionSolver = "mathsat:5.6.10", - refinementSolver = "mathsat:5.6.10", - refinement = Refinement.SEQ_ITP, - timeoutMs = 0 - ), checker) - edges.add(Edge(config_NONLIN_INT_EXPL_SEQ_ITP_mathsat, config_NONLIN_INT_PRED_CART_SEQ_ITP_mathsat, - if (inProcess) timeoutOrSolverError else anyError)) - val config_NONLIN_INT_PRED_CART_SEQ_ITP_Z3 = ConfigNode("NONLIN_INT_PRED_CART_SEQ_ITP_Z3-$inProcess", + inProcess = inProcess, + domain = Domain.PRED_CART, + abstractionSolver = "mathsat:5.6.10", + refinementSolver = "mathsat:5.6.10", + refinement = Refinement.SEQ_ITP, + timeoutMs = 0 + ), checker + ) + edges.add( + Edge( + config_NONLIN_INT_EXPL_SEQ_ITP_mathsat, config_NONLIN_INT_PRED_CART_SEQ_ITP_mathsat, + if (inProcess) timeoutOrSolverError else anyError + ) + ) + val config_NONLIN_INT_PRED_CART_SEQ_ITP_Z3 = ConfigNode( + "NONLIN_INT_PRED_CART_SEQ_ITP_Z3-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -462,10 +600,13 @@ fun complexPortfolio24( refinementSolver = "Z3", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) + ), checker + ) edges.add( - Edge(config_NONLIN_INT_PRED_CART_SEQ_ITP_mathsat, config_NONLIN_INT_PRED_CART_SEQ_ITP_Z3, solverError)) - val config_NONLIN_INT_EXPL_NWT_IT_WP_cvc5 = ConfigNode("NONLIN_INT_EXPL_NWT_IT_WP_cvc5:1.0.8-$inProcess", + Edge(config_NONLIN_INT_PRED_CART_SEQ_ITP_mathsat, config_NONLIN_INT_PRED_CART_SEQ_ITP_Z3, solverError) + ) + val config_NONLIN_INT_EXPL_NWT_IT_WP_cvc5 = ConfigNode( + "NONLIN_INT_EXPL_NWT_IT_WP_cvc5:1.0.8-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -473,12 +614,22 @@ fun complexPortfolio24( refinementSolver = "cvc5:1.0.8", refinement = Refinement.NWT_IT_WP, timeoutMs = 0 - ), checker) - edges.add(Edge(config_NONLIN_INT_PRED_CART_SEQ_ITP_mathsat, config_NONLIN_INT_EXPL_NWT_IT_WP_cvc5, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_NONLIN_INT_PRED_CART_SEQ_ITP_Z3, config_NONLIN_INT_EXPL_NWT_IT_WP_cvc5, - if (inProcess) timeoutOrSolverError else anyError)) - val config_ARR_EXPL_NWT_IT_WP_cvc5 = ConfigNode("ARR_EXPL_NWT_IT_WP_cvc5:1.0.8-$inProcess", + ), checker + ) + edges.add( + Edge( + config_NONLIN_INT_PRED_CART_SEQ_ITP_mathsat, config_NONLIN_INT_EXPL_NWT_IT_WP_cvc5, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_NONLIN_INT_PRED_CART_SEQ_ITP_Z3, config_NONLIN_INT_EXPL_NWT_IT_WP_cvc5, + if (inProcess) timeoutOrSolverError else anyError + ) + ) + val config_ARR_EXPL_NWT_IT_WP_cvc5 = ConfigNode( + "ARR_EXPL_NWT_IT_WP_cvc5:1.0.8-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -486,29 +637,43 @@ fun complexPortfolio24( refinementSolver = "cvc5:1.0.8", refinement = Refinement.NWT_IT_WP, timeoutMs = 100000 - ), checker) - val config_ARR_EXPL_NWT_IT_WP_Z3 = ConfigNode("ARR_EXPL_NWT_IT_WP_Z3-$inProcess", baseConfig.adaptConfig( - inProcess = inProcess, - domain = Domain.EXPL, - abstractionSolver = "Z3", - refinementSolver = "Z3", - refinement = Refinement.NWT_IT_WP, - timeoutMs = 100000 - ), checker) + ), checker + ) + val config_ARR_EXPL_NWT_IT_WP_Z3 = ConfigNode( + "ARR_EXPL_NWT_IT_WP_Z3-$inProcess", baseConfig.adaptConfig( + inProcess = inProcess, + domain = Domain.EXPL, + abstractionSolver = "Z3", + refinementSolver = "Z3", + refinement = Refinement.NWT_IT_WP, + timeoutMs = 100000 + ), checker + ) edges.add(Edge(config_ARR_EXPL_NWT_IT_WP_cvc5, config_ARR_EXPL_NWT_IT_WP_Z3, solverError)) - val config_ARR_PRED_CART_SEQ_ITP_Z3 = ConfigNode("ARR_PRED_CART_SEQ_ITP_Z3-$inProcess", baseConfig.adaptConfig( - inProcess = inProcess, - domain = Domain.PRED_CART, - abstractionSolver = "Z3", - refinementSolver = "Z3", - refinement = Refinement.SEQ_ITP, - timeoutMs = 300000 - ), checker) - edges.add(Edge(config_ARR_EXPL_NWT_IT_WP_cvc5, config_ARR_PRED_CART_SEQ_ITP_Z3, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_ARR_EXPL_NWT_IT_WP_Z3, config_ARR_PRED_CART_SEQ_ITP_Z3, - if (inProcess) timeoutOrSolverError else anyError)) - val config_ARR_PRED_CART_SEQ_ITP_z3 = ConfigNode("ARR_PRED_CART_SEQ_ITP_z3:4.12.2-$inProcess", + val config_ARR_PRED_CART_SEQ_ITP_Z3 = ConfigNode( + "ARR_PRED_CART_SEQ_ITP_Z3-$inProcess", baseConfig.adaptConfig( + inProcess = inProcess, + domain = Domain.PRED_CART, + abstractionSolver = "Z3", + refinementSolver = "Z3", + refinement = Refinement.SEQ_ITP, + timeoutMs = 300000 + ), checker + ) + edges.add( + Edge( + config_ARR_EXPL_NWT_IT_WP_cvc5, config_ARR_PRED_CART_SEQ_ITP_Z3, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_ARR_EXPL_NWT_IT_WP_Z3, config_ARR_PRED_CART_SEQ_ITP_Z3, + if (inProcess) timeoutOrSolverError else anyError + ) + ) + val config_ARR_PRED_CART_SEQ_ITP_z3 = ConfigNode( + "ARR_PRED_CART_SEQ_ITP_z3:4.12.2-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -516,9 +681,11 @@ fun complexPortfolio24( refinementSolver = "z3:4.12.2", refinement = Refinement.SEQ_ITP, timeoutMs = 300000 - ), checker) + ), checker + ) edges.add(Edge(config_ARR_PRED_CART_SEQ_ITP_Z3, config_ARR_PRED_CART_SEQ_ITP_z3, solverError)) - val config_ARR_PRED_CART_SEQ_ITP_princess = ConfigNode("ARR_PRED_CART_SEQ_ITP_princess:2023-06-19-$inProcess", + val config_ARR_PRED_CART_SEQ_ITP_princess = ConfigNode( + "ARR_PRED_CART_SEQ_ITP_princess:2023-06-19-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -526,12 +693,22 @@ fun complexPortfolio24( refinementSolver = "princess:2023-06-19", refinement = Refinement.SEQ_ITP, timeoutMs = 500000 - ), checker) - edges.add(Edge(config_ARR_PRED_CART_SEQ_ITP_Z3, config_ARR_PRED_CART_SEQ_ITP_princess, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_ARR_PRED_CART_SEQ_ITP_z3, config_ARR_PRED_CART_SEQ_ITP_princess, - if (inProcess) timeoutOrSolverError else anyError)) - val config_ARR_PRED_CART_SEQ_ITP_cvc5 = ConfigNode("ARR_PRED_CART_SEQ_ITP_cvc5:1.0.8-$inProcess", + ), checker + ) + edges.add( + Edge( + config_ARR_PRED_CART_SEQ_ITP_Z3, config_ARR_PRED_CART_SEQ_ITP_princess, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_ARR_PRED_CART_SEQ_ITP_z3, config_ARR_PRED_CART_SEQ_ITP_princess, + if (inProcess) timeoutOrSolverError else anyError + ) + ) + val config_ARR_PRED_CART_SEQ_ITP_cvc5 = ConfigNode( + "ARR_PRED_CART_SEQ_ITP_cvc5:1.0.8-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -539,9 +716,11 @@ fun complexPortfolio24( refinementSolver = "cvc5:1.0.8", refinement = Refinement.SEQ_ITP, timeoutMs = 500000 - ), checker) + ), checker + ) edges.add(Edge(config_ARR_PRED_CART_SEQ_ITP_princess, config_ARR_PRED_CART_SEQ_ITP_cvc5, solverError)) - val config_MULTITHREAD_EXPL_SEQ_ITP_Z3 = ConfigNode("MULTITHREAD_EXPL_SEQ_ITP_Z3-$inProcess", + val config_MULTITHREAD_EXPL_SEQ_ITP_Z3 = ConfigNode( + "MULTITHREAD_EXPL_SEQ_ITP_Z3-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -549,8 +728,10 @@ fun complexPortfolio24( refinementSolver = "Z3", refinement = Refinement.SEQ_ITP, timeoutMs = 150000 - ), checker) - val config_MULTITHREAD_EXPL_SEQ_ITP_mathsat = ConfigNode("MULTITHREAD_EXPL_SEQ_ITP_mathsat:5.6.10-$inProcess", + ), checker + ) + val config_MULTITHREAD_EXPL_SEQ_ITP_mathsat = ConfigNode( + "MULTITHREAD_EXPL_SEQ_ITP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -558,9 +739,11 @@ fun complexPortfolio24( refinementSolver = "mathsat:5.6.10", refinement = Refinement.SEQ_ITP, timeoutMs = 150000 - ), checker) + ), checker + ) edges.add(Edge(config_MULTITHREAD_EXPL_SEQ_ITP_Z3, config_MULTITHREAD_EXPL_SEQ_ITP_mathsat, solverError)) - val config_MULTITHREAD_EXPL_NWT_IT_WP_z3 = ConfigNode("MULTITHREAD_EXPL_NWT_IT_WP_z3:4.12.2-$inProcess", + val config_MULTITHREAD_EXPL_NWT_IT_WP_z3 = ConfigNode( + "MULTITHREAD_EXPL_NWT_IT_WP_z3:4.12.2-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.EXPL, @@ -568,22 +751,33 @@ fun complexPortfolio24( refinementSolver = "z3:4.12.2", refinement = Refinement.NWT_IT_WP, timeoutMs = 300000 - ), checker) - edges.add(Edge(config_MULTITHREAD_EXPL_SEQ_ITP_Z3, config_MULTITHREAD_EXPL_NWT_IT_WP_z3, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_MULTITHREAD_EXPL_SEQ_ITP_mathsat, config_MULTITHREAD_EXPL_NWT_IT_WP_z3, - if (inProcess) timeoutOrSolverError else anyError)) + ), checker + ) + edges.add( + Edge( + config_MULTITHREAD_EXPL_SEQ_ITP_Z3, config_MULTITHREAD_EXPL_NWT_IT_WP_z3, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_MULTITHREAD_EXPL_SEQ_ITP_mathsat, config_MULTITHREAD_EXPL_NWT_IT_WP_z3, + if (inProcess) timeoutOrSolverError else anyError + ) + ) val config_MULTITHREAD_EXPL_NWT_IT_WP_mathsat = ConfigNode( "MULTITHREAD_EXPL_NWT_IT_WP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( - inProcess = inProcess, - domain = Domain.EXPL, - abstractionSolver = "mathsat:5.6.10", - refinementSolver = "mathsat:5.6.10", - refinement = Refinement.NWT_IT_WP, - timeoutMs = 300000 - ), checker) + inProcess = inProcess, + domain = Domain.EXPL, + abstractionSolver = "mathsat:5.6.10", + refinementSolver = "mathsat:5.6.10", + refinement = Refinement.NWT_IT_WP, + timeoutMs = 300000 + ), checker + ) edges.add(Edge(config_MULTITHREAD_EXPL_NWT_IT_WP_z3, config_MULTITHREAD_EXPL_NWT_IT_WP_mathsat, solverError)) - val config_MULTITHREAD_PRED_CART_SEQ_ITP_Z3 = ConfigNode("MULTITHREAD_PRED_CART_SEQ_ITP_Z3-$inProcess", + val config_MULTITHREAD_PRED_CART_SEQ_ITP_Z3 = ConfigNode( + "MULTITHREAD_PRED_CART_SEQ_ITP_Z3-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -591,23 +785,35 @@ fun complexPortfolio24( refinementSolver = "Z3", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) - edges.add(Edge(config_MULTITHREAD_EXPL_NWT_IT_WP_z3, config_MULTITHREAD_PRED_CART_SEQ_ITP_Z3, - if (inProcess) timeoutOrNotSolvableError else anyError)) - edges.add(Edge(config_MULTITHREAD_EXPL_NWT_IT_WP_mathsat, config_MULTITHREAD_PRED_CART_SEQ_ITP_Z3, - if (inProcess) timeoutOrSolverError else anyError)) + ), checker + ) + edges.add( + Edge( + config_MULTITHREAD_EXPL_NWT_IT_WP_z3, config_MULTITHREAD_PRED_CART_SEQ_ITP_Z3, + if (inProcess) timeoutOrNotSolvableError else anyError + ) + ) + edges.add( + Edge( + config_MULTITHREAD_EXPL_NWT_IT_WP_mathsat, config_MULTITHREAD_PRED_CART_SEQ_ITP_Z3, + if (inProcess) timeoutOrSolverError else anyError + ) + ) val config_MULTITHREAD_PRED_CART_SEQ_ITP_mathsat = ConfigNode( "MULTITHREAD_PRED_CART_SEQ_ITP_mathsat:5.6.10-$inProcess", baseConfig.adaptConfig( - inProcess = inProcess, - domain = Domain.PRED_CART, - abstractionSolver = "mathsat:5.6.10", - refinementSolver = "mathsat:5.6.10", - refinement = Refinement.SEQ_ITP, - timeoutMs = 0 - ), checker) + inProcess = inProcess, + domain = Domain.PRED_CART, + abstractionSolver = "mathsat:5.6.10", + refinementSolver = "mathsat:5.6.10", + refinement = Refinement.SEQ_ITP, + timeoutMs = 0 + ), checker + ) edges.add( - Edge(config_MULTITHREAD_PRED_CART_SEQ_ITP_Z3, config_MULTITHREAD_PRED_CART_SEQ_ITP_mathsat, solverError)) - val config_MULTITHREAD_PRED_CART_SEQ_ITP_z3 = ConfigNode("MULTITHREAD_PRED_CART_SEQ_ITP_z3:4.12.2-$inProcess", + Edge(config_MULTITHREAD_PRED_CART_SEQ_ITP_Z3, config_MULTITHREAD_PRED_CART_SEQ_ITP_mathsat, solverError) + ) + val config_MULTITHREAD_PRED_CART_SEQ_ITP_z3 = ConfigNode( + "MULTITHREAD_PRED_CART_SEQ_ITP_z3:4.12.2-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, domain = Domain.PRED_CART, @@ -615,9 +821,11 @@ fun complexPortfolio24( refinementSolver = "z3:4.12.2", refinement = Refinement.SEQ_ITP, timeoutMs = 0 - ), checker) + ), checker + ) edges.add( - Edge(config_MULTITHREAD_PRED_CART_SEQ_ITP_mathsat, config_MULTITHREAD_PRED_CART_SEQ_ITP_z3, solverError)) + Edge(config_MULTITHREAD_PRED_CART_SEQ_ITP_mathsat, config_MULTITHREAD_PRED_CART_SEQ_ITP_z3, solverError) + ) if (trait == ArithmeticTrait.BITWISE) { return STM(config_BITWISE_EXPL_NWT_IT_WP_cvc5, edges) } diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/horn.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/horn.kt index 5a3933b59c..1a56abd89c 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/horn.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/horn.kt @@ -34,7 +34,8 @@ fun hornPortfolio( parseContext: ParseContext, portfolioConfig: XcfaConfig<*, *>, logger: Logger, - uniqueLogger: Logger): STM { + uniqueLogger: Logger +): STM { val checker = { config: XcfaConfig<*, *> -> runConfig(config, logger, uniqueLogger, true) } @@ -43,12 +44,14 @@ fun hornPortfolio( input = null, xcfaWCtx = Triple(xcfa, mcm, parseContext), propertyFile = null, - property = portfolioConfig.inputConfig.property), + property = portfolioConfig.inputConfig.property + ), frontendConfig = FrontendConfig( lbeLevel = LbePass.level, loopUnroll = LoopUnrollPass.UNROLL_LIMIT, inputType = InputType.C, - specConfig = CFrontendConfig(arithmetic = ArchitectureConfig.ArithmeticType.efficient)), + specConfig = CFrontendConfig(arithmetic = ArchitectureConfig.ArithmeticType.efficient) + ), backendConfig = BackendConfig( backend = Backend.CHC, solverHome = portfolioConfig.backendConfig.solverHome, @@ -56,7 +59,8 @@ fun hornPortfolio( specConfig = HornConfig( solver = "z3:4.13.0", validateSolver = false - )), + ) + ), outputConfig = OutputConfig( versionInfo = false, resultFolder = Paths.get("./").toFile(), // cwd @@ -103,34 +107,42 @@ fun hornPortfolio( timeoutMs: Long = 0, inProcess: Boolean = this.backendConfig.inProcess ): XcfaConfig<*, HornConfig> { - return copy(backendConfig = backendConfig.copy( - timeoutMs = timeoutMs, - inProcess = inProcess, - specConfig = backendConfig.specConfig!!.copy( - solver = solver, + return copy( + backendConfig = backendConfig.copy( + timeoutMs = timeoutMs, + inProcess = inProcess, + specConfig = backendConfig.specConfig!!.copy( + solver = solver, + ) ) - )) + ) } fun getStm(inProcess: Boolean): STM { val edges = LinkedHashSet() - val configZ3 = ConfigNode("Z3-$inProcess", + val configZ3 = ConfigNode( + "Z3-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, timeoutMs = 100_000 - ), checker) - val configEldarica = ConfigNode("Eldarica-$inProcess", + ), checker + ) + val configEldarica = ConfigNode( + "Eldarica-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, solver = "eldarica:2.1", timeoutMs = 500_000 - ), checker) - val configGolem = ConfigNode("Golem-$inProcess", + ), checker + ) + val configGolem = ConfigNode( + "Golem-$inProcess", baseConfig.adaptConfig( inProcess = inProcess, solver = "golem:0.5.0", timeoutMs = 300_000 - ), checker) + ), checker + ) edges.add(Edge(configZ3, configEldarica, anyError)) edges.add(Edge(configEldarica, configGolem, anyError)) diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/stm.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/stm.kt index d98b44e8f9..27d08a1c2b 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/stm.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/stm.kt @@ -36,8 +36,10 @@ ${innerSTM.visualize()} }""".trimIndent() } -class ConfigNode(name: String, private val config: XcfaConfig<*, *>, - private val check: (config: XcfaConfig<*, *>) -> SafetyResult<*, *>) : Node(name) { +class ConfigNode( + name: String, private val config: XcfaConfig<*, *>, + private val check: (config: XcfaConfig<*, *>) -> SafetyResult<*, *> +) : Node(name) { override fun execute(): Pair { println("Current configuration: $config") @@ -48,10 +50,12 @@ class ConfigNode(name: String, private val config: XcfaConfig<*, *>, .map { "state ${name.replace(Regex("[:\\.-]+"), "_")}: $it" }.reduce { a, b -> "$a\n$b" } } -data class Edge(val source: Node, +data class Edge( + val source: Node, val target: Node, val trigger: (Throwable) -> Boolean, - val guard: (Node, Edge) -> Boolean = { _, _ -> true }) { + val guard: (Node, Edge) -> Boolean = { _, _ -> true } +) { init { source.outEdges.add(this) @@ -70,8 +74,10 @@ class ExceptionTrigger( val label: String? = null ) : (Throwable) -> Boolean { - constructor(vararg exceptions: Throwable, label: String? = null) : this(exceptions.toSet(), - label = label) + constructor(vararg exceptions: Throwable, label: String? = null) : this( + exceptions.toSet(), + label = label + ) override fun invoke(e: Throwable): Boolean = if (exceptions.isNotEmpty()) @@ -89,7 +95,8 @@ data class STM(val initNode: Node, val edges: Set) { val nodes = edges.map { listOf(it.source, it.target) }.flatten().toSet() nodes.forEach { check( - it.parent == null || it.parent === this) { "Edges to behave encapsulated (offender: $it)" } + it.parent == null || it.parent === this + ) { "Edges to behave encapsulated (offender: $it)" } it.parent = this } } @@ -116,9 +123,11 @@ ${edges.map { it.visualize() }.reduce { a, b -> "$a\n$b" }} println("Handling exception as ${edge.trigger}") currentNode = edge.target } else { - println("Could not handle trigger $e (Available triggers: ${ - currentNode.outEdges.map { it.trigger }.toList() - })") + println( + "Could not handle trigger $e (Available triggers: ${ + currentNode.outEdges.map { it.trigger }.toList() + })" + ) throw e } } diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GsonUtils.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GsonUtils.kt index ad9011bd82..72ddc379d7 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GsonUtils.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GsonUtils.kt @@ -76,30 +76,39 @@ private fun traceHelper(stateType: java.lang.reflect.Type): java.lang.reflect.Ty ).type @JvmOverloads -internal fun getGson(xcfa: XCFA, domain: () -> Domain = { error("Domain needs to be specified.") }, - solver: () -> Solver = { error("Solver is necessary.") }): Gson { +internal fun getGson( + xcfa: XCFA, domain: () -> Domain = { error("Domain needs to be specified.") }, + solver: () -> Solver = { error("Solver is necessary.") } +): Gson { val (scope, env) = xcfa.getSymbols() return getGson(scope, env, false, domain, solver) } @JvmOverloads -internal fun getGson(domain: () -> Domain = { error("Domain needs to be specified.") }, - solver: () -> Solver = { error("Solver is necessary.") }): Gson { +internal fun getGson( + domain: () -> Domain = { error("Domain needs to be specified.") }, + solver: () -> Solver = { error("Solver is necessary.") } +): Gson { return getGson(XcfaScope(SymbolTable()), Env(), true, domain, solver) } -private fun getGson(scope: XcfaScope, env: Env, newScope: Boolean, domain: () -> Domain, - solver: () -> Solver): Gson { +private fun getGson( + scope: XcfaScope, env: Env, newScope: Boolean, domain: () -> Domain, + solver: () -> Solver +): Gson { val gsonBuilder = GsonBuilder() lateinit var gson: Gson gsonBuilder.registerTypeHierarchyAdapter(FrontendConfig::class.java, SpecFrontendConfigTypeAdapter { gson }) gsonBuilder.registerTypeHierarchyAdapter(BackendConfig::class.java, SpecBackendConfigTypeAdapter { gson }) gsonBuilder.registerTypeHierarchyAdapter(File::class.java, StringTypeAdapter { File(it) }) - gsonBuilder.registerTypeHierarchyAdapter(XcfaLocation::class.java, - StringTypeAdapter(xcfaLocationAdapter)) + gsonBuilder.registerTypeHierarchyAdapter( + XcfaLocation::class.java, + StringTypeAdapter(xcfaLocationAdapter) + ) gsonBuilder.registerTypeHierarchyAdapter(XCFA::class.java, XcfaAdapter { gson }) gsonBuilder.registerTypeHierarchyAdapter(VarDecl::class.java, - VarDeclAdapter({ gson }, scope, env, !newScope)) + VarDeclAdapter({ gson }, scope, env, !newScope) + ) gsonBuilder.registerTypeHierarchyAdapter(Stmt::class.java, StringTypeAdapter { StatementWrapper(it, scope).instantiate(env) }) gsonBuilder.registerTypeHierarchyAdapter(Expr::class.java, @@ -110,9 +119,11 @@ private fun getGson(scope: XcfaScope, env: Env, newScope: Boolean, domain: () -> StringTypeAdapter { BasicVarIndexing.fromString(it, scope, env) }) gsonBuilder.registerTypeHierarchyAdapter(ExplState::class.java, ExplStateAdapter(scope, env)) gsonBuilder.registerTypeHierarchyAdapter(PredState::class.java, - PredStateAdapter({ gson }, scope, env)) + PredStateAdapter({ gson }, scope, env) + ) gsonBuilder.registerTypeHierarchyAdapter(XcfaLabel::class.java, - XcfaLabelAdapter(scope, env, { gson })) + XcfaLabelAdapter(scope, env, { gson }) + ) gsonBuilder.registerTypeHierarchyAdapter(MetaData::class.java, MetaDataAdapter()) gsonBuilder.registerTypeHierarchyAdapter(Pair::class.java, PairAdapter { gson }) gsonBuilder.registerTypeHierarchyAdapter(Optional::class.java, OptionalAdapter { gson }) @@ -120,15 +131,19 @@ private fun getGson(scope: XcfaScope, env: Env, newScope: Boolean, domain: () -> XcfaStateAdapter({ gson }) { domain().stateType }) gsonBuilder.registerTypeHierarchyAdapter(XcfaAction::class.java, XcfaActionAdapter { gson }) gsonBuilder.registerTypeHierarchyAdapter(Trace::class.java, TraceAdapter({ gson }, { - TypeToken.getParameterized(TypeToken.get(XcfaState::class.java).type, - domain().stateType).type + TypeToken.getParameterized( + TypeToken.get(XcfaState::class.java).type, + domain().stateType + ).type }, TypeToken.get(XcfaAction::class.java).type)) gsonBuilder.registerTypeHierarchyAdapter(ARG::class.java, ArgAdapter({ gson }, { domain().partialOrd(solver()) }, - { argAdapterHelper(domain().stateType) })) + { argAdapterHelper(domain().stateType) }) + ) gsonBuilder.registerTypeHierarchyAdapter(SafetyResult::class.java, SafetyResultAdapter({ gson }, { argHelper(domain().stateType) }, - { traceHelper(domain().stateType) })) + { traceHelper(domain().stateType) }) + ) gsonBuilder.registerTypeHierarchyAdapter(ParseContext::class.java, ParseContextAdapter { gson }) gsonBuilder.registerTypeHierarchyAdapter(FrontendMetadata::class.java, diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/PropertyUtils.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/PropertyUtils.kt index c053280a14..cc3c24338d 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/PropertyUtils.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/PropertyUtils.kt @@ -36,8 +36,10 @@ fun determineProperty(config: XcfaConfig<*, *>, logger: Logger): ErrorDetection } else -> { - logger.write(Logger.Level.INFO, - "Unknown property $propertyFile, using full state space exploration (no refinement)\n") + logger.write( + Logger.Level.INFO, + "Unknown property $propertyFile, using full state space exploration (no refinement)\n" + ) ErrorDetection.NO_ERROR } } diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaParser.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaParser.kt index cb18d5c237..a987f153d7 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaParser.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaParser.kt @@ -46,13 +46,17 @@ fun getXcfa(config: XcfaConfig<*, *>, parseContext: ParseContext, logger: Logger when (config.frontendConfig.inputType) { InputType.CHC -> { val chcConfig = config.frontendConfig.specConfig as CHCFrontendConfig - parseChc(config.inputConfig.input!!, chcConfig.chcTransformation, parseContext, logger, - uniqueWarningLogger) + parseChc( + config.inputConfig.input!!, chcConfig.chcTransformation, parseContext, logger, + uniqueWarningLogger + ) } InputType.C -> { - parseC(config.inputConfig.input!!, config.inputConfig.property, parseContext, logger, - uniqueWarningLogger) + parseC( + config.inputConfig.input!!, config.inputConfig.property, parseContext, logger, + uniqueWarningLogger + ) } InputType.LLVM -> XcfaUtils.fromFile(config.inputConfig.input!!, ArithmeticType.efficient) @@ -76,48 +80,65 @@ fun getXcfa(config: XcfaConfig<*, *>, parseContext: ParseContext, logger: Logger exitProcess(ExitCodes.FRONTEND_FAILED.code) } -private fun parseC(input: File, explicitProperty: ErrorDetection, parseContext: ParseContext, logger: Logger, - uniqueWarningLogger: Logger): XCFA { +private fun parseC( + input: File, explicitProperty: ErrorDetection, parseContext: ParseContext, logger: Logger, + uniqueWarningLogger: Logger +): XCFA { val xcfaFromC = try { val stream = FileInputStream(input) - getXcfaFromC(stream, parseContext, false, - explicitProperty == ErrorDetection.OVERFLOW, uniqueWarningLogger).first + getXcfaFromC( + stream, parseContext, false, + explicitProperty == ErrorDetection.OVERFLOW, uniqueWarningLogger + ).first } catch (e: Throwable) { if (parseContext.arithmetic == ArchitectureConfig.ArithmeticType.efficient) { parseContext.arithmetic = ArchitectureConfig.ArithmeticType.bitvector logger.write(Logger.Level.INFO, "Retrying parsing with bitvector arithmetic...\n") val stream = FileInputStream(input) - val xcfa = getXcfaFromC(stream, parseContext, false, - explicitProperty == ErrorDetection.OVERFLOW, uniqueWarningLogger).first + val xcfa = getXcfaFromC( + stream, parseContext, false, + explicitProperty == ErrorDetection.OVERFLOW, uniqueWarningLogger + ).first parseContext.addArithmeticTrait(ArithmeticTrait.BITWISE) xcfa } else { throw e } } - logger.write(Logger.Level.RESULT, - "Arithmetic: ${parseContext.arithmeticTraits}\n") + logger.write( + Logger.Level.RESULT, + "Arithmetic: ${parseContext.arithmeticTraits}\n" + ) return xcfaFromC } -private fun parseChc(input: File, chcTransformation: ChcFrontend.ChcTransformation, parseContext: ParseContext, - logger: Logger, uniqueWarningLogger: Logger): XCFA { +private fun parseChc( + input: File, chcTransformation: ChcFrontend.ChcTransformation, parseContext: ParseContext, + logger: Logger, uniqueWarningLogger: Logger +): XCFA { var chcFrontend: ChcFrontend - val xcfaBuilder = if (chcTransformation == ChcFrontend.ChcTransformation.PORTFOLIO) { // try forward, fallback to backward - chcFrontend = ChcFrontend(ChcFrontend.ChcTransformation.FORWARD) - try { - chcFrontend.buildXcfa(CharStreams.fromStream(FileInputStream(input)), - ChcPasses(parseContext, uniqueWarningLogger)) - } catch (e: UnsupportedOperationException) { - logger.write(Logger.Level.INFO, "Non-linear CHC found, retrying using backward transformation...\n") - chcFrontend = ChcFrontend(ChcFrontend.ChcTransformation.BACKWARD) - chcFrontend.buildXcfa(CharStreams.fromStream(FileInputStream(input)), - ChcPasses(parseContext, uniqueWarningLogger)) + val xcfaBuilder = + if (chcTransformation == ChcFrontend.ChcTransformation.PORTFOLIO) { // try forward, fallback to backward + chcFrontend = ChcFrontend(ChcFrontend.ChcTransformation.FORWARD) + try { + chcFrontend.buildXcfa( + CharStreams.fromStream(FileInputStream(input)), + ChcPasses(parseContext, uniqueWarningLogger) + ) + } catch (e: UnsupportedOperationException) { + logger.write(Logger.Level.INFO, "Non-linear CHC found, retrying using backward transformation...\n") + chcFrontend = ChcFrontend(ChcFrontend.ChcTransformation.BACKWARD) + chcFrontend.buildXcfa( + CharStreams.fromStream(FileInputStream(input)), + ChcPasses(parseContext, uniqueWarningLogger) + ) + } + } else { + chcFrontend = ChcFrontend(chcTransformation) + chcFrontend.buildXcfa( + CharStreams.fromStream(FileInputStream(input)), + ChcPasses(parseContext, uniqueWarningLogger) + ) } - } else { - chcFrontend = ChcFrontend(chcTransformation) - chcFrontend.buildXcfa(CharStreams.fromStream(FileInputStream(input)), - ChcPasses(parseContext, uniqueWarningLogger)) - } return xcfaBuilder.build() } \ No newline at end of file diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaWitnessWriter.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaWitnessWriter.kt index 722fa7d91d..5ad00f3717 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaWitnessWriter.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaWitnessWriter.kt @@ -47,7 +47,8 @@ class XcfaWitnessWriter { if (safetyResult.isUnsafe && safetyResult.asUnsafe().cex is Trace<*, *>) { val concrTrace: Trace, XcfaAction> = XcfaTraceConcretizer.concretize( safetyResult.asUnsafe().cex as Trace>, XcfaAction>?, cexSolverFactory, - parseContext) + parseContext + ) val witnessTrace = traceToWitness(trace = concrTrace, parseContext = parseContext) val witness = Witness(witnessTrace, inputFile) @@ -57,63 +58,93 @@ class XcfaWitnessWriter { val taskHash = WitnessWriter.createTaskHash(inputFile.absolutePath) val dummyWitness = StringBuilder() dummyWitness.append( - "") + "" + ) .append(System.lineSeparator()).append( - "") + "" + ) .append(System.lineSeparator()).append( - "") + "" + ) .append(System.lineSeparator()).append( - "") + "" + ) .append(System.lineSeparator()).append( - "false").append(System.lineSeparator()).append( - "").append(System.lineSeparator()).append( - "") + "false" + ).append(System.lineSeparator()).append( + "" + ).append(System.lineSeparator()).append( + "" + ) .append(System.lineSeparator()).append( - "false").append(System.lineSeparator()).append( - "").append(System.lineSeparator()).append( - "") + "false" + ).append(System.lineSeparator()).append( + "" + ).append(System.lineSeparator()).append( + "" + ) .append(System.lineSeparator()).append( - "") + "" + ) .append(System.lineSeparator()).append( - "") + "" + ) .append(System.lineSeparator()).append( - "") + "" + ) .append(System.lineSeparator()).append( - "") + "" + ) .append(System.lineSeparator()).append( - "") + "" + ) .append(System.lineSeparator()).append( - "").append(System.lineSeparator()).append( - "correctness_witness") + "" + ).append(System.lineSeparator()).append( + "correctness_witness" + ) .append(System.lineSeparator()).append( - "theta").append(System.lineSeparator()).append( - "CHECK( init(main()), LTL(G ! call(reach_error())) )") + "theta" + ).append(System.lineSeparator()).append( + "CHECK( init(main()), LTL(G ! call(reach_error())) )" + ) .append(System.lineSeparator()).append( - "C").append(System.lineSeparator()).append( - "32bit").append(System.lineSeparator()) + "C" + ).append(System.lineSeparator()).append( + "32bit" + ).append(System.lineSeparator()) .append( - "") + "" + ) dummyWitness.append(taskHash) dummyWitness.append("").append(System.lineSeparator()).append( - "") + "" + ) val tz: TimeZone = TimeZone.getTimeZone("UTC") val df: DateFormat = SimpleDateFormat( - "yyyy-MM-dd'T'HH:mm:ss'Z'") // Quoted "Z" to indicate UTC, no timezone offset + "yyyy-MM-dd'T'HH:mm:ss'Z'" + ) // Quoted "Z" to indicate UTC, no timezone offset df.timeZone = tz val isoDate: String = df.format(Date()) dummyWitness.append(isoDate) dummyWitness.append("").append(System.lineSeparator()).append( - "") + "" + ) dummyWitness.append(inputFile.name) dummyWitness.append("").append(System.lineSeparator()).append( - "").append(System.lineSeparator()).append( - "true").append(System.lineSeparator()).append( - "").append(System.lineSeparator()).append( - "").append(System.lineSeparator()).append( - "") + "" + ).append(System.lineSeparator()).append( + "true" + ).append(System.lineSeparator()).append( + "" + ).append(System.lineSeparator()).append( + "" + ).append(System.lineSeparator()).append( + "" + ) try { BufferedWriter(FileWriter(witnessfile)).use { bw -> diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/TraceToWitness.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/TraceToWitness.kt index 38ab39f52b..d6848feffe 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/TraceToWitness.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/TraceToWitness.kt @@ -46,8 +46,10 @@ fun traceToWitness( val newStates = ArrayList() val newActions = ArrayList() - var lastNode = WitnessNode(id = "N${newStates.size}", entry = true, sink = false, - violation = false) + var lastNode = WitnessNode( + id = "N${newStates.size}", entry = true, sink = false, + violation = false + ) newStates.add(lastNode) for (i in 0 until trace.length()) { @@ -67,8 +69,10 @@ fun traceToWitness( ) if (node != WitnessNode(id = "N${newStates.size}")) { newStates.add(node) - val edge = WitnessEdge(sourceId = lastNode.id, targetId = node.id, - threadId = trace.actions[i].pid.toString()) + val edge = WitnessEdge( + sourceId = lastNode.id, targetId = node.id, + threadId = trace.actions[i].pid.toString() + ) newActions.add(edge) lastNode = node } @@ -76,10 +80,14 @@ fun traceToWitness( val action = trace.actions[i] val flattenedSequence = flattenSequence(action.edge.label) for (xcfaLabel in flattenedSequence) { - val node = WitnessNode(id = "N${newStates.size}", entry = false, sink = false, - violation = false) - var edge = labelToEdge(lastNode, node, xcfaLabel, action.pid, - nextState.sGlobal.getVal(), parseContext) + val node = WitnessNode( + id = "N${newStates.size}", entry = false, sink = false, + violation = false + ) + var edge = labelToEdge( + lastNode, node, xcfaLabel, action.pid, + nextState.sGlobal.getVal(), parseContext + ) if (newThreads.isNotEmpty() && xcfaLabel is StartLabel) { edge = edge.copy(createThread = newThreads.joinToString(",")) } @@ -120,8 +128,10 @@ fun shouldInclude(edge: WitnessEdge, verbosity: Verbosity): Boolean = } -private fun labelToEdge(lastNode: WitnessNode, node: WitnessNode, xcfaLabel: XcfaLabel, pid: Int, - valuation: Valuation, parseContext: ParseContext): WitnessEdge = +private fun labelToEdge( + lastNode: WitnessNode, node: WitnessNode, xcfaLabel: XcfaLabel, pid: Int, + valuation: Valuation, parseContext: ParseContext +): WitnessEdge = WitnessEdge( sourceId = lastNode.id, targetId = node.id, @@ -190,14 +200,17 @@ private fun printLit(litExpr: LitExpr<*>): String? { for (i in boolList.indices) { if (i % 4 == 0 && i > 0) { if (aggregate < 10) hexDigits.add( - ('0'.code + aggregate).toChar()) else hexDigits.add( - ('A'.code - 10 + aggregate).toChar()) + ('0'.code + aggregate).toChar() + ) else hexDigits.add( + ('A'.code - 10 + aggregate).toChar() + ) aggregate = 0 } if (boolList[i]) aggregate += 1 shl i % 4 } if (aggregate < 10) hexDigits.add(('0'.code + aggregate).toChar()) else hexDigits.add( - ('A'.code - 10 + aggregate).toChar()) + ('A'.code - 10 + aggregate).toChar() + ) val stringBuilder = StringBuilder("0x") for (character in Lists.reverse(hexDigits)) { stringBuilder.append(character) diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/Witness.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/Witness.kt index 4569a1b557..4bcbcc99bb 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/Witness.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/Witness.kt @@ -59,8 +59,12 @@ class Witness(private val trace: Trace, programFile: F attributes.add(WitnessAttribute("assumption", "string", "edge", "assumption")) attributes.add(WitnessAttribute("assumption.scope", "string", "edge", "assumption.scope")) - attributes.add(WitnessAttribute("assumption.resultfunction", "string", "edge", - "assumption.resultfunction")) + attributes.add( + WitnessAttribute( + "assumption.resultfunction", "string", "edge", + "assumption.resultfunction" + ) + ) attributes.add(WitnessAttribute("control", "string", "edge", "control")) attributes.add(WitnessAttribute("startline", "string", "edge", "startline")) attributes.add(WitnessAttribute("endline", "string", "edge", "endline")) @@ -69,7 +73,8 @@ class Witness(private val trace: Trace, programFile: F attributes.add(WitnessAttribute("enterLoopHead", "string", "edge", "enterLoopHead")) attributes.add(WitnessAttribute("enterFunction", "string", "edge", "enterFunction")) attributes.add( - WitnessAttribute("returnFromFunction", "string", "edge", "returnFromFunction")) + WitnessAttribute("returnFromFunction", "string", "edge", "returnFromFunction") + ) attributes.add(WitnessAttribute("threadId", "string", "edge", "threadId")) attributes.add(WitnessAttribute("createThread", "string", "edge", "createThread")) attributes.add(WitnessAttribute("stmt", "string", "edge", "stmt")) @@ -271,7 +276,8 @@ private fun bytesToHex(hash: ByteArray): String { private fun getIsoDate(): String { val tz: TimeZone = TimeZone.getTimeZone("UTC") val df: DateFormat = SimpleDateFormat( - "yyyy-MM-dd'T'HH:mm:ss'Z'") // Quoted "Z" to indicate UTC, no timezone offset + "yyyy-MM-dd'T'HH:mm:ss'Z'" + ) // Quoted "Z" to indicate UTC, no timezone offset df.timeZone = tz return df.format(Date()) @@ -281,7 +287,8 @@ private fun getIsoDate(): String { private fun prettyFormat(input: String, indent: Int): String { return try { val xmlInput: Source = StreamSource( - StringReader(input.replace(Regex("( )|[\\t\\n\\r]"), ""))) + StringReader(input.replace(Regex("( )|[\\t\\n\\r]"), "")) + ) val stringWriter = StringWriter() val xmlOutput = StreamResult(stringWriter) val transformerFactory: TransformerFactory = TransformerFactory.newInstance() diff --git a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliParseTest.kt b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliParseTest.kt index a6aa6b8bb5..d886fe23dd 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliParseTest.kt +++ b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliParseTest.kt @@ -169,12 +169,14 @@ class XcfaCliParseTest { @ParameterizedTest @MethodSource("cFiles") fun testCParse(filePath: String) { - main(arrayOf( - "--input-type", "C", - "--input", javaClass.getResource(filePath)!!.path, - "--backend", "NONE", "--stacktrace", - "--debug" - )) + main( + arrayOf( + "--input-type", "C", + "--input", javaClass.getResource(filePath)!!.path, + "--backend", "NONE", "--stacktrace", + "--debug" + ) + ) } // @ParameterizedTest @@ -192,61 +194,71 @@ class XcfaCliParseTest { @ParameterizedTest @MethodSource("chcFiles") fun testCHCParse(filePath: String, chcTransformation: ChcFrontend.ChcTransformation) { - main(arrayOf( - "--input-type", "CHC", - "--chc-transformation", chcTransformation.toString(), - "--input", javaClass.getResource(filePath)!!.path, - "--backend", "NONE", - "--stacktrace", - "--debug" - )) + main( + arrayOf( + "--input-type", "CHC", + "--chc-transformation", chcTransformation.toString(), + "--input", javaClass.getResource(filePath)!!.path, + "--backend", "NONE", + "--stacktrace", + "--debug" + ) + ) } @ParameterizedTest @MethodSource("dslFiles") fun testDSLParse(filePath: String) { - main(arrayOf( - "--input-type", "DSL", - "--input", javaClass.getResource(filePath)!!.path, - "--backend", "NONE", - "--stacktrace", - "--debug" - )) + main( + arrayOf( + "--input-type", "DSL", + "--input", javaClass.getResource(filePath)!!.path, + "--backend", "NONE", + "--stacktrace", + "--debug" + ) + ) } @ParameterizedTest @MethodSource("jsonFiles") fun testJSONParse(filePath: String) { - main(arrayOf( - "--input-type", "JSON", - "--input", javaClass.getResource(filePath)!!.path, - "--backend", "NONE", - "--stacktrace", - "--debug" - )) + main( + arrayOf( + "--input-type", "JSON", + "--input", javaClass.getResource(filePath)!!.path, + "--backend", "NONE", + "--stacktrace", + "--debug" + ) + ) } @ParameterizedTest @MethodSource("cFiles") fun testJSONParseRoundTrip(filePath: String) { val temp = createTempDirectory() - main(arrayOf( - "--enable-output", - "--input-type", "C", - "--input", javaClass.getResource(filePath)!!.path, - "--backend", "NONE", - "--stacktrace", - "--output-directory", temp.toAbsolutePath().toString(), - "--debug" - )) + main( + arrayOf( + "--enable-output", + "--input-type", "C", + "--input", javaClass.getResource(filePath)!!.path, + "--backend", "NONE", + "--stacktrace", + "--output-directory", temp.toAbsolutePath().toString(), + "--debug" + ) + ) val xcfaJson = temp.resolve("xcfa.json").toFile() - main(arrayOf( - "--input-type", "JSON", - "--input", xcfaJson.absolutePath.toString(), - "--backend", "NONE", - "--stacktrace", - "--debug" - )) + main( + arrayOf( + "--input-type", "JSON", + "--input", xcfaJson.absolutePath.toString(), + "--backend", "NONE", + "--stacktrace", + "--debug" + ) + ) temp.toFile().deleteRecursively() } @@ -254,24 +266,28 @@ class XcfaCliParseTest { @MethodSource("simpleCFiles") fun testCParseRoundTrip(filePath: String) { val temp = createTempDirectory() - main(arrayOf( - "--enable-output", - "--input-type", "C", - "--input", javaClass.getResource(filePath)!!.path, - "--backend", "NONE", - "--stacktrace", - "--output-directory", temp.toAbsolutePath().toString(), - "--debug" - )) + main( + arrayOf( + "--enable-output", + "--input-type", "C", + "--input", javaClass.getResource(filePath)!!.path, + "--backend", "NONE", + "--stacktrace", + "--output-directory", temp.toAbsolutePath().toString(), + "--debug" + ) + ) val xcfaC = temp.resolve("xcfa.c").toFile() checkState(xcfaC.exists(), "File does not exist: $xcfaC") - main(arrayOf( - "--input-type", "C", - "--input", xcfaC.absolutePath.toString(), - "--backend", "NONE", - "--stacktrace", - "--debug" - )) + main( + arrayOf( + "--input-type", "C", + "--input", xcfaC.absolutePath.toString(), + "--backend", "NONE", + "--stacktrace", + "--debug" + ) + ) temp.toFile().deleteRecursively() } diff --git a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliPortfolioTest.kt b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliPortfolioTest.kt index 9d9dc0e0f2..d7838c0403 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliPortfolioTest.kt +++ b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliPortfolioTest.kt @@ -63,17 +63,23 @@ class XcfaCliPortfolioTest { @ParameterizedTest @MethodSource("portfolios") - fun testPortfolio(portfolio: (xcfa: XCFA, - mcm: MCM, - parseContext: ParseContext, - portfolioConfig: XcfaConfig<*, *>, - logger: Logger, - uniqueLogger: Logger) -> STM) { + fun testPortfolio( + portfolio: ( + xcfa: XCFA, + mcm: MCM, + parseContext: ParseContext, + portfolioConfig: XcfaConfig<*, *>, + logger: Logger, + uniqueLogger: Logger + ) -> STM + ) { for (value in ArithmeticTrait.values()) { - val stm = portfolio(XCFA("name", setOf()), emptySet(), ParseContext(), - XcfaConfig(), NullLogger.getInstance(), NullLogger.getInstance()) + val stm = portfolio( + XCFA("name", setOf()), emptySet(), ParseContext(), + XcfaConfig(), NullLogger.getInstance(), NullLogger.getInstance() + ) Assertions.assertTrue(stm.visualize().isNotEmpty()) } diff --git a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliVerifyTest.kt b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliVerifyTest.kt index c5fb4dbb56..8b1c73b540 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliVerifyTest.kt +++ b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliVerifyTest.kt @@ -144,8 +144,10 @@ class XcfaCliVerifyTest { fun chcFiles(): Stream { return Stream.of( Arguments.of("/chc/chc-LIA-Lin_000.smt2", ChcFrontend.ChcTransformation.FORWARD, "--domain PRED_CART"), - Arguments.of("/chc/chc-LIA-Arrays_000.smt2", ChcFrontend.ChcTransformation.BACKWARD, - "--domain PRED_CART --search BFS"), + Arguments.of( + "/chc/chc-LIA-Arrays_000.smt2", ChcFrontend.ChcTransformation.BACKWARD, + "--domain PRED_CART --search BFS" + ), ) } } @@ -243,14 +245,16 @@ class XcfaCliVerifyTest { @ParameterizedTest @MethodSource("chcFiles") fun testCHCVerify(filePath: String, chcTransformation: ChcFrontend.ChcTransformation, extraArgs: String?) { - main(arrayOf( - "--input-type", "CHC", - "--chc-transformation", chcTransformation.toString(), - "--input", javaClass.getResource(filePath)!!.path, - "--stacktrace", - *(extraArgs?.split(" ")?.toTypedArray() ?: emptyArray()), - "--debug" - )) + main( + arrayOf( + "--input-type", "CHC", + "--chc-transformation", chcTransformation.toString(), + "--input", javaClass.getResource(filePath)!!.path, + "--stacktrace", + *(extraArgs?.split(" ")?.toTypedArray() ?: emptyArray()), + "--debug" + ) + ) } @ParameterizedTest diff --git a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliWitnessTest.kt b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliWitnessTest.kt index bc5657f5ba..8405c761ae 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliWitnessTest.kt +++ b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliWitnessTest.kt @@ -39,24 +39,28 @@ class XcfaCliWitnessTest { @JvmStatic fun cFiles(): Stream { return Stream.of( - Arguments.of("/c/litmustest/singlethread/witness_test.c", null, listOf( - WitnessEdge( - startlineRange = Pair(5, 5), - endlineRange = Pair(5, 5), - startoffsetRange = Pair(100, 130), - endoffsetRange = Pair(100, 130), - assumption = Regex("i *== *-1"), - ), - )), - Arguments.of("/c/litmustest/singlethread/witness_test.c", "--backend BOUNDED", listOf( - WitnessEdge( - startlineRange = Pair(5, 5), - endlineRange = Pair(5, 5), - startoffsetRange = Pair(100, 130), - endoffsetRange = Pair(100, 130), - assumption = Regex("i *== *-1"), - ), - )), + Arguments.of( + "/c/litmustest/singlethread/witness_test.c", null, listOf( + WitnessEdge( + startlineRange = Pair(5, 5), + endlineRange = Pair(5, 5), + startoffsetRange = Pair(100, 130), + endoffsetRange = Pair(100, 130), + assumption = Regex("i *== *-1"), + ), + ) + ), + Arguments.of( + "/c/litmustest/singlethread/witness_test.c", "--backend BOUNDED", listOf( + WitnessEdge( + startlineRange = Pair(5, 5), + endlineRange = Pair(5, 5), + startoffsetRange = Pair(100, 130), + endoffsetRange = Pair(100, 130), + assumption = Regex("i *== *-1"), + ), + ) + ), ) } diff --git a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaDslTest.kt b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaDslTest.kt index 53d5ba6130..8fb8f64b90 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaDslTest.kt +++ b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaDslTest.kt @@ -88,18 +88,23 @@ class XcfaDslTest { fun verifyXcfa() { SolverManager.registerSolverManager(Z3SolverManager.create()) val config = XcfaConfig( - backendConfig = BackendConfig(backend = Backend.CEGAR, specConfig = CegarConfig())) + backendConfig = BackendConfig(backend = Backend.CEGAR, specConfig = CegarConfig()) + ) run { val xcfa = getSyncXcfa() - val checker = getChecker(xcfa, emptySet(), config, ParseContext(), NullLogger.getInstance(), - NullLogger.getInstance()) + val checker = getChecker( + xcfa, emptySet(), config, ParseContext(), NullLogger.getInstance(), + NullLogger.getInstance() + ) val safetyResult = checker.check() Assert.assertTrue(safetyResult.isSafe) } run { val xcfa = getAsyncXcfa() - val checker = getChecker(xcfa, emptySet(), config, ParseContext(), NullLogger.getInstance(), - NullLogger.getInstance()) + val checker = getChecker( + xcfa, emptySet(), config, ParseContext(), NullLogger.getInstance(), + NullLogger.getInstance() + ) val safetyResult = checker.check() Assert.assertTrue(safetyResult.isUnsafe) } diff --git a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaToCTest.kt b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaToCTest.kt index 51372ee26d..fc7783b64f 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaToCTest.kt +++ b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaToCTest.kt @@ -55,11 +55,17 @@ class XcfaToCTest { val chcFrontend = ChcFrontend(chcTransformation) val xcfa = chcFrontend.buildXcfa( CharStreams.fromStream(FileInputStream(javaClass.getResource(filePath)!!.path)), ChcPasses( - ParseContext(), NullLogger.getInstance())).build() + ParseContext(), NullLogger.getInstance() + ) + ).build() val temp = createTempDirectory() val file = temp.resolve("${filePath.split("/").last()}.c").also { - it.toFile().writeText(xcfa.toC(ParseContext(), - true, false, false)) + it.toFile().writeText( + xcfa.toC( + ParseContext(), + true, false, false + ) + ) } System.err.println(file) } diff --git a/subprojects/xcfa/xcfa-cli/src/test/resources/simple.kts b/subprojects/xcfa/xcfa-cli/src/test/resources/simple.kts index fb98c7344d..2a8aaae312 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/resources/simple.kts +++ b/subprojects/xcfa/xcfa-cli/src/test/resources/simple.kts @@ -34,7 +34,8 @@ fun portfolio( parseContext: ParseContext, portfolioConfig: XcfaConfig<*, *>, logger: Logger, - uniqueLogger: Logger): STM { + uniqueLogger: Logger +): STM { val checker = { config: XcfaConfig<*, *> -> runConfig(config, logger, uniqueLogger, true) } @@ -43,12 +44,14 @@ fun portfolio( input = null, xcfaWCtx = Triple(xcfa, mcm, parseContext), propertyFile = null, - property = portfolioConfig.inputConfig.property), + property = portfolioConfig.inputConfig.property + ), frontendConfig = FrontendConfig( lbeLevel = LbePass.LbeLevel.LBE_SEQ, loopUnroll = 50, inputType = InputType.C, - specConfig = CFrontendConfig(arithmetic = ArchitectureConfig.ArithmeticType.efficient)), + specConfig = CFrontendConfig(arithmetic = ArchitectureConfig.ArithmeticType.efficient) + ), backendConfig = BackendConfig( backend = Backend.CEGAR, solverHome = portfolioConfig.backendConfig.solverHome, @@ -72,7 +75,9 @@ fun portfolio( refinement = Refinement.SEQ_ITP, exprSplitter = ExprSplitterOptions.WHOLE, pruneStrategy = PruneStrategy.FULL - ))), + ) + ) + ), outputConfig = OutputConfig( versionInfo = false, resultFolder = Paths.get("./").toFile(), // cwd @@ -91,7 +96,8 @@ fun portfolio( abstractorConfig = baseCegarConfig.abstractorConfig.copy(search = Search.DFS), ) baseConfig = baseConfig.copy( - backendConfig = baseConfig.backendConfig.copy(specConfig = multiThreadedCegarConfig)) + backendConfig = baseConfig.backendConfig.copy(specConfig = multiThreadedCegarConfig) + ) } if (!xcfa.isInlined) { diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/Utils.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/Utils.kt index cc6f24571b..924f0f7a24 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/Utils.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/Utils.kt @@ -453,27 +453,35 @@ fun XcfaLabel.simplify(valuation: MutableValuation, parseContext: ParseContext): is MemoryAssignStmt<*, *, *> -> { simplified as MemoryAssignStmt<*, *, *> if (parseContext.metadata.getMetadataValue(stmt.expr, "cType").isPresent) - parseContext.metadata.create(simplified.expr, "cType", - CComplexType.getType(stmt.expr, parseContext)) + parseContext.metadata.create( + simplified.expr, "cType", + CComplexType.getType(stmt.expr, parseContext) + ) if (parseContext.metadata.getMetadataValue(stmt.deref, "cType").isPresent) - parseContext.metadata.create(simplified.deref, "cType", - CComplexType.getType(stmt.deref, parseContext)) + parseContext.metadata.create( + simplified.deref, "cType", + CComplexType.getType(stmt.deref, parseContext) + ) StmtLabel(simplified, metadata = metadata) } is AssignStmt<*> -> { simplified as AssignStmt<*> if (parseContext.metadata.getMetadataValue(stmt.expr, "cType").isPresent) - parseContext.metadata.create(simplified.expr, "cType", - CComplexType.getType(stmt.expr, parseContext)) + parseContext.metadata.create( + simplified.expr, "cType", + CComplexType.getType(stmt.expr, parseContext) + ) StmtLabel(simplified, metadata = metadata) } is AssumeStmt -> { simplified as AssumeStmt if (parseContext.metadata.getMetadataValue(stmt.cond, "cType").isPresent) { - parseContext.metadata.create(simplified.cond, "cType", - CComplexType.getType(stmt.cond, parseContext)) + parseContext.metadata.create( + simplified.cond, "cType", + CComplexType.getType(stmt.cond, parseContext) + ) } parseContext.metadata.create(simplified, "cTruth", stmt.cond is NeqExpr<*>) StmtLabel(simplified, metadata = metadata, choiceType = choiceType) @@ -520,8 +528,10 @@ val XCFA.lazyPointsToGraph: Lazy, Set>>> .filter { (i, pair) -> pair.second != ParamDirection.IN && it.params[i] is RefExpr<*> } .map { (i, pair) -> val (param, _) = pair - Assign(cast((it.params[i] as RefExpr<*>).decl as VarDecl<*>, param.type), - cast(param.ref, param.type)) + Assign( + cast((it.params[i] as RefExpr<*>).decl as VarDecl<*>, param.type), + cast(param.ref, param.type) + ) } } ?: listOf() } @@ -534,8 +544,10 @@ val XCFA.lazyPointsToGraph: Lazy, Set>>> Assign(cast(param, param.type), cast(it.params[i], param.type)) } + proc.params.filter { it.second != ParamDirection.IN }.mapIndexed { i, (param, _) -> - Assign(cast((it.params[i] as RefExpr<*>).decl as VarDecl<*>, param.type), - cast(param.ref, param.type)) + Assign( + cast((it.params[i] as RefExpr<*>).decl as VarDecl<*>, param.type), + cast(param.ref, param.type) + ) } } ?: listOf() } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/XcfaToC.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/XcfaToC.kt index 6eacb8f086..0114015fc1 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/XcfaToC.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/XcfaToC.kt @@ -57,8 +57,10 @@ import hu.bme.mit.theta.xcfa.model.* private const val arraySize = 10; -fun XCFA.toC(parseContext: ParseContext, arraySupport: Boolean, exactArraySupport: Boolean, - intRangeConstraint: Boolean): String = """ +fun XCFA.toC( + parseContext: ParseContext, arraySupport: Boolean, exactArraySupport: Boolean, + intRangeConstraint: Boolean +): String = """ extern void abort(); extern unsigned short __VERIFIER_nondet_ushort(); extern short __VERIFIER_nondet_short(); diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaAdapter.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaAdapter.kt index 9cf2736445..338ff8d66d 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaAdapter.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaAdapter.kt @@ -111,7 +111,8 @@ class XcfaAdapter(val gsonSupplier: () -> Gson) : TypeAdapter() { private fun parseInitProcedures( reader: JsonReader, - procedures: Map): List>>> { + procedures: Map + ): List>>> { reader.beginArray() val ret = ArrayList>>>() val paramsType = object : TypeToken>>() {}.type @@ -190,9 +191,11 @@ class XcfaAdapter(val gsonSupplier: () -> Gson) : TypeAdapter() { } } } - ret[name] = XcfaProcedure(name, params, vars, locs.values.toSet(), edges, initLoc, + ret[name] = XcfaProcedure( + name, params, vars, locs.values.toSet(), edges, initLoc, Optional.ofNullable(finalLoc), - Optional.ofNullable(errorLoc)).also { it.parent = xcfa } + Optional.ofNullable(errorLoc) + ).also { it.parent = xcfa } reader.endObject() } reader.endArray() diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaLabelAdapter.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaLabelAdapter.kt index eeebe05881..a06254cf5b 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaLabelAdapter.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaLabelAdapter.kt @@ -80,11 +80,14 @@ class XcfaLabelAdapter(val scope: Scope, val env: Env, val gsonSupplier: () -> G checkNotNull(constructor) { "${clazz.simpleName} has no fromString() method." } val obj = try { - constructor.call(clazz.companionObject!!.objectInstance, content, scope, env, - metadata) + constructor.call( + clazz.companionObject!!.objectInstance, content, scope, env, + metadata + ) } catch (e: Exception) { System.err.println( - "Could not parse $content\nscope: ${scope}\nenv: $env\ntype: ${clazz.simpleName}") + "Could not parse $content\nscope: ${scope}\nenv: $env\ntype: ${clazz.simpleName}" + ) throw e } check(obj is XcfaLabel) diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Dsl.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Dsl.kt index b146c7d4f9..e3885b34b8 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Dsl.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Dsl.kt @@ -39,10 +39,14 @@ class VarContext(val builder: XcfaBuilder, private val local: Boolean) { infix fun Pair.init(initValue: String): VarDecl { val varDecl = Var(first, second) builder.addVar( - XcfaGlobalVar(varDecl, + XcfaGlobalVar( + varDecl, ExpressionWrapper(SimpleScope(SymbolTable()), initValue).instantiate( - Env()) as LitExpr<*>, - local)) + Env() + ) as LitExpr<*>, + local + ) + ) return varDecl } } @@ -89,7 +93,8 @@ class XcfaProcedureBuilderContext(val builder: XcfaProcedureBuilder) { fun start(vararg expr: Any) { val exprs = expr.map { if (it is Expr<*>) it else if (it is String) this@XcfaProcedureBuilderContext.builder.parse( - it) else error("Bad type") + it + ) else error("Bad type") } builder.parent.addEntryPoint(builder, exprs) } @@ -112,7 +117,8 @@ class XcfaProcedureBuilderContext(val builder: XcfaProcedureBuilder) { infix fun String.assign(to: String): SequenceLabel { val lhs: VarDecl = this@XcfaProcedureBuilderContext.builder.lookup( - this) as VarDecl + this + ) as VarDecl val rhs: Expr = this@XcfaProcedureBuilderContext.builder.parse(to) as Expr val label = StmtLabel(Assign(lhs, rhs)) labelList.add(label) @@ -128,7 +134,8 @@ class XcfaProcedureBuilderContext(val builder: XcfaProcedureBuilder) { infix fun String.assign(to: Expr<*>): SequenceLabel { val lhs: VarDecl = this@XcfaProcedureBuilderContext.builder.lookup( - this) as VarDecl + this + ) as VarDecl val rhs: Expr = to as Expr val label = StmtLabel(Assign(lhs, rhs)) labelList.add(label) @@ -171,7 +178,8 @@ class XcfaProcedureBuilderContext(val builder: XcfaProcedureBuilder) { operator fun XcfaProcedureBuilderContext.invoke(vararg expr: Any): SequenceLabel { val exprs = expr.map { if (it is Expr<*>) it else if (it is String) this@XcfaProcedureBuilderContext.builder.parse( - it) else error("Bad type") + it + ) else error("Bad type") } val label = InvokeLabel(this.builder.name, exprs, EmptyMetaData) this@SequenceLabelContext.labelList.add(label) @@ -181,7 +189,8 @@ class XcfaProcedureBuilderContext(val builder: XcfaProcedureBuilder) { operator fun String.invoke(vararg expr: Any): SequenceLabel { val exprs = expr.map { if (it is Expr<*>) it else if (it is String) this@XcfaProcedureBuilderContext.builder.parse( - it) else error("Bad type") + it + ) else error("Bad type") } val label = InvokeLabel(this, exprs, EmptyMetaData) this@SequenceLabelContext.labelList.add(label) @@ -192,7 +201,8 @@ class XcfaProcedureBuilderContext(val builder: XcfaProcedureBuilder) { val lhs = this@XcfaProcedureBuilderContext.builder.lookup(this) val exprs = expr.map { if (it is Expr<*>) it else if (it is String) this@XcfaProcedureBuilderContext.builder.parse( - it) else error("Bad type") + it + ) else error("Bad type") } val label = StartLabel(ctx.builder.name, exprs, lhs, EmptyMetaData) labelList.add(label) @@ -202,7 +212,8 @@ class XcfaProcedureBuilderContext(val builder: XcfaProcedureBuilder) { fun VarDecl<*>.start(ctx: XcfaProcedureBuilderContext, vararg expr: Any): SequenceLabel { val exprs = expr.map { if (it is Expr<*>) it else if (it is String) this@XcfaProcedureBuilderContext.builder.parse( - it) else error("Bad type") + it + ) else error("Bad type") } val label = StartLabel(ctx.builder.name, exprs, this, EmptyMetaData) labelList.add(label) @@ -213,7 +224,8 @@ class XcfaProcedureBuilderContext(val builder: XcfaProcedureBuilder) { val lhs = this@XcfaProcedureBuilderContext.builder.lookup(this) val exprs = expr.map { if (it is Expr<*>) it else if (it is String) this@XcfaProcedureBuilderContext.builder.parse( - it) else error("Bad type") + it + ) else error("Bad type") } val label = StartLabel(ctx, exprs, lhs, EmptyMetaData) labelList.add(label) @@ -223,7 +235,8 @@ class XcfaProcedureBuilderContext(val builder: XcfaProcedureBuilder) { fun VarDecl<*>.start(ctx: String, vararg expr: Any): SequenceLabel { val exprs = expr.map { if (it is Expr<*>) it else if (it is String) this@XcfaProcedureBuilderContext.builder.parse( - it) else error("Bad type") + it + ) else error("Bad type") } val label = StartLabel(ctx, exprs, this, EmptyMetaData) labelList.add(label) @@ -301,8 +314,10 @@ fun XcfaBuilder.threadlocal(lambda: VarContext.() -> Unit) { context.apply(lambda) } -fun XcfaBuilder.procedure(name: String, passManager: ProcedurePassManager, - lambda: XcfaProcedureBuilderContext.() -> Unit): XcfaProcedureBuilderContext { +fun XcfaBuilder.procedure( + name: String, passManager: ProcedurePassManager, + lambda: XcfaProcedureBuilderContext.() -> Unit +): XcfaProcedureBuilderContext { val builder = XcfaProcedureBuilder(name, passManager) builder.parent = this val procBuilder = XcfaProcedureBuilderContext(builder).apply(lambda) @@ -310,7 +325,9 @@ fun XcfaBuilder.procedure(name: String, passManager: ProcedurePassManager, return procBuilder } -fun XcfaBuilder.procedure(name: String, - lambda: XcfaProcedureBuilderContext.() -> Unit): XcfaProcedureBuilderContext { +fun XcfaBuilder.procedure( + name: String, + lambda: XcfaProcedureBuilderContext.() -> Unit +): XcfaProcedureBuilderContext { return procedure(name, ProcedurePassManager(), lambda) } \ No newline at end of file diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Visualizer.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Visualizer.kt index 177c75758d..4080379efa 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Visualizer.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Visualizer.kt @@ -37,7 +37,8 @@ fun XcfaProcedure.toDot(edgeLabelCustomizer: ((XcfaEdge) -> String)?): String { locs.forEach { builder.appendLine("${it.name}[];") } edges.forEach { builder.appendLine( - "${it.source.name} -> ${it.target.name} [label=\"${it.label} ${edgeLabelCustomizer?.invoke(it) ?: ""}\"];") + "${it.source.name} -> ${it.target.name} [label=\"${it.label} ${edgeLabelCustomizer?.invoke(it) ?: ""}\"];" + ) } return builder.toString() } \ No newline at end of file diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XcfaLabel.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XcfaLabel.kt index 93f636b306..519a9d8627 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XcfaLabel.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XcfaLabel.kt @@ -50,9 +50,11 @@ data class InvokeLabel @JvmOverloads constructor( fun fromString(s: String, scope: Scope, env: Env, metadata: MetaData): XcfaLabel { val (name, params) = Regex("([^\\(]*)\\((.*)\\)").matchEntire(s)!!.destructured - return InvokeLabel(name, + return InvokeLabel( + name, params.split(",").map { ExpressionWrapper(scope, it).instantiate(env) }, - metadata = metadata) + metadata = metadata + ) } } } @@ -87,11 +89,14 @@ data class StartLabel( fun fromString(s: String, scope: Scope, env: Env, metadata: MetaData): XcfaLabel { val (pidVarName, pidVarType, name, params) = Regex( - "\\(var (.*) (.*)\\) = start (.*)\\((.*)\\)").matchEntire(s)!!.destructured + "\\(var (.*) (.*)\\) = start (.*)\\((.*)\\)" + ).matchEntire(s)!!.destructured val pidVar = env.eval(scope.resolve(pidVarName).orElseThrow()) as VarDecl<*> - return StartLabel(name, + return StartLabel( + name, params.split(",").map { ExpressionWrapper(scope, it).instantiate(env) }, pidVar, - metadata = metadata) + metadata = metadata + ) } } } @@ -109,7 +114,8 @@ data class JoinLabel( fun fromString(s: String, scope: Scope, env: Env, metadata: MetaData): XcfaLabel { val (pidVarName, pidVarType) = Regex("join \\(var (.*) (.*)\\)").matchEntire( - s)!!.destructured + s + )!!.destructured val pidVar = env.eval(scope.resolve(pidVarName).orElseThrow()) as VarDecl<*> return JoinLabel(pidVar, metadata = metadata) } @@ -130,7 +136,8 @@ data class StmtLabel @JvmOverloads constructor( init { check( - stmt !is NonDetStmt && stmt !is SequenceStmt) { "NonDetStmt and SequenceStmt are not supported in XCFA. Use the corresponding labels instead." } + stmt !is NonDetStmt && stmt !is SequenceStmt + ) { "NonDetStmt and SequenceStmt are not supported in XCFA. Use the corresponding labels instead." } } override fun toStmt(): Stmt = stmt @@ -147,11 +154,15 @@ data class StmtLabel @JvmOverloads constructor( val matchResult = Regex("\\((.*)\\)\\[choiceType=(.*)]").matchEntire(s) if (matchResult != null) { val (stmt, choiceTypeStr) = matchResult.destructured - return StmtLabel(StatementWrapper(stmt, scope).instantiate(env), - choiceType = ChoiceType.valueOf(choiceTypeStr), metadata = metadata) + return StmtLabel( + StatementWrapper(stmt, scope).instantiate(env), + choiceType = ChoiceType.valueOf(choiceTypeStr), metadata = metadata + ) } else { - return StmtLabel(StatementWrapper(s, scope).instantiate(env), - choiceType = ChoiceType.NONE, metadata = metadata) + return StmtLabel( + StatementWrapper(s, scope).instantiate(env), + choiceType = ChoiceType.NONE, metadata = metadata + ) } } } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/AssumeFalseRemovalPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/AssumeFalseRemovalPass.kt index 17bbdde26e..7db5191f4b 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/AssumeFalseRemovalPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/AssumeFalseRemovalPass.kt @@ -29,7 +29,8 @@ class AssumeFalseRemovalPass : ProcedurePass { override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { builder.getEdges().toSet().forEach { edge -> if (edge.getFlatLabels() - .any { it is StmtLabel && it.stmt is AssumeStmt && it.stmt.cond is FalseExpr }) { + .any { it is StmtLabel && it.stmt is AssumeStmt && it.stmt.cond is FalseExpr } + ) { builder.removeEdge(edge) } } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/AtomicReadsOneWritePass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/AtomicReadsOneWritePass.kt index d4927ebaad..5366595cc5 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/AtomicReadsOneWritePass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/AtomicReadsOneWritePass.kt @@ -160,9 +160,12 @@ class AtomicReadsOneWritePass : ProcedurePass { private fun XcfaLabel.replaceAccesses(localVersions: Map, VarDecl<*>>): XcfaLabel { return when (this) { is StmtLabel -> when (val stmt = stmt) { - is AssignStmt<*> -> StmtLabel(AssignStmt.of( - cast(localVersions[stmt.varDecl] ?: stmt.varDecl, stmt.varDecl.type), - cast(stmt.expr.replace(localVersions), stmt.varDecl.type))) + is AssignStmt<*> -> StmtLabel( + AssignStmt.of( + cast(localVersions[stmt.varDecl] ?: stmt.varDecl, stmt.varDecl.type), + cast(stmt.expr.replace(localVersions), stmt.varDecl.type) + ) + ) is AssumeStmt -> StmtLabel(AssumeStmt.of(stmt.cond.replace(localVersions))) is HavocStmt<*> -> StmtLabel(HavocStmt.of(localVersions[stmt.varDecl] ?: stmt.varDecl)) diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/CLibraryFunctionsPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/CLibraryFunctionsPass.kt index 7803f1daaf..9fddf43123 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/CLibraryFunctionsPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/CLibraryFunctionsPass.kt @@ -71,9 +71,13 @@ class CLibraryFunctionsPass : ProcedurePass { val param = invokeLabel.params[4] - listOf(StartLabel((funcptr as RefExpr).decl.name, - listOf(Int(0), param), // int(0) to solve StartLabel not handling return params - (handle as RefExpr).decl as VarDecl<*>, metadata)) + listOf( + StartLabel( + (funcptr as RefExpr).decl.name, + listOf(Int(0), param), // int(0) to solve StartLabel not handling return params + (handle as RefExpr).decl as VarDecl<*>, metadata + ) + ) } "pthread_mutex_lock" -> { @@ -101,8 +105,10 @@ class CLibraryFunctionsPass : ProcedurePass { check(handle is RefExpr && (handle as RefExpr).decl is VarDecl) listOf( - FenceLabel(setOf("start_cond_wait(${cond.decl.name},${handle.decl.name})"), - metadata), + FenceLabel( + setOf("start_cond_wait(${cond.decl.name},${handle.decl.name})"), + metadata + ), FenceLabel(setOf("cond_wait(${cond.decl.name},${handle.decl.name})"), metadata) ) } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ErrorLocationPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ErrorLocationPass.kt index d539cb6240..6dd64e2b45 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ErrorLocationPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ErrorLocationPass.kt @@ -29,13 +29,16 @@ class ErrorLocationPass(private val checkOverflow: Boolean) : ProcedurePass { for (edge in ArrayList(builder.getEdges())) { val edges = edge.splitIf(this::predicate) if (edges.size > 1 || (edges.size == 1 && predicate( - (edges[0].label as SequenceLabel).labels[0]))) { + (edges[0].label as SequenceLabel).labels[0] + )) + ) { builder.removeEdge(edge) edges.forEach { if (predicate((it.label as SequenceLabel).labels[0])) { if (builder.errorLoc.isEmpty) builder.createErrorLoc() builder.addEdge( - XcfaEdge(it.source, builder.errorLoc.get(), SequenceLabel(listOf()))) + XcfaEdge(it.source, builder.errorLoc.get(), SequenceLabel(listOf())) + ) } else { builder.addEdge(it) } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FetchExecuteWriteback.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FetchExecuteWriteback.kt index 0ed1eee7a1..89c11f3a78 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FetchExecuteWriteback.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FetchExecuteWriteback.kt @@ -74,28 +74,39 @@ class FetchExecuteWriteback(val parseContext: ParseContext) : ProcedurePass { val lut = getDerefLut(dereferences, builder) SequenceLabel(lut.map { StmtLabel(Assign(cast(it.value, it.value.type), - cast(it.key.map { it.replaceDerefs(lut) }, it.value.type))) - } + InvokeLabel(this.name, this.params.map { it.replaceDerefs(lut) }, metadata, - tempLookup), metadata) + cast(it.key.map { it.replaceDerefs(lut) }, it.value.type) + ) + ) + } + InvokeLabel( + this.name, this.params.map { it.replaceDerefs(lut) }, metadata, + tempLookup + ), metadata + ) } is StartLabel -> { val lut = getDerefLut(dereferences, builder) SequenceLabel(lut.map { StmtLabel(Assign(cast(it.value, it.value.type), - cast(it.key.map { it.replaceDerefs(lut) }, it.value.type))) + cast(it.key.map { it.replaceDerefs(lut) }, it.value.type) + ) + ) } + StartLabel(name, params.map { it.replaceDerefs(lut) }, pidVar, metadata, tempLookup), metadata) } - is StmtLabel -> SequenceLabel(stmt.replaceDerefs(builder).map { StmtLabel(it, choiceType, metadata) }, - metadata) + is StmtLabel -> SequenceLabel( + stmt.replaceDerefs(builder).map { StmtLabel(it, choiceType, metadata) }, + metadata + ) else -> error("Not implemented for ${this.javaClass.simpleName}") } } else this - private fun getDerefLut(dereferences: List>, - builder: XcfaProcedureBuilder) = dereferences.associateWith { + private fun getDerefLut( + dereferences: List>, + builder: XcfaProcedureBuilder + ) = dereferences.associateWith { val tmpVar = Var("__THETA_heap_tmp_$cnt", it.type) builder.addVar(tmpVar) tmpVar @@ -119,14 +130,21 @@ class FetchExecuteWriteback(val parseContext: ParseContext) : ProcedurePass { val accessType = dereferencesWithAccessTypes.filter { dereferences.contains(it.first) } for (dereference in accessType.filter { it.second.isRead }.map { it.first }) { ret.add(Assign(cast(lut[dereference]!!, dereference.type), - cast(dereference.map { it.replaceDerefs(lut.filter { it.key != dereference }) }, dereference.type))) + cast(dereference.map { it.replaceDerefs(lut.filter { it.key != dereference }) }, dereference.type) + ) + ) } ret.add(stmt) for (dereference in accessType.filter { it.second.isWritten }.map { it.first }) { - ret.add(MemoryAssign( - cast(dereference.map { it.replaceDerefs(lut.filter { it.key != dereference }) }, - dereference.type) as Dereference<*, *, Type>, - cast(lut[dereference]!!, dereference.type).ref)) + ret.add( + MemoryAssign( + cast( + dereference.map { it.replaceDerefs(lut.filter { it.key != dereference }) }, + dereference.type + ) as Dereference<*, *, Type>, + cast(lut[dereference]!!, dereference.type).ref + ) + ) } return ret } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FinalLocationPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FinalLocationPass.kt index 987722b622..e586621cad 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FinalLocationPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FinalLocationPass.kt @@ -31,15 +31,23 @@ class FinalLocationPass(private val checkOverflow: Boolean) : ProcedurePass { for (edge in ArrayList(builder.getEdges())) { val edges = edge.splitIf(this::predicate) if (edges.size > 1 || (edges.size == 1 && predicate( - (edges[0].label as SequenceLabel).labels[0]))) { + (edges[0].label as SequenceLabel).labels[0] + )) + ) { builder.removeEdge(edge) edges.forEach { if (predicate((it.label as SequenceLabel).labels[0])) { if (builder.finalLoc.isEmpty) builder.createFinalLoc() - builder.addEdge(XcfaEdge(it.source, builder.finalLoc.get(), SequenceLabel( - listOf( - StmtLabel(Stmts.Assume(BoolExprs.False()), metadata = it.metadata)), - metadata = it.metadata))) + builder.addEdge( + XcfaEdge( + it.source, builder.finalLoc.get(), SequenceLabel( + listOf( + StmtLabel(Stmts.Assume(BoolExprs.False()), metadata = it.metadata) + ), + metadata = it.metadata + ) + ) + ) } else { builder.addEdge(it) } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FpFunctionsToExprsPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FpFunctionsToExprsPass.kt index 8a05f0ef2b..8cabaf35e0 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FpFunctionsToExprsPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FpFunctionsToExprsPass.kt @@ -57,44 +57,78 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { } private val handlers: MutableMap> = LinkedHashMap() - private fun addHandler(names: Array, - handler: BiFunction) { + private fun addHandler( + names: Array, + handler: BiFunction + ) { for (name in names) { handlers[name] = handler } } init { - addHandler(arrayOf("fabs", "fabsf", - "fabsl")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "fabs", "fabsf", + "fabsl" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleFabs(builder, callStmt) } - addHandler(arrayOf("floor", "floorf", - "floorl")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "floor", "floorf", + "floorl" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleFloor(builder, callStmt) } - addHandler(arrayOf("fmax", "fmaxf", - "fmaxl")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "fmax", "fmaxf", + "fmaxl" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleFmax(builder, callStmt) } - addHandler(arrayOf("fmin", "fminf", - "fminl")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "fmin", "fminf", + "fminl" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleFmin(builder, callStmt) } - addHandler(arrayOf("fmod", "fmodf", - "fmodl")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "fmod", "fmodf", + "fmodl" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleFmod(builder, callStmt) } - addHandler(arrayOf("sqrt", "sqrtf", - "sqrtl")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "sqrt", "sqrtf", + "sqrtl" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleSqrt(builder, callStmt) } - addHandler(arrayOf("round", "roundf", - "roundl")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "round", "roundf", + "roundl" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleRound(builder, callStmt) } - addHandler(arrayOf("isnan", "__isnan", "isnanf", "__isnanf", "isnanl", - "__isnanl")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "isnan", "__isnan", "isnanf", "__isnanf", "isnanl", + "__isnanl" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleIsnan(builder, callStmt) } addHandler(arrayOf("trunc")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> @@ -103,22 +137,37 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { addHandler(arrayOf("ceil")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleCeil(builder, callStmt) } - addHandler(arrayOf( - "isnormal")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "isnormal" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleIsnormal(builder, callStmt) } - addHandler(arrayOf("isinf", "__isinf", "__isinff", "isinff", - "__isinfl", "isinfl")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "isinf", "__isinf", "__isinff", "isinff", + "__isinfl", "isinfl" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleIsinf(builder, callStmt) } - addHandler(arrayOf( - "isfinite", "finite", "isfinitef", "finitef", "isfinite", "finitel", "__finite", "__finitef", "__finitel", - "__isfinite", - "__isfinitef", "__isfinitel")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "isfinite", "finite", "isfinitef", "finitef", "isfinite", "finitel", "__finite", "__finitef", + "__finitel", + "__isfinite", + "__isfinitef", "__isfinitel" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleIsfinite(builder, callStmt) } - addHandler(arrayOf("__fpclassify", "__fpclassifyf", - "__fpclassifyl")) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> + addHandler( + arrayOf( + "__fpclassify", "__fpclassifyf", + "__fpclassifyl" + ) + ) { builder: XcfaProcedureBuilder, callStmt: InvokeLabel -> handleFpclassify(builder, callStmt) } } @@ -127,10 +176,16 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { Preconditions.checkState(callStmt.params.size == 2, "Function is presumed to be unary!") val expr = callStmt.params[0] Preconditions.checkState(expr is RefExpr<*>) - val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl, - FpRoundToIntegralExpr.of(FpRoundingMode.RTZ, - TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), - CComplexType.getType(expr, parseContext).smtType) as Expr)) + val assign = Stmts.Assign( + (expr as RefExpr<*>).decl as VarDecl, + FpRoundToIntegralExpr.of( + FpRoundingMode.RTZ, + TypeUtils.cast( + CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), + CComplexType.getType(expr, parseContext).smtType + ) as Expr + ) + ) if (parseContext.metadata.getMetadataValue(expr, "cType").isPresent) { parseContext.metadata.create(assign.expr, "cType", CComplexType.getType(expr, parseContext)) } @@ -141,10 +196,16 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { Preconditions.checkState(callStmt.params.size == 2, "Function is presumed to be unary!") val expr = callStmt.params[0] Preconditions.checkState(expr is RefExpr<*>) - val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl, - FpRoundToIntegralExpr.of(FpRoundingMode.RTP, - TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), - CComplexType.getType(expr, parseContext).smtType) as Expr)) + val assign = Stmts.Assign( + (expr as RefExpr<*>).decl as VarDecl, + FpRoundToIntegralExpr.of( + FpRoundingMode.RTP, + TypeUtils.cast( + CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), + CComplexType.getType(expr, parseContext).smtType + ) as Expr + ) + ) if (parseContext.metadata.getMetadataValue(expr, "cType").isPresent) { parseContext.metadata.create(assign.expr, "cType", CComplexType.getType(expr, parseContext)) } @@ -158,38 +219,54 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { val type = CSignedInt(null, parseContext) val assign: AssignStmt<*> = Stmts.Assign( TypeUtils.cast((expr as RefExpr<*>).decl as VarDecl<*>, type.smtType), - TypeUtils.cast(AbstractExprs.Ite( - FpIsInfiniteExpr.of(callStmt.params[1] as Expr), - type.unitValue, type.nullValue), - type.smtType)) + TypeUtils.cast( + AbstractExprs.Ite( + FpIsInfiniteExpr.of(callStmt.params[1] as Expr), + type.unitValue, type.nullValue + ), + type.smtType + ) + ) parseContext.metadata.create(assign.expr, "cType", type) return StmtLabel(assign, metadata = callStmt.metadata) } - private fun handleIsfinite(builder: XcfaProcedureBuilder, - callStmt: InvokeLabel): XcfaLabel { + private fun handleIsfinite( + builder: XcfaProcedureBuilder, + callStmt: InvokeLabel + ): XcfaLabel { Preconditions.checkState(callStmt.params.size == 2, "Function is presumed to be unary!") val expr = callStmt.params[0] Preconditions.checkState(expr is RefExpr<*>) val type = CSignedInt(null, parseContext) val assign: AssignStmt<*> = Stmts.Assign( TypeUtils.cast((expr as RefExpr<*>).decl as VarDecl<*>, type.smtType), - TypeUtils.cast(AbstractExprs.Ite( - Or(FpIsInfiniteExpr.of(callStmt.params[1] as Expr), - FpIsNanExpr.of(callStmt.params[1] as Expr)), - type.nullValue, type.unitValue), - type.smtType)) + TypeUtils.cast( + AbstractExprs.Ite( + Or( + FpIsInfiniteExpr.of(callStmt.params[1] as Expr), + FpIsNanExpr.of(callStmt.params[1] as Expr) + ), + type.nullValue, type.unitValue + ), + type.smtType + ) + ) parseContext.metadata.create(assign.expr, "cType", type) return StmtLabel(assign, metadata = callStmt.metadata) } - private fun handleIsnormal(builder: XcfaProcedureBuilder, - callStmt: InvokeLabel): XcfaLabel { + private fun handleIsnormal( + builder: XcfaProcedureBuilder, + callStmt: InvokeLabel + ): XcfaLabel { throw UnsupportedOperationException() } - private fun handleFpclassify(builder: XcfaProcedureBuilder, - callStmt: InvokeLabel): XcfaLabel { + private fun handleFpclassify( + builder: XcfaProcedureBuilder, + callStmt: InvokeLabel + ): XcfaLabel { throw UnsupportedOperationException() } @@ -204,7 +281,10 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { TypeUtils.cast( AbstractExprs.Ite( FpIsNanExpr.of(callStmt.params[1] as Expr), - type.unitValue, type.nullValue), type.smtType)) + type.unitValue, type.nullValue + ), type.smtType + ) + ) parseContext.metadata.create(assign.expr, "cType", type) return StmtLabel(assign, metadata = callStmt.metadata) } else { @@ -216,10 +296,16 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { Preconditions.checkState(callStmt.params.size == 2, "Function is presumed to be unary!") val expr = callStmt.params[0] Preconditions.checkState(expr is RefExpr<*>) - val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl, - FpRoundToIntegralExpr.of(FpRoundingMode.RNA, - TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), - CComplexType.getType(expr, parseContext).smtType) as Expr)) + val assign = Stmts.Assign( + (expr as RefExpr<*>).decl as VarDecl, + FpRoundToIntegralExpr.of( + FpRoundingMode.RNA, + TypeUtils.cast( + CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), + CComplexType.getType(expr, parseContext).smtType + ) as Expr + ) + ) if (parseContext.metadata.getMetadataValue(expr, "cType").isPresent) { parseContext.metadata.create(assign.expr, "cType", CComplexType.getType(expr, parseContext)) } @@ -230,10 +316,16 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { Preconditions.checkState(callStmt.params.size == 2, "Function is presumed to be unary!") val expr = callStmt.params[0] Preconditions.checkState(expr is RefExpr<*>) - val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl, - FpSqrtExpr.of(FpRoundingMode.RNE, - TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), - CComplexType.getType(expr, parseContext).smtType) as Expr)) + val assign = Stmts.Assign( + (expr as RefExpr<*>).decl as VarDecl, + FpSqrtExpr.of( + FpRoundingMode.RNE, + TypeUtils.cast( + CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), + CComplexType.getType(expr, parseContext).smtType + ) as Expr + ) + ) if (parseContext.metadata.getMetadataValue(expr, "cType").isPresent) { parseContext.metadata.create(assign.expr, "cType", CComplexType.getType(expr, parseContext)) } @@ -245,15 +337,25 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { } private fun handleFmin(builder: XcfaProcedureBuilder, callStmt: InvokeLabel): XcfaLabel { - Preconditions.checkState(callStmt.params.size == 3, - "Function is presumed to be binary!") + Preconditions.checkState( + callStmt.params.size == 3, + "Function is presumed to be binary!" + ) val expr = callStmt.params[0] Preconditions.checkState(expr is RefExpr<*>) - val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl, - FpMinExpr.of(TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), - CComplexType.getType(expr, parseContext).smtType) as Expr, - TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[2]), - CComplexType.getType(expr, parseContext).smtType) as Expr)) + val assign = Stmts.Assign( + (expr as RefExpr<*>).decl as VarDecl, + FpMinExpr.of( + TypeUtils.cast( + CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), + CComplexType.getType(expr, parseContext).smtType + ) as Expr, + TypeUtils.cast( + CComplexType.getType(expr, parseContext).castTo(callStmt.params[2]), + CComplexType.getType(expr, parseContext).smtType + ) as Expr + ) + ) if (parseContext.metadata.getMetadataValue(expr, "cType").isPresent) { parseContext.metadata.create(assign.expr, "cType", CComplexType.getType(expr, parseContext)) } @@ -261,15 +363,25 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { } private fun handleFmax(builder: XcfaProcedureBuilder, callStmt: InvokeLabel): XcfaLabel { - Preconditions.checkState(callStmt.params.size == 3, - "Function is presumed to be binary!") + Preconditions.checkState( + callStmt.params.size == 3, + "Function is presumed to be binary!" + ) val expr = callStmt.params[0] Preconditions.checkState(expr is RefExpr<*>) - val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl, - FpMaxExpr.of(TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), - CComplexType.getType(expr, parseContext).smtType) as Expr, - TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[2]), - CComplexType.getType(expr, parseContext).smtType) as Expr)) + val assign = Stmts.Assign( + (expr as RefExpr<*>).decl as VarDecl, + FpMaxExpr.of( + TypeUtils.cast( + CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), + CComplexType.getType(expr, parseContext).smtType + ) as Expr, + TypeUtils.cast( + CComplexType.getType(expr, parseContext).castTo(callStmt.params[2]), + CComplexType.getType(expr, parseContext).smtType + ) as Expr + ) + ) if (parseContext.metadata.getMetadataValue(expr, "cType").isPresent) { parseContext.metadata.create(assign.expr, "cType", CComplexType.getType(expr, parseContext)) } @@ -280,10 +392,16 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { Preconditions.checkState(callStmt.params.size == 2, "Function is presumed to be unary!") val expr = callStmt.params[0] Preconditions.checkState(expr is RefExpr<*>) - val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl, - FpRoundToIntegralExpr.of(FpRoundingMode.RTN, - TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), - CComplexType.getType(expr, parseContext).smtType) as Expr)) + val assign = Stmts.Assign( + (expr as RefExpr<*>).decl as VarDecl, + FpRoundToIntegralExpr.of( + FpRoundingMode.RTN, + TypeUtils.cast( + CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), + CComplexType.getType(expr, parseContext).smtType + ) as Expr + ) + ) if (parseContext.metadata.getMetadataValue(expr, "cType").isPresent) { parseContext.metadata.create(assign.expr, "cType", CComplexType.getType(expr, parseContext)) } @@ -294,9 +412,15 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass { Preconditions.checkState(callStmt.params.size == 2, "Function is presumed to be unary!") val expr = callStmt.params[0] Preconditions.checkState(expr is RefExpr<*>) - val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl, - FpAbsExpr.of(TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), - CComplexType.getType(expr, parseContext).smtType) as Expr)) + val assign = Stmts.Assign( + (expr as RefExpr<*>).decl as VarDecl, + FpAbsExpr.of( + TypeUtils.cast( + CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]), + CComplexType.getType(expr, parseContext).smtType + ) as Expr + ) + ) if (parseContext.metadata.getMetadataValue(expr, "cType").isPresent) { parseContext.metadata.create(assign.expr, "cType", CComplexType.getType(expr, parseContext)) } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/HavocPromotionAndRange.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/HavocPromotionAndRange.kt index 7b0b3eccfa..b1fb46146a 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/HavocPromotionAndRange.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/HavocPromotionAndRange.kt @@ -75,7 +75,8 @@ class HavocPromotionAndRange(val parseContext: ParseContext) : ProcedurePass { // val type = CComplexType.getType(((edge.label.labels[index + 1] as StmtLabel).stmt as AssignStmt<*>).expr, parseContext) val havoc = Havoc(varDecl) newLabels.add( - StmtLabel(havoc, metadata = edge.label.labels[index].metadata)) + StmtLabel(havoc, metadata = edge.label.labels[index].metadata) + ) // newLabels.add(StmtLabel(type.limit(varDecl.ref))) } else if (index == indices[offset] + 1) { offset++ @@ -98,11 +99,15 @@ class HavocPromotionAndRange(val parseContext: ParseContext) : ProcedurePass { for ((index, value) in reversed) { val varDecl = ((value as StmtLabel).stmt as HavocStmt<*>).varDecl if (parseContext.metadata.getMetadataValue(varDecl.ref, "cType").isPresent) { - val type = CComplexType.getType(varDecl.ref, - parseContext) // TODO: what to do when no info is available? + val type = CComplexType.getType( + varDecl.ref, + parseContext + ) // TODO: what to do when no info is available? if (type !is CVoid) { - list.add(index + 1, - StmtLabel(type.limit(varDecl.ref), metadata = value.metadata)) + list.add( + index + 1, + StmtLabel(type.limit(varDecl.ref), metadata = value.metadata) + ) } } } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/InlineProceduresPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/InlineProceduresPass.kt index 48114fc020..c4656380c5 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/InlineProceduresPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/InlineProceduresPass.kt @@ -63,25 +63,34 @@ class InlineProceduresPass(val parseContext: ParseContext) : ProcedurePass { procedure.getVars().forEach { builder.addVar(it) } procedure.getParams().forEach { builder.addVar(it.first) } procedure.getEdges().forEach { - builder.addEdge(it.withSource(checkNotNull(newLocs[it.source])) - .withTarget(checkNotNull(newLocs[it.target]))) + builder.addEdge( + it.withSource(checkNotNull(newLocs[it.source])) + .withTarget(checkNotNull(newLocs[it.target])) + ) } val inStmts: MutableList = ArrayList() val outStmts: MutableList = ArrayList() for ((i, param) in procedure.getParams().withIndex()) { if (param.second != ParamDirection.OUT) { - val stmt = AssignStmt.of(cast(param.first, param.first.type), - cast(CComplexType.getType(param.first.ref, parseContext) - .castTo(invokeLabel.params[i]), param.first.type)) + val stmt = AssignStmt.of( + cast(param.first, param.first.type), + cast( + CComplexType.getType(param.first.ref, parseContext) + .castTo(invokeLabel.params[i]), param.first.type + ) + ) inStmts.add(StmtLabel(stmt, metadata = invokeLabel.metadata)) } if (param.second != ParamDirection.IN) { val varDecl = (invokeLabel.params[i] as RefExpr<*>).decl as VarDecl<*> - val stmt = AssignStmt.of(cast(varDecl, param.first.type), cast( - CComplexType.getType(varDecl.ref, parseContext).castTo(param.first.ref), - param.first.type)) + val stmt = AssignStmt.of( + cast(varDecl, param.first.type), cast( + CComplexType.getType(varDecl.ref, parseContext).castTo(param.first.ref), + param.first.type + ) + ) outStmts.add(StmtLabel(stmt, metadata = invokeLabel.metadata)) } } @@ -92,13 +101,20 @@ class InlineProceduresPass(val parseContext: ParseContext) : ProcedurePass { builder.addEdge(XcfaEdge(source, checkNotNull(newLocs[initLoc]), SequenceLabel(inStmts))) if (finalLoc.isPresent) - builder.addEdge(XcfaEdge(checkNotNull(newLocs[finalLoc.get()]), target, - SequenceLabel(outStmts))) + builder.addEdge( + XcfaEdge( + checkNotNull(newLocs[finalLoc.get()]), target, + SequenceLabel(outStmts) + ) + ) if (errorLoc.isPresent) { if (builder.errorLoc.isEmpty) builder.createErrorLoc() builder.addEdge( - XcfaEdge(checkNotNull(newLocs[errorLoc.get()]), builder.errorLoc.get(), - SequenceLabel(listOf()))) + XcfaEdge( + checkNotNull(newLocs[errorLoc.get()]), builder.errorLoc.get(), + SequenceLabel(listOf()) + ) + ) } } else { builder.addEdge(e) diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/LbePass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/LbePass.kt index bc745cfe67..8e37818330 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/LbePass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/LbePass.kt @@ -145,8 +145,10 @@ class LbePass(val parseContext: ParseContext) : ProcedurePass { * @param strict If true, cascade collapsing is limited to locations in locationsToVisit. * @return Returns the list of removed locations. */ - private fun collapseParallelsAndSnakes(locationsToVisit: List, - strict: Boolean): List { + private fun collapseParallelsAndSnakes( + locationsToVisit: List, + strict: Boolean + ): List { val editedLocationsToVisit = locationsToVisit.toMutableList() val removedLocations = mutableListOf() while (editedLocationsToVisit.isNotEmpty()) { @@ -200,8 +202,10 @@ class LbePass(val parseContext: ParseContext) : ProcedurePass { * @param locationsToVisit Adds the targets of parallel edges to this list (new parallel edges and snakes * can appear in these locations) */ - private fun collapseParallelEdges(location: XcfaLocation, - locationsToVisit: MutableList) { + private fun collapseParallelEdges( + location: XcfaLocation, + locationsToVisit: MutableList + ) { val edgesByTarget = mutableMapOf>() for (edge in location.outgoingEdges) { val edgesToTarget = edgesByTarget.getOrDefault(edge.target, ArrayList()) @@ -235,8 +239,10 @@ class LbePass(val parseContext: ParseContext) : ProcedurePass { * added to this list * @param removedLocations The list of removed locations: the collapsed location is added to this list */ - private fun collapsePartOfSnake(location: XcfaLocation, - locationsToVisit: MutableList, removedLocations: MutableList) { + private fun collapsePartOfSnake( + location: XcfaLocation, + locationsToVisit: MutableList, removedLocations: MutableList + ) { if (location.incomingEdges.size == 1 && location.outgoingEdges.size == 1) { val previousLocation = location.incomingEdges.first().source val removed = removeMiddleLocation(location) diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MallocFunctionPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MallocFunctionPass.kt index 07a1b62bb9..638bee932d 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MallocFunctionPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MallocFunctionPass.kt @@ -45,7 +45,9 @@ class MallocFunctionPass(val parseContext: ParseContext) : ProcedurePass { for (edge in ArrayList(builder.getEdges())) { val edges = edge.splitIf(this::predicate) if (edges.size > 1 || (edges.size == 1 && predicate( - (edges[0].label as SequenceLabel).labels[0]))) { + (edges[0].label as SequenceLabel).labels[0] + )) + ) { builder.removeEdge(edge) edges.forEach { if (predicate((it.label as SequenceLabel).labels[0])) { @@ -54,15 +56,21 @@ class MallocFunctionPass(val parseContext: ParseContext) : ProcedurePass { val mallocVar = builder.parent.malloc if (builder.parent.getVars().none { it.wrappedVar == mallocVar }) { // initial creation builder.parent.addVar( - XcfaGlobalVar(mallocVar, CComplexType.getType(ret, parseContext).nullValue)) + XcfaGlobalVar(mallocVar, CComplexType.getType(ret, parseContext).nullValue) + ) val initProc = builder.parent.getInitProcedures().map { it.first } checkState(initProc.size == 1, "Multiple start procedure are not handled well") initProc.forEach { - val initAssign = StmtLabel(Assign(cast(mallocVar, mallocVar.type), - cast(CComplexType.getType(ret, parseContext).nullValue, mallocVar.type))) + val initAssign = StmtLabel( + Assign( + cast(mallocVar, mallocVar.type), + cast(CComplexType.getType(ret, parseContext).nullValue, mallocVar.type) + ) + ) val newEdges = it.initLoc.outgoingEdges.map { it.withLabel( - SequenceLabel(listOf(initAssign) + it.label.getFlatLabels(), it.label.metadata)) + SequenceLabel(listOf(initAssign) + it.label.getFlatLabels(), it.label.metadata) + ) } it.initLoc.outgoingEdges.forEach(it::removeEdge) newEdges.forEach(it::addEdge) @@ -70,14 +78,24 @@ class MallocFunctionPass(val parseContext: ParseContext) : ProcedurePass { } val assign1 = AssignStmt.of( cast(mallocVar, ret.type), - cast(Add(mallocVar.ref, CComplexType.getType(ret, parseContext).getValue("3")), - ret.type)) + cast( + Add(mallocVar.ref, CComplexType.getType(ret, parseContext).getValue("3")), + ret.type + ) + ) val assign2 = AssignStmt.of( - cast(ret.decl as VarDecl<*>, ret.type), cast(mallocVar.ref, ret.type)) - builder.addEdge(XcfaEdge(it.source, it.target, SequenceLabel( - listOf( - StmtLabel(assign1, metadata = invokeLabel.metadata), - StmtLabel(assign2, metadata = invokeLabel.metadata))))) + cast(ret.decl as VarDecl<*>, ret.type), cast(mallocVar.ref, ret.type) + ) + builder.addEdge( + XcfaEdge( + it.source, it.target, SequenceLabel( + listOf( + StmtLabel(assign1, metadata = invokeLabel.metadata), + StmtLabel(assign2, metadata = invokeLabel.metadata) + ) + ) + ) + ) } else { builder.addEdge(it) } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NoSideEffectPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NoSideEffectPass.kt index ffcda3e8bb..cf88e7314b 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NoSideEffectPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NoSideEffectPass.kt @@ -30,7 +30,9 @@ class NoSideEffectPass(val parseContext: ParseContext) : ProcedurePass { for (edge in ArrayList(builder.getEdges())) { val edges = edge.splitIf(this::predicate) if (edges.size > 1 || (edges.size == 1 && predicate( - (edges[0].label as SequenceLabel).labels[0]))) { + (edges[0].label as SequenceLabel).labels[0] + )) + ) { builder.removeEdge(edge) edges.forEach { if (predicate((it.label as SequenceLabel).labels[0])) { diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NondetFunctionPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NondetFunctionPass.kt index fd7dfcb847..b5b4eb8faf 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NondetFunctionPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NondetFunctionPass.kt @@ -32,15 +32,23 @@ class NondetFunctionPass : ProcedurePass { for (edge in ArrayList(builder.getEdges())) { val edges = edge.splitIf(this::predicate) if (edges.size > 1 || (edges.size == 1 && predicate( - (edges[0].label as SequenceLabel).labels[0]))) { + (edges[0].label as SequenceLabel).labels[0] + )) + ) { builder.removeEdge(edge) edges.forEach { if (predicate((it.label as SequenceLabel).labels[0])) { val invokeLabel = it.label.labels[0] as InvokeLabel val havoc = HavocStmt.of( - (invokeLabel.params[0] as RefExpr<*>).decl as VarDecl<*>) - builder.addEdge(XcfaEdge(it.source, it.target, SequenceLabel( - listOf(StmtLabel(havoc, metadata = invokeLabel.metadata))))) + (invokeLabel.params[0] as RefExpr<*>).decl as VarDecl<*> + ) + builder.addEdge( + XcfaEdge( + it.source, it.target, SequenceLabel( + listOf(StmtLabel(havoc, metadata = invokeLabel.metadata)) + ) + ) + ) } else { builder.addEdge(it) } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NormalizePass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NormalizePass.kt index 418090364d..db22bd7169 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NormalizePass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/NormalizePass.kt @@ -65,7 +65,9 @@ class NormalizePass : ProcedurePass { is NopLabel -> {} is StmtLabel -> if (!(label.stmt is AssumeStmt && label.stmt.cond.equals( - True()))) collector.forEach { it.add(label) } + True() + )) + ) collector.forEach { it.add(label) } else -> collector.forEach { it.add(label) } } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ProcedurePassManager.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ProcedurePassManager.kt index 02cb00683e..836a01d635 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ProcedurePassManager.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ProcedurePassManager.kt @@ -78,26 +78,28 @@ class CPasses(checkOverflow: Boolean, parseContext: ParseContext, uniqueWarningL ) ) -class ChcPasses(parseContext: ParseContext, uniqueWarningLogger: Logger) : ProcedurePassManager(listOf( - // formatting - NormalizePass(), - DeterministicPass(), - // removing redundant elements - EmptyEdgeRemovalPass(), - UnusedLocRemovalPass(), - // optimizing - SimplifyExprsPass(parseContext), -), listOf( - // trying to inline procedures - InlineProceduresPass(parseContext), - RemoveDeadEnds(), - EliminateSelfLoops(), - // handling remaining function calls - LbePass(parseContext), - NormalizePass(), // needed after lbe, TODO - DeterministicPass(), // needed after lbe, TODO - // Final cleanup - UnusedVarPass(uniqueWarningLogger), -)) +class ChcPasses(parseContext: ParseContext, uniqueWarningLogger: Logger) : ProcedurePassManager( + listOf( + // formatting + NormalizePass(), + DeterministicPass(), + // removing redundant elements + EmptyEdgeRemovalPass(), + UnusedLocRemovalPass(), + // optimizing + SimplifyExprsPass(parseContext), + ), listOf( + // trying to inline procedures + InlineProceduresPass(parseContext), + RemoveDeadEnds(), + EliminateSelfLoops(), + // handling remaining function calls + LbePass(parseContext), + NormalizePass(), // needed after lbe, TODO + DeterministicPass(), // needed after lbe, TODO + // Final cleanup + UnusedVarPass(uniqueWarningLogger), + ) +) class LitmusPasses : ProcedurePassManager() \ No newline at end of file diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ReferenceElimination.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ReferenceElimination.kt index e06e7ce39f..b216917361 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ReferenceElimination.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ReferenceElimination.kt @@ -60,8 +60,12 @@ class ReferenceElimination(val parseContext: ParseContext) : ProcedurePass { val lit = CComplexType.getType(varDecl.ref, parseContext).getValue("$cnt") builder.parent.addVar(XcfaGlobalVar(varDecl, lit)) parseContext.metadata.create(varDecl.ref, "cType", ptrType) - val assign = StmtLabel(AssignStmt.of(cast(varDecl, varDecl.type), - cast(lit, varDecl.type))) + val assign = StmtLabel( + AssignStmt.of( + cast(varDecl, varDecl.type), + cast(lit, varDecl.type) + ) + ) Pair(varDecl, assign) } } @@ -77,8 +81,12 @@ class ReferenceElimination(val parseContext: ParseContext) : ProcedurePass { val varDecl = Var(it.name + "*", ptrType.smtType) builder.addVar(varDecl) parseContext.metadata.create(varDecl.ref, "cType", ptrType) - val assign = StmtLabel(AssignStmt.of(cast(varDecl, varDecl.type), - cast(CComplexType.getType(varDecl.ref, parseContext).getValue("$cnt"), varDecl.type))) + val assign = StmtLabel( + AssignStmt.of( + cast(varDecl, varDecl.type), + cast(CComplexType.getType(varDecl.ref, parseContext).getValue("$cnt"), varDecl.type) + ) + ) Pair(varDecl, assign) } + globalReferredVars @@ -106,25 +114,37 @@ class ReferenceElimination(val parseContext: ParseContext) : ProcedurePass { } @JvmOverloads - fun XcfaLabel.changeReferredVars(varLut: Map, Pair, StmtLabel>>, - parseContext: ParseContext? = null): XcfaLabel = + fun XcfaLabel.changeReferredVars( + varLut: Map, Pair, StmtLabel>>, + parseContext: ParseContext? = null + ): XcfaLabel = if (varLut.isNotEmpty()) when (this) { - is InvokeLabel -> InvokeLabel(name, params.map { it.changeReferredVars(varLut, parseContext) }, - metadata = metadata) - - is NondetLabel -> NondetLabel(labels.map { it.changeReferredVars(varLut, parseContext) }.toSet(), - metadata = metadata) - - is SequenceLabel -> SequenceLabel(labels.map { it.changeReferredVars(varLut, parseContext) }, - metadata = metadata) - - is StartLabel -> StartLabel(name, params.map { it.changeReferredVars(varLut, parseContext) }, - pidVar, metadata = metadata) + is InvokeLabel -> InvokeLabel( + name, params.map { it.changeReferredVars(varLut, parseContext) }, + metadata = metadata + ) + + is NondetLabel -> NondetLabel( + labels.map { it.changeReferredVars(varLut, parseContext) }.toSet(), + metadata = metadata + ) + + is SequenceLabel -> SequenceLabel( + labels.map { it.changeReferredVars(varLut, parseContext) }, + metadata = metadata + ) + + is StartLabel -> StartLabel( + name, params.map { it.changeReferredVars(varLut, parseContext) }, + pidVar, metadata = metadata + ) is StmtLabel -> SequenceLabel(stmt.changeReferredVars(varLut, parseContext).map { - StmtLabel(it, metadata = metadata, - choiceType = this.choiceType) + StmtLabel( + it, metadata = metadata, + choiceType = this.choiceType + ) }).let { if (it.labels.size == 1) it.labels[0] else it } else -> this @@ -132,8 +152,10 @@ class ReferenceElimination(val parseContext: ParseContext) : ProcedurePass { else this @JvmOverloads - fun Stmt.changeReferredVars(varLut: Map, Pair, StmtLabel>>, - parseContext: ParseContext? = null): List { + fun Stmt.changeReferredVars( + varLut: Map, Pair, StmtLabel>>, + parseContext: ParseContext? = null + ): List { val stmts = when (this) { is AssignStmt<*> -> if (this.varDecl in varLut.keys) { val newVar = varLut[this.varDecl]!!.first @@ -142,20 +164,31 @@ class ReferenceElimination(val parseContext: ParseContext) : ProcedurePass { Dereference( cast(newVar.ref, newVar.type), cast(CComplexType.getSignedLong(parseContext).nullValue, newVar.type), - this.expr.type), - this.expr.changeReferredVars(varLut, parseContext))) + this.expr.type + ), + this.expr.changeReferredVars(varLut, parseContext) + ) + ) } else { - listOf(AssignStmt.of(cast(this.varDecl, this.varDecl.type), - cast(this.expr.changeReferredVars(varLut, parseContext), this.varDecl.type))) + listOf( + AssignStmt.of( + cast(this.varDecl, this.varDecl.type), + cast(this.expr.changeReferredVars(varLut, parseContext), this.varDecl.type) + ) + ) } is MemoryAssignStmt<*, *, *> -> listOf( - MemoryAssignStmt.create(deref.changeReferredVars(varLut, parseContext) as Dereference<*, *, *>, - expr.changeReferredVars(varLut, parseContext))) + MemoryAssignStmt.create( + deref.changeReferredVars(varLut, parseContext) as Dereference<*, *, *>, + expr.changeReferredVars(varLut, parseContext) + ) + ) is AssumeStmt -> listOf(AssumeStmt.of(cond.changeReferredVars(varLut, parseContext))) is SequenceStmt -> listOf( - SequenceStmt.of(this.stmts.flatMap { it.changeReferredVars(varLut, parseContext) })) + SequenceStmt.of(this.stmts.flatMap { it.changeReferredVars(varLut, parseContext) }) + ) is SkipStmt -> listOf(this) else -> TODO("Not yet implemented ($this)") @@ -170,8 +203,10 @@ class ReferenceElimination(val parseContext: ParseContext) : ProcedurePass { } @JvmOverloads - fun Expr.changeReferredVars(varLut: Map, Pair, StmtLabel>>, - parseContext: ParseContext? = null): Expr = + fun Expr.changeReferredVars( + varLut: Map, Pair, StmtLabel>>, + parseContext: ParseContext? = null + ): Expr = if (this is RefExpr) { (decl as VarDecl).changeReferredVars(varLut) } else if (this is Reference<*, *> && this.expr is RefExpr<*> && (this.expr as RefExpr<*>).decl in varLut.keys) { @@ -185,10 +220,13 @@ class ReferenceElimination(val parseContext: ParseContext) : ProcedurePass { } fun VarDecl.changeReferredVars( - varLut: Map, Pair, StmtLabel>>): Expr = + varLut: Map, Pair, StmtLabel>> + ): Expr = varLut[this]?.first?.let { - Dereference(cast(it.ref, it.type), cast(CComplexType.getSignedInt(parseContext).nullValue, it.type), - this.type) as Expr + Dereference( + cast(it.ref, it.type), cast(CComplexType.getSignedInt(parseContext).nullValue, it.type), + this.type + ) as Expr } ?: this.ref } \ No newline at end of file diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SvCompIntrinsicsPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SvCompIntrinsicsPass.kt index 46933ea4e9..c92d5f08ee 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SvCompIntrinsicsPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SvCompIntrinsicsPass.kt @@ -40,7 +40,8 @@ class SvCompIntrinsicsPass : ProcedurePass { builder.addEdge(outgoingEdge.withLabel(SequenceLabel(labels))) } for (incomingEdge in ArrayList( - builder.finalLoc.getOrNull()?.incomingEdges ?: listOf())) { + builder.finalLoc.getOrNull()?.incomingEdges ?: listOf() + )) { builder.removeEdge(incomingEdge) val labels = ArrayList((incomingEdge.label as SequenceLabel).labels) labels.add(FenceLabel(setOf("ATOMIC_END"), metadata = incomingEdge.metadata)) @@ -50,18 +51,24 @@ class SvCompIntrinsicsPass : ProcedurePass { for (edge in ArrayList(builder.getEdges())) { val edges = edge.splitIf(this::predicate) if (edges.size > 1 || (edges.size == 1 && predicate( - (edges[0].label as SequenceLabel).labels[0]))) { + (edges[0].label as SequenceLabel).labels[0] + )) + ) { builder.removeEdge(edge) val labels: MutableList = ArrayList() edges.forEach { if (predicate((it.label as SequenceLabel).labels[0])) { val invokeLabel = it.label.labels[0] as InvokeLabel val fence = when (invokeLabel.name) { - "__VERIFIER_atomic_begin" -> FenceLabel(setOf("ATOMIC_BEGIN"), - metadata = invokeLabel.metadata) + "__VERIFIER_atomic_begin" -> FenceLabel( + setOf("ATOMIC_BEGIN"), + metadata = invokeLabel.metadata + ) - "__VERIFIER_atomic_end" -> FenceLabel(setOf("ATOMIC_END"), - metadata = invokeLabel.metadata) + "__VERIFIER_atomic_end" -> FenceLabel( + setOf("ATOMIC_END"), + metadata = invokeLabel.metadata + ) else -> invokeLabel } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedVarPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedVarPass.kt index 1f88251fab..8825144189 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedVarPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedVarPass.kt @@ -64,7 +64,8 @@ class UnusedVarPass(private val uniqueWarningLogger: Logger) : ProcedurePass { if (!varsAndParams.containsAll(usedVars)) { uniqueWarningLogger.write(Logger.Level.INFO, "WARNING: There are some used variables not present as declarations: " + - "${usedVars.filter { it !in varsAndParams }}\n") + "${usedVars.filter { it !in varsAndParams }}\n" + ) } builder.getVars().filter { it !in usedVars }.forEach { builder.removeVar(it) } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/Utils.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/Utils.kt index cb5c74b8cb..55ae7e42e0 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/Utils.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/Utils.kt @@ -76,27 +76,41 @@ fun Stmt.flatten(): List { fun XcfaLabel.changeVars(varLut: Map, VarDecl<*>>, parseContext: ParseContext? = null): XcfaLabel = if (varLut.isNotEmpty()) when (this) { - is InvokeLabel -> InvokeLabel(name, params.map { it.changeVars(varLut, parseContext) }, - metadata = metadata) + is InvokeLabel -> InvokeLabel( + name, params.map { it.changeVars(varLut, parseContext) }, + metadata = metadata + ) is JoinLabel -> JoinLabel(pidVar.changeVars(varLut), metadata = metadata) - is NondetLabel -> NondetLabel(labels.map { it.changeVars(varLut, parseContext) }.toSet(), - metadata = metadata) - - is ReadLabel -> ReadLabel(local.changeVars(varLut), global.changeVars(varLut), labels, - metadata = metadata) - - is SequenceLabel -> SequenceLabel(labels.map { it.changeVars(varLut, parseContext) }, - metadata = metadata) - - is StartLabel -> StartLabel(name, params.map { it.changeVars(varLut, parseContext) }, - pidVar.changeVars(varLut), metadata = metadata) - - is StmtLabel -> StmtLabel(stmt.changeVars(varLut, parseContext), metadata = metadata, - choiceType = this.choiceType) - - is WriteLabel -> WriteLabel(local.changeVars(varLut), global.changeVars(varLut), labels, - metadata = metadata) + is NondetLabel -> NondetLabel( + labels.map { it.changeVars(varLut, parseContext) }.toSet(), + metadata = metadata + ) + + is ReadLabel -> ReadLabel( + local.changeVars(varLut), global.changeVars(varLut), labels, + metadata = metadata + ) + + is SequenceLabel -> SequenceLabel( + labels.map { it.changeVars(varLut, parseContext) }, + metadata = metadata + ) + + is StartLabel -> StartLabel( + name, params.map { it.changeVars(varLut, parseContext) }, + pidVar.changeVars(varLut), metadata = metadata + ) + + is StmtLabel -> StmtLabel( + stmt.changeVars(varLut, parseContext), metadata = metadata, + choiceType = this.choiceType + ) + + is WriteLabel -> WriteLabel( + local.changeVars(varLut), global.changeVars(varLut), labels, + metadata = metadata + ) is ReturnLabel -> ReturnLabel(enclosedLabel.changeVars(varLut)) @@ -107,11 +121,15 @@ fun XcfaLabel.changeVars(varLut: Map, VarDecl<*>>, parseContext: Par @JvmOverloads fun Stmt.changeVars(varLut: Map, VarDecl<*>>, parseContext: ParseContext? = null): Stmt { val stmt = when (this) { - is AssignStmt<*> -> AssignStmt.of(cast(varDecl.changeVars(varLut), varDecl.type), - cast(expr.changeVars(varLut, parseContext), varDecl.type)) - - is MemoryAssignStmt<*, *, *> -> MemoryAssignStmt.create(deref.changeVars(varLut) as Dereference, - expr.changeVars(varLut)) + is AssignStmt<*> -> AssignStmt.of( + cast(varDecl.changeVars(varLut), varDecl.type), + cast(expr.changeVars(varLut, parseContext), varDecl.type) + ) + + is MemoryAssignStmt<*, *, *> -> MemoryAssignStmt.create( + deref.changeVars(varLut) as Dereference, + expr.changeVars(varLut) + ) is HavocStmt<*> -> HavocStmt.of(varDecl.changeVars(varLut)) is AssumeStmt -> AssumeStmt.of(cond.changeVars(varLut, parseContext)) diff --git a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/gson/GsonTest.kt b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/gson/GsonTest.kt index 65a89e0533..056ed4d9f0 100644 --- a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/gson/GsonTest.kt +++ b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/gson/GsonTest.kt @@ -46,11 +46,14 @@ class GsonTest { private fun getGson(scope: XcfaScope, env: Env, newScope: Boolean): Gson { val gsonBuilder = GsonBuilder() lateinit var gson: Gson - gsonBuilder.registerTypeHierarchyAdapter(XcfaLocation::class.java, - StringTypeAdapter(xcfaLocationAdapter)) + gsonBuilder.registerTypeHierarchyAdapter( + XcfaLocation::class.java, + StringTypeAdapter(xcfaLocationAdapter) + ) gsonBuilder.registerTypeHierarchyAdapter(XCFA::class.java, XcfaAdapter { gson }) gsonBuilder.registerTypeHierarchyAdapter(VarDecl::class.java, - VarDeclAdapter({ gson }, scope, env, !newScope)) + VarDeclAdapter({ gson }, scope, env, !newScope) + ) gsonBuilder.registerTypeHierarchyAdapter(Stmt::class.java, StringTypeAdapter { StatementWrapper(it, scope).instantiate(env) }) gsonBuilder.registerTypeHierarchyAdapter(Expr::class.java, @@ -60,7 +63,8 @@ class GsonTest { gsonBuilder.registerTypeHierarchyAdapter(VarIndexing::class.java, StringTypeAdapter { BasicVarIndexing.fromString(it, scope, env) }) gsonBuilder.registerTypeHierarchyAdapter(XcfaLabel::class.java, - XcfaLabelAdapter(scope, env, { gson })) + XcfaLabelAdapter(scope, env, { gson }) + ) gsonBuilder.registerTypeHierarchyAdapter(MetaData::class.java, MetaDataAdapter()) gsonBuilder.registerTypeHierarchyAdapter(Pair::class.java, PairAdapter { gson }) gsonBuilder.registerTypeHierarchyAdapter(Optional::class.java, OptionalAdapter { gson }) @@ -112,8 +116,10 @@ class GsonTest { val env = Env() val gson = getGson(symbolTable, env, true) - assertEquals(parseContext.metadata.lookupKeyValue, - gson.fromJson(gson.toJson(parseContext), ParseContext::class.java).metadata.lookupKeyValue) + assertEquals( + parseContext.metadata.lookupKeyValue, + gson.fromJson(gson.toJson(parseContext), ParseContext::class.java).metadata.lookupKeyValue + ) } diff --git a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/passes/PassTests.kt b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/passes/PassTests.kt index 570ab2b126..e1084b1fab 100644 --- a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/passes/PassTests.kt +++ b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/passes/PassTests.kt @@ -45,7 +45,8 @@ class PassTests { global: VarContext.() -> Unit, input: XcfaProcedureBuilderContext.() -> Unit, output: (XcfaProcedureBuilderContext.() -> Unit)?, - val passes: List) : Arguments { + val passes: List + ) : Arguments { private val builder = XcfaBuilder("").also { it.global(global) } private val inputBuilder = builder.procedure("", input).builder @@ -332,11 +333,13 @@ class PassTests { } (init to final) { "y".assign( - "(ite (isinfinite x) #b00000000000000000000000000000001 #b00000000000000000000000000000000)") + "(ite (isinfinite x) #b00000000000000000000000000000001 #b00000000000000000000000000000000)" + ) } (init to final) { "y".assign( - "(ite (or (isinfinite x) (fpisnan x)) #b00000000000000000000000000000000 #b00000000000000000000000000000001)") + "(ite (or (isinfinite x) (fpisnan x)) #b00000000000000000000000000000000 #b00000000000000000000000000000001)" + ) } }, ), @@ -372,7 +375,8 @@ class PassTests { "y".assign("x").also { parseContext.metadata.create( ((it.labels.last() as StmtLabel).stmt as AssignStmt<*>).varDecl.ref, "cType", - CSignedInt(null, parseContext)) + CSignedInt(null, parseContext) + ) } } }, @@ -531,8 +535,10 @@ class PassTests { @ParameterizedTest @MethodSource("getData") - fun testPass(input: XcfaProcedureBuilder, output: XcfaProcedureBuilder?, - passes: List) { + fun testPass( + input: XcfaProcedureBuilder, output: XcfaProcedureBuilder?, + passes: List + ) { println("Trying to run $passes on input...") val actualOutput = passes.fold(input) { acc, procedurePass -> procedurePass.run(acc) } .build(dummyXcfa) @@ -562,10 +568,15 @@ class PassTests { @Test fun testInline() { val xcfaSource = xcfa("example") { - procedure("main", ProcedurePassManager(listOf( - NormalizePass(), - DeterministicPass(), - InlineProceduresPass(parseContext)))) { + procedure( + "main", ProcedurePassManager( + listOf( + NormalizePass(), + DeterministicPass(), + InlineProceduresPass(parseContext) + ) + ) + ) { (init to final) { "proc1"() } diff --git a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/passes/UtilsTest.kt b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/passes/UtilsTest.kt index 77c48dc44e..f2f25a473a 100644 --- a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/passes/UtilsTest.kt +++ b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/passes/UtilsTest.kt @@ -39,25 +39,37 @@ class UtilsTest { @JvmStatic fun getLabels(): List = listOf( - Arguments.of(InvokeLabel("", listOf(x.ref, y.ref), EmptyMetaData), - InvokeLabel("", listOf(xPrime.ref, y.ref), EmptyMetaData)), + Arguments.of( + InvokeLabel("", listOf(x.ref, y.ref), EmptyMetaData), + InvokeLabel("", listOf(xPrime.ref, y.ref), EmptyMetaData) + ), Arguments.of(JoinLabel(x, EmptyMetaData), JoinLabel(xPrime, EmptyMetaData)), Arguments.of(NondetLabel(setOf(NopLabel), EmptyMetaData), NondetLabel(setOf(NopLabel), EmptyMetaData)), - Arguments.of(SequenceLabel(listOf(NopLabel), EmptyMetaData), - SequenceLabel(listOf(NopLabel), EmptyMetaData)), + Arguments.of( + SequenceLabel(listOf(NopLabel), EmptyMetaData), + SequenceLabel(listOf(NopLabel), EmptyMetaData) + ), Arguments.of(ReadLabel(x, y, setOf(), EmptyMetaData), ReadLabel(xPrime, y, setOf(), EmptyMetaData)), Arguments.of(WriteLabel(x, y, setOf(), EmptyMetaData), WriteLabel(xPrime, y, setOf(), EmptyMetaData)), Arguments.of(FenceLabel(setOf(), EmptyMetaData), FenceLabel(setOf(), EmptyMetaData)), - Arguments.of(StartLabel("", listOf(x.ref), y, EmptyMetaData), - StartLabel("", listOf(xPrime.ref), y, EmptyMetaData)), + Arguments.of( + StartLabel("", listOf(x.ref), y, EmptyMetaData), + StartLabel("", listOf(xPrime.ref), y, EmptyMetaData) + ), Arguments.of(ReturnLabel(JoinLabel(x, EmptyMetaData)), ReturnLabel(JoinLabel(xPrime, EmptyMetaData))), - Arguments.of(StmtLabel(Assign(x, y.ref)), - StmtLabel(Assign(xPrime, y.ref))), - Arguments.of(StmtLabel(Havoc(x)), - StmtLabel(Havoc(xPrime))), - Arguments.of(StmtLabel(Assume(Eq(x.ref, y.ref))), - StmtLabel(Assume(Eq(xPrime.ref, y.ref)))), + Arguments.of( + StmtLabel(Assign(x, y.ref)), + StmtLabel(Assign(xPrime, y.ref)) + ), + Arguments.of( + StmtLabel(Havoc(x)), + StmtLabel(Havoc(xPrime)) + ), + Arguments.of( + StmtLabel(Assume(Eq(x.ref, y.ref))), + StmtLabel(Assume(Eq(xPrime.ref, y.ref))) + ), Arguments.of(StmtLabel(Skip()), StmtLabel(Skip())), ) } diff --git a/subprojects/xcfa/xcfa2chc/src/test/java/hu/bme/mit/theta/xcfa2chc/TestChcUtils.kt b/subprojects/xcfa/xcfa2chc/src/test/java/hu/bme/mit/theta/xcfa2chc/TestChcUtils.kt index 487a206379..63d339aeb7 100644 --- a/subprojects/xcfa/xcfa2chc/src/test/java/hu/bme/mit/theta/xcfa2chc/TestChcUtils.kt +++ b/subprojects/xcfa/xcfa2chc/src/test/java/hu/bme/mit/theta/xcfa2chc/TestChcUtils.kt @@ -139,27 +139,47 @@ class TestChcUtils { val init = Relation("init", i2i, i2i, i2i, i2i, Int()) // br, co, rf, com - val T0 = Relation("T0", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), - Int()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T0G = Relation("T0_gate", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), - Int()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T0C = Relation("T0_critical", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), - Int()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T0CF = Relation("T0_critical_final", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), - Int()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T0F = Relation("T0_final", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), - Int()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - - val T1 = Relation("T1", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), - Int()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T1G = Relation("T1_gate", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), - Int()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T1C = Relation("T1_critical", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), - Int()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T1CF = Relation("T1_critical_final", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), - Int()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T1F = Relation("T1_final", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), - Int()) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T0 = Relation( + "T0", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), + Int() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T0G = Relation( + "T0_gate", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), + Int() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T0C = Relation( + "T0_critical", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), + Int() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T0CF = Relation( + "T0_critical_final", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), + Int() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T0F = Relation( + "T0_final", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), + Int() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + + val T1 = Relation( + "T1", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), + Int() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T1G = Relation( + "T1_gate", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), + Int() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T1C = Relation( + "T1_critical", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), + Int() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T1CF = Relation( + "T1_critical_final", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), + Int() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T1F = Relation( + "T1_final", i2i, i2i, i2i, i2i, Int(), Int(), Int(), Int(), + Int() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt val W = Relation("W", i2i, i2i, i2i, i2i, Int(), Int(), Int()) // br, co, rf, com, eid, vid, val @@ -440,23 +460,39 @@ class TestChcUtils { val init = Relation("init", i2i, i2i, i2i, i2i, Int()) // br, co, rf, com - val T0 = Relation("T0", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), - Bool()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T0G = Relation("T0_gate", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), - Bool()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T0C = Relation("T0_critical", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), - Bool()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T0F = Relation("T0_final", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), - Bool()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - - val T1 = Relation("T1", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), - Bool()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T1G = Relation("T1_gate", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), - Bool()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T1C = Relation("T1_critical", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), - Bool()) // br, co, rf, com, eid, turn, flag0, flag1, cnt - val T1F = Relation("T1_final", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), - Bool()) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T0 = Relation( + "T0", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), + Bool() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T0G = Relation( + "T0_gate", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), + Bool() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T0C = Relation( + "T0_critical", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), + Bool() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T0F = Relation( + "T0_final", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), + Bool() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + + val T1 = Relation( + "T1", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), + Bool() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T1G = Relation( + "T1_gate", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), + Bool() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T1C = Relation( + "T1_critical", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), + Bool() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt + val T1F = Relation( + "T1_final", i2i, i2i, i2i, i2i, Int(), Bool(), Bool(), Bool(), + Bool() + ) // br, co, rf, com, eid, turn, flag0, flag1, cnt val W = Relation("W", i2i, i2i, i2i, i2i, Int(), Int(), Bool()) // br, co, rf, com, eid, vid, val diff --git a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsToRelations.kt b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsToRelations.kt index 4e4a63908b..8d733b0bfe 100644 --- a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsToRelations.kt +++ b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsToRelations.kt @@ -55,7 +55,8 @@ fun XSTS.toRelations(): List { is EnumLitExpr -> { val value = enumValueLut.computeIfAbsent(this.type) { LinkedHashMap() }.computeIfAbsent( - this.value) { cnt++ } + this.value + ) { cnt++ } return IntLitExpr.of(BigInteger.valueOf(value.toLong())) } diff --git a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/RandomXsts.kt b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/RandomXsts.kt index a78b5bb70c..06eead3068 100644 --- a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/RandomXsts.kt +++ b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/RandomXsts.kt @@ -29,8 +29,10 @@ import hu.bme.mit.theta.xsts.XSTS import kotlin.random.Random @JvmOverloads -fun generateXsts(seed: Int, numCtrl: Int = 1, numClock: Int = 1, numOther: Int = 3, - requireAllVarsWritten: Boolean = false): XSTS { +fun generateXsts( + seed: Int, numCtrl: Int = 1, numClock: Int = 1, numOther: Int = 3, + requireAllVarsWritten: Boolean = false +): XSTS { val writtenVars = object : StmtVisitor>, Set>> { override fun visit(stmt: SkipStmt?, param: Set>): Set> { return param @@ -77,7 +79,8 @@ fun generateXsts(seed: Int, numCtrl: Int = 1, numClock: Int = 1, numOther: Int = } override fun visit( - stmt: MemoryAssignStmt?, param: Set>?): Set> { + stmt: MemoryAssignStmt?, param: Set>? + ): Set> { TODO("Not yet implemented") } @@ -178,17 +181,21 @@ class RandomXsts(seed: Int, val exprMaxDepth: Int) { } fun randomSeq(currDepth: Int, maxDepth: Int): Stmt { - return Stmts.SequenceStmt(listOf( - randomIntermediate(currDepth + 1, maxDepth), - randomIntermediate(currDepth + 1, maxDepth) - )) + return Stmts.SequenceStmt( + listOf( + randomIntermediate(currDepth + 1, maxDepth), + randomIntermediate(currDepth + 1, maxDepth) + ) + ) } fun randomNonDet(currDepth: Int, maxDepth: Int): Stmt { - return Stmts.NonDetStmt(listOf( - randomIntermediate(currDepth + 1, maxDepth), - randomIntermediate(currDepth + 1, maxDepth) - )) + return Stmts.NonDetStmt( + listOf( + randomIntermediate(currDepth + 1, maxDepth), + randomIntermediate(currDepth + 1, maxDepth) + ) + ) } @@ -196,7 +203,8 @@ class RandomXsts(seed: Int, val exprMaxDepth: Int) { var expr: Expr do expr = randomBoolExpr(0) while (ExprUtils.getVars(expr).isEmpty()) - return IfStmt.of(expr, + return IfStmt.of( + expr, randomIntermediate(currDepth + 1, maxDepth), randomIntermediate(currDepth + 1, maxDepth) ) @@ -222,7 +230,8 @@ class RandomXsts(seed: Int, val exprMaxDepth: Int) { { BoolExprs.Or( randomBoolExpr(currDepth + 1), - randomBoolExpr(currDepth + 1)) + randomBoolExpr(currDepth + 1) + ) }, { BoolExprs.Imply(randomBoolExpr(currDepth + 1), randomBoolExpr(currDepth + 1)) }, { BoolExprs.Iff(randomBoolExpr(currDepth + 1), randomBoolExpr(currDepth + 1)) }, @@ -296,7 +305,8 @@ class RandomXsts(seed: Int, val exprMaxDepth: Int) { } fun randomAssume() = (listOf(this::randomDataAssume) + (if (clockVars.isEmpty()) listOf() else listOf( - this::randomClockConstraint))).random(random)() + this::randomClockConstraint + ))).random(random)() fun randomDataAssume(): Stmt { var expr: Expr @@ -323,13 +333,15 @@ class RandomXsts(seed: Int, val exprMaxDepth: Int) { ).random()() val compareTo = IntExprs.Int(random.nextInt(10)) - return Stmts.Assume(listOf( - { IntExprs.Leq(c, compareTo) }, - { IntExprs.Lt(c, compareTo) }, - { IntExprs.Geq(c, compareTo) }, - { IntExprs.Gt(c, compareTo) }, - { IntExprs.Eq(c, compareTo) }, - ).random(random)()) + return Stmts.Assume( + listOf( + { IntExprs.Leq(c, compareTo) }, + { IntExprs.Lt(c, compareTo) }, + { IntExprs.Geq(c, compareTo) }, + { IntExprs.Gt(c, compareTo) }, + { IntExprs.Eq(c, compareTo) }, + ).random(random)() + ) } fun randomHavoc(): Stmt { diff --git a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsSerializer.kt b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsSerializer.kt index 833a03799a..e3d98a6c68 100644 --- a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsSerializer.kt +++ b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsSerializer.kt @@ -100,7 +100,8 @@ object XstsSerializer : StmtVisitor { } override fun visit( - stmt: MemoryAssignStmt?, param: Void?): String { + stmt: MemoryAssignStmt?, param: Void? + ): String { TODO("Not yet implemented") } diff --git a/subprojects/xsts/xsts/src/main/kotlin/hu/bme/mit/theta/xsts/utils/XSTSVarChanger.kt b/subprojects/xsts/xsts/src/main/kotlin/hu/bme/mit/theta/xsts/utils/XSTSVarChanger.kt index c38b044ec5..7c9fd82f2f 100644 --- a/subprojects/xsts/xsts/src/main/kotlin/hu/bme/mit/theta/xsts/utils/XSTSVarChanger.kt +++ b/subprojects/xsts/xsts/src/main/kotlin/hu/bme/mit/theta/xsts/utils/XSTSVarChanger.kt @@ -25,7 +25,9 @@ fun XSTS.copyWithReplacingVars(variableMapping: Map>): XSTS { val matchingCtrlVarNames = ctrlVars.filter { variableMapping.containsKey(it.name) }.map { it.name } val newCtrlVars = ctrlVars.filter { it.name !in variableMapping } .toSet() + variableMapping.filter { it.key in matchingCtrlVarNames }.values.toSet() - return XSTS(newCtrlVars, init.changeVars(variableMapping) as NonDetStmt, + return XSTS( + newCtrlVars, init.changeVars(variableMapping) as NonDetStmt, tran.changeVars(variableMapping) as NonDetStmt, env.changeVars(variableMapping) as NonDetStmt, - initFormula.changeVars(variableMapping), prop.changeVars(variableMapping)) + initFormula.changeVars(variableMapping), prop.changeVars(variableMapping) + ) } \ No newline at end of file From e37b32302b2cb72893e26b52bc63d305e999a98f Mon Sep 17 00:00:00 2001 From: "ThetaBotMaintainer[bot]" <139346997+ThetaBotMaintainer[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:24:37 +0000 Subject: [PATCH 14/16] Reformatted code --- .../bounded/BoundedCheckerBuilder.kt | 6 +++-- .../hu/bme/mit/theta/analysis/ptr/PtrUtils.kt | 3 ++- .../mit/theta/grammar/gson/StateAdapters.kt | 3 ++- .../hu/bme/mit/theta/grammar/gson/TestGson.kt | 18 +++++++++----- .../bme/mit/theta/xcfa/cli/ExecuteConfig.kt | 3 ++- .../bme/mit/theta/xcfa/cli/utils/GsonUtils.kt | 9 ++++--- .../xcfa/passes/FetchExecuteWriteback.kt | 24 ++++++++++++------- .../mit/theta/xcfa/passes/UnusedVarPass.kt | 3 ++- .../hu/bme/mit/theta/xcfa/gson/GsonTest.kt | 6 +++-- 9 files changed, 49 insertions(+), 26 deletions(-) diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/bounded/BoundedCheckerBuilder.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/bounded/BoundedCheckerBuilder.kt index b54dc029aa..03de89fb27 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/bounded/BoundedCheckerBuilder.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/bounded/BoundedCheckerBuilder.kt @@ -34,7 +34,8 @@ fun buildBMC( bmcEnabled: () -> Boolean = { true }, lfPathOnly: () -> Boolean = { true }, ): BoundedChecker { - return BoundedChecker(monolithicExpr, shouldGiveUp, bmcSolver, bmcEnabled, lfPathOnly, null, { false }, null, + return BoundedChecker( + monolithicExpr, shouldGiveUp, bmcSolver, bmcEnabled, lfPathOnly, null, { false }, null, { false }, valToState, biValToAction, logger ) } @@ -71,7 +72,8 @@ fun buildIMC( lfPathOnly: () -> Boolean = { true }, imcEnabled: (Int) -> Boolean = { true }, ): BoundedChecker { - return BoundedChecker(monolithicExpr, shouldGiveUp, bmcSolver, bmcEnabled, lfPathOnly, itpSolver, imcEnabled, null, + return BoundedChecker( + monolithicExpr, shouldGiveUp, bmcSolver, bmcEnabled, lfPathOnly, itpSolver, imcEnabled, null, { false }, valToState, biValToAction, logger ) } \ No newline at end of file diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrUtils.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrUtils.kt index d1748f2526..e051625334 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrUtils.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrUtils.kt @@ -149,7 +149,8 @@ fun Expr.uniqueDereferences( Pair(ret, retDeref) } else { val ret = ArrayList() - Pair(ret, + Pair( + ret, this.withOps(this.ops.map { it.uniqueDereferences(vargen, lookup).also { ret.addAll(it.first) }.second }) ) } diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StateAdapters.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StateAdapters.kt index 1675ec639a..30031d82e0 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StateAdapters.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StateAdapters.kt @@ -89,7 +89,8 @@ class PredStateAdapter(val gsonSupplier: () -> Gson, val scope: Scope, val env: check(reader.nextName() == "bottom") if (reader.nextBoolean()) ret = PredState.bottom() check(reader.nextName() == "preds") - val preds = gson.fromJson>>(reader, + val preds = gson.fromJson>>( + reader, object : TypeToken>>() {}.type ) if (ret == null) ret = PredState.of(preds) diff --git a/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/gson/TestGson.kt b/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/gson/TestGson.kt index 026a4626ee..c4d39653a0 100644 --- a/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/gson/TestGson.kt +++ b/subprojects/common/grammar/src/test/java/hu/bme/mit/theta/grammar/gson/TestGson.kt @@ -101,13 +101,16 @@ class TestGson { private fun getExplBuilder(gsonSuppl: () -> Gson): GsonBuilder { val gsonBuilder = GsonBuilder() - gsonBuilder.registerTypeHierarchyAdapter(ARG::class.java, + gsonBuilder.registerTypeHierarchyAdapter( + ARG::class.java, ArgAdapter(gsonSuppl, { ExplOrd.getInstance() }, { explArgAdapterHelper() }) ) - gsonBuilder.registerTypeHierarchyAdapter(Trace::class.java, + gsonBuilder.registerTypeHierarchyAdapter( + Trace::class.java, TraceAdapter(gsonSuppl, { ExplState::class.java }, SimpleStmtAction::class.java) ) - gsonBuilder.registerTypeHierarchyAdapter(SafetyResult::class.java, + gsonBuilder.registerTypeHierarchyAdapter( + SafetyResult::class.java, SafetyResultAdapter(gsonSuppl, { explArgHelper() }, { explTraceHelper() }) ) @@ -117,13 +120,16 @@ class TestGson { private fun getPredBuilder(gsonSuppl: () -> Gson): GsonBuilder { val gsonBuilder = GsonBuilder() - gsonBuilder.registerTypeHierarchyAdapter(ARG::class.java, + gsonBuilder.registerTypeHierarchyAdapter( + ARG::class.java, ArgAdapter(gsonSuppl, { PartialOrd { a, b -> true } }, { predArgAdapterHelper() }) ) - gsonBuilder.registerTypeHierarchyAdapter(Trace::class.java, + gsonBuilder.registerTypeHierarchyAdapter( + Trace::class.java, TraceAdapter(gsonSuppl, { PredState::class.java }, SimpleStmtAction::class.java) ) - gsonBuilder.registerTypeHierarchyAdapter(SafetyResult::class.java, + gsonBuilder.registerTypeHierarchyAdapter( + SafetyResult::class.java, SafetyResultAdapter(gsonSuppl, { predArgHelper() }, { predTraceHelper() }) ) diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/ExecuteConfig.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/ExecuteConfig.kt index afb0bb997a..e835aaf239 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/ExecuteConfig.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/ExecuteConfig.kt @@ -181,7 +181,8 @@ fun frontend(config: XcfaConfig<*, *>, logger: Logger, uniqueLogger: Logger): Tr ) logger.write(RESULT, "ParsingResult Success\n") - logger.write(RESULT, + logger.write( + RESULT, "Alias graph size: ${xcfa.pointsToGraph.size} -> ${xcfa.pointsToGraph.values.map { it.size }.toList()}\n" ) diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GsonUtils.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GsonUtils.kt index 72ddc379d7..8ef9ed0318 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GsonUtils.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GsonUtils.kt @@ -106,7 +106,8 @@ private fun getGson( StringTypeAdapter(xcfaLocationAdapter) ) gsonBuilder.registerTypeHierarchyAdapter(XCFA::class.java, XcfaAdapter { gson }) - gsonBuilder.registerTypeHierarchyAdapter(VarDecl::class.java, + gsonBuilder.registerTypeHierarchyAdapter( + VarDecl::class.java, VarDeclAdapter({ gson }, scope, env, !newScope) ) gsonBuilder.registerTypeHierarchyAdapter(Stmt::class.java, @@ -118,10 +119,12 @@ private fun getGson( gsonBuilder.registerTypeHierarchyAdapter(VarIndexing::class.java, StringTypeAdapter { BasicVarIndexing.fromString(it, scope, env) }) gsonBuilder.registerTypeHierarchyAdapter(ExplState::class.java, ExplStateAdapter(scope, env)) - gsonBuilder.registerTypeHierarchyAdapter(PredState::class.java, + gsonBuilder.registerTypeHierarchyAdapter( + PredState::class.java, PredStateAdapter({ gson }, scope, env) ) - gsonBuilder.registerTypeHierarchyAdapter(XcfaLabel::class.java, + gsonBuilder.registerTypeHierarchyAdapter( + XcfaLabel::class.java, XcfaLabelAdapter(scope, env, { gson }) ) gsonBuilder.registerTypeHierarchyAdapter(MetaData::class.java, MetaDataAdapter()) diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FetchExecuteWriteback.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FetchExecuteWriteback.kt index 89c11f3a78..894f89ccb2 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FetchExecuteWriteback.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/FetchExecuteWriteback.kt @@ -73,9 +73,11 @@ class FetchExecuteWriteback(val parseContext: ParseContext) : ProcedurePass { is InvokeLabel -> { val lut = getDerefLut(dereferences, builder) SequenceLabel(lut.map { - StmtLabel(Assign(cast(it.value, it.value.type), - cast(it.key.map { it.replaceDerefs(lut) }, it.value.type) - ) + StmtLabel( + Assign( + cast(it.value, it.value.type), + cast(it.key.map { it.replaceDerefs(lut) }, it.value.type) + ) ) } + InvokeLabel( this.name, this.params.map { it.replaceDerefs(lut) }, metadata, @@ -87,9 +89,11 @@ class FetchExecuteWriteback(val parseContext: ParseContext) : ProcedurePass { is StartLabel -> { val lut = getDerefLut(dereferences, builder) SequenceLabel(lut.map { - StmtLabel(Assign(cast(it.value, it.value.type), - cast(it.key.map { it.replaceDerefs(lut) }, it.value.type) - ) + StmtLabel( + Assign( + cast(it.value, it.value.type), + cast(it.key.map { it.replaceDerefs(lut) }, it.value.type) + ) ) } + StartLabel(name, params.map { it.replaceDerefs(lut) }, pidVar, metadata, tempLookup), metadata) } @@ -129,9 +133,11 @@ class FetchExecuteWriteback(val parseContext: ParseContext) : ProcedurePass { val ret = ArrayList() val accessType = dereferencesWithAccessTypes.filter { dereferences.contains(it.first) } for (dereference in accessType.filter { it.second.isRead }.map { it.first }) { - ret.add(Assign(cast(lut[dereference]!!, dereference.type), - cast(dereference.map { it.replaceDerefs(lut.filter { it.key != dereference }) }, dereference.type) - ) + ret.add( + Assign( + cast(lut[dereference]!!, dereference.type), + cast(dereference.map { it.replaceDerefs(lut.filter { it.key != dereference }) }, dereference.type) + ) ) } ret.add(stmt) diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedVarPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedVarPass.kt index 8825144189..c8ed0b0c27 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedVarPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedVarPass.kt @@ -62,7 +62,8 @@ class UnusedVarPass(private val uniqueWarningLogger: Logger) : ProcedurePass { val allVars = Sets.union(builder.getVars(), builder.parent.getVars().map { it.wrappedVar }.toSet()) val varsAndParams = Sets.union(allVars, builder.getParams().map { it.first }.toSet()) if (!varsAndParams.containsAll(usedVars)) { - uniqueWarningLogger.write(Logger.Level.INFO, + uniqueWarningLogger.write( + Logger.Level.INFO, "WARNING: There are some used variables not present as declarations: " + "${usedVars.filter { it !in varsAndParams }}\n" ) diff --git a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/gson/GsonTest.kt b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/gson/GsonTest.kt index 056ed4d9f0..b7b48eb5a4 100644 --- a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/gson/GsonTest.kt +++ b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/gson/GsonTest.kt @@ -51,7 +51,8 @@ class GsonTest { StringTypeAdapter(xcfaLocationAdapter) ) gsonBuilder.registerTypeHierarchyAdapter(XCFA::class.java, XcfaAdapter { gson }) - gsonBuilder.registerTypeHierarchyAdapter(VarDecl::class.java, + gsonBuilder.registerTypeHierarchyAdapter( + VarDecl::class.java, VarDeclAdapter({ gson }, scope, env, !newScope) ) gsonBuilder.registerTypeHierarchyAdapter(Stmt::class.java, @@ -62,7 +63,8 @@ class GsonTest { StringTypeAdapter { TypeWrapper(it).instantiate() }) gsonBuilder.registerTypeHierarchyAdapter(VarIndexing::class.java, StringTypeAdapter { BasicVarIndexing.fromString(it, scope, env) }) - gsonBuilder.registerTypeHierarchyAdapter(XcfaLabel::class.java, + gsonBuilder.registerTypeHierarchyAdapter( + XcfaLabel::class.java, XcfaLabelAdapter(scope, env, { gson }) ) gsonBuilder.registerTypeHierarchyAdapter(MetaData::class.java, MetaDataAdapter()) From ad26bfb24720ea453c5ff4c2bab1965d38bfb188 Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Fri, 18 Oct 2024 22:44:41 +0200 Subject: [PATCH 15/16] Fixed pre- and post statements of ternary operators --- .../grammar/function/FunctionVisitor.java | 79 ++++++++++++++++--- 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java index 427034fb2c..83adb2c0ed 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java @@ -465,6 +465,18 @@ public CStatement visitBodyDeclaration(CParser.BodyDeclarationContext ctx) { CAssignment cAssignment = new CAssignment(declaration.getVarDecls().get(0).getRef(), declaration.getInitExpr(), "=", parseContext); recordMetadata(ctx, cAssignment); compound.getcStatementList().add(cAssignment); + if (declaration.getInitExpr() instanceof CCompound compoundInitExpr) { + final var preCompound = new CCompound(parseContext); + final var postCompound = new CCompound(parseContext); + final var preStatements = collectPreStatements(compoundInitExpr); + preCompound.getcStatementList().addAll(preStatements); + final var postStatements = collectPostStatements(compoundInitExpr); + postCompound.getcStatementList().addAll(postStatements); + resetPreStatements(compoundInitExpr); + resetPostStatements(compoundInitExpr); + compound.setPreStatements(preCompound); + compound.setPostStatements(postCompound); + } } } } else { @@ -509,7 +521,16 @@ public CStatement visitAssignmentExpressionAssignmentExpression(CParser.Assignme CCompound preStatements = new CCompound(parseContext); CCompound postStatements = new CCompound(parseContext); Expr ret = ctx.unaryExpression().accept(expressionVisitor); - CAssignment cAssignment = new CAssignment(ret, ctx.assignmentExpression().accept(this), ctx.assignmentOperator().getText(), parseContext); + CStatement rhs = ctx.assignmentExpression().accept(this); + if (rhs instanceof CCompound compoundInitExpr) { + final var preStatementList = collectPreStatements(compoundInitExpr); + preStatements.getcStatementList().addAll(preStatementList); + final var postStatementList = collectPostStatements(compoundInitExpr); + postStatements.getcStatementList().addAll(postStatementList); + resetPreStatements(compoundInitExpr); + resetPostStatements(compoundInitExpr); + } + CAssignment cAssignment = new CAssignment(ret, rhs, ctx.assignmentOperator().getText(), parseContext); compound.getcStatementList().add(cAssignment); preStatements.getcStatementList().addAll(expressionVisitor.getPreStatements()); compound.setPreStatements(preStatements); @@ -525,6 +546,34 @@ public CStatement visitAssignmentExpressionConditionalExpression(CParser.Assignm return ctx.conditionalExpression().accept(this); } + private void resetPreStatements(CStatement statement) { + if (statement instanceof CCompound compound) { + compound.setPreStatements(null); + for (CStatement cStatement : compound.getcStatementList()) { + resetPreStatements(cStatement); + } + } + } + + private void resetPostStatements(CStatement statement) { + if (statement instanceof CCompound compound) { + compound.setPostStatements(null); + for (CStatement cStatement : compound.getcStatementList()) { + resetPostStatements(cStatement); + } + } + } + + private List getStatementList(CStatement statement) { + if (statement instanceof CCompound compound) { + return compound.getcStatementList(); + } else if (statement != null) { + return List.of(statement); + } else { + return List.of(); + } + } + /* This collects the following: - the current compound's pre-statement @@ -536,7 +585,7 @@ private List collectPreStatements(CStatement cStatement) { return Stream.concat( Stream.concat( collectPreStatements(cStatement.getPreStatements()).stream(), - Stream.of(cStatement.getPreStatements())), + getStatementList(cStatement.getPreStatements()).stream()), ((CCompound) cStatement).getcStatementList().stream().flatMap(cStatement1 -> collectPreStatements(cStatement1).stream()) ).toList(); } else return List.of(); @@ -553,8 +602,8 @@ private List collectPostStatements(CStatement cStatement) { return Stream.concat( ((CCompound) cStatement).getcStatementList().stream().flatMap(cStatement1 -> collectPostStatements(cStatement1).stream()), Stream.concat( - Stream.of(cStatement.getPreStatements()), - collectPostStatements(cStatement.getPreStatements()).stream()) + getStatementList(cStatement.getPostStatements()).stream(), + collectPostStatements(cStatement.getPostStatements()).stream()) ).toList(); } else return List.of(); } @@ -586,26 +635,34 @@ public CStatement visitConditionalExpression(CParser.ConditionalExpressionContex CCompound ifTruePre = new CCompound(parseContext); - ifTruePre.getcStatementList().addAll(collectPreStatements(ifTrue)); + List ifTruePreList = collectPreStatements(ifTrue); + ifTruePre.getcStatementList().addAll(ifTruePreList); ifTruePre.setPostStatements(new CCompound(parseContext)); ifTruePre.setPreStatements(new CCompound(parseContext)); CCompound ifFalsePre = new CCompound(parseContext); - ifFalsePre.getcStatementList().addAll(collectPreStatements(ifFalse)); + List ifFalsePreList = collectPreStatements(ifFalse); + ifFalsePre.getcStatementList().addAll(ifFalsePreList); ifFalsePre.setPostStatements(new CCompound(parseContext)); ifFalsePre.setPreStatements(new CCompound(parseContext)); CCompound ifTruePost = new CCompound(parseContext); - ifTruePost.getcStatementList().addAll(collectPostStatements(ifTrue)); + List ifTruePostList = collectPostStatements(ifTrue); + ifTruePost.getcStatementList().addAll(ifTruePostList); ifTruePost.setPostStatements(new CCompound(parseContext)); ifTruePost.setPreStatements(new CCompound(parseContext)); CCompound ifFalsePost = new CCompound(parseContext); - ifFalsePost.getcStatementList().addAll(collectPostStatements(ifFalse)); + List ifFalsePostList = collectPostStatements(ifFalse); + ifFalsePost.getcStatementList().addAll(ifFalsePostList); ifFalsePost.setPostStatements(new CCompound(parseContext)); ifFalsePost.setPreStatements(new CCompound(parseContext)); - preStatements.getcStatementList().add(new CIf(guardCompound, ifTruePre, ifFalsePre, parseContext)); - postStatements.getcStatementList().add(new CIf(guardCompound, ifTruePost, ifFalsePost, parseContext)); + if (!ifTruePreList.isEmpty() || !ifFalsePreList.isEmpty()) { + preStatements.getcStatementList().add(new CIf(guardCompound, ifTruePre, ifFalsePre, parseContext)); + } + if (!ifTruePostList.isEmpty() || !ifFalsePostList.isEmpty()) { + postStatements.getcStatementList().add(new CIf(guardCompound, ifTruePost, ifFalsePost, parseContext)); + } CComplexType smallestCommonType = CComplexType.getSmallestCommonType(List.of(CComplexType.getType(lhs, parseContext), CComplexType.getType(rhs, parseContext)), parseContext); IteExpr ite = Ite( @@ -621,7 +678,7 @@ public CStatement visitConditionalExpression(CParser.ConditionalExpressionContex CExpr cexpr = new CExpr(iteExpr, parseContext); compound.getcStatementList().add(cexpr); - preStatements.getcStatementList().addAll(expressionVisitor.getPreStatements()); + preStatements.getcStatementList().addAll(0, expressionVisitor.getPreStatements()); compound.setPreStatements(preStatements); recordMetadata(ctx, compound); compound.setPostStatements(postStatements); From 8749d326dfa13f155135295f5bd726e774252ec5 Mon Sep 17 00:00:00 2001 From: Levente Bajczi Date: Sat, 19 Oct 2024 10:17:28 +0200 Subject: [PATCH 16/16] Fixed pre- and post statements of nested ternary operators --- .../transformation/grammar/function/FunctionVisitor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java index 83adb2c0ed..4f9041fa08 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java @@ -566,7 +566,7 @@ private void resetPostStatements(CStatement statement) { private List getStatementList(CStatement statement) { if (statement instanceof CCompound compound) { - return compound.getcStatementList(); + return compound.getcStatementList().stream().flatMap(i -> getStatementList(i).stream()).toList(); } else if (statement != null) { return List.of(statement); } else { @@ -587,7 +587,7 @@ private List collectPreStatements(CStatement cStatement) { collectPreStatements(cStatement.getPreStatements()).stream(), getStatementList(cStatement.getPreStatements()).stream()), ((CCompound) cStatement).getcStatementList().stream().flatMap(cStatement1 -> collectPreStatements(cStatement1).stream()) - ).toList(); + ).filter(i -> !(i instanceof CExpr)).toList(); } else return List.of(); } @@ -604,7 +604,7 @@ private List collectPostStatements(CStatement cStatement) { Stream.concat( getStatementList(cStatement.getPostStatements()).stream(), collectPostStatements(cStatement.getPostStatements()).stream()) - ).toList(); + ).filter(i -> !(i instanceof CExpr)).toList(); } else return List.of(); }